diff --git a/.github/scripts/generate-tensorrt-test-matrix.py b/.github/scripts/generate-tensorrt-test-matrix.py new file mode 100644 index 0000000000..e5a9b9fae4 --- /dev/null +++ b/.github/scripts/generate-tensorrt-test-matrix.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 + +import argparse +import copy +import json +import sys + +# please update the cuda version you want to test with the future tensorRT version here +# channel: nightly if the future tensorRT version test workflow is triggered from the main branch or your personal branch +# channel: test if the future tensorRT version test workflow is triggered from the release branch(release/2.5 etc....) +CUDA_VERSIONS_DICT = { + "nightly": ["cu124"], + "test": ["cu121", "cu124"], + "release": ["cu121", "cu124"], +} + +# please update the python version you want to test with the future tensorRT version here +# channel: nightly if the future tensorRT version test workflow is triggered from the main branch or your personal branch +# channel: test if the future tensorRT version test workflow is triggered from the release branch(release/2.5 etc....) +PYTHON_VERSIONS_DICT = { + "nightly": ["3.9"], + "test": ["3.9", "3.10", "3.11", "3.12"], + "release": ["3.9", "3.10", "3.11", "3.12"], +} + +# please update the future tensorRT version you want to test here +TENSORRT_VERSIONS_DICT = { + "windows": { + "10.4.0": { + "urls": "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.4.0/zip/TensorRT-10.4.0.26.Windows.win10.cuda-12.6.zip", + "strip_prefix": "TensorRT-10.4.0.26", + "sha256": "3a7de83778b9e9f812fd8901e07e0d7d6fc54ce633fcff2e340f994df2c6356c", + }, + "10.5.0": { + "urls": "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.5.0/zip/TensorRT-10.5.0.18.Windows.win10.cuda-12.6.zip", + "strip_prefix": "TensorRT-10.5.0.18", + "sha256": "e6436f4164db4e44d727354dccf7d93755efb70d6fbfd6fa95bdfeb2e7331b24", + }, + "10.6.0": { + "urls": "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.6.0/zip/TensorRT-10.6.0.26.Windows.win10.cuda-12.6.zip", + "strip_prefix": "TensorRT-10.6.0.26", + "sha256": "6c6d92c108a1b3368423e8f69f08d31269830f1e4c9da43b37ba34a176797254", + }, + }, + "linux": { + "10.4.0": { + "urls": "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.4.0/tars/TensorRT-10.4.0.26.Linux.x86_64-gnu.cuda-12.6.tar.gz", + "strip_prefix": "TensorRT-10.4.0.26", + "sha256": "cb0273ecb3ba4db8993a408eedd354712301a6c7f20704c52cdf9f78aa97bbdb", + }, + "10.5.0": { + "urls": "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.5.0/tars/TensorRT-10.5.0.18.Linux.x86_64-gnu.cuda-12.6.tar.gz", + "strip_prefix": "TensorRT-10.5.0.18", + "sha256": "f404d379d639552a3e026cd5267213bd6df18a4eb899d6e47815bbdb34854958", + }, + "10.6.0": { + "urls": "https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.6.0/tars/TensorRT-10.6.0.26.Linux.x86_64-gnu.cuda-12.6.tar.gz", + "strip_prefix": "TensorRT-10.6.0.26", + "sha256": "33d3c2f3f4c84dc7991a4337a6fde9ed33f5c8e5c4f03ac2eb6b994a382b03a0", + }, + }, +} + + +def main(args: list[str]) -> None: + parser = argparse.ArgumentParser() + parser.add_argument( + "--matrix", + help="matrix", + type=str, + default="", + ) + + options = parser.parse_args(args) + if options.matrix == "": + raise Exception("--matrix is empty, please provide the matrix json str") + + matrix_dict = json.loads(options.matrix) + includes = matrix_dict["include"] + assert len(includes) > 0 + if "channel" not in includes[0]: + raise Exception(f"channel field is missing from the matrix: {options.matrix}") + channel = includes[0]["channel"] + if channel not in ("nightly", "test", "release"): + raise Exception( + f"channel field: {channel} is not supported, currently supported value: nightly, test, release" + ) + + if "validation_runner" not in includes[0]: + raise Exception( + f"validation_runner field is missing from the matrix: {options.matrix}" + ) + if "windows" in includes[0]["validation_runner"]: + arch = "windows" + elif "linux" in includes[0]["validation_runner"]: + arch = "linux" + else: + raise Exception( + f"{includes[0].validation_runner} is not the supported arch, currently only support windows and linux" + ) + + cuda_versions = CUDA_VERSIONS_DICT[channel] + python_versions = PYTHON_VERSIONS_DICT[channel] + tensorrt_versions = TENSORRT_VERSIONS_DICT[arch] + + filtered_includes = [] + for item in includes: + if ( + item["desired_cuda"] in cuda_versions + and item["python_version"] in python_versions + ): + for tensorrt_version, tensorrt_json in tensorrt_versions.items(): + new_item = copy.deepcopy(item) + tensorrt_json["version"] = tensorrt_version + new_item["tensorrt"] = tensorrt_json + filtered_includes.append(new_item) + filtered_matrix_dict = {} + filtered_matrix_dict["include"] = filtered_includes + print(json.dumps(filtered_matrix_dict)) + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/.github/workflows/build-tensorrt-linux.yml b/.github/workflows/build-tensorrt-linux.yml new file mode 100644 index 0000000000..7581c38ae8 --- /dev/null +++ b/.github/workflows/build-tensorrt-linux.yml @@ -0,0 +1,222 @@ +name: Build Torch-TensorRT wheel on Linux with Future TensorRT Versions + +on: + workflow_call: + inputs: + repository: + description: 'Repository to checkout, defaults to ""' + default: "" + type: string + ref: + description: 'Reference to checkout, defaults to "nightly"' + default: "nightly" + type: string + test-infra-repository: + description: "Test infra repository to use" + default: "pytorch/test-infra" + type: string + test-infra-ref: + description: "Test infra reference to use" + default: "" + type: string + build-matrix: + description: "Build matrix to utilize" + default: "" + type: string + pre-script: + description: "Pre script to run prior to build" + default: "" + type: string + post-script: + description: "Post script to run prior to build" + default: "" + type: string + smoke-test-script: + description: "Script for Smoke Test for a specific domain" + default: "" + type: string + env-var-script: + description: "Script that sets Domain-Specific Environment Variables" + default: "" + type: string + package-name: + description: "Name of the actual python package that is imported" + default: "" + type: string + trigger-event: + description: "Trigger Event in caller that determines whether or not to upload" + default: "" + type: string + cache-path: + description: "The path(s) on the runner to cache or restore. The path is relative to repository." + default: "" + type: string + cache-key: + description: "The key created when saving a cache and the key used to search for a cache." + default: "" + type: string + architecture: + description: Architecture to build for x86_64 for default Linux, or aarch64 for Linux aarch64 builds + required: false + type: string + default: x86_64 + submodules: + description: Works as stated in actions/checkout, but the default value is recursive + required: false + type: string + default: recursive + setup-miniconda: + description: Set to true if setup-miniconda is needed + required: false + type: boolean + default: true + +permissions: + id-token: write + contents: read + +jobs: + build: + strategy: + fail-fast: false + matrix: ${{ fromJSON(inputs.build-matrix) }} + env: + PYTHON_VERSION: ${{ matrix.python_version }} + PACKAGE_TYPE: wheel + REPOSITORY: ${{ inputs.repository }} + REF: ${{ inputs.ref }} + CU_VERSION: ${{ matrix.desired_cuda }} + UPLOAD_TO_BASE_BUCKET: ${{ matrix.upload_to_base_bucket }} + ARCH: ${{ inputs.architecture }} + TENSORRT_STRIP_PREFIX: ${{ matrix.tensorrt.strip_prefix }} + TENSORRT_VERSION: ${{ matrix.tensorrt.version }} + TENSORRT_URLS: ${{ matrix.tensorrt.urls }} + TENSORRT_SHA256: ${{ matrix.tensorrt.sha256 }} + UPLOAD_ARTIFACT_NAME: pytorch_tensorrt_${{ matrix.tensorrt.version }}_${{ matrix.python_version }}_${{ matrix.desired_cuda }}_${{ inputs.architecture }} + name: build_tensorrt${{ matrix.tensorrt.version }}_py${{matrix.python_version}}_${{matrix.desired_cuda}} + runs-on: ${{ matrix.validation_runner }} + container: + image: ${{ matrix.container_image }} + options: ${{ matrix.gpu_arch_type == 'cuda' && '--gpus all' || ' ' }} + # If a build is taking longer than 120 minutes on these runners we need + # to have a conversation + timeout-minutes: 120 + + steps: + - name: Clean workspace + shell: bash -l {0} + run: | + set -x + echo "::group::Cleanup debug output" + rm -rf "${GITHUB_WORKSPACE}" + mkdir -p "${GITHUB_WORKSPACE}" + if [[ "${{ inputs.architecture }}" = "aarch64" ]]; then + rm -rf "${RUNNER_TEMP}/*" + fi + echo "::endgroup::" + - uses: actions/checkout@v3 + with: + # Support the use case where we need to checkout someone's fork + repository: ${{ inputs.test-infra-repository }} + ref: ${{ inputs.test-infra-ref }} + path: test-infra + - uses: actions/checkout@v3 + if: ${{ env.ARCH == 'aarch64' }} + with: + # Support the use case where we need to checkout someone's fork + repository: "pytorch/builder" + ref: "main" + path: builder + - name: Set linux aarch64 CI + if: ${{ inputs.architecture == 'aarch64' }} + shell: bash -l {0} + env: + DESIRED_PYTHON: ${{ matrix.python_version }} + run: | + set +e + # TODO: This is temporary aarch64 setup script, this should be integrated into aarch64 docker. + ${GITHUB_WORKSPACE}/builder/aarch64_linux/aarch64_ci_setup.sh + echo "/opt/conda/bin" >> $GITHUB_PATH + set -e + - uses: ./test-infra/.github/actions/set-channel + - name: Set PYTORCH_VERSION + if: ${{ env.CHANNEL == 'test' }} + run: | + # When building RC, set the version to be the current candidate version, + # otherwise, leave it alone so nightly will pick up the latest + echo "PYTORCH_VERSION=${{ matrix.stable_version }}" >> "${GITHUB_ENV}" + - uses: ./test-infra/.github/actions/setup-binary-builds + env: + PLATFORM: ${{ inputs.architecture == 'aarch64' && 'linux-aarch64' || ''}} + with: + repository: ${{ inputs.repository }} + ref: ${{ inputs.ref }} + submodules: ${{ inputs.submodules }} + setup-miniconda: ${{ inputs.setup-miniconda }} + python-version: ${{ env.PYTHON_VERSION }} + cuda-version: ${{ env.CU_VERSION }} + arch: ${{ env.ARCH }} + - name: Combine Env Var and Build Env Files + if: ${{ inputs.env-var-script != '' }} + working-directory: ${{ inputs.repository }} + shell: bash -l {0} + run: | + cat "${{ inputs.env-var-script }}" >> "${BUILD_ENV_FILE}" + - name: Install torch dependency + shell: bash -l {0} + run: | + set -x + # shellcheck disable=SC1090 + source "${BUILD_ENV_FILE}" + # shellcheck disable=SC2086 + ${CONDA_RUN} ${PIP_INSTALL_TORCH} + - name: Run Pre-Script with Caching + if: ${{ inputs.pre-script != '' }} + uses: ./test-infra/.github/actions/run-script-with-cache + with: + cache-path: ${{ inputs.cache-path }} + cache-key: ${{ inputs.cache-key }} + repository: ${{ inputs.repository }} + script: ${{ inputs.pre-script }} + - name: Build clean + working-directory: ${{ inputs.repository }} + shell: bash -l {0} + run: | + set -x + source "${BUILD_ENV_FILE}" + ${CONDA_RUN} python setup.py clean + - name: Build the wheel (bdist_wheel) + working-directory: ${{ inputs.repository }} + shell: bash -l {0} + run: | + set -x + source "${BUILD_ENV_FILE}" + ${CONDA_RUN} python setup.py bdist_wheel + + - name: Run Post-Script + if: ${{ inputs.post-script != '' }} + uses: ./test-infra/.github/actions/run-script-with-cache + with: + repository: ${{ inputs.repository }} + script: ${{ inputs.post-script }} + - name: Smoke Test + shell: bash -l {0} + env: + PACKAGE_NAME: ${{ inputs.package-name }} + SMOKE_TEST_SCRIPT: ${{ inputs.smoke-test-script }} + run: | + set -x + source "${BUILD_ENV_FILE}" + # TODO: add smoke test for the auditwheel tarball built + + # NB: Only upload to GitHub after passing smoke tests + - name: Upload wheel to GitHub + continue-on-error: true + uses: actions/upload-artifact@v3 + with: + name: ${{ env.UPLOAD_ARTIFACT_NAME }} + path: ${{ inputs.repository }}/dist + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ inputs.repository }}-${{ github.event_name == 'workflow_dispatch' }}-${{ inputs.job-name }} + cancel-in-progress: true \ No newline at end of file diff --git a/.github/workflows/build-test-tensorrt-linux.yml b/.github/workflows/build-test-tensorrt-linux.yml new file mode 100644 index 0000000000..3f4abb9add --- /dev/null +++ b/.github/workflows/build-test-tensorrt-linux.yml @@ -0,0 +1,317 @@ +name: Build and Test Torch-TensorRT on Linux with Future TensorRT Versions + +on: + workflow_dispatch: + +permissions: + id-token: write + contents: read + packages: write + +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 + with-cpu: false + + generate-tensorrt-matrix: + needs: [generate-matrix] + outputs: + matrix: ${{ steps.generate.outputs.matrix }} + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - uses: actions/checkout@v3 + with: + repository: pytorch/tensorrt + - name: Generate tensorrt matrix + id: generate + run: | + set -eou pipefail + MATRIX_BLOB=${{ toJSON(needs.generate-matrix.outputs.matrix) }} + MATRIX_BLOB="$(python3 .github/scripts/generate-tensorrt-test-matrix.py --matrix "${MATRIX_BLOB}")" + echo "${MATRIX_BLOB}" + echo "matrix=${MATRIX_BLOB}" >> "${GITHUB_OUTPUT}" + + build: + needs: [generate-tensorrt-matrix] + name: Build torch-tensorrt whl package + 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: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + package-name: torch_tensorrt + uses: ./.github/workflows/build-tensorrt-linux.yml + with: + repository: ${{ matrix.repository }} + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-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 }} + + tests-py-torchscript-fe: + name: Test torchscript frontend [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-torchscript-fe + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH + pushd . + cd tests/modules + python hub.py + popd + pushd . + cd tests/py/ts + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/ts_api_test_results.xml api/ + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/ts_models_test_results.xml models/ + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/ts_integrations_test_results.xml integrations/ + popd + + tests-py-dynamo-converters: + name: Test dynamo converters [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-dynamo-converters + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + pushd . + cd tests/py/dynamo + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_converters_test_results.xml -n 8 conversion/ + popd + + tests-py-dynamo-fe: + name: Test dynamo frontend [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-dynamo-fe + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + pushd . + cd tests/py/dynamo + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dyn_models_export.xml --ir dynamo models/ + popd + + tests-py-dynamo-serde: + name: Test dynamo export serde [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-dynamo-serde + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + pushd . + cd tests/py/dynamo + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/export_serde_test_results.xml --ir dynamo models/test_export_serde.py + popd + + tests-py-torch-compile-be: + name: Test torch compile backend [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-torch-compile-be + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + pushd . + cd tests/py/dynamo + python -m pytest -ra -n 10 --junitxml=${RUNNER_TEST_RESULTS_DIR}/torch_compile_be_test_results.xml backend/ + python -m pytest -ra -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/torch_complete_be_e2e_test_results.xml --ir torch_compile models/test_models.py + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/torch_compile_dyn_models_export.xml --ir torch_compile models/test_dyn_models.py + popd + + tests-py-dynamo-core: + name: Test dynamo core [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-dynamo-core + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + pushd . + cd tests/py/dynamo + python -m pytest -ra -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_runtime_test_results.xml --ignore runtime/test_002_cudagraphs_py.py --ignore runtime/test_002_cudagraphs_cpp.py runtime/ + python -m pytest -ra -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_partitioning_test_results.xml partitioning/ + python -m pytest -ra -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_lowering_test_results.xml lowering/ + popd + + tests-py-dynamo-cudagraphs: + name: Test dynamo cudagraphs [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-dynamo-cudagraphs + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + pushd . + cd tests/py/dynamo + nvidia-smi + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_runtime_cudagraphs_cpp_test_results.xml runtime/test_002_cudagraphs_cpp.py || true + python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_runtime_cudagraphs_py_test_results.xml runtime/test_002_cudagraphs_py.py || true + popd + + tests-py-core: + name: Test core [Python] + needs: [generate-tensorrt-matrix, build] + strategy: + fail-fast: false + matrix: + include: + - repository: pytorch/tensorrt + package-name: torch_tensorrt + pre-script: packaging/pre_build_script.sh + post-script: packaging/post_build_script.sh + smoke-test-script: packaging/smoke_test_script.sh + uses: ./.github/workflows/linux-test.yml + with: + job-name: tests-py-core + repository: "pytorch/tensorrt" + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-tensorrt-matrix.outputs.matrix }} + pre-script: ${{ matrix.pre-script }} + script: | + export USE_HOST_DEPS=1 + export CI_BUILD=1 + pushd . + cd tests/py/core + python -m pytest -ra -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_core_test_results.xml . + popd + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ inputs.repository }}-${{ github.event_name == 'workflow_dispatch' }}-${{ inputs.job-name }} + cancel-in-progress: true \ No newline at end of file diff --git a/.github/workflows/linux-test.yml b/.github/workflows/linux-test.yml index 7b8a826453..6ddc601f2c 100644 --- a/.github/workflows/linux-test.yml +++ b/.github/workflows/linux-test.yml @@ -68,7 +68,8 @@ jobs: SCRIPT: ${{ inputs.script }} RUNNER_TEST_RESULTS_DIR: /tmp/test_results ARCH: ${{ inputs.architecture }} - name: ${{ inputs.job-name }}-${{ matrix.desired_cuda }} + DOWNLOAD_ARTIFACT_NAME: pytorch_tensorrt_${{ matrix.tensorrt.version }}_${{ matrix.python_version }}_${{ matrix.desired_cuda }}_${{ inputs.architecture }} + name: ${{ inputs.job-name }}-${{ matrix.tensorrt.version }}-${{ matrix.python_version }}-${{ matrix.desired_cuda }} runs-on: ${{ matrix.validation_runner }} container: image: ${{ matrix.container_image }} @@ -112,10 +113,17 @@ jobs: repository: ${{ inputs.repository }} script: ${{ inputs.pre-script }} - name: Download artifacts + if: ${{ matrix.tensorrt == '' }} uses: actions/download-artifact@v3 with: name: ${{ env.ARTIFACT_NAME }} path: /opt/torch-tensorrt-builds/ + - name: Download artifacts + if: ${{ matrix.tensorrt != '' }} + uses: actions/download-artifact@v3 + with: + name: ${{ env.DOWNLOAD_ARTIFACT_NAME }} + path: /opt/torch-tensorrt-builds/ # - name: Install torch and torch-tensorrt # if: ${{ inputs.pre-script != '' }} # uses: ./test-infra/.github/actions/run-script-with-cache diff --git a/packaging/pre_build_script.sh b/packaging/pre_build_script.sh index 1dbfb1c3eb..6b107b63b0 100755 --- a/packaging/pre_build_script.sh +++ b/packaging/pre_build_script.sh @@ -21,6 +21,15 @@ pip install --force-reinstall --pre ${TORCH_TORCHVISION} --index-url ${INDEX_URL export TORCH_BUILD_NUMBER=$(python -c "import torch, urllib.parse as ul; print(ul.quote_plus(torch.__version__))") export TORCH_INSTALL_PATH=$(python -c "import torch, os; print(os.path.dirname(torch.__file__))") +if [[ ${TENSORRT_VERSION} != "" ]]; then + # this is the upgraded TensorRT version, replace current tensorrt version to the upgrade tensorRT version in the pyproject.toml + current_version=$(cat dev_dep_versions.yml | grep __tensorrt_version__ | sed 's/__tensorrt_version__: //g' | sed 's/"//g') + sed -i -e "s/tensorrt-cu12==${current_version}/tensorrt-cu12==${TENSORRT_VERSION}/g" \ + -e "s/tensorrt-cu12-bindings==${current_version}/tensorrt-cu12-bindings==${TENSORRT_VERSION}/g" \ + -e "s/tensorrt-cu12-libs==${current_version}/tensorrt-cu12-libs==${TENSORRT_VERSION}/g" \ + pyproject.toml +fi + if [[ "${CU_VERSION::4}" < "cu12" ]]; then # replace dependencies from tensorrt-cu12-bindings/libs to tensorrt-cu11-bindings/libs sed -i -e "s/tensorrt-cu12==/tensorrt-${CU_VERSION::4}==/g" \ @@ -29,7 +38,11 @@ if [[ "${CU_VERSION::4}" < "cu12" ]]; then pyproject.toml fi -cat toolchains/ci_workspaces/MODULE.bazel.tmpl | envsubst > MODULE.bazel +if [[ ${TENSORRT_VERSION} != "" ]]; then + cat toolchains/ci_workspaces/MODULE_tensorrt.bazel.tmpl | envsubst > MODULE.bazel +else + cat toolchains/ci_workspaces/MODULE.bazel.tmpl | envsubst > MODULE.bazel +fi cat MODULE.bazel export CI_BUILD=1 diff --git a/toolchains/ci_workspaces/MODULE_tensorrt.bazel.tmpl b/toolchains/ci_workspaces/MODULE_tensorrt.bazel.tmpl new file mode 100644 index 0000000000..aff07a0383 --- /dev/null +++ b/toolchains/ci_workspaces/MODULE_tensorrt.bazel.tmpl @@ -0,0 +1,115 @@ +module( + name = "torch_tensorrt", + repo_name = "org_pytorch_tensorrt", + version = "${BUILD_VERSION}" +) + +bazel_dep(name = "googletest", version = "1.14.0") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_python", version = "0.34.0") + +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain( + ignore_root_user_error = True, + python_version = "3.11", +) + +bazel_dep(name = "rules_pkg", version = "1.0.1") +git_override( + module_name = "rules_pkg", + commit = "17c57f4", + remote = "https://github.com/narendasan/rules_pkg", +) + +local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") + +# External dependency for torch_tensorrt if you already have precompiled binaries. +local_repository( + name = "torch_tensorrt", + path = "/opt/conda/lib/python3.8/site-packages/torch_tensorrt", +) + + +new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository") + +# CUDA should be installed on the system locally +new_local_repository( + name = "cuda", + build_file = "@//third_party/cuda:BUILD", + path = "${CUDA_HOME}", +) + +new_local_repository( + name = "cuda_win", + build_file = "@//third_party/cuda:BUILD", + path = "${CUDA_HOME}", +) + + +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +############################################################################################################# +# Tarballs and fetched dependencies (default - use in cases when building from precompiled bin and tarballs) +############################################################################################################# + +http_archive( + name = "libtorch", + build_file = "@//third_party/libtorch:BUILD", + strip_prefix = "libtorch", + urls = ["https://download.pytorch.org/libtorch/${CHANNEL}/${CU_VERSION}/libtorch-cxx11-abi-shared-with-deps-latest.zip"], +) + +# Download these tarballs manually from the NVIDIA website +# Either place them in the distdir directory in third_party and use the --distdir flag +# or modify the urls to "file:////.tar.gz + +http_archive( + name = "tensorrt", + build_file = "@//third_party/tensorrt/archive:BUILD", + sha256 = "${TENSORRT_SHA256}", + strip_prefix = "${TENSORRT_STRIP_PREFIX}", + urls = [ + "${TENSORRT_URLS}", + ], +) + +http_archive( + name = "tensorrt_win", + build_file = "@//third_party/tensorrt/archive:BUILD", + sha256 = "${TENSORRT_SHA256}", + strip_prefix = "${TENSORRT_STRIP_PREFIX}", + urls = [ + "${TENSORRT_URLS}", + ], +) + + +#################################################################################### +# Locally installed dependencies (use in cases of custom dependencies or aarch64) +#################################################################################### + +# NOTE: In the case you are using just the pre-cxx11-abi path or just the cxx11 abi path +# with your local libtorch, just point deps at the same path to satisfy bazel. + +# NOTE: NVIDIA's aarch64 PyTorch (python) wheel file uses the CXX11 ABI unlike PyTorch's standard +# x86_64 python distribution. If using NVIDIA's version just point to the root of the package +# for both versions here and do not use --config=pre-cxx11-abi + +new_local_repository( + name = "libtorch_win", + path = "${TORCH_INSTALL_PATH}", + build_file = "third_party/libtorch/BUILD" +) + +new_local_repository( + name = "libtorch_pre_cxx11_abi", + path = "${TORCH_INSTALL_PATH}", + build_file = "third_party/libtorch/BUILD" +) + +#new_local_repository( +# name = "tensorrt", +# path = "/usr/", +# build_file = "@//third_party/tensorrt/local:BUILD" +#)