Part XVII — LLM Post-Training: SFT, DPO, GRPO & Reasoning / Test-Time Compute · Chapter 11

Ship a tiny fine-tuned assistant

Hook

A trained model isn't a product. A product needs a cheap way to specialize it, a cheap way to steer it per request, and a cheap way to actually serve it. This part built exactly those three things, separately. Wire them together, and that's a shipped assistant.

Intuition

One backbone, fine-tuned once via LoRA (short for Low-Rank Adaptation). Two different system prompts, applied at request time with no retraining at all. The same underlying model, two different jobs.

Formalize

Three mechanisms, three chapters, one pipeline:

W+BALoRA backbone  fixed  y^(xq)=iwi(xq)yiprompted per request  served via  KV cachelinear, not quadratic, cost\underbrace{W + BA}_{\text{LoRA backbone}} \;\xrightarrow{\text{fixed}}\; \underbrace{\hat y(x_q) = \textstyle\sum_i w_i(x_q) y_i}_{\text{prompted per request}} \;\xrightarrow{\text{served via}}\; \underbrace{\text{KV cache}}_{\text{linear, not quadratic, cost}}
  • WW — the frozen pretrained backbone weight matrix.
  • BB, AA — the LoRA low-rank factors whose product forms the fine-tuning update to WW.
  • y^(xq)\hat y(x_q) — the model's predicted output for a request's query xqx_q.
  • xqx_q — the query for a given request.
  • wi(xq)w_i(x_q) — the weight assigned to demonstration ii for this query, from the prompting mechanism.
  • yiy_i — the output demonstrated for example ii in the request's prompt.
  1. Fine-tune once, offline

    The backbone is fine-tuned exactly once, offline, via LoRA.

  2. Steer per request, with no retraining

    Every request reuses that same frozen backbone, steered only by whatever system prompt accompanies it.

  3. Serve cheaply, without shrinking the model

    Serving many such requests stays cheap because each individual generation reuses its own cached attention via a KV cache (short for Key-Value cache), not because the model got any smaller.

Play

Half the trainable parameters to reach the backbone. Two completely different behaviors from one frozen backbone, chosen purely by prompt. Fifty times less total serving work across a batch of requests. None of these three numbers depends on the other two — that's what makes them composable into one pipeline instead of one monolithic system.

Worked example

Fine-tune once, prompt per request, serve 50 requests of 100 tokens each:

  1. Fine-tune the backbone with LoRA, once

    The rank-1 update converges to loss 6.16×1031\approx6.16\times10^{-31} using 88 trainable parameters instead of 1616 — the exact result verified in this part's first chapter, unchanged here.

  2. Steer behavior per request with a system prompt

    The same frozen backbone, for a query of 2.52.5:

    • Prompted with "double" demonstrations, answers 4.534\approx4.534
    • Prompted with "negate" demonstrations instead, the identical backbone answers 2.267\approx-2.267

    No retraining, no change to a single weight.

  3. Serve both, cheaply

    5050 requests at 100100 tokens each cost:

    • 252,500252{,}500 units of attention work without a KV cache
    • Just 5,0005{,}000 with one

    A 50.5×50.5\times reduction, applied identically regardless of which prompt each request used.

Checkpoint

Find the system prompt that makes the shipped assistant answer with a negative number.

Pick a system prompt to try it
Summary
fine-tune once (LoRA)+steer per request (prompting)+serve cheaply (caching)=a shippable assistant\text{fine-tune once (LoRA)} + \text{steer per request (prompting)} + \text{serve cheaply (caching)} = \text{a shippable assistant}

None of these three mechanisms is new in this chapter — every number here was already verified, separately, in the three chapters that came before it. What's new is only the composition: a specialization step that happens once, a steering step that happens per request with no retraining, and a serving step that makes many such requests affordable. That gap — between a model that works in one demo and a model that can actually serve real traffic — is most of what "modern LLM engineering" means in practice. This closes Part XIII — Modern LLM Engineering, and with it, the full expansion of this course: forty-three chapters across reinforcement learning, classical ML, model evaluation, advanced architectures, explainability, multimodal systems, and the engineering that ships all of it.