Repository navigation
Test that quantization works without the [hf] extra - #3024
Conversation
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]>
|
No actionable comments were generated in the recent review.
|
| 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:
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: 
5 · 
1
-
Failed checks: 1 warning Passed checks: 5 passed-
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 callsmtq.quantize; it does not addtorch.load(..., weights_only=False),numpy.load(..., allow_pickle=True), hardcodedtrust_remote_code=True, external-inputeval()/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.
There was a problem hiding this comment.
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.
|
@ConnorBaker please fix the code quality issues and merge the PR |
|
Thanks for the review! The 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 Report✅ All modified and coverable lines are covered by tests. 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
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:
|
|
/ok to test 7b7cd66 |
What does this PR do?
Type of change: new tests
#2671 made
import modelopt.torchwork on a base install and addedtests/unit/torch/test_import.pyto 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.quantizeon a base install fails: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 inmodelopt.torch.export. #1828 replaced that lookup withmodelopt.torch.models.list_all_possible, so main andrelease/0.48.0quantize fine. No test would catch it coming back: every CI environment hashuggingface_hub, if only throughtimmfromdev-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 withhuggingface_hubinstalled (throughtimm):import modelopt.torch.exportadded back to_collect_grouped_linears: fails at the quantize step, withModuleNotFoundError: import of huggingface_hub halted; None in sys.modules._GATE_UP_PAIRSimport.pre-commit runwith 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 onrelease/0.48.0with #2671.Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
Found while packaging 0.47.0 for Nixpkgs (NixOS/nixpkgs#577198).
release/0.48.0doesn't havetest_import.pyyet, 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