Repository navigation
Fall back to Python INT4 packing when the extension fails to build - #3026
Conversation
modelopt.onnx.quantization.extensions builds modelopt_round_and_pack_ext
with cppimport, which runs setuptools, when it is first imported (INT4
packing imports it on first use), and falls back to the Python
implementation if that fails. But setuptools raises SystemExit when the
build fails, which `except Exception` doesn't catch, so without a
working C++ compiler the import ends the process instead:
error: command 'c++' failed: No such file or directory
Catch SystemExit too, and test that a failed build falls back.
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 |
|---|---|
Handle extension import termination modelopt/onnx/quantization/extensions.py, tests/unit/onnx/quantization/test_extensions.py, CHANGELOG.rst |
The loader catches SystemExit as well as Exception and sets round_and_pack_ext to None. The test simulates SystemExit during import, and the changelog describes the Python fallback. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related issues
- Issue 3025 describes the same
cppimportbuild failure. This change handles theSystemExitfallback, but does not address temporary build-directory cleanup.
Suggested labels: cherry-pick-0.48.0
Suggested reviewers: kevalmorabia97
Merge Risk: 
Minimal · up to 17d26
-
The reported extension-build failure now falls back to Python packing. No issue identified in the supplied evidence needs resolution before merge.
Pre-merge checks: 
5 · 
1
-
Failed checks: 1 warning Passed checks: 5 passed-
Full details: Title check
-
Explanation
The title states the main change: when the INT4 packing extension fails to build, the code now falls back to Python INT4 packing. The changeset matches this. The extensions.py fallback now catches SystemExit as well as Exception, the changelog notes the fallback, and a unit test covers the SystemExit path. The title is specific and concise, and it names the behavior a reviewer scanning history needs to know.
Full details: Security Anti-Patterns
-
Explanation
PASS. The PR changes only the extension fallback, its unit test, and the changelog. The added Python code catches
(Exception, SystemExit)and contains notorch.load(..., weights_only=False),numpy.load(..., allow_pickle=True), hardcodedtrust_remote_code=True,eval,exec, or# nosec. No dependency manifest changed.
-
Full details: Docstring Coverage
-
Explanation
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 2 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
🧪 Generate unit tests (beta)
-
- Create a new PR
🛠️ Fix failing CI checks: 💡
-
- 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.
|
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 #3026 +/- ##
==========================================
+ Coverage 77.49% 79.15% +1.65%
==========================================
Files 661 661
Lines 74949 74949
==========================================
+ Hits 58085 59328 +1243
+ Misses 16864 15621 -1243
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 17d263a |
#2928 #2885 #2908 #2929 #2950 #2972 #2877 #2951 #2816 #3005 #3012 #2971 #3015 #3006 #3026 #2988 #3028 #1860 #3030 #2612 #3033 #2653 #2599 #2655 #2618 #2868 #3032 #3027 #2869 #2984 #2975 #2345 #3020 #2997 (#3072) ## Cherry-picked PRs - #2817 - #2671 - #2892 - #2876 - #2910 - #2911 - #2919 - #2904 - #2937 - #2928 - #2885 - #2908 - #2929 - #2950 - #2972 - #2877 - #2951 - #2816 - #3005 - #3012 - #2971 - #3015 - #3006 - #3026 - #2988 - #3028 - #1860 - #3030 - #2612 - #3033 - #2653 - #2599 - #2655 - #2618 - #2868 - #3032 - #3027 - #2869 - #2984 - #2975 - #2345 - #3020 - #2997 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Diffusion exports now offer more control over attention-quantizer metadata and preserve sparse-attention settings in a format compatible with downstream tooling. * Model loading better handles select bundled model implementations, and Docker guidance now covers writable CUDA-extension cache locations. * **Bug Fixes** * Improved reliability for model export and checkpoint saving, quantization across devices, ONNX processing, and calibration. * Temporary TensorRT and autotuning artifacts now use private directories by default. * **Documentation** * Updated installation guidance, compatibility notes, and links; corrected typos across guides and examples. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Chad Voegele <[email protected]> Signed-off-by: Rohan Joshi <[email protected]> Signed-off-by: LinCanNerd <[email protected]> Signed-off-by: Keval Morabia <[email protected]> Signed-off-by: weimingc <[email protected]> Signed-off-by: Noey Yang <[email protected]> Signed-off-by: Kai Xu <[email protected]> Signed-off-by: Zhehao Hu <[email protected]> Signed-off-by: noeyy-mino <[email protected]> Signed-off-by: joe-nv <[email protected]> Signed-off-by: yingguo-trt <[email protected]> Signed-off-by: Shengliang Xu <[email protected]> Signed-off-by: Chenjie Luo <[email protected]> Signed-off-by: anmaurya001 <[email protected]> Signed-off-by: Connor Baker <[email protected]> Signed-off-by: wiederse <[email protected]> Signed-off-by: Vu Dinh <[email protected]> Signed-off-by: Pratik Gandhi <[email protected]> Signed-off-by: Michael Rusu <[email protected]> Signed-off-by: Michael-Rusu <[email protected]> Signed-off-by: namgyu-youn <[email protected]> Signed-off-by: Sylvester Kaczmarek <[email protected]> Signed-off-by: Javier de Jesus <[email protected]> Signed-off-by: javierdejesusda <[email protected]> Signed-off-by: Zhiyu Cheng <[email protected]> Signed-off-by: Juhi Mittal <[email protected]> Signed-off-by: Dmitry Rantovov <[email protected]> Signed-off-by: h-guo18 <[email protected]> Co-authored-by: Chad Voegele <[email protected]> Co-authored-by: LinCanNerd <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Keval Morabia <[email protected]> Co-authored-by: Wei-Ming Chen <[email protected]> Co-authored-by: noeyy-mino <[email protected]> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: kaix-nv <[email protected]> Co-authored-by: Zhehao Hu <[email protected]> Co-authored-by: joe <[email protected]> Co-authored-by: yingguo-trt <[email protected]> Co-authored-by: Shengliang Xu <[email protected]> Co-authored-by: Chenjie Luo <[email protected]> Co-authored-by: anmaurya001 <[email protected]> Co-authored-by: Connor Baker <[email protected]> Co-authored-by: Jiao Mingyang <[email protected]> Co-authored-by: Vu Dinh <[email protected]> Co-authored-by: Pratik Gandhi <[email protected]> Co-authored-by: Michael R <[email protected]> Co-authored-by: Michael-Rusu <[email protected]> Co-authored-by: namgyu-youn <[email protected]> Co-authored-by: Sylvester Kaczmarek <[email protected]> Co-authored-by: Javier De Jesus <[email protected]> Co-authored-by: Zhiyu <[email protected]> Co-authored-by: Juhi Mittal <[email protected]> Co-authored-by: Dmitry Rantovov <[email protected]> Co-authored-by: h-guo18 <[email protected]>
What does this PR do?
Type of change: Bug fix
modelopt/onnx/quantization/extensions.pybuildsmodelopt_round_and_pack_extwith cppimport when it is first imported. INT4 packing (quant_utils.pack_float32_to_4bit_cpp_based) imports it on first use. If the build fails, the module is meant to fall back to the Python implementation. But cppimport builds withsetuptools.setup(), which raisesSystemExitwhen the build fails, andexcept Exceptiondoesn't catch that. So in a writable install without a working C++ compiler, the import ends the process:(exit status 1). This catches
SystemExittoo, adds a unit test that fails a build the way setuptools does, and adds a changelog entry, since 0.47.0 and earlier have the bug.Usage
N/A
Testing
On main at efda42c:
tests/unit/onnx/quantization/test_extensions.py(new) fails on main (SystemExit: error: command 'c++' failed: No such file or directory) and passes with this PR.test_quant_utils.pypasses with this PR. The test stubscppimport.impto raise theSystemExitthat setuptools raises, so it doesn't depend on how each platform's compiler can be made to fail; the next item runs the real build.modelopt.onnx.quantization.extensionsin a new process from a writable copy of the installed package, withCC/CXX/LDSHAREDpointing at a compiler that doesn't exist: on main the process exits with status 1; with this PR it logs the warning andround_and_pack_extisNone. With a compiler, both build and load the extension, and INT4 packing with it matches the Python fallback.pre-commit runwith this repository's configuration (ruff 0.15.20, mypy 2.1.0, bandit, the rst hooks) passes on the changed files.Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
Found while packaging 0.47.0 for Nixpkgs (NixOS/nixpkgs#577198).
extensions.pyis the same in 0.47.0,release/0.48.0and main.tests/unit/onnx/conftest.py's prebuild (#2461) suppresses onlyException, so it would not have caught this either.A failed build still leaves cppimport's temporary build directory in
$TMPDIR, since cppimport removes it only when the build succeeds. Now that the process survives, that happens in every process that tries; #3025 describes it.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