Skip to content

Commit 32d905b

Browse files
authored
Merge pull request #2146 from zewenli98/main
abandoned create_plugin() function
2 parents c3a65ef + 8923872 commit 32d905b

File tree

1 file changed

+6
-276
lines changed

1 file changed

+6
-276
lines changed

core/conversion/converters/impl/interpolate.cpp

Lines changed: 6 additions & 276 deletions
Original file line numberDiff line numberDiff line change
@@ -336,28 +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-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
340-
if (!align_corners) {
341-
TORCHTRT_THROW_ERROR(
342-
"Unable to convert node: "
343-
<< util::node_info(n) << "\nupsample_linear1d only supports align_corner with TensorRT <= 7.0.");
344-
} else {
345-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, true);
346-
}
347-
#else
348-
TORCHTRT_CHECK(
349-
!(align_corners && ctx->input_is_dynamic),
350-
"Torch-TensorRT currently does not support the compilation of dynamic engines from code using using PyTorch [bi/tri]linear interpolation via scale factor and align_corners=True");
351-
if (align_corners) {
352-
// Align corners and scale factor behave slightly different together in TRT and PyTorch so run the
353-
// layer in ATen to maintain consistancy between Torch-TensorRT and PyTorch
354-
// https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate
355-
create_plugin(
356-
ctx, n, in, "linear1d", in_shape, {}, {}, {scale}, std::string("linear"), align_corners, true);
357-
} else {
358-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
359-
}
360-
#endif
339+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
361340
} else {
362341
// Case 2: user uses output size
363342
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -366,18 +345,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
366345

367346
auto out_shape = in_shape;
368347
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
369-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
370-
if (!align_corners) {
371-
// align_corners not supported in TensorRT, create plugin and
372-
// run layer through PyTorch
373-
create_plugin(
374-
ctx, n, in, "linear1d", in_shape, out_shape, out_size, {}, std::string("linear"), align_corners);
375-
} else {
376-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, true);
377-
}
378-
#else
379348
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
380-
#endif
381349
}
382350

383351
return true;
@@ -400,28 +368,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
400368
float scale = scale_factors[0];
401369
std::vector<float> padded_scales(in_shape.size(), 1);
402370
padded_scales[padded_scales.size() - 1] = scale;
403-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
404-
if (!align_corners) {
405-
TORCHTRT_THROW_ERROR(
406-
"Unable to convert node: "
407-
<< util::node_info(n) << "\nupsample_linear1d only supports align_corner with TensorRT <= 7.0.");
408-
} else {
409-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, true);
410-
}
411-
#else
412-
TORCHTRT_CHECK(
413-
!(align_corners && ctx->input_is_dynamic),
414-
"Torch-TensorRT currently does not support the compilation of dynamc engines from code using PyTorch [bi/tri]linear interpolation via scale factor and align_corners=True");
415-
if (align_corners) {
416-
// Align corners and scale factor behave slightly different together in TRT and PyTorch so run the
417-
// layer in ATen to maintain consistancy between Torch-TensorRT and PyTorch
418-
// https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate
419-
create_plugin(
420-
ctx, n, in, "linear1d", in_shape, {}, {}, {scale}, std::string("linear"), align_corners, true);
421-
} else {
422-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
423-
}
424-
#endif
371+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
425372
} else {
426373
// Case 2: user uses output size
427374
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -430,18 +377,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
430377

431378
auto out_shape = in_shape;
432379
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
433-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
434-
if (!align_corners) {
435-
// align_corners not supported in TensorRT, create plugin and
436-
// run layer through PyTorch
437-
create_plugin(
438-
ctx, n, in, "linear1d", in_shape, out_shape, out_size, {}, std::string("linear"), align_corners);
439-
} else {
440-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, true);
441-
}
442-
#else
443380
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
444-
#endif
445381
}
446382

