PIXELBANKv8.2.1
Menu
Back to VLM Study Plan
Week 7-8

Chapter 7: Training Recipes: Pretraining, SFT & RLHF

Master the complete training pipeline that transforms a randomly initialized model into a capable, aligned visual assistant. From large-scale pretraining on billions of image-text pairs through supervised fine-tuning on curated instructions to reinforcement learning from human feedback, understand each stage's objectives, data requirements, and failure modes — including the persistent challenge of hallucination.

Chapter Overview

Training a modern VLM is not a single optimization run — it is a carefully orchestrated sequence of training stages, each with distinct objectives, data distributions, and hyperparameter regimes. Getting this recipe wrong at any stage cascades into downstream failures that are difficult to diagnose.

The standard VLM training pipeline has evolved into three (sometimes four) distinct phases:

  1. Pretraining on massive, noisy web data teaches the model basic visual-language associations. The objective is broad coverage, not precision. Models process billions of image-text pairs from datasets like LAION-5B and DataComp, learning that "dog" co-occurs with images of dogs, that spatial prepositions have visual correlates, and that captions describe salient image content.

  2. Supervised Fine-Tuning (SFT) on carefully curated instruction data transforms the pretrained model into an instruction-following assistant. Here, quality dominates quantity: a few hundred thousand high-quality examples outperform millions of noisy ones. The critical insight is loss masking — computing gradients only on the assistant's response tokens, not on the instruction or system prompt.

  3. Alignment via RLHF or DPO adjusts the model's behavior to match human preferences. This stage addresses a fundamental gap: SFT teaches the model what to say in response to instructions, but not how to say it well — avoiding hallucination, being appropriately cautious, and calibrating confidence. RLHF uses a reward model trained on human preference comparisons, while DPO directly optimizes on preference pairs without a reward model.

The mathematical foundations of each stage differ significantly:

  • Pretraining minimizes cross-entropy over massive token sequences: Lpretrain=tlogp(xtx<t,v)\mathcal{L}_{\text{pretrain}} = -\sum_{t} \log p(x_t | x_{<t}, \mathbf{v})
  • SFT minimizes cross-entropy only on response tokens: LSFT=tresponselogp(xtx<t,v,instruction)\mathcal{L}_{\text{SFT}} = -\sum_{t \in \text{response}} \log p(x_t | x_{<t}, \mathbf{v}, \text{instruction})
  • RLHF maximizes expected reward with KL penalty: maxπE[r(x,y)]βKL[ππref]\max_{\pi} \mathbb{E}[r(x,y)] - \beta \cdot \text{KL}[\pi \| \pi_{\text{ref}}]

Each stage has its own failure modes: pretraining can memorize noise, SFT can overfit to formatting, and RLHF can reward-hack. Understanding these failure modes is as important as understanding the training objectives.

This chapter also addresses the persistent challenge of hallucination — arguably the single most important unsolved problem in VLMs. We examine why models fabricate objects, misattribute properties, and invent spatial relationships, and explore the mitigation strategies (RLHF, data quality, specialized objectives) that have shown promise.

Finally, we cover the training infrastructure required to run these recipes at scale: distributed training across hundreds of GPUs, mixed-precision arithmetic, gradient checkpointing, and the engineering challenges that make VLM training as much a systems problem as a research one.

Chapter Roadmap

Click any topic to jump in

1
Pretraining Objectives

ITC, ITM, masked LM, and next-token prediction — the four objectives that teach VLMs to connect vision and language.

Data for pretraining
2
Pretraining Data

Web-scale collection, deduplication, quality filtering, and safety — building billion-pair datasets like LAION-5B.

From pretrained to instruction-following
3
Supervised Fine-Tuning

Loss masking, instruction curation, and chat templates — teaching the pretrained model to follow instructions.

Two approaches to alignment

RL-based vs direct optimization

4
RLHF for VLMs

Visual reward models and PPO — aligning VLM outputs with human preferences through reinforcement learning.

5
DPO & Preferences

Direct preference optimization as a simpler alternative to RLHF — no reward model needed.

Key challenges in training

Quality problems and infrastructure needs

6
Hallucination

Why VLMs fabricate visual details, the CHAIR metric, and mitigation strategies from training to inference.

7
Training Infrastructure

DeepSpeed, FSDP, mixed precision, gradient checkpointing — the systems needed for large-scale VLM training.

Sign up to unlock this chapter

This chapter is part of PixelBank Premium. Create a free account, then upgrade to read the full lesson — concepts, walkthroughs, and exercises.

Training Recipes: Pretraining, SFT & RLHF | PixelBank