Skip to content

Commit f13a63d

Browse files
committed
refactor(//py)!: Build system is now PEP517 compatible
BREAKING CHANGE: A ton of files have been moved in order to support PEP517 standards based builds. Users are now advised to use commands such as the following: Editable installs: python -m pip install --verbose --pre -e . [if necessary add --index-url to access nightly builds of pytorch] Wheel files: python -m pip wheel --verbose --pre . [if necessary add --index-url to access nightly builds of pytorch] --config-setting="--build-option=<options you would pass to setup.py>" -w dist Alternative build processes are also supported pypa/build: python -m build --wheel --skip-dependency-check --no-isolation > Skip dependency check means you need to install py/requirements.txt first due to issues with TensorRT's python package Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> tools: adding a pyproject.toml linter Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent 4c5c564 commit f13a63d

11 files changed

+229
-104
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ bazel-tensorrt
6666
*.cache
6767
*cifar-10-batches-py*
6868
bazel-project
69-
build/
69+
build/
70+
wheelhouse/

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ repos:
3030
args:
3131
- --warnings=all
3232
- id: buildifier-lint
33+
- repo: https://github.com/abravalheri/validate-pyproject
34+
rev: v0.13
35+
hooks:
36+
- id: validate-pyproject
3337
- repo: local
3438
hooks:
3539
- id: dont-commit-upstream

py/ci/Dockerfile.ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM pytorch/manylinux-builder:cuda11.7
1+
FROM pytorch/manylinux-builder:cuda11.8
22
ARG trt_version
33

44
RUN echo -e "Installing with TensorRT ${trt_version}"

py/ci/build_manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
py38
22
py39
33
py310
4+
py311
45
libtorchtrt_pre_cxx11_abi

py/ci/build_whl.sh

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,84 +8,96 @@ export PROJECT_DIR=/workspace/project
88

99
cp -r $CUDA_HOME /usr/local/cuda
1010

11+
build_wheel() {
12+
$1/bin/python -m pip install --upgrade pip
13+
$1/bin/python -m pip wheel . --config-setting="--build-option=--release" --config-setting="--build-option=--ci" -w dist
14+
}
15+
16+
patch_wheel() {
17+
$2/bin/python -m pip install auditwheel
18+
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$1/torch/lib:$1/tensorrt/:${CUDA_HOME}/lib64:${CUDA_HOME}/lib64/stubs $2/bin/python -m auditwheel repair $(cat ${PROJECT_DIR}/py/ci/soname_excludes.params) --plat manylinux_2_34_x86_64 dist/torch_tensorrt-*-$3-linux_x86_64.whl
19+
}
20+
1121
py37() {
12-
cd /workspace/project/py
22+
cd /workspace/project
1323
PY_BUILD_CODE=cp37-cp37m
1424
PY_VERSION=3.7
1525
PY_NAME=python${PY_VERSION}
1626
PY_DIR=/opt/python/${PY_BUILD_CODE}
1727
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
18-
${PY_DIR}/bin/python -m pip install --upgrade pip
19-
${PY_DIR}/bin/python -m pip install -r requirements.txt
20-
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
21-
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
22-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PY_PKG_DIR}/torch/lib:${PY_PKG_DIR}/tensorrt/:${CUDA_HOME}/lib64:${CUDA_HOME}/lib64/stubs ${PY_DIR}/bin/python -m auditwheel repair $(cat ${PROJECT_DIR}/py/ci/soname_excludes.params) --plat manylinux_2_17_x86_64 dist/torch_tensorrt-*-${PY_BUILD_CODE}-linux_x86_64.whl
28+
build_wheel ${PY_DIR}
29+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
2330
}
2431

2532
py38() {
26-
cd /workspace/project/py
33+
cd /workspace/project
2734
PY_BUILD_CODE=cp38-cp38
2835
PY_VERSION=3.8
2936
PY_NAME=python${PY_VERSION}
3037
PY_DIR=/opt/python/${PY_BUILD_CODE}
3138
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
32-
${PY_DIR}/bin/python -m pip install --upgrade pip
33-
${PY_DIR}/bin/python -m pip install -r requirements.txt
34-
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
35-
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
36-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PY_PKG_DIR}/torch/lib:${PY_PKG_DIR}/tensorrt/:${CUDA_HOME}/lib64:${CUDA_HOME}/lib64/stubs ${PY_DIR}/bin/python -m auditwheel repair $(cat ${PROJECT_DIR}/py/ci/soname_excludes.params) --plat manylinux_2_17_x86_64 dist/torch_tensorrt-*-${PY_BUILD_CODE}-linux_x86_64.whl
39+
build_wheel ${PY_DIR}
40+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
3741
}
3842

