Auto Recipe β Recipe Index & Recommendation#
This skill indexes every shipped recipe and helps users pick the right starting config, adjust parallelism, and avoid common pitfalls.
How to Use This Skill#
Ask the user for: model name/size, GPU count & type, training goal (pretrain / SFT / PEFT), and sequence length (if non-default).
Look up the best-match recipe in the index below.
Recommend the recipe function name + entry-point command.
Provide adjustment advice (parallelism resizing, batch tuning, pitfalls).
First Answer Checklist#
When recommending recipes, always include these distinctions before the long index details:
Library recipes under
src/megatron/bridge/recipes/are for functional training and usescripts/training/run_recipe.py.Benchmark recipes under
src/megatron/bridge/perf_recipes/are for upper-bound throughput benchmarks. They own their canonical benchmark data and settings and should not be presented as production training recipes.For a first-time Bridge smoke test, recommend
llama3_8b_pretrain_configwith mock data via--dataset mock.For normal SFT recommendations, select a finetuning preset such as
--dataset squador--dataset tulu3; for pretrain and mock validation recommendations, use--dataset mock. Do not pair the pretraining-onlymockpreset with an SFT or PEFT mode.After the recipe and dataset, give the required resizing rules: TP must divide
num_key_value_heads, use the lowest TP that still fits the dense state, keep TP within one node unless using NVL72-class interconnect, enable SP when TP > 1, configure CP for long context, and make both dense and expert meshes divide the allocation.State whether each proposed override changes the convergence contract or only the execution/performance mapping. Do not trade convergence semantics for throughput without calling it a new experiment.
Configuration Layers and Change Control#
Separate training semantics from their hardware mapping before recommending or tuning a recipe.
Convergence configuration includes the starting checkpoint and trainable parameters; dataset/revision/split/order/seeds; tokenizer, masking, truncation, and packing; sequence length; global batch and token budget; objective and loss coefficients; natural or forced MoE routing and token-dropping policy; optimizer, LR, schedule, warmup, betas, epsilon, weight decay, clipping, and dropout; arithmetic and optimizer-state precision; and PEFT adapter settings. Changing one of these creates a new convergence experiment.
Execution/performance configuration includes hardware count and topology; TP/PP/VP/CP/EP/ETP/DP/SP; recompute and offload; distributed optimizer/FSDP; communication overlap; fusions and attention backends; CUDA graphs and compilation; checkpoint I/O; and MoE transport through all-to-all, DeepEP, or HybridEP when the routing policy is unchanged. These settings should preserve the objective and effective updates, although floating-point reduction order can produce small numerical drift that still needs validation.
Treat micro batch size and gradient accumulation as execution fingerprints. Tune them only with fixed global batch size, global batch membership/order, normalization, optimizer boundaries, and token budget, and validate fresh loss sentinels for each layout. Packing, precision, forced MoE load balancing, token dropping/capacity, and router/auxiliary loss changes are never performance-only knobs.
Treat mock data, forced balancing, disabled correctness checks, and timing-only
schedules as benchmark-only shortcuts. They may be appropriate in
perf_recipes, but their losses and checkpoints are not convergence evidence.
For comparable model-verification recipes, choose a cohort-wide convergence contract before tuning performance. Keep the same bounded data selection, preprocessing, sequence length, global batch, optimizer/schedule, precision, seeds, routing policy, optimizer-step horizon, and processed-token checkpoints where the architectures permit. Record any necessary model-specific deviation and do not present that result as apples-to-apples convergence evidence. Absolute losses from different architectures or tokenizers are not directly rankable; compare stability and trend at equal token counts.
When a recipeβs batch disagrees with the chosen convergence contract, modify and validate the library recipe separately. A declared bounded-verification protocol may explicitly apply the same LR, schedule, sequence, and data overrides across a cohort, but do not make one-off convergence changes merely to improve throughput. Conversely, first try TP/PP/CP/EP, recompute/offload, dispatcher transport, overlap, fusion, and CUDA graphs when optimizing fit or throughput.
Entry Points#
Library recipes (functional training)#
# Pretrain with mock data
uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \
--recipe <recipe_function_name> \
--dataset mock
# SFT with SQuAD
uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \
--recipe <recipe_function_name> \
--dataset squad
# Override any field via CLI
uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \
--recipe llama3_8b_pretrain_config \
--dataset mock \
'model.tensor_model_parallel_size=2' \
'train.global_batch_size=64'
Benchmark recipes (throughput benchmarks)#
./scripts/training/train.sh \
--nodes 2 --gpus-per-node 8 \
--account ACCOUNT --partition PARTITION --container-image IMAGE \
--recipe qwen3_30b_a3b_pretrain_16gpu_h100_bf16_config \
--mode pretrain
The total GPU allocation must match the count encoded in the recipe name. The
user selects the node shape, and the selected partition must provide the
requested hardware. The launcher does not inject benchmark offline defaults or
cluster-specific launch policy. Use --env NAME for exported offline or NCCL
fabric settings and repeated --srun-arg=ARG options for srun.
Configure CPU/NUMA wrappers and Slurm segment sizing through the target cluster
integration, or use scripts/performance/setup_experiment.py when its compatibility
policies are required. The unified
launcher supports exact exported text pretraining, text SFT/PEFT, Qwen-VL
pretraining, and Wan pretraining recipes and infers their forward step. Text
SFT/PEFT text benchmark recipes retain the flat runnerβs mock-data default;
Qwen-VL and Wan retain their model-specific datasets. Exported benchmark PEFT
recipes are fixed LoRA configs; use a configurable library recipe for DoRA.
Trailing KEY=VALUE overrides are accepted, but an overridden benchmark
recipe no longer represents its canonical benchmark configuration. Use
scripts/performance/setup_experiment.py for selector-based invocation,
dataset replacement, topology resizing, and specialized benchmark controls.
See the Benchmark Recipe Index for important caveats before using these for anything beyond throughput benchmarking.
Benchmark Recipe Layout#
Benchmark recipes use the same Python function format as library recipes, but live in a dedicated namespace for throughput benchmarking:
Benchmark recipes live in
src/megatron/bridge/perf_recipes/<family>/<hardware>/<model>.pyEach benchmark recipe is a self-contained Python function (e.g.
llama3_8b_pretrain_8gpu_h100_bf16_config())Recipe names encode model, task, GPU count, hardware, precision, and optional variant
scripts/performance/utils/utils.pyderives compatibilityWorkloadBaseConfigviews from the flat recipe itselfShared helpers:
_benchmark_common()(50 iters, timing, TE RNG),_perf_precision()(bf16 / fp8_cs / fp8_mx / nvfp4)
Why Python, not YAML? Previous YAML-based approaches had problems: recipe logic was split across multiple indirection layers, configs were not self-contained, and the two-level pipeline made maintenance and debugging difficult. Python functions are explicit, greppable, and composable.
The training launcher discovers library and benchmark recipes from the complete exported function name. Five legacy duplicate names select the benchmark definition; use the corresponding generic alias for those functional workloads. New recipe names should be unique across both packages.
Recipe Index (Library & Benchmark)#
The full per-family recipe tables β every shipped library recipe
(src/megatron/bridge/recipes/) and benchmark recipe
(src/megatron/bridge/perf_recipes/), with parallelism degrees, minimum GPU
counts, and hardware coverage β are kept in a dedicated reference file so this
skill stays concise:
β See references/recipe-index.md β Library
Recipe Index (Llama, Qwen2/2.5/3, Qwen3-MoE, Qwen3-Next, DeepSeek, GLM-4.5,
Gemma, Nemotron, VLM, Diffusion) and Benchmark Recipe Index (per-hardware
throughput configs).
Load that file to pull an exact recipe function name or its default parallelism; the guidance below tells you which entry to look up.
Recommendation Decision Tree#
User wants to train a model
β
ββ Know the model name?
β ββ Yes β Look up in references/recipe-index.md
β β ββ Has a recipe for their size + mode? β Use it directly
β β ββ No exact match? β Use closest size, adjust parallelism
β ββ No β Ask for model name, size, and HF model ID
β
ββ What's the training goal?
β ββ Pretrain β Use *_pretrain_config
β ββ SFT (full fine-tune) β Use *_sft_config
β ββ PEFT (LoRA/DoRA) β Use *_peft_config (lowest GPU requirement)
β
ββ How many GPUs?
β ββ 1 GPU β Only PEFT recipes work (TP=1, PP=1)
β ββ 8 GPUs (1 node) β Most 8Bβ16B models, small MoE (EP=8)
β ββ 16β64 GPUs β 70B dense, medium MoE
β ββ 128+ GPUs β 405B+, large MoE (DeepSeek V3, Kimi K2)
β
ββ Want throughput benchmarks?
β ββ Yes β Use benchmark recipes (src/megatron/bridge/perf_recipes/)
β β ββ Exact exported recipe β scripts/training/train.sh --recipe <exact function name>
β β ββ Selector/specialized workflow β scripts/performance/setup_experiment.py
β ββ No β Use library recipes (scripts/training/run_recipe.py)
β
ββ Long context?
ββ > 8K β Need CP (context parallelism), check *_16k / *_64k / *_128k variants
ββ β€ 8K β Default recipes work
Adjustment Advice (When Recommending)#
Parallelism Resizing Rules#
When the userβs GPU count differs from the recipe default:
TP must divide
num_key_value_heads(GQA constraint). E.g. ifnum_key_value_heads=8, valid TP = {1, 2, 4, 8}.TP should stay within a single node (NVLink). TP > 8 requires inter-node NVLink (e.g., GB200 NVL72).
PP adds pipeline bubbles. Minimize PP; only increase when TP alone canβt fit the model. Use VP (virtual pipeline) to mitigate bubble overhead.
EP doesnβt reduce dense-layer memory. Only expert parameters shard with EP. Shared attention/embeddings are replicated. For βOOM with MoEβ, increase EP first, not TP.
SP should be True whenever TP > 1. It eliminates redundant activation copies and is essentially free.
CP requires all-to-all or ring attention. Check
cp_comm_type. For GQA models,a2a+p2phierarchical CP allows CP > num_kv_heads.Dense and expert meshes overlap. Do not multiply TP and EP together. The minimum MoE world size is
PP Γ max(TP Γ CP, EP Γ ETP). Dense DP isworld_size / (TP Γ PP Γ CP)and expert EDP isworld_size / (PP Γ EP Γ ETP); both quotients must be integral, and the expert count must be divisible by EP.
Fit-First, Then Fill Tuning Loop#
For an MoE recipe on a fixed allocation, use this practical order:
Start with the lowest legal TP that can hold the dense parameters, optimizer state, and workspaces. Do not raise TP only to reduce activation memory; TP communication is expensive, so try recompute first.
Use the largest legal EP that matches the expert count and topology. EP=8 is a common first candidate on one 8-GPU node, and EP=32 is a common first candidate on a 32-GPU allocation. These are starting points, not universal defaults: EP shards expert weights only, not dense layers or activations.
Prefer architecture-specific selective recompute. For Qwen3.5 GDN layers, verify
gdn_norm_outon the exact Megatron Core revision instead of assumingcore_attncovers the GDN peak. Use full-layer recompute only when the targeted boundaries still do not make the complete step fit.After a stable baseline completes optimizer initialization and several steady steps, inspect W&B memory and confirm every rankβs peak allocated and reserved memory in the runtime logs; rank 0 can miss the hot EP or PP rank. If there is safe headroom, test one change at a time: lower TP by one legal step or increase MBS while keeping GBS, data order, and optimizer boundaries fixed.
Keep the candidate only when it improves end-to-end tokens/s/GPU or step time with healthy loss and no skipped/NaN iterations. Leave headroom for checkpointing, evaluation, routing imbalance, and optional CUDA graphs.
On EP=8, a large expert footprint can remain capacity-limited enough to need full recompute. EP=32 usually reduces expert-weight pressure substantially, making selective recompute a better candidate, but Qwen3.5 GDN coverage and the hot rankβs measured peak still decide.
Batch Size Tuning#
Start with the recipeβs
micro_batch_size. If OOM, reduce to 1; after the run fits, use measured headroom to sweep MBS upward again.global_batch_sizedetermines learning dynamics. Scale with DP:GBS = micro_batch_size Γ DP Γ gradient_accumulation_steps.For MoE,
micro_batch_size=1is typical at scale.
Common Pitfalls to Warn About#
Pitfall |
Symptom |
Fix |
|---|---|---|
TP > num_kv_heads |
Crash: βTP must divide num_query_groupsβ |
Reduce TP to a divisor of num_kv_heads |
PP without VP |
Poor throughput (large bubble) |
Set |
EP too low for large MoE |
OOM on expert params |
Increase EP; each expert lives on EP/num_experts ranks |
CUDA graphs + packed sequences |
Assert: βCUDA graph accepts only Tensor inputsβ |
Disable packing or use |
CUDA graphs + full recompute |
Assert: βfull recompute only with full iteration CUDA graphβ |
Disable recompute or switch to |
|
Assert on provider init when CUDA graphs enabled |
Set |
FSDP + TP > 1 on H100 |
Possible comm bottleneck |
Prefer FSDP with TP=1 or TP=2 on H100; FSDP shines on GB/B-series |
Long context without CP |
OOM on activations |
Add CP=2/4/8; use |
MoE |
May hurt throughput (False in many H100 presets) |
Set |
VLM SFT missing image data |
Runs but produces garbage |
Provide actual multimodal dataset or use mock VLM data |
Qwen35-VL MoE FSDP |
Tested on Blackwell only |
May not work on H100; validate first |
Recipe Override Examples#
# Scale Llama3 8B from 2 GPUs to 8 GPUs (increase DP)
uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \
--recipe llama3_8b_pretrain_config \
--dataset mock
# Run the native 4-GPU Qwen3-MoE 30B PEFT topology
uv run python -m torch.distributed.run --nproc_per_node=4 scripts/training/run_recipe.py \
--recipe qwen3_30b_a3b_peft_config \
--dataset tulu3
# Add long context to an existing recipe
uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \
--recipe llama3_8b_pretrain_config \
--dataset mock \
'model.seq_length=32768' \
'model.context_parallel_size=4'
# Enable CUDA graphs on any recipe
uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \
--recipe qwen3_30b_a3b_pretrain_config \
--dataset mock \
'model.cuda_graph_impl=transformer_engine' \
'model.cuda_graph_scope=[attn,moe_router,moe_preprocess]' \
'model.use_te_rng_tracker=True' \
'rng.te_rng_tracker=True'
Quick Reference: Which Recipe for My Situation?#
I want to⦠|
Start with |
GPUs needed |
|---|---|---|
Try Bridge for the first time |
|
2 |
Fine-tune a 7-8B model |
|
2β4 |
LoRA on 1 GPU |
|
1 |
Pretrain a dense 70B |
|
32β64 |
Train a small MoE |
|
16 |
Train a large MoE (235B+) |
|
256β512 |
Benchmark text-pretrain throughput |
Benchmark recipe via |
Exact encoded count |
Long-context training |
|
16+ |
VLM fine-tuning |
|
4β8 |
Diffusion training |
|
8 |
Code Anchors#
What |
Path |
|---|---|
Library recipes root |
|
Recipe |
|
Common recipe helpers |
|
Training entry point |
|
Training Slurm launcher |
|
Benchmark recipes root |
|
Benchmark compatibility launcher |
|
Benchmark recipe helpers |
|
Benchmark overrides |
|
Last signature refresh: 2026-08-03.