Skip to content

Fall back to Python INT4 packing when the extension fails to build - #3026

Merged
kevalmorabia97 merged 1 commit into
NVIDIA:mainfrom
ConnorBaker:int4-ext-catch-systemexit
Oct 26, 2026
Merged

kevalmorabia97 merged 1 commit into
NVIDIA:mainfrom
ConnorBaker:int4-ext-catch-systemexit

Conversation

@ConnorBaker

@ConnorBaker ConnorBaker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

modelopt/onnx/quantization/extensions.py builds modelopt_round_and_pack_ext with 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 with setuptools.setup(), which raises SystemExit when the build fails, and except Exception doesn't catch that. So in a writable install without a working C++ compiler, the import ends the process:

INFO - Loading extension modelopt_round_and_pack_ext...
error: command '/nonexistent/c++' failed: No such file or directory

(exit status 1). This catches SystemExit too, 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.py passes with this PR. The test stubs cppimport.imp to raise the SystemExit that 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.
  • Importing modelopt.onnx.quantization.extensions in a new process from a writable copy of the installed package, with CC/CXX/LDSHARED pointing at a compiler that doesn't exist: on main the process exits with status 1; with this PR it logs the warning and round_and_pack_ext is None. With a compiler, both build and load the extension, and INT4 packing with it matches the Python fallback.
  • pre-commit run with 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"

  • 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?: ✅
  • Did you get Claude approval on this PR?: ❌ (not run yet)

Additional Information

Found while packaging 0.47.0 for Nixpkgs (NixOS/nixpkgs#577198). extensions.py is the same in 0.47.0, release/0.48.0 and main. tests/unit/onnx/conftest.py's prebuild (#2461) suppresses only Exception, 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

  • Bug Fixes
    • ONNX INT4 quantization now falls back to the Python implementation if the optimized packing extension cannot be loaded, rather than terminating the process.
  • Documentation
    • Updated the 0.49.0 bug-fix notes to describe the fallback behavior.

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]>
@ConnorBaker
ConnorBaker requested review from a team as code owners October 26, 2026 17:08
@ConnorBaker
ConnorBaker requested a review from gcunhase 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 17d263a.

Files selected for processing: 3
  • CHANGELOG.rst
  • modelopt/onnx/quantization/extensions.py
  • tests/unit/onnx/quantization/test_extensions.py

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

Walkthrough

The extension loader now catches SystemExit during C++ extension import and sets round_and_pack_ext to None. A unit test checks this fallback state, and the changelog records the behavior.

Changes: ONNX INT4 extension fallback

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: Normal

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

Change: Bug fix

Possibly related issues

  • Issue 3025 describes the same cppimport build failure. This change handles the SystemExit fallback, 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: 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 2 functions across 2 files. (1 skipped: 1 … 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 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 Sys…
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 PASS. The PR changes only the extension fallback, its unit test, and the changelog. The added Python code catches (Exception, SystemExit) and contains no torch.load(..., weights_only=False), `nump…
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 no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded trust_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.

@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 79.15%. Comparing base (a382b8e) to head (17d263a).
⚠️ Report is 5 commits behind head on main.

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     
Flag Coverage Δ
examples-diffusers 19.90% <0.00%> (-0.01%) ⬇️
examples-gpt-oss 13.44% <0.00%> (+<0.01%) ⬆️
examples-hf_ptq 23.34% <0.00%> (-0.04%) ⬇️
examples-llm_distill 13.52% <0.00%> (-0.01%) ⬇️
examples-llm_eval 17.17% <0.00%> (-0.01%) ⬇️
examples-llm_qat 17.34% <0.00%> (-0.04%) ⬇️
examples-llm_sparsity 16.76% <0.00%> (-0.01%) ⬇️
examples-megatron_bridge 26.48% <0.00%> (-0.22%) ⬇️
examples-specdec_bench 13.23% <0.00%> (-0.01%) ⬇️
examples-speculative_decoding 17.42% <0.00%> (-0.07%) ⬇️
examples-torch_onnx 21.21% <0.00%> (-0.03%) ⬇️
examples-torch_trt 15.15% <0.00%> (-0.01%) ⬇️
examples-vllm_serve 17.38% <0.00%> (-0.01%) ⬇️
gpu 59.00% <0.00%> (+7.96%) ⬆️
unit 61.15% <100.00%> (+<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

Copy link
Copy Markdown
Collaborator

/ok to test 17d263a

@kevalmorabia97
kevalmorabia97 merged commit c2c2b49 into NVIDIA:main Oct 26, 2026
53 of 54 checks passed
kevalmorabia97 added a commit that referenced this pull request Oct 28, 2026
#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]>
@rohansjoshi rohansjoshi added the cherry-pick-done Added by bot once PR is cherry-picked to the release branch label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-0.48.0 cherry-pick-done Added by bot once PR is cherry-picked to the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants