Skip to content

Commit fff1b80

Browse files
committed
chore: Upgrade to TRT 10.0
chore: updates to trt api chore: trt 10 fixes chore: more fixes
1 parent 4ae6ab9 commit fff1b80

File tree

20 files changed

+205
-182
lines changed

20 files changed

+205
-182
lines changed

core/conversion/converters/impl/constant_pad.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ auto constant_pad_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns
5555
util::toDims(c10::IntArrayRef(stride)));
5656
TORCHTRT_CHECK(slice_layer, "Unable to create slice layer from node: " << *n);
5757
slice_layer->setName((util::node_info(n) + "_slice").c_str());
58-
slice_layer->setMode(nvinfer1::SliceMode::kFILL);
58+
slice_layer->setMode(nvinfer1::SampleMode::kFILL);
5959
slice_layer->setInput(4, *value_itensor);
6060

6161
if (ctx->input_is_dynamic) {

core/conversion/converters/impl/conv_deconv.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ nvinfer1::ILayer* add_bias_layer(
6161
auto* sliceLayer = ctx->net->addSlice(*input_tensor, dummy, dummy, stride);
6262
sliceLayer->setInput(1, *start);
6363
sliceLayer->setInput(2, *size);
64-
sliceLayer->setMode(nvinfer1::SliceMode::kFILL);
64+
sliceLayer->setMode(nvinfer1::SampleMode::kFILL);
6565
nvinfer1::ITensor* slice_output = sliceLayer->getOutput(0);
6666

6767
nvinfer1::Dims constantDims;
@@ -194,7 +194,7 @@ bool add_conv_deconv(ConversionCtx* ctx, const torch::jit::Node* n, args& args)
194194
nvinfer1::IConvolutionLayer* convLayer =
195195
ctx->net->addConvolutionNd(*in, num_output_maps, filter_dim, kernel_weights, bias.data);
196196
convLayer->setStrideNd(stride);
197-
convLayer->setPaddingMode(nvinfer1::PaddingMode::kCAFFE_ROUND_DOWN);
197+
convLayer->setPaddingMode(nvinfer1::PaddingMode::kEXPLICIT_ROUND_DOWN);
198198
convLayer->setPaddingNd(padding);
199199
convLayer->setPostPadding(out_padding);
200200
convLayer->setDilationNd(dilation);
@@ -293,7 +293,7 @@ bool add_conv_deconv(ConversionCtx* ctx, const torch::jit::Node* n, args& args)
293293
TORCHTRT_CHECK(conv, "Unable to create convolution layer from node: " << *n);
294294

295295
conv->setStrideNd(stride);
296-
conv->setPaddingMode(nvinfer1::PaddingMode::kCAFFE_ROUND_DOWN);
296+
conv->setPaddingMode(nvinfer1::PaddingMode::kEXPLICIT_ROUND_DOWN);
297297
conv->setPaddingNd(padding);
298298
conv->setPostPadding(out_padding);
299299
conv->setDilationNd(dilation);

core/conversion/converters/impl/interpolate.cpp

+25-25
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void resize_layer_size(
7272
nvinfer1::ITensor* in,
7373
std::vector<int64_t> out_shape,
7474
std::vector<float> scales,
75-
nvinfer1::ResizeMode mode,
75+
nvinfer1::InterpolationMode mode,
7676
bool align_corners = false) {
7777
TORCHTRT_CHECK((out_shape.size() > 0) ^ (scales.size() > 0), "only one of out_shape or scales should be defined");
7878
auto resize_layer = ctx->net->addResize(*in);
@@ -141,7 +141,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
141141
float scale = args[2].IValue()->toDouble();
142142
std::vector<float> padded_scales(in_shape.size(), 1);
143143
padded_scales[padded_scales.size() - 1] = scale;
144-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kNEAREST);
144+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kNEAREST);
145145
} else {
146146
// Case 2: user uses output size
147147
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -150,7 +150,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
150150

151151
auto out_shape = in_shape;
152152
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
153-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kNEAREST);
153+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kNEAREST);
154154
}
155155

