Skip to content

Commit adc29b0

Browse files
authored
Merge branch 'main' into aten_size_fix
2 parents 34e7b09 + 3736a7e commit adc29b0

File tree

137 files changed

+849
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+849
-330
lines changed

.circleci/config.yml

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ commands:
263263
parameters:
264264
torch-build:
265265
type: string
266-
default: "2.0.0.dev20230129+cu117"
266+
default: "2.0.0.dev20230219+cu117"
267267
torch-build-index:
268268
type: string
269269
default: "https://download.pytorch.org/whl/nightly/cu117"
@@ -463,7 +463,7 @@ commands:
463463
- run:
464464
name: Run core / C++ tests
465465
environment:
466-
LD_LIBRARY_PATH: "/home/circleci/project/bazel-project/external/libtorch_pre_cxx11_abi/lib/:/home/circleci/project/bazel-project/external/tensorrt/lib/:/usr/local/cuda/lib64/:$LD_LIBRARY_PATH"
466+
LD_LIBRARY_PATH: "/opt/circleci/.pyenv/versions/3.9.4/lib/python3.9/site-packages/torch_tensorrt.libs:/home/circleci/project/bazel-project/external/libtorch_pre_cxx11_abi/lib/:/home/circleci/project/bazel-project/external/tensorrt/lib/:/usr/local/cuda/lib64/:$LD_LIBRARY_PATH"
467467
command: |
468468
set -e
469469
mv toolchains/ci_workspaces/WORKSPACE.<< parameters.platform >> WORKSPACE
@@ -719,7 +719,7 @@ jobs:
719719
at: /tmp/dist
720720
- run:
721721
name: "Install torch-tensorrt"
722-
command: pip3 install /tmp/dist/x86_64-linux/*
722+
command: pip3 install /tmp/dist/x86_64-linux/*cp39-cp39*.whl
723723
- dump-test-env
724724
- test-ts-core
725725

@@ -747,7 +747,7 @@ jobs:
747747
torch-build-index: << parameters.torch-build-index >>
748748
- run:
749749
name: "Install torch-tensorrt"
750-
command: pip3 install --pre /tmp/dist/x86_64-linux/*
750+
command: pip3 install --pre /tmp/dist/x86_64-linux/*cp39-cp39*.whl
751751
- dump-test-env
752752
- test-ts-py-api
753753

@@ -777,7 +777,7 @@ jobs:
777777
# command: export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH
778778
- run:
779779
name: "Install torch-tensorrt"
780-
command: pip3 install --pre /tmp/dist/x86_64-linux/*
780+
command: pip3 install --pre /tmp/dist/x86_64-linux/*cp39-cp39*.whl
781781
# We install torch after torch-trt because pip automatically enforces the version constraint otherwise
782782
- dump-test-env
783783
- test-fx
@@ -791,9 +791,10 @@ jobs:
791791
type: string
792792
torch-build-index:
793793
type: string
794+
parallelism: 4
794795
machine:
795796
image: ubuntu-2004-cuda-11.4:202110-01
796-
resource_class: xlarge
797+
resource_class: gpu.nvidia.small
797798
steps:
798799
- when:
799800
condition: << parameters.enabled >>
@@ -805,18 +806,58 @@ jobs:
805806
cd ~/project/py/
806807
docker build -t torch_tensorrt_release_env --build-arg trt_version=<< pipeline.parameters.trt-version-short >> -f ci/Dockerfile.ci .
807808
- run:
808-
name: Build Python packages and pre-cxx11-abi tarball
809+
name: Build Python packages
809810
command: |
810811
cd ~/project/py/
811812
cp ~/project/toolchains/ci_workspaces/WORKSPACE.x86_64.release.rhel ~/project/WORKSPACE
812-
docker run -it --rm -v ~/project:/workspace/project torch_tensorrt_release_env /bin/bash /workspace/project/py/ci/build_whl.sh
813+
docker run -it --rm --gpus all -v ~/project:/workspace/project torch_tensorrt_release_env /bin/bash -c "source /workspace/project/py/ci/build_whl.sh && $(circleci tests split --total=4 ~/project/py/ci/build_manifest.txt)"
814+
- run:
815+
name: Collect packages
816+
command: |
817+
mkdir -p /tmp/dist/x86_64-linux
818+
cp -r ~/project/py/wheelhouse/* /tmp/dist/x86_64-linux
819+
- persist_to_workspace:
820+
root: /tmp/dist
821+
paths:
822+
- x86_64-linux
823+
- store_artifacts:
824+
path: /tmp/dist/x86_64-linux
825+
destination: x86_64-linux
826+
- unless:
827+
condition: << parameters.enabled >>
828+
steps:
829+
- run:
830+
name: Skipped packaging
831+
command: echo -e "Packaging stage not enabled"
832+
833+
# TODO: Merge this with above
834+
package-x86_64-linux-cxx11-abi:
835+
parameters:
836+
enabled:
837+
type: boolean
838+
default: false
839+
torch-build:
840+
type: string
841+
torch-build-index:
842+
type: string
843+
machine:
844+
image: ubuntu-2004-cuda-11.4:202110-01
845+
resource_class: xlarge
846+
steps:
847+
- when:
848+
condition: << parameters.enabled >>
849+
steps:
850+
- checkout
813851
- create-env:
814852
os: "ubuntu2004"
815853
platform: "x86_64"
816854
cudnn-version: << pipeline.parameters.cudnn-version >>
817855
trt-version-short: << pipeline.parameters.trt-version-short >>
818856
bazel-version: << pipeline.parameters.bazel-version >>
819857
bazel-platform: "x86_64"
858+
- install-torch-from-index:
859+
torch-build: << parameters.torch-build >>
860+
torch-build-index: << parameters.torch-build-index >>
820861
- run:
821862
name: Build cxx11-abi tarball
822863
command: |
@@ -825,13 +866,16 @@ jobs:
825866
cp ~/project/toolchains/ci_workspaces/WORKSPACE.x86_64.release.ubuntu ~/project/WORKSPACE
826867
bazel build //:libtorchtrt -c opt --noshow_progress
827868
sudo chown -R $(whoami) ~/project/py
828-
CUDA_VERSION=$(cd ~/project/py/torch_tensorrt && python3 -c "from _version import __cuda_version__;print(__cuda_version__)")
829-
TORCHTRT_VERSION=$(cd ~/project/py/torch_tensorrt && python3 -c "from _version import __version__;print(__version__)")
830-
TRT_VERSION=$(cd ~/project/py/torch_tensorrt && python3 -c "from _version import __tensorrt_version__;print(__tensorrt_version__)")
831-
CUDNN_VERSION=$(cd ~/project/py/torch_tensorrt && python3 -c "from _version import __cudnn_version__;print(__cudnn_version__)")
869+
cd ~/project/py
870+
CUDA_VERSION=$(python3 -c "from versions import __cuda_version__;print(__cuda_version__)")
871+
TORCHTRT_VERSION=$(python3 -c "from versions import __version__;print(__version__)")
872+
TRT_VERSION=$(python3 -c "from versions import __tensorrt_version__;print(__tensorrt_version__)")
873+
CUDNN_VERSION=$(python3 -c "from versions import __cudnn_version__;print(__cudnn_version__)")
874+
TORCH_VERSION=$(python3 -c "from torch import __version__;print(__version__.split('+')[0])")
832875
pip3 install --upgrade pip
833876
pip3 install -r ~/project/py/requirements.txt
834877
TORCH_VERSION=$(python3 -c "from torch import __version__;print(__version__.split('+')[0])")
878+
mkdir -p ~/project/py/dist/
835879
cp ~/project/bazel-bin/libtorchtrt.tar.gz ~/project/py/dist/libtorchtrt-${TORCHTRT_VERSION}-cudnn${CUDNN_VERSION}-tensorrt${TRT_VERSION}-cuda${CUDA_VERSION}-libtorch${TORCH_VERSION}-x86_64-linux.tar.gz
836880
- run:
837881
name: Collect packages
@@ -1026,7 +1070,7 @@ parameters:
10261070
# Nightly platform config
10271071
torch-build:
10281072
type: string
1029-
default: "2.0.0.dev20230129+cu117"
1073+
default: "2.0.0.dev20230219+cu117"
10301074
torch-build-index:
10311075
type: string
10321076
default: "https://download.pytorch.org/whl/nightly/cu117"
@@ -1113,7 +1157,13 @@ workflows:
11131157
when: << pipeline.parameters.enable-packaging >>
11141158
jobs:
11151159

1116-
- build-x86_64-linux:
1160+
- package-x86_64-linux:
1161+
enabled: << pipeline.parameters.enable-packaging >>
1162+
torch-build: << pipeline.parameters.torch-build >>
1163+
torch-build-index: << pipeline.parameters.torch-build-index >>
1164+
1165+
- package-x86_64-linux-cxx11-abi:
1166+
enabled: << pipeline.parameters.enable-packaging >>
11171167
torch-build: << pipeline.parameters.torch-build >>
11181168
torch-build-index: << pipeline.parameters.torch-build-index >>
11191169

@@ -1124,31 +1174,21 @@ workflows:
11241174
trt-version-long: << pipeline.parameters.trt-version-long >>
11251175
cudnn-version: << pipeline.parameters.cudnn-version >>
11261176
requires:
1127-
- build-x86_64-linux
1177+
- package-x86_64-linux
11281178

11291179
- test-py-ts-x86_64-linux:
11301180
torch-build: << pipeline.parameters.torch-build >>
11311181
torch-build-index: << pipeline.parameters.torch-build-index >>
11321182
trt-version-long: << pipeline.parameters.trt-version-long >>
11331183
requires:
1134-
- build-x86_64-linux
1184+
- package-x86_64-linux
11351185

11361186
- test-py-fx-x86_64-linux:
11371187
torch-build: << pipeline.parameters.torch-build >>
11381188
torch-build-index: << pipeline.parameters.torch-build-index >>
11391189
trt-version-long: << pipeline.parameters.trt-version-long >>
11401190
requires:
1141-
- build-x86_64-linux
1142-
1143-
1144-
- package-x86_64-linux:
1145-
enabled: << pipeline.parameters.enable-packaging >>
1146-
torch-build: << pipeline.parameters.torch-build >>
1147-
torch-build-index: << pipeline.parameters.torch-build-index >>
1148-
#requires:
1149-
#- test-core-cpp-x86_64-linux
1150-
#- test-py-ts-x86_64-linux
1151-
#- test-py-fx-x86_64-linux
1191+
- package-x86_64-linux
11521192

11531193
on-push:
11541194
jobs:

WORKSPACE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ new_local_repository(
5656
http_archive(
5757
name = "libtorch",
5858
build_file = "@//third_party/libtorch:BUILD",
59-
sha256 = "59b8b5e1954a86d50b79c13f06398d385b200da13e37a08ecf31d3c62e5ca127",
59+
sha256 = "8b3b48615169c83c1b643c0efade078ea080b1da598e15fcf01bc59421f3095e",
6060
strip_prefix = "libtorch",
61-
urls = ["https://download.pytorch.org/libtorch/nightly/cu117/libtorch-cxx11-abi-shared-with-deps-2.0.0.dev20230103%2Bcu117.zip"],
61+
urls = ["https://download.pytorch.org/libtorch/nightly/cu117/libtorch-cxx11-abi-shared-with-deps-2.0.0.dev20230219%2Bcu117.zip"],
6262
)
6363

6464
http_archive(
6565
name = "libtorch_pre_cxx11_abi",
6666
build_file = "@//third_party/libtorch:BUILD",
67-
sha256 = "e260fc7476be89d1650953e8643e9f7363845f5a52de4bab87ac0e619c1f6ad4",
67+
sha256 = "aa7fd06079d260ff83c344d043fb84fbd9cf831cf375ed8b5a1b62416817af31",
6868
strip_prefix = "libtorch",
69-
urls = ["https://download.pytorch.org/libtorch/nightly/cu117/libtorch-shared-with-deps-2.0.0.dev20230103%2Bcu117.zip"],
69+
urls = ["https://download.pytorch.org/libtorch/nightly/cu117/libtorch-shared-with-deps-2.0.0.dev20230219%2Bcu117.zip"],
7070
)
7171

7272
# Download these tarballs manually from the NVIDIA website

core/conversion/converters/impl/batch_norm.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,28 @@ void _batch_norm(
2020
const torch::Tensor& mean,
2121
const torch::Tensor& var,
2222
const float eps) {
23-
auto scale = gamma / torch::sqrt(var + eps);
24-
auto bias = beta - mean * scale;
23+
auto orig_dtype = var.dtype();
24+
// perform compile-time weight calculations in float to improve accuracy
25+
// resulting weights will be embedded as the original dtype
26+
auto calculation_gamma = gamma;
27+
auto calculation_beta = beta;
28+
auto calculation_mean = mean;
29+
auto calculation_var = var;
30+
if (orig_dtype == torch::kHalf) {
31+
calculation_gamma = calculation_gamma.to(torch::kFloat);
32+
calculation_beta = calculation_beta.to(torch::kFloat);
33+
calculation_mean = calculation_mean.to(torch::kFloat);
34+
calculation_var = calculation_var.to(torch::kFloat);
35+
}
36+
auto scale = calculation_gamma / torch::sqrt(calculation_var + eps);
37+
auto bias = calculation_beta - calculation_mean * scale;
2538
LOG_DEBUG("_batch_norm Tensor Scale : " << scale.sizes());
2639
LOG_DEBUG("_batch_norm Tensor bias : " << bias.sizes());
2740

28-
auto scale_weights = Weights(ctx, scale);
29-
auto bias_weights = Weights(ctx, bias);
41+
auto scale_weights = Weights(ctx, scale.to(orig_dtype));
42+
auto bias_weights = Weights(ctx, bias.to(orig_dtype));
3043

31-
auto power = Weights(ctx, at::ones_like(scale));
44+
auto power = Weights(ctx, at::ones_like(scale).to(orig_dtype));
3245
auto bn =
3346
ctx->net->addScaleNd(*input, nvinfer1::ScaleMode::kCHANNEL, bias_weights.data, scale_weights.data, power.data, 1);
3447
bn->setName(util::node_info(n).c_str());

core/conversion/converters/impl/select.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,29 @@ auto select_registrations TORCHTRT_UNUSED =
180180
return true;
181181
}})
182182
.pattern(
183+
{"aten::index_select(Tensor self, int dim, Tensor index) -> Tensor",
184+
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
185+
auto in = args[0].ITensorOrFreeze(ctx);
186+
auto maxDim = static_cast<int64_t>(in->getDimensions().nbDims);
187+
auto dim = args[1].unwrapToInt();
188+
// Handle negative axis by refering to nbDims of input Tensor
189+
dim = dim < 0 ? dim + maxDim : dim;
190+
auto index = args[2].ITensorOrFreeze(ctx);
191+
192+
LOG_DEBUG("Gather input dimensions: " << in->getDimensions());
193+
LOG_DEBUG("Dimension to select: " << dim);
194+
LOG_DEBUG("Index dimensions: " << index->getDimensions());
195+
196+
auto gather_layer = ctx->net->addGather(*in, *index, dim);
197+
TORCHTRT_CHECK(gather_layer, "Unable to create gather layer from node: " << *n);
198+
auto out = gather_layer->getOutput(0);
199+
LOG_DEBUG("Gather tensor shape: " << out->getDimensions());
200+
201+
out = ctx->AssociateValueAndTensor(n->outputs()[0], out);
202+
LOG_DEBUG("Output tensor shape: " << out->getDimensions());
203+
return true;
204+
}})
205+
.pattern(
183206
{"aten::narrow(Tensor(a) self, int dim, int start, int length) -> Tensor(a)",
184207
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
185208
auto in = args[0].ITensor();

core/conversion/converters/impl/unary.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ auto reciprocal_registration TORCHTRT_UNUSED = RegisterNodeConversionPatterns().
3434
return true;
3535
}});
3636

37+
auto logical_not_registration TORCHTRT_UNUSED = RegisterNodeConversionPatterns().pattern(
38+
{"aten::logical_not(Tensor self) -> Tensor", [](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
39+
auto in = args[0].ITensorOrFreeze(ctx);
40+
if (in->getType() != nvinfer1::DataType::kBOOL) {
41+
// unary not layer only supports bool inputs
42+
in = castITensor(ctx, in, nvinfer1::DataType::kBOOL, util::node_info(n).c_str());
43+
}
44+
auto unary_layer = ctx->net->addUnary(*in, nvinfer1::UnaryOperation::kNOT);
45+
TORCHTRT_CHECK(unary_layer, "Unable to create logical_not layer from node: " << *n);
46+
unary_layer->setName(util::node_info(n).c_str());
47+
auto out_tensor = ctx->AssociateValueAndTensor(n->outputs()[0], unary_layer->getOutput(0));
48+
LOG_DEBUG("Output tensor shape: " << out_tensor->getDimensions());
49+
return true;
50+
}});
51+
3752
#define convert(unary, trt_type) \
3853
auto unary##_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns().pattern( \
3954
{"aten::" #unary "(Tensor self) -> Tensor", \

core/conversion/converters/impl/unsqueeze.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ auto unsqueeze_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns().
3232

3333
auto shuffle_layer = ctx->net->addShuffle(*self);
3434
TORCHTRT_CHECK(shuffle_layer, "Unable to create shuffle layer from node: " << *n);
35-
shuffle_layer->setReshapeDimensions(util::unsqueezeDims(self->getDimensions(), dim));
35+
shuffle_layer->setReshapeDimensions(util::unsqueezeDims(self->getDimensions(), dim, 1, false));
3636

3737
auto out = ctx->AssociateValueAndTensor(n->outputs()[0], shuffle_layer->getOutput(0));
3838

cpp/src/compile_spec.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ CompileSpec::CompileSpec(torch::jit::IValue input_signature) {
3636
graph_inputs.input_signature = input_signature;
3737
}
3838

39-
void to_internal_input_signature(torch::jit::IValue input_ivalue, torch::jit::IValue& converted_ivalue) {
39+
void to_internal_input_signature(torch::jit::IValue input_ivalue, torch::jit::IValue& converted_ivalue, int depth = 0) {
40+
TORCHTRT_CHECK(
41+
depth <= 2, "Input nesting depth exceeds max supported depth, use 1 level: [A, B], or 2 level: [A, (B, C)]")
4042
if (input_ivalue.isTuple()) {
4143
auto input_tuple = input_ivalue.toTuple();
4244
std::vector<torch::jit::IValue> converted_elements;
4345
for (auto item : input_tuple->elements()) {
4446
torch::jit::IValue converted_item;
45-
to_internal_input_signature(item, converted_item);
47+
to_internal_input_signature(item, converted_item, depth++);
4648
converted_elements.push_back(converted_item);
4749
auto tuple_ptr = c10::ivalue::Tuple::create(converted_elements);
4850
converted_ivalue = torch::jit::IValue(tuple_ptr);
@@ -53,7 +55,7 @@ void to_internal_input_signature(torch::jit::IValue input_ivalue, torch::jit::IV
5355
auto converted_elements = c10::impl::GenericList(type);
5456
for (auto item : input_list) {
5557
torch::jit::IValue converted_item;
56-
to_internal_input_signature(item, converted_item);
58+
to_internal_input_signature(item, converted_item, depth++);
5759
converted_elements.push_back(converted_item);
5860
}
5961
converted_ivalue = torch::jit::IValue(converted_elements);

docs/_cpp_api/classtorch__tensorrt_1_1DataType.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1212

13-
<title>Class DataType &mdash; Torch-TensorRT v1.4.0dev0+3d59933 documentation</title>
13+
<title>Class DataType &mdash; Torch-TensorRT v1.4.0.dev0+b388010 documentation</title>
1414

1515

1616

@@ -215,7 +215,7 @@
215215

216216

217217
<div class="version">
218-
v1.4.0dev0+3d59933
218+
v1.4.0.dev0+b388010
219219
</div>
220220

221221

docs/_cpp_api/classtorch__tensorrt_1_1Device_1_1DeviceType.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1212

13-
<title>Class Device::DeviceType &mdash; Torch-TensorRT v1.4.0dev0+3d59933 documentation</title>
13+
<title>Class Device::DeviceType &mdash; Torch-TensorRT v1.4.0.dev0+b388010 documentation</title>
1414

1515

1616

@@ -215,7 +215,7 @@
215215

216216

217217
<div class="version">
218-
v1.4.0dev0+3d59933
218+
v1.4.0.dev0+b388010
219219
</div>
220220

221221

docs/_cpp_api/classtorch__tensorrt_1_1TensorFormat.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1212

13-
<title>Class TensorFormat &mdash; Torch-TensorRT v1.4.0dev0+3d59933 documentation</title>
13+
<title>Class TensorFormat &mdash; Torch-TensorRT v1.4.0.dev0+b388010 documentation</title>
1414

1515

1616

@@ -215,7 +215,7 @@
215215

216216

217217
<div class="version">
218-
v1.4.0dev0+3d59933
218+
v1.4.0.dev0+b388010
219219
</div>
220220

221221

0 commit comments

Comments
 (0)