Unit 10 of 10 · about 5 hours · measure

Quality, memory, latency and update-cost comparison, and model merging

A training-memory saving is not a serving-speed result. The final choice must meet quality and retention constraints while accounting for every update and inference cost.

You'll be able to

  • Compare prompted, smaller-model, full-update and low-rank or distilled candidates under a fixed evaluator and inference budget.
  • Separate training memory, serving memory, latency, throughput and total update cost in a decision table.
  • Explain task vectors and test a small common-base merge without assuming capability composition.

Covers

Quality, train memory, latency, serving memory and update-cost comparisonModel merging and task-vector vocabulary
1

Read

In this order, only the parts listed

0 of 2 done

  1. LoRA Without Regret: matched comparisons and compute accountingLoRA Without Regret

    What matters for LoRA; Methods and results, with its subsections LoRA rank and Batch size effects; Layers Where LoRA Is Applied; and Compute efficiency advantage of LoRA under Discussion

    Read the curves as log-loss evidence under the article's settings, not sampled task scores or universal hyperparameters. The roughly two-thirds FLOP ratio is an analytical matrix-operation estimate, not measured wall time. Headings checked 2026-10-16.

  2. Modern LLM Notebook 16: model-merging vocabularyModern LLM Notebook - LoRA, Distillation and OPD

    Section 11, Model Merging; Mainstream Merging Methods, Task Arithmetic code block

    Optional topic: stop after the common-base task-vector formula. Skip the mergekit installation and 7B recipe. Treat the method table as vocabulary, not evidence that a method is best for a given pair.

2

Focus on

  • Hold evaluation prompts, scoring, decoding, maximum generated tokens and batch policy fixed. Report target and retention slices with uncertainty or paired per-example changes. Give each training method its own small declared learning-rate search; also report total search cost and matched-token comparisons.
  • Measure peak allocated and reserved training memory separately from steady serving memory, optimizer state and saved artifact bytes. Record hardware, library and checkpoint revisions, precision, context, batch and cache policy. Include warmup and synchronization in timings, but exclude them from measured repetitions. On CPU, report process memory and elapsed time rather than invented CUDA measurements.
  • Separate prefill, decode, time to first token, end-to-end latency and throughput. Measure merged and unmerged adapters separately. Include teacher generation/scoring, filtering, student rollouts, retries and evaluation in update cost. Use CPU toy models when the full comparison does not fit; label those results mechanism evidence, not production rankings.
  • A task vector is ; task arithmetic forms . Require a common base revision, matching tensors and tokenizer semantics. This differs from exactly folding one LoRA branch into its base. Select coefficients on validation data and test target and retention regressions.
Common mistakes · 3
  • Reporting fewer trainable parameters as an equal-factor speedup. Frozen layers still run forward and usually propagate input gradients; attention, activation storage and kernel overhead remain.
  • Comparing methods with different generated lengths or batch sizes and calling the result a latency win. Report both controlled-budget measurements and any separate production-policy experiment.
  • Averaging LoRA factors instead of their effective weight updates. The product of averaged factors introduces cross terms and need not equal the average update; quantized merges also need numerical and task regression checks.
3

Try it yourself

Closed-book, before checking anything

Make the section mini-project's decision table using a CPU toy run or one consumer GPU. Mark unmeasured candidates explicitly. First check a synthetic cost ledger: an extra 3,600 seconds of one-time update work and 0.02 seconds saved per request break even at 180,000 requests, assuming equal quality, hardware cost per second and all other costs. This is arithmetic, not a benchmark. For the optional merge check, use base vector and adapted vectors and . Coefficients 0.5 and 0.25 yield merged vector . Verify zero coefficients recover the base and one unit coefficient recovers that adapted vector; then evaluate rather than infer skill composition.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Does an exactly merged ordinary LoRA adapter make the dense model smaller?Answer

    No. It removes the extra inference branch, not the base weight tensor. Saving adapter files alone is a different storage and deployment choice.

  2. 2.Can the smallest training-memory method have the worst serving latency?Answer

    Yes. Training state, inference kernels, quantization, extra branches, prefix length and generated length affect different costs. Measure the actual deployment form.

  3. 3.When does the synthetic break-even calculation stop being useful?Answer

    When per-request savings are nonpositive, quality differs, updates recur, hardware costs differ or omitted teacher and deployment costs matter. Recompute with the actual workload and constraints.

  4. 4.Does task-vector addition prove the merged model has both source skills?Answer

    No. Tensor compatibility makes the arithmetic defined, not the behaviors compositional. Conflicting updates can harm either skill or retention, so use held-out evaluations.

You're done when

The section mini-project's comparison names a preferred intervention under explicit quality, retention, memory and latency constraints, includes prompted and no-training controls, and separates measurements from estimates. The optional merge arithmetic must pass before any behavioral merge claim.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 17 more in the section
  • LoRA Without RegretThinking Machines Lab · support

    Read "What matters", the rank, batch-size and layer results, and "Setting LoRA hyperparameters": all-layer LoRA at high rank matches full fine-tuning loss, the best LoRA learning rate is about ten times higher, and large batches hurt LoRA more. The curves are log loss, not sampled evaluations.

  • Modern LLM Notebook - LoRA, Distillation and OPDWalking Labs · support

    Use notebooks-en/part2-training/16-lora.ipynb, 17-distillation.ipynb and notebooks-en/part4-frontiers/31-opd.ipynb for compact implementations. Derive the objectives from MiniLLM and GKD rather than the notebooks, and scale the 7B distillation example down.