3943
py39() {
40-
cd /workspace/project/py
44+
cd /workspace/project
4145
PY_BUILD_CODE=cp39-cp39
4246
PY_VERSION=3.9
4347
PY_NAME=python${PY_VERSION}
4448
PY_DIR=/opt/python/${PY_BUILD_CODE}
4549
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
46-
${PY_DIR}/bin/python -m pip install --upgrade pip
47-
${PY_DIR}/bin/python -m pip install -r requirements.txt
48-
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
49-
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
50-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PY_PKG_DIR}/torch/lib:${PY_PKG_DIR}/tensorrt/:${CUDA_HOME}/lib64:${CUDA_HOME}/lib64/stubs ${PY_DIR}/bin/python -m auditwheel repair $(cat ${PROJECT_DIR}/py/ci/soname_excludes.params) --plat manylinux_2_17_x86_64 dist/torch_tensorrt-*-${PY_BUILD_CODE}-linux_x86_64.whl
50+
build_wheel ${PY_DIR}
51+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
5152
}
5253

5354
py310() {
54-
cd /workspace/project/py
55+
cd /workspace/project
5556
PY_BUILD_CODE=cp310-cp310
5657
PY_VERSION=3.10
5758
PY_NAME=python${PY_VERSION}
5859
PY_DIR=/opt/python/${PY_BUILD_CODE}
5960
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
60-
${PY_DIR}/bin/python -m pip install --upgrade pip
61-
${PY_DIR}/bin/python -m pip install -r requirements.txt
62-
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
63-
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
64-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PY_PKG_DIR}/torch/lib:${PY_PKG_DIR}/tensorrt/:${CUDA_HOME}/lib64:${CUDA_HOME}/lib64/stubs ${PY_DIR}/bin/python -m auditwheel repair $(cat ${PROJECT_DIR}/py/ci/soname_excludes.params) --plat manylinux_2_17_x86_64 dist/torch_tensorrt-*-${PY_BUILD_CODE}-linux_x86_64.whl
61+
build_wheel ${PY_DIR}
62+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
63+
}
64+
65+
py311() {
66+
cd /workspace/project
67+
PY_BUILD_CODE=cp311-cp311
68+
PY_VERSION=3.11
69+
PY_NAME=python${PY_VERSION}
70+
PY_DIR=/opt/python/${PY_BUILD_CODE}
71+
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
72+
build_wheel ${PY_DIR}
73+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
6574
}
6675

67-
#build_py311() {
68-
# /opt/python/cp311-cp311/bin/python -m pip install -r requirements.txt
69-
# /opt/python/cp311-cp311/bin/python setup.py bdist_wheel --release --ci
70-
# #auditwheel repair --plat manylinux2014_x86_64
71-
#}
76+
py312() {
77+
cd /workspace/project
78+
PY_BUILD_CODE=cp312-cp312
79+
PY_VERSION=3.12
80+
PY_NAME=python${PY_VERSION}
81+
PY_DIR=/opt/python/${PY_BUILD_CODE}
82+
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
83+
build_wheel ${PY_DIR}
84+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
85+
}
7286

7387
libtorchtrt() {
74-
cd /workspace/project/py
88+
cd /workspace/project
7589
mkdir -p /workspace/project/py/wheelhouse
7690
PY_BUILD_CODE=cp310-cp310
7791
PY_VERSION=3.10
7892
PY_NAME=python${PY_VERSION}
7993
PY_DIR=/opt/python/${PY_BUILD_CODE}
8094
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
81-
${PY_DIR}/bin/python -m pip install --upgrade pip
82-
${PY_DIR}/bin/python -m pip install -r requirements.txt
83-
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
84-
bazel build //:libtorchtrt --platforms //toolchains:ci_rhel_x86_64_linux -c opt --noshow_progress
85-
CUDA_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cuda_version__;print(__cuda_version__)")
86-
TORCHTRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __version__;print(__version__)")
87-
TRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __tensorrt_version__;print(__tensorrt_version__)")
88-
CUDNN_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cudnn_version__;print(__cudnn_version__)")
95+
build_wheel ${PY_DIR}
96+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
97+
CUDA_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.cuda_version()")
98+
TORCHTRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.torch_tensorrt_version()")
99+
TRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.tensorrt_version()")
100+
CUDNN_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.cudnn_version()")
89101
TORCH_VERSION=$(${PY_DIR}/bin/python -c "from torch import __version__;print(__version__.split('+')[0])")
90102
cp ${PROJECT_DIR}/bazel-bin/libtorchtrt.tar.gz ${PROJECT_DIR}/py/wheelhouse/libtorchtrt-${TORCHTRT_VERSION}-cudnn${CUDNN_VERSION}-tensorrt${TRT_VERSION}-cuda${CUDA_VERSION}-libtorch${TORCH_VERSION}-x86_64-linux.tar.gz
91103
}
@@ -98,14 +110,12 @@ libtorchtrt_pre_cxx11_abi() {
98110
PY_NAME=python${PY_VERSION}
99111
PY_DIR=/opt/python/${PY_BUILD_CODE}
100112
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
101-
${PY_DIR}/bin/python -m pip install --upgrade pip
102-
${PY_DIR}/bin/python -m pip install -r requirements.txt
103-
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
104-
bazel build //:libtorchtrt --config pre_cxx11_abi --platforms //toolchains:ci_rhel_x86_64_linux -c opt --noshow_progress
105-
CUDA_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cuda_version__;print(__cuda_version__)")
106-
TORCHTRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __version__;print(__version__)")
107-
TRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __tensorrt_version__;print(__tensorrt_version__)")
108-
CUDNN_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cudnn_version__;print(__cudnn_version__)")
113+
build_wheel ${PY_DIR}
114+
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
115+
CUDA_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.cuda_version()")
116+
TORCHTRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.torch_tensorrt_version()")
117+
TRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.tensorrt_version()")
118+
CUDNN_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "import versions; versions.cudnn_version()")
109119
TORCH_VERSION=$(${PY_DIR}/bin/python -c "from torch import __version__;print(__version__.split('+')[0])")
110120
cp ${PROJECT_DIR}/bazel-bin/libtorchtrt.tar.gz ${PROJECT_DIR}/py/wheelhouse/libtorchtrt-${TORCHTRT_VERSION}-pre-cxx11-abi-cudnn${CUDNN_VERSION}-tensorrt${TRT_VERSION}-cuda${CUDA_VERSION}-libtorch${TORCH_VERSION}-x86_64-linux.tar.gz
111121
}

