Skip to content

Test that quantization works without the [hf] extra - #3024

Merged
kevalmorabia97 merged 1 commit into
NVIDIA:mainfrom
ConnorBaker:test-quantize-without-hf-extra
Oct 26, 2026
Merged

kevalmorabia97 merged 1 commit into
NVIDIA:mainfrom
ConnorBaker:test-quantize-without-hf-extra

Conversation

@ConnorBaker

@ConnorBaker ConnorBaker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new tests

#2671 made import modelopt.torch work on a base install and added tests/unit/torch/test_import.py to keep it that way. This extends that test: in the same subprocess, with the [hf] extra's modules still made unavailable, it also quantizes a small model (mtq.INT8_DEFAULT_CFG, max calibration).

The import alone doesn't cover this. In 0.47.0, even with #2671 applied, mtq.quantize on a base install fails:

  File ".../modelopt/torch/quantization/model_calib.py", line 99, in _collect_grouped_linears
    from modelopt.torch.export.layer_utils import _GATE_UP_PAIRS
  File ".../modelopt/torch/export/__init__.py", line 28, in <module>
    from .unified_export_megatron import *
  File ".../modelopt/torch/export/unified_export_megatron.py", line 32, in <module>
    from huggingface_hub import get_safetensors_metadata, hf_hub_download
ModuleNotFoundError: No module named 'huggingface_hub'

Max calibration checks that fused sibling linears share one weight global_amax, and since #1605 (0.46.0) it looked up the gate/up projection names in modelopt.torch.export. #1828 replaced that lookup with modelopt.torch.models.list_all_possible, so main and release/0.48.0 quantize fine. No test would catch it coming back: every CI environment has huggingface_hub, if only through timm from dev-test.

The quantize step goes into the existing subprocess rather than a second one, following CONTRIBUTING's rule for unit tests that spawn processes. On a shared x86 builder, over 5 interleaved runs, the subprocess used a median 4.37 s of CPU time both with and without the quantize step; the difference is within the run-to-run spread (4.1 to 4.7 s), so nearly all of it is the import.

Usage

N/A

Testing

tests/unit/torch/test_import.py, on main at efda42c, in an environment with huggingface_hub installed (through timm):

  • With this PR: passes.
  • The same, with import modelopt.torch.export added back to _collect_grouped_linears: fails at the quantize step, with ModuleNotFoundError: import of huggingface_hub halted; None in sys.modules.
  • 0.47.0 with Fix import modelopt.torch without the [hf] extra #2671 and this test: fails the same way, at the _GATE_UP_PAIRS import.
  • pre-commit run with this repository's configuration (ruff 0.15.20, mypy 2.1.0) passes on the changed file.

Earlier, without the test, in environments that really lack the [hf] extra (modelopt and its required dependencies only): INT8 quantization of a small model, in one process and in two gloo ranks, fails on 0.47.0 with #2671, and passes on main (then 3788881) and on release/0.48.0 with #2671.

Before your PR is "Ready for review"

  • 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
  • Did you get Claude approval on this PR?: N/A

Additional Information

Found while packaging 0.47.0 for Nixpkgs (NixOS/nixpkgs#577198). release/0.48.0 doesn't have test_import.py yet, so this belongs with #2671's cherry-pick, if it's wanted there.

AI disclosure: this change, the testing described above and this description were produced with Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded PyTorch import coverage to verify that a small model can be quantized with calibration when optional Hugging Face modules are unavailable.

test_import.py checks that `import modelopt.torch` works on a base
install, but nothing checks that it can then quantize: every test
environment has huggingface_hub, if only through timm. 0.47.0 can't,
even with NVIDIA#2671. Max calibration checks that fused sibling linears
share their weight global_amax, and looked up the gate/up projection
names in modelopt.torch.export.layer_utils; importing
modelopt.torch.export imports huggingface_hub, so `mtq.quantize` fails
with

    ModuleNotFoundError: No module named 'huggingface_hub'

NVIDIA#1828 incidentally removed that import, taking the names from
modelopt.torch.models instead. Also quantize a small model in the
import test's subprocess, where the [hf] extra's modules are made
unavailable, so that this stays fixed without spawning another
process.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Connor Baker <[email protected]>
@ConnorBaker
ConnorBaker requested a review from a team as a code owner October 26, 2026 17:08
@copy-pr-bot

copy-pr-bot Bot commented Oct 26, 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 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between efda42c and 7b7cd66.

Files selected for processing: 1
  • tests/unit/torch/test_import.py

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

Walkthrough

The subprocess test now checks that it can import PyTorch and run ModelOpt quantization while optional Hugging Face modules are blocked.

Changes: Import and quantization test

Layer / File(s) Summary
Extend subprocess check
tests/unit/torch/test_import.py
The subprocess imports PyTorch and the quantization API, builds a sequential model, and calls quantize with INT8_DEFAULT_CFG and a calibration callback.

Priority: Normal

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

Change: Other

Suggested reviewers: kevalmorabia97, lincannerd

Merge Risk: Minimal · up to 7b7cd

The added regression check can remain in the normal pull-request test workflow; no actionable merge-blocking risk is established.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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: testing quantization without the optional [hf] extra.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed The pull request changes only tests/unit/torch/test_import.py. The added code imports PyTorch and ModelOpt, constructs a model, and calls mtq.quantize; it does not add `torch.load(..., weights_onl…
Full details: Security Anti-Patterns

Explanation

The pull request changes only tests/unit/torch/test_import.py. The added code imports PyTorch and ModelOpt, constructs a model, and calls mtq.quantize; it does not add torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded trust_remote_code=True, external-input eval()/exec(), or # nosec. It also does not modify dependency files.

Finishing Touches
🧪 Generate unit tests (beta)
  • 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.

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

Bot review (gpt-6.1-sol) — DM the bot to share feedback.

LGTM: the regression test exercises real calibration with optional modules blocked; human sign-off is required for the justified existing-test edit.

Needs action:

  • Confirm the extension to tests/unit/torch/test_import.py: it preserves the import check and adds INT8 max calibration in the same subprocess without weakening coverage.

@kevalmorabia97

Copy link
Copy Markdown
Collaborator

@ConnorBaker please fix the code quality issues and merge the PR

@kevalmorabia97
kevalmorabia97 enabled auto-merge (squash) October 26, 2026 17:13
@ConnorBaker

Copy link
Copy Markdown
Contributor Author

Thanks for the review! The code-quality failure isn't from this change: the pre-commit step's npm install got a 404 for @typescript-eslint/[email protected], which npm published at 17:08:21Z, a few minutes before the job ran (17:11Z). The tarball resolves now, so a re-run of code-quality should pass.

I don't have write access to this repository, so I can't re-run the job or merge the PR myself. Could a maintainer re-run it and merge?

AI disclosure: this comment was drafted with Claude Code (Claude Opus 5.5).

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.49%. Comparing base (a382b8e) to head (7b7cd66).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3024   +/-   ##
=======================================
  Coverage   77.49%   77.49%           
=======================================
  Files         661      661           
  Lines       74949    74949           
=======================================
  Hits        58085    58085           
  Misses      16864    16864           
Flag Coverage Δ
unit 61.15% <ø> (ø)

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

Copy link
Copy Markdown
Collaborator

/ok to test 7b7cd66

@kevalmorabia97
kevalmorabia97 merged commit 7a42e68 into NVIDIA:main Oct 26, 2026
47 of 48 checks passed
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.

3 participants