Multimodal Language Models
Multimodal models add representation, alignment and data contracts that text-only intuition does not cover. This stage implements one bounded image-text path and tests whether the model is grounded or merely exploiting pairing and language priors.
Section 9 of 11 · 9 units · about 38 hours
By the end you can Implement one image-text encoder, projector or fusion mechanism; verify masks and positions; compare against text-only and corrupted-pair baselines; and report retrieval or generation quality, grounding failures and compute by modality slice.
Units
- Image patches, vision encoders and visual-token counts, and resolution, context and compute cost4h
- Projectors between representation spaces, and early, late and cross-attention fusion4h
- The symmetric CLIP contrastive loss, the SigLIP pairwise sigmoid loss and batch-size behavior6h
- Paired, interleaved, instruction and synthetic multimodal data with generator provenance4h
- Modality tokens, attention masks and multimodal RoPE coordinates4h
- Frozen encoders, projector warmup, staged fine-tuning, and retrieval versus generative objectives5h
- Missing, corrupted and conflicting modalities, visual grounding and hallucination4h
- Cross-modal leakage, modality slices, and text-only and corrupted-pair baselines5h
- Audio and video tokenization and native multimodal generation objectives2h
Build it
Mini project · about 18 to 24 hours
A grounded image-text branch with intervention evidence
Extend lmlab with a frozen vision encoder and a tested projector into your existing causal decoder. Keep retrieval, answer generation and image dependence separate so a fluent answer or lower loss cannot stand in for grounding. Run on CPU or your GPU without paid generation.
- 1Build the COCO manifest in
mm/with caption and instruction parents, image-group splits, per-image rights, transformations, generator provenance and rejected-item counts. Plant renamed, re-encoded and caption-derived leaks; check hashes and reviewed lineage against known fixtures, quarantine affected groups and retain the audit. - 2Reuse TensorTonic Patchify and notebook Projector checks; add loop-oracle reconstruction, noncontiguous-input, dtype, parameter-count and zero-gate tests. Differential-test frozen-batch CLIP and SigLIP losses and gradients against OpenCLIP, reconciling reductions; retain resolution, token and FLOP budgets before training.
- 3Connect frozen features through the projector to the causal decoder in
mm/. Pass TensorTonic Multimodal RoPE coordinates, then independently test expanded labels, truncation, image ownership, padding, future-token isolation, serialization and cached-versus-full logits; retain failures. Optionally explain strided-video coordinates and audio/image generation's missing output contracts. - 4Check answer-only loss and gradients against a shifted-target oracle, optimizer membership and unchanged frozen tensors. Compare projector warmup plus bounded decoder updates against no warmup from shared state, across seeds with matched exposure and update budgets; retain compute differences and failed runs in
registry/. - 5Build the original POPE random-negative scorer: test joins, missing and duplicate ids, strict parsing and confusion counts against hand-labeled fixtures. Reserve image groups before training; retain raw answers, parsed-subset metrics, all-item accuracy, yes ratio, invalids and coverage beside frozen retrieval and text-only baselines.
- 6Evaluate intact, missing, corrupted and checked deranged-image conditions plus pixel-verified conflicting captions on identical held-out items. Predeclare object, text-in-image, spatial, counting, resolution and harmless embedded-instruction slices; check answers independently and retain image-group paired uncertainty separately from seed variation, including a negative or unresolved result.
- 7Compare fixed retrieval candidates and generation budgets with length-matched blank features and a trained shuffled-pair control. Reconcile raw records with per-modality quality, coverage, token, latency and peak-memory tables in
reports/; disclose unmatched compute, unknown pretraining overlap and distinctions between image dependence, grounding and safety.
What you hand in
- The
mm/module, versioned COCO lineage, encoder and decoder identities, assembly metadata and independent correctness tests. - Matched staged-training and modality-control records in
registry/, including failed attempts and retained negative evidence. - A
reports/grounding dossier with original POPE answers, parser audits, retrieval and generation results, clustered uncertainty and modality costs.
How to check it
- Self-grade with the rubric below
- TensorTonic: Patchify a Batch of Images
Reuse public patch cases; add reconstruction, noncontiguous-input and dtype checks.
- Modern LLM Notebook 29: Projector exercise
Reuse the projector assertion, not the noncausal pipeline demo or post-normalization gate as an identity oracle.
- OpenCLIP release 3.3.0 loss oracle
Compare losses and feature, multiplier and bias gradients with normalized features and explicitly aligned reductions.
- TensorTonic: Assign Multimodal RoPE Coordinates
Coordinate cases do not replace expanded-sequence, causal-mask or cached-decoding tests.
- Original POPE COCO random-negative questions at pinned commit
Use held-out image groups and your audited parser; disclose departures from the original evaluator and limited subset scope.
How it's graded
Lineage and leakage
Pass: Your audit catches all planted leak types, quarantines their source groups and preserves per-image rights, answer evidence, generator unknowns and rejection counts.
Great: A rebuilt manifest reproduces splits and exposure counts; reviewed near-duplicate candidates distinguish semantic similarity from shared pixels without claiming clean pretraining.
Connected objective correctness
Pass: Your loop, gradient and OpenCLIP oracles pass before training; assembly, freeze boundaries, parameter counts, serialization and cached decoding pass independent regression tests.
Great: Planted mask, reduction, image-ownership and stale-feature defects fail their intended checks; actual optimizer and activation storage explain the resource ledger.
Grounding attribution
Pass: Your hand-checked scorer preserves invalids and ids; retrieval, answer quality and modality interventions retain fixed budgets, clustered uncertainty, seed variation and negative evidence.
Great: Separate inference interventions and trained shuffled-pair controls isolate language shortcuts, resolution and extra-context explanations; no benchmark outcome is presented as general multimodal safety.
Resources
- CS336 2026 - Alignment and MultimodalityStanford University
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.
- CLIP Paper and Official CodeOpenAI
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_transformandtokenize, 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
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.
- LLaVA - Visual Instruction TuningLLaVA Team
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_projectorin the code. Build only a tiny frozen-encoder plus projector path and compare it with text-only and shuffled-pair controls. - Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution (Wang et al., 2024)Alibaba Qwen
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
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.
- Modern LLM Notebook - Vision-Language ModelsWalking Labs
Complete
notebooks-en/part4-frontiers/29-vlm.ipynbthrough the minimal VLM. Add missing-image, conflicting-caption, resolution and serialization tests that the walkthrough does not supply. - smol-course Unit 3 - Vision Language ModelsHugging Face
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
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
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
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. - LLM Post-Training Laboratory - Multimodal ModuleRoadmap-Final
Use the optional multimodal evidence module for versioned aligned data, projector or fusion tests, retrieval and generation evaluation, and modality-specific safety checks.
- OpenCLIPML Foundations
Use release 3.3.0 for one small comparison:
ClipLossandSigLipLossinsrc/open_clip/loss.pyas oracles for your losses, and the zero-shot classifier. OpenAI RN50 weights needforce_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
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.
- High Fidelity Neural Audio Compression (EnCodec)Meta AI
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.