Skip to content

Measure qtensor GPU memory tests with allocator stats - #2707

Merged
kevalmorabia97 merged 1 commit into
NVIDIA:mainfrom
LinCanNerd:fix/fp4-cast-mem-test-integrated-gpu
Oct 26, 2026
Merged

kevalmorabia97 merged 1 commit into
NVIDIA:mainfrom
LinCanNerd:fix/fp4-cast-mem-test-integrated-gpu

Conversation

@LinCanNerd

@LinCanNerd LinCanNerd commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix (tests)

Fixes #2706.

test_cast_fp4_impl_gpu_mem and test_mxfp8_quantize_gpu_mem measured memory with torch.cuda.mem_get_info(), which reports device-wide usage. On GPUs that share memory with the CPU, such as Jetson Thor, that value changes with every other allocation on the system. As a result, the NVFP4 test fails intermittently there: the measurement is 2.05×–2.15× of the input on an idle machine against a 2.1× bound, and higher when anything else is running.

Both tests now measure the caching allocator's peak while the cast runs (reset_peak_memory_stats(), then max_memory_allocated() minus the starting memory_allocated()). This counts only the tensors the call allocates, the same way test_qtensor in this file already checks memory. The bounds are unchanged.

test mem_get_info delta (Thor) allocator peak (Thor) bound
test_cast_fp4_impl_gpu_mem 2.05×–2.15× 1.50× 2.1×
test_mxfp8_quantize_gpu_mem 2.05× 2.10×–2.15× 3×

The allocator peak includes temporaries freed before the call returns, so it is the stricter measure of the call's working memory.

Usage

No API change.

Testing

On Jetson Thor (sm_110, JetPack 7.2.1, torch 2.13.0+cu130):

  • pytest tests/gpu/torch/quantization/test_qtensor_cuda.py -k gpu_mem: 5 of 5 runs passed. Before the change, the NVFP4 test failed intermittently.
  • pytest tests/gpu/torch/quantization/test_qtensor_cuda.py: 219 passed.
  • pre-commit run --files tests/gpu/torch/quantization/test_qtensor_cuda.py: passed.

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?: N/A (test fix)
  • Did you update Changelog?: N/A (tests only)
  • Did you get Claude approval on this PR?: N/A

Additional Information

Found while running tests/gpu/torch/quantization and tests/gpu/torch/kernels on Jetson Thor. The only other Thor-specific failure is #2705, which has its own PR.

Summary by CodeRabbit

  • Tests
    • Updated GPU quantization memory checks to track peak memory allocated during NVFP4 casting and MXFP8 quantization. Existing memory limits are unchanged. This provides a consistent view of the memory used by these operations during testing.

test_cast_fp4_impl_gpu_mem and test_mxfp8_quantize_gpu_mem measured
memory with torch.cuda.mem_get_info(), which reports device-wide usage.
On GPUs that share memory with the CPU, such as Jetson Thor, that value
moves with every other allocation on the system, so the NVFP4 test fails
intermittently there (2.05x-2.15x of the input against a 2.1x bound).

Both tests now measure the caching allocator's peak while the cast runs,
which counts only this process's tensors: 1.50x for NVFP4 and 2.10x for
MXFP8 on Thor, stable across runs.

Signed-off-by: LinCanNerd <[email protected]>
@LinCanNerd
LinCanNerd requested a review from a team as a code owner October 8, 2026 10:14
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 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.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/Model-Optimizer/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: d754d839-83eb-409f-9e4f-94da1326597b
📥 Commits

Reviewing files that changed from the base of the PR and between 90ba9fb and 2efefd2.

📒 Files selected for processing (1)
  • tests/gpu/torch/quantization/test_qtensor_cuda.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

The NVFP4 cast and MXFP8 quantization memory tests now measure peak caching-allocator allocation with a shared helper. Their existing memory limits remain unchanged.

Changes

CUDA memory test measurement

Layer / File(s) Summary
Measure allocator peak in memory tests
tests/gpu/torch/quantization/test_qtensor_cuda.py
A shared helper synchronizes CUDA and measures peak allocation above the pre-call baseline. The NVFP4 and MXFP8 memory tests use this measurement instead of device-wide free-memory readings. Their limits remain 2.1× and 3× input size, respectively.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: kevalmorabia97

Merge Risk: ⚪ Minimal · up to 2efef

No concrete merge-blocking risk is identified in the supplied changes.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: measuring qtensor GPU memory tests with allocator statistics.
Linked Issues check ✅ Passed Issue #2706 requires test_cast_fp4_impl_gpu_mem to measure _cast_fp4 memory independently of device-wide activity. The PR adds _peak_gpu_mem_increase, which synchronizes CUDA, resets allocator p…
Out of Scope Changes check ✅ Passed The diff changes only tests/gpu/torch/quantization/test_qtensor_cuda.py. The helper and its two call-site changes directly support issue #2706 by replacing device-wide memory readings with allocator…
Security Anti-Patterns ✅ Passed PASS. The pull request changes only tests/gpu/torch/quantization/test_qtensor_cuda.py; it does not change the modelopt package, examples, pyproject.toml, or requirements.txt. The added code on…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@LinCanNerd

Copy link
Copy Markdown
Contributor Author

@AAnoosheh When you have a moment, could you run /ok to test on this PR? CI has not started here yet. Thanks!

@kevalmorabia97

Copy link
Copy Markdown
Collaborator

/ok to test 2efefd2

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.06%. Comparing base (90ba9fb) to head (2efefd2).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2707      +/-   ##
==========================================
+ Coverage   71.54%   78.06%   +6.52%     
==========================================
  Files         640      640              
  Lines       71316    71316              
==========================================
+ Hits        51020    55671    +4651     
+ Misses      20296    15645    -4651     
Flag Coverage Δ
gpu 58.83% <ø> (+25.31%) ⬆️
unit 59.71% <ø> (-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.

@kevalmorabia97 kevalmorabia97 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.

Approve: a test-only fix that replaces the device-wide mem_get_info delta with the caching allocator's peak, with unchanged bounds.

No action needed.

No action needed:

  • The helper syncs, resets the peak, and subtracts the starting memory_allocated() (which includes the input), so it counts only what the call allocates, as test_qtensor already does.
  • I reproduced the PR's ratios on an RTX 6000 Ada: _cast_fp4 1.50x (bound 2.1x), MXFP8QTensor.quantize 2.10x (bound 3x). Both tests pass.
  • No changelog needed; no setup-owned paths touched.

@kevalmorabia97

Copy link
Copy Markdown
Collaborator

/ok to test 2efefd2

@kevalmorabia97
kevalmorabia97 enabled auto-merge (squash) October 26, 2026 20:24
@kevalmorabia97
kevalmorabia97 merged commit aab3a02 into NVIDIA:main Oct 26, 2026
37 checks passed
ll2088 added a commit to ll2088/sglang that referenced this pull request Nov 2, 2026
Ported from NVIDIA/Model-Optimizer#2707
Generated by autojump (AI); review before merging.
ll2088 added a commit to ll2088/sglang that referenced this pull request Nov 2, 2026
Ported from NVIDIA/Model-Optimizer#2707
Generated by autojump (AI); review before merging.
ll2088 added a commit to ll2088/sglang that referenced this pull request Nov 2, 2026
Ported from NVIDIA/Model-Optimizer#2707
Generated by autojump (AI); review before merging.
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.

test_cast_fp4_impl_gpu_mem is flaky on Jetson Thor: mem_get_info reports system-wide memory on integrated GPUs

2 participants