Skip to content

Commit 0f668a3

Browse files
Replace setup.py with uv-compatible pyproject.toml and add uv.lock for nspect scanning (#945)
## What does this PR do? **Type of change:** Project config update <!-- Use one of the following: Bug fix, new feature, new example, new tests, documentation. --> Remove unnecessary setup.py as the same can be done with pyproject.toml. No change for users in terms of installation command. ## Testing <!-- Mention how have you tested your change if applicable. --> Per PR tests passing is sufficient validation <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Migrated project configuration from setup.py to pyproject.toml, adopting modern Python packaging standards. * Updated CI/CD workflows and development tools to reference the new configuration location. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
1 parent 94b2cb2 commit 0f668a3

12 files changed

Lines changed: 3599 additions & 161 deletions

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ LICENSE @NVIDIA/modelopt-setup-codeowners
99
LICENSE_HEADER @NVIDIA/modelopt-setup-codeowners
1010
pyproject.toml @NVIDIA/modelopt-setup-codeowners
1111
SECURITY.md @NVIDIA/modelopt-setup-codeowners
12-
setup.py @NVIDIA/modelopt-setup-codeowners
1312
tox.ini @NVIDIA/modelopt-setup-codeowners
1413

1514
# Library

.github/workflows/bump_uv_lock.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Bump uv.lock
2+
3+
on:
4+
schedule:
5+
- cron: "0 9 * * 1" # Every Monday at 9:00 UTC
6+
workflow_dispatch: # On-demand
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
bump-uv-lock:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 15
16+
steps:
17+
- uses: actions/checkout@v6
18+
with:
19+
ref: ${{ github.ref_name }}
20+
- uses: actions/setup-python@v6
21+
with:
22+
python-version: "3.12"
23+
- run: pip install uv toml
24+
- name: Enable torch override in pyproject.toml to avoid unnecessary nvidia-cu* dependencies in uv.lock
25+
run: |
26+
python -c "
27+
import toml
28+
t = toml.load('pyproject.toml')
29+
t['tool']['uv']['override-dependencies'] = ['torch; sys_platform == \"never\"']
30+
toml.dump(t, open('pyproject.toml', 'w'))
31+
"
32+
- run: uv lock --upgrade
33+
- name: Check for changes
34+
id: changes
35+
run: |
36+
if git diff --quiet; then
37+
echo "changed=false" >> "$GITHUB_OUTPUT"
38+
else
39+
echo "changed=true" >> "$GITHUB_OUTPUT"
40+
fi
41+
- name: Create pull request
42+
if: steps.changes.outputs.changed == 'true'
43+
env:
44+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
BASE="${{ github.ref_name }}"
47+
SAFE_BASE=$(echo "$BASE" | tr '/' '-')
48+
BRANCH="auto/bump-uv-lock-${SAFE_BASE}-$(date +%Y-%m-%d)"
49+
git checkout -b "$BRANCH"
50+
git add uv.lock
51+
git config user.name "github-actions[bot]"
52+
git config user.email "github-actions[bot]@users.noreply.github.com"
53+
git commit -m "[chore]: bump uv.lock"
54+
git push origin "$BRANCH"
55+
gh pr create \
56+
--title "[chore]: weekly bump of uv.lock on ${BASE} ($(date +%Y-%m-%d))" \
57+
--body "$(cat <<'EOF'
58+
## Summary
59+
Automated weekly update of uv.lock file for nSpect Scanning:
60+
- `uv.lock` — upgraded all transitive dependencies to latest compatible versions
61+
EOF
62+
)" \
63+
--base "$BASE"

