Repository navigation
python3Packages.{onnx-graphsurgeon,polygraphy,cppimport,nvidia-modelopt}: init - #577198
Merged
Merged
Conversation
ConnorBaker
force-pushed
the
nvidia-modelopt-init
branch
3 times, most recently
from
October 26, 2026 05:08
55c5a5d to
7f8c6de
Compare
This was referenced Oct 26, 2026
ConnorBaker
force-pushed
the
nvidia-modelopt-init
branch
from
October 26, 2026 17:08
7f8c6de to
faf9f63
Compare
kevalmorabia97
pushed a commit
to NVIDIA/Model-Optimizer
that referenced
this pull request
Oct 26, 2026
### 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 #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](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: 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](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Connor Baker <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
kevalmorabia97
pushed a commit
to NVIDIA/Model-Optimizer
that referenced
this pull request
Oct 26, 2026
### What does this PR do?
Type of change: Bug fix
The PyTorch Geometric quantization plugin is optional:
`modelopt/torch/quantization/plugins/__init__.py` loads it under
`import_plugin("torch_geometric")`. But
`tests/unit/torch/quantization/plugins/test_pytorch_geometric_plugin.py`
imports `torch_geometric` unconditionally, so in an environment without
it, pytest stops at collection and runs nothing else:
```
E ModuleNotFoundError: No module named 'torch_geometric'
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
```
The other tests in that directory that need an optional package
(accelerate, diffusers, peft, transformers) skip when it's missing. This
skips these the same way, with `pytest.importorskip("torch_geometric")`.
`torch-geometric` is in the `dev-test` extra, so CI, which installs it,
isn't affected. This is for environments without it, such as a
distribution's package build.
### Usage
N/A
### Testing
The file together with `tests/unit/torch/test_import.py`, on main at
efda42c:
- Without `torch_geometric`, main: `Interrupted: 1 error during
collection`, nothing runs. With this PR: `1 passed, 1 skipped`.
- With `torch_geometric` 2.8.1 installed, with this PR: the three
geometric tests run and pass.
- `pre-commit run` with this repository's configuration (ruff 0.15.20,
mypy 2.1.0) passes on the changed file.
### 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?: N/A
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
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). The
file is the same in 0.47.0 and `release/0.48.0`.
**AI disclosure:** this change, the testing described above and this
description were produced with Claude Code (Claude Opus 5.5).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Tests**
* Tests for PyTorch Geometric now skip when the optional package is
unavailable.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Signed-off-by: Connor Baker <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
kevalmorabia97
pushed a commit
to NVIDIA/Model-Optimizer
that referenced
this pull request
Oct 26, 2026
### What does this PR do? Type of change: Bug fix Goes back to `setuptools-scm>=8`, the build requirement from before 291498b ("Pin setuptools-scm<10.0 to fix CICD"). That cap went in about two hours after setuptools-scm 10.0.2, the first 10.x release on PyPI that isn't yanked, came out (16:30 UTC on 2026-03-25). Every 10.0.x release aborts the build of a checkout that git reports as having dubious ownership, as in a container whose user doesn't own the checkout: ``` git introspection failed: fatal: detected dubious ownership in repository at '...' ``` The logs of the March runs have expired, so I can't confirm that this was the CI failure. That failure is specific to 10.0.x. Every release from 10.1.1 (on PyPI since 2026-06-22) builds such a checkout, with the same files as a normally owned one. 10.1 takes the file list from the work tree it found for the version, through `git --git-dir=... ls-files`, and git doesn't check ownership for an explicit `--git-dir` (pypa/setuptools-scm#1378 and pypa/setuptools-scm#1405, see Testing). pip installs the newest matching release (and so does uv, by default), so it no longer picks 10.0.x. But the cap keeps out every 10.x release, the fixed ones included: - **Builds without isolation that check the build requirements fail.** Distributions build against the setuptools-scm they ship, and `python -m build --no-isolation` (which Nixpkgs uses, for example) checks the build requirements against it. It refuses setuptools-scm 10.1 or later: `ERROR Unmet dependencies ... setuptools-scm<10,>=8`. Nixpkgs, which has 10.2.1, has to patch the bound out. - **With build isolation, pip picks 9.2.2 instead**, on any index that has it. In a checkout with dubious ownership, 9.2.2 builds, but leaves out every file that only git lists, and only logs `listing git files failed - pretending there aren't any`: - The sdist has 918 of its 2443 files. The 1525 missing are `tests/` (578), `examples/` (496), `tools/` (159), `plugins/` (111), `docs/` (64), `.github/` and others. PyPI has no ModelOpt source sdist (0.46.0rc0 and 0.46.0rc1 have only `wheel-stub` redirects), but `python -m build` makes one by default, and builds the wheel from it. - The wheel misses 19 documentation files (16 `README.md`, 2 `README` and `modelopt_recipes/ptq.md`). The package data that `pyproject.toml` asks for (`*.cpp`, `*.cu`, `*.cuh`, `*.h`, `*.yml`, `*.yaml`) is all there, and no code reads those files, so the wheel works. **`>=8` or `>=8,!=10.0.*`?** Either is fine; this PR uses `>=8`, and I'm happy to switch if you prefer the exclusion. With PyPI as it is, both resolve to 10.3.4. They differ in two places: - In builds that check the build requirements (such as `python -m build --no-isolation`), `!=10.0.*` keeps refusing a 10.0.x that builds a normally owned checkout fine, as the cap does now for everything from 10.0. `>=8` accepts it. Distributions do ship 10.0.x: Repology lists 10.0.5 as the current version in, for example, Chimera, openSUSE Tumbleweed, OpenMandriva Rolling and SageMath. I haven't checked which of them run such a check. - Where an index or a constraint offers nothing newer than 10.0.x, `>=8` picks 10.0.x, which aborts under dubious ownership, while `!=10.0.*` picks 9.2.2 (or fails to resolve). For installs like CI's (`pip install -e`, with isolation), the exclusion is the more conservative choice: it can never pick a release known to abort there. No upper bound either way: there is no setuptools-scm 11, and an upper bound is what keeps 10.1 and later out now. ### Usage N/A ### Testing These ran on main at 3788881, before the rebase onto efda42c (which doesn't touch `pyproject.toml`); the table's wheel builds and the Nixpkgs check were rerun on the rebased commit. Offline, with Python 3.14.8 and setuptools 83.0.0. Dubious ownership is simulated with a `git` wrapper that sets `GIT_TEST_ASSUME_DIFFERENT_OWNER=1`, git's test hook for its ownership check (exporting the variable directly wouldn't work, because setuptools-scm removes `GIT_*` from git's environment). I checked the simulation against a real owner mismatch (a repository owned by another user): git, setuptools-scm's API and the pip builds below behave the same. - **Every setuptools-scm 10.x on PyPI** (10.0.1 to 10.3.4, yanked releases included), pinned exactly, `pip wheel --no-deps .` with build isolation: 10.0.1 to 10.0.5 abort as above; 10.1.1 to 10.3.4 build, and their wheels have the same files as in a normally owned checkout. - **This PR vs. main**, `pip wheel --no-deps .` with build isolation from a local wheelhouse, in a checkout with dubious ownership: | Wheelhouse | main (`>=8,<10`) | this PR (`>=8`) | `>=8,!=10.0.*` | |---|---|---|---| | setuptools-scm 10.3.4 | no matching distribution | 10.3.4, 931 files | 10.3.4, 931 files | | 10.0.2 to 10.0.5 | no matching distribution | 10.0.5, aborts | no matching distribution | | 9.2.2 and 10.0.2 to 10.0.5 (PyPI between March and June) | 9.2.2, **912 files** | 10.0.5, aborts | 9.2.2, **912 files** | | all of the above and 10.1.1 to 10.3.4 | 9.2.2, **912 files** | 10.3.4, 931 files | 10.3.4, 931 files | In a normally owned checkout, every build that runs produces 931 files. Rerun on the rebased commit (and main at efda42c): the same results and file counts. - **sdist**, with a real owner mismatch: 9.2.2 writes 918 files, against 2443 with the checkout marked safe; 10.3.4 writes 2445 (the same 2443 plus `scm_file_list.json` and `scm_version.json`). - **CI's command forms**: a depth-1 clone without tags (as `actions/checkout` makes) shows the same pattern (10.3.4: 931 files, 10.0.5 aborts, 9.2.2: 912). With `pip install -e .` under dubious ownership, 10.0.5 fails with `git introspection failed`; 10.3.4 and 9.2.2 install. - **Which change in 10.1:** I built setuptools-scm and vcs-versioning from pypa/setuptools-scm at commits between 10.0.5 and 10.1.0, then built ModelOpt with them. Every commit builds a normally owned checkout. Under dubious ownership, the first one that builds is pypa/setuptools-scm@324b21d ("use run_git (--git-dir) in file finder", pypa/setuptools-scm#1405). It needs pypa/setuptools-scm@dc2a075 (pypa/setuptools-scm#1378), whose `egg_info.find_sources()` takes the file list from that work tree instead of going through `walk_revctrl()` → `git_find_files()`, which still aborts. With that override disabled, 324b21d and 10.1.0 abort again. - **Nixpkgs** (`python -m build --no-isolation` with setuptools-scm 10.2.1), rerun on the rebased commit: main fails with `Unmet dependencies`; this PR builds. - `pre-commit run` with this repository's configuration passes on the changed file. Not tested: the CI workflows or their containers. ### 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?: N/A - Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: N/A - Did you get Claude approval on this PR?: N/A ### Additional Information Found while packaging ModelOpt 0.47.0 for Nixpkgs (NixOS/nixpkgs#577198), which relaxes the bound in the meantime. 0.47.0 and `release/0.48.0` have the same cap. The open #2167 adds `"setuptools-scm>=8,<10"` to `examples/puzzletron/ci/setup_env.sh`; that still satisfies `>=8`, so the two don't conflict. **AI disclosure:** this change, the testing described above and this description were produced with Claude Code (Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Chores** * Updated the build configuration to support a broader range of compatible build environments. This change affects how the project is prepared for building and does not alter application features or behavior. No user-facing functionality has changed. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Connor Baker <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
kevalmorabia97
pushed a commit
to NVIDIA/Model-Optimizer
that referenced
this pull request
Oct 26, 2026
…3026) ### 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](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: ✅ - 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](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Connor Baker <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
ConnorBaker
force-pushed
the
nvidia-modelopt-init
branch
2 times, most recently
from
October 27, 2026 16:03
5e37ec5 to
9d5dbf0
Compare
ConnorBaker
force-pushed
the
nvidia-modelopt-init
branch
5 times, most recently
from
October 28, 2026 08:32
4ee1abf to
9b67ca4
Compare
ConnorBaker
marked this pull request as ready for review
October 28, 2026 19:47
ConnorBaker
force-pushed
the
nvidia-modelopt-init
branch
from
October 29, 2026 03:08
9b67ca4 to
d057832
Compare
Assisted-by: Claude Code (Claude Opus 5.5)
Assisted-by: Claude Code (Claude Opus 5.5)
Assisted-by: Claude Code (Claude Opus 5.5)
Assisted-by: Claude Code (Claude Opus 5.5)
GaetanLepage
force-pushed
the
nvidia-modelopt-init
branch
from
October 30, 2026 07:20
d057832 to
e350ed2
Compare
Contributor
|
GaetanLepage
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds NVIDIA Model Optimizer and the TensorRT tools it uses:
python3Packages.onnx-graphsurgeon: init at 0.6.2, from NVIDIA/TensorRTtools/onnx-graphsurgeon(PyPI stops at 0.6.1: Publish onnx-graphsurgeon 0.6.2 NVIDIA/TensorRT#4895).python3Packages.polygraphy: init at 0.53.6, from NVIDIA/TensorRTtools/Polygraphy. TensorRT 11.3 removed itssetup.py(OSS release exports drop pyproject.toml files; Polygraphy can't be built from source since 11.3 NVIDIA/TensorRT#4894), so this vendors thepyproject.tomlcommit of #4894 - Polygraphy: add the missing pyproject.toml NVIDIA/TensorRT#4896 (open).python3Packages.cppimport: init at 26.04.17; modelopt's ONNX INT4 quantization imports it.python3Packages.nvidia-modelopt: init at 0.47.0, from the GitHub tag (PyPI only has wheels).onnx-graphsurgeon and polygraphy build from
cudaPackages.tensorrt-samples.src, the TensorRT OSS release ofcudaPackages.tensorrt(v11.4), so Nixpkgs fetches that tree once.Update scripts:
versionto the tool's__version__in that source, so a TensorRT update should run them in the same change.--use-github-releases, because the default releases feed also lists upstream's0.48.0devtag as a stable version.For review:
version. With Jetson capabilities, for example, it selects TensorRT 11.1, whose tools are 0.6.1 and 0.49.27, so their builds would fail, at the latest inpythonMetadataCheckPhase(not built).postFixup, because stripping would invalidate cppimport's checksum.torch-geometricis a check input, so the PyTorch Geometric plugin tests run.torch.utils.cpp_extension, so users need a CUDA toolkit (nvcc and the CUDA runtime headers) and a C++ compiler and ninja available. Without them, integer and FP8 fake quantization fall back to PyTorch, but MX quantization raises; so does NVFP4, unless Triton is available and the GPU's compute capability is at least 8.9, in which case it uses a Triton kernel instead.wonderwords(not packaged),cupy-cuda12x(optional; INT4 quantization falls back to NumPy) andmlflow.RuntimeError: Failed to initialize cpuinfo!: the sandbox has no/sysat all (checked on an aarch64-linux builder), the cause torch-cluster and accelerate cite for the same deselects. Outside the sandbox, on a GB10, the 6 polygraphy tests and 4 of the 5 nvidia-modelopt tests pass.test_chained_modes_preserve_forward_patching_during_quantizefails there too, differently: oneDNN can't create a float16 convolution.Testing, at this push merged into master ecbf60a (2026-10-28), with Python 3.14:
cudaSupport(cudaCapabilities = [ "8.9" ]):gpuCheck: 180 passed, 30 skipped on an RTX 4090.cudaSupport(cudaCapabilities = [ "12.1" ]):gpuCheck, run outside the sandbox on a GB10 (the build sandbox there has no GPU): 180 passed, 30 skipped.maintainers/scripts/update.nixon an earlier push (not re-run at this one; theupdateScripts are unchanged):allowAliases = falseandcheckMeta = true. WithcudaSupport, all four evaluate on the two Linux systems.gpuCheckin an aarch64-linux build sandbox.🤖 Generated with Claude Code