Where to Intervene in a Pretrained Model
CMU DLSys Lecture 22: Customizing Pretrained Models
Training a specialized model from scratch for every downstream domain breaks down once the base model grows to billions of parameters. You cannot afford to collect a full pretraining corpus per task, nor store an independent multi-gigabyte weight checkpoint for every user workflow or output format.
CMU’s Fall 2026 Lecture 22 slides (Customizing Pretrained models, Tianqi Chen and Tim Dettmers; note that the course schedule links slides only and no public video recording) frame customization as an architectural choice: where along a frozen forward pass should adaptation attach? Across image generation and large language models (LLMs), all techniques in the lecture attach at one of three interfaces along a frozen forward pass: input and conditioning embeddings (CLIP conditioning or multimodal visual tokens), frozen backbone weights augmented with parallel branches (ControlNet or LoRA), or output logits (XGrammar and repetition penalties).

Why keep the backbone frozen
The standard supervised recipe fixes a hypothesis class , a multi-class cross-entropy loss , and a mini-batch update (slides, p. 4):
Collecting separate training data and training an isolated model per domain loses cross-domain knowledge (slides, p. 5). Pretraining reverses that flow: fit a single large backbone on broad data once, then adapt it cleanly to domain constraints (slides, pp. 5, 14). Even before adding new layers, prompts and context shape what an LLM produces without altering weights (slides, p. 15). When prompts alone are insufficient, each customization method trades expressiveness, step-0 stability, and serving cost differently.
Conditioning diffusion through aligned embeddings
In image generation, customization begins by injecting an external signal into the denoising predictor. CLIP (Radford et al.; slides, p. 6) trains a text encoder and an image encoder jointly over batches of paired captions and images, producing embeddings and in a shared vector space. Maximizing similarity along the matched diagonal pairs relative to off-diagonal mismatches aligns natural language with visual concepts so downstream generators can reuse text embeddings directly.
From Lecture 20, unconditional diffusion sampling integrates the reverse-time variance-preserving SDE (slides, p. 7):
where generation runs backward from prior noise to data with , is the noise schedule, is the forward noise scale, and supplies the score estimate (dW_t denotes the reverse-time Wiener increment on the slide). Adding a condition simply routes an embedding —such as a CLIP text embedding—into the noise predictor (slides, p. 8).
Because pixel-space denoising is expensive, Latent Diffusion Models (Rombach et al., CVPR 2022; slides, p. 9; paper) compress pixels through a perceptual encoder , run the denoising U-Net in latent space, inject conditioning tokens (text, semantic maps, representations, or images) via cross-attention (), and reconstruct pixels via .
Zero-initialized residual branches protect step-0 behavior
Prompt embeddings steer high-level semantics, yet they struggle to enforce pixel-aligned spatial structure like edge maps or body poses, and naive full fine-tuning risks erasing pretrained visual knowledge. Both ControlNet (slides, pp. 10–12) and LoRA (slides, p. 16) attach a parallel residual branch alongside locked weights so that, when the branch is initialized to zero, the step-0 output equals the untouched pretrained model.

ControlNet: locked copy plus zero convolutions
Slide 10 sketches ControlNet’s locked block alongside a trainable copy gated by two zero convolutions and notes: “Initialized as original model (due to zero weight convolution)” (Zhang, Rao, and Agrawala; slides, p. 10). In the notation of the cited paper—not printed symbolically on slide 10—locking , cloning a trainable copy , and inserting two zero-initialized convolutions and (both weights and biases initialized to ) yields
At step , both zero convolutions output , so identically. Even with sparse or noisy spatial conditions such as Canny edge maps or human pose skeletons (slides, p. 12), the trainable copy starts in an uncorrupted pretrained state. In Stable Diffusion (slides, p. 11), ControlNet duplicates the locked encoder blocks ( down to ) and the middle block, then injects zero-convolved residuals back into both the locked middle block and the U-Net decoder skip paths.
Why doesn’t zero initialization freeze learning forever? Tracing the author’s step-by-step backward derivation (not printed on slide 10), write the copy’s output as and the outer convolution at batch element and spatial position as with and upstream loss gradient . On the very first backward pass:
- Because , backpropagating through the outer convolution multiplies by , blocking gradients from reaching and at step .
- Meanwhile, the outer zero convolution itself receives a kernel gradient summed over batch and spatial positions:
Because enters the pretrained-initialized copy unchanged (), is typically nonzero at step ; whenever that sum across batch and space is nonzero, step updates away from , unlocking nonzero gradients for and on step . As a constructed scalar check (not a diffusion measurement), set with (), , , , and SGD step : at step , and , moving ; holding fixed on step , the inner zero convolution immediately receives .
LoRA: low-rank weight adaptation
For linear projections in LLMs and attention or diffusion blocks, slide 16 freezes the pretrained weight matrix and attaches two low-rank matrices and with (LoRA, Hu et al.):
using column-vector convention matching the forward diagram on slide 16 (noting that writing sets unit scaling or absorbs into a factor; in Hu et al.’s full convention, not printed on slide 16, with and Gaussian at initialization so at step ). Just like ControlNet in the author’s step-0 gradient check, zeroes at step while can update immediately and unlock on step . At deployment, a single customized model can merge weights offline into for zero added inference latency, whereas slide 14’s challenge of shipping domain variants motivates a multi-adapter serving design where frozen stays shared in GPU memory and small adapters swap per request.
For a constructed dimension and parameter check on a square projection with rank :
- Frozen base weights: parameters.
- Trainable LoRA weights: parameters— () of .
This reduction shrinks per-task checkpoint storage and trainable optimizer states directly, though activation memory during backpropagation still scales with sequence length and batch size; activation checkpointing can reduce the amount retained.
Multi-modality via embedding mapping
What if the model needs a new input modality—such as images inside an autoregressive text LLM—rather than a spatial condition inside diffusion? MiniGPT-4 (Zhu, Chen et al.) and LLaVA (Liu, Li et al.) project encoded image features into "visual tokens" that share the LLM’s embedding dimension and enter alongside text embeddings in the LLM input sequence (slides, p. 17). Once projected into that common token space, visual and text embeddings flow through the same transformer layers without changing the LLM’s text vocabulary.
Enforcing output syntax at logit time with XGrammar
Prompting and LoRA steer probabilities, not hard syntax guarantees. When an application requires strictly valid JSON or a typed schema (class Task(BaseModel): done: bool; name: str; steps: List[int]; slides, p. 19), disallowed tokens must be forced to probability zero after the LLM emits raw logits (slides, p. 18):
Applying softmax to (alongside optional repetition penalties, slides, p. 18) guarantees every sampled step respects the constraint without touching a single weight. Yet constrained decoding introduces three systems bottlenecks named on slide 19:
- Large vocabulary size: every decoding step scores tens or hundreds of thousands of candidate subword tokens.
- Unbounded grammar states: recursive context-free grammars (CFGs)—modeled by pushdown automata (PDA) with a stack, such as slide 20’s nested-array grammar (written literally on the slide without outer grouping around
<str> | <array>, which under unambiguous EBNF grouping for its nonempty-array automaton isitem ::= <str> | <array>andarray ::= '[' <item> (',' <item>)* ']')—create infinitely many stack configurations, making static tables over full stack histories impossible. - CPU–GPU speed mismatch: GPUs generate logits quickly, so computing masks on the CPU cannot keep up with GPU decoding (slides, p. 19).

