Megatron policy can't start from a builder-format Megatron Bridge checkpoint (`pretrained_checkpoint.format: megatron_bridge`)
What is wrong
Starting a Megatron policy from a Megatron Bridge checkpoint that Bridge saved in its new builder format fails during policy setup:
(MegatronPolicyWorker) nemo_rl/models/policy/workers/megatron_policy_worker.py:987 __init__
nemo_rl/models/megatron/setup.py:2634 setup_model_and_optimizer
megatron/bridge/models/model_provider.py:682 get_model
megatron/bridge/models/model_provider.py:781 _create_model
megatron/training/models/gpt.py:203 __getattr__
AttributeError: Neither GPTModelConfig nor TransformerConfig has any attribute 'provide'.
This already affects main. The current Bridge pin (7e9dcd609, #4752) converts Qwen3 dense through the builder, so a Qwen3 checkpoint made with Bridge's convert.sh import fails today. The next bump (#4832, 000920a) adds Qwen2/2.5 and MiMo, OLMoE, GLM-4.5, Hy V3, MiniMax-M2, Ling MoE V2, EXAONE 4.0, ERNIE 4.5, Beam and GPT-OSS. Checkpoints saved by Bridge training runs whose recipes call get_model_config() (the Llama 3 and Qwen3 recipes at the current pin) have the same format, so they should fail the same way (from the code, not run).
The other routes are unaffected. Starting from an HF model id (NeMo RL converts it itself), format: megatron_lm, resume, LoRA and refit all pass on Bridge main; see Validation.
Why
Bridge is moving model construction from GPTModelProvider to ModelConfig + ModelBuilder. For migrated families, Bridge's own conversion (AutoBridge.import_ckpt, which scripts/conversion/convert.sh import calls) builds the model through the builder (auto_bridge.py#L1744) and saves that config (model_load_save.py#L643). The checkpoint's run_config.yaml then has _target_: megatron.bridge.models.gpt.model_config.BridgeGPTModelConfig and a _builder_ key.
For format: megatron_bridge, setup_model_config reads that file with load_model_config(), which returns whatever class it names (model_load_save.py#L316). Here that is a BridgeGPTModelConfig, not a provider. The flat overrides that follow still work, because the builder config forwards flat reads and writes to its nested transformer config. Setup fails at the first provider-only call: get_model(), which calls provide() (model_provider.py#L781). With PEFT on it should fail one call earlier, at register_pre_wrap_hook() (from the code, not run).
The tests don't catch it: phase 2 of grpo_megatron_mbridge_restore.sh restores NeMo RL's own conversion, which goes through to_megatron_provider(load_weights=True) and always saves a provider (community_import.py#L176).
To reproduce:
# Bridge checkout (main, or NeMo RL's pin for Qwen3), in an environment with APEX (see Regression test)
./scripts/conversion/convert.sh import --hf-model Qwen/Qwen3-0.6B --megatron-path /tmp/qwen3-mb
# NeMo RL main
cat > /tmp/restore.yaml <<'EOF'
defaults: /path/to/RL/examples/configs/grpo_math_1B_megatron.yaml
checkpointing:
pretrained_checkpoint:
path: /tmp/qwen3-mb/iter_0000000
format: megatron_bridge
EOF
uv run python examples/run_grpo.py --config /tmp/restore.yaml \
policy.model_name=Qwen/Qwen3-0.6B cluster.gpus_per_node=2 grpo.max_num_steps=2
Fix
When load_model_config() returns a builder config, rebuild the provider from the HF config the way the megatron_lm route already does (setup.py#L1012-L1024), and keep loading the weights from the checkpoint:
--- a/nemo_rl/models/megatron/setup.py
+++ b/nemo_rl/models/megatron/setup.py
@@ -1071,6 +1071,19 @@ def setup_model_config(
)
raise
+ # Bridge checkpoints written through its builder path (run_config.yaml has a
+ # `_builder_` key) load as a ModelConfig, which has no provide() or
+ # register_pre_wrap_hook(). Rebuild the provider from the HF config, as the
+ # megatron_lm route does; the weights still load from this checkpoint.
+ if not isinstance(model_cfg, ModelProviderMixin):
+ from transformers import AutoConfig
+
+ hf_cfg = AutoConfig.from_pretrained(hf_model_name, trust_remote_code=True)
+ model_cfg = AutoBridge.from_hf_config(hf_cfg).to_megatron_provider(
+ load_weights=False
+ )
+ derive_provider_from_hf = True
+
# Construct the final provider with model-only overrides before applying
Trade-off: the architecture comes from the HF config, not from the checkpoint, the same as format: megatron_lm today. An architecture change saved only in the checkpoint's run_config.yaml would be ignored. The longer-term option is to build the policy through Bridge's ModelBuilder directly, since Bridge is deprecating provider_bridge.
Regression test: add a phase to tests/functional/grpo_megatron_mbridge_restore.sh that converts with Bridge's converter (builder format for migrated families) and restores with format: megatron_bridge. In NeMo RL's container, Bridge's converter currently fails for an unrelated reason: Bridge turns on gradient accumulation fusion whenever Transformer Engine imports, and MCore's output layer then needs APEX's fused_weight_gradient_mlp_cuda, which the image doesn't have. That is a Bridge-side problem. Until it's fixed, the test helper can build the checkpoint with gradient_accumulation_fusion=False on the model config.
Validation
H100, 2 GPUs per run, NeMo RL f6d0c3d in NeMo RL's nightly container from 2026-10-21 (built after #4752; dependency fingerprint matches). "Bridge main" means Bridge 4aa119666 with its MCore (89b28875) first on PYTHONPATH. Bytecode traces show that every Bridge and MCore import in those runs resolved to that tree. The one exception is the restore test's Megatron-LM conversion helper, which adds the vendored MCore on purpose.
Each restore run is 2 GRPO steps of grpo_math_1B_megatron.yaml with the grpo_megatron.sh overrides and the restore test's metric gates. "Matches" means train/reward, train/mean_gen_tokens_per_sample, train/token_mult_prob_error and train/loss are identical at both steps to the same run started from the HF model id. So the weights loaded from the checkpoint are exactly the converted HF weights.
| Checkpoint from Bridge's converter | Bridge | Without the fix | With the fix |
|---|---|---|---|
| Qwen2.5-0.5B, builder format | main 4aa119666 | AttributeError |
Passes; matches the HF-id run |
| Qwen3-0.6B, builder format | main 4aa119666 | AttributeError |
Passes; matches the HF-id run |
| Qwen3-0.6B, builder format | pin 7e9dcd609 | AttributeError |
Passes; matches the HF-id run |
| Qwen2.5-0.5B, provider format | pin 7e9dcd609 | Loads | Passes (new branch not taken) |
grpo_megatron_mbridge_restore.sh, 3 phases |
main 4aa119666 | Passes | Passes |
Without the fix, Bridge main also passes grpo_megatron.sh, grpo_megatron_mbridge_restore.sh, grpo_megatron_lora.sh, a non-colocated refit run, sft_resume_diamond.sh and test_converters.sh. So the builder migration doesn't change NeMo RL's other routes.
Related, separate from this bug
- A provider-format
convert.shcheckpoint recordsuse_cpu_initialization: Trueandgradient_accumulation_fusion: Trueinrun_config.yaml. On themegatron_bridgeroute NeMo RL resets the fusion flag (setup.py#L1829) but neveruse_cpu_initialization, so the policy is built on CPU. With such a Qwen2.5 checkpoint, the step-1 loss matched the HF-id run but the step-1 grad norm differed (7.542 vs 7.526), and step 2 drifted. The fix above avoids this for builder-format checkpoints only. - On shared nodes, Ray discovery picks up other clusters.
init_ray()first callsray.init(address="auto")(virtual_cluster.py#L488), which attaches to any Ray cluster on the node, including another user's. The memory tracker callsmemory_summary()without an address (memory_tracker.py#L43), which raisesFound multiple active Ray instanceswhen more than one cluster runs there. PointingRAY_ADDRESSat the job's own head avoids both.