py/ci/soname_excludes.params

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@
3131
--exclude libcublasLt.so.11
3232
--exclude libnvinfer.so.8
3333
--exclude libcudnn.so.8
34+
--exclude libcublas.so.12
35+
--exclude libcublasLt.so.12
36+
--exclude libcublas.so.12.1.3.1
37+
--exclude libcublasLt.so.12.1.3.1
38+
--exclude libcudart.so.11.8.89
39+
--exclude libcudart.so.11

py/versions.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

pyproject.toml

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[build-system]
22
requires = [
33
"setuptools",
4+
"packaging",
45
"wheel",
56
"numpy",
67
"ninja",
@@ -9,17 +10,71 @@ requires = [
910
"cffi",
1011
"typing_extensions",
1112
"future",
12-
"tensorrt >=8.6,<8.7"
13+
"tensorrt>=8.6,<8.7",
14+
#"torch >=2.0.0,<2.1.0",
15+
"torch==2.1.0.dev20230619+cu121",
16+
"pybind11==2.6.2"
1317
]
18+
build-backend = "setuptools.build_meta"
1419

15-
# Use legacy backend to import local packages in setup.py
16-
#build-backend = "setuptools.build_meta:__legacy__"
20+
[project]
21+
name = "torch_tensorrt"
22+
authors = [
23+
{name="NVIDIA Corporation", email="[email protected]"}
24+
]
25+
description = "Torch-TensorRT is a package which allows users to automatically compile PyTorch and TorchScript modules to TensorRT while remaining in PyTorch"
26+
license = {file = "LICENSE"}
27+
classifiers = [
28+
"Development Status :: 5 - Production/Stable",
29+
"Environment :: GPU :: NVIDIA CUDA",
30+
"License :: OSI Approved :: BSD License",
31+
"Intended Audience :: Developers",
32+
"Intended Audience :: Science/Research",
33+
"Operating System :: POSIX :: Linux",
34+
"Programming Language :: C++",
35+
"Programming Language :: Python",
36+
"Programming Language :: Python :: Implementation :: CPython",
37+
"Topic :: Scientific/Engineering",
38+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
39+
"Topic :: Software Development",
40+
"Topic :: Software Development :: Libraries",
41+
]
42+
readme = {file = "py/README.md", content-type = "text/markdown"}
43+
requires-python = ">=3.8"
44+
keywords = ["pytorch", "torch", "tensorrt", "trt", "ai", "artificial intelligence", "ml", "machine learning", "dl", "deep learning", "compiler", "dynamo", "torchscript", "inference"]
45+
dependencies = [
46+
"torch>=2.0.0,<2.1.0",
47+
"tensorrt>=8.6,<8.7",
48+
"packaging>=23",
49+
"numpy>=1.24,<1.25",
50+
]
51+
dynamic = ["version"]
52+
53+
[project.optional-dependencies]
54+
torchvision = ["torchvision >=0.16.dev,<0.17.0"]
55+
56+
[project.urls]
57+
Homepage = "https://pytorch.org/tensorrt"
58+
Documentation = "https://pytorch.org/tensorrt"
59+
Repository = "https://github.com/pytorch/tensorrt.git"
60+
Changelog = "https://github.com/pytorch/tensorrt/releases"
1761

1862

1963
[tool.black]
2064
# Uncomment if pyproject.toml worked fine to ensure consistency with flake8
2165
# line-length = 120
22-
target-versions = ["py38", "py39", "py310"]
66+
target-versions = ["py38", "py39", "py310", "py311"]
2367
force-exclude = """
2468
elu_converter/setup.py
2569
"""
70+
71+
[tool.mypy]
72+
show_error_codes = true
73+
disable_error_code = "attr-defined"
74+
no_implicit_optional = true
75+
76+
[tool.setuptools]
77+
package-dir = {"" = "py"}
78+
79+
[tool.setuptools.packages.find]
80+
where = ["py"]

0 commit comments

Comments
 (0)