XGrammar (slides, p. 21) mitigates this bottleneck using one structural property of subword vocabularies: most tokens (>99%, as reported on slide 21) are context-independent given only the top state of the PDA stack. At the active string node (Node (1) in rule <str> for partial input ["a; slides, pp. 20–21), ordinary substrings like a or ab" stay accepted regardless of what sits lower on the stack, while tokens like \ or \ab are rejected in the slide’s simplified string grammar (str ::= '"' [^"\]* '"') regardless of deeper history (note that full JSON syntax permits \ to begin escape sequences). Only a tiny set of context-dependent outlier tokens (such as "ab or a"b, which close the string and pop back to deeper stack rules; slides, p. 21) depends on deeper stack entries.
XGrammar therefore splits masking into two stages (slides, p. 21):
- Compile time (stack-top adaptive cache): Precompute bitmasks for the context-independent tokens per PDA stack-top node.
- Decode time (tiny outlier check): Retrieve the cached bitmask by indexing the current parsing state, then test only the remaining context-dependent outlier tokens efficiently.
For a constructed arithmetic check (not a universal slide bound or benchmark), suppose an illustrative vocabulary has tokens and >99% are context-independent at a given stack-top node: strictly < 1% leaves fewer than 1,280 outlier tokens (at most 1,279 tokens) to check at runtime, while a dense -bit-per-token precomputed mask takes per cached stack-top node before metadata.
Choosing the customization interface
| Method | Attachment Interface | Parameters Trained for Customization | Step-0 Behavior | Extra Runtime Work | Slide Example |
|---|---|---|---|---|---|
| Prompting / CLIP condition | Conditioning / embeddings | None (context or encoder) | Zero backbone changes | Condition encoding + cross-attention | Text-to-image SDE (pp. 6–8) |
| Visual token projection | Input embedding sequence | Vision encoder and/or projector (setup-dependent) | Extends input token sequence | Visual encoder pass + extra tokens | MiniGPT-4, LLaVA (p. 17) |
| ControlNet | Parallel zero-conv blocks | Encoder copy + zero-convs | Exact original output () | Parallel encoder + middle/decoder skip paths | Canny / pose Stable Diffusion (pp. 10–12) |
| LoRA | Parallel low-rank weights | Matrices (rank ) | Exact original output (, Hu et al.) | Zero if merged; tiny if unmerged | LLMs & diffusion (p. 16) |
| XGrammar masking | Post-LLM raw logits | None | Weights untouched; disallowed tokens receive | Cached bitmask lookup + outlier stack check | Typed JSON / CFG decoding (pp. 18–21) |
Across all three interfaces, the systems pattern is consistent: touch only the narrow interface needed for the missing capability. Keep the pretrained forward pass intact at step when adapting weights, project new modalities cleanly into shared token space when inputs change, and enforce deterministic syntax at the logits rather than hoping gradient descent never emits an invalid comma.
Sources
- CMU 10-414/714 Fall 2026 Lecture Schedule and Lecture 22 slides: Customizing Pretrained models (22 pp.) (Tianqi Chen and Tim Dettmers; no public video recording is listed for Lecture 22).
- Diffusion SDE figures (
pp. 7–8): CVPR 2022 Tutorial on Diffusion Models. - Cited works from the slides: Radford et al., Learning Transferable Visual Models From Natural Language Supervision (
p. 6); Rombach et al., High-Resolution Image Synthesis with Latent Diffusion Models, CVPR 2022 (arXiv:2112.10752,p. 9); Zhang, Rao, and Agrawala, Adding Conditional Control to Text-to-Image Diffusion Models (pp. 10–12); Hu et al., LoRA: Low-Rank Adaptation of Large Language Models (p. 16); Zhu, Chen et al., MiniGPT-4 & Liu, Li et al., Visual Instruction Tuning (LLaVA) (p. 17); and XGrammar (p. 21).