Unit 6 of 9 · about 5 hours · implement

Frozen encoders, projector warmup, staged fine-tuning, and retrieval versus generative objectives

A correct forward shape is not a generative model. The important transition is from disconnected components to causal answer training whose gradients, frozen state and held-out behavior can be audited.

You'll be able to

  • Implement a frozen-encoder, trainable-projector path into a causal decoder with answer-only likelihood.
  • Verify the gradient and optimizer boundaries of projector warmup and bounded decoder fine-tuning.
  • Evaluate retrieval and generation as distinct objectives without inferring grounding from either training loss.

Covers

Frozen encoders, projector warmup and staged fine-tuningPaired retrieval versus generative instruction objectives
1

Read

In this order, only the parts listed

0 of 3 done

  1. CS336 Spring 2026 Lecture 17: multimodal modelsCS336 2026 - Alignment and Multimodality

    The clip Ablation block and llava Training block

  2. Visual Instruction Tuning, arXiv:2304.08485v1: trainingLLaVA - Visual Instruction Tuning

    Sections 4.1 and 4.2, Table 2 and Equation 3: architecture, assistant prediction targets and the two training stages

    Use the freeze schedule and objective, not the Vicuna-scale run. Reuse your saved small lmlab decoder and the vision encoder from the Deep Learning unit on paired modalities; pin both checkpoint hashes and preprocessing in the run manifest.

  3. Modern LLM Notebook 29: freeze schedule and minimal pipelineModern LLM Notebook - Vision-Language Models

    Sections 8 to 10 and Exercise 3: Calculate Two-Stage Training Ratios

    Section 10 is a shape demo: its TransformerEncoder call has no causal mask or positional encoding. Do not use its loss as autoregressive evidence. Insert the visual prefix into your tested causal decoder, retaining its positions and loss shift.

2

Focus on

  • Warm up only the projector with the encoder and decoder parameters frozen. The decoder still needs autograd through its operations to the projected inputs; do not wrap that forward pass in torch.no_grad().
  • For the local route, reuse the paired encoder's frozen grid features and a roughly 10M-parameter decoder from your earlier work. Cache detached vision features with preprocessing and checkpoint hashes. PyTorch 2.14.1 is the reference; CPU and shorter sequences suffice for the same correctness tests.
  • In stage two, unfreeze a declared decoder subset and rebuild or update optimizer groups deliberately. Match image ids, answer-token exposure, update budget and evaluation settings against a no-warmup branch initialized from the same saved state; report any compute difference.
  • Retrieval ranks candidates in a shared feature space; generative training predicts answer tokens conditioned on image and prompt. Keep a frozen retrieval baseline, a text-only decoder baseline and independent answer evaluation. Neither low contrastive loss nor low answer loss proves grounding.
Common mistakes · 3
  • Equating eval() with freezing. It changes behavior such as dropout, not parameter trainability; requires_grad=False does not itself select evaluation behavior.
  • Detaching projector outputs or disabling decoder autograd during warmup. The projector then cannot learn through the frozen decoder.
  • Selecting a training stage on the final test images. Keep a development split and preserve the final split for the frozen comparison.
3

Try it yourself

Closed-book, before checking anything

From a blank file, write one answer-only training step through a trainable projector and a frozen causal decoder. Snapshot frozen tensors before the step: they must remain unchanged while the projector receives a finite nonzero gradient on a nondegenerate batch. With shifted labels, check that only assistant targets enter the denominator, not visual or prompt positions. Save and reload the projector plus assembly metadata; in evaluation mode require the same logits within rtol=1e-5, atol=1e-6 on the same fixed CPU batch.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Why can a frozen decoder still train a projector?Answer

    Its operations remain differentiable with respect to the input embeddings. Frozen weights need no gradients, but gradients to projected visual inputs can still flow.

  2. 2.Does a smaller count of trainable parameters imply proportionally smaller total training memory?Answer

    No. Frozen weights remain resident and decoder activations may still be needed for the projector's backward path. Optimizer state, activations and total memory must be accounted for separately.

  3. 3.A model ranks the correct caption first but cannot answer a counting question. Is that inconsistent?Answer

    No. Ranking a finite candidate set and generating an accurate count are different tasks. The contrastive representation may not preserve or expose the required count.

You're done when