.github/workflows/example_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
.github/workflows/example_tests.yml
4343
examples/**
4444
modelopt/**
45-
setup.py
45+
pyproject.toml
4646
tests/examples/**
4747
fail_on_initial_diff_error: true
4848
wait-checks:

.github/workflows/gpu_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
.github/workflows/gpu_tests.yml
4444
modelopt/**
4545
tests/gpu/**
46+
pyproject.toml
4647
tox.ini
47-
setup.py
4848
fail_on_initial_diff_error: true
4949
wait-checks:
5050
needs: [check-file-changes]

.github/workflows/unit_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- ".github/workflows/unit_tests.yml"
1111
- "modelopt/**"
1212
- "tests/unit/**"
13-
- "setup.py"
13+
- "pyproject.toml"
1414
- "tox.ini"
1515
schedule:
1616
- cron: "0 0 * * *" # Nightly

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NOTE: Make sure to update version in dev requirements (setup.py) as well!
1+
# NOTE: Make sure to update version in dev requirements (pyproject.toml) as well!
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: v6.0.0
@@ -7,6 +7,7 @@ repos:
77
args: [--maxkb=500, --enforce-all]
88
exclude: >
99
(?x)^(
10+
uv.lock|
1011
examples/diffusers/quantization/assets/.*.png|
1112
examples/diffusers/cache_diffusion/assets/.*.png|
1213
)$

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ NVIDIA Model Optimizer Changelog (Linux)
1818
- Add support for advanced weight scale search for NVFP4 quantization and its export path.
1919
- Enable PTQ workflow for Qwen3.5 MoE models.
2020

21+
**Misc**
22+
23+
- Migrated project metadata from ``setup.py`` to a fully declarative ``pyproject.toml``.
24+
2125
0.42 (2026-02-xx)
2226
^^^^^^^^^^^^^^^^^
2327

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pip install -e .[dev]
7979

8080
You can also directly use the [TensorRT-LLM docker images](https://catalog.ngc.nvidia.com/orgs/nvidia/teams/tensorrt-llm/containers/release/tags)
8181
(e.g., `nvcr.io/nvidia/tensorrt-llm/release:<version>`), which have Model Optimizer pre-installed.
82-
Make sure to upgrade Model Optimizer to the latest version using ``pip`` as described above.
82+
Make sure to upgrade Model Optimizer to the latest version as described above.
8383
Visit our [installation guide](https://nvidia.github.io/Model-Optimizer/getting_started/2_installation.html) for
8484
more fine-grained control on installed dependencies or for alternative docker images and environment variables to setup.
8585

pyproject.toml

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,122 @@ requires = ["cython", "setuptools>=80", "setuptools-scm>=8"]
66
build-backend = "setuptools.build_meta"
77

88
[tool.setuptools_scm]
9+
fallback_version = "0.0.0"
10+
11+
12+
####################################################################################################
13+
############################### PROJECT METADATA #################################################
14+
####################################################################################################
15+
[project]
16+
name = "nvidia-modelopt"
17+
dynamic = ["version"]
18+
description = "Nvidia Model Optimizer: a unified model optimization and deployment toolkit."
19+
readme = { text = "Checkout https://github.com/nvidia/Model-Optimizer for more information.", content-type = "text/markdown" }
20+
license = "Apache-2.0"
21+
license-files = ["LICENSE_HEADER"]
22+
requires-python = ">=3.10,<3.13"
23+
authors = [{ name = "NVIDIA Corporation" }]
24+
classifiers = [
25+
"Programming Language :: Python :: 3",
26+
"Intended Audience :: Developers",
27+
"Intended Audience :: Science/Research",
28+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
29+
]
30+
dependencies = [
31+
# Common
32+
"ninja", # for faster building of C++ / CUDA extensions
33+
"numpy",
34+
"nvidia-ml-py>=12",
35+
"packaging",
36+
"setuptools>=80", # torch.utils.cpp_extension imports setuptools at load time
37+
"torch>=2.6",
38+
"tqdm",
39+
# modelopt.torch
40+
"pulp",
41+
"pydantic>=2.0",
42+
"regex",
43+
"rich",
44+
"safetensors",
45+
"scipy",
46+
]
47+
48+
[project.optional-dependencies]
49+
onnx = [
50+
"cppimport",
51+
"cupy-cuda12x; platform_machine != 'aarch64' and platform_system != 'Darwin'",
52+
"lief",
53+
"ml_dtypes",
54+
"onnx-graphsurgeon",
55+
"onnx~=1.19.0",
56+
"onnxconverter-common~=1.16.0",
57+
# ORT for Windows
58+
"onnxruntime-gpu==1.22.0; platform_system == 'Windows'",
59+
# ORT with Python <= 3.10
60+
"onnxruntime~=1.22.0; python_version <= '3.10' and (platform_machine == 'aarch64' or platform_system == 'Darwin')",
61+
"onnxruntime-gpu~=1.22.0; python_version <= '3.10' and platform_machine != 'aarch64' and platform_system != 'Darwin' and platform_system != 'Windows'",
62+
# ORT with Python > 3.10
63+
"onnxruntime~=1.24.2; python_version > '3.10' and (platform_machine == 'aarch64' or platform_system == 'Darwin')",
64+
"onnxruntime-gpu~=1.24.2; python_version > '3.10' and platform_machine != 'aarch64' and platform_system != 'Darwin' and platform_system != 'Windows'",
65+
"onnxscript",
66+
"onnxslim>=0.1.76",
67+
"polygraphy>=0.49.22",
68+
]
69+
hf = [
70+
"accelerate>=1.0.0",
71+
"datasets>=3.0.0",
72+
"deepspeed>=0.9.6; platform_system != 'Darwin' and platform_system != 'Windows'",
73+
"diffusers>=0.32.2",
74+
"huggingface_hub>=0.24.0",
75+
"nltk",
76+
"peft>=0.17.0",
77+
"transformers>=4.53,<5.0", # Should match modelopt/torch/__init__.py and tox.ini
78+
"wonderwords",
79+
]
80+
dev-lint = [
81+
"bandit[toml]==1.7.9", # security/compliance checks
82+
"mypy==1.17.1",
83+
"pre-commit==4.3.0",
84+
"ruff==0.12.11",
85+
]
86+
dev-docs = [
87+
"autodoc_pydantic>=2.1.0",
88+
"sphinx~=8.1.0",
89+
"sphinx-argparse>=0.5.2",
90+
"sphinx-autobuild>=2024.10.3",
91+
"sphinx-copybutton>=0.5.2",
92+
"sphinx-inline-tabs>=2023.4.21",
93+
"sphinx-rtd-theme~=3.0.0",
94+
"sphinx-togglebutton>=0.3.2",
95+
]
96+
dev-test = [
97+
"pytest",
98+
"pytest-cov",
99+
"pytest-instafail",
100+
"pytest-timeout",
101+
"sentencepiece",
102+
"timm",
103+
"torchprofile>=0.0.4", # optional dependency for modelopt.torch
104+
"torchvision",
105+
"torch-geometric",
106+
"tox>4.18",
107+
"tox-current-env>=0.0.12",
108+
]
109+
# Compound extras via self-references
110+
all = ["nvidia-modelopt[onnx,hf]"]
111+
dev = ["nvidia-modelopt[all,dev-docs,dev-lint,dev-test]"]
112+
113+
[project.urls]
114+
Homepage = "https://github.com/NVIDIA/Model-Optimizer"
115+
116+
[tool.setuptools.packages.find]
117+
include = ["modelopt*"]
118+
119+
[tool.setuptools.package-data]
120+
modelopt = ["**/*.h", "**/*.cpp", "**/*.cu"]
121+
122+
[tool.uv]
123+
managed = true
124+
# override-dependencies = ["torch; sys_platform == 'never'"]
9125

10126

11127
####################################################################################################
@@ -142,7 +258,6 @@ markers = [
142258

143259

144260
[tool.coverage.run]
145-
# measure branch coverage in addition to statement coverage
146261
branch = false
147262
include = ["modelopt/*"]
148263
omit = ["*/plugins/*", "*/export/*"]

0 commit comments

Comments
 (0)