Skip to content

feat(modelopt): add format-general real-quant vLLM rollout - #3945

Open
mxinO wants to merge 181 commits into
mainfrom
mxin/general-real-quant-refit
Open

mxinO wants to merge 181 commits into
mainfrom
mxin/general-real-quant-refit

Conversation

@mxinO

@mxinO mxinO commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Adds format-general ModelOpt real-quant rollout to NeMo-RL.

  • builds the vLLM deployment configuration from the calibrated policy before generation startup
  • streams ModelOpt-packed weights and format-owned sidecars through the Megatron-Bridge export plan
  • supports per-layer and mixed schemas without format tables in NeMo-RL
  • resolves grouped Hugging Face MoE mappings to native per-expert refit tensors through Megatron-Bridge
  • uses vLLM native layerwise reload for repeated real-quant refits
  • removes the prior custom NVFP4 packing, scale mapping, and quantization-method path, including the w4a4/w4a16 mode helpers (resolve_nvfp4_real_quant_mode, build_vllm_modelopt_nvfp4_config, and nvfp4_quant_algo from build: update Megatron-Bridge and its runtime dependencies #5005). The mode was derived from policy.quant_cfg anyway; the calibrated export's own quantization_config is now the single source for the rollout format
  • preserves registered NVFP4 MoE scale storage and graph-captured kernel references during native reload
  • shares real-quant config validation and vLLM config preparation (validate_real_quant_policy_config, prepare_real_quant_generation_config) between GRPO and distillation; the policy-first startup sequence is written out in each entrypoint. Fake-quant generation is unchanged

A rollout format is qualified when ModelOpt can export its canonical tensors and the pinned vLLM ModelOpt loader selects the intended native method for that exact schema. NeMo-RL does not translate unsupported schemas. Depending on vLLM, they may be rejected or may select an unquantized fallback, so representative native methods must be inspected before qualification.

Online refit call flow

ModelOpt real-quant online refit caller path

Collective refit replaces the IPC/ZMQ transport calls with broadcast_weights_for_collective() and update_weights_from_collective(); the export and native vLLM reload paths are unchanged.

Issues

Follows #5005 (merged), which brought the Megatron-Bridge, ModelOpt and runtime versions this PR builds on.

Convergence / perf / functionality proof

Validation

After the review follow-ups (head eb87715d6): ruff and pyrefly are clean (baseline pruned), and 1,122 unit tests plus 254 vLLM-marked tests pass locally. The later RADIO and self-review fixes (through 6a56638e5) pass the touched vLLM (268) and default-lane (564) tests locally; their Megatron-worker tests run in CI. Two nightly recipes were added: Qwen3-1.7B QA distillation with real-quant rollout (GB200) and Qwen3-8B DAPO W4A16 non-colocated. The real-quant nightlies, including both new recipes, are running on this head; results will be added here.

After merging main (vLLM 0.33.0): conflicts were resolved against main's vLLM 0.33 code and independently reviewed; every vLLM API the real-quant patches use (ModelOpt MoE/linear methods, MoE backend enums, moe_quant_config/moe_kernel, layerwise reload) was checked against v0.33.0. Locally, the real-quant config (78), vLLM backend (202), patches (41), RADIO native vision refit including CUDA (36 + 7), refit loader (16), GRPO (507), PPO (113), distillation (36) and config-validation (447) unit tests pass. Since then, full CI passes on the vLLM 0.33 heads (85/85 checks), and the real-quant nightlies ran on vLLM 0.33 (pipeline 83132280): Qwen3-30B-A3B W4A4 real-quant GRPO passed with quantization=modelopt_fp4 (gen-KL 0.0159, JS 0.0043); Nano W4A16 real-quant passed (gen-KL 0.0012, max token-mult-prob error 1.026); Qwen3-1.7B QA distillation passed; Qwen3-8B DAPO W4A16 met its metric gates (gen-KL max 0.00127) after updating a stale log check. The benchmark and qualification results below were measured on vLLM 0.29.

Earlier: independent aggregate source and dependency-lock review is clean. Fresh qualification of the updated shared stack passed 34 Megatron export/refit tests, eight optimizer/offload tests, and 470 vLLM/refit tests, with no skips or failures. These include installed Bridge fake-quant discovery, four-rank export-group coordination, canonical CPU/GPU byte parity, GDN fake-refit row preservation, and immediate/after-ACK IPC coverage and failure cleanup. Locked native environments and Bridge/export and vLLM ModelOpt plugin imports passed. Shared dependency qualification in #5005 separately covers training/reference/checkpoint and upstream grouped/head/GDN/pipeline-scale regressions. Full CI for these updated heads is pending.

Earlier focused startup validation with the now-pinned Omni Bridge fix passed 72 tests: 15 calibration, 25 Bridge media-export, 8 worker-loading and 24 composed native vision-refit cases, with no skips or failures. These check initial/repeated media parameter values and storage, late LayerScales, folded-checkpoint defaults and CUDA-graph replay. Actual tiny Gemma2/Gemma3 constructors also passed dummy initialization, repeated native reload, derived-normalizer storage checks and embedding-graph replay, including a negative control. These are focused module/configuration checks, not full Super media-model or training qualification.

Earlier functional qualification includes:

  • focused NeMo-RL real-quant unit suites and branch linters passed
  • dense W4A16 native-loader functional training completed repeated refits with finite loss and KL
  • matched Qwen3-8B runs completed 150 steps for BF16-attention control and MXFP8-attention treatment, both with NVFP4 W4A16 MLP
  • a four-node Qwen3.5 grouped-MoE W4A4 job completed two GRPO steps and repeated native vLLM refits with finite loss, KL, and reward

Earlier native-layer qualification also passed 70 exact CUDA-graph comparisons after changing packed weights and scales, with captures before and after refit. These cover layer reload and scale preservation. The earlier functional and native-layer results used prior revisions; the benchmark below identifies its measured revision separately.

BF16 vs fake/real NVFP4 W4A4 benchmark

Qwen3-30B-A3B; 128 prompts × 16 responses = 2,048 responses per update; total sequence cap 32,768. Each arm used four GB200 nodes / 16 GPUs, training TP2/CP2/EP16/ETP1 and rollout TP1/EP1, with CUDA graphs enabled, eight concurrent sequences per engine and a 32 GiB KV-cache budget per engine. Fake and real quantization used the same calibrated routed-expert NVFP4 recipe.

The tables report update 3 after two warmup updates, measured at c2b0d063, before the latest compatibility fixes. All three arms completed three finite updates and repeated trained-weight refits/rollouts.

Stage elapsed time (seconds)

Lower is better. Refit is included in preparation, not an additional stage to sum.

Stage BF16 Fake W4A4 Real W4A4
Preparation, including refit 9.23 7.70 30.99
↳ Refit 5.33 3.74 26.62
Rollout 1,275.26 1,606.21 1,042.61
Policy/reference logprobs 65.84 68.66 63.65
Policy training 194.07 252.69 253.32
Full update 1,547.52 1,938.43 1,393.70

Sampled peak GPU memory (GiB/GPU)

Maximum whole-device memory across all 16 GPUs during each stage, sampled every 200 ms; these are sampled, not continuous, peaks.

Stage BF16 Fake W4A4 Real W4A4
Preparation 120.93 129.58 66.95
↳ Refit 120.93 127.55 66.95
Rollout 113.91 129.58 90.52
Policy/reference logprobs 184.30 182.33 183.94
Policy training 75.45 92.79 91.50
Full-update peak 184.30 182.33 183.94

Real W4A4 rollout throughput was 14,134 output tokens/s, versus 11,548 for BF16 and 9,185 for fake quantization: 1.224× and 1.539×, respectively. Full updates were 9.94% / 28.10% shorter. Refit and policy training were still slower than BF16, and higher-precision logprob computation kept the full-update memory peak near 182–184 GiB/GPU.

Qualification: Fake quantization required ModelOpt QDQ with the Triton MoE backend; BF16 and real quantization used native TRTLLM. These are single measured warmed updates on separate exclusive node groups, not repeated statistical estimates, quality-parity evidence or demonstrated larger-batch/fewer-node capacity. Full-update timers exclude subsequent JSONL/logging overhead.

Qwen3-8B mixed-format qualification

The matched training comparison covers common steps 31-150:

  • control: BF16 attention + NVFP4 W4A16 MLP
  • treatment: MXFP8 attention + NVFP4 W4A16 MLP
  • final validation reward/accuracy: 0.2168 control, 0.2012 treatment

Qwen3-8B training and validation reward comparison

MXFP8 attention projection speed

GB200, vLLM 0.25.1, Qwen3-8B TP2 QKV/O shapes, measured as one CUDA graph over 36 distinct layers and 72 projections. Values above 1.0 mean MXFP8 is faster.

Decode rows M MXFP8 speed vs BF16
1 0.649x
32 0.645x
128 0.666x
512 0.881x
1024 0.956x
2048 1.194x
4096 1.285x

The current FlashInfer CuTeDSL MXFP8 path is slower at the rollout decode sizes and crosses over only at prefill-scale batches.

Needs upstream changes

Everything else this PR needs is merged and already pinned on main through #5005:

Builds on #5005 (merged) for the Megatron-Bridge and runtime updates and is up to date with main. This PR has no submodule change; it uses the merged Bridge commit ae0a1b02 already pinned on main by #5005, including the checkpoint-loading fixes, Mamba projection export mappings, and Omni media export boundaries. This PR bumps ModelOpt from cc4b76d7 (pinned by #5005) to 3c815f8d, the merge of Model-Optimizer#3434, so NVFP4 export packing matches the fake quant at rounding boundaries; only the ModelOpt lock entry changes. The integration targets vLLM 0.33.0 (main).

PR commands and CI
  • CI label, exactly one:
    • 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.
  • /review: automated review comments. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

mxinO added 14 commits August 15, 2026 09:11
…nt-refit

Signed-off-by: Meng Xin <[email protected]>

# Conflicts:
#	tests/unit/algorithms/test_grpo.py
@copy-pr-bot

copy-pr-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Sep 1, 2026
@mxinO mxinO changed the title refactor(modelopt): generalize real-quant vLLM refit feat(modelopt): add format-general real-quant vLLM rollout Sep 1, 2026
Add distillation-qwen3-1.7b-1n4g-megatron-qa-nvfp4-real (GB200) and the
non-colocated sibling of the Qwen3-8B W4A16 nightly, raising the H100 nightly
budget to 5548 GPU hours. Make distillation real quant runnable by adding
real_quant_export_cpu_offload to distillation_math.yaml.

Move the mixed MXFP8/NVFP4 example to a recipe with a manual driver listed in
disabled.txt, drop the uncovered Qwen2.5-0.5B real-quant example, and point the
guide at configs that tests run.

Signed-off-by: Meng Xin <[email protected]>
Grep the native ModelOpt method name in the functional real-quant case and run
it in the fast lane. Drop the recipe-pinning test (shipped configs already pass
check_outdated_config), the dead DEEPEP_FALLBACK_RECIPES set, duplicated test
lines, and the file-path import in the SGLang patches test.

Signed-off-by: Meng Xin <[email protected]>
@mxinO

mxinO commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test eb87715

@mxinO

mxinO commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7c95c01

Check the RADIO config vLLM builds for the vision model, whose
initializer_factor sets ls1/ls2, instead of the checkpoint's remote-code
vision_config. The published Nano-Omni RADIOConfig has an empty
model_type and no layerscale_value, so the old check rejected it.

Dummy-loaded generation workers never download the checkpoint index, so
prefetch it at the immutable revision in prepare_refit_info, before the
first refit.

Signed-off-by: Meng Xin <[email protected]>
@mxinO

mxinO commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d1b3f2a

- Run Bridge's check_exportable_quantizers before building the export
  plan, so recipes with KV-cache or output quantizers fail at startup
  instead of rolling out without them.
- Reject a non-null policy.generation.quant_cfg with real_quant;
  policy.quant_cfg alone selects the rollout format.
- Wrap FP8 MoE reload only when vLLM's quant config holds reciprocal
  scales, instead of copying vLLM's backend list.
- Raise when the RADIO LayerScale loader patch cannot find its anchor.
- Test that RealQuantWorker.load_model prepares the unwrapped model.
- Point the Nano3 real-quant docs at nvfp4_experts_weightonly.yaml and
  fix the stale recipe comment.

Signed-off-by: Meng Xin <[email protected]>
@mxinO

mxinO commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6a56638

@mxinO mxinO left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deriving vLLM's quantization_config from the calibrated ModelOpt export plan removes the custom NVFP4 methods and, with them, the whole class of policy-vs-generation mode mismatches. Real quant now reuses the base reload lifecycle through named hooks, reject_outdated_real_quant_ignore follows the migration convention, and Policy.get_real_quantization_config checks that every rank agrees. The two open change requests on the RADIO LayerScale identity check (thread) and the cache-only index lookup (thread) are fixed in d1b3f2a.

Inline items:

  1. (C1) Call Bridge's check_exportable_quantizers before building the export plan, so KV-cache or output quantizers fail at startup instead of rolling out in BF16.
  2. (C2, C3, C4, C5) The Nano3 real-quant docs still name nano3_nvfp4_weightonly.yaml, which, without real_quant_ignore, quantizes Mamba in_proj/out_proj and shared experts; point them at nvfp4_experts_weightonly.yaml.
  3. (C6) Reject a non-null policy.generation.quant_cfg when real_quant is on, instead of ignoring it.
  4. (C7) Decide which FP8 MoE backends to wrap from vLLM's built quant config, not a copied backend list.
  5. (C8) Raise, not warn, when the RADIO LayerScale loader patch misses its anchor, so the new LayerScale guard can run.
  6. (C9) Test that RealQuantWorker.load_model calls both MoE scale helpers on the unwrapped model.
  7. (C10) Update the Nano3 recipe comment that still refers to the deleted rollout exclusions.
  8. (C11) Type prepare_real_quant_generation_config's policy argument as Policy.

Still open from an earlier thread: the reply on the per-tensor clone promised to add its refit-time cost to the PR description; it is not there yet.

Follow-ups, not asks for this PR:

Validation: CI Lint passes at d1b3f2a; the red pr-description check is only the human review box. Locally at d1b3f2a, the vLLM patch, RADIO and backend unit modules pass (284 tests); at 7c95c01, the other touched vLLM, ModelOpt and algorithm unit modules passed. The mcore-only test_megatron_quant_worker.py was not run.

nemo-rl-review: kind=self harness=claude-code/2.1.331 model=claude-opus-5-5 effort=high review-pr-team=v2 reviewed=d1b3f2a

Comment thread docs/guides/quantization-aware-rl.md Resolved
Comment thread docs/guides/quantization-aware-rl.md Resolved
Comment thread docs/guides/quantization-aware-rl.md Resolved
Comment thread docs/guides/quantization-aware-rl.md Resolved
Comment thread nemo_rl/modelopt/utils.py Resolved
@mxinO

mxinO commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 59999b0

Bump Model-Optimizer from cc4b76d7 to 3c815f8d, the merge of
NVIDIA/Model-Optimizer#3434. NVFP4 export packing now quantizes with
the same reciprocal scale as the Triton fake quant, so real-quant
rollout weights match the fake-quantized training weights at rounding
boundaries.

Signed-off-by: Meng Xin <[email protected]>
@mxinO mxinO added CI:L1 Run doctests, unit tests, and functional tests and removed CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Nov 24, 2026
@mxinO

mxinO commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 97f4361

Restore logprob preparation to the upstream gather lifecycle and explicit MXFP8 shared-buffer restaging. Preserve open-step gradient guards and the independent checkpoint, refit, warm-up, and optimizer-offload fixes.

Signed-off-by: Meng Xin <[email protected]>
@mxinO

mxinO commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e4791ec

@aroshanghias-nvd aroshanghias-nvd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the RADIO / Nano-VL refit changes at e4791ec.

Both issues from my previous review are fixed in d1b3f2a:

  • The identity fallback checks vLLM's constructed RADIO config, so the actual Nano-Omni remote-code config is accepted while explicit-scale and non-identity cases remain guarded.
  • Generation workers prefetch the checkpoint index at the immutable revision during setup, before refit collectives; refit-time validation remains cache-only.

Four independent focused CPU checks passed on this head: actual Nano-Omni config plus native reload, non-identity rejection, explicit-source-scale rejection, and a genuinely empty generation cache followed by index prefetch and native refit. Successful refits initialize omitted ls1/ls2 to 1.0, and the storage-preservation check passes.

Approval scope: RADIO / Nano-VL. This follow-up validation was CPU-only.

@mxinO

mxinO commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6f941d9

…nt-refit

Resolve the nightly GPU-hour budget: main raised it from 5516 to 5524 and
this branch raised it to 5548 for its new nightlies; the combined dry run
totals 5556.

Signed-off-by: Meng Xin <[email protected]>
@mxinO

mxinO commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5f631b1

@mxinO

mxinO commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d7e50ce

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants