Skip to content

perf: avoid CPU round trip during NVFP4 refit - #3308

Merged
terrykong merged 12 commits into
NVIDIA-NeMo:mainfrom
seonjinn:sna/nvfp4-gpu-direct-refit
Jul 30, 2026
Merged

terrykong merged 12 commits into
NVIDIA-NeMo:mainfrom
seonjinn:sna/nvfp4-gpu-direct-refit

Conversation

@seonjinn

Copy link
Copy Markdown
Contributor

What does this PR do?

Real NVFP4 refit quantizes and packs policy weights on GPU, but the existing export path copies every packed tensor to CPU before colocated CUDA IPC copies it back to GPU for vLLM reload.

This PR adds opt-in generation.real_quant_export_cpu_offload: false for colocated CUDA-IPC refit. The CPU path remains the default, and GPU-resident export is rejected for non-colocated or explicit refit transports.

Benchmark setup

  • Nemotron Nano 30B-A3B, DAPOMath17K, seed 42
  • 2 B200 nodes x 8 GPUs
  • 100 training steps per run; means over steps 3-100
  • Matched CPU-offload and GPU-resident export runs for W4A16 and W4A4 rollout

Impact

Metric W4A16 Delta W4A4 Delta
Transfer/update (s) 21.85 -> 4.89 -77.6% 22.46 -> 5.78 -74.3%
Refit total (s) 27.62 -> 11.72 -57.6% 34.00 -> 18.22 -46.4%
E2E step time (s) 59.69 -> 45.10 -24.5% 71.57 -> 55.60 -22.3%
E2E tok/s/GPU 32.18 -> 41.01 +27.4% 26.03 -> 33.51 +28.8%

Accuracy impact

Metric W4A16 CPU -> GPU W4A4 CPU -> GPU
Mean rollout reward 0.1773 -> 0.2864 0.2723 -> 0.2487

These are single-seed sampled training rewards, not held-out accuracy. The W4A4 paired step-level reward difference has a 95% CI of [-0.0711, +0.0239], which includes zero. Training trajectories diverge after the first update, so this benchmark does not claim convergence parity.

Correctness

  • CPU offload remains the default and fallback for lower GPU-memory headroom.
  • GPU-resident export is limited to colocated CUDA IPC with no explicit refit transport.
  • W4A16 and W4A4 ModelOpt exports match CPU offload in tensor names, shapes, dtypes, and raw bytes.
  • 11 focused CUDA tests passed on B200, including CUDA IPC staging parity.
  • All four matched 100-step benchmark arms completed without OOM, NaN, assertion, refit, or Ray actor failures.

Trade-off

GPU-resident export retains packed tensors on the source GPU during refit, trading the host round trip for additional transient GPU memory. Users can keep the default CPU path when memory headroom is limited.

@seonjinn
seonjinn requested review from a team as code owners July 21, 2026 21:55
@copy-pr-bot

copy-pr-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@seonjinn seonjinn changed the title perf(modelopt): avoid CPU round trip during NVFP4 refit perf: avoid CPU round trip during NVFP4 refit Jul 21, 2026
@seonjinn seonjinn added the CI:L1 Run doctests, unit tests, and functional tests label Jul 21, 2026
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 9643550

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@parthmannan can you also review?

@terrykong
terrykong requested a review from parthmannan July 24, 2026 04:56

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Team review of the NVFP4 GPU-resident export path. Nice work — the benchmarks in the description are thorough, and the safety story checks out under scrutiny: all in-repo real_quant recipes inherit the new key via their defaults: chains rooted at grpo_math_1B.yaml; configure_generation_config runs on every entrypoint before workers are built; refit_transport: null is the only route to CUDA IPC so the guard has no false positives; and the cpu=False path yields a fresh packed tensor with stream-synchronized IPC staging, so there is no aliasing hazard. 3 inline suggestions below — the test-lane one is the only item worth addressing before merge.

Generated by Claude Code

Comment thread nemo_rl/models/generation/__init__.py Resolved
@seonjinn
seonjinn requested a review from a team as a code owner July 27, 2026 21:56
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Jul 27, 2026
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 30b4139

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 35b966a

terrykong added a commit that referenced this pull request Jul 28, 2026
test_vllm_megatron_pipeline_parallel began failing intermittently on
L0_Unit_Tests_Mcore (fail, pass, fail across three runs) with
'Failed: Timeout (>120.0s) from pytest-timeout' -- a wall-clock timeout,
not an assertion.

Measured rather than guessed. Call time for this test:

  vLLM 0.20   103.80s   (PR #3308, job 90163013717)
  vLLM 0.25   113.10s   (this branch, job 89878378208)

So 0.25 costs ~9.3s / +9% here, and the headroom under the 120s budget
drops from 16.2s to 6.9s. Less than normal run-to-run variance on a shared
runner, which is exactly why it flips between pass and fail.

The budget was already marginal before this bump -- 86% consumed on 0.20 --
so this raises it to 240s rather than chasing the regression to the second.
The measurements and job IDs are recorded at the marker so the next person
does not have to re-derive them.

Note the +9% is engine-init overhead in a test that builds both a Megatron
pp=2 policy and a vLLM engine inside one budget; it is not a generation
throughput regression.

Signed-off-by: Terry Kong <[email protected]>
@seonjinn seonjinn self-assigned this Jul 28, 2026
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test a13023c

terrykong added a commit that referenced this pull request Jul 30, 2026
test_vllm_megatron_pipeline_parallel began failing intermittently on
L0_Unit_Tests_Mcore (fail, pass, fail across three runs) with
'Failed: Timeout (>120.0s) from pytest-timeout' -- a wall-clock timeout,
not an assertion.

Measured rather than guessed. Call time for this test:

  vLLM 0.20   103.80s   (PR #3308, job 90163013717)
  vLLM 0.25   113.10s   (this branch, job 89878378208)

So 0.25 costs ~9.3s / +9% here, and the headroom under the 120s budget
drops from 16.2s to 6.9s. Less than normal run-to-run variance on a shared
runner, which is exactly why it flips between pass and fail.

The budget was already marginal before this bump -- 86% consumed on 0.20 --
so this raises it to 240s rather than chasing the regression to the second.
The measurements and job IDs are recorded at the marker so the next person
does not have to re-derive them.

Note the +9% is engine-init overhead in a test that builds both a Megatron
pp=2 policy and a vLLM engine inside one budget; it is not a generation
throughput regression.

Signed-off-by: Terry Kong <[email protected]>
@terrykong
terrykong merged commit 16662da into NVIDIA-NeMo:main Jul 30, 2026
97 checks passed
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.

2 participants