Slides · Fine-tuning

Fine-tuning: interview drills

Fine-tuning: interview drills

Turning the module into spoken answers: a ninety-second opener, sizing arithmetic, a loss by hand, a forty-minute program design and symptom diagnosis.

By the end you can state the opener with its break-even, work memory, parameter and time estimates while naming what each leaves out, read a DPO loss, structure a design answer, and name likely causes in order with the first check.

Concept

How to use these drills

  • Answer aloud, under a clock, before opening the key. Reading a drill teaches little.
  • Provenance: each drill slide carries its own label, Common industry pattern or Generated practice. None is verified as asked by a named company, and this deck makes no such claim.
  • Every figure in the drills is invented for the exercise. Every calculation was recomputed with a script. The code slide holds the LoRA, ZeRO and time estimators with their test results.
  • Sizes are decimal GB. Every memory figure is a floor that leaves out activations, logits and framework overhead.
  • Library behaviour quoted here is as read in the docs on 24 and 25 October 2026. If your interview uses a newer version, say which version you last read.

Diagram

The order of a strong answer

Diagram: Five numbered steps run in a line: name the failure, name the cheapest fix, price the tune against it, say how you will know, and say how...

1 Name the failure

2 Name the cheapest fix

3 Price the tune against it

4 Say how you will know

5 Say how you keep it

Diagram summary: Five numbered steps run in a line: name the failure, name the cheapest fix, price the tune against it, say how you will know, and say how you keep it.

Every answer, from ninety seconds to forty minutes, follows these five moves in this order.

Worked example

The ninety-second opener, with its evidence

Provenance: Generated practice.

“I start by naming what failed. Stale or missing facts go to retrieval. Wrong behaviour goes to a stronger prompt and examples. Cost or latency goes to caching or a smaller model. A tune enters only if those fall short, and it has to beat the best option I could ship, on the newest base model, on held-out data. Then I price it: one-off cost over the daily saving after hosting, tested against the cheapest alternative. If it still pays, I begin with a small LoRA run, size memory and time from stated assumptions, gate the result with slices and base-versus-tuned suites, ship behind a canary with a rollback pointer, and re-decide when the base model changes.”

Number or claim you may sayWhere it comes from
16 bytes per parameter for Adam in mixed precisionThe ZeRO paper adds 2 bytes of weights, 2 of gradients and an optimiser multiplier of 12
About 6 operations per parameter per training tokenThe scaling-laws paper takes the backward pass as about twice the forward pass
A LoRA adapter starts as a no-opThe LoRA paper initialises one factor at random and the other at zero, so the update starts at zero

Sources1 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models2 Scaling Laws for Neural Language Models3 LoRA: Low-Rank Adaptation of Large Language Models

Compare

Match the failure to the cheapest fix

Provenance: Generated practice.

What is failingFirst thing to tryWhat a tune would still cost
The answer needs facts that change weeklyRetrieval or a tool callRetraining every time the facts move
The format or tone is offA sharper prompt with examplesData, a run, a gate and upkeep
The bill or latency is too highPrompt caching, a smaller modelA project that must beat the cached baseline
A narrow skill fails at high volume after promptingA small LoRA runThe full program, from baseline to rollback

This table is course advice. Say the row that fits your case, then the cost in the last column.

Check yourself

Check: critique this opener

Provenance: Generated practice.

A candidate answers: “Fine-tuning is the professional approach and LoRA makes it cheap, so I would fine-tune the biggest model we can afford and measure afterwards.” Using the five-move order, what is missing, and how would you repair the first two sentences?

Answer

It starts at the method. There is no failure named (move 1), no cheaper fix considered (move 2), no price against a baseline (move 3), and measuring afterwards leaves no way to know (move 4). A repair: “First I would ask what is failing: missing facts, wrong behaviour or cost. I would measure the best prompt with caching on, and only if a gap remains would I price a small LoRA run against it.”

Worked example

Worked: one project, two baselines

Provenance: Generated practice.

Illustrative: a tune costs $9,000 once and adds $150 a day to host. It would cut the daily model bill from $720 to $240. Prompt caching alone, with no project, would cut the bill to $400.