156156
return true;
@@ -172,7 +172,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
172172
float scale = scale_factors[0];
173173
std::vector<float> padded_scales(in_shape.size(), 1);
174174
padded_scales[padded_scales.size() - 1] = scale;
175-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kNEAREST);
175+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kNEAREST);
176176
} else {
177177
// Case 2: user uses output size
178178
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -181,7 +181,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
181181

182182
auto out_shape = in_shape;
183183
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
184-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kNEAREST);
184+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kNEAREST);
185185
}
186186

187187
return true;
@@ -203,7 +203,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
203203
std::vector<float> padded_scales(in_shape.size(), 1);
204204
padded_scales[padded_scales.size() - 2] = scale_h;
205205
padded_scales[padded_scales.size() - 1] = scale_w;
206-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kNEAREST);
206+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kNEAREST);
207207
} else {
208208
// Case 2: user uses output size
209209
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -212,7 +212,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
212212

213213
auto out_shape = in_shape;
214214
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
215-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kNEAREST);
215+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kNEAREST);
216216
}
217217

218218
return true;
@@ -236,7 +236,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
236236
std::vector<float> padded_scales(in_shape.size(), 1);
237237
padded_scales[padded_scales.size() - 2] = scale_h;
238238
padded_scales[padded_scales.size() - 1] = scale_w;
239-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kNEAREST);
239+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kNEAREST);
240240
} else {
241241
// Case 2: user uses output size
242242
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -245,7 +245,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
245245

246246
auto out_shape = in_shape;
247247
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
248-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kNEAREST);
248+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kNEAREST);
249249
}
250250

251251
return true;
@@ -270,7 +270,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
270270
padded_scales[padded_scales.size() - 3] = scale_d;
271271
padded_scales[padded_scales.size() - 2] = scale_h;
272272
padded_scales[padded_scales.size() - 1] = scale_w;
273-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kNEAREST);
273+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kNEAREST);
274274
} else {
275275
// Case 2: user uses output size
276276
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -279,7 +279,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
279279

280280
auto out_shape = in_shape;
281281
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
282-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kNEAREST);
282+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kNEAREST);
283283
}
284284

285285
return true;
@@ -306,7 +306,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
306306
padded_scales[padded_scales.size() - 3] = scale_d;
307307
padded_scales[padded_scales.size() - 2] = scale_h;
308308
padded_scales[padded_scales.size() - 1] = scale_w;
309-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kNEAREST);
309+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kNEAREST);
310310
} else {
311311
// Case 2: user uses output size
312312
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -315,7 +315,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
315315

316316
auto out_shape = in_shape;
317317
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
318-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kNEAREST);
318+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kNEAREST);
319319
}
320320

321321
return true;
@@ -336,7 +336,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
336336
float scale = args[3].IValue()->toDouble();
337337
std::vector<float> padded_scales(in_shape.size(), 1);
338338
padded_scales[padded_scales.size() - 1] = scale;
339-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
339+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kLINEAR, align_corners);
340340
} else {
341341
// Case 2: user uses output size
342342
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -345,7 +345,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
345345

346346
auto out_shape = in_shape;
347347
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
348-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
348+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kLINEAR, align_corners);
349349
}
350350

351351
return true;
@@ -368,7 +368,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
368368
float scale = scale_factors[0];
369369
std::vector<float> padded_scales(in_shape.size(), 1);
370370
padded_scales[padded_scales.size() - 1] = scale;
371-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
371+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kLINEAR, align_corners);
372372
} else {
373373
// Case 2: user uses output size
374374
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -377,7 +377,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
377377

378378
auto out_shape = in_shape;
379379
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
380-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
380+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kLINEAR, align_corners);
381381
}
382382

383383
return true;
@@ -400,7 +400,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
400400
std::vector<float> padded_scales(in_shape.size(), 1);
401401
padded_scales[padded_scales.size() - 2] = scale_h;
402402
padded_scales[padded_scales.size() - 1] = scale_w;
403-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
403+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kLINEAR, align_corners);
404404
} else {
405405
// Case 2: user uses output size
406406
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -410,7 +410,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
410410

411411
auto out_shape = in_shape;
412412
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
413-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
413+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kLINEAR, align_corners);
414414
}
415415

