Skip to content

Commit 8923872

Browse files
authored
Merge branch 'pytorch:main' into main
2 parents 0976470 + 0527edd commit 8923872

36 files changed

+1102
-99
lines changed

.github/code-owners.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
- "narendasan"
33

44
"component: api [Python]":
5-
- "narendasan"
5+
- "gs-olive"
6+
- "peri044"
67

78
"component: api":
89
- "narendasan"
@@ -11,18 +12,23 @@
1112
- "narendasan"
1213

1314
"component: conversion":
14-
- "narendasan"
15+
- "apbose"
1516
- "peri044"
1617

1718
"component: converters":
18-
- "peri044"
19-
- "bowang007"
19+
- "apbose"
20+
- "zewenli98"
2021

2122
"component: core":
2223
- "narendasan"
2324
- "peri044"
2425
- "bowang007"
2526

27+
"component: dynamo":
28+
- "narendasan"
29+
- "gs-olive"
30+
- "peri044"
31+
2632
"component: evaluators":
2733
- "narendasan"
2834
- "peri044"
@@ -32,7 +38,7 @@
3238

3339
"component: lowering":
3440
- "peri044"
35-
- "narendasan"
41+
- "gs-olive"
3642

3743
"component: partitioning":
3844
- "bowang007"
@@ -43,13 +49,18 @@
4349

4450
"component: quantization":
4551
- "peri044"
52+
- "bowang007"
4653

4754
"component: runtime":
4855
- "narendasan"
4956

5057
"component: tests":
5158
- "narendasan"
5259

60+
"component: torch_compile":
61+
- "gs-olive"
62+
- "narendasan"
63+
5364
"component: torchtrtc":
5465
- "narendasan"
5566

.github/pr-labels.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,43 @@
1212

1313
"component: conversion":
1414
- core/conversion/**/*
15-
15+
- py/torch_tensorrt/dynamo/conversion/**/*
16+
1617
"component: converters":
1718
- core/conversion/converters/**/*
19+
- py/torch_tensorrt/dynamo/conversion/impl/**/*
1820

1921
"component: evaluators":
2022
- core/conversion/evaluators/**/*
2123

2224
"component: fx":
2325
- py/torch_tensorrt/fx/**/*
2426

27+
"component: dynamo":
28+
- py/torch_tensorrt/dynamo/**/*
29+
30+
"component: torch_compile":
31+
- py/torch_tensorrt/dynamo/backend/*
32+
2533
"component: partitioning":
2634
- core/partitioning/**/*
2735

2836
"component: runtime":
2937
- core/runtime/**/*
38+
- py/torch_tensorrt/dynamo/runtime/**/*
3039

3140
"component: lowering":
3241
- core/lowering/**/*
42+
- py/torch_tensorrt/dynamo/lowering/**/*
3343

3444
"component: tests":
3545
- tests/**/*
3646

3747
"component: build system":
3848
- WORKSPACE
3949
- BUILD
50+
- pyproject.toml
51+
- setup.py
4052

4153
"documentation":
4254
- docs/**/*

