diff --git a/.github/workflows/build-wheels-linux.yml b/.github/workflows/build-wheels-linux.yml new file mode 100644 index 0000000000..4ae7512e0a --- /dev/null +++ b/.github/workflows/build-wheels-linux.yml @@ -0,0 +1,53 @@ +name: Build Linux Wheels + +on: + pull_request: + push: + branches: + - nightly + - main + - release/* + tags: + # NOTE: Binary build pipelines should only get triggered on release candidate builds + # Release candidate tags look like: v1.11.0-rc1 + - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ + workflow_dispatch: + +jobs: + generate-matrix: + uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main + with: + package-type: wheel + os: linux + test-infra-repository: pytorch/test-infra + test-infra-ref: main + with-rocm: false + build: + needs: generate-matrix + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + pre-script: packaging/pre_build_script.sh + env-var-script: packaging/env_vars.txt + post-script: "" + smoke-test-script: "" + package-name: torch_tensorrt + name: ${{ matrix.repository }} + uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main + with: + repository: ${{ matrix.repository }} + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + env-var-script: ${{ matrix.env-var-script }} + post-script: ${{ matrix.post-script }} + package-name: ${{ matrix.package-name }} + smoke-test-script: ${{ matrix.smoke-test-script }} + trigger-event: ${{ github.event_name }} + secrets: + AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }} + AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }} \ No newline at end of file diff --git a/.github/workflows/docgen.yml b/.github/workflows/docgen.yml index 47dd165d86..eabe615c44 100644 --- a/.github/workflows/docgen.yml +++ b/.github/workflows/docgen.yml @@ -10,32 +10,33 @@ on: jobs: build-docs: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest container: image: docker.io/pytorch/manylinux-builder:cuda12.1 steps: - uses: actions/checkout@v3 with: ref: ${{github.head_ref}} + - name: Select python + run: | + export PATH=/opt/python/cp311-cp311/bin/:$PATH - name: Install base deps run: | - ./packaging/pre_build_script.sh + python3 -m pip install pyyaml + VERSION_SUFFIX=cu121 ./packaging/pre_build_script.sh - name: Get HEAD SHA id: vars run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - name: Get Bazel version - id: bazel_info - run: echo "version=$(cat .bazelversion)" >> $GITHUB_OUTPUT - name: Build Python Package run: | - cp toolchains/ci_workspaces/WORKSPACE.x86_64.cu121.release.rhel WORKSPACE - python -m pip install pip<=23 - python -m pip install --pre -e . --extra-index-url https://download.pytorch.org/whl/nightly/cu121 + python3 -m pip install pip --upgrade + CUDA_HOME=/usr/local/cuda-12.1 CI_BUILD=1 python3 -m pip install --pre -e . --extra-index-url https://download.pytorch.org/whl/nightly/cu121 - name: Generate New Docs run: | cd docsrc - python -m pip install -r requirements.txt - python -c "import torch_tensorrt; print(torch_tensorrt.__version__)" + yum install -y doxygen pandoc + python3 -m pip install -r requirements.txt + python3 -c "import torch_tensorrt; print(torch_tensorrt.__version__)" make html cd .. - uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/.github/workflows/nightlies.yml b/.github/workflows/nightlies.yml new file mode 100644 index 0000000000..31e3b034f6 --- /dev/null +++ b/.github/workflows/nightlies.yml @@ -0,0 +1,27 @@ +name: Cut Nightly + +on: + schedule: + - cron: '30 9 * * *' + workflow_dispatch: + +jobs: + cut_nightly: + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@v3 + with: + ref: main + - name: Create nightly commit + shell: bash + run: | + git config --global user.email "torch-tensorrt.github.bot@nvidia.com" + git config --global user.name "Torch-TensorRT Github Bot" + git fetch origin nightly + HEAD_COMMIT_HASH=$(git rev-parse HEAD) + NIGHTLY_DATE=$(date +"%Y-%m-%d") + # shellcheck disable=SC1083 + NIGHTLY_RELEASE_COMMIT=$(git commit-tree -p FETCH_HEAD HEAD^{tree} -m "${NIGHTLY_DATE} nightly release (${HEAD_COMMIT_HASH})") + # shellcheck disable=SC1083 + git push -f origin "${NIGHTLY_RELEASE_COMMIT}:nightly" \ No newline at end of file diff --git a/versions.yml b/dev_dep_versions.yml similarity index 100% rename from versions.yml rename to dev_dep_versions.yml diff --git a/packaging/env_vars.txt b/packaging/env_vars.txt new file mode 100644 index 0000000000..46f906b1ff --- /dev/null +++ b/packaging/env_vars.txt @@ -0,0 +1,2 @@ +export CI_BUILD="1" +export RELEASE="1" \ No newline at end of file diff --git a/packaging/post_build_script.sh b/packaging/post_build_script.sh new file mode 100644 index 0000000000..e69de29bb2 diff --git a/py/ci/build_whl.sh b/py/ci/build_whl.sh index 0998e87384..12f72a9351 100755 --- a/py/ci/build_whl.sh +++ b/py/ci/build_whl.sh @@ -6,11 +6,23 @@ export CXX=g++ export CUDA_HOME=/usr/local/cuda-12.1 export PROJECT_DIR=/workspace/project -cp -r $CUDA_HOME /usr/local/cuda +rm -rf /usr/local/cuda + +if [[ $CUDA_HOME == "/usr/local/cuda-12.1" ]]; then + cp -r /usr/local/cuda-11.8 /usr/local/cuda + cp -r /usr/local/cuda-12.0/ /usr/local/cuda/ + rsync -a /usr/local/cuda-12.1/ /usr/local/cuda/ + export CUDA_HOME=/usr/local/cuda +else + ln -s $CUDA_HOME /usr/local/cuda +fi 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 + $1/bin/python -m pip install --upgrade pip setuptools + $1/bin/python -m pip install -r py/requirements.txt + #$1/bin/python -m pip wheel . -w dist + export BUILD_VERSION=$(cd ${PROJECT_DIR} && $1/bin/python3 -c "import versions; versions.torch_tensorrt_version_release()") + CI_BUILD=1 RELEASE=1 $1/bin/python setup.py bdist_wheel } patch_wheel() { @@ -86,7 +98,7 @@ libtorchtrt() { ${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_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()") + TORCHTRT_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.torch_tensorrt_version_release()") 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])") @@ -106,7 +118,7 @@ libtorchtrt_pre_cxx11_abi() { ${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_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()") + TORCHTRT_VERSION=$(cd ${PROJECT_DIR} && ${PY_DIR}/bin/python3 -c "import versions; versions.torch_tensorrt_version_release()") 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])") diff --git a/pyproject.toml b/pyproject.toml index ae130dc08a..d545fc844e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,8 +9,8 @@ requires = [ "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", + #"torch >=2.1.0.dev,<2.2.0", + "torch==2.1.0.dev20230731", "pybind11==2.6.2", "numpy", ] @@ -42,8 +42,8 @@ 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", + #"torch >=2.1.0.dev,<2.2.0", + "torch==2.1.0.dev20230731", "tensorrt>=8.6,<8.7", "packaging>=23", "numpy", diff --git a/setup.py b/setup.py index 8e5c5330b7..7304c6f368 100644 --- a/setup.py +++ b/setup.py @@ -19,35 +19,29 @@ import platform import warnings -dir_path = os.path.dirname(os.path.realpath(__file__)) + "/py" +import yaml +import re +import os +import subprocess -CXX11_ABI = False -JETPACK_VERSION = None -FX_ONLY = False -LEGACY = False -RELEASE = False -CI_RELEASE = False +from datetime import datetime +from pathlib import Path +from typing import List __version__: str = "0.0.0" __cuda_version__: str = "0.0" __cudnn_version__: str = "0.0" __tensorrt_version__: str = "0.0" - -def load_version_info(): - global __version__ - global __cuda_version__ - global __cudnn_version__ - global __tensorrt_version__ - with open("versions.yml", "r") as stream: - versions = yaml.safe_load(stream) - __version__ = versions["__version__"] - __cuda_version__ = versions["__cuda_version__"] - __cudnn_version__ = versions["__cudnn_version__"] - __tensorrt_version__ = versions["__tensorrt_version__"] +LEGACY_BASE_VERSION_SUFFIX_PATTERN = re.compile("a0$") -load_version_info() +def get_root_dir() -> Path: + return Path( + subprocess.check_output(["git", "rev-parse", "--show-toplevel"]) + .decode("ascii") + .strip() + ) def get_git_revision_short_hash() -> str: @@ -58,6 +52,45 @@ def get_git_revision_short_hash() -> str: ) +def get_base_version() -> str: + root = get_root_dir() + try: + dirty_version = open(root / "version.txt", "r").read().strip() + except FileNotFoundError: + print("# WARNING: Base version not found defaulting BUILD_VERSION to 0.1.0") + dirty_version = "0.1.0" + # Strips trailing a0 from version.txt, not too sure why it's there in the + # first place + return re.sub(LEGACY_BASE_VERSION_SUFFIX_PATTERN, "", dirty_version) + + +def load_dep_info(): + global __cuda_version__ + global __cudnn_version__ + global __tensorrt_version__ + with open("dev_dep_versions.yml", "r") as stream: + versions = yaml.safe_load(stream) + if (gpu_arch_version := os.environ.get("CU_VERSION")) is not None: + __cuda_version__ = ( + (gpu_arch_version[2:])[:-1] + "." + (gpu_arch_version[2:])[-1:] + ) + else: + __cuda_version__ = versions["__cuda_version__"] + __cudnn_version__ = versions["__cudnn_version__"] + __tensorrt_version__ = versions["__tensorrt_version__"] + + +load_dep_info() + +dir_path = str(get_root_dir()) + "/py" + +CXX11_ABI = False +JETPACK_VERSION = None +FX_ONLY = False +LEGACY = False +RELEASE = False +CI_BUILD = False + if "--fx-only" in sys.argv: FX_ONLY = True sys.argv.remove("--fx-only") @@ -66,16 +99,31 @@ def get_git_revision_short_hash() -> str: LEGACY = True sys.argv.remove("--legacy") -if "--release" not in sys.argv: - __version__ = __version__ + "+" + get_git_revision_short_hash() -else: +if "--release" in sys.argv: RELEASE = True sys.argv.remove("--release") +if (release_env_var := os.environ.get("RELEASE")) is not None: + if release_env_var == "1": + RELEASE = True + +if (gpu_arch_version := os.environ.get("CU_VERSION")) is None: + gpu_arch_version = f"cu{__cuda_version__.replace('.','')}" + + +if RELEASE: + __version__ = os.environ.get("BUILD_VERSION") +else: + __version__ = f"{get_base_version()}.dev0+{get_git_revision_short_hash()}" + if "--ci" in sys.argv: sys.argv.remove("--ci") if RELEASE: - CI_RELEASE = True + CI_BUILD = True + +if (ci_env_var := os.environ.get("CI_BUILD")) is not None: + if ci_env_var == "1": + CI_BUILD = True if "--use-cxx11-abi" in sys.argv: sys.argv.remove("--use-cxx11-abi") @@ -159,7 +207,7 @@ def build_libtorchtrt_pre_cxx11_abi(develop=True, use_dist_dir=True, cxx11_abi=F cmd.append("--platforms=//toolchains:jetpack_5.0") print("Jetpack version: 5.0") - if CI_RELEASE: + if CI_BUILD: cmd.append("--platforms=//toolchains:ci_rhel_x86_64_linux") print("CI based build") @@ -412,6 +460,7 @@ def run(self): dir_path + "/../bazel-TensorRT/external/tensorrt/include", dir_path + "/../bazel-tensorrt/external/tensorrt/include", dir_path + "/../", + "/usr/local/cuda", ], extra_compile_args=[ "-Wno-deprecated", diff --git a/toolchains/ci_workspaces/WORKSPACE.x86_64.release.rhel b/toolchains/ci_workspaces/WORKSPACE.x86_64.cu118.release.rhel similarity index 91% rename from toolchains/ci_workspaces/WORKSPACE.x86_64.release.rhel rename to toolchains/ci_workspaces/WORKSPACE.x86_64.cu118.release.rhel index 8d6ff234e8..79c7575d2b 100644 --- a/toolchains/ci_workspaces/WORKSPACE.x86_64.release.rhel +++ b/toolchains/ci_workspaces/WORKSPACE.x86_64.cu118.release.rhel @@ -43,7 +43,7 @@ local_repository( new_local_repository( name = "cuda", build_file = "@//third_party/cuda:BUILD", - path = "/usr/local/cuda-12.1", + path = "/usr/local/cuda-11.8", ) new_local_repository( @@ -58,17 +58,17 @@ new_local_repository( http_archive( name = "libtorch", build_file = "@//third_party/libtorch:BUILD", - sha256 = "1ae8366aaf7af7f68f142ba644fe26c837c6fa8347ec6bd9ce605ac60e7f7e5e", + sha256 = "174579a7ee2a506d063714160c5fc57da428f7935311ef511c8f19820eb14c86", strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.0.dev20230703%2Bcu121.zip"], + urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.0.dev20230731%2Bcu121.zip"], ) http_archive( name = "libtorch_pre_cxx11_abi", build_file = "@//third_party/libtorch:BUILD", - sha256 = "9add4832f4da9223866d85810820b816ab3319d5a227066101eeb6cbb76adb4b", + sha256 = "532217063c65354d5534211badadc9c370d889cb1c3fdb295c9b3d0f181bc0ba", strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-shared-with-deps-2.1.0.dev20230703%2Bcu121.zip"], + urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-shared-with-deps-2.1.0.dev20230731%2Bcu121.zip"], ) #################################################################################### diff --git a/toolchains/ci_workspaces/WORKSPACE.x86_64.release.ubuntu b/toolchains/ci_workspaces/WORKSPACE.x86_64.release.ubuntu index 60e29f2b60..745272d328 100644 --- a/toolchains/ci_workspaces/WORKSPACE.x86_64.release.ubuntu +++ b/toolchains/ci_workspaces/WORKSPACE.x86_64.release.ubuntu @@ -58,17 +58,17 @@ new_local_repository( http_archive( name = "libtorch", build_file = "@//third_party/libtorch:BUILD", - sha256 = "1ae8366aaf7af7f68f142ba644fe26c837c6fa8347ec6bd9ce605ac60e7f7e5e", + sha256 = "174579a7ee2a506d063714160c5fc57da428f7935311ef511c8f19820eb14c86", strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.0.dev20230703%2Bcu121.zip"], + urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.0.dev20230731%2Bcu121.zip"], ) http_archive( name = "libtorch_pre_cxx11_abi", build_file = "@//third_party/libtorch:BUILD", - sha256 = "9add4832f4da9223866d85810820b816ab3319d5a227066101eeb6cbb76adb4b", + sha256 = "532217063c65354d5534211badadc9c370d889cb1c3fdb295c9b3d0f181bc0ba", strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-shared-with-deps-2.1.0.dev20230703%2Bcu121.zip"], + urls = ["https://download.pytorch.org/libtorch/nightly/cu121/libtorch-shared-with-deps-2.1.0.dev20230731%2Bcu121.zip"], ) #################################################################################### diff --git a/version.txt b/version.txt new file mode 100644 index 0000000000..32408126ec --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +2.0.0a0 \ No newline at end of file diff --git a/versions.py b/versions.py index f038aabb24..772737aab7 100644 --- a/versions.py +++ b/versions.py @@ -1,29 +1,141 @@ import yaml +import re +import os +import subprocess -__version__: str = "0.0.0" -__cuda_version__: str = "0.0" -__cudnn_version__: str = "0.0" -__tensorrt_version__: str = "0.0" +from datetime import datetime +from pathlib import Path +from typing import List +__version__ = "0.0.0" +__cuda_version__ = "0.0" +__cudnn_version__ = "0.0" +__tensorrt_version__ = "0.0" -def load_version_info(): - global __version__ + +LEADING_V_PATTERN = re.compile("^v") +TRAILING_RC_PATTERN = re.compile("-rc[0-9]*$") +LEGACY_BASE_VERSION_SUFFIX_PATTERN = re.compile("a0$") + + +class NoGitTagException(Exception): + pass + + +def get_root_dir() -> Path: + return Path( + subprocess.check_output(["git", "rev-parse", "--show-toplevel"]) + .decode("ascii") + .strip() + ) + + +def get_tag() -> str: + root = get_root_dir() + # We're on a tag + am_on_tag = ( + subprocess.run( + ["git", "describe", "--tags", "--exact"], + cwd=root, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ).returncode + == 0 + ) + tag = "" + if am_on_tag: + dirty_tag = ( + subprocess.check_output(["git", "describe"], cwd=root) + .decode("ascii") + .strip() + ) + # Strip leading v that we typically do when we tag branches + # ie: v1.7.1 -> 1.7.1 + tag = re.sub(LEADING_V_PATTERN, "", dirty_tag) + # Strip trailing rc pattern + # ie: 1.7.1-rc1 -> 1.7.1 + tag = re.sub(TRAILING_RC_PATTERN, "", tag) + return tag + + +def get_base_version() -> str: + root = get_root_dir() + try: + dirty_version = open(root / "version.txt", "r").read().strip() + except FileNotFoundError: + print("# WARNING: Base version not found defaulting BUILD_VERSION to 0.1.0") + dirty_version = "0.1.0" + # Strips trailing a0 from version.txt, not too sure why it's there in the + # first place + return re.sub(LEGACY_BASE_VERSION_SUFFIX_PATTERN, "", dirty_version) + + +class PytorchVersion: + def __init__( + self, + gpu_arch_version: str, + no_build_suffix: bool, + base_build_version: str, + ) -> None: + self.gpu_arch_version = gpu_arch_version + self.no_build_suffix = no_build_suffix + if base_build_version == "": + base_build_version = get_base_version() + self.base_build_version = base_build_version + + def get_post_build_suffix(self) -> str: + if self.no_build_suffix or self.gpu_arch_version is None: + return "" + return f"+{self.gpu_arch_version}" + + def get_release_version(self) -> str: + if self.base_build_version: + return f"{self.base_build_version}{self.get_post_build_suffix()}" + if not get_tag(): + raise NoGitTagException( + "Not on a git tag, are you sure you want a release version?" + ) + return f"{get_tag()}{self.get_post_build_suffix()}" + + def get_nightly_version(self) -> str: + date_str = datetime.today().strftime("%Y%m%d") + build_suffix = self.get_post_build_suffix() + return f"{self.base_build_version}.dev{date_str}{build_suffix}" + + +def load_dep_info(): global __cuda_version__ global __cudnn_version__ global __tensorrt_version__ - with open("versions.yml", "r") as stream: + with open("dev_dep_versions.yml", "r") as stream: versions = yaml.safe_load(stream) - __version__ = versions["__version__"] - __cuda_version__ = versions["__cuda_version__"] + gpu_arch_version = os.environ.get("CU_VERSION") + if gpu_arch_version is not None: + __cuda_version__ = ( + (gpu_arch_version[2:])[:-1] + "." + (gpu_arch_version[2:])[-1:] + ) + else: + __cuda_version__ = versions["__cuda_version__"] __cudnn_version__ = versions["__cudnn_version__"] __tensorrt_version__ = versions["__tensorrt_version__"] -load_version_info() +load_dep_info() + +gpu_arch_version = os.environ.get("CU_VERSION") +version = PytorchVersion( + gpu_arch_version=gpu_arch_version, + no_build_suffix=False, + base_build_version=get_base_version(), +) + + +def torch_tensorrt_version_nightly(): + print(version.get_nightly_version()) -def torch_tensorrt_version(): - print(__version__) +def torch_tensorrt_version_release(): + print(version.get_release_version()) def cuda_version():