Repository navigation
fix(automodel): merge LoRA into refit weights under activation checkpointing - #4810
Merged
yuki-97 merged 5 commits intoOct 22, 2026
Conversation
…ointing With activation_checkpointing: true Automodel wraps every decoder block in torch's CheckpointWrapper. state_dict() strips the wrapper's "_checkpoint_wrapped_module." component from its keys but named_modules() keeps it, so the module map that the refit exporter built from named_modules() never matched a per-layer state_dict weight name. _maybe_merge_lora_weight then found no LinearLoRA for those weights and the refit streamed bare base weights to the inference engine: generation kept sampling the base model for the whole run while training updated the adapters (only LoRA modules outside the wrapper, e.g. lm_head, were merged). Key the module map by Automodel's canonical_parameter_fqn(), the same state-dict spelling its checkpoint and optimizer code use, so the exporter follows Automodel's naming contract instead of hard-coding wrapper prefixes. Raise if a LinearLoRA still has no matching state_dict weight rather than silently dropping its update. Merge in fp32 and round once so the refit tensor equals an offline fp32 merge of the same adapter (the bf16 two-step merge could differ by one ulp per element). Tests: the checkpoint-wrapper case fails on main (refit tensor equals the base weight); the guard and the fp32 merge each have a test. Co-authored-by: sniu <[email protected]> Signed-off-by: Yuekai <[email protected]>
… catches a broken refit Before/after runs of grpo-qwen3-8B-base-1n8g-automodel-lora (2 x 4 GB200 GPUs, 20 steps) with and without the LoRA refit fix: with the adapters merged into the refit weights gen_kl_error stays at 0.0010-0.0011 for all 20 steps; with the inference engine stuck on the base weights it climbs to 0.0013-0.0015 over steps 17-20, while max reward (0.44 vs 0.37) and the 256-sample validation accuracy stay within noise. The previous 0.002 bound passed both runs, so the nightly never caught the bug. Bound the final and maximum gen_kl_error at 0.0013 instead. Signed-off-by: Yuekai <[email protected]>
Contributor
Author
|
/ok to test 9c12c91 |
Signed-off-by: Yuekai <[email protected]>
Contributor
Author
|
/ok to test bd46301 |
RayenTian
reviewed
Oct 21, 2026
RayenTian
reviewed
Oct 21, 2026
Contributor
|
Thanks a lot for adding this @yuekaizhang ! Left some comments. |
…ollow-up Signed-off-by: Yuekai <[email protected]>
Contributor
Author
|
/ok to test f107761 |
Contributor
Author
|
/ok to test 633cdf1 |
RayenTian
approved these changes
Oct 21, 2026
3 of 4 tasks
rahul-sarvam
added a commit
to rahul-sarvam/RL
that referenced
this pull request
Oct 31, 2026
Merge Automodel's grouped expert adapters into gate_and_up_projs and down_projs before HF conversion during merged refitting, and exclude the bare adapter parameters from both streamed weights and refit metadata. Preserve canonical module names under activation checkpointing and extend the reachability guard from NVIDIA-NeMo#4810 to both grouped expert base weights. Compute the per-expert A @ B delta in fp32 and cast once, matching the dense LoRA merge without modifying training parameters in place. Document explicit expert targeting and lora_refit_mode: merged. Cover gated/non-gated GroupedExpertsLoRA and GroupedExpertsDeepEPLoRA layouts, checkpoint wrappers, missing weights, metadata, precision, and two-rank CPU DTensor gathering. The 33 expert cases and 33 existing LoRA/refit regressions pass against Automodel b916107a on CPU. Signed-off-by: Rahul A R <[email protected]>
soluwalana
pushed a commit
to soluwalana/RL
that referenced
this pull request
Oct 31, 2026
Merge Automodel's grouped expert adapters into gate_and_up_projs and down_projs before HF conversion during merged refitting, and exclude the bare adapter parameters from both streamed weights and refit metadata. Preserve canonical module names under activation checkpointing and extend the reachability guard from NVIDIA-NeMo#4810 to both grouped expert base weights. Compute the per-expert A @ B delta in fp32 and cast once, matching the dense LoRA merge without modifying training parameters in place. Document explicit expert targeting and lora_refit_mode: merged. Cover gated/non-gated GroupedExpertsLoRA and GroupedExpertsDeepEPLoRA layouts, checkpoint wrappers, missing weights, metadata, precision, and two-rank CPU DTensor gathering. The 33 expert cases and 33 existing LoRA/refit regressions pass against Automodel b916107a on CPU. Signed-off-by: Rahul A R <[email protected]>
soluwalana
pushed a commit
to soluwalana/RL
that referenced
this pull request
Oct 31, 2026
Merge Automodel's grouped expert adapters into gate_and_up_projs and down_projs before HF conversion during merged refitting, and exclude the bare adapter parameters from both streamed weights and refit metadata. Preserve canonical module names under activation checkpointing and extend the reachability guard from NVIDIA-NeMo#4810 to both grouped expert base weights. Compute the per-expert A @ B delta in fp32 and cast once, matching the dense LoRA merge without modifying training parameters in place. Document explicit expert targeting and lora_refit_mode: merged. Cover gated/non-gated GroupedExpertsLoRA and GroupedExpertsDeepEPLoRA layouts, checkpoint wrappers, missing weights, metadata, precision, and two-rank CPU DTensor gathering. The 33 expert cases and 33 existing LoRA/refit regressions pass against Automodel b916107a on CPU. Signed-off-by: Rahul A R <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Fixes the silent LoRA refit failure on the Automodel (DTensor) backend when
activation_checkpointing: true(#4470): the adapters trained on the policy were never mergedinto the weights sent to the inference engine, so vLLM kept sampling from the base model for the
whole run while
lora_A/lora_Bkept moving. Reported on Nemotron 3.5 Lightning (#4470),Nemotron 3.5 Super (#4259) and Nemotron 3.5 Super VL (a partner run: train reward flat at ~0.45,
~0.83 with the fix). Every Automodel LoRA + activation-checkpointing recipe is affected, including
grpo-qwen3-8B-base-1n8g-automodel-lorain the nightlies.Root cause. With activation checkpointing Automodel wraps every decoder block in torch's
CheckpointWrapper.state_dict()strips the wrapper's_checkpoint_wrapped_module.componentfrom its keys,
named_modules()keeps it, and_module_params_generatorbuilt its module mapfrom
named_modules():named_modules()layers.0._checkpoint_wrapped_module.q_projstate_dict()layers.0.q_proj.weight_maybe_merge_lora_weighttherefore found noLinearLoRAfor any weight inside a block andreturned the bare base tensor; only LoRA modules outside the wrapper (e.g.
lm_head) were merged.Fix.
nemo_automodel.shared.parameter_names.canonical_parameter_fqn(),the same state-dict spelling Automodel's own checkpoint and optimizer code use, so NeMo RL follows
Automodel's naming contract instead of hard-coding wrapper prefixes.
LinearLoRAstill has no matchingstate_dictweight, so this class of failure is loudinstead of a slowly growing
gen_kl_error.(the bf16 two-step merge could differ by one ulp per element).
Tests.
test_merges_lora_inside_activation_checkpoint_wrapperfails onmain(the refit tensorequals the base weight);
test_raises_when_lora_module_has_no_state_dict_weightcovers the guard;test_bf16_lora_merge_matches_offline_fp32_mergecovers the fp32 merge.Nightly.
grpo-qwen3-8B-base-1n8g-automodel-lorabefore/after, 2 x 4 GB200 GPUs, 20 steps,same base commit, only this fix differing:
gen_kl_errorsteps 1-20A longer 100-step run of the same recipe on 1 x 4 GB200 GPUs shows the failure is not a small
drift: without the fix the generator never receives the adapter, so the trained policy walks
away from it until the run collapses, while the fixed run keeps learning.
gen_kl_error@10 / 50 / 80 / 100Related. Consolidates #3953 (anubhutivyas: prefix strip + guard + fp32 merge) and #4259
(zhiyuanma-agents: prefix strip incl.
_orig_mod, fp32 merge, tests), both written against the olddtensor_policy_worker_v2.pyand no longer applying tomain, plus the local patch fromsniu@salesforce (co-authored here) that first used
canonical_parameter_fqn._orig_mod.(
torch.compile) is not handled: NeMo RL's Automodel path does not compile the policy, andOptimizedModuledoes not strip the prefix fromstate_dict()keys the wayCheckpointWrapperdoes; if that changes it belongs in Automodel's
canonical_parameter_fqn.Usage
No user-facing change. Any Automodel recipe with
automodel_cfg.lora_cfg.enabled: trueandautomodel_cfg.activation_checkpointing: truenow refits the merged weights.