mirror of
https://github.com/NVIDIA/Model-Optimizer.git
synced 2026-10-21 06:10:05 +08:00
### What does this PR do? Type of change: New feature / infrastructure improvement Follow-up to #1285 for correct CI test environment for megatron based tests Replaces `tox` + `tox-current-env` with `nox` for all test, lint, docs, and wheel build sessions. The primary motivation was that `tox-current-env` is incompatible with uv venvs in NGC containers (e.g. NeMo's `/opt/venv`) — it picks the system Python via `sys._base_executable` instead of the container's venv Python which has megatron packages pre-installed. Key changes: - **`noxfile.py`** replaces `tox.ini` with GPU, CPU unit, partial-install, pre-commit, docs, and wheel sessions - **GPU sessions** use `venv_backend="none"` (run directly in container env) and `python -m pip/pytest` to avoid PATH mismatches - **uv** is set as the default venv backend (if available) for CPU sessions (faster installs) Also includes CI workflow simplifications: - **`_pr_gate.yml`** new reusable workflow centralizing file-change detection + linux-check wait logic (was duplicated across 3 workflow files) - **Collapsed pr/non-pr job pairs** into single jobs with conditional `runs-on` in `gpu_tests.yml`, `example_tests.yml`, `regression_tests.yml` - **Collapsed `multi-py` / `multi-torch` / `multi-transformers`** into a single `multi-version` matrix job in `unit_tests.yml` - **PR path filtering** for unit test secondary jobs (multi-version, launcher, partial-install) — skipped if no relevant files changed - **Fixed schedule/workflow_dispatch skipping** — jobs with `needs: [pr-gate]` were incorrectly skipped when all pr-gate internal jobs were skipped; fixed by making the gate job always run - **multi-version, launcher, partial-install** now also run on `schedule` / `workflow_dispatch` ### Usage ```bash python -m pip install nox uv # install nox and uv (once) nox -l # list all sessions nox -s gpu_megatron # run a GPU session (inside container) nox -s "unit-3.12(torch_211, tf_latest)" # run a specific unit test combination nox -s "unit-3.12(torch_211, tf_latest)" -R # force-recreate venv (e.g. after dep changes) COVERAGE_PROCESS_START=pyproject.toml nox -s "unit-3.12(torch_211, tf_latest)" # with coverage ``` ### Testing - Ran `nox -l` to verify all session names - Ran `gpu_megatron` session locally inside NeMo container — confirmed it uses `/opt/venv/bin/python` correctly - Manually triggered nightly-runs: - Unit: https://github.com/NVIDIA/Model-Optimizer/actions/runs/24608013657 - GPU: https://github.com/NVIDIA/Model-Optimizer/actions/runs/24608018763 - Examples: https://github.com/NVIDIA/Model-Optimizer/actions/runs/24608017322 ### Before your PR is "*Ready for review*" Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md) and your commits are signed (`git commit -s -S`). Make sure you read and follow the [Security Best Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors) (e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(..., weights_only=False)`, `pickle`, etc.). - Is this change backward compatible?: N/A — CI infrastructure only - If you copied code from any other sources or added a new PIP dependency, did you follow guidance in `CONTRIBUTING.md`: ✅ (added `nox` and `uv` to `dev-test`, both Apache-2.0) - 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 — no user-facing changes ### Additional Information Supersedes the tox-current-env workaround in the parent branch. --------- Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
340 lines
10 KiB
TOML
340 lines
10 KiB
TOML
####################################################################################################
|
|
############################### BUILD CONFIGURATION ##############################################
|
|
####################################################################################################
|
|
[build-system]
|
|
requires = ["setuptools>=80", "setuptools-scm>=8,<10"]
|
|
build-backend = "setuptools.build_meta"
|
|
|
|
[tool.setuptools_scm]
|
|
fallback_version = "0.0.0"
|
|
|
|
|
|
####################################################################################################
|
|
############################### PROJECT METADATA #################################################
|
|
####################################################################################################
|
|
[project]
|
|
name = "nvidia-modelopt"
|
|
dynamic = ["version"]
|
|
description = "Nvidia Model Optimizer: a unified model optimization and deployment toolkit."
|
|
readme = { text = "Checkout https://github.com/nvidia/Model-Optimizer for more information.", content-type = "text/markdown" }
|
|
license = "Apache-2.0"
|
|
license-files = ["LICENSE_HEADER"]
|
|
requires-python = ">=3.10,<3.14"
|
|
authors = [{ name = "NVIDIA Corporation" }]
|
|
classifiers = [
|
|
"Programming Language :: Python :: 3",
|
|
"Programming Language :: Python :: 3.10",
|
|
"Programming Language :: Python :: 3.11",
|
|
"Programming Language :: Python :: 3.12",
|
|
"Programming Language :: Python :: 3.13",
|
|
"Intended Audience :: Developers",
|
|
"Intended Audience :: Science/Research",
|
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
]
|
|
dependencies = [
|
|
# Common
|
|
"ninja", # for faster building of C++ / CUDA extensions
|
|
"numpy",
|
|
"nvidia-ml-py>=12",
|
|
"packaging",
|
|
"setuptools>=80", # torch.utils.cpp_extension imports setuptools at load time
|
|
"torch>=2.8",
|
|
"tqdm",
|
|
# modelopt.torch
|
|
"PyYAML>=6.0",
|
|
"omegaconf>=2.3.0",
|
|
"pulp<4.0", # breaking changes in upcoming 4.0 release
|
|
"pydantic>=2.0",
|
|
"regex",
|
|
"rich",
|
|
"safetensors",
|
|
"scipy",
|
|
]
|
|
|
|
[project.optional-dependencies]
|
|
onnx = [
|
|
"cppimport",
|
|
"cupy-cuda12x; platform_machine != 'aarch64' and platform_system != 'Darwin'",
|
|
"lief",
|
|
"ml_dtypes",
|
|
"onnx-graphsurgeon>=0.6.1",
|
|
"onnx~=1.21.0",
|
|
"onnxconverter-common~=1.16.0",
|
|
# ORT for Windows
|
|
"onnxruntime-gpu==1.22.0; platform_system == 'Windows'",
|
|
# ORT with Python <= 3.10
|
|
"onnxruntime~=1.22.0; python_version <= '3.10' and (platform_machine == 'aarch64' or platform_system == 'Darwin')",
|
|
"onnxruntime-gpu~=1.22.0; python_version <= '3.10' and platform_machine != 'aarch64' and platform_system != 'Darwin' and platform_system != 'Windows'",
|
|
# ORT with Python > 3.10
|
|
"onnxruntime~=1.24.2; python_version > '3.10' and (platform_machine == 'aarch64' or platform_system == 'Darwin')",
|
|
"onnxruntime-gpu~=1.24.2; python_version > '3.10' and platform_machine != 'aarch64' and platform_system != 'Darwin' and platform_system != 'Windows'",
|
|
"onnxscript",
|
|
"onnxslim>=0.1.76",
|
|
"polygraphy>=0.49.22",
|
|
]
|
|
hf = [
|
|
"accelerate>=1.0.0",
|
|
"datasets>=3.0.0",
|
|
"deepspeed>=0.9.6; platform_system != 'Darwin' and platform_system != 'Windows'",
|
|
"diffusers>=0.32.2",
|
|
"huggingface_hub>=0.24.0",
|
|
"nltk",
|
|
"peft>=0.17.0",
|
|
"sentencepiece>=0.2.1", # Also implicitly used in test_unified_export_megatron, test_vllm_fakequant_megatron_export
|
|
"tiktoken",
|
|
"transformers>=4.56", # Should match modelopt/torch/__init__.py and noxfile.py
|
|
"wonderwords",
|
|
]
|
|
|
|
puzzletron = [ # Dependedencies for modelopt.torch.puzzletron subpackage
|
|
"fire",
|
|
"hydra-core==1.3.2",
|
|
"immutabledict",
|
|
"lru-dict",
|
|
"pandas",
|
|
"typeguard",
|
|
]
|
|
dev-lint = [
|
|
"bandit[toml]==1.7.9", # security/compliance checks
|
|
"mypy==1.17.1",
|
|
"pre-commit==4.3.0",
|
|
"ruff==0.12.11",
|
|
]
|
|
dev-docs = [
|
|
"autodoc_pydantic>=2.1.0",
|
|
"sphinx~=8.1.0",
|
|
"sphinx-argparse>=0.5.2",
|
|
"sphinx-autobuild>=2024.10.3",
|
|
"sphinx-copybutton>=0.5.2",
|
|
"sphinx-inline-tabs>=2023.4.21",
|
|
"sphinx-rtd-theme~=3.0.0",
|
|
"sphinx-togglebutton>=0.3.2",
|
|
]
|
|
dev-test = [
|
|
"coverage[toml]>=7.13.0", # a1_coverage.pth for subprocess tracking requires this
|
|
"nox",
|
|
"pytest",
|
|
"pytest-cov",
|
|
"pytest-instafail",
|
|
"pytest-timeout",
|
|
"uv",
|
|
# test-specific dependencies
|
|
"timm",
|
|
"torchprofile==0.0.4", # optional dependency for modelopt.torch
|
|
"torchvision",
|
|
"torch-geometric",
|
|
]
|
|
# Compound extras via self-references
|
|
all = ["nvidia-modelopt[onnx,hf,puzzletron]"]
|
|
dev = ["nvidia-modelopt[all,dev-docs,dev-lint,dev-test]"]
|
|
|
|
[project.urls]
|
|
Homepage = "https://github.com/NVIDIA/Model-Optimizer"
|
|
|
|
[tool.setuptools.packages.find]
|
|
include = ["modelopt*"]
|
|
|
|
[tool.setuptools.package-data]
|
|
modelopt = ["**/*.h", "**/*.cpp", "**/*.cu"]
|
|
modelopt_recipes = ["**/*.yml", "**/*.yaml"]
|
|
|
|
[tool.uv]
|
|
managed = true
|
|
# override-dependencies = ["torch; sys_platform == 'never'"]
|
|
|
|
|
|
####################################################################################################
|
|
############################### LINTING, FORMATTING CONFIGURATION ################################
|
|
####################################################################################################
|
|
[tool.ruff]
|
|
target-version = "py310"
|
|
line-length = 100 # Line length limit for code
|
|
fix = true
|
|
|
|
[tool.ruff.format]
|
|
# Like Black, respect magic trailing commas.
|
|
skip-magic-trailing-comma = false
|
|
docstring-code-format = true
|
|
# Set the line length limit used when formatting code snippets in docstrings.
|
|
docstring-code-line-length = "dynamic"
|
|
|
|
[tool.ruff.lint]
|
|
# See available rules at https://docs.astral.sh/ruff/rules/
|
|
# Flake8 is equivalent to pycodestyle + pyflakes + mccabe.
|
|
select = [
|
|
"C4", # Flake8 comprehensions
|
|
"D", # pydocstyle
|
|
"E", # pycodestyle errors
|
|
"F", # pyflakes
|
|
"FURB", # refurb
|
|
"I", # isort
|
|
"ISC", # flake8-implicit-str-concat
|
|
"N", # pep8 naming
|
|
"PERF", # Perflint
|
|
"PGH", # pygrep-hooks
|
|
"PIE", # flake8-pie
|
|
"PLE", # pylint errors
|
|
"PLR", # pylint refactor
|
|
"PT", # flake8-pytest-style
|
|
"RUF", # ruff
|
|
"SIM", # flake8-simplify
|
|
"TC", # flake8-type-checking
|
|
"UP", # pyupgrade
|
|
"W", # pycodestyle warnings
|
|
]
|
|
extend-ignore = [
|
|
"D105",
|
|
"D417",
|
|
"N812",
|
|
"PLR0402",
|
|
"PLR0912",
|
|
"PLR0913",
|
|
"PLR0915",
|
|
"PLR2004",
|
|
"PLR0911",
|
|
"PT011",
|
|
"PT018",
|
|
"PT028",
|
|
"PT030",
|
|
"RUF002",
|
|
"RUF012",
|
|
"SIM102",
|
|
"SIM108",
|
|
"SIM115",
|
|
"UP032",
|
|
"UP038",
|
|
]
|
|
|
|
|
|
[tool.ruff.lint.per-file-ignores]
|
|
"__init__.py" = ["F401", "F403"]
|
|
"examples/*" = ["D"]
|
|
"noxfile.py" = ["D", "E501"]
|
|
"tests/*" = ["B017", "D", "E402", "PT012"]
|
|
"*/_[a-zA-Z]*" = ["D"] # Private packages (_abc/*.py) or modules (_xyz.py)
|
|
"*.ipynb" = [
|
|
"D",
|
|
"E501",
|
|
] # Ignore missing docstrings or line length for Jupyter notebooks
|
|
"modelopt/torch/puzzletron/*" = [
|
|
"C4",
|
|
"D",
|
|
"E",
|
|
"F",
|
|
"N",
|
|
"PERF",
|
|
"RUF",
|
|
"SIM",
|
|
"UP",
|
|
] # TODO: Disabled for now, will enable later, once all puzzletron code is migrated
|
|
"modelopt/torch/quantization/triton/*" = ["N803", "N806", "E731"] # triton style
|
|
"modelopt/torch/sparsity/attention_sparsity/kernels/*" = [
|
|
"N803",
|
|
"N806",
|
|
] # triton kernel style
|
|
"examples/deepseek/ds_kernel.py" = ["N803", "N806", "E731"] # triton style
|
|
|
|
[tool.ruff.lint.pycodestyle]
|
|
max-line-length = 120 # Line length limit for comments and docstrings
|
|
|
|
|
|
[tool.ruff.lint.pydocstyle]
|
|
convention = "google"
|
|
|
|
|
|
[tool.ruff.lint.isort]
|
|
known-first-party = ["modelopt"]
|
|
split-on-trailing-comma = false
|
|
|
|
|
|
[tool.mypy]
|
|
files = "."
|
|
install_types = true
|
|
non_interactive = true
|
|
show_error_codes = true
|
|
disable_error_code = [
|
|
"assignment",
|
|
"operator",
|
|
"has-type",
|
|
"var-annotated",
|
|
"override",
|
|
]
|
|
explicit_package_bases = true
|
|
namespace_packages = true
|
|
# strict checks
|
|
strict = true
|
|
disallow_subclassing_any = false
|
|
disallow_untyped_decorators = false
|
|
disallow_any_generics = false
|
|
disallow_untyped_calls = false
|
|
disallow_incomplete_defs = false
|
|
disallow_untyped_defs = false
|
|
warn_return_any = false
|
|
|
|
|
|
[[tool.mypy.overrides]]
|
|
module = ["tests.*"]
|
|
ignore_errors = true
|
|
|
|
[[tool.mypy.overrides]]
|
|
module = ["examples.*"]
|
|
disable_error_code = ["attr-defined"]
|
|
|
|
[tool.bandit]
|
|
exclude_dirs = [".github/", "examples/", "noxfile.py", "tests/"]
|
|
# Do not change `skips`. It should be consistent with NVIDIA's Wheel-CI-CD bandit.yml config.
|
|
# Use of `# nosec BXXX` requires special approval
|
|
skips = [
|
|
"B101", # assert_used
|
|
"B110", # try_except_pass
|
|
"B112", # try_except_continue
|
|
"B303", # MD2, MD4, MD5, or SHA1
|
|
"B311", # random
|
|
]
|
|
|
|
|
|
####################################################################################################
|
|
############################### TESTING CONFIGURATION ############################################
|
|
####################################################################################################
|
|
[tool.pytest.ini_options]
|
|
# Default additional options
|
|
# Show a short test summary info for all except passed tests with -ra flag
|
|
# print execution time for 50 slowest tests and generate coverage reports
|
|
addopts = "-v -ra --instafail --cov-report=term-missing --cov-report=html --cov-report=xml:coverage.xml --cov-config=pyproject.toml --durations=50 --strict-markers"
|
|
pythonpath = ["tests/"]
|
|
markers = [
|
|
"manual: Only run when --run-manual is given",
|
|
"release: Regression tests that should be run before every release",
|
|
]
|
|
|
|
|
|
[tool.coverage.run]
|
|
branch = false
|
|
parallel = true
|
|
concurrency = ["multiprocessing", "thread"]
|
|
source_pkgs = ["modelopt", "modelopt_recipes"]
|
|
|
|
|
|
[tool.coverage.report]
|
|
skip_covered = true
|
|
ignore_errors = true
|
|
exclude_lines = [
|
|
"pragma: no cover",
|
|
# Don't complain about missing debug or verbose code
|
|
"def __repr__",
|
|
"if verbose",
|
|
# Don't complain if tests don't hit defensive exception handling code
|
|
"raise AssertionError",
|
|
"raise NotImplementedError",
|
|
"raise RuntimeError",
|
|
"raise ValueError",
|
|
"raise KeyError",
|
|
"raise AttributeError",
|
|
"except ImportError",
|
|
# Don't complain if non-runnable code isn't run
|
|
"if __name__ == \"__main__\":",
|
|
"if TYPE_CHECKING:",
|
|
# Don't complain about abstract methods, they aren't run
|
|
"@(abc\\.)?abstractmethod",
|
|
]
|