447383
return true;
@@ -464,38 +400,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
464400
std::vector<float> padded_scales(in_shape.size(), 1);
465401
padded_scales[padded_scales.size() - 2] = scale_h;
466402
padded_scales[padded_scales.size() - 1] = scale_w;
467-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
468-
if (!align_corners) {
469-
TORCHTRT_THROW_ERROR(
470-
"Unable to convert node: "
471-
<< util::node_info(n) << "\nupsample_linear2d only supports align_corner with TensorRT <= 7.0.");
472-
} else {
473-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, true);
474-
}
475-
#else
476-
TORCHTRT_CHECK(
477-
!(align_corners && ctx->input_is_dynamic),
478-
"Torch-TensorRT currently does not support the compilation of dynamc engines from code using PyTorch [bi/tri]linear interpolation via scale factor and align_corners=True");
479-
if (align_corners) {
480-
// Align corners and scale factor behave slightly different together in TRT and PyTorch so run the
481-
// layer in ATen to maintain consistancy between Torch-TensorRT and PyTorch
482-
// https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate
483-
create_plugin(
484-
ctx,
485-
n,
486-
in,
487-
"bilinear2d",
488-
in_shape,
489-
{},
490-
{},
491-
{scale_h, scale_w},
492-
std::string("bilinear"),
493-
align_corners,
494-
true);
495-
} else {
496-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
497-
}
498-
#endif
403+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
499404
} else {
500405
// Case 2: user uses output size
501406
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -505,28 +410,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
505410

506411
auto out_shape = in_shape;
507412
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
508-
509-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
510-
if (!align_corners) {
511-
// align_corners not supported in TensorRT, create plugin and
512-
// run layer through PyTorch
513-
create_plugin(
514-
ctx,
515-
n,
516-
in,
517-
"bilinear2d",
518-
in_shape,
519-
out_shape,
520-
out_size,
521-
{},
522-
std::string("bilinear"),
523-
align_corners);
524-
} else {
525-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, true);
526-
}
527-
#else
528413
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
529-
#endif
530414
}
531415

532416
return true;
@@ -551,38 +435,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
551435
std::vector<float> padded_scales(in_shape.size(), 1);
552436
padded_scales[padded_scales.size() - 2] = scale_h;
553437
padded_scales[padded_scales.size() - 1] = scale_w;
554-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
555-
if (!align_corners) {
556-
TORCHTRT_THROW_ERROR(
557-
"Unable to convert node: "
558-
<< util::node_info(n) << "\nupsample_linear2d only supports align_corner with TensorRT <= 7.0.");
559-
} else {
560-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, true);
561-
}
562-
#else
563-
TORCHTRT_CHECK(
564-
!(align_corners && ctx->input_is_dynamic),
565-
"Torch-TensorRT currently does not support the compilation of dynamc engines from code using PyTorch [bi/tri]linear interpolation via scale factor and align_corners=True");
566-
if (align_corners) {
567-
// Align corners and scale factor behave slightly different together in TRT and PyTorch so run the
568-
// layer in ATen to maintain consistancy between Torch-TensorRT and PyTorch
569-
// https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate
570-
create_plugin(
571-
ctx,
572-
n,
573-
in,
574-
"bilinear2d",
575-
in_shape,
576-
{},
577-
{},
578-
scale_factors.vec(),
579-
std::string("bilinear"),
580-
align_corners,
581-
true);
582-
} else {
583-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
584-
}
585-
#endif
438+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
586439
} else {
587440
// Case 2: user uses output size
588441
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -592,28 +445,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
592445

593446
auto out_shape = in_shape;
594447
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
595-
596-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
597-
if (!align_corners) {
598-
// align_corners not supported in TensorRT, create plugin and
599-
// run layer through PyTorch
600-
create_plugin(
601-
ctx,
602-
n,
603-
in,
604-
"bilinear2d",
605-
in_shape,
606-
out_shape,
607-
out_size,
608-
{},
609-
std::string("bilinear"),
610-
align_corners);
611-
} else {
612-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, true);
613-
}
614-
#else
615448
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
616-
#endif
617449
}
618450

