Repository navigation
fix(automodel): preserve native FP32 A_log during refit - #5456
sharonyu-115 wants to merge 3 commits into
Conversation
Signed-off-by: Yuekai Zhang <[email protected]> Signed-off-by: Shuang Yu <[email protected]>
07cbc78 to
176ac81
Compare
|
/ok to test 176ac81 |
sharonyu-115
left a comment
There was a problem hiding this comment.
Thanks for splitting this out of #4963 with its own evidence. The change keeps source-FP32 A_log tensors FP32 in the Automodel refit payload and metadata, the same way e_score_correction_bias is handled, so the inference engine's fp32 A_log storage no longer receives a bf16-rounded value every refit.
What the review checked against pinned source (vLLM v0.33.0, SGLang 3003d70f, Automodel b916107a, transformers 5.16.1):
- The premise holds. vLLM and SGLang allocate
A_logfp32 and load it with a dtype-casting copy (weight_utils.py#L1543). Mamba2 engines storeAfp32 from HFA_logvia-exp(x.float())(mamba_mixer2.py#L481-L496), so Nemotron-H style models benefit too. - Metadata and payload agree on every path. Each transport sizes receive buffers from per-tensor metadata dtype (IPC vllm_backend.py#L2038-L2045, collective packed_tensor.py#L256). The pipeline-parallel exporter takes its manifest dtypes from the same generator (automodel_policy_worker.py#L671-L678, pipeline_parallel.py#L515-L520), and the draft branch applies the same function.
- The name domain is right. The predicate sees HF-adapted names, and every transformers 5.16.1 SSM model spells the leaf
A_log. - The name-list shape is the right design. C2 explains why a blanket "preserve source fp32" rule or importing Automodel's list would both be wrong.
- The new test reaches both call sites. Both literals change under bf16 rounding (0.123456 -> 0.12353515625, 0.876543 -> 0.875), the fp64 case exercises the
== float32half of the guard, and theautomodelmark routes it to the L0_Unit_Tests_Automodel_Policy shards where the skipif cannot fire silently. Not executed here (no GPU/torch on the review node); the body reports 11 passed in the nightly container. - A checkpoint fact in favour of the change: all 960 fp32
A_logvalues in Qwen3.5-35B-A3B-Base are exactly bf16-representable, which explains why the effect appears only after training moves them.
Inline comments:
- (C1) Restore the GB200 17-step A/B next to the H100 run and re-save the body with LF endings so the
pr-descriptioncheck can pass. - (C2) Docstring nit: name the owner of the fp32 set and the rule for adding to it.
FYI, no action in this PR:
- Kimi-K3 (KDA) keeps
dt_biasand the conv1d weights fp32 in both Automodel (kimi_k3/state_dict_adapter.py#L36-L44) and vLLM (kimi_gdn_linear_attn.py#L237-L239, #L265-L267). A leaf-name rule cannot express that (the conv leaf isweight). NeMo-RL has no Kimi recipe today, so this is a note for when one lands. - Follow-up idea: the fp32-preserve set has no test in a lane that can import the engine, so engine-side changes would drift silently. A vllm-lane check of the layer constructors' fp32 parameters against this set would close that.
Linters: pinned ruff v0.9.9 (check, isort, format) pass on both files; pre-commit itself could not run on the review node. CI: L0/L1 jobs were pending at review time; pr-description is red for the CRLF reason in C1.
Process note: lanes ran as named teammates (rl-expert, comment-reviewer, test-agent, bug-finder, design-reviewer, devil-advocate, comment-editor) with peer messaging; this build has no shared task list, so the leader brokered hand-offs.
nemo-rl-review: kind=self harness=claude-code/2.1.319 model=claude-fable-5-1 effort=medium review-pr-team=v3 reviewed=176ac81
…tend it Append to the _refit_tensor_dtype docstring that the preserved-name set mirrors which parameters the inference engines (vLLM, SGLang) allocate as FP32, why it cannot be derived from the trainer's source dtype (all trainer params are FP32 master weights), and the rule for adding a leaf. Addresses review comment C2 on NVIDIA-NeMo#5456. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Shuang Yu <[email protected]>
|
/ok to test 1778ce7 |
|
/ok to test ccca9ce |
|
Hi @yuki-97 would you please help review this PR? Thank you very much! |
What and why
Split out of #4963 at review request (comment): this change is independent of Automodel single-controller training and affects the existing refit path.
During Automodel refit,
_refit_tensor_dtypecasts floating-point tensors to the refit dtype (bf16) before they are streamed to the inference engine. SSMA_logparameters are stored as FP32 in the checkpoint and stay FP32 in the inference model, so the payload was downcast to bf16 and then copied back into FP32 storage, losing precision on the way.This PR keeps source-FP32
A_logtensors in FP32 in the refit payload and in the refit metadata, the same waye_score_correction_biasis already handled. A unit test,test_refit_ssm_a_log_precision_and_metadata, covers the payload dtype and the metadata.The change is by @yuekaizhang; it is cherry-picked unchanged from #4963 and rebased on current
main(f35d1c2). The only rebase-time edit is in the new unit test: theobject.__new__worker fixture now setspipeline = Noneand_weight_exporter = None, whichprepare_refit_inforeads since #4960 / #4963 landed (same as the neighbouring fixtures onmain).Issues
None
Convergence / perf / functionality proof
V1 Stack validation - H100, 2 x 8 GPUs, 200 steps (W&B)
Same recipe (
grpo-qwen3.5-35ba3b-2n8g-automodel-ep16, stock 2 x 8 layout, seed 42) repeated on H100 with checkpoint-resume across chained 4-hour jobs. "Before" ismainat e77523f, "after" is e77523f plus this change (07cbc78). Before reached step 192 and after reached step 196 before the job chain ran out, so the table covers the 192 steps both runs completed.W&B project: https://wandb.ai/nv-welcome/nemo-rl-pr5456-alog-fp32 (runs before, after).
train/gen_kl_errortrain/token_mult_prob_errortrain/policy_kl_errortrain/sampling_importance_ratiotrain/rewardtrain/losstrain/grad_normtrain/num_masked_seqs_by_logprob_errortiming/train/total_step_time(s)Last 50 common steps (143-192):
gen_kl_errorbefore 0.000856 vs after 0.000786;token_mult_prob_errorbefore 1.0313 vs after 1.0172;rewardbefore 0.617 vs after 0.621.Generation/training mismatch metrics (blue = before, orange = after):
Reward, loss, grad norm:
Reading:
train/gen_kl_erroris lower with the fix on 85% of steps (mean 0.000859 vs 0.000816). Both arms are a single seed and per-step values are autocorrelated, so the Welch p column is indicative only; the 85%-of-steps figure and the last-50-step means are the summaries to rely on. The two runs overlap for the first ~20 steps and then separate, with the gap growing over training. This is expected from the checkpoint: all 960 FP32A_logvalues in Qwen3.5-35B-A3B-Base are exactly bf16-representable (low 16 bits zero), so the bf16 payload is lossless at step 0 and only loses precision once optimizer updates moveA_logoff the bf16 grid.token_mult_prob_error3.0,policy_kl_error1.98; step 158: 1.65 / 0.63). The after run's worst step is 70 (1.09 / 0.074). This is a single seed per arm and the trajectories diverge after the first ~20 steps, so the spike count is suggestive rather than conclusive; the per-stepgen_kl_errorshift is the robust signal.Unit test on the rebased branch (
test_refit_ssm_a_log_precision_and_metadata, 3 parametrizations, plus the other-k refittests intest_automodel_worker.py) run in the CI nightly container: 11 passed, 0 failed (job 23190116,rl.nightly.sqsh2026-11-28).GB200, 4 x 4 GPUs, 17 steps (TensorBoard)
Original matched before/after run of
grpo-qwen3.5-35ba3b-2n8g-automodel-ep16(non-single-controller path) on Qwen3.5-35B-A3B-Base, whose checkpoint has 30 FP32A_logtensors of shape(32,). "Before" ismainat e77523f; "after" is the same commit plus this change. Same recipe, seed and overrides on both sides.Layout: 4 nodes x 4 GB200 GPUs instead of the recipe's 2 x 8, with
cluster.num_nodes=4 cluster.gpus_per_node=4 policy.generation.vllm_cfg.tensor_parallel_size=4, W&B off, andpolicy.automodel_cfg.env_vars.PYTORCH_CUDA_ALLOC_CONF=expandable_segments:False. Both jobs hit the 150-minute limit before step 20, so the table compares the first 17 steps, which both runs completed. There are no W&B links; the numbers come from the TensorBoard scalars.train/gen_kl_errortrain/token_mult_prob_errortrain/policy_kl_errortrain/sampling_importance_ratiotrain/rewardPer-step
train/gen_kl_error:Per-step
train/token_mult_prob_error:Reading: over 17 steps the two runs are within step-to-step noise. This matches the checkpoint fact above: at step 0 the bf16 payload is lossless, so a short run cannot show a difference. The longer H100 run above is where the
gen_kl_errorseparation becomes visible.Needs upstream changes
None
PR commands and CI
CI:Lfast: the default for most PRs. Runs a fast test subset.CI:L1: dependency or container changes (pyproject.toml,uv.lock,Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.CI:docs: docs-only changes. Runs doc tests only./ok to test <full-commit-sha>: start CI for that commit. Post again after each push./internal-ci test-case=<job>: run NVIDIA's internal nemo-ci pipeline for the PR head; eligible teams only./review: automated review comments. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.