Skip to content

Commit 5c1bf0c

Browse files
authored
Merge branch 'master' into double_long_ival
2 parents e7608c8 + b333543 commit 5c1bf0c

File tree

73 files changed

+1078
-395
lines changed

Some content is hidden

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

73 files changed

+1078
-395
lines changed

.github/workflows/docgen.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,32 @@ on:
1010

1111
jobs:
1212
build-docs:
13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-18.04
14+
container:
15+
image: docker.pkg.github.com/nvidia/trtorch/docgen:latest
16+
credentials:
17+
username: $GITHUB_ACTOR
18+
password: ${{secrets.GITHUB_TOKEN}}
1419
steps:
1520
- uses: actions/checkout@v2
1621
with:
1722
ref: ${{github.head_ref}}
18-
- name: Docker login
19-
run: docker login docker.pkg.github.com -u $GITHUB_ACTOR -p $GITHUB_TOKEN
20-
env:
21-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
22-
- name: Run image
23-
run: docker run -it -d --name builder -v $GITHUB_WORKSPACE:/workspace -w /workspace docker.pkg.github.com/nvidia/trtorch/docgen:latest
24-
- name: Build python package
25-
run: docker exec builder bash -c "cp docker/WORKSPACE.docker WORKSPACE && cd py && python3 setup.py install"
26-
- name: Generate new docs
27-
run: docker exec builder bash -c "cd docsrc && make html"
23+
- name: Get HEAD SHA
24+
id: vars
25+
run: echo "::set-output name=sha::$(git rev-parse --short HEAD)"
26+
- name: Build Python Package
27+
run: |
28+
cp docker/WORKSPACE.docs WORKSPACE
29+
cd py
30+
python3 setup.py install
31+
- name: Generate New Docs
32+
run: |
33+
cd docsrc
34+
make html
2835
- uses: stefanzweifel/git-auto-commit-action@v4
2936
with:
3037
# Required
31-
commit_message: >
32-
docs: [Automated] Regenerating documenation from ${{github.head_ref}}
38+
commit_message: "docs: [Automated] Regenerating documenation for ${{ steps.vars.outputs.sha }}"
3339
commit_options: "--no-verify --signoff"
3440
file_pattern: docs/
3541
commit_user_name: TRTorch Github Bot

.github/workflows/linter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Run image
2020
run: |
2121
docker run -it -d --name cpplinter -e GITHUB_TOKEN=$GITHUB_TOKEN -v $GITHUB_WORKSPACE:/workspace -v $GITHUB_EVENT_PATH:/GITHUB_EVENT.json -w /workspace docker.pkg.github.com/nvidia/trtorch/docgen:latest
22-
docker exec cpplinter bash -c "cp /workspace/docker/WORKSPACE.docker /workspace/WORKSPACE"
22+
docker exec cpplinter bash -c "cp /workspace/docker/WORKSPACE.docs /workspace/WORKSPACE"
2323
env:
2424
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2525
- name: Install dependencies
@@ -41,7 +41,7 @@ jobs:
4141
- name: Run image
4242
run: |
4343
docker run -it -d --name pylinter -e GITHUB_TOKEN=$GITHUB_TOKEN -v $GITHUB_WORKSPACE:/workspace -v $GITHUB_EVENT_PATH:/GITHUB_EVENT.json -w /workspace docker.pkg.github.com/nvidia/trtorch/docgen:latest
44-
docker exec pylinter bash -c "cp /workspace/docker/WORKSPACE.docker /workspace/WORKSPACE"
44+
docker exec pylinter bash -c "cp /workspace/docker/WORKSPACE.docs /workspace/WORKSPACE"
4545
env:
4646
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
4747
- name: Install dependencies

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We use the PyTorch Slack for communication about core development, integration w
1616