619451
return true;
@@ -638,38 +470,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
638470
padded_scales[padded_scales.size() - 3] = scale_d;
639471
padded_scales[padded_scales.size() - 2] = scale_h;
640472
padded_scales[padded_scales.size() - 1] = scale_w;
641-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
642-
if (!align_corners) {
643-
TORCHTRT_THROW_ERROR(
644-
"Unable to convert node: "
645-
<< util::node_info(n) << "\nupsample_linear3d only supports align_corner with TensorRT <= 7.0.");
646-
} else {
647-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, true);
648-
}
649-
#else
650-
TORCHTRT_CHECK(
651-
!(align_corners && ctx->input_is_dynamic),
652-
"Torch-TensorRT currently does not support the compilation of dynamc engines from code using PyTorch [bi/tri]linear interpolation via scale factor and align_corners=True");
653-
if (align_corners) {
654-
// Align corners and scale factor behave slightly different together in TRT and PyTorch so run the
655-
// layer in ATen to maintain consistancy between Torch-TensorRT and PyTorch
656-
// https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate
657-
create_plugin(
658-
ctx,
659-
n,
660-
in,
661-
"trilinear3d",
662-
in_shape,
663-
{},
664-
{},
665-
{scale_d, scale_h, scale_w},
666-
std::string("trilinear"),
667-
align_corners,
668-
true);
669-
} else {
670-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
671-
}
672-
#endif
473+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
673474
} else {
674475
// Case 2: user uses output size
675476
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -679,27 +480,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
679480

680481
auto out_shape = in_shape;
681482
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
682-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
683-
if (!align_corners) {
684-
// align_corners not supported in TensorRT, create plugin and
685-
// run layer through PyTorch
686-
create_plugin(
687-
ctx,
688-
n,
689-
in,
690-
"trilinear3d",
691-
in_shape,
692-
out_shape,
693-
out_size,
694-
{},
695-
std::string("trilinear"),
696-
align_corners);
697-
} else {
698-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, true);
699-
}
700-
#else
701483
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
702-
#endif
703484
}
704485

705486
return true;
@@ -726,38 +507,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
726507
padded_scales[padded_scales.size() - 3] = scale_d;
727508
padded_scales[padded_scales.size() - 2] = scale_h;
728509
padded_scales[padded_scales.size() - 1] = scale_w;
729-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
730-
if (!align_corners) {
731-
TORCHTRT_THROW_ERROR(
732-
"Unable to convert node: "
733-
<< util::node_info(n) << "\nupsample_linear3d only supports align_corner with TensorRT <= 7.0.");
734-
} else {
735-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, true);
736-
}
737-
#else
738-
TORCHTRT_CHECK(
739-
!(align_corners && ctx->input_is_dynamic),
740-
"Torch-TensorRT currently does not support the compilation of dynamc engines from code using PyTorch [bi/tri]linear interpolation via scale factor and align_corners=True");
741-
if (align_corners) {
742-
// Align corners and scale factor behave slightly different together in TRT and PyTorch so run the
743-
// layer in ATen to maintain consistancy between Torch-TensorRT and PyTorch
744-
// https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate
745-
create_plugin(
746-
ctx,
747-
n,
748-
in,
749-
"trilinear3d",
750-
in_shape,
751-
{},
752-
{},
753-
scale_factors.vec(),
754-
std::string("trilinear"),
755-
align_corners,
756-
true);
757-
} else {
758-
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
759-
}
760-
#endif
510+
resize_layer_size(ctx, n, in, {}, padded_scales, nvinfer1::ResizeMode::kLINEAR, align_corners);
761511
} else {
762512
// Case 2: user uses output size
763513
auto out_size = util::toVec(util::toDims(args[1].unwrapToIntList()));
@@ -767,27 +517,7 @@ auto interpolate_registrations TORCHTRT_UNUSED =
767517

768518
auto out_shape = in_shape;
769519
std::copy(out_size.begin(), out_size.end(), out_shape.begin() + (in_shape.size() - out_size.size()));
770-
#if NV_TENSORRT_MAJOR < 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR < 1) // IF TRT VERSION <= 7.0
771-
if (!align_corners) {
772-
// align_corners not supported in TensorRT, create plugin and
773-
// run layer through PyTorch
774-
create_plugin(
775-
ctx,
776-
n,
777-
in,
778-
"trilinear3d",
779-
in_shape,
780-
out_shape,
781-
out_size,
782-
{},
783-
std::string("trilinear"),
784-
align_corners);
785-
} else {
786-
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, true);
787-
}
788-
#else
789520
resize_layer_size(ctx, n, in, out_shape, {}, nvinfer1::ResizeMode::kLINEAR, align_corners);
790-
#endif
791521
}
792522

793523
return true;

0 commit comments

Comments
 (0)