Compared withDaily saving after hostingDays to break even
Today’s uncached bill720−(240+150)=330720 - (240 + 150) = 3309000/330=27.39000 / 330 = 27.3
Caching alone400−(240+150)=10400 - (240 + 150) = 109000/10=9009000 / 10 = 900

The same project looks like a month’s payback against the wrong baseline and a multi-year payback against the right one. Always quote the second row.

Check yourself

Check: how long until it pays for itself?

Provenance: Generated practice.

A tune costs $15,000 once. The tuned setup costs $210 a day for the model plus $200 a day to host. Caching alone would give a bill of $520 a day. How many days to break even against caching, and what would you add to the cost side before presenting the number?

Answer

The tuned total is 210+200=410210 + 200 = 410 a day, so the saving is 520−410=110520 - 410 = 110 a day and the break-even is 15000/11015000 / 110, about 136 days. Add what the table omits: evaluation, labelling upkeep, and a re-tune when the base model changes. That is about 4.5 months of payback, so a new base model arriving a few months after launch could force a re-tune before the project has repaid.

Math

The memory formulas

full fine-tuning=16P bytes\text{full fine-tuning} = 16P\ \text{bytes}LoRA=2P+16A bytes\text{LoRA} = 2P + 16A\ \text{bytes}QLoRA=0.5P+16A+0.127P8 bytes\text{QLoRA} = 0.5P + 16A + \frac{0.127P}{8}\ \text{bytes}ZeRO per GPU (stages 0 to 3)=16P ∣ 4P+12PN ∣ 2P+14PN ∣ 16PN\text{ZeRO per GPU (stages 0 to 3)} = 16P \ \big|\ 4P + \frac{12P}{N} \ \big|\ 2P + \frac{14P}{N} \ \big|\ \frac{16P}{N}adapter size A=∑r×(din+dout) over every adapted matrix\text{adapter size } A = \sum r \times (d_{\text{in}} + d_{\text{out}}) \text{ over every adapted matrix}
SymbolMeaning
PPParameters in the base model
AATrainable adapter parameters; 16 bytes covers weights, gradients and Adam terms
NNNumber of GPUs sharing the states
0.1270.127Bits per parameter left for quantisation constants after double quantisation, as the QLoRA paper computes for its block size

The memory formulas are floors: activations, the logits tensor and framework overhead come on top. The adapter size AA is the exact trainable-parameter count, while the bytes it costs sit inside a floor like the rest.

Sources1 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models4 QLoRA: Efficient Finetuning of Quantized LLMs3 LoRA: Low-Rank Adaptation of Large Language Models

Worked example

Worked: full fine-tuning states

Provenance: Generated practice.

ModelArithmeticStates
1.5B16×1.516 \times 1.524 GB
13B16×1316 \times 13208 GB
70B16×7016 \times 701,120 GB

The ZeRO paper states the same 24 GB minimum for its 1.5B-parameter example. At 80 GB a card, the 70B states alone need 14 cards (1120/801120 / 80), before activations or communication buffers. Say that omission out loud.

Source1 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models

Worked example

Worked: adapter parameters when shapes differ

Provenance: Generated practice.

A made-up decoder: hidden size 2,048, 16 layers, rank 32, adapters on the four attention projections. The query and output projections are 2,048 by 2,048; the key and value projections map 2,048 down to 512.

Matrixr×(din+dout)r \times (d_{\text{in}} + d_{\text{out}})Parameters
Query32×(2048+2048)32 \times (2048 + 2048)131,072
Output32×(2048+2048)32 \times (2048 + 2048)131,072
Key32×(2048+512)32 \times (2048 + 512)81,920
Value32×(2048+512)32 \times (2048 + 512)81,920
One layersum425,984
16 layers425984×16425984 \times 166,815,744

The frozen attention weights hold 16×(2×20482+2×2048×512)=167,772,16016 \times (2 \times 2048^{2} + 2 \times 2048 \times 512) = 167{,}772{,}160 parameters, so the adapter is about 4.06 percent of them. Its training states at 16 bytes each are about 0.109 GB.

Source3 LoRA: Low-Rank Adaptation of Large Language Models

Check yourself

Check: pick the rank from a budget

