Repository navigation
[NVBug 6779760] Test NVFP4 export of CPU-offloaded models - #2825
Conversation
Add an NVFP4 case to test_export_hf_checkpoint_cpu_offloaded. NVFP4 is the
format that crashed with a cuda/cpu device mismatch when exporting a
CPU-offloaded model in 0.35.0, and the test only covered FP8.
Also stop the fixture from mapping the parent modules ("" and "model").
Mapping them made accelerate load the offloaded layer onto the GPU before
offloading it, so after hook removal its weight came back on GPU rather than
CPU, unlike from_pretrained(device_map=...) as hf_ptq loads it. Without this
the new case cannot reproduce the bug's device layout.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Chenjie Luo <[email protected]>
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Parameterize offloaded export test tests/gpu/torch/export/test_offload_export.py |
The test description includes NVFP4 calibration. The device map skips root and model parent modules. The test covers two FP8 configurations and NVFP4, and checks the exported algorithm against the selected quant_algo. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Other
Suggested reviewers: fridah-nv
Merge Risk: 
Minimal · previous review 06968
-
The expanded test covers FP8 and NVFP4 CPU-offloaded exports and checks their serialized algorithms; no concrete merge-blocking issue is evident from the inspected changes.
Pre-merge checks: 
5 · 
1
-
Failed checks: 1 warning Passed checks: 5 passed -
✨ Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2825 +/- ##
==========================================
- Coverage 79.87% 79.36% -0.51%
==========================================
Files 661 661
Lines 75417 75417
==========================================
- Hits 60237 59856 -381
- Misses 15180 15561 +381
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
meenchen
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
LGTM: this is a well-motivated regression test for NVBug 6779760, but it edits an existing test file, so a human needs to sign off.
Needs action:
- Sign off on the edits to
tests/gpu/torch/export/test_offload_export.py. The_make_cpu_offloaded_modelfix and the parametrizedquant_algocheck are justified, and the existing FP8 cases and their assertions are unchanged.
No action needed:
- The fixture change also affects
test_streaming_export_matches_batch_export. The author reports all 5 tests passing, which includes it. - The author checked that the test catches the bug: with 0.35.0's export behaviour put back, only the NVFP4 case fails, with the original
cuda:0 and cpuerror. The unmodified test file passes, which shows the old test missed it. I inspected the tests but didn't run them. - The PR body says the same root-mapped
device_mapin_test_utils/torch/quantization/offload.pywill be fixed in a follow-up PR. That's fine.
|
What does this PR do?
Type of change: new tests
Adds NVFP4 to the CPU-offloaded export GPU test (
test_export_hf_checkpoint_cpu_offloaded). Until now that test covered only FP8.NVBug 6779760: on a 64 GB DGX Spark, the NVFP4 playbook (ModelOpt 0.35.0) crashed during export with
RuntimeError: Expected all tensors to be on the same device ... cuda:0 and cpu. On GB10,cudaMemGetInfodoes not count reclaimable page cache as free memory, sohf_ptqCPU-offloads part of the model.Main is already fixed. Device alignment came in #432 (0.39.0), and offloaded models have used the streaming exporter since #2008 (0.46.0). This PR adds a regression guard for that exact configuration.
The fixture also needed a fix. It mapped the parent modules (
"","model") to GPU 0, which makes accelerate load the "offloaded" layer onto the GPU before offloading it. After hook removal, that layer's weight came back on GPU instead of CPU, so the fixture never produced the bug's layout.from_pretrained(device_map=...), which is howhf_ptqloads, does not do this. The fixture now leaves the parents unmapped.Follow-up (not in this PR):
tests/_test_utils/torch/quantization/offload.py::make_cpu_offloaded_modelbuilds the same root-mapped device_map. It is used bytest_vllm_fakequant_hf_export.pyandtest_accelerate_gpu.py.Testing
All runs were on a DGX Spark (GB10) in
nvcr.io/nvidia/tensorrt-llm/release:spark-single-gpu-dev, with torch 2.8.0a0, transformers 5.18.0 and accelerate 1.10.1.pytest tests/gpu/torch/export/test_offload_export.py: 5 passed.get_weights_scaling_factororget_weight_scaling_factor.[quant_cfg2-NVFP4]fails, with the bug'sRuntimeError ... cuda:0 and cpu.cpuand amax oncuda:0after hook removal, matchingfrom_pretrained(device_map=...). Before the fix, both were oncuda:0.weight_scale_2exact, ~0.09 relative error on both).Not run: other GPU architectures, and CI's environment.
Before your PR is "Ready for review"
Make sure you read and follow Contributor guidelines and your commits are signed (
git commit -s -S).Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded
trust_remote_code=True,torch.load(..., weights_only=False),pickle, etc.).CONTRIBUTING.md: N/AAdditional Information
NVBug 6779760. The playbook fix (bump the Spark section from 0.35.0 to 0.41.0) is tracked on the bug.
🤖 Generated with Claude Code
Summary by CodeRabbit