1717
- Use the built in linting tools to ensure that your code matches the style guidelines
1818
```sh
19-
# C++ Linting (After installing clang-format)
19+
# C++ Linting (After installing clang-format [Version 9.0.0])
2020
# Print non-conforming sections of code
2121
bazel run //tools/linter:cpplint_diff -- //...
2222
# Modify code to conform with style guidelines

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ torch.jit.save(trt_ts_module, "trt_torchscript_module.ts")
7373
### Dependencies
7474
These are the following dependencies used to verify the testcases. TRTorch can work with other versions, but the tests are not guaranteed to pass.
7575

76-
- Bazel 3.7.0
77-
- Libtorch 1.7.x (built with CUDA 11.0)
78-
- CUDA 11.0 (10.2 on Jetson)
79-
- cuDNN 8
80-
- TensorRT 7.2
76+
- Bazel 4.0.0
77+
- Libtorch 1.8.0 (built with CUDA 11.1)
78+
- CUDA 11.1 (10.2 on Jetson)
79+
- cuDNN 8.1
80+
- TensorRT 7.2.3
8181

8282
## Prebuilt Binaries and Wheel files
8383

WORKSPACE

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ git_repository(
3535
# CUDA should be installed on the system locally
3636
new_local_repository(
3737
name = "cuda",
38-
path = "/usr/local/cuda-11.0/",
38+
path = "/usr/local/cuda-11.1/",
3939
build_file = "@//third_party/cuda:BUILD",
4040
)
4141

@@ -53,16 +53,16 @@ http_archive(
5353
name = "libtorch",
5454
build_file = "@//third_party/libtorch:BUILD",
5555
strip_prefix = "libtorch",
56-
sha256 = "117f6dd65b7267839197397edd0b10fd2900b0f291e3e54b0b800caefc31bcb6",
57-
urls = ["https://download.pytorch.org/libtorch/cu110/libtorch-cxx11-abi-shared-with-deps-1.7.1%2Bcu110.zip"],
56+
sha256 = "62a2c06761c32576b30f5884240cf675b937945d929e4b13cc776de8d9c2236c",
57+
urls = ["https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.8.0%2Bcu111.zip"],
5858
)
5959

6060
http_archive(
6161
name = "libtorch_pre_cxx11_abi",
6262
build_file = "@//third_party/libtorch:BUILD",
6363
strip_prefix = "libtorch",
64-
sha256 = "c77f926afd55d7e860ec9c7abc992c25be77c89771c3ec6fcc13ea42f07d46df",
65-
urls = ["https://download.pytorch.org/libtorch/cu110/libtorch-shared-with-deps-1.7.1%2Bcu110.zip"],
64+
sha256 = "1c8b0c0883dd17f5ce952d42ec5f7f0cc7ceb370307535cee26a66c10419f1f6",
65+
urls = ["https://download.pytorch.org/libtorch/cu111/libtorch-shared-with-deps-1.8.0%2Bcu111.zip"],
6666
)
6767

6868
# Download these tarballs manually from the NVIDIA website
@@ -71,18 +71,18 @@ http_archive(
7171

7272
http_archive(
7373
name = "cudnn",
74-
urls = ["https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.0.5/11.0_20201106/cudnn-11.0-linux-x64-v8.0.5.39.tgz",],
74+
urls = ["https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.1.1.33/11.2_20210301/cudnn-11.2-linux-x64-v8.1.1.33.tgz",],
7575
build_file = "@//third_party/cudnn/archive:BUILD",
76-
sha256 = "4e16ee7895deb4a8b1c194b812ba49586ef7d26902051401d3717511898a9b73",
76+
sha256 = "98a8784e92862f20018d20c281b30d4a0cd951f93694f6433ccf4ae9c502ba6a",
7777
strip_prefix = "cuda"
7878
)
7979

8080
http_archive(
8181
name = "tensorrt",
82-
urls = ["https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.2.2/tars/TensorRT-7.2.2.3.Ubuntu-18.04.x86_64-gnu.cuda-11.0.cudnn8.0.tar.gz",],
82+
urls = ["https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.2.3/tars/TensorRT-7.2.3.4.Ubuntu-18.04.x86_64-gnu.cuda-11.1.cudnn8.1.tar.gz",],
8383
build_file = "@//third_party/tensorrt/archive:BUILD",
84-
strip_prefix = "TensorRT-7.2.2.3",
85-
sha256 = "b5c325e38e1d92ce1ce92ca8b54ede9c224bf128c9a53eb0b9022f1ee4313ee0"
84+
strip_prefix = "TensorRT-7.2.3.4",
85+
sha256 = "d3a1f478e304b48878604fac70ce7920fece71f9cac62f925c9c59c197f5d087"
8686
)
8787

8888
####################################################################################

core/conversion/converters/impl/batch_norm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ auto batch_norm_registrations TRTORCH_UNUSED = RegisterNodeConversionPatterns().
4343
auto should_unpack = util::toVec(orig_shape).size() < 4;
4444
if (should_unpack) {
4545
// expand spatial dims from 1D to 2D
46-
auto new_shape = util::toDimsPad(util::toVec(orig_shape), 4);
46+
auto new_shape = util::toDimsTailPad(util::toVec(orig_shape), 4);
4747
LOG_DEBUG(
4848
"Input shape is less than 4D got: "
4949
<< orig_shape << ", inserting shuffle layer to reshape to 4D tensor shape: " << new_shape);

core/conversion/converters/impl/plugins/interpolate_plugin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ int InterpolatePlugin::enqueue(
254254
cudaStream_t stream) {
255255
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1)
256256
at::Tensor input = at::from_blob((void*)inputs[0], util::toVec(inputDesc->dims), [](void*) {}, tensor_options_);
257-
at::Tensor output = at::from_blob(outputs[0], util::volume(outputDesc->dims), [](void*) {}, tensor_options_);
257+
at::Tensor output = at::from_blob(
258+
outputs[0], util::volume(outputDesc->dims), [](void*) {}, tensor_options_);
258259

259260
at::cuda::CUDAStream torch_stream = at::cuda::getStreamFromPool();
260261
at::cuda::CUDAStreamGuard torch_guard(torch_stream);

core/conversion/converters/impl/select.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool add_split(ConversionCtx* ctx, const torch::jit::Node* n, args& args, bool s
1818
auto in = args[0].ITensor();
1919
auto axis = args[2].unwrapToInt();
2020
auto inDimSize = in->getDimensions().d[axis];
21-
auto numOutputs = 1;
21+
auto numOutputs = 1, numRemainder = 0;
2222
std::vector<int64_t> sizes;
2323

2424
if (split_list) {
@@ -27,10 +27,13 @@ bool add_split(ConversionCtx* ctx, const torch::jit::Node* n, args& args, bool s
2727
} else {
2828
auto split_size = args[1].unwrapToInt();
2929
numOutputs = inDimSize / split_size;
30-
if (numOutputs == 1) {
30+
numRemainder = inDimSize % split_size;
31+
for (int64_t i = 0; i < numOutputs; i++) {
3132
sizes.push_back(split_size);
32-
} else {
33-
sizes = std::vector<int64_t>(numOutputs, 1);
33+
}
34+
if (numRemainder) {
35+
numOutputs += 1;
36+
sizes.push_back(numRemainder);
3437
}
3538
}
3639

@@ -42,7 +45,7 @@ bool add_split(ConversionCtx* ctx, const torch::jit::Node* n, args& args, bool s
4245
list.reserve(numOutputs);
4346

4447
int start_idx = 0;
45-
for (int i = 0; i < numOutputs; i++) {
48+
for (int64_t i = 0; i < numOutputs; i++) {
4649
at::Tensor indices = torch::arange(start_idx, start_idx + sizes[i], 1).to(torch::kI32);
4750
auto indicesTensor = tensor_to_const(ctx, indices);
4851

@@ -68,7 +71,9 @@ auto select_registrations TRTORCH_UNUSED =
6871
.pattern({"aten::select.int(Tensor(a) self, int dim, int index) -> (Tensor(a))",
6972
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
7073
auto in = args[0].ITensor();
74+
auto maxDim = static_cast<int64_t>(in->getDimensions().nbDims);
7175
auto axis = args[1].unwrapToInt();
76+
axis = axis < 0 ? axis + maxDim : axis;
7277
auto ind = (int32_t)args[2].unwrapToInt();
7378

7479
// index to access needs to be an at::Tensor
@@ -89,7 +94,7 @@ auto select_registrations TRTORCH_UNUSED =
8994
// IShuffleLayer removes redundant dimensions
9095
auto shuffle_layer = ctx->net->addShuffle(*gather_out);
9196
TRTORCH_CHECK(shuffle_layer, "Unable to create shuffle layer from node: " << *n);
92-
shuffle_layer->setReshapeDimensions(util::unpadDims(gather_out->getDimensions()));
97+
shuffle_layer->setReshapeDimensions(util::squeezeDims(gather_out->getDimensions(), axis));
9398
shuffle_layer->setName(util::node_info(n).c_str());
9499
auto shuffle_out = shuffle_layer->getOutput(0);
95100

@@ -174,9 +179,11 @@ auto select_registrations TRTORCH_UNUSED =
174179
{"aten::embedding(Tensor weight, Tensor indices, int padding_idx=-1, bool scale_grad_by_freq=False, bool sparse=False) -> (Tensor)",
175180
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
176181
auto embeddingTensor = args[0].ITensorOrFreeze(ctx);
177-
auto indicesTensor = args[1].ITensor();
182+
auto indicesTensor = args[1].ITensorOrFreeze(ctx);
178183
// Set datatype for indices tensor to INT32
179-
indicesTensor->setType(nvinfer1::DataType::kINT32);
184+
auto identity = ctx->net->addIdentity(*indicesTensor);
185+
identity->setOutputType(0, nvinfer1::DataType::kINT32);
186+
indicesTensor = identity->getOutput(0);
180187

181188
// IGatherLayer takes in input tensor, the indices, and the axis of input tensor to take indices from
182189
auto gather_layer = ctx->net->addGather(*embeddingTensor, *indicesTensor, 0);

core/conversion/converters/impl/unsqueeze.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ auto unsqueeze_registrations TRTORCH_UNUSED = RegisterNodeConversionPatterns().p
2121
auto dim = args[1].unwrapToInt();
2222

2323
auto selfDim = util::toVec(self->getDimensions());
24+
int64_t nbDims = selfDim.size();
25+
TRTORCH_CHECK(
26+
dim <= nbDims && dim >= -(nbDims + 1),
27+
"Dimension out of range (expected to be in range of [" << -(nbDims + 1) << ", " << nbDims << "], but got "
28+
<< dim << ")");
2429
if (dim < 0) {
25-
dim = selfDim.size() + dim;
30+
dim = nbDims + 1 + dim;
2631
}
2732

2833
auto shuffle_layer = ctx->net->addShuffle(*self);

core/conversion/evaluators/aten.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,20 @@ auto aten_registrations TRTORCH_UNUSED =
396396
EvalOptions().validSchemas({
397397
"aten::numel(Tensor self) -> int",
398398
})})
399+
.evaluator({c10::Symbol::fromQualString("aten::t"),
400+
[](const torch::jit::Node* n, kwargs& args) -> c10::optional<torch::jit::IValue> {
401+
auto tensor_var = args.at(n->input(0));
402+
if (tensor_var.IValue()->isTensor()) {
403+
auto tensor = tensor_var.unwrapToTensor();
404+
return tensor.t();
405+
} else {
406+
TRTORCH_THROW_ERROR("Unimplemented data type for aten::t evaluator: ITensor");
407+
return {};
408+
}
409+
},
410+
EvalOptions().validSchemas({
411+
"aten::t(Tensor self) -> Tensor",
412+
})})
399413
.evaluator({c10::Symbol::fromQualString("aten::dim"),
400414
[](const torch::jit::Node* n, kwargs& args) -> c10::optional<torch::jit::IValue> {
401415
auto tensor_var = args.at(n->input(0));
@@ -467,7 +481,61 @@ auto aten_registrations TRTORCH_UNUSED =
467481
LOG_WARNING("Warning from TorchScript: " << *warning);
468482
return {};
469483
},
470-
EvalOptions()});
484+
EvalOptions()})
485+
.evaluator({c10::Symbol::fromQualString("aten::arange"),
486+
[](const torch::jit::Node* n, kwargs& args) -> c10::optional<torch::jit::IValue> {
487+
int input_size = n->inputs().size();
488+
int scalar_count = 0;
489+
for (int i = 0; i < input_size; i++) {
490+
if (args.at(n->input(i)).IValue()->isScalar()) {
491+
scalar_count += 1;
492+
}
493+
}
494+
if (scalar_count == 1) {
495+
if (args.at(n->input(0)).IValue()->isInt()) {
496+
int end_scalar = args.at(n->input(0)).unwrapToInt();
497+
return torch::arange(end_scalar);
498+
} else if (args.at(n->input(0)).IValue()->isDouble()) {
499+
float end_scalar = args.at(n->input(0)).unwrapToScalar().to<float>();
500+
return torch::arange(end_scalar);
501+
}
502+
} else if (scalar_count == 2) {
503+
if (args.at(n->input(0)).IValue()->isDouble() || args.at(n->input(1)).IValue()->isDouble()) {
504+
float start_scalar = args.at(n->input(0)).unwrapToScalar().to<float>();
505+
float end_scalar = args.at(n->input(1)).unwrapToScalar().to<float>();
506+
return torch::arange(start_scalar, end_scalar);
507+
} else {
508+
int start_scalar = args.at(n->input(0)).unwrapToInt();
509+
int end_scalar = args.at(n->input(1)).unwrapToInt();
510+
return torch::arange(start_scalar, end_scalar);
511+
}
512+
} else if (scalar_count == 3) {
513+
if (args.at(n->input(0)).IValue()->isDouble() || args.at(n->input(1)).IValue()->isDouble() ||
514+
args.at(n->input(2)).IValue()->isDouble()) {
515+
float start_scalar = args.at(n->input(0)).unwrapToScalar().to<float>();
516+
float end_scalar = args.at(n->input(1)).unwrapToScalar().to<float>();
517+
float step_scalar = args.at(n->input(2)).unwrapToScalar().to<float>();
518+
return torch::arange(start_scalar, end_scalar, step_scalar);
519+
} else {
520+
int start_scalar = args.at(n->input(0)).unwrapToInt();
521+
int end_scalar = args.at(n->input(1)).unwrapToInt();
522+
int step_scalar = args.at(n->input(2)).unwrapToInt();
523+
return torch::arange(start_scalar, end_scalar, step_scalar);
524+
}
525+
} else {
526+
TRTORCH_THROW_ERROR(
527+
"Invalid input argument size for aten::arange, input argument size: " << input_size);
528+
}
529+
return {};
530+
},
531+
EvalOptions().validSchemas({
532+
R"SIG(aten::arange(Scalar end, *, int? dtype=None, int? layout=None,
533+
Device? device=None, bool? pin_memory=None) -> (Tensor))SIG",
534+
R"SIG(aten::arange.start(Scalar start, Scalar end, *, ScalarType? dtype=None,
535+
Layout? layout=None, Device? device=None, bool? pin_memory=None) -> (Tensor))SIG",
536+
R"SIG(aten::arange.start_step(Scalar start, Scalar end, Scalar step, *, ScalarType? dtype=None,
537+
Layout? layout=None, Device? device=None, bool? pin_memory=None) -> (Tensor))SIG",
538+
})});
471539
} // namespace
472540
} // namespace evaluators
473541
} // namespace conversion

0 commit comments

Comments
 (0)