Megatron Bridge backend configuration reference#
Megatron Bridge integrates Megatron-Core training with Hugging Face–centric workflows. In Primus, the megatron_bridge framework is used for post-training with module preset sft_trainer.yaml, and the repository also ships a pretraining preset at primus/configs/modules/megatron_bridge/pretrain_trainer.yaml.
Recipe system#
Megatron Bridge resolves training defaults through a recipe and flavor:
recipeis a Python module path undermegatron.bridge.recipes(e.g.qwen.qwen3).flavoris the function name inside that module (e.g.qwen3_8b_finetune_config) that returns aConfigContainer.
At runtime, load_recipe_config in primus/backends/megatron_bridge/config_utils.py:
Imports
megatron.bridge.recipes.<recipe>and calls<flavor>(**filtered_backend_args)to build the baselineConfigContainer.Deep-merges Primus
backend_args(from YAML + CLI) into that dataclass via_merge_dict_to_dataclass, so user overrides sit on top of recipe defaults.
You normally specify recipe, flavor, hf_path, and dataset in the model YAML; training hyperparameters and parallelism go in module overrides or experiment module overrides (modules.post_trainer.overrides for SFT/post-training, modules.pre_trainer.overrides for pretraining examples).
1. Base module parameters#
From primus/configs/modules/megatron_bridge/sft_trainer.yaml (extends module_base.yaml). Pretraining examples use pretrain_trainer.yaml instead.
Parameter |
Default |
Description |
|---|---|---|
|
|
Module participates in the training graph. |
|
|
Inherited from |
|
|
File sink verbosity. |
|
|
Stderr sink verbosity. |
2. Training#
Parameter |
Default |
Description |
|---|---|---|
|
|
Backend stage selector. Primus dispatches post-training via |
|
|
See Base module parameters. |
CLI note: The user-facing suite is posttrain (primus train posttrain --config ...). The YAML stage field selects the Megatron Bridge trainer implementation (sft), not the CLI suite name.
For Bridge pretraining, use the normal pretraining suite (primus train pretrain --config ...) with experiments that reference modules.pre_trainer.config: pretrain_trainer.yaml.
3. Fine-tuning method (PEFT)#
Primus examples set these under modules.post_trainer.overrides (see examples/megatron_bridge/configs/).
Parameter |
Example |
Description |
|---|---|---|
|
|
Parameter-efficient fine-tuning mode. |
|
|
LoRA rank (example: |
|
|
LoRA scaling alpha (same example). |
|
|
Pack multiple short sequences per microbatch when supported. |
Additional keys such as pretrained_checkpoint, use_distributed_optimizer, or cross_entropy_loss_fusion appear in larger examples and are merged into the recipe ConfigContainer when the dataclass exposes matching fields.
4. Parallelism#
Typical overrides from Megatron Bridge examples:
Parameter |
Example |
Description |
|---|---|---|
|
|
Tensor parallelism degree. |
|
|
Pipeline parallelism degree. |
|
|
Virtual pipeline stages per rank when PP > 1. |
|
|
Context parallelism degree. |
|
|
Sequence parallelism within TP groups. |
|
|
Optional Megatron FSDP path. |
5. Training hyperparameters#
Parameter |
Example |
Description |
|---|---|---|
|
|
Total training iterations. |
|
|
Global batch across data-parallel groups. |
|
|
Per-GPU microbatch before gradient accumulation. |
|
|
Training sequence length. |
|
|
Steps between evaluations. |
|
|
Steps between checkpoint saves. |
6. Learning rate#
Parameter |
Example |
Description |
|---|---|---|
|
|
Peak learning rate for fine-tuning. |
|
|
Floor learning rate after decay. |
|
|
Linear warmup length in iterations. |
|
|
Optional decay span; |
7. Precision#
Parameter |
Example |
Description |
|---|---|---|
|
|
Mixed-precision recipe for Megatron Bridge. |
|
|
Optional communication/compute overlap policy object. |
|
|
Dtype for pipeline stages when PP is enabled. |
8. Memory optimization#
Parameter |
Example |
Description |
|---|---|---|
|
|
Activation recomputation granularity. |
|
|
How recomputation is scheduled across layers. |
|
|
Number of layers per recompute group (workload-dependent). |
9. Primus-Turbo#
From sft_trainer.yaml (defaults shown).
Parameter |
Default |
Description |
|---|---|---|
|
|
Master flag for Primus-Turbo optimized kernels and paths. |
|
|
Turbo attention implementation. |
|
|
Turbo parallel linear layers. |
|
|
Turbo grouped GEMM flag for MoE paths (the preset ships this key). The former |
|
|
Fused MoE router with auxiliary loss handling. |
|
|
FP8 path inside Turbo attention. |
|
|
DeepEP-style expert-parallel integration. |
|
|
Compute-unit count hint for DeepEP. |
|
|
Use dedicated communication streams. |
|
|
Sync-free MoE scheduling stage. |
|
|
Fuse activation with probability tensors where applicable. |
|
|
Turbo RMSNorm path. |
Environment: PRIMUS_TURBO_MOE_DISPATCH_COMBINE_BACKEND (default TURBO) is read in primus/backends/megatron/patches/args/rocm_arg_validation.py to select MoE dispatch/combine behavior when Turbo MoE is active.
10. Model and dataset#
Model YAML files (qwen3_8b.yaml, qwen3_32b.yaml, llama31_70b.yaml) supply:
Parameter |
Example |
Description |
|---|---|---|
|
|
Recipe module under |
|
|
Flavor function producing the baseline |
|
|
Hugging Face model id for weights/tokenizer flows. |
|
nested |
Example: |
Logging (optional overrides in examples): wandb_project, wandb_entity, wandb_exp_name might be set under overrides for experiment tracking when Weights & Biases is configured.
Argument merge mechanics#
MegatronBridgeArgBuilder (primus/backends/megatron_bridge/argument_builder.py) performs a deep merge of CLI and YAML into a single dict/namespace before load_recipe_config runs. Nested dicts (for example dataset or optimizer sections) combine recursively; explicit None in the merged structure can clear fields depending on merge rules in _merge_dict_to_dataclass.
Example layouts#
Under examples/megatron_bridge/configs/, per-GPU directories (for example MI300X/, MI355X/) contain full experiment YAMLs that set work_group, user_name, exp_name, workspace, and Megatron Bridge modules. Post-training examples use modules.post_trainer with config: sft_trainer.yaml; MI300X pretraining examples use modules.pre_trainer with config: pretrain_trainer.yaml. Both patterns set framework: megatron_bridge, model: <preset>.yaml, and an overrides block for parallelism, LR, precision, and related options.