.github/workflows/docgen.yml

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,75 +12,30 @@ jobs:
1212
build-docs:
1313
runs-on: ubuntu-20.04
1414
container:
15-
image: ghcr.io/pytorch/tensorrt/docgen:latest
16-
credentials:
17-
username: ${{ github.actor }}
18-
password: ${{ secrets.GITHUB_TOKEN }}
15+
image: docker.io/pytorch/manylinux-builder:cuda12.1
1916
steps:
20-
- name: Reclaim space
21-
run: |
22-
rm -rf /usr/share/dotnet
23-
rm -rf /opt/ghc
24-
rm -rf "/usr/local/share/boost"
25-
rm -rf /usr/local/cuda/cuda-*
26-
- name: Install base deps
27-
run: |
28-
apt update
29-
DEBIAN_FRONTEND=noninteractive apt install -y software-properties-common gcc git curl wget make zlib1g-dev bzip2 libbz2-dev lzma lzma-dev libreadline-dev libsqlite3-dev libssl-dev libffi-dev doxygen pandoc
30-
git config --global --add safe.directory '*'
31-
- name: Set up Python 3.10.12
32-
uses: actions/setup-python@v4
33-
with:
34-
python-version: 3.10.12
3517
- uses: actions/checkout@v3
3618
with:
3719
ref: ${{github.head_ref}}
20+
- name: Install base deps
21+
run: |
22+
./packaging/pre_build_script.sh
3823
- name: Get HEAD SHA
3924
id: vars
4025
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
4126
- name: Get Bazel version
4227
id: bazel_info
4328
run: echo "version=$(cat .bazelversion)" >> $GITHUB_OUTPUT
44-
- name: Install Bazel
45-
run: |
46-
wget -q https://github.com/bazelbuild/bazel/releases/download/${{ steps.bazel_info.outputs.version }}/bazel-${{ steps.bazel_info.outputs.version }}-linux-x86_64 -O /usr/bin/bazel
47-
chmod a+x /usr/bin/bazel
48-
- name: Install cudnn + tensorrt
49-
run: |
50-
apt-get update
51-
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
52-
mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
53-
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
54-
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 536F8F1DE80F6A35
55-
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
56-
add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
57-
apt-get update
58-
apt-get install -y libcudnn8 libcudnn8-dev
59-
60-
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
61-
add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
62-
apt-get update
63-
64-
apt-get install -y libnvinfer8 libnvinfer-plugin8 libnvinfer-dev libnvinfer-plugin-dev
65-
- name: Install Torch
66-
run: |
67-
python3 -m pip install -r py/requirements.txt --user
6829
- name: Build Python Package
6930
run: |
70-
cp toolchains/ci_workspaces/WORKSPACE.x86_64 WORKSPACE
71-
cd py
72-
python3 -m pip install pip==21.3.1
73-
echo $(which python3)
74-
echo $(python3 -c 'import site; print(site.getsitepackages()[0])')
75-
mkdir -p /opt/circleci/.pyenv/versions/3.9.4/lib/python3.9/
76-
ln -s $(python3 -c 'import site; print(site.getsitepackages()[0])') /opt/circleci/.pyenv/versions/3.9.4/lib/python3.9/site-packages
77-
python3 setup.py install
78-
cd ..
31+
cp toolchains/ci_workspaces/WORKSPACE.x86_64.cu121.release.rhel WORKSPACE
32+
python -m pip install pip<=23
33+
python -m pip install --pre -e . --extra-index-url https://download.pytorch.org/whl/nightly/cu121
7934
- name: Generate New Docs
8035
run: |
8136
cd docsrc
82-
python3 -m pip install -r requirements.txt
83-
python3 -c "import torch_tensorrt; print(torch_tensorrt.__version__)"
37+
python -m pip install -r requirements.txt
38+
python -c "import torch_tensorrt; print(torch_tensorrt.__version__)"
8439
make html
8540
cd ..
8641
- uses: stefanzweifel/git-auto-commit-action@v4

