LLM Fine-Tuning and Alignment Questions
Adapting foundation models to specific tasks and desired behavior. Covers transfer learning and using pretrained models, full and parameter-efficient fine-tuning, instruction tuning, and alignment methods such as RLHF and preference optimization. Focuses on when and how to customize a base model rather than prompt it, and the data and compute tradeoffs involved.
Design an experiment to evaluate how aggressive quantization (4-bit or lower, combined with LoRA/adapters) of a fine-tuned or instruction-tuned model impacts alignment objectives such as helpfulness and safety when serving on CPU or resource-constrained hardware. Cover the experimental groups, metrics, sampling strategy, statistical analysis, calibration/quantization-aware fine-tuning steps, and mitigation techniques if quantization measurably degrades aligned behavior.
Sample Answer
Direct answer: Evaluating how 4-bit quantization affects alignment requires comparing the FP16 baseline against multiple quantization variants (post-training quantization, quantization-aware fine-tuning, and a hybrid that keeps critical layers at higher precision) on the SAME prompts with the SAME decoding settings, measuring helpfulness and safety with properly powered, paired statistical tests, not just a qualitative before-and-after comparison.
Structured elaboration:
- Experimental groups: the original FP16 model as the control; a post-training-quantized 4-bit variant (the cheapest to produce); a quantization-aware fine-tuned 4-bit variant (recalibrated on instruction data, typically higher quality but more expensive to produce); and a hybrid variant keeping a small number of critical layers at higher precision while quantizing the rest, run with identical decoding settings and seeds across all variants so any observed difference is attributable to quantization itself, not incidental sampling variation.
- Metrics: helpfulness via human-rated scores on a representative, stratified prompt set plus automated metrics for tasks where they apply; safety via a red-team prompt suite scored both by human labelers and an automated toxicity or unsafe-content classifier; calibration (confidence versus accuracy); and operational metrics (latency, memory, throughput), since quantization's whole point is an operational trade-off, that side needs to be measured with the same rigor as the alignment side.
- Sampling and statistical rigor: use a stratified prompt corpus spanning common instructions, factual/knowledge questions, reasoning tasks, and adversarial/safety prompts, sized via a power analysis targeting a meaningful minimum effect (a moderate effect size at 80% power typically implies several hundred human-rated samples per metric); randomize prompt order, blind human raters to which model variant produced each response, use multiple raters and measure their agreement, and analyze with PAIRED tests on the same prompts across model variants (an appropriate paired test for ordinal ratings, an appropriate paired test for binary safety outcomes), reporting effect sizes and confidence intervals with a multiple-comparison correction since several quantization variants are being compared against the same baseline.
- Mitigation if degradation is found: cluster the failure cases to identify the specific pattern (a particular content type, or a specific behavior like hallucination rate rising specifically on longer responses), then apply a targeted fix, quantization-aware fine-tuning on a combined instruction-plus-safety dataset, keeping specific sensitive layers (commonly attention projections) at higher precision, per-channel quantization or learned scaling factors, or a lightweight LoRA fine-tune specifically to restore the lost alignment behavior while keeping most of the quantization's size and speed benefit; re-run the SAME evaluation protocol after any mitigation, since a fix that looks like it worked on a quick spot-check needs the same statistical rigor as the original comparison to actually confirm the regression is closed.
Worked example: A concrete degradation-and-fix cycle: the paired comparison shows the plain post-training-quantized 4-bit variant has a statistically significant increase in unsafe-response rate on the adversarial prompt slice specifically (not on the benign slice), clustering the failed cases reveals they concentrate on a specific attack pattern; a targeted fix, quantization-aware fine-tuning including that specific attack pattern's examples in the recalibration data, is applied and the full evaluation protocol (including the same paired statistical test) is re-run; only if the unsafe-response rate on that same adversarial slice is no longer significantly different from the FP16 baseline is the fix considered validated, a smaller informal spot-check would not have caught whether the fix generalized beyond the specific examples used to construct it.
Trade-offs and pitfalls: Comparing quantized and unquantized models with different decoding settings, seeds, or prompt sets (rather than the same ones) confounds any observed difference with those incidental factors rather than isolating the effect of quantization itself. A second pitfall is treating a spot-check on a handful of examples as sufficient evidence a mitigation worked, without the same statistical rigor (paired tests, effect sizes, correction for multiple comparisons) applied to the post-mitigation evaluation, a fix can look successful on the specific failures it was built to address while a proper re-evaluation would reveal it did not generalize to the broader adversarial slice.
Write a Python function to compute Kendall's Tau for a set of predicted preference scores versus ground-truth pairwise labels. Input: list of tuples (score_a, score_b, true_preference) where true_preference is 1 if a>b else 0. Output: numeric Kendall's Tau. Explain how you handle ties in scores or labels.
Sample Answer
Direct answer: Kendall's Tau for reward-model evaluation compares, across many pairs, whether the model's PREDICTED preference (from its scores) agrees with the TRUE preference label, and reduces to (concordant pairs minus discordant pairs) divided by the total number of pairs.
Structured elaboration: For each pair, the predicted preference is derived from comparing score_a and score_b (a is predicted-preferred if score_a > score_b); if that predicted preference matches the true_preference label, the pair is concordant, if it disagrees, it is discordant. Ties in the predicted scores (score_a exactly equal to score_b) are neither concordant nor discordant, they still count in the denominator (this is one defensible convention among a few for handling ties in Tau; the specific convention should be stated explicitly, since Tau has more than one standard variant).
Worked example (executed):
def kendalls_tau(pairs):
"""pairs: list of (score_a, score_b, true_preference), true_preference=1 if a>b else 0."""
n = len(pairs)
if n == 0:
return 0.0
concordant = discordant = tied = 0
for score_a, score_b, true_pref in pairs:
predicted_pref = 1 if score_a > score_b else (0 if score_a < score_b else None)
if predicted_pref is None:
tied += 1
continue
if predicted_pref == true_pref:
concordant += 1
else:
discordant += 1
return (concordant - discordant) / n
I verified this against three cases: all predictions agreeing with ground truth gives tau exactly 1.0; all predictions disagreeing gives tau exactly -1.0; and a mixed case with 2 concordant pairs, 1 discordant pair, and 1 predicted-score tie out of 4 total pairs gives (2−1)/4=0.25, matching the function's output exactly.
Trade-offs and pitfalls: Silently dropping tied pairs from BOTH the numerator and the denominator (rather than keeping them in the denominator as this implementation does) produces a different numeric convention and would not be comparable to a Tau computed the way scikit-learn or scipy define it by default, so the tie-handling convention should always be documented alongside any reported Tau value. A second consideration: Kendall's Tau treats every pair equally regardless of how large or small the true or predicted score gap is, so a reward model that gets every pair's ORDERING right but is badly miscalibrated in magnitude would still score a perfect Tau of 1.0, this metric measures ranking agreement, not calibration, and should be paired with a calibration check (like the reward-model calibration techniques discussed elsewhere in this pipeline) rather than used alone.
Discuss approaches for multi-objective reward shaping where you must trade off helpfulness and non-harmfulness in RL training. What formulations would you consider, and what practical training schedule or curriculum would you use to reach an acceptable trade-off?
Sample Answer
Direct answer: Trading off helpfulness against non-harmfulness in RL training is best treated as an explicit multi-objective problem, not folded into a single unstructured reward, and the three main approaches, constrained optimization, Pareto-frontier exploration, and scalarization, differ in whether they give a hard safety guarantee, a set of options to choose from, or a simple but potentially blind single trade-off point.
Structured elaboration:
- Constrained optimization: formulate the objective as maximizing expected helpfulness subject to a bound on a non-harmfulness cost (or the reverse), using methods like constrained policy optimization or Lagrangian (primal-dual) approaches that directly enforce the safety constraint during learning via an adaptive penalty; this gives the strongest guarantee that harm stays below a set bound, at the cost of some potential loss in achievable helpfulness compared with an unconstrained optimum.
- Pareto-frontier exploration: instead of picking one fixed trade-off up front, train a set of policies spanning different points on the helpfulness-versus-harm trade-off curve (via multi-objective evolutionary methods, multi-objective policy gradients, or population-based training), producing a genuine menu of options a human decision-maker can choose from, at the cost of more training compute to produce and maintain multiple candidate policies.
- Scalarization: combine the two objectives into a single weighted reward (linear scalarization is simplest, nonlinear forms like a Chebyshev scalarization can capture trade-off shapes a simple weighted sum misses); this is the cheapest to implement and train, but a fixed weighting can hide non-convex parts of the true trade-off frontier, some genuinely good trade-off points are unreachable by any linear weighting no matter how it is tuned.
- Practical staged training schedule: pretrain for helpfulness in a lower-risk setting with dense reward signal first, then introduce safety-constraint signals and switch to a constrained or Lagrangian objective, then, if resources allow, refine with a Pareto sweep across weight settings and distill the chosen operating point into a single deployable policy.
Worked example: A concrete instance of the linear-scalarization blind spot: if the true trade-off frontier between helpfulness and harm avoidance has a concave "dent" (a region where a small sacrifice in one objective buys a large gain in the other), no single linear weighting of the two objectives will ever select a policy inside that dent, since a linear scalarization can only reach points on the convex hull of the frontier; a nonlinear scalarization or a genuine Pareto sweep across several policies is needed to discover and select that operating point, which is exactly why "just weight the two rewards and tune the weight" is not always sufficient.
Trade-offs and pitfalls: Constrained optimization gives the strongest formal safety guarantee but can measurably reduce the achievable helpfulness ceiling compared with an unconstrained policy, a real cost that needs to be weighed against the value of the guarantee for the specific product. Pareto-sweep methods expose real options but require a genuine, defensible selection criterion for choosing the final operating point, otherwise the extra training cost of producing multiple candidates is wasted if the final choice is made arbitrarily. Tracking constraint-violation rate, expected helpfulness, and worst-case regret together (rather than any single number) is what makes the trade-off visible enough to make that final selection defensibly.
Discuss in depth the trade-offs between adapter modules, LoRA, prefix-tuning, and prompt-tuning: parameter efficiency, training speed, inference memory and compute, and task expressivity. Given a 10B-parameter transformer with limited GPU memory, how would you choose between them in practice, and where does one approach substantially outperform another?
Sample Answer
Direct answer: Adapters, LoRA, prefix-tuning, and prompt-tuning are all parameter-efficient fine-tuning families that add a small trainable component instead of updating the full model, but they differ sharply in parameter count, training speed, inference overhead, and expressivity, so the right choice depends on model size, task complexity, and deployment constraints.
Structured elaboration:
- Parameter efficiency: prompt-tuning is the sparsest (only a small set of soft-prompt embeddings, often tens of thousands of parameters total), LoRA scales with the chosen rank (typically tens of thousands to a few million parameters for a large model), adapters add small bottleneck feed-forward modules per layer (usually somewhat more parameters than LoRA at comparable capacity), and prefix-tuning learns key/value prefix tensors per attention layer (parameter count scales with prefix length times number of layers).
- Training speed: prompt-tuning and LoRA are fastest since they touch few parameters and integrate cleanly with existing linear-algebra kernels; adapters add a modest amount of extra forward/backward compute per layer; prefix-tuning tends to be slowest of the four because the learned prefixes interact with attention at every layer and increase per-step memory.
- Inference memory and compute: prompt-tuning has negligible inference overhead; LoRA can be merged into the base weights after training for exactly zero inference overhead (the common production choice), or kept unmerged for the small overhead of instant adapter swapping; adapters add a small but real per-layer compute cost that generally cannot be merged away since they include a nonlinearity; prefix-tuning increases attention state size and compute proportional to prefix length and model depth, the highest inference cost of the four.
- Task expressivity: adapters, because they include a nonlinearity, can learn more complex per-layer transformations and tend to be strongest for multi-task or multilingual transfer; LoRA is a purely linear low-rank update but has proven surprisingly expressive for instruction tuning and generation; prefix-tuning is good at steering generation behavior by reshaping what each layer attends to; prompt-tuning is the least expressive of the four and depends on the base model already containing the needed capability, which is why it mainly works well at very large model scale.
- CV vs NLP: in NLP, LoRA is the dominant production choice for large language models because of its mergeability, while adapters remain strong for encoder-style multilingual/multi-task transfer (stacking language and task adapters); in CV (for example ViT), adapters and LoRA-style low-rank updates to attention/MLP projections are both used for domain adaptation without catastrophic forgetting, while prefix-tuning is rarer since attention key/value prefixes map less naturally onto image patches.
Worked example: Consider fine-tuning a 10B-parameter language model (the scale given in the question) on 10 different downstream tasks with limited GPU memory. LoRA at rank 8-16 typically matches full fine-tuning accuracy on instruction-style tasks while training under 1% of the parameters, and because it can be merged, deploying 10 task variants costs the same inference latency as the base model, only the storage of 10 small adapter files (tens of megabytes each) differs. Adapters would be the better choice instead if the 10 tasks are in genuinely different languages or domains where you want strict per-task modularity (enabling or disabling a task's adapter independently) and can accept a small constant per-layer inference overhead. Prompt-tuning would only be competitive here if the base model were dramatically larger (100B or more parameters), since at 10B it usually still underperforms both LoRA and adapters on tasks needing real semantic adaptation.
Trade-offs and pitfalls: The most common mistake is picking a method by its parameter-efficiency ranking alone without considering deployment: prefix-tuning's extra attention-state cost can dominate serving latency at scale even though it trains few parameters, and unmerged LoRA/adapters both add per-request overhead if you forget to merge or cache them. A second pitfall is assuming one method's published results transfer directly across model scale: prompt-tuning's competitiveness is scale-dependent, so a technique that works at 100B+ parameters can underperform badly at 1-10B.
Design a controlled experiment to compare full fine-tuning, LoRA, and Adapter-based fine-tuning on a 5-class text classification problem with 2,000 labeled examples. Describe dataset splits, metrics (including resource metrics), hyperparameter search strategy, compute/resource tracking, and how you would report statistical significance between methods.
Sample Answer
Direct answer: A controlled, repeatable experiment comparing full fine-tuning, LoRA, and adapter-based fine-tuning on the same 2,000-example 5-class classification dataset needs matched dataset splits, an equal hyperparameter-search budget per method, both accuracy and resource metrics, and paired statistical tests across multiple seeds, not a single run per method.
Structured elaboration:
- Dataset splits: a stratified split preserving class balance, for example 70% train (1,400), 15% validation (300), 15% held-out test (300), plus either 5-fold stratified cross-validation on the combined train-and-validation portion, or multiple randomized seeds, to get a genuine variance estimate rather than a single point comparison between methods.
- Metrics: macro F1 as the primary metric (appropriate for a 5-class task, since it does not let a dominant class hide poor performance on the others) plus accuracy; a calibration metric (expected calibration error) since a well-calibrated model matters beyond raw accuracy; and resource metrics for every method, peak GPU memory, total GPU-hours, number of trainable parameters, final checkpoint size on disk, and inference latency/throughput at a fixed batch size, since the whole point of the comparison is cost versus performance, not performance alone.
- Hyperparameter search: give each method the SAME search budget (for example 30 trials) over its own relevant space, learning rate and batch size and weight decay for all three, plus rank and alpha specifically for LoRA, and bottleneck dimension and nonlinearity specifically for adapters, using a method like Bayesian optimization or ASHA to make efficient use of that shared budget rather than a naive grid search.
- Reproducibility and tracking: log every hyperparameter, GPU identifier, peak memory, GPU-hours, wall-clock time, checkpoint, and random seed with an experiment tracker, and pin the software environment (container or environment file) with seed-controlled data loaders so the entire comparison can be rerun and reproduced later.
- Statistical significance: run at least 5 independent repeats per method with different seeds using each method's best validation hyperparameters, report mean and standard error on the held-out test set, and use a PAIRED test (a paired t-test or Wilcoxon signed-rank test, since the same data splits and seeds are shared across methods) rather than an unpaired comparison, along with an effect size and confidence interval, not just a p-value.
Worked example: After running this design, a typical result table might show LoRA reaching macro F1 within half a point of full fine-tuning while using roughly a third of the GPU-hours and a small fraction of the trainable parameters, a genuine case where the practical conclusion (LoRA is the better choice) depends as much on the resource-cost columns as on the raw F1 column; presenting this as a Pareto front of F1 against GPU-hours (rather than only a table of best F1 per method) makes that cost-performance trade-off visible to a decision-maker at a glance, and reporting the paired significance test alongside it confirms whether a half-point F1 difference is a real effect or within the noise of seed variance.
Trade-offs and pitfalls: Comparing only the single best hyperparameter configuration found for each method, without repeating that configuration across multiple seeds, risks reporting a lucky (or unlucky) seed as the method's real performance; and reporting only accuracy or F1 without the resource-cost columns hides the entire point of a parameter-efficiency comparison, a small accuracy edge for full fine-tuning is not automatically worth 3x the GPU-hours, and the experiment's report should make that trade-off explicit rather than declaring a single winner on accuracy alone.
Unlock Full Question Bank
Get access to all LLM Fine-Tuning and Alignment interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.