Skip to content

Commit

Permalink
infra: Testing out GHA based infra
Browse files Browse the repository at this point in the history
Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
  • Loading branch information
narendasan committed Aug 1, 2023
1 parent f7b03f4 commit a263690
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 65 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build-wheels-linux.yml
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 11 additions & 10 deletions .github/workflows/docgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/nightlies.yml
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
2 changes: 2 additions & 0 deletions packaging/env_vars.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export CI_BUILD="1"
export RELEASE="1"
Empty file added packaging/post_build_script.sh
Empty file.
22 changes: 17 additions & 5 deletions py/ci/build_whl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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])")
Expand All @@ -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])")
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -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",
Expand Down
99 changes: 74 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"],
)

####################################################################################
Expand Down
Loading

0 comments on commit a263690

Please sign in to comment.