Skip to content

Commit 4d8a94a

Browse files
fix the libtorch version mismatch issue (#3086)
1 parent e30a703 commit 4d8a94a

File tree

9 files changed

+41
-158
lines changed

9 files changed

+41
-158
lines changed

.github/scripts/install-torch-tensorrt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set -eou pipefail
1+
set -exou pipefail
22

33
TORCH_TORCHVISION=$(grep "^torch" ${PWD}/py/requirements.txt)
44
INDEX_URL=https://download.pytorch.org/whl/${CHANNEL}/${CU_VERSION}

.github/workflows/release-wheel-linux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ jobs:
199199
mkdir release/tarball
200200
mkdir release/wheel
201201
if [[ "${{ inputs.cxx11-tarball-release }}" == "true" ]]; then
202-
bazel build //:libtorchtrt --compilation_mode opt --config=default
202+
bazel build //:libtorchtrt --compilation_mode opt --config=linux
203203
cp bazel-bin/libtorchtrt.tar.gz \
204204
release/tarball/libtorchtrt-${BUILD_VERSION}-tensorrt${TRT_VERSION}-cuda${CU_VERSION:2}-libtorch${PYTORCH_VERSION}-x86_64-linux.tar.gz
205205
else

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ wheelhouse/
7373
tests/py/dynamo/models/*.ts
7474
tests/py/dynamo/models/*.ep
7575
*.deb
76-
*.tar.xz
76+
*.tar.xz
77+
MODULE.bazel.lock

MODULE.bazel.lock

-127
This file was deleted.

packaging/pre_build_script.sh

+15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
#!/bin/bash
22

3+
set -x
4+
35
# Install dependencies
46
python3 -m pip install pyyaml
7+
58
yum install -y ninja-build gettext
9+
610
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/bazelisk-linux-amd64 \
711
&& mv bazelisk-linux-amd64 /usr/bin/bazel \
812
&& chmod +x /usr/bin/bazel
913

14+
TORCH_TORCHVISION=$(grep "^torch" py/requirements.txt)
15+
INDEX_URL=https://download.pytorch.org/whl/${CHANNEL}/${CU_VERSION}
16+
17+
# Install all the dependencies required for Torch-TensorRT
18+
pip uninstall -y torch torchvision
19+
pip install --force-reinstall --pre ${TORCH_TORCHVISION} --index-url ${INDEX_URL}
20+
pip install --pre -r tests/py/requirements.txt --use-deprecated legacy-resolver
21+
22+
1023
export TORCH_BUILD_NUMBER=$(python -c "import torch, urllib.parse as ul; print(ul.quote_plus(torch.__version__))")
1124
export TORCH_INSTALL_PATH=$(python -c "import torch, os; print(os.path.dirname(torch.__file__))")
1225

1326
cat toolchains/ci_workspaces/MODULE.bazel.tmpl | envsubst > MODULE.bazel
27+
28+
cat MODULE.bazel
1429
export CI_BUILD=1

packaging/pre_build_script_windows.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set -eou pipefail
1+
set -exou pipefail
22

33
pip install -U numpy packaging pyyaml setuptools wheel
44

@@ -10,9 +10,18 @@ choco install bazelisk -y
1010

1111
#curl -Lo TensorRT.zip https://developer.download.nvidia.com/compute/machine-learning/tensorrt/10.0.1/zip/TensorRT-10.0.1.6.Windows10.win10.cuda-12.4.zip
1212
#unzip -o TensorRT.zip -d C:/
13+
TORCH_TORCHVISION=$(grep "^torch" py/requirements.txt)
14+
INDEX_URL=https://download.pytorch.org/whl/${CHANNEL}/${CU_VERSION}
15+
16+
# Install all the dependencies required for Torch-TensorRT
17+
pip uninstall -y torch torchvision
18+
pip install --force-reinstall --pre ${TORCH_TORCHVISION} --index-url ${INDEX_URL}
19+
pip install --pre -r tests/py/requirements.txt --use-deprecated legacy-resolver
1320

1421
export CUDA_HOME="$(echo ${CUDA_PATH} | sed -e 's#\\#\/#g')"
22+
export TORCH_INSTALL_PATH="$(python -c "import torch, os; print(os.path.dirname(torch.__file__))" | sed -e 's#\\#\/#g')"
1523

1624
cat toolchains/ci_workspaces/MODULE.bazel.tmpl | envsubst > MODULE.bazel
1725

26+
cat MODULE.bazel
1827
echo "RELEASE=1" >> ${GITHUB_ENV}

py/torch_tensorrt/_compile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,4 @@ def save(
534534
exp_program = torch.export.export(
535535
module, tuple(arg_inputs), kwargs=kwarg_inputs, strict=False
536536
)
537-
torch.export.save(exp_program, file_path)
537+
torch.export.save(exp_program, file_path)

py/torch_tensorrt/dynamo/conversion/_conversion.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
from typing import Any, List, Optional, Sequence
55

6+
import tensorrt as trt
67
import torch
78
from torch.fx.experimental.proxy_tensor import unset_fake_temporarily
89
from torch_tensorrt._Device import Device
@@ -17,8 +18,6 @@
1718
from torch_tensorrt.dynamo.runtime import PythonTorchTensorRTModule, TorchTensorRTModule
1819
from torch_tensorrt.dynamo.utils import get_torch_inputs
1920

20-
import tensorrt as trt
21-
2221
logger = logging.getLogger(__name__)
2322

2423

toolchains/ci_workspaces/MODULE.bazel.tmpl

+10-24
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ http_archive(
6060
urls = ["https://download.pytorch.org/libtorch/${CHANNEL}/${CU_VERSION}/libtorch-cxx11-abi-shared-with-deps-latest.zip"],
6161
)
6262

63-
http_archive(
64-
name = "libtorch_pre_cxx11_abi",
65-
build_file = "@//third_party/libtorch:BUILD",
66-
strip_prefix = "libtorch",
67-
urls = ["https://download.pytorch.org/libtorch/${CHANNEL}/${CU_VERSION}/libtorch-shared-with-deps-latest.zip"],
68-
)
69-
70-
http_archive(
71-
name = "libtorch_win",
72-
build_file = "@//third_party/libtorch:BUILD",
73-
strip_prefix = "libtorch",
74-
urls = ["https://download.pytorch.org/libtorch/${CHANNEL}/${CU_VERSION}/libtorch-win-shared-with-deps-latest.zip"],
75-
)
76-
7763
# Download these tarballs manually from the NVIDIA website
7864
# Either place them in the distdir directory in third_party and use the --distdir flag
7965
# or modify the urls to "file:///<PATH TO TARBALL>/<TARBALL NAME>.tar.gz
@@ -110,17 +96,17 @@ http_archive(
11096
# x86_64 python distribution. If using NVIDIA's version just point to the root of the package
11197
# for both versions here and do not use --config=pre-cxx11-abi
11298

113-
#new_local_repository(
114-
# name = "libtorch",
115-
# path = "${TORCH_INSTALL_PATH}",
116-
# build_file = "third_party/libtorch/BUILD"
117-
#)
99+
new_local_repository(
100+
name = "libtorch_win",
101+
path = "${TORCH_INSTALL_PATH}",
102+
build_file = "third_party/libtorch/BUILD"
103+
)
118104

119-
#new_local_repository(
120-
# name = "libtorch_pre_cxx11_abi",
121-
# path = "${TORCH_INSTALL_PATH}",
122-
# build_file = "third_party/libtorch/BUILD"
123-
#
105+
new_local_repository(
106+
name = "libtorch_pre_cxx11_abi",
107+
path = "${TORCH_INSTALL_PATH}",
108+
build_file = "third_party/libtorch/BUILD"
109+
)
124110

125111
#new_local_repository(
126112
# name = "tensorrt",

0 commit comments

Comments
 (0)