Provenance: Generated practice.

A decoder has hidden size 4,096 and 32 layers, with adapters on four square attention projections per layer. You want at most 20 million trainable parameters. What is the largest whole rank, which power-of-two rank would you actually use, and what are the adapter’s training states at that rank?

Answer

Each unit of rank costs 4×(4096+4096)×32=1,048,5764 \times (4096 + 4096) \times 32 = 1{,}048{,}576 parameters, so the budget allows 20000000/1048576=19.0720000000 / 1048576 = 19.07, a largest whole rank of 19. Rank 16 is the power-of-two choice: 16,777,216 parameters, and at 16 bytes each about 0.268 GB of states.

Worked example

Worked: QLoRA states

Provenance: Generated practice.

A 13B base in 4 bits with an adapter of 1 percent of the base (0.13B parameters).

PartArithmeticGB
4-bit base0.5×130.5 \times 136.50
Adapter states0.13×160.13 \times 162.08
Quantisation constants13×0.127/813 \times 0.127 / 80.21
Floorsum8.79

The QLoRA paper describes dequantising each weight tensor to BFloat16 before the matrix multiply, so activations and the logits tensor keep 16-bit sizes. That is why 8.79 GB is a floor and not a prediction.

Source4 QLoRA: Efficient Finetuning of Quantized LLMs

Check yourself

Check: how big a base fits?

Provenance: Generated practice.

A team has a 24 GB card and reserves 4 GB for activations and overhead. The adapter is 0.5 percent of the base. Using the QLoRA formula, what is the largest base, in billions of parameters, whose states fit the remaining 20 GB?

Answer

Per billion parameters the states cost 0.5+0.127/8+0.005×16=0.5960.5 + 0.127 / 8 + 0.005 \times 16 = 0.596 GB. Dividing, 20/0.59620 / 0.596 is about 33.6, so about 33 billion parameters is the ceiling under these assumptions. The reserve is a guess: a long sequence or a large batch can need more than 4 GB, which lowers the ceiling.

Worked example

Worked: ZeRO stages for 13B on 8 GPUs

Provenance: Generated practice.

StageFormulaPer GPU
Plain data parallel16×1316 \times 13208 GB
ZeRO-14×13+12×13/84 \times 13 + 12 \times 13 / 871.5 GB
ZeRO-22×13+14×13/82 \times 13 + 14 \times 13 / 848.75 GB
ZeRO-316×13/816 \times 13 / 826 GB

On 48 GB cards only stage 3 fits, and stage 2 misses by 0.75 GB before any activations. The paper reports that stages 1 and 2 keep the communication volume of data parallelism, while stage 3 adds about 50 percent.

Source1 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models

Check yourself

Check: when no stage is enough

Provenance: Generated practice.

A 7B model is fully tuned on 4 GPUs of 24 GB. Compute the per-GPU states for stages 0 to 3. Does any stage fit, and what are your two next moves?

Answer

Stage 0 is 112 GB, stage 1 is 4×7+12×7/4=494 \times 7 + 12 \times 7 / 4 = 49 GB, stage 2 is 2×7+14×7/4=38.52 \times 7 + 14 \times 7 / 4 = 38.5 GB, and stage 3 is 16×7/4=2816 \times 7 / 4 = 28 GB. None fits 24 GB, and these are floors. Moves: add GPUs (at 8 GPUs stage 3 needs 14 GB, but that leaves about 10 GB of a 24 GB card for activations and overhead) or switch to LoRA or QLoRA, which shrink the states at the source.

Math

Training time from first principles

full fine-tuning: FLOPs=6ND\text{full fine-tuning: } \text{FLOPs} = 6NDLoRA: FLOPs=4ND\text{LoRA: } \text{FLOPs} = 4NDtime=FLOPssustained rate\text{time} = \frac{\text{FLOPs}}{\text{sustained rate}}
SymbolMeaning
NNModel parameters
DDTraining tokens, summed over epochs
sustained rate\text{sustained rate}FLOP/s the hardware really delivers, always below peak; an assumption you state