Also in this section

  • RLHF Book - Training Overview, Instruction Tuning and Synthetic DataNathan Lambert · primary

    Read Chapter 3 (training overview and canonical recipes; no exercises), Chapter 4 (instruction tuning, 04-instruction-tuning.html) and Chapter 12 (synthetic data and distillation, 12-synthetic-data.html). Do the Suggested Experiments in Chapters 4 and 12 at a scale that fits your GPU. Use the recipe maps to separate continued pretraining, SFT, rejection sampling and distillation before selecting an intervention.

  • CS336 Assignment 5 Supplement - SFTStanford University · required

    Do supplement Sections 3 and 4: zero-shot baselines, look_at_sft, get_packed_sft_dataset and the SFT script, with the data tests passing on CPU. The handout fine-tunes Llama 3.1 8B on B200s and judges with a 70B model; use a small open model that fits your GPU and rule-based scoring on fixed MMLU and GSM8K subsets, and keep the evaluation identical before and after.

  • LoRA: Low-Rank Adaptation of Large Language ModelsMicrosoft Research · required

    Read Section 4 and Figure 1 (Section 3 explains why adapters add latency): derive the low-rank update, the alpha over r scale, the zero initialization of B and the parameter count, then implement LoRA for selected decoder linear layers and test that the merged weights reproduce the adapter output. The paper adapts attention only; later work finds the MLP layers matter.

  • LoRA Learns Less and Forgets Less (Biderman et al., 2024)Columbia University and Databricks · required

    Read Section 3 and Sections 4.1 to 4.7 with Figures 2 to 4: on code and math, full fine-tuning learns more of the target and forgets more of the source, and LoRA rank controls the trade-off. Slice forgetting on your own evaluations.

  • QLoRA: Efficient Finetuning of Quantized LLMsUniversity of Washington · reference

    Read the method and memory-analysis sections only after plain LoRA passes. Use it to explain quantized-base adaptation and its numerical assumptions, not as a mandatory large training run.

  • Distilling the Knowledge in a Neural Network (Hinton et al., 2015)Google · reference

    Read Sections 1 and 2 for the temperature-softened softmax and the mix of soft and hard targets that later distillation methods reuse.

  • Hugging Face LLM Course Chapter 11 and smol-course Unit 1Hugging Face · support

    Work through 11.2 (chat templates), 11.3 (SFT with TRL) and 11.4 (LoRA with PEFT) on SmolLM2-135M, then smol-course Unit 1 for an SFT, LoRA and evaluation loop. TRL 1.15.0 trains on the whole sequence unless you set assistant_only_loss=True, and the template must expose assistant spans for that to work.

  • MiniLLM: Knowledge Distillation of Large Language Models (Gu et al., 2024)Tsinghua and Microsoft Research · support

    Read Section 2.1 (reverse KL from student to teacher, and why it is mode-seeking) and Section 2.2 (the on-policy gradient and its stabilizers). It needs white-box teacher log probabilities.

  • On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes (Agarwal et al., 2024)Google DeepMind · support

    Read Sections 3 and 4 with Algorithm 1: the student-data fraction lambda mixes fixed data with student samples, and the divergence is a choice. Budget the extra student rollouts and teacher scoring per step.

  • On-Policy DistillationThinking Machines Lab · support

    Read the loss (per-token reverse KL on student samples), the pseudocode and the reasoning and personalization results. Teacher and student share a tokenizer and lineage there; the FLOP ratios are estimates.

  • Tulu 3, Sections 3 and 4 (data and supervised fine-tuning)Allen Institute for AI · support

    Read Section 3 (prompt curation and decontamination) and Section 4 (the SFT mix, data experiments and recipe) as an auditable data contract to imitate at small scale, not a scale to reproduce.

  • Don't Stop Pretraining: Adapt Language Models to Domains and Tasks (Gururangan et al., 2020)Allen Institute for AI · support

    Read Sections 3 and 4: domain-adaptive and task-adaptive continued pretraining before fine-tuning. Compare continued pretraining with SFT at matched tokens and a fixed evaluator.

  • Build a Large Language Model (From Scratch), Chapter 7 and Appendix ESebastian Raschka / Manning · support

    Use Chapter 7 (SFT, pp. 204-249) and Appendix E (LoRA, pp. 322-336) for the smallest full SFT and LoRA run. The chapter trains on instructions too by default; Exercise 7.2 (p. 223) is the masked variant, and there is no packing.

  • Build a Reasoning Model (From Scratch), Chapter 8Sebastian Raschka / Manning · support

    Use Chapter 8 (pp. 267-304: generating and filtering a distillation set, losses, training loop and evaluation) as a runnable 0.6B sequence-distillation baseline with provenance.

  • TensorTonic - Assistant-Only SFT Loss MaskTensorTonic · support

    Solve Build an Assistant-Only SFT Loss Mask (cs336-l15-assistant-only-sft-mask). It takes role ids, so add your own tests for chat-template parsing, multi-turn roles, truncation, packed examples and special-token boundaries. Public test cases check the listed edge cases, not gradients or the hidden grader, so keep your own tests beside each solution.

  • RLHF Book Code - Instruction Tuning and DistillationNathan Lambert · support

    Read instruction_tuning/train.py and utils.py (it masks all but the final assistant turn) and distillation/loss.py. The default configs use 1B to 1.7B models and long contexts; cut the model, context and sample count to fit your GPU, hold the data and evaluator fixed, sweep one variable and compare with a no-distillation baseline.

  • PEFT conceptual guide: Soft promptsHugging Face · reference

    Read Prompt tuning and Prefix tuning only (page read 2026-10-16). These supply the optional soft-prompt mechanisms missing from the section pool; no extra training run is required.