416416
return true;
@@ -435,7 +435,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
435435
std::vector<float> padded_scales(in_shape.size(), 1);
436436
padded_scales[padded_scales.size() - 2] = scale_h;
437437
padded_scales[padded_scales.size() - 1] = scale_w;
438-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
438+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kLINEAR, align_corners);
439439
} else {
440440
// Case 2: user uses output size
441441
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -445,7 +445,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
445445

446446
auto out_shape = in_shape;
447447
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
448-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
448+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kLINEAR, align_corners);
449449
}
450450

451451
return true;
@@ -470,7 +470,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
470470
padded_scales[padded_scales.size() - 3] = scale_d;
471471
padded_scales[padded_scales.size() - 2] = scale_h;
472472
padded_scales[padded_scales.size() - 1] = scale_w;
473-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
473+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kLINEAR, align_corners);
474474
} else {
475475
// Case 2: user uses output size
476476
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -480,7 +480,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
480480

481481
auto out_shape = in_shape;
482482
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
483-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
483+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kLINEAR, align_corners);
484484
}
485485

486486
return true;
@@ -507,7 +507,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
507507
padded_scales[padded_scales.size() - 3] = scale_d;
508508
padded_scales[padded_scales.size() - 2] = scale_h;
509509
padded_scales[padded_scales.size() - 1] = scale_w;
510-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
510+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::InterpolationMode::kLINEAR, align_corners);
511511
} else {
512512
// Case 2: user uses output size
513513
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -517,7 +517,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
517517

518518
auto out_shape = in_shape;
519519
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
520-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
520+
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::InterpolationMode::kLINEAR, align_corners);
521521
}
522522

523523
return true;

core/conversion/converters/impl/linear.cpp

+17-13
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,26 @@ auto linear_registrations TORCHTRT_UNUSED = RegisterNodeConversionPatterns().pat
4040
in = in_shuffle->getOutput(0);
4141
}
4242

43-
auto w_tensor = args[1].IValue()->toTensor();
44-
Weights w = Weights(ctx, w_tensor);
43+
// Convert w_tensor to ITensor
44+
auto weight = args[1].IValue()->toTensor();
45+
auto weight_tensor = tensor_to_const(ctx, weight, util::node_info(n) + "_weight");
46+
auto mm_layer = ctx->net->addMatrixMultiply(
47+
*in, nvinfer1::MatrixOperation::kNONE, *weight_tensor, nvinfer1::MatrixOperation::kNONE);
4548

46-
nvinfer1::ILayer* new_layer;
47-
if (!args[2].IValue()->isNone()) {
48-
Weights b(ctx, args[2].IValue()->toTensor());
49-
new_layer = ctx->net->addFullyConnected(*in, w.num_output_maps, w.data, b.data);
50-
} else {
51-
LOG_DEBUG("There is no bias for the linear layer");
52-
new_layer = ctx->net->addFullyConnected(*in, w.num_output_maps, w.data, Weights().data);
53-
}
49+
TORCHTRT_CHECK(mm_layer, "Unable to create linear layer from node: " << *n);
50+
mm_layer->setName(util::node_info(n).c_str());
5451

55-
TORCHTRT_CHECK(new_layer, "Unable to create linear layer from node: " << *n);
52+
auto mm_output = mm_layer->getOutput(0);
5653

57-
new_layer->setName(util::node_info(n).c_str());
58-
auto out_tensor = ctx->AssociateValueAndTensor(n->outputs()[0], new_layer->getOutput(0));
54+
if (!args[2].IValue()->isNone()) {
55+
// Convert bias to ITensor
56+
auto bias = args[2].IValue()->toTensor();
57+
auto bias_tensor = tensor_to_const(ctx, bias, util::node_info(n) + "_bias");
58+
auto bias_add_layer = add_elementwise(
59+
ctx, nvinfer1::ElementWiseOperation::kSUM, mm_output, bias_tensor, util::node_info(n) + "_bias_add");
60+
mm_output = bias_add_layer->getOutput(0);
61+
}
62+
auto out_tensor = ctx->AssociateValueAndTensor(n->outputs()[0], mm_output);
5963

6064
LOG_DEBUG("Output tensor shape: " << out_tensor->getDimensions());
6165

0 commit comments

Comments
 (0)