The scaling-laws paper takes the backward pass as about twice the forward pass, which gives 2N + 4N per token. A course derivation, not a measurement, splits the backward 4N into 2N for input gradients and 2N for weight gradients. Frozen layers still need input gradients, so LoRA saves only the weight-gradient part and keeps 4N.

Both counts are floors. Activation checkpointing recomputes the forward pass during the backward pass, which in a course derivation adds about one more forward pass, 2N per token, giving about 8ND for full tuning and 6ND for LoRA. The TRL documentation (main branch, read 25 October 2026) shows SFTConfig and DPOConfig defaulting gradient_checkpointing to True, so a default run may pay that extra pass. Check your installed version.

Sources2 Scaling Laws for Neural Language Models5 SFT Trainer (TRL documentation)6 DPO Trainer (TRL documentation)

Worked example

Worked: a 7B run

Provenance: Generated practice.

A 7B model, 120 million tokens per epoch, 2 epochs, one GPU sustaining 250 TFLOP/s.

StepArithmeticResult
Tokens DD120×106×2120 \times 10^{6} \times 2240×106240 \times 10^{6}
Full FLOPs6×7×109×240×1066 \times 7 \times 10^{9} \times 240 \times 10^{6}1.008×10191.008 \times 10^{19}
Full time1.008×1019/(250×1012)1.008 \times 10^{19} / (250 \times 10^{12})40,320 s, 11.2 h
LoRA FLOPs4×7×109×240×1064 \times 7 \times 10^{9} \times 240 \times 10^{6}6.72×10186.72 \times 10^{18}
LoRA time6.72×1018/(250×1012)6.72 \times 10^{18} / (250 \times 10^{12})26,880 s, 7.47 h

State what the figure ignores: any recompute from activation checkpointing, and that the 112 GB of full-tuning states cannot sit on one card, so the real run needs several GPUs and loses some efficiency to communication.

Check yourself

Check: run the formula backwards

Provenance: Generated practice.

You have a 6-hour LoRA budget on an 8B model, with a GPU sustaining 300 TFLOP/s. How many training tokens can you process, and what dataset size does that allow at 3 epochs?

Answer

The budget is 6×3600×300×1012=6.48×10186 \times 3600 \times 300 \times 10^{12} = 6.48 \times 10^{18} FLOPs. LoRA costs 4×8×109=3.2×10104 \times 8 \times 10^{9} = 3.2 \times 10^{10} FLOPs per token, so D=6.48×1018/(3.2×1010)=202.5D = 6.48 \times 10^{18} / (3.2 \times 10^{10}) = 202.5 million tokens. At 3 epochs that is a dataset of 67.5 million tokens. This is an upper bound: lost efficiency and evaluation time reduce it.

Worked example

Worked: a DPO loss, two betas

Provenance: Generated practice.

The loss is −ln⁡σ(β×(preferred log-ratio−rejected log-ratio))-\ln \sigma(\beta \times (\text{preferred log-ratio} - \text{rejected log-ratio})). Illustrative: preferred +1.5, rejected -0.5.

betaMarginsigmoid(margin)Loss
0.10.20.5500.598
0.71.40.8020.220

A larger beta makes the same movement look more finished, so the pair stops pulling sooner. The loss uses only the difference of the two log-ratios: preferred -0.2 and rejected -2.2 also give a margin of 0.2 at beta 0.1, and the same loss of 0.598.

Source7 Direct Preference Optimization: Your Language Model is Secretly a Reward Model

Check yourself

Check: which pair has the lower loss?

Provenance: Generated practice.

At beta 0.3, pair X has a preferred log-ratio of +0.5 and a rejected log-ratio of -0.5. Pair Y has -1.0 and -2.5. Compute both losses. What does the comparison say about trusting the loss alone?

Answer

X has a margin of 0.3×1.0=0.30.3 \times 1.0 = 0.3 and a loss of 0.554. Y has a margin of 0.3×1.5=0.450.3 \times 1.5 = 0.45 and a loss of 0.493, so Y scores better even though its preferred answer became less likely than under the reference. A falling loss does not prove good answers are becoming more probable, so also log the absolute likelihood of the preferred answers.

Source7 Direct Preference Optimization: Your Language Model is Secretly a Reward Model

Code

The estimators as code

Python

import math


