Skip to content

Commit b774440

Browse files
authored
fix: Legacy CI pip installation (#2239)
1 parent 64ce49b commit b774440

File tree

4 files changed

+398
-23
lines changed

4 files changed

+398
-23
lines changed

.circleci/config.yml

+66-16
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,11 @@ commands:
317317
name: Build torch-tensorrt python legacy release (pre-cxx11-abi)
318318
command: |
319319
export CUDA_HOME=/usr/local/cuda-<< parameters.cuda-version >>/
320-
mv toolchains/ci_workspaces/WORKSPACE.<< parameters.platform >> WORKSPACE
321-
python3 -m pip install pip==22.0.2
322-
python3 -m pip wheel --no-deps --verbose --pre . --extra-index-url https://pypi.nvidia.com --extra-index-url << parameters.torch-build-index >> --config-setting="--build-option=--legacy" -w dist
320+
mv toolchains/ci_workspaces/WORKSPACE.<< parameters.platform >>.legacy WORKSPACE
321+
mv toolchains/legacy/pyproject.toml pyproject.toml
322+
python3 -m pip install wheel setuptools pyyaml
323+
python3 -m pip install pybind11==2.6.2
324+
python3 setup.py bdist_wheel --legacy
323325
python3 -m pip install dist/torch_tensorrt*
324326
mkdir -p /tmp/dist/builds
325327
cp dist/torch_tensorrt* /tmp/dist/builds
@@ -838,8 +840,11 @@ jobs:
838840
legacy:
839841
type: boolean
840842
default: false
843+
ci-image:
844+
type: string
845+
default: "linux-cuda-12:2023.05.1"
841846
machine:
842-
image: linux-cuda-12:2023.05.1
847+
image: << parameters.ci-image >>
843848
resource_class: gpu.nvidia.small
844849
steps:
845850
- checkout
@@ -905,8 +910,14 @@ jobs:
905910
type: string
906911
cudnn-version:
907912
type: string
913+
ci-image:
914+
type: string
915+
default: "linux-cuda-12:2023.05.1"
916+
platform:
917+
type: string
918+
default: "x86_64"
908919
machine:
909-
image: linux-cuda-12:2023.05.1
920+
image: << parameters.ci-image >>
910921
resource_class: gpu.nvidia.medium
911922
parallelism: 4
912923
steps:
@@ -931,7 +942,8 @@ jobs:
931942
name: "Install torch-tensorrt"
932943
command: pip3 install /tmp/dist/x86_64-linux/*cp310-cp310*.whl
933944
- dump-test-env
934-
- test-ts-core
945+
- test-ts-core:
946+
platform: << parameters.platform >>
935947

936948
test-py-ts-x86_64-linux:
937949
parameters:
@@ -945,8 +957,11 @@ jobs:
945957
type: string
946958
python-version:
947959
type: string
960+
ci-image:
961+
type: string
962+
default: "linux-cuda-12:2023.05.1"
948963
machine:
949-
image: linux-cuda-12:2023.05.1
964+
image: << parameters.ci-image >>
950965
resource_class: gpu.nvidia.medium
951966
steps:
952967
- checkout
@@ -978,9 +993,12 @@ jobs:
978993
type: string
979994
python-version:
980995
type: string
996+
ci-image:
997+
type: string
998+
default: "linux-cuda-12:2023.05.1"
981999
parallelism: 8
9821000
machine:
983-
image: linux-cuda-12:2023.05.1
1001+
image: << parameters.ci-image >>
9841002
resource_class: gpu.nvidia.medium
9851003
steps:
9861004
- checkout
@@ -1014,9 +1032,12 @@ jobs:
10141032
type: string
10151033
python-version:
10161034
type: string
1035+
ci-image:
1036+
type: string
1037+
default: "linux-cuda-12:2023.05.1"
10171038
parallelism: 8
10181039
machine:
1019-
image: linux-cuda-12:2023.05.1
1040+
image: << parameters.ci-image >>
10201041
resource_class: gpu.nvidia.medium
10211042
steps:
10221043
- checkout
@@ -1053,9 +1074,12 @@ jobs:
10531074
type: string
10541075
python-version:
10551076
type: string
1077+
ci-image:
1078+
type: string
1079+
default: "linux-cuda-12:2023.05.1"
10561080
parallelism: 4
10571081
machine:
1058-
image: linux-cuda-12:2023.05.1
1082+
image: << parameters.ci-image >>
10591083
resource_class: gpu.nvidia.medium
10601084
steps:
10611085
- checkout
@@ -1092,9 +1116,12 @@ jobs:
10921116
type: string
10931117
torch-build-index:
10941118
type: string
1119+
ci-image:
1120+
type: string
1121+
default: "linux-cuda-12:2023.05.1"
10951122
parallelism: 4
10961123
machine:
1097-
image: linux-cuda-12:2023.05.1
1124+
image: << parameters.ci-image >>
10981125
resource_class: gpu.nvidia.small
10991126
steps:
11001127
- when:
@@ -1142,8 +1169,11 @@ jobs:
11421169
type: string
11431170
torch-build-index:
11441171
type: string
1172+
ci-image:
1173+
type: string
1174+
default: "linux-cuda-12:2023.05.1"
11451175
machine:
1146-
image: linux-cuda-12:2023.05.1
1176+
image: << parameters.ci-image >>
11471177
resource_class: gpu.nvidia.small
11481178
steps:
11491179
- when:
@@ -1278,8 +1308,11 @@ jobs:
12781308
type: string
12791309
python-version:
12801310
type: string
1311+
ci-image:
1312+
type: string
1313+
default: "linux-cuda-12:2023.05.1"
12811314
machine:
1282-
image: linux-cuda-12:2023.05.1
1315+
image: << parameters.ci-image >>
12831316
resource_class: gpu.nvidia.small
12841317
steps:
12851318
- checkout
@@ -1315,8 +1348,11 @@ jobs:
13151348
parameters:
13161349
torch-base-image:
13171350
type: string
1351+
ci-image:
1352+
type: string
1353+
default: "linux-cuda-12:2023.05.1"
13181354
machine:
1319-
image: linux-cuda-12:2023.05.1
1355+
image: << parameters.ci-image >>
13201356
resource_class: gpu.nvidia.small
13211357
steps:
13221358
- checkout
@@ -1343,8 +1379,11 @@ jobs:
13431379
default: false
13441380
torch-base-image:
13451381
type: string
1382+
ci-image:
1383+
type: string
1384+
default: "linux-cuda-12:2023.05.1"
13461385
machine:
1347-
image: linux-cuda-12:2023.05.1
1386+
image: << parameters.ci-image >>
13481387
resource_class: gpu.nvidia.small
13491388
steps:
13501389
- when:
@@ -1400,7 +1439,7 @@ parameters:
14001439
# Legacy platform config
14011440
cuda-version-legacy:
14021441
type: string
1403-
default: "11.7"
1442+
default: "11.8"
14041443
torch-build-legacy:
14051444
type: string
14061445
default: "1.13.1+cu117"
@@ -1419,6 +1458,12 @@ parameters:
14191458
trt-version-long-legacy:
14201459
type: string
14211460
default: "8.6.1"
1461+
ci-image-legacy:
1462+
type: string
1463+
default: "linux-cuda-11:2023.02.1"
1464+
platform-legacy:
1465+
type: string
1466+
default: "x86_64.legacy"
14221467

14231468
# Jetson platform config
14241469
cuda-jetson-version:
@@ -1523,6 +1568,7 @@ workflows:
15231568
torch-build-index: << pipeline.parameters.torch-build-index-legacy >>
15241569
python-version: << pipeline.parameters.python-version >>
15251570
legacy: << pipeline.parameters.enable-legacy >>
1571+
ci-image: << pipeline.parameters.ci-image-legacy >>
15261572

15271573
- test-core-cpp-x86_64-linux:
15281574
name: test-core-cpp-x86_64-linux-legacy
@@ -1533,6 +1579,8 @@ workflows:
15331579
trt-version-long: << pipeline.parameters.trt-version-long-legacy >>
15341580
cudnn-version: << pipeline.parameters.cudnn-version-legacy >>
15351581
python-version: << pipeline.parameters.python-version >>
1582+
ci-image: << pipeline.parameters.ci-image-legacy >>
1583+
platform: << pipeline.parameters.platform-legacy >>
15361584
requires:
15371585
- build-x86_64-linux-legacy
15381586

@@ -1543,6 +1591,7 @@ workflows:
15431591
torch-build-index: << pipeline.parameters.torch-build-index-legacy >>
15441592
trt-version-long: << pipeline.parameters.trt-version-long-legacy >>
15451593
python-version: << pipeline.parameters.python-version >>
1594+
ci-image: << pipeline.parameters.ci-image-legacy >>
15461595
requires:
15471596
- build-x86_64-linux-legacy
15481597

@@ -1552,6 +1601,7 @@ workflows:
15521601
torch-build-index: << pipeline.parameters.torch-build-index-legacy >>
15531602
trt-version-long: << pipeline.parameters.trt-version-long-legacy >>
15541603
python-version: << pipeline.parameters.python-version >>
1604+
ci-image: << pipeline.parameters.ci-image-legacy >>
15551605
requires:
15561606
- build-x86_64-linux-legacy
15571607

py/torch_tensorrt/_compile.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@
77
import torch
88
import torch.fx
99
import torch_tensorrt.ts
10-
from torch._export import ExportedProgram
1110
from torch_tensorrt._enums import dtype
1211
from torch_tensorrt._Input import Input
13-
from torch_tensorrt.dynamo.compile import compile as dynamo_compile
12+
from torch_tensorrt._utils import sanitized_torch_version
1413
from torch_tensorrt.fx import InputTensorSpec
1514
from torch_tensorrt.fx.lower import compile as fx_compile
1615
from torch_tensorrt.fx.utils import LowerPrecision
1716
from torch_tensorrt.ts._compiler import compile as torchscript_compile
1817
from typing_extensions import TypeGuard
1918

19+
from packaging import version
20+
21+
DYNAMO_ENABLED = version.parse(sanitized_torch_version()) >= version.parse("2.1.dev")
22+
23+
if DYNAMO_ENABLED:
24+
from torch._export import ExportedProgram
25+
from torch_tensorrt.dynamo.compile import compile as dynamo_compile
26+
2027
logger = logging.getLogger(__name__)
2128

2229
__all__ = [
@@ -64,7 +71,7 @@ def _parse_module_type(module: Any) -> _ModuleType:
6471
return _ModuleType.ts
6572
elif isinstance(module, torch.fx.GraphModule):
6673
return _ModuleType.fx
67-
elif isinstance(module, ExportedProgram):
74+
elif DYNAMO_ENABLED and isinstance(module, ExportedProgram):
6875
return _ModuleType.ep
6976
elif isinstance(module, torch.nn.Module):
7077
return _ModuleType.nn
@@ -93,13 +100,14 @@ def _get_target_ir(module_type: _ModuleType, ir: str) -> _IRType:
93100
else:
94101
if ir == "default":
95102
# Options are listed in order of preference
96-
if module_is_fxable:
103+
if DYNAMO_ENABLED and module_is_fxable:
97104
logger.info("ir was set to default, using dynamo as ir")
98105
return _IRType.dynamo
99106
elif module_is_tsable:
100-
logger.warning(
101-
"Input graph is a Torchscript module but the ir provided is default (dynamo). Please set ir=torchscript to suppress the warning. Compiling the module with ir=torchscript"
102-
)
107+
if DYNAMO_ENABLED:
108+
logger.warning(
109+
"Input graph is a Torchscript module but the ir provided is default (dynamo). Please set ir=torchscript to suppress the warning. Compiling the module with ir=torchscript"
110+
)
103111
return _IRType.ts
104112
elif module_is_exportable:
105113
raise ValueError(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
workspace(name = "Torch-TensorRT")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "rules_python",
7+
sha256 = "863ba0fa944319f7e3d695711427d9ad80ba92c6edd0b7c7443b84e904689539",
8+
strip_prefix = "rules_python-0.22.0",
9+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.22.0/rules_python-0.22.0.tar.gz",
10+
)
11+
12+
load("@rules_python//python:repositories.bzl", "py_repositories")
13+
14+
py_repositories()
15+
16+
http_archive(
17+
name = "rules_pkg",
18+
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
19+
urls = [
20+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
21+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
22+
],
23+
)
24+
25+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
26+
27+
rules_pkg_dependencies()
28+
29+
http_archive(
30+
name = "googletest",
31+
sha256 = "755f9a39bc7205f5a0c428e920ddad092c33c8a1b46997def3f1d4a82aded6e1",
32+
strip_prefix = "googletest-5ab508a01f9eb089207ee87fd547d290da39d015",
33+
urls = ["https://github.com/google/googletest/archive/5ab508a01f9eb089207ee87fd547d290da39d015.zip"],
34+
)
35+
36+
# External dependency for torch_tensorrt if you already have precompiled binaries.
37+
local_repository(
38+
name = "torch_tensorrt",
39+
path = "/opt/circleci/.pyenv/versions/3.10.9/lib/python3.10/site-packages/torch_tensorrt"
40+
)
41+
42+
# CUDA should be installed on the system locally
43+
new_local_repository(
44+
name = "cuda",
45+
build_file = "@//third_party/cuda:BUILD",
46+
path = "/usr/local/cuda-11.8/",
47+
)
48+
49+
new_local_repository(
50+
name = "cublas",
51+
build_file = "@//third_party/cublas:BUILD",
52+
path = "/usr",
53+
)
54+
55+
####################################################################################
56+
# Locally installed dependencies (use in cases of custom dependencies or aarch64)
57+
####################################################################################
58+
59+
# NOTE: In the case you are using just the pre-cxx11-abi path or just the cxx11 abi path
60+
# with your local libtorch, just point deps at the same path to satisfy bazel.
61+
62+
# NOTE: NVIDIA's aarch64 PyTorch (python) wheel file uses the CXX11 ABI unlike PyTorch's standard
63+
# x86_64 python distribution. If using NVIDIA's version just point to the root of the package
64+
# for both versions here and do not use --config=pre-cxx11-abi
65+
66+
new_local_repository(
67+
name = "libtorch",
68+
path = "/opt/circleci/.pyenv/versions/3.10.9/lib/python3.10/site-packages/torch",
69+
build_file = "third_party/libtorch/BUILD"
70+
)
71+
72+
new_local_repository(
73+
name = "libtorch_pre_cxx11_abi",
74+
path = "/opt/circleci/.pyenv/versions/3.10.9/lib/python3.10/site-packages/torch",
75+
build_file = "third_party/libtorch/BUILD"
76+
)
77+
78+
new_local_repository(
79+
name = "cudnn",
80+
path = "/usr/",
81+
build_file = "@//third_party/cudnn/local:BUILD"
82+
)
83+
84+
new_local_repository(
85+
name = "tensorrt",
86+
path = "/usr/",
87+
build_file = "@//third_party/tensorrt/local:BUILD"
88+
)
89+
90+
load("@rules_python//python:pip.bzl", "pip_parse")
91+
92+
pip_parse(
93+
name = "devtools_deps",
94+
requirements = "//:requirements-dev.txt",
95+
)
96+
97+
load("@devtools_deps//:requirements.bzl", "install_deps")
98+
99+
install_deps()

0 commit comments

Comments
 (0)