SFT#
Supervised fine-tuning (SFT) updates the language model weights and multimodal projection layers (vision and audio encoders often stay frozen). Use SFT when you need maximum adaptation capacity (~90–96% of parameters trainable vs. ~0.04–0.17% for LoRA; see LoRA) and can afford the higher compute and memory of full-parameter training and larger checkpoints (hundreds of GB per save vs. tens of MB for LoRA). Reference GPU memory and throughput numbers are in SFT vs. LoRA (compute and checkpoint size) on the LoRA page.
Both stacks share the same high-level recipe layout under configs/. Cluster settings (Slurm, container, cache directory) live in launch_local.yaml; training hyperparameters live in the recipe YAML.
Runbooks (commands and smoke examples):
AutoModel: automodel/sft/SFT_GUIDE.MD
Megatron-Bridge: megatron-bridge/sft/SFT_GUIDE.MD
Environment variables and overrides: AutoModel SFT reference and Megatron-Bridge SFT reference.
Megatron-Bridge also requires a Megatron-format base checkpoint: HF→Megatron conversion.
What Gets Trained#
SFT often keeps vision and audio encoders frozen and trains the LLM plus multimodal projectors (the layers that map vision/sound features into the language model). Use freeze_config in the recipe YAML (true = frozen, false = trainable).
AutoModel
Parameter |
Controls |
|---|---|
|
Video embedding layer; no additional effect when |
|
Vision encoder (RADIO) |
|
Audio / sound encoder |
|
MoE language model decoder |
There are no separate projector freeze flags; vision and audio projectors train when the LM is unfrozen.
Megatron-Bridge
Parameter |
Controls |
|---|---|
|
MoE language model decoder |
|
Vision encoder |
|
Vision-to-LM projector |
|
Audio / sound encoder |
|
Audio-to-LM projector |
Unfreezing encoders increases memory and risk of catastrophic forgetting; keeping encoders frozen is a good starting point.
Training Schedule and Batching#
Parameter |
AutoModel ( |
Megatron-Bridge ( |
|---|---|---|
Global batch size |
|
|
Per-GPU microbatch |
|
|
Max steps |
|
|
Validation |
|
|
Checkpoints |
|
|
Impact: Higher global batch size stabilizes MoE training but needs more GPUs for gradient accumulation. More GPUs increase data-parallel capacity. Fewer max_steps is fine for smoke tests; production runs typically use hundreds to thousands of steps with cosine decay aligned to max_steps.
Optimizer and Learning Rate#
Parameter |
AutoModel |
Megatron-Bridge |
|---|---|---|
Optimizer |
|
|
Learning rate |
Default 5e-5 for full SFT |
Default 5e-5 for full SFT |
LR schedule |
|
|
Grad clip |
|
|
Memory savers |
|
|
Megatron-Bridge CPU offload
Full SFT can run out of GPU memory even when model weights are sharded across TP/EP. CPU offload moves Adam optimizer state (momentum, variance, and related buffers) from GPU VRAM to host RAM so more room is left for activations and gradients. Tradeoffs: higher host memory use and some overhead when tensors move between GPU and CPU during the optimizer step.
Recipe fields:
optimizer_cpu_offload— enable offload (true/false)overlap_cpu_optimizer_d2h_h2d: trueuse_precision_aware_optimizer— must betruewhen offload is enabled
DDP (non-FSDP) on a single 8-GPU node often requires CPU offload.
Further reading:
Megatron Core — Optimizer CPU Offload — CPU offload guide
Megatron Core OptimizerConfig — offload recipe fields
Megatron-Bridge FSDP
FSDP shards model parameters, gradients, and optimizer states across data-parallel ranks, lowering per-GPU memory use. This can allow lower TP/EP degrees to speed up training.
Recipe fields:
use_megatron_fsdp: trueprecision.bf16_optimizer_states: true— requiresoptimizer.use_precision_aware_optimizer: true
Recommended environment:
environment:
pytorch_cuda_alloc_conf: expandable_segments:True
nccl_nvls_enable: 0
torch_nccl_avoid_record_streams: 1
cuda_device_max_connections: 32
Further reading:
Impact: LR that is too high diverges MoE models quickly; too low underfits. Warmup (often ~10% of total steps) reduces early instability.
Distributed Parallelism#
Distributed training has four dimensions of parallelism: TP, PP, EP, and CP. The current reference MoE recipes use TP1 and EP8; keep PP and CP at 1.
Set supported degrees under distributed in the recipe YAML (or via TP and EP env overrides on launch):
TP (tensor parallelism) — splits weight matrices within a layer across GPUs (e.g. attention and MLP shards).
EP (expert parallelism) — shards MoE expert networks across GPUs (required for the current reference model’s MoE decoder).
PP (pipeline parallelism) — splits the model depth-wise across pipeline stages. Not supported by the current reference recipes; keep
pp_sizeat1.CP (context parallelism) — splits sequence length across GPUs for very long contexts. Not supported by the current reference recipes; keep
cp_sizeat1.
Parameter |
AutoModel ( |
Megatron-Bridge ( |
|---|---|---|
|
Tensor-parallel degree; use |
Tensor-parallel degree; use |
|
Expert-parallel degree; |
Expert-parallel degree; use |
|
Not supported by the current reference recipes; keep at |
Not supported by the current reference recipes; keep at |
|
Not supported by the current reference recipes; keep at |
Not supported by the current reference recipes; keep at |
Impact: Let world_size = nodes × GPUs_per_node.
AutoModel (current reference recipes and training scripts use pp_size=1 and cp_size=1):
world_sizemust be divisible bytp_size × pp_size × cp_size.ep_sizemust divideworld_size / pp_size.Data-parallel degree:
dp_size = world_size / (tp_size × pp_size × cp_size).
Example: 1 node × 8 GPUs, tp_size=1, pp_size=1, cp_size=1, ep_size=8 → dp_size=8, and 8 / 1 is divisible by 8.
Megatron-Bridge (current reference recipes and training scripts use pp_size=1 and cp_size=1):
Attention-path data-parallel degree follows the standard Megatron rule:
dp_size = world_size / (tp_size × pp_size × cp_size).As a minimum-GPU bound,
world_sizemust be at leastpp_size × max(tp_size × cp_size, ep_size).
Example: 1 node × 8 GPUs, tp_size=1, pp_size=1, cp_size=1, ep_size=8 → minimum = 1 × max(1, 8) = 8, which matches world_size=8.
Further reading:
NeMo AutoModel — Distributed Setup — FSDP2 + expert parallelism
Megatron-Bridge — Parallelisms —
tp_size,pp_size,cp_size,ep_size,dp_sizeMegatron Core — Parallelism Strategies — TP, PP, CP, EP
Changing parallelism after training changes the checkpoint layout, so keep MODEL_NAME and topology consistent to resume.
Data, Video, and Sequence Budget#
Training data is JSONL (one JSON object per line) in HuggingFace Conversation format: a conversation array of user / assistant turns with typed content (video, text, and optionally audio). Rows may also include id and class metadata; class is the question-type / template name (for example server_winner) and is used by eval tooling but is not required for training.
Video (and audio) paths in the JSON are relative to video_root in the recipe YAML. Training resolves each file as video_root + the relative path (normalized, no leading slash).
Example line:
{
"id": "sample-001",
"class": "server_winner",
"conversation": [
{"role": "user", "content": [
{"type": "video", "path": "match_id/segment.mp4"},
{"type": "text", "text": "Who won this point?"}
]},
{"role": "assistant", "content": [
{"type": "text", "text": "Player A won."}
]}
]
}
The class field is optional for training but recommended in curated datasets so eval can break down accuracy by question type.
The following table summarizes recipe fields that control data loading, video sampling, and sequence budget.
Parameter |
AutoModel |
Megatron-Bridge |
|---|---|---|
Train / val JSONL |
|
|
Subsample |
|
|
Video frames |
|
|
Sequence length |
|
|
Sequence packing |
|
|
Sequence packing improves throughput by fitting multiple short samples in one sequence; packed token count must exceed your longest sample (video + audio + text). See NeMo AutoModel — Datasets overview (packed sequence support) and Megatron-Bridge — Packed sequences.
Generate metadata for packed training with avlm/utils/build_video_metadata.py; AutoModel uses train and validation metadata, while Megatron-Bridge uses train metadata only. See the AutoModel SFT guide and Megatron-Bridge SFT guide.
MoE Backend (AutoModel Only)#
model.backend.dispatcher: deepep routes expert tokens across GPUs during forward/backward. Pre-Hopper GPUs (e.g. A100) need the matching DeepEP wheel installed at launch (see Setup Notes). Using deepep on pre-Hopper, ep_size is limited to the number of GPUs per node (=8). Override with DISPATCHER=torch only for debugging (slower).
Weights & Biases#
Training metrics are logged via the wandb section in the recipe YAML. Set entity to your W&B account.
Field |
Effect |
|---|---|
|
|
|
|
Both stacks |
Scripts fall back to |
Quick Start#
Complete Setup (container,
launch_local.yaml, recipe YAML with your data paths).Edit recipe YAML: data paths,
max_steps, freeze flags, and memory knobs (frames,seq_length/pack_size).AutoModel:
launch_interactive_session.sh→train_interactive.sh; thensbatch_starter.shfor scale.Megatron-Bridge: HF→Meg conversion once, then the same interactive → sbatch flow.
Smoke commands and CLI override tables are in the code-repo guides above.