Skip to content

Fix NVFP4 multi-GPU export device handling - #2197

Draft
realAsma wants to merge 2 commits into
mainfrom
asma/fix-nvfp4-multi-gpu-export
Draft

Fix NVFP4 multi-GPU export device handling#2197
realAsma wants to merge 2 commits into
mainfrom
asma/fix-nvfp4-multi-gpu-export

Conversation

@realAsma

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

NVFP4 weight export could allocate intermediate tensors on the process's current CUDA device instead of the input tensor's device. This caused export failures when a model shard lived on a different GPU. This change scopes NVFP4 quantization to the input device while restoring the caller's current device afterward.

The export path also now uses the quantizer's public is_enabled state instead of inferring that state from its formatted representation.

Usage

N/A — this fixes existing multi-GPU export behavior without changing the public API.

Testing

  • pre-commit run --files modelopt/torch/export/unified_export_hf.py modelopt/torch/quantization/qtensor/nvfp4_tensor.py tests/gpu/torch/quantization/test_qtensor_cuda.py tests/unit/torch/export/test_export_weight.py
  • pytest tests/unit/torch/export/test_export_weight.py::test_export_quantized_weight_does_not_repr_input_quantizer -q -x
  • CUDA_VISIBLE_DEVICES=1,2 pytest tests/gpu/torch/quantization/test_qtensor_cuda.py::TestQTensor::test_nvfp4_export_uses_input_device -q -x

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.).

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: N/A — focused bug fix; no critical or previously documented release issue
  • Did you get Claude approval on this PR?: N/A — draft preparation only

Additional Information

No new dependency or public API is introduced.

Signed-off-by: realAsma <akuriparambi@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 14, 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.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 60f459c8-b10f-4157-81d7-5849e1ecfd33

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://NVIDIA.github.io/Model-Optimizer/pr-preview/pr-2197/

Built to branch gh-pages at 2026-08-14 21:46 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.07692% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.96%. Comparing base (5e887aa) to head (25819df).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...odelopt/torch/quantization/qtensor/nvfp4_tensor.py 68.18% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2197      +/-   ##
==========================================
- Coverage   78.97%   78.96%   -0.01%     
==========================================
  Files         522      522              
  Lines       60606    60612       +6     
==========================================
  Hits        47862    47862              
- Misses      12744    12750       +6     
Flag Coverage Δ
unit 55.57% <73.07%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: realAsma <akuriparambi@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant