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.
Define reward hacking in the context of RLHF for LLMs, and give two concrete examples (for example, a model producing safe-sounding but misleading content, or padding responses to exploit a length-based reward heuristic). What early-detection monitoring signals would reveal reward hacking, and what mitigations would you apply at the dataset, reward-model, and policy-training levels?
Sample Answer
Direct answer: Reward hacking is when a policy learns to exploit quirks or blind spots in the reward model to score highly without actually becoming more helpful, harmless, or otherwise better in the way the reward model was meant to measure.
Structured elaboration: Two concrete examples: a model that pads its responses with extra, low-content filler because the reward model (trained on human preferences that happened to correlate length with thoroughness) scores longer answers higher regardless of whether the extra content adds value; and a model that produces confident-sounding but subtly misleading or unsupported claims because such responses were rated as "sounds helpful" by raters who did not fact-check every claim, so the reward model rewards fluent-sounding confidence rather than genuine correctness. Early-detection signals to monitor include: a growing gap between the reward model's score and an independent, harder-to-game metric (a smaller held-out human-eval sample, or a factuality check) on the same outputs; response length or specific stylistic markers (like certain hedging or confidence phrases) becoming disproportionately predictive of high reward scores over time; and reward scores rising while a fixed regression suite of prompts the model previously handled well starts showing quality regressions.
Worked example: If, over a training run, average response length grows from around 80 to 220 tokens while a spot-check human-eval score stays flat or drops, that pattern (reward increasing, but only correlated with length rather than with the independent quality check) is a strong reward-hacking signal specifically around length exploitation.
Trade-offs and pitfalls: Mitigations at the dataset level (collecting more diverse preference examples that decouple length or confident tone from actual quality), at the reward-model level (regularization, calibration checks, and periodically re-validating the reward model against fresh human judgments), and at the policy-training level (a KL penalty against the reference policy, and stopping training before the reward-model score and an independent quality check diverge) each address a different point in the pipeline, and relying on only one of the three tends to leave the others' failure modes uncovered.
As the AI/engineering lead for a significant new downstream domain, decide whether to retrain a foundation model from scratch, continue pretraining, fine-tune adapters on top of a frozen base, or instead keep the model frozen and rely on retrieval-augmented prompting. Propose a decision framework weighing data volume, domain distance, cost, risk of forgetting, latency, maintainability, regulatory constraints, user experience, and time-to-market.
Sample Answer
Direct answer: Deciding whether to retrain a foundation model from scratch, continue pretraining, or only fine-tune adapters (or stay frozen and use retrieval-augmented prompting instead) should be driven by a structured cost-benefit framework, quantifying the actual domain gap and available data, estimating benefit against compute cost, and weighing forgetting risk and time-to-market, rather than defaulting to whichever option sounds most thorough.
Structured elaboration:
- Quantify the domain gap and data sufficiency first: measure how far the target domain's data actually is from the source distribution (an embedding-shift statistic, or a task-level performance delta on a few-shot evaluation), and count how much labeled and unlabeled target data is actually available, since the right answer depends heavily on both numbers, not on intuition about how "different" the domain feels.
- Estimate benefit versus cost explicitly: expected performance gain tends to scale with both the domain gap and the (diminishing-returns) log of available data volume, while compute cost scales very differently across the three options, retraining from scratch costs roughly the full model's original pretraining compute, continued pretraining costs a fraction of that, and adapters cost comparatively little; putting a real GPU-hour and dollar estimate against each option turns "which is best" into a concrete comparison.
- Weigh risk and operational factors: the likelihood of catastrophic forgetting scales with how orthogonal the new task or domain is to the base model's original capabilities (and is mitigated by replay or multi-task fine-tuning); adapters reach production fastest, continued pretraining next, full retraining slowest; and a full retrain may trigger a costly re-certification or revalidation process in a regulated setting that adapters would not.
- Decision guidelines: prefer staying frozen and relying on retrieval-augmented prompting when the gap is mainly about missing or fast-changing FACTUAL knowledge rather than a behavioral or stylistic shift, when the underlying corpus changes faster than any retraining cadence could track, or when auditability (being able to cite the exact source behind an answer) matters more than baking the knowledge into the weights, since RAG avoids fine-tuning cost and forgetting risk entirely at the price of retrieval-time latency and dependence on a well-maintained index; prefer fine-tuning adapters when the domain gap is small to moderate, data is limited, time pressure is high, and risk tolerance is low; prefer continued pretraining when the gap is moderate, unlabeled data is abundant, and you need broad improvement across many downstream tasks while still preserving base capabilities; reserve retraining from scratch for a very large domain shift (a genuinely new modality or language), a massive high-quality dataset, or a required architectural change, since anything short of that rarely justifies its cost.
- Validate cheaply before committing: run a linear-probe or few-shot evaluation, a short (one to two epoch) continued-pretraining trial, and a quick adapter prototype against your core success metrics before committing to the full-scale version of whichever option the framework points to, these cheap probes catch a wrong framework-based call before it becomes an expensive mistake.
Worked example: For a moderate domain shift (say, adapting a general assistant to a specialized professional vertical) with a large pool of unlabeled in-domain text but only a modest labeled set, the framework points toward continued pretraining on the unlabeled corpus followed by adapters or LoRA fine-tuning on the labeled data, rather than either a frozen-plus-RAG approach (which would under-use the abundant unlabeled data) or a full retrain (which the domain gap and available compute do not justify). Running a cheap 1-2 epoch continued-pretraining probe first and measuring the delta on a held-out task-relevant evaluation confirms whether that recommendation is actually earning its cost before committing the full compute budget to it.
Trade-offs and pitfalls: The most common mistake is skipping the cheap validation probes and committing straight to the framework's recommended option at full scale, if the domain-gap estimate was wrong, that mistake is expensive to discover only after a full-scale continued-pretraining or retraining run has already consumed most of its budget. A second pitfall specific to regulated or safety-critical deployments is underestimating the re-certification cost a full retrain can trigger, which can dominate the total cost comparison even when the raw compute cost looks similar to continued pretraining.
Explain how to integrate RLHF training and deployment into an ML CI/CD pipeline: reproducible training runs, automated evaluation gates (offline plus human review), canary and shadow deployments for RL-trained policies, model versioning, and safe rollback when production metrics regress. What lineage and logging metadata would you record (dataset versions, prompt templates, annotator IDs, seeds, model checkpoints, and for production interactions: prompts, model outputs, log-probs, timestamps, and judgments) to support audits, reproducibility, and rollback?
Sample Answer
Direct answer: Integrating RLHF into a CI/CD pipeline needs immutable, hash-versioned datasets and containerized, seeded training runs for true reproducibility, automated offline evaluation gates backed by human review for borderline cases, a staged shadow-then-canary rollout with automated rollback tied to pre-defined safety and quality thresholds, and an explicit, comprehensive lineage and logging schema covering both training-time and production-time artifacts.
Structured elaboration:
- Reproducibility: every training run should record the exact code commit, container image, random seeds, hyperparameters, and dataset hash to an experiment tracker and artifact store, with software dependencies pinned, so any run can genuinely be reproduced later, not just approximately re-run; produced artifacts (policy weights, reward model, tokenizer/config, and the exact evaluation seeds used) should be signed and versioned with full lineage metadata.
- Lineage and logging metadata: for every training run, record the dataset version as a content hash (not just a filename), the exact version of the prompt template used to construct both training and evaluation examples, the annotator ID (or a stable anonymized annotator identifier) behind every human-labeled example so a labeling-quality issue can be traced back to its source, the random seed, and the resulting model checkpoint's own version identifier, all written to the same experiment-tracking and artifact store described above; separately, for every PRODUCTION interaction, log the exact prompt sent, the model's output, the per-token or per-sequence log-probabilities the policy assigned (useful later for offline analysis, bootstrapping a reward model, or debugging a distribution shift), a precise timestamp, and any downstream judgment recorded on that interaction (a human reviewer's label, an automated safety-classifier verdict, or a user feedback signal); this production log, not just the training-run metadata, is what actually lets an audit or an incident investigation reconstruct exactly what the model saw, said, and was judged on at a specific point in time.
- Automated evaluation gates: offline checks span basic regression tests (API shape, deterministic sanity checks) through behavioral evaluation (simulated scenarios, adversarial test cases, safety-constraint checks, and distributional-shift tests), with explicit pass/fail thresholds on core metrics and proper statistical-significance checks, not a single point-estimate comparison; when a run's metrics land near a threshold or trigger a heuristic flag (unusual uncertainty, novel behavior patterns), route it to human review rather than either auto-passing or auto-failing.
- Staged rollout: a SHADOW deployment first, routing a copy of real traffic to the new policy without ever serving its responses, purely to compare decisions and latency against the current baseline; then a CANARY rollout gradually shifting a small, increasing percentage of live traffic (for example 1%, then 5%, then 25%, then 50%) behind a feature flag or traffic-routing layer, with continuous monitoring throughout.
- Rollback and safety: pre-define explicit SLO and drift thresholds; if the canary's core metrics degrade beyond those thresholds, or a safety violation occurs, for a sustained window, trigger an automated rollback to the last known-good model version via the model registry's version pointer, keeping the previous model warm (not cold-started) so the rollback itself does not introduce a latency spike; capture the incident's full trace, drawing on exactly the production-interaction logs above, for a post-rollback forensic replay.
Worked example: A concrete gate sequence for one training run: the run completes and produces a candidate policy; automated offline evaluation runs the full regression and behavioral suite, if every metric clears its threshold with statistical confidence, the candidate proceeds automatically to shadow deployment; if one metric lands within a defined "uncertain zone" near its threshold, a human reviewer examines a sample of the flagged trajectories (drawing on the logged prompts, outputs, and log-probs) before the candidate is allowed to proceed; only after a clean shadow-deployment comparison does the candidate begin the staged canary rollout, with the very first automated rollback trigger armed from the moment canary traffic starts, not added later once the rollout looks stable.
Trade-offs and pitfalls: Skipping the shadow-deployment stage to save time is a common shortcut that removes the cheapest, lowest-risk opportunity to catch a problem (since shadow traffic never actually affects a real user) before any live traffic is exposed to the new policy. A second common pitfall is defining rollback thresholds loosely enough that a real regression persists for an extended window before triggering an automatic rollback, the threshold and the required sustained-duration window both need to be tuned deliberately against how much exposure is tolerable, not left at a default that was never revisited after the first incident. A third pitfall is logging only training-run metadata and skipping the production-interaction log (prompts, outputs, log-probs, timestamps, judgments), without that log a post-incident audit cannot actually reconstruct what a specific user saw or how a specific response was judged, it can only reconstruct how the model was trained.
What is alignment drift (sometimes called alignment regression) in deployed LLMs and what common causes create it post-deployment? Provide at least three practical mitigation strategies teams can apply to reduce drift risk over time.
Sample Answer
Direct answer: Alignment drift is when a deployed model's behavior gradually diverges from its intended safety, policy, or utility goals over time, for example starting to produce unsafe, biased, or off-specification outputs even though it passed evaluation initially, and it typically comes from a small set of well-understood causes rather than random decay.
Structured elaboration: Common causes include data drift (the distribution of real user inputs shifting toward new topics or adversarial phrasing the model was not evaluated against), incremental model updates or pipeline changes introducing unintended behavioral side effects, feedback-loop effects (model-generated content getting re-ingested into future training data, reinforcing whatever undesirable patterns already existed), changes in the surrounding system (prompt-template edits, third-party tool or integration changes) that shift the effective input the model sees without the model itself changing, and drift in the evaluation metrics or labeling standards themselves, making an apparently-stable score mask a real underlying change. Three practical mitigation categories address these: continuous monitoring with alerting on safety and quality metrics (using both random and high-risk-targeted sampling so rare but severe drift is not diluted into an aggregate average); robust CI/CD gating for any model or pipeline change (regression tests against an immutable evaluation set, red-team scenarios, and canary rollouts before a change reaches full traffic); and data-governance controls specifically around feedback loops (never blindly retraining on the model's own recent outputs without labeling and vetting them first, since that is exactly how a feedback loop reinforces its own drift).
Worked example: A concrete drift-detection trigger: if a fixed, immutable regression suite (never updated to "adjust for" the new normal) shows a safety-violation rate creeping up 0.5 percentage points per week over a month, even though no explicit model change was deployed in that window, that pattern points toward either upstream data drift (user inputs are shifting) or a feedback-loop effect (model outputs are being re-ingested somewhere upstream), and distinguishing the two requires checking whether the input distribution itself has measurably shifted versus whether recent training data included un-vetted model-generated content.
Trade-offs and pitfalls: The single most common way alignment drift becomes hard to detect is silently updating the evaluation set or metric definitions "to keep them current" without preserving an immutable baseline version, once the yardstick itself moves, a real behavioral regression can be invisible in the metrics. A second common failure is that fixing drift by immediately re-fine-tuning on freshly-observed problematic outputs, without vetting that data first, can itself become the next feedback loop that causes further drift down the line.
You see an increase in hallucinations after fine-tuning an LLM on domain-specific QA. Propose a systematic debugging and mitigation plan: experiments to isolate the cause, dataset checks, training interventions, and runtime techniques to reduce hallucinations.
Sample Answer
Direct answer: Debugging a hallucination increase after fine-tuning on domain-specific QA requires first isolating whether the cause is the DATA, the TRAINING process, or INFERENCE-time behavior, since each points to a different fix, then applying training-level and runtime mitigations in parallel rather than waiting for one full explanation before acting.
Structured elaboration:
- Isolation experiments: an A/B comparison of the base (pre-fine-tune) model against the fine-tuned model on the SAME held-out QA set, with human-evaluated faithfulness labels, quantifies exactly how much the fine-tuning step itself changed the hallucination rate; breaking this down by domain, question type, and question length surfaces WHERE the increase concentrates rather than treating it as uniform; an ablation fine-tuning on subsets of the data (a smaller fraction, or excluding a specific noisy source) tests whether the increase scales with a specific portion of the training data; and running the same prompts at temperature zero isolates whether the behavior is a genuinely learned pattern versus incidental sampling randomness.
- Dataset checks: audit the provenance of training sources specifically for dubious or fabricated content (scraped forum answers, synthetic chat data of uncertain quality), sample-check labels for actual hallucinated or unsupported answers that may have been included as if they were correct targets, check for data contamination (examples that overlap with or leak the evaluation set), and measure distributional drift between the fine-tuning data and the actual intended production query distribution, a training set that looks fine in isolation can still be a poor match for what the model will actually be asked in production.
- Training interventions: prioritize high-quality, evidence-backed examples early in training and downweight or remove low-confidence sources; add an explicit training signal against hallucination, negative examples pairing a question with a plausible-but-false answer labeled as bad, or an auxiliary objective requiring the model to point to supporting evidence for its claims; reduce the learning rate, use fewer epochs, or freeze lower layers to avoid overwriting general world knowledge the base model already had correct; mix in a small fraction of the original clean pretraining or instruction-tuning data to help preserve that general knowledge; and explicitly teach the model to say "no reliable source" or otherwise abstain when evidence is genuinely absent, rather than only ever training it to produce a confident answer.
- Runtime mitigations, deployable faster than a full retrain: retrieval-augmented generation that conditions the answer on retrieved documents and requires citations; a separate verifier model that checks generated claims against retrieved evidence and triggers a fallback or abstention when support is weak; lower-temperature, more conservative decoding specifically for factual answers; and an explicit confidence threshold below which the system returns "insufficient evidence" rather than a confident guess.
- Evaluation and ongoing monitoring: track hallucination rate on a dedicated factual-QA regression suite going forward, and block any future release that regresses beyond a set threshold, treating this the same way a functional regression test would be treated, not as a one-time investigation.
Worked example: A concrete short investigation plan: in the first week, run the A/B comparison plus a source audit on a sample of the training data; if the noise is concentrated in one identifiable source (for example scraped forum content with a much higher rate of unverified claims than the rest of the dataset), remove that source and re-run a small-scale fine-tune to confirm the hallucination rate drops before committing to a full production retrain; in parallel, deploy retrieval-augmented generation plus a verifier as an immediate runtime hotfix, since that mitigates user-facing harm regardless of how long the training-side investigation takes; over the following weeks, run controlled comparisons (clean data only, clean data plus an evidence-pointing objective, clean data plus RLHF specifically for factuality) against the same held-out faithfulness-labeled set to decide which training-level fix is actually worth adopting long-term.
Trade-offs and pitfalls: Waiting for a complete root-cause explanation before deploying ANY mitigation delays reducing real user-facing harm unnecessarily, the runtime mitigations (retrieval augmentation, a verifier, conservative decoding) can and should deploy in parallel with the slower training-level investigation, not after it concludes. A second pitfall is treating a reduced hallucination rate after removing one suspected noisy source as final proof of the diagnosis without re-running the full evaluation suite, a small-scale confirmation run is a good first check, but the production decision should rest on the same rigorous held-out evaluation used throughout this investigation, not an informal spot-check.
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.