Repository navigation
feat(vllm): fp32 LM head for all models via vLLM head_dtype - #5061
Merged
Merged
Conversation
vllm_cfg.fp32_lm_head now sets vLLM's native hf_overrides head_dtype="float32" (vllm-project/vllm#48390, in the pinned 0.29.0), which runs the lm_head GEMM on the bf16 operands with an fp32 output for any model whose lm_head is unquantized. That is the same GEMM as Megatron's logit_dtype=float32 (policy.megatron_cfg.fp32_lm_head), so the matched pair now removes the head's bf16 rounding from the generation/training logprob mismatch for every model, not only Nemotron-H. With head_dtype set, vLLM's LogitsProcessor no longer calls lm_head.forward or quant_method.apply, so the Nemotron-H source patch would be dead code; it is removed together with its env-var plumbing and the non-Nemotron-H warning. NRL_VLLM_FP32_LM_HEAD in vllm_cfg.env_vars and a head_dtype in the hf overrides are rejected so the flag stays the single, validated switch. The functional test now checks the result instead of a log line: with logprobs_mode=raw_logits the sampled token's raw logit is bf16-representable with the bf16 head (control) and off the bf16 grid with the fp32 head, on Qwen3-0.6B (tied embeddings) and Nemotron-3-Nano-4B. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Nitin Vegesna <[email protected]>
Resolve the conflict in nemo_rl/models/policy/utils.py: keep main's LoRA refit helpers (#3964) and drop the _NEMOTRON_H_* constants, which this branch no longer uses. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Nitin Vegesna <[email protected]>
Contributor
Author
|
/ok to test c1f4981 |
ZhiyuLi-Nvidia
enabled auto-merge (squash)
November 4, 2026 00:54
ZhiyuLi-Nvidia
approved these changes
Nov 4, 2026
isomap
added a commit
to isomap/RL
that referenced
this pull request
Nov 5, 2026
Brings in NVIDIA-NeMo#5061 (vLLM fp32 LM head via head_dtype), NVIDIA-NeMo#5058 and NVIDIA-NeMo#4825. No conflicts; NVIDIA-NeMo#5061 changes the fp32_lm_head comment next to this branch's logprobs_mode comment in vllm/config.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hayate Iso <[email protected]>
yeyu-nvidia
added a commit
to yeyu-nvidia/RL
that referenced
this pull request
Nov 25, 2026
Conflict resolutions: - vllm_quant_backend.py / vllm_modelopt.py: keep NVIDIA-NeMo#3945 native real-quant; NVIDIA-NeMo#5153 only ported the legacy nemo_modelopt path, which NVIDIA-NeMo#3945 removes. - prepare_nccl_reshard_refit_info: keep the draft-aware manifest, add NVIDIA-NeMo#5153 follow_source_reshard_path. - _finish_train_step_body: keep the CP-aware draft count reductions, add NVIDIA-NeMo#5153 in-loss sequence-filter survivor counts. - RADIO final LayerNorm patch: NVIDIA-NeMo#5153 0.33 anchors, but load through the param weight_loader hook so native refit tracks it (38cd96a). - Drop the stale _patch_vllm_nemotron_h_fp32_lm_head (superseded upstream by NVIDIA-NeMo#5061; referenced an undefined constant, never called). - Real-quant suites: grep quantization=modelopt only (0.33 dropped the Detected ModelOpt NVFP4 checkpoint line). - uv.lock: NVIDIA-NeMo#5153, to be re-locked. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ye Yu <[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 ?
Makes
policy.generation.vllm_cfg.fp32_lm_headwork for every model, not only Nemotron-H. It now sets vLLM'snative
hf_overrides={"head_dtype": "float32"}(vllm-project/vllm#48390,in the pinned vLLM 0.29.0) and removes the Nemotron-H-only source patch.
Issues
Follow-up to #4096. Today
vllm_cfg.fp32_lm_head=trueon any non-Nemotron-H model only produces a warning, andgeneration keeps the BF16 head. The pairing that
validate_fp32_lm_head_configenforces therefore ends upeffectively one-sided for Qwen, Llama and other models, which its own error message says makes the mismatch worse.
Changes
vllm_worker._apply_fp32_lm_head: when the flag is set, addshead_dtype="float32"to the engine'shf_overrides.LogitsProcessorthen runs the lm_head GEMM on the BF16 operands with an FP32 output(
torch.mm(..., out_dtype=float32)). That is the same GEMM as Megatron'slogit_dtype=float32, whichmegatron_cfg.fp32_lm_headsets.lm_headbydefault.
_patch_vllm_nemotron_h_fp32_lm_head, theNRL_VLLM_FP32_LM_HEADenv plumbing, and thenon-Nemotron-H warning, together with the HF-config fetch that warning needed in
Policy.__init__. Oncehead_dtypeis set, vLLM never callslm_head.forwardorquant_method.apply, so the patch would be dead code.NRL_VLLM_FP32_LM_HEADinvllm_cfg.env_varsis still rejected, now with "no longer read".head_dtypeinpolicy.hf_config_overridesorgeneration.vllm_kwargs.hf_overridesis rejected, so theflag stays the single switch covered by the trainer-match check.
head_dtypeoverride raises.tests/unit/models/generation/test_vllm_fp32_lm_head.py, including a@pytest.mark.vllmtest that pinsvLLM's
head_dtypecontract.smaller tests.
tests/functional/vllm_fp32_lm_head.sh): now checks the numerics directly instead of a logline.
logprobs_mode="raw_logits", so vLLM returns the sampled token's raw logit.the BF16 grid.
Usage
Validation
Run on H200 ×2 with the locked environment (
uv sync --locked --extra vllm --group test, vLLM 0.29.0), main at4d464d5 vs this PR:
test_vllm_patches.py,test_policy_validation.py,test_vllm_fp8_hf_overrides.py,test_vllm_fp32_lm_head.py(new)--vllm-onlyQwen/Qwen3-0.6B(tied embeddings)nvidia/NVIDIA-Nemotron-3-Nano-4B-BF16_apply_fp32_lm_headforced to a no-opfp32 head looks bf16-rounded)meta-llama/Llama-3.2-1B) because therunner had no HF token.
--vllm-onlycountstays at 16: the new
head_dtypecontract test replaces the Nemotron-H source-anchor test.tensor_parallel_size=2,enforce_eager=False(FULL_AND_PIECEWISEgraphs captured).raw_logits: fp32 head 64/64 off the bf16 grid, bf16 head 0/64, on both models.processed_logprobs(what training consumes): every matched greedy token differs between the bf16 and fp32heads (42/42 Qwen, 51/51 Nemotron; mean |Δ| ≈ 0.013–0.015). So the fp32 logits reach
log_softmax; vLLM'ssampler only upcasts.
NEMO_RL_PY_EXECUTABLES_SYSTEM=1, so all actors share one venv, andwith
deep_ep/deep_gemmnot installed. Neither is used by these models.Why this matters: on Qwen3-8B GRPO in NeMo-RL (
grpo_math_8B_megatron, nightly 3cde458 with vLLM 0.29.0, oneGB200 node per arm, 3 steps, seed 42, plus a replicate), an FP32 LM head on both sides cut
gen_kl_error74%(7.5e-4 → 2.0e-4; the replicate is within 2%) and
token_mult_prob_error − 1by 49%. Megatron's FP32 head alonegives only −37%. Setting
policy.generation.vllm_kwargs.hf_overrides.head_dtypeby hand does not work in GRPO:grpo.pyoverwritesvllm_kwargs["hf_overrides"]withpolicy.hf_config_overrides(ppo.py and distillation.py dothe same), so the override never reaches vLLM. (The two-sided run above patched that line to merge the dicts.) This
PR sets
head_dtypeinside the vLLM worker, after that overwrite. Today a two-sided setup only works forNemotron-H, because NeMo-RL rejects one-sided configs; this PR makes it reachable for other models.
Before your PR is "Ready for review"
Pre checks:
Additional Information
fp32_lm_headand touchvllm/config.pyandpolicy/utils.py. Whichever lands second needs a small rebase.VllmGenerationWorker, so theynever had the FP32 head and still do not.
🤖 Generated with Claude Code