Skip to content

Commit

Permalink
refactor(//py)!: Build system is now PEP517 compatible
Browse files Browse the repository at this point in the history
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 <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>

tools: adding a pyproject.toml linter

Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>

chore: update CI for new build path

Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>

Adding no deps flag

refactor: Formally define package contents in setup.py

Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
  • Loading branch information
narendasan committed Jul 17, 2023
1 parent bac0c59 commit 8dfd895
Show file tree
Hide file tree
Showing 19 changed files with 519 additions and 354 deletions.
189 changes: 125 additions & 64 deletions .circleci/config.yml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ bazel-tensorrt
*.cache
*cifar-10-batches-py*
bazel-project
build/
build/
wheelhouse/
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ repos:
args:
- --warnings=all
- id: buildifier-lint
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.13
hooks:
- id: validate-pyproject
- repo: local
hooks:
- id: dont-commit-upstream
Expand Down
11 changes: 0 additions & 11 deletions py/Dockerfile

This file was deleted.

44 changes: 0 additions & 44 deletions py/build_whl.sh

This file was deleted.

2 changes: 1 addition & 1 deletion py/ci/Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM pytorch/manylinux-builder:cuda11.7
FROM pytorch/manylinux-builder:cuda12.1
ARG trt_version

RUN echo -e "Installing with TensorRT ${trt_version}"
Expand Down
1 change: 1 addition & 0 deletions py/ci/build_manifest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
py38
py39
py310
py311
libtorchtrt_pre_cxx11_abi
95 changes: 49 additions & 46 deletions py/ci/build_whl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,87 @@ export PROJECT_DIR=/workspace/project

cp -r $CUDA_HOME /usr/local/cuda

py37() {
cd /workspace/project/py
PY_BUILD_CODE=cp37-cp37m
PY_VERSION=3.7
PY_NAME=python${PY_VERSION}
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
${PY_DIR}/bin/python -m pip install --upgrade pip
${PY_DIR}/bin/python -m pip install -r requirements.txt
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
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
build_wheel() {
$1/bin/python -m pip install --upgrade pip
$1/bin/python -m pip wheel . --config-setting="--build-option=--release" --config-setting="--build-option=--ci" -w dist
}

patch_wheel() {
$2/bin/python -m pip install auditwheel
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
}

py38() {
cd /workspace/project/py
cd /workspace/project
PY_BUILD_CODE=cp38-cp38
PY_VERSION=3.8
PY_NAME=python${PY_VERSION}
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
${PY_DIR}/bin/python -m pip install --upgrade pip
${PY_DIR}/bin/python -m pip install -r requirements.txt
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
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
build_wheel ${PY_DIR}
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
}

py39() {
cd /workspace/project/py
cd /workspace/project
PY_BUILD_CODE=cp39-cp39
PY_VERSION=3.9
PY_NAME=python${PY_VERSION}
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
${PY_DIR}/bin/python -m pip install --upgrade pip
${PY_DIR}/bin/python -m pip install -r requirements.txt
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
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
build_wheel ${PY_DIR}
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
}

py310() {
cd /workspace/project/py
cd /workspace/project
PY_BUILD_CODE=cp310-cp310
PY_VERSION=3.10
PY_NAME=python${PY_VERSION}
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
${PY_DIR}/bin/python -m pip install --upgrade pip
${PY_DIR}/bin/python -m pip install -r requirements.txt
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
${PY_DIR}/bin/python setup.py bdist_wheel --release --ci
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
build_wheel ${PY_DIR}
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
}

#build_py311() {
# /opt/python/cp311-cp311/bin/python -m pip install -r requirements.txt
# /opt/python/cp311-cp311/bin/python setup.py bdist_wheel --release --ci
# #auditwheel repair --plat manylinux2014_x86_64
#}
py311() {
cd /workspace/project
PY_BUILD_CODE=cp311-cp311
PY_VERSION=3.11
PY_NAME=python${PY_VERSION}
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
build_wheel ${PY_DIR}
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
}

py312() {
cd /workspace/project
PY_BUILD_CODE=cp312-cp312
PY_VERSION=3.12
PY_NAME=python${PY_VERSION}
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
build_wheel ${PY_DIR}
patch_wheel ${PY_PKG_DIR} ${PY_DIR} ${PY_BUILD_CODE}
}

libtorchtrt() {
cd /workspace/project/py
cd /workspace/project
mkdir -p /workspace/project/py/wheelhouse
PY_BUILD_CODE=cp310-cp310
PY_VERSION=3.10
PY_NAME=python${PY_VERSION}
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
${PY_DIR}/bin/python -m pip install --upgrade pip
${PY_DIR}/bin/python -m pip install -r requirements.txt
${PY_DIR}/bin/python -m pip install -r py/requirements.txt
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
bazel build //:libtorchtrt --platforms //toolchains:ci_rhel_x86_64_linux -c opt --noshow_progress
CUDA_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cuda_version__;print(__cuda_version__)")
TORCHTRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __version__;print(__version__)")
TRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __tensorrt_version__;print(__tensorrt_version__)")
CUDNN_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cudnn_version__;print(__cudnn_version__)")
CUDA_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.cuda_version()")
TORCHTRT_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.torch_tensorrt_version()")
TRT_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.tensorrt_version()")
CUDNN_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.cudnn_version()")
TORCH_VERSION=$(${PY_DIR}/bin/python -c "from torch import __version__;print(__version__.split('+')[0])")
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
}
Expand All @@ -99,13 +102,13 @@ libtorchtrt_pre_cxx11_abi() {
PY_DIR=/opt/python/${PY_BUILD_CODE}
PY_PKG_DIR=${PY_DIR}/lib/${PY_NAME}/site-packages/
${PY_DIR}/bin/python -m pip install --upgrade pip
${PY_DIR}/bin/python -m pip install -r requirements.txt
${PY_DIR}/bin/python -m pip install -r ${PROJECT_DIR}/py/requirements.txt
${PY_DIR}/bin/python -m pip install setuptools wheel auditwheel
bazel build //:libtorchtrt --config pre_cxx11_abi --platforms //toolchains:ci_rhel_x86_64_linux -c opt --noshow_progress
CUDA_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cuda_version__;print(__cuda_version__)")
TORCHTRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __version__;print(__version__)")
TRT_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __tensorrt_version__;print(__tensorrt_version__)")
CUDNN_VERSION=$(cd ${PROJECT_DIR}/py && ${PY_DIR}/bin/python3 -c "from versions import __cudnn_version__;print(__cudnn_version__)")
CUDA_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.cuda_version()")
TORCHTRT_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.torch_tensorrt_version()")
TRT_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.tensorrt_version()")
CUDNN_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.cudnn_version()")
TORCH_VERSION=$(${PY_DIR}/bin/python -c "from torch import __version__;print(__version__.split('+')[0])")
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
}
6 changes: 6 additions & 0 deletions py/ci/soname_excludes.params
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
--exclude libcublasLt.so.11
--exclude libnvinfer.so.8
--exclude libcudnn.so.8
--exclude libcublas.so.12
--exclude libcublasLt.so.12
--exclude libcublas.so.12.1.3.1
--exclude libcublasLt.so.12.1.3.1
--exclude libcudart.so.11.8.89
--exclude libcudart.so.11
1 change: 1 addition & 0 deletions py/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ torch==2.1.0.dev20230703+cu121
torchvision==0.16.0.dev20230703+cu121
--extra-index-url https://pypi.ngc.nvidia.com
tensorrt==8.6.1
pyyaml
4 changes: 0 additions & 4 deletions py/versions.py

This file was deleted.

79 changes: 66 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,78 @@
[build-system]
requires = [
"setuptools",
"wheel",
"numpy",
"ninja",
"pyyaml",
"setuptools",
"cffi",
"typing_extensions",
"future",
"tensorrt >=8.6,<8.7"
"setuptools>=68.0.0",
"packaging>=23.1",
"wheel>=0.40.0",
"numpy>=1.25.0",
"ninja>=1.11.0",
"pyyaml>=6.0",
"cffi>=1.15.1",
"typing_extensions>=4.7.0",
"future>=0.18.3",
"tensorrt>=8.6,<8.7",
#"torch >=2.0.0,<2.1.0",
"torch==2.1.0.dev20230703+cu121",
"pybind11==2.6.2"
]
build-backend = "setuptools.build_meta"

# Use legacy backend to import local packages in setup.py
#build-backend = "setuptools.build_meta:__legacy__"
[project]
name = "torch_tensorrt"
authors = [
{name="NVIDIA Corporation", email="narens@nvidia.com"}
]
description = "Torch-TensorRT is a package which allows users to automatically compile PyTorch and TorchScript modules to TensorRT while remaining in PyTorch"
license = {file = "LICENSE"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: GPU :: NVIDIA CUDA",
"License :: OSI Approved :: BSD License",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: POSIX :: Linux",
"Programming Language :: C++",
"Programming Language :: Python",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
]
readme = {file = "py/README.md", content-type = "text/markdown"}
requires-python = ">=3.8"
keywords = ["pytorch", "torch", "tensorrt", "trt", "ai", "artificial intelligence", "ml", "machine learning", "dl", "deep learning", "compiler", "dynamo", "torchscript", "inference"]
dependencies = [
#"torch>=2.0.0,<2.1.0",
"torch==2.1.0.dev20230703+cu121",
"tensorrt>=8.6,<8.7",
"packaging>=23",
"numpy>=1.25.0",
]
dynamic = ["version"]

[project.optional-dependencies]
torchvision = ["torchvision >=0.16.dev,<0.17.0"]

[project.urls]
Homepage = "https://pytorch.org/tensorrt"
Documentation = "https://pytorch.org/tensorrt"
Repository = "https://github.com/pytorch/tensorrt.git"
Changelog = "https://github.com/pytorch/tensorrt/releases"


[tool.black]
# Uncomment if pyproject.toml worked fine to ensure consistency with flake8
# line-length = 120
target-versions = ["py38", "py39", "py310"]
target-versions = ["py38", "py39", "py310", "py311", "py312"]
force-exclude = """
elu_converter/setup.py
"""

[tool.mypy]
show_error_codes = true
disable_error_code = "attr-defined"
no_implicit_optional = true

[tool.setuptools]
package-dir = {"" = "py"}
include-package-data = false
Loading

0 comments on commit 8dfd895

Please sign in to comment.