def _positive(x):
    return (isinstance(x, (int, float)) and not isinstance(x, bool)
            and math.isfinite(x) and x > 0)


def _whole(x, minimum=1):
    return isinstance(x, int) and not isinstance(x, bool) and x >= minimum


def lora_params(rank, shapes):
    if not _whole(rank):
        raise ValueError("rank must be a whole number, at least 1")
    if not shapes or not all(len(s) == 2 and all(_whole(d) for d in s) for s in shapes):
        raise ValueError("need (d_in, d_out) pairs of positive whole numbers")
    return sum(rank * (d_in + d_out) for d_in, d_out in shapes)


def zero_gb(params_b, n_gpus, stage):
    if not _positive(params_b) or not _whole(n_gpus):
        raise ValueError("parameters must be positive and GPUs a whole number")
    if not _whole(stage, 0) or stage > 3:
        raise ValueError("stage must be 0, 1, 2 or 3")
    p, n = params_b, n_gpus
    if stage == 0:
        return 16 * p
    if stage == 1:
        return 4 * p + 12 * p / n
    if stage == 2:
        return 2 * p + 14 * p / n
    return 16 * p / n


def train_hours(params_b, tokens_m, tflops, lora=False):
    if not all(_positive(v) for v in (params_b, tokens_m, tflops)):
        raise ValueError("all inputs must be positive, finite numbers")
    flops = (4 if lora else 6) * params_b * 1e9 * tokens_m * 1e6
    return flops / (tflops * 1e12) / 3600
Test (Python 3.14.6, standard library only, 25 October 2026)Result
Rank 32, shapes of the adapter slide, times 16 layers6,815,744
zero_gb(13, 8, s) for stages 0 to 3208, 71.5, 48.75, 26.0
zero_gb(7, 4, s) for stages 0 to 3112, 49.0, 38.5, 28.0
train_hours(7, 240, 250) full, then LoRA11.2, 7.47
27 bad inputs: rank 0, 2.5 or True; an empty shape list; a negative, NaN, fractional or True dimension; a three-number shape; stage 4, 1.0 or True; zero, fractional or True GPUs; zero, negative, NaN, infinite or True parameters, tokens or rateall 27 raise ValueError as intended

Memory inputs are billions of parameters and the result is decimal GB; token inputs are millions.

Sources1 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models3 LoRA: Low-Rank Adaptation of Large Language Models2 Scaling Laws for Neural Language Models

Process

A forty-minute design answer, in order

Provenance: Common industry pattern.

  1. Clarify: success metrics, constraints such as personal data, acceptable regression, timeline, who maintains it.
  2. Baseline first: the best prompt with examples, caching on, priced.
  3. Data: label noise, personal data, deduplication, a group split, a golden set with slices.
  4. Method and training plan: LoRA first; memory and time with assumptions stated.
  5. Gate: ladder, interval, slices, regression and safety suites versus the base, pass rules written first.
  6. Rollout and upkeep: shadow, canary, rollback pointer, re-tune triggers.
  7. Alternatives and fallback: what you would do if the tune fails the gate.

A rough split (course advice) is 4 minutes on step 1, 5 on step 2, 6 on step 3, 6 on step 4, 6 on step 5, 6 on step 6, and 7 on step 7 with questions.

Worked example

Worked: do the arithmetic before the method

Provenance: Generated practice.

Prompt (all figures invented). An insurer receives 1.2 million claim emails a month. A large API model with a 700-token fixed prompt sorts each into one of 14 categories and drafts a reply. The team has 25,000 labelled emails, strict personal-data rules and one platform engineer. Should they fine-tune?

StepArithmeticResult
Emails per day (30-day month)1,200,000/301{,}200{,}000 / 3040,000
Fixed-prefix tokens per day40,000×70040{,}000 \times 70028 million
Prefix cost at an assumed $1 per million28×128 \times 1$28 a day
With cached input billed at an assumed 10 percent28×0.128 \times 0.1$2.80 a day

Uncached, the fixed prefix alone is about $10,000 a year (28×36528 \times 365), a small line next to a team. The email body and the drafted reply add tokens that this table does not price, so measure those before drawing a cost conclusion. The case, if any, must rest on quality, tone or latency that a better prompt cannot reach, and on the data being clean. Say that before naming LoRA.

