Skip to content
Tech Interview Prep
Technical interview guide

Fine-Tuning & Adaptation

Adapting a pretrained LLM's behavior via further training, and how that differs from prompting or RAG.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: Transformer, InstructGPT, LoRA, QLoRA, DPO, LIMA, Model Cards, Datasheets, Hugging Face PEFT/Transformers/TRL, NIST AI RMF, and OWASP supply-chain references reviewed 2026-09-06.

Overview

Curated: · Written: · Reviewed:

Fine-Tuning & Adaptation

In one line

Fine-tuning changes how a model behaves: output format, style, tool-call habits, classification boundaries, and the cost and latency profile of a task. Reach for it only after prompting, retrieval or tools fail to fix the observed failure. It does not reliably add fresh facts, and it cannot enforce authorization or guarantee truth.

Key definitions

  • SFT: supervised fine-tuning on prompt and expert-answer pairs, with loss on assistant tokens only.
  • LoRA: the base weights stay frozen while low-rank matrices A and B are trained into selected linear layers.
  • QLoRA: LoRA on a frozen base stored in 4-bit NF4. Serving must match the quantization scheme, compute dtype and merge or load steps used in training.
  • DPO: preference tuning against a frozen reference policy, with no separate reward model.
  • Catastrophic forgetting: loss of capabilities the training data never touched. Check it on a retained-capability suite.
  • Distillation: a small student imitates a stronger teacher's outputs.

Formulas and complexity

LoRA update for a frozen weight W, with rank r and scale alpha:

W′=W+αrBA,A∈Rr×din,  B∈Rdout×rW' = W + \frac{\alpha}{r} B A, \quad A \in \mathbb{R}^{r \times d_{in}}, \; B \in \mathbb{R}^{d_{out} \times r}

Trainable parameters per targeted module:

r (din+dout)r \,(d_{in} + d_{out})

How it works

  1. Freeze the base model and inject low-rank matrices into the targeted linear layers, such as q_proj and v_proj.
  2. Train on prompt-answer pairs with label -100 on prompt and tool-result tokens, which PyTorch cross-entropy ignores by default.
  3. Score each checkpoint on a frozen eval set and a retained-capability suite, not on training loss.
  4. Promote the adapter, or merge it into one base revision.
yes no no yes Observed failure Prompt, RAG or tools fix it? Stop: no training Dedupe and split data by group LoRA SFT on assistant tokens Gates pass on frozen eval and retained suite? Change data or objective Promote adapter

When to use and when not to

SituationPreferWhy
Facts change weeklyRAGDocs belong in retrieval, not weights
Arithmetic, lookups, permission checksTools or codeMust be exact and enforceable
Schema breaks under load or house style driftsLoRA SFTA prompt cannot hold the behavior
Base model already passes the schema gatePrompt and schema changesNothing to train
Many tasks on one baseHot-swapped adaptersFull fine-tuning multiplies checkpoints
Change a low-rank update cannot expressFull fine-tuningMore capacity, more forgetting risk
Reviewers reject valid answersPreference tuningOnly after SFT is stable

Traps interviewers probe

  1. Lowest loss means best model. Fix: judge checkpoints on gates. In the worked example, epoch 12 had loss 0.31 but 61% tool-JSON pass and 7 of 50 canary hits. Epoch 3 passed both at 94%.
  2. Random row split. Fix: deduplicate first, then keep paraphrases and same-source rows in one partition. A random split is the most common way to inflate scores.
  3. Fine-tuning for facts. Fix: put changing facts in retrieval and tune behavior only.
  4. Training on prompt tokens. Fix: mask prompt and tool-result labels to -100 so the loss covers assistant tokens.
  5. No frozen baseline. Fix: score the untouched base on the same gates before the first run.

Interview tips

Open by naming the failure, then the rung of the ladder that fixes it: prompt, retrieval, tools, fine-tuning, then continued pretraining. Interviewers listen for this order.

Follow-ups to expect:

  • If the base model already passes the schema gate, would you train? Probably not. Change the prompt and tool schema first.
  • How do you know a canary leak is real? Exact-match the planted string over a fixed number of greedy samples, then rerun with sampling to see whether it appears at other temperatures.
  • What if the checkpoint fails on one language or length slice? Slice the results before choosing. A passing average can hide a failing slice.

30-second answer outline: State the failure and the metric. Try prompt, RAG and tools first. If the behavior still fails, run LoRA SFT on assistant tokens only, with deduplicated data and a grouped split. Gate the checkpoint on a frozen base comparison, schema pass rate, canary exact match and a retained-capability suite. Pick the checkpoint that passes the gates, not the one with the lowest loss.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.