Skip to content

Commit ff8c872

Browse files
gs-oliveHolyWu
andauthored
cherry-pick: Python Runtime Windows Builds on TRT 10 (#2764) (#2776)
Co-authored-by: HolyWu <[email protected]>
1 parent f534f12 commit ff8c872

File tree

29 files changed

+601
-104
lines changed

29 files changed

+601
-104
lines changed

.bazelrc

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ build --cxxopt="-fdiagnostics-color=always"
2525
build --cxxopt='-std=c++17'
2626
#build --linkopt="-Wl,--no-as-needed"
2727

28+
build:windows --cxxopt="/GS-" --cxxopt="/std:c++17" --cxxopt="/permissive-"
29+
build:windows --cxxopt="/wd4244" --cxxopt="/wd4267" --cxxopt="/wd4819"
30+
build:windows --features=windows_export_all_symbols
2831

2932
build:python --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
3033
build:python --linkopt="-D_GLIBCXX_USE_CXX11_ABI=0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set -eou pipefail
2+
source "${BUILD_ENV_FILE}"
3+
4+
# Install test index version of Torch and Torchvision
5+
${CONDA_RUN} ${PIP_INSTALL_TORCH} torchvision
6+
${CONDA_RUN} pip install pyyaml mpmath==1.3.0
7+
8+
# Install TRT from PyPi
9+
TRT_VERSION=$(${CONDA_RUN} python -c "import yaml; print(yaml.safe_load(open('dev_dep_versions.yml', 'r'))['__tensorrt_version__'])")
10+
${CONDA_RUN} pip install tensorrt==${TRT_VERSION} tensorrt-${CU_VERSION::4}==${TRT_VERSION} tensorrt-${CU_VERSION::4}-bindings==${TRT_VERSION} tensorrt-${CU_VERSION::4}-libs==${TRT_VERSION} --extra-index-url https://pypi.nvidia.com
11+
12+
# Install pre-built Torch-TRT
13+
${CONDA_RUN} pip install ${RUNNER_ARTIFACT_DIR}/torch_tensorrt*.whl
14+
15+
echo -e "Running test script";
+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: Build and test Windows wheels
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- nightly
9+
- release/*
10+
tags:
11+
# NOTE: Binary build pipelines should only get triggered on release candidate builds
12+
# Release candidate tags look like: v1.11.0-rc1
13+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
14+
workflow_dispatch:
15+
16+
jobs:
17+
generate-matrix:
18+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
19+
with:
20+
package-type: wheel
21+
os: windows
22+
test-infra-repository: pytorch/test-infra
23+
test-infra-ref: main
24+
with-rocm: false
25+
with-cpu: false
26+
27+
build:
28+
needs: generate-matrix
29+
permissions:
30+
id-token: write
31+
contents: read
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include:
36+
- repository: pytorch/tensorrt
37+
pre-script: packaging/pre_build_script_windows.sh
38+
smoke-test-script: packaging/smoke_test_windows.py
39+
package-name: torch_tensorrt
40+
name: Build torch-tensorrt whl package
41+
uses: pytorch/test-infra/.github/workflows/build_wheels_windows.yml@main
42+
with:
43+
repository: ${{ matrix.repository }}
44+
ref: ""
45+
test-infra-repository: pytorch/test-infra
46+
test-infra-ref: main
47+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
48+
pre-script: ${{ matrix.pre-script }}
49+
smoke-test-script: ${{ matrix.smoke-test-script }}
50+
package-name: ${{ matrix.package-name }}
51+
trigger-event: ${{ github.event_name }}
52+
53+
tests-py-dynamo-converters:
54+
name: Test dynamo converters [Python]
55+
needs: [generate-matrix, build]
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
include:
60+
- repository: pytorch/tensorrt
61+
package-name: torch_tensorrt
62+
uses: ./.github/workflows/windows-test.yml
63+
with:
64+
job-name: tests-py-dynamo-converters
65+
repository: "pytorch/tensorrt"
66+
ref: ""
67+
test-infra-repository: pytorch/test-infra
68+
test-infra-ref: main
69+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
70+
pre-script: packaging/driver_upgrade.bat
71+
script: |
72+
export USE_HOST_DEPS=1
73+
pushd .
74+
cd tests/py/dynamo
75+
${CONDA_RUN} python -m pip install --pre pytest-xdist timm transformers parameterized expecttest==0.1.6 --use-deprecated=legacy-resolver
76+
${CONDA_RUN} python -m pytest --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_converters_test_results.xml -n 10 conversion/
77+
popd
78+
79+
tests-py-dynamo-fe:
80+
name: Test dynamo frontend [Python]
81+
needs: [generate-matrix, build]
82+
strategy:
83+
fail-fast: false
84+
matrix:
85+
include:
86+
- repository: pytorch/tensorrt
87+
package-name: torch_tensorrt
88+
uses: ./.github/workflows/windows-test.yml
89+
with:
90+
job-name: tests-py-dynamo-fe
91+
repository: "pytorch/tensorrt"
92+
ref: ""
93+
test-infra-repository: pytorch/test-infra
94+
test-infra-ref: main
95+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
96+
pre-script: packaging/driver_upgrade.bat
97+
script: |
98+
export USE_HOST_DEPS=1
99+
pushd .
100+
cd tests/py/dynamo
101+
${CONDA_RUN} python -m pip install --pre pytest-xdist timm transformers parameterized expecttest==0.1.6 --use-deprecated=legacy-resolver
102+
${CONDA_RUN} python -m pytest --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_fe_test_results.xml --ir dynamo models/test_models_export.py
103+
${CONDA_RUN} python -m pytest --junitxml=${RUNNER_TEST_RESULTS_DIR}/dyn_models_export.xml --ir dynamo models/test_dyn_models.py
104+
popd
105+
106+
tests-py-torch-compile-be:
107+
name: Test torch compile backend [Python]
108+
needs: [generate-matrix, build]
109+
strategy:
110+
fail-fast: false
111+
matrix:
112+
include:
113+
- repository: pytorch/tensorrt
114+
package-name: torch_tensorrt
115+
uses: ./.github/workflows/windows-test.yml
116+
with:
117+
job-name: tests-py-torch-compile-be
118+
repository: ${{ matrix.repository }}
119+
ref: ""
120+
test-infra-repository: pytorch/test-infra
121+
test-infra-ref: main
122+
pre-script: packaging/driver_upgrade.bat
123+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
124+
script: |
125+
export USE_HOST_DEPS=1
126+
pushd .
127+
cd tests/py/dynamo
128+
${CONDA_RUN} python -m pip install --pre pytest-xdist timm transformers parameterized expecttest==0.1.6 --use-deprecated=legacy-resolver
129+
${CONDA_RUN} python -m pytest -n 10 --junitxml=${RUNNER_TEST_RESULTS_DIR}/torch_compile_be_test_results.xml backend/
130+
${CONDA_RUN} python -m pytest -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/torch_comple_be_e2e_test_results.xml --ir torch_compile models/test_models.py
131+
popd
132+
133+
tests-py-dynamo-core:
134+
name: Test dynamo core [Python]
135+
needs: [generate-matrix, build]
136+
strategy:
137+
fail-fast: false
138+
matrix:
139+
include:
140+
- repository: pytorch/tensorrt
141+
package-name: torch_tensorrt
142+
uses: ./.github/workflows/windows-test.yml
143+
with:
144+
job-name: tests-py-dynamo-core
145+
repository: "pytorch/tensorrt"
146+
ref: ""
147+
test-infra-repository: pytorch/test-infra
148+
test-infra-ref: main
149+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
150+
pre-script: packaging/driver_upgrade.bat
151+
script: |
152+
export USE_HOST_DEPS=1
153+
pushd .
154+
cd tests/py/dynamo
155+
${CONDA_RUN} python -m pip install --pre pytest-xdist timm transformers parameterized expecttest==0.1.6 --use-deprecated=legacy-resolver
156+
${CONDA_RUN} python -m pytest -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_runtime_test_results.xml runtime/
157+
${CONDA_RUN} python -m pytest -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_partitioning_test_results.xml partitioning/
158+
${CONDA_RUN} python -m pytest -n 4 --junitxml=${RUNNER_TEST_RESULTS_DIR}/tests_py_dynamo_core_lowering_test_results.xml lowering/
159+
popd

.github/workflows/windows-test.yml

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Test on Windows
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
repository:
7+
description: 'Repository to checkout, defaults to ""'
8+
default: ""
9+
type: string
10+
ref:
11+
description: 'Reference to checkout, defaults to "nightly"'
12+
default: "nightly"
13+
type: string
14+
test-infra-repository:
15+
description: "Test infra repository to use"
16+
default: "pytorch/test-infra"
17+
type: string
18+
test-infra-ref:
19+
description: "Test infra reference to use"
20+
default: ""
21+
type: string
22+
build-matrix:
23+
description: "Build matrix to utilize"
24+
default: ""
25+
type: string
26+
pre-script:
27+
description: "Pre script to run prior to build"
28+
default: ""
29+
type: string
30+
script:
31+
description: 'Script to utilize'
32+
default: "python setup.py bdist_wheel"
33+
type: string
34+
job-name:
35+
description: "Name for the job, which is displayed in the GitHub UI"
36+
default: "windows-job"
37+
type: string
38+
continue-on-error:
39+
description: "Prevents a job from failing when a step fails. Set to true to allow a job to pass when exec script step fails."
40+
default: false
41+
type: boolean
42+
43+
jobs:
44+
test:
45+
strategy:
46+
fail-fast: false
47+
matrix: ${{ fromJSON(inputs.build-matrix) }}
48+
env:
49+
PYTHON_VERSION: ${{ matrix.python_version }}
50+
PACKAGE_TYPE: wheel
51+
REPOSITORY: ${{ inputs.repository }}
52+
REF: ${{ inputs.ref }}
53+
CU_VERSION: ${{ matrix.desired_cuda }}
54+
SCRIPT: ${{ inputs.script }}
55+
PYTHONUTF8: 1
56+
name: ${{ inputs.job-name }}-${{ matrix.desired_cuda }}
57+
runs-on: windows.8xlarge.nvidia.gpu.nonephemeral
58+
defaults:
59+
run:
60+
shell: bash -l {0}
61+
# If a build is taking longer than 60 minutes on these runners we need
62+
# to have a conversation
63+
timeout-minutes: 60
64+
steps:
65+
- name: Clean workspace
66+
run: |
67+
echo "::group::Cleanup debug output"
68+
rm -rfv "${GITHUB_WORKSPACE}"
69+
mkdir -p "${GITHUB_WORKSPACE}"
70+
echo "::endgroup::"
71+
- name: Checkout repository (${{ inputs.test-infra-repository }}@${{ inputs.test-infra-ref }})
72+
uses: actions/checkout@v3
73+
with:
74+
# Support the use case where we need to checkout someone's fork
75+
repository: ${{ inputs.test-infra-repository }}
76+
ref: ${{ inputs.test-infra-ref }}
77+
path: test-infra
78+
- name: Setup Windows
79+
uses: ./test-infra/.github/actions/setup-windows
80+
- name: Setup SSH
81+
uses: ./test-infra/.github/actions/setup-ssh
82+
with:
83+
github-secret: ${{ github.token }}
84+
- name: Add Conda scripts to GitHub path
85+
run: |
86+
echo "C:/Jenkins/Miniconda3/Scripts" >> $GITHUB_PATH
87+
- uses: ./test-infra/.github/actions/set-channel
88+
- uses: ./test-infra/.github/actions/setup-binary-builds
89+
with:
90+
repository: ${{ inputs.repository }}
91+
ref: ${{ inputs.ref }}
92+
setup-miniconda: false
93+
python-version: ${{ env.PYTHON_VERSION }}
94+
cuda-version: ${{ env.CU_VERSION }}
95+
arch: ${{ env.ARCH }}
96+
- name: Run Pre-Script with Caching
97+
if: ${{ inputs.pre-script != '' }}
98+
uses: ./test-infra/.github/actions/run-script-with-cache
99+
with:
100+
cache-path: ${{ inputs.cache-path }}
101+
cache-key: ${{ inputs.cache-key }}
102+
repository: ${{ inputs.repository }}
103+
script: ${{ inputs.pre-script }}
104+
is_windows: 'enabled'
105+
- name: Download artifacts
106+
uses: actions/download-artifact@v3
107+
with:
108+
name: ${{ env.ARTIFACT_NAME }}
109+
path: ${{ runner.temp }}/artifacts/
110+
- name: Pack script
111+
continue-on-error: ${{ inputs.continue-on-error }}
112+
working-directory: ${{ inputs.repository }}
113+
env:
114+
ALL_SECRETS: ${{ toJSON(secrets) }}
115+
run: |
116+
set -eou pipefail
117+
source "${BUILD_ENV_FILE}"
118+
{
119+
echo "${SCRIPT}";
120+
} > "user_script"
121+
cat .github/scripts/install-torch-tensorrt-windows.sh user_script > exec_script
122+
- name: Run script
123+
uses: ./test-infra/.github/actions/run-script-with-cache
124+
with:
125+
repository: ${{ inputs.repository }}
126+
script: exec_script
127+
is_windows: 'enabled'
128+
- name: Surface failing tests
129+
if: always()
130+
uses: pmeier/[email protected]
131+
with:
132+
path: ${{ env.RUNNER_TEST_RESULTS_DIR }}
133+
fail-on-empty: false
134+
- name: Teardown Windows
135+
if: ${{ always() }}
136+
uses: ./test-infra/.github/actions/teardown-windows
137+
138+
concurrency:
139+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ inputs.repository }}-${{ github.event_name == 'workflow_dispatch' }}-${{ inputs.job-name }}
140+
cancel-in-progress: true

BUILD BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pkg_tar(
5252
pkg_tar(
5353
name = "lib",
5454
srcs = select({
55-
":windows": ["//cpp/lib:torch_tensorrt.dll"],
55+
":windows": ["//cpp/lib:torchtrt.dll"],
5656
"//conditions:default": [
5757
"//cpp/lib:libtorchtrt.so",
5858
"//cpp/lib:libtorchtrt_plugins.so",
@@ -66,7 +66,7 @@ pkg_tar(
6666
pkg_tar(
6767
name = "lib_rt",
6868
srcs = select({
69-
":windows": ["//cpp/lib:torch_tensorrt_runtime.dll"],
69+
":windows": ["//cpp/lib:torchtrt_runtime.dll"],
7070
"//conditions:default": [
7171
"//cpp/lib:libtorchtrt_runtime.so",
7272
],

core/conversion/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ cc_library(
3131
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
3232
"//conditions:default": ["@libtorch"],
3333
}),
34+
alwayslink = True,
3435
)
3536

3637
pkg_tar(

core/conversion/conversionctx/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ cc_library(
2626
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
2727
"//conditions:default": ["@libtorch"],
2828
}),
29+
alwayslink = True,
2930
)
3031

3132
pkg_tar(

core/conversion/converters/impl/activation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ auto acthardtanh TORCHTRT_UNUSED =
9191

9292
// Out_tensor of ParametricReLU shape is all 0, when slopes nDims is not equal to in nDims.
9393
// Since make sure splopes nDims is equal to in nDims.
94-
if (slopes.ndimension() == 1 and original_shape.nbDims != slopes.ndimension()) {
94+
if (slopes.ndimension() == 1 && original_shape.nbDims != slopes.ndimension()) {
9595
std::vector<int64_t> slopes_new_shape(original_shape.nbDims, 1);
9696
auto first_inputs_allowed_formats = ctx->net->getInput(0)->getAllowedFormats();
9797
for (size_t inputs_index = 1; inputs_index < ctx->num_inputs; inputs_index++) {

core/ir/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cc_library(
2828
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
2929
"//conditions:default": ["@libtorch"],
3030
}),
31+
alwayslink = True,
3132
)
3233

3334
pkg_tar(

core/lowering/passes/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cc_library(
5252
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
5353
"//conditions:default": ["@libtorch"],
5454
}),
55+
alwayslink = True,
5556
)
5657

5758
pkg_tar(

0 commit comments

Comments
 (0)