Source8 Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To!

Diagram

The decision flow behind the answer

Diagram: The answer branches early.

no

yes

Clarify goals

Best prompt, caching on

Gap left?

Stop: ship the prompt

Data, gate, LoRA run

Canary, rollback

Upkeep, re-decide

Diagram summary: The answer branches early. If the best prompt with caching leaves no gap, stop and ship it. Only a remaining gap leads to data work, a gated LoRA run, a canary with a rollback pointer, and upkeep that re-decides when the base model changes.

Check yourself

Check: find the gaps in this outline

Provenance: Generated practice.

A candidate outlines: “Take the 25,000 labelled emails, run LoRA on the largest model that fits, and ship it if its accuracy beats the current system.” Name the three most serious gaps in priority order and the first sentence you would say to repair the outline.

Answer

First, no baseline: the current system is not the best prompt with caching on, so the comparison is too easy. Second, no gate beyond an average: no held-out split by thread or customer, slices, interval, or base-versus-tuned regression and safety suites. Third, no rollout or upkeep: no canary, rollback pointer or re-decision when the base changes. Repair opener: “Before any training I would price the best prompt with caching on, and set the pass rules for the gate.”

Compare

Symptoms, causes in order, first check

Provenance: Generated practice.

SymptomCauses to walk throughFirst check
Loss stays near its starting valueLabels masked out, nothing reaches the model, learning rate far too lowCount unmasked label tokens in a decoded batch
Held-out loss rises from epoch 2 while training loss fallsOverfitting, duplicate rows, too many epochsDuplicate overlap, then the best held-out checkpoint
One language or customer is far worse than the averageSlice hidden by the average, thin data for that sliceA slice report against the baseline
Fewer refusals of harmful prompts, though the data was harmlessSafety erosion from tuningThe safety suite on the tuned model versus the base
Replies stop mid-sentenceLength cap, end token missing from targetsDecode the end of a batch and read the length setting

The TRL documentation says assistant_only_loss needs a chat template with generation markers (it patches the template itself for known families such as Qwen3), and that the end token must match the template so replies terminate. The causes in the table are course judgement.

Sources5 SFT Trainer (TRL documentation)8 Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To!

Diagram

Name the symptom, then the first check

Diagram: First decide where the problem shows.

training run

evaluation

Where does it show?

Curve odd or replies cut

Group or safety result

Count unmasked tokens, decode batch end

Slice report, base vs tuned suites

Diagram summary: First decide where the problem shows. In the training run, an odd loss curve or cut-off replies point to counting unmasked label tokens and decoding the end of a batch; in evaluation, one group doing worse or refusals falling point to a slice report and the base-versus-tuned suites.

Check yourself

Check: three epochs, one good checkpoint

Provenance: Generated practice.

Held-out accuracy was 0.84 after epoch 1 and 0.81 after epoch 3, while training loss kept falling. A scan finds that about 11 percent of the rows are near-duplicates of each other. Name the likely causes in order, the first check, and two fixes.

Answer

Overfitting helped by duplicates is first. The first check is whether duplicated rows fall on both sides of the split, because duplicates also inflate the early score. Fixes: deduplicate and re-split by group, then keep the epoch-1 checkpoint or lower the epoch count or adapter rank. Re-run the base-versus-tuned suites on whichever checkpoint is kept.

Source5 SFT Trainer (TRL documentation)

Compare

Rapid-fire answers (about twenty seconds each)

Provenance: Generated practice.

QuestionShort answer
Why 16 bytes a parameter, not 2?Gradients add 2, and Adam keeps an fp32 copy of the weights plus two moment estimates, 12 bytes
What do you add when you quote a memory floor?Activations, logits and framework overhead
Why does a LoRA adapter start as a no-op?One factor is zero, so the weight update begins at zero and the model equals the base
What does QLoRA do before a matrix multiply?Dequantises the stored 4-bit weight tensor to BFloat16
What does ZeRO-3 cost besides code?About 50 percent more communication than data parallelism, per the paper
What does 6ND count?About 2 operations per parameter-token forward and 4 backward
What does a bigger DPO beta do?The loss saturates sooner, so the model stays nearer the reference
What do you say about a library default?The version you last read, and that it should be re-checked