Your warmup step changes only permitted state, reload preserves fixed-batch logits within tolerance, and you can state separate retrieval and generation evaluation contracts before training longer.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 12 more in the section
  • CS336 2026 - Alignment and MultimodalityStanford University · primary

    Step through the Lecture 17 trace ("multimodal models": CLIP, SigLIP, LLaVA, LLaVA-OneVision, Qwen-VL, Qwen2-VL, Qwen3-VL, Chameleon). Reconstruct patching, projector, fusion, multimodal positions and the chosen objective before implementing the bounded image-text path.

  • LLaVA - Visual Instruction TuningLLaVA Team · required

    Read Section 3 (GPT-assisted instruction data built from captions and boxes) and Sections 4.1 and 4.2 (a linear projection, then two-stage training). LLaVA-1.5 (https://arxiv.org/abs/2310.03744) swaps in a two-layer MLP; see build_vision_projector in the code. Build only a tiny frozen-encoder plus projector path and compare it with text-only and shuffled-pair controls.

  • Modern LLM Notebook - Vision-Language ModelsWalking Labs · support

    Complete notebooks-en/part4-frontiers/29-vlm.ipynb through the minimal VLM. Add missing-image, conflicting-caption, resolution and serialization tests that the walkthrough does not supply.

Also in this section

  • CLIP Paper and Official CodeOpenAI · required

    Read Section 2.2 and the Figure 3 pseudocode (normalized embeddings, logits scaled by a learned temperature, the symmetric cross-entropy), then Section 2.3. Check preprocessing and tokenization in the official code (clip/clip.py _transform and tokenize, https://github.com/openai/CLIP). The README says logits are "times 100", but the model learns the scale.

  • Sigmoid Loss for Language Image Pre-Training (Zhai et al., 2023)Google DeepMind · required

    Read Sections 3.1 and 3.2 and Algorithm 1: a pairwise sigmoid loss with a learned temperature and bias instead of a softmax over the batch. Negatives still matter; keep the reduction convention explicit.

  • Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution (Wang et al., 2024)Alibaba Qwen · required

    Read Section 2.1 and Figure 3 (dynamic resolution, 2x2 token merging, M-RoPE with temporal, height and width components) and Section 3.3.2 (the M-RoPE ablation). Variable resolution means variable tokens and memory.

  • POPE: Evaluating Object Hallucination in Large Vision-Language ModelsRenmin University · required

    Read Sections 5.1 and 5.2 of the paper (https://aclanthology.org/2023.emnlp-main.20.pdf), then evaluate one negative-sampling slice (random, popular or adversarial) with accuracy, F1 and the yes ratio. Join answers by question id, not row order, and keep the original files apart from POPEv2.

  • smol-course Unit 3 - Vision Language ModelsHugging Face · support

    Work through Unit 3 for a runnable VLM fine-tuning path on SmolVLM2. Check its memory notes against your GPU and shrink the model, image resolution or batch before running.

  • COCO Captions SubsetCOCO Consortium · support

    Select 50 to 200 image ids from one annotation split with all their captions, record each image's license, and keep every caption of an evaluation image out of training. The annotations are CC BY 4.0; the images keep their own terms.

  • Flamingo: a Visual Language Model for Few-Shot Learning (Alayrac et al., 2022)DeepMind · support

    Read Sections 2.1 to 2.3 (details in Appendix A.1.1 to A.1.3): the Perceiver Resampler, gated cross-attention with tanh gates starting at zero, and multi-image masking. It is the cross-attention contrast to LLaVA's token concatenation.

  • TensorTonic - Alignment and Multimodality SetTensorTonic · support

    Solve Patchify a Batch of Images (cs336-l17-vision-transformer-patchify), Implement Symmetric CLIP Contrastive Loss (cs336-l17-symmetric-clip-loss), Implement the SigLIP Pairwise Loss (cs336-l17-siglip-pairwise-loss) and Assign Multimodal RoPE Coordinates (cs336-l17-multimodal-rope-coordinates). Its SigLIP loss averages over all B squared pairs while OpenCLIP divides the sum by B, so multiply by B before comparing. Public test cases check the listed edge cases, not gradients or the hidden grader, so keep your own tests beside each solution.

  • OpenCLIPML Foundations · reference

    Use release 3.3.0 for one small comparison: ClipLoss and SigLipLoss in src/open_clip/loss.py as oracles for your losses, and the zero-shot classifier. OpenAI RN50 weights need force_quick_gelu=True. The main branch has a refactored training stack; do not adopt the distributed trainer.

  • Chameleon: Mixed-Modal Early-Fusion Foundation Models (Chameleon Team, 2024)Meta FAIR · reference

    Read Sections 2.1 to 2.3: images as 1024 discrete tokens from an 8192-entry codebook, interleaved data and the stability fixes. Early fusion still depends on the image tokenizer.

  • LLM Post-Training Laboratory - Multimodal ModuleRoadmap-Final · support

    Use the optional multimodal evidence module for versioned aligned data, projector or fusion tests, retrieval and generation evaluation, and modality-specific safety checks.

  • High Fidelity Neural Audio Compression (EnCodec)Meta AI · reference

    Sections 3.1 to 3.4 of arXiv:2210.13438v1: temporal downsampling, residual codebooks, code prediction and codec reconstruction objectives. Read for audio-token vocabulary and rate accounting, not a codec training run.