.github/workflows/docker_builder.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'Torch-TensorRT Docker Build'
2+
3+
# Apply workflow only to main branch
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- nightly
9+
10+
# If pushes to main are made in rapid succession,
11+
# cancel existing docker builds and use newer commits
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref_name }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
runs-on: linux.2xlarge
19+
20+
# Define key environment variables
21+
# Container name is of the form torch_tensorrt:<branch_name>
22+
env:
23+
DOCKER_REGISTRY: ghcr.io/pytorch/tensorrt
24+
CONTAINER_NAME: torch_tensorrt:${{ github.ref_name }}
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v2
32+
with:
33+
registry: ${{ env.DOCKER_REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
# Automatically detect TensorRT and cuDNN default versions for Torch-TRT build
38+
- name: Build Docker image
39+
env:
40+
DOCKER_TAG: ${{ env.DOCKER_REGISTRY }}/${{ env.CONTAINER_NAME }}
41+
run: |
42+
python3 -m pip install pyyaml
43+
TRT_VERSION=$(python3 -c "import versions; versions.tensorrt_version()")
44+
echo "TRT VERSION = ${TRT_VERSION}"
45+
CUDNN_VERSION=$(python3 -c "import versions; versions.cudnn_version()")
46+
echo "CUDNN VERSION = ${CUDNN_VERSION}"
47+
48+
DOCKER_BUILDKIT=1 docker build --build-arg TENSORRT_VERSION=$TRT_VERSION --build-arg CUDNN_VERSION=$CUDNN_VERSION -f docker/Dockerfile --tag $DOCKER_TAG .
49+
50+
- name: Push Docker image
51+
env:
52+
DOCKER_URL: ${{ env.DOCKER_REGISTRY }}/${{ env.CONTAINER_NAME }}
53+
run: docker push $DOCKER_URL
54+
55+
# Clean up all untagged containers in registry
56+
- name: Container Registry Cleanup
57+
uses: actions/delete-package-versions@v4
58+
with:
59+
package-name: "tensorrt/torch_tensorrt"
60+
package-type: container
61+
min-versions-to-keep: 0
62+
delete-only-untagged-versions: True

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ docsrc/_build
3232
docsrc/_notebooks
3333
docsrc/_cpp_api
3434
docsrc/_tmp
35+
docsrc/tutorials/_rendered_examples
3536
*.so
3637
__pycache__
3738
*.egg-info
@@ -67,4 +68,4 @@ bazel-tensorrt
6768
*cifar-10-batches-py*
6869
bazel-project
6970
build/
70-
wheelhouse/
71+
wheelhouse/

core/conversion/converters/impl/layer_norm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ auto layer_norm_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns()
2020

2121
/* Layer_Norm normalizes over last N dimensions.
2222
normalizaed_shape could be (C,H,W), (H,W), or (W). */
23-
auto normalized_shape = args[1].unwrapToIntList();
24-
auto normalized_shape_vec = util::toVec(util::toDims(normalized_shape));
23+
// This could be an IntList or ITensorList. We only need the size of this list.
24+
auto normalized_shape = args[1].IValue()->toList();
2525

2626
// Unwrap eps.
2727
auto eps = args[4].unwrapToDouble();
@@ -30,7 +30,7 @@ auto layer_norm_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns()
3030

3131
// Set up axis_ask for E[x].
3232
uint32_t axis_mask = 0;
33-
for (size_t i = 0; i < normalized_shape_vec.size(); i++) {
33+
for (size_t i = 0; i < normalized_shape.size(); i++) {
3434
axis_mask |= 1 << (shape.size() - i - 1);
3535
}
3636
LOG_DEBUG("Axis Mask for E[x]" << std::bitset<32>(axis_mask));

core/conversion/converters/impl/quantization.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ namespace {
1111

1212
#if NV_TENSORRT_MAJOR > 7
1313
// clang-format off
14+
15+
bool add_qdq(ConversionCtx *ctx, const torch::jit::Node* n, nvinfer1::ITensor* input, nvinfer1::ITensor* scale, std::string& opName) {
16+
nvinfer1::IQuantizeLayer* quantize_layer = ctx->net->addQuantize(*input, *scale);
17+
TORCHTRT_CHECK(quantize_layer, "Unable to create QuantizeLayer from node: " << *n);
18+
quantize_layer->setAxis(0);
19+
20+
nvinfer1::IDequantizeLayer* dequantize_layer = ctx->net->addDequantize(*quantize_layer->getOutput(0), *scale);
21+
TORCHTRT_CHECK(dequantize_layer, "Unable to create DequantizeLayer from node: " << *n);
22+
dequantize_layer->setAxis(0);
23+
24+
auto qdq_out = ctx->AssociateValueAndTensor(n->outputs()[0], dequantize_layer->getOutput(0));
25+
LOG_DEBUG("[" << opName << "]"<< " Output tensor shape: " << qdq_out->getDimensions());
26+
27+
return true;
28+
}
29+
1430
auto quantization_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns()
1531
.pattern({"aten::fake_quantize_per_tensor_affine(Tensor self, float scale, int zero_point, int quant_min, int quant_max) -> (Tensor)",
1632
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
@@ -20,18 +36,16 @@ auto quantization_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns
2036
auto scale = args[1].unwrapToScalar().to<float>();
2137
auto scaleTensor = tensor_to_const(ctx, torch::tensor({scale}));
2238
// Add and configure a QuantizeLayer.
23-
nvinfer1::IQuantizeLayer* quantize_layer = ctx->net->addQuantize(*input, *scaleTensor);
24-
quantize_layer->setAxis(0);
25-
26-
// Add and configure DequantizeLayer following a QuantizeLayer
27-
nvinfer1::IDequantizeLayer* dequantize_layer = ctx->net->addDequantize(*quantize_layer->getOutput(0), *scaleTensor);
28-
dequantize_layer->setAxis(0);
29-
30-
auto qdq_out = ctx->AssociateValueAndTensor(n->outputs()[0], dequantize_layer->getOutput(0));
31-
LOG_DEBUG("[fake_quantize_per_tensor_affine] Output tensor shape: " << qdq_out->getDimensions());
32-
33-
return true;
39+
std::string opName("aten::fake_quantize_per_tensor_affine");
40+
return add_qdq(ctx, n, input, scaleTensor, opName);
3441
}})
42+
.pattern({"aten::fake_quantize_per_tensor_affine.tensor_qparams(Tensor self, Tensor scale, Tensor zero_point, int quant_min, int quant_max) -> (Tensor)",
43+
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
44+
auto input = args[0].ITensorOrFreeze(ctx);
45+
auto scale = args[1].ITensorOrFreeze(ctx);
46+
std::string opName("aten::fake_quantize_per_tensor_affine.tensor_qparams");
47+
return add_qdq(ctx, n, input, scale, opName);
48+
}})
3549
.pattern({"aten::fake_quantize_per_channel_affine(Tensor self, Tensor scale, Tensor zero_point, int axis, int quant_min, int quant_max) -> (Tensor)",
3650
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
3751
// This aten operator is generated from torch.fake_quantize_per_channel_affine op in Pytorch python API.

core/conversion/converters/impl/select.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ auto select_registrations TORCHTRT_UNUSED =
165165
}
166166

167167
shuffle_layer->setReshapeDimensions(util::squeezeDims(
168-
out->getDimensions(),
169-
dim,
170-
ctx->input_is_dynamic,
171-
ctx->input_is_dynamic && (num_zero_dimensions > 0)));
168+
out->getDimensions(), dim, false, ctx->input_is_dynamic && (num_zero_dimensions > 0)));
172169
shuffle_layer->setName(util::node_info(n).c_str());
173170
out = shuffle_layer->getOutput(0);
174171
}
@@ -710,9 +707,8 @@ auto select_registrations TORCHTRT_UNUSED =
710707
auto val_t_dtype = util::TRTDataTypeToScalarType(self->getType());
711708

712709
// Initialize contant tensor for fill with the inherited data type
713-
auto val_t = tensor_to_const(
714-
ctx, torch::full(util::toVec(self->getDimensions()), val, {torch::dtype(val_t_dtype)}));
715-
710+
std::vector<int64_t> singleton_dims(self->getDimensions().nbDims, 1);
711+
auto val_t = tensor_to_const(ctx, torch::full(singleton_dims, val, {torch::dtype(val_t_dtype)}));
716712
TORCHTRT_CHECK(
717713
util::broadcastable(self->getDimensions(), mask->getDimensions(), /*multidirectional=*/false),
718714
"Self and mask tensors are not broadcastable");

0 commit comments

Comments
 (0)