Sources1 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models3 LoRA: Low-Rank Adaptation of Large Language Models4 QLoRA: Efficient Finetuning of Quantized LLMs2 Scaling Laws for Neural Language Models

Compare

A 45-minute mock plan

Provenance: Generated practice.

MinutesPartPrompt idea
0 to 5Warm-up“Tune or retrieve for our internal docs assistant?”
5 to 15DepthA LoRA config to size, then “where does QLoRA’s memory go?”
15 to 22Debug“The tuned model regressed on general tasks.”
22 to 28Alignment“DPO, RLHF or GRPO for a maths tutor?”
28 to 43DesignA program design, with the interviewer probing data, gate, rollback and cost
43 to 45Close“Three biggest risks, and what do you measure first?”

The interviewer does not teach during the mock. Afterwards, note the two places you lost the thread and repeat those drills on a nearby variant a few days later.

Summary

Summary

  • Open with the failure, the cheapest fix, the price against the right baseline, the proof and the upkeep. Quote break-even against caching, not against the uncached bill.
  • Memory: 16P full, 2P + 16A LoRA, about 0.5P + 16A plus constants for QLoRA, and four ZeRO formulas. All are floors.
  • Adapter size is r×(din+dout)r \times (d_{\text{in}} + d_{\text{out}}) per matrix, so check each matrix’s real shape.
  • Time is 6ND over a sustained rate, with LoRA at 4ND; both are floors. Run it backwards to size a budget.
  • The DPO loss depends on the difference of two log-ratios scaled by beta.
  • Design in order, and diagnose by naming causes in order with the first check.

References

References & Sources (1 of 2)

  1. ZeRO: Memory Optimizations Toward Training Trillion Parameter Models (opens in a new tab)

    Samyam Rajbhandari, Jeff Rasley, Olatunji Ruwase, Yuxiong He2019Preprint

    Used for The 2P + 2P + KP memory accounting with K = 12 for mixed-precision Adam, the 24 GB example for 1.5B parameters, the ZeRO stage formulas, and the 1.5 times communication of stage 3.

  2. Scaling Laws for Neural Language Models (opens in a new tab)

    Jared Kaplan, Sam McCandlish, Tom Henighan, Tom B. Brown, et al.2020Preprint

    Used for Training compute of about 6N operations per token, with the backward pass about twice the forward pass.

  3. LoRA: Low-Rank Adaptation of Large Language Models (opens in a new tab)

    Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, et al.2022ICLR 2022Paper

    Used for The low-rank update with one factor random and the other zero, so the update starts at zero.

  4. QLoRA: Efficient Finetuning of Quantized LLMs (opens in a new tab)

    Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, Luke Zettlemoyer2023NeurIPS 2023Paper

    Used for 4-bit storage with dequantisation to BFloat16 for the multiply, and 0.127 bits per parameter of constants after double quantisation.

  5. SFT Trainer (TRL documentation) (opens in a new tab)

    Hugging Face2026Documentation

    Used for Read on 25 October 2026: assistant_only_loss needs a chat template with generation markers (TRL patches the template itself for known families such as Qwen3), the end token must be aligned with the chat template, and SFTConfig defaults gradient_checkpointing to True.

References

References & Sources (2 of 2)

  1. DPO Trainer (TRL documentation) (opens in a new tab)

    Hugging Face2026Documentation

    Used for Read on 25 October 2026 (main-branch docs): DPOConfig defaults gradient_checkpointing to True, as SFTConfig does.

  2. Direct Preference Optimization: Your Language Model is Secretly a Reward Model (opens in a new tab)

    Rafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D. Manning, et al.2023NeurIPS 2023Paper

    Used for The DPO loss as a sigmoid of beta times the difference of two log-ratios against a reference.

  3. Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To! (opens in a new tab)

    Xiangyu Qi, Yi Zeng, Tinghao Xie, Pin-Yu Chen, et al.2024ICLR 2024Paper

    Used for Fine-tuning can degrade safety alignment, including with benign datasets.