diff --git a/core/conversion/converters/impl/conv_deconv.cpp b/core/conversion/converters/impl/conv_deconv.cpp index 2defe97efd..2cc88779c8 100644 --- a/core/conversion/converters/impl/conv_deconv.cpp +++ b/core/conversion/converters/impl/conv_deconv.cpp @@ -18,27 +18,25 @@ auto conv_registrations = RegisterNodeConversionPatterns() auto in = args[0].ITensor(); auto w = Weights(ctx, args[1].unwrapToTensor()); - auto stride = util::toDimsHW(args[3].unwrapToIntList()); + auto stride = util::toDims(args[3].unwrapToIntList()); LOG_DEBUG("stride: " << stride); - auto padding = util::toDimsHW(args[4].unwrapToIntList()); + auto padding = util::toDims(args[4].unwrapToIntList()); LOG_DEBUG("padding: " << padding); - auto dilation = util::toDimsHW(args[5].unwrapToIntList()); + auto dilation = util::toDims(args[5].unwrapToIntList()); LOG_DEBUG("dilation: " << dilation); bool transposed = args[6].unwrapToBool(); - auto out_padding = util::toDimsHW(args[7].unwrapToIntList()); + auto out_padding = util::toDims(args[7].unwrapToIntList()); LOG_DEBUG("out_padding: " << out_padding); int64_t groups = args[8].unwrapToInt(); nvinfer1::ILayer* new_layer; if (transposed) { - //TODO: Check deconv correctness - LOG_WARNING(ctx->logger, "Deconvolution converter has not be tested"); nvinfer1::IDeconvolutionLayer* deconv; if (args[2].IValue()->isTensor()) { Weights b(ctx, args[2].IValue()->toTensor()); - deconv = ctx->net->addDeconvolutionNd(*in, w.num_output_maps, w.kernel_shape, w.data, b.data); + deconv = ctx->net->addDeconvolutionNd(*in, w.num_input_maps, w.kernel_shape, w.data, b.data); } else { - deconv = ctx->net->addDeconvolutionNd(*in, w.num_output_maps, w.kernel_shape, w.data, {}); + deconv = ctx->net->addDeconvolutionNd(*in, w.num_input_maps, w.kernel_shape, w.data, {}); } TRTORCH_CHECK(deconv, "Unable to create deconvolution layer from node: " << *n); diff --git a/tests/core/converters/BUILD b/tests/core/converters/BUILD index a91d08865f..2a93517e7d 100644 --- a/tests/core/converters/BUILD +++ b/tests/core/converters/BUILD @@ -16,7 +16,7 @@ converter_test( ) converter_test( - name = "test_conv" + name = "test_conv_deconv" ) converter_test( @@ -56,7 +56,7 @@ test_suite( tests = [ ":test_activation", ":test_batch_norm", - ":test_conv", + ":test_conv_deconv", ":test_element_wise", ":test_linear", ":test_matrix_multiply", diff --git a/tests/core/converters/test_conv.cpp b/tests/core/converters/test_conv_deconv.cpp similarity index 61% rename from tests/core/converters/test_conv.cpp rename to tests/core/converters/test_conv_deconv.cpp index 154a5b06ca..2c633e4b29 100644 --- a/tests/core/converters/test_conv.cpp +++ b/tests/core/converters/test_conv_deconv.cpp @@ -203,6 +203,173 @@ TEST(Converters, ATenConvolutionWithPaddingConvertsCorrectly) { ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); } +TEST(Converters, ATenConvTransposeConvertsCorrectly) { + const auto graph = R"IR( + graph(%0 : Tensor, + %1 : Float(8, 3, 3, 3), + %2 : Float(8)): + %3 : int = prim::Constant[value=1]() + %4 : int = prim::Constant[value=0]() + %5 : int = prim::Constant[value=1]() + %6 : int = prim::Constant[value=0]() + %7 : bool = prim::Constant[value=1]() + %8 : int[] = prim::ListConstruct(%3, %3) + %9 : int[] = prim::ListConstruct(%4, %4) + %10 : int[] = prim::ListConstruct(%5, %5) + %11 : int[] = prim::ListConstruct(%6, %6) + %12 : Tensor = aten::_convolution(%0, %1, %2, %8, %9, %10, %7, %11, %3, %7, %7, %7) + return (%12))IR"; + + auto g = std::make_shared(); + torch::jit::parseIR(graph, &*g); + + auto in = at::randint(1, 3, {1, 8, 5, 5}, {at::kCUDA}); + auto w = at::randint(1, 3, {8, 3, 3, 3}, {at::kCUDA}); + auto b = at::randint(1, 3, {3}, {at::kCUDA}); + + auto jit_in = at::clone(in); + auto jit_w = at::clone(w); + auto jit_b = at::clone(b); + + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {jit_w, jit_b}); + auto jit_results = trtorch::tests::util::RunGraph(g, params, {jit_in}); + + auto trt_in = at::clone(in); + auto trt_w = at::clone(w); + auto trt_b = at::clone(b); + params = trtorch::core::conversion::get_named_params(g->inputs(), {trt_w, trt_b}); + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {trt_in}); + + auto trt = trt_results[0].reshape(jit_results[0].sizes()); + + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); +} + +TEST(Converters, ATenConvTransposeNoBiasConvertsCorrectly) { + const auto graph = R"IR( + graph(%0 : Tensor, + %1 : Float(4, 1, 3, 3)): + %2 : None = prim::Constant() + %3 : int = prim::Constant[value=1]() + %4 : int = prim::Constant[value=0]() + %5 : int = prim::Constant[value=1]() + %6 : int = prim::Constant[value=0]() + %7 : bool = prim::Constant[value=1]() + %8 : int[] = prim::ListConstruct(%3, %3) + %9 : int[] = prim::ListConstruct(%4, %4) + %10 : int[] = prim::ListConstruct(%5, %5) + %11 : int[] = prim::ListConstruct(%6, %6) + %12 : Tensor = aten::_convolution(%0, %1, %2, %8, %9, %10, %7, %11, %3, %7, %7, %7) + return (%12))IR"; + + auto g = std::make_shared(); + torch::jit::parseIR(graph, &*g); + + auto in = at::randint(1, 2, {1, 4, 3, 3}, {at::kCUDA}); + auto w = at::randint(1, 2, {4, 1, 2, 2}, {at::kCUDA}); + + auto jit_in = at::clone(in); + auto jit_w = at::clone(w); + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {jit_w}); + auto jit_results = trtorch::tests::util::RunGraph(g, params, {jit_in}); + + auto trt_in = at::clone(in); + auto trt_w = at::clone(w); + params = trtorch::core::conversion::get_named_params(g->inputs(), {trt_w}); + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {trt_in}); + + auto trt = trt_results[0].reshape(jit_results[0].sizes()); + + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); +} + + +TEST(Converters, ATenConvTransposeWithStrideConvertsCorrectly) { + const auto graph = R"IR( + graph(%0 : Tensor, + %1 : Float(4, 3, 3, 3), + %2 : Float(4)): + %3 : int = prim::Constant[value=3]() + %4 : int = prim::Constant[value=0]() + %5 : int = prim::Constant[value=1]() + %6 : int = prim::Constant[value=0]() + %7 : bool = prim::Constant[value=1]() + %8 : int[] = prim::ListConstruct(%3, %3) + %9 : int[] = prim::ListConstruct(%4, %4) + %10 : int[] = prim::ListConstruct(%5, %5) + %11 : int[] = prim::ListConstruct(%6, %6) + %12 : int = prim::Constant[value=1]() + %13 : Tensor = aten::_convolution(%0, %1, %2, %8, %9, %10, %7, %11, %12, %7, %7, %7) + return (%13))IR"; + + auto g = std::make_shared(); + torch::jit::parseIR(graph, &*g); + + auto in = at::randint(1, 10, {1, 4, 9, 9}, {at::kCUDA}); + auto w = at::randint(1, 10, {4, 3, 3, 3}, {at::kCUDA}); + auto b = at::randint(1, 10, {3}, {at::kCUDA}); + + auto jit_in = at::clone(in); + auto jit_w = at::clone(w); + auto jit_b = at::clone(b); + + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {jit_w, jit_b}); + auto jit_results = trtorch::tests::util::RunGraph(g, params, {jit_in}); + + auto trt_in = at::clone(in); + auto trt_w = at::clone(w); + auto trt_b = at::clone(b); + params = trtorch::core::conversion::get_named_params(g->inputs(), {trt_w, trt_b}); + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {trt_in}); + + auto trt = trt_results[0].reshape(jit_results[0].sizes()); + + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); +} + +TEST(Converters, ATenConvTransposeWithPaddingConvertsCorrectly) { + const auto graph = R"IR( + graph(%0 : Tensor, + %1 : Float(4, 3, 4, 4), + %2 : Float(4)): + %3 : int = prim::Constant[value=1]() + %4 : int = prim::Constant[value=2]() + %5 : int = prim::Constant[value=1]() + %6 : int = prim::Constant[value=0]() + %7 : bool = prim::Constant[value=1]() + %8 : int[] = prim::ListConstruct(%3, %3) + %9 : int[] = prim::ListConstruct(%4, %4) + %10 : int[] = prim::ListConstruct(%5, %5) + %11 : int[] = prim::ListConstruct(%6, %6) + %12 : int = prim::Constant[value=1]() + %13 : Tensor = aten::_convolution(%0, %1, %2, %8, %9, %10, %7, %11, %12, %7, %7, %7) + return (%13))IR"; + + auto g = std::make_shared(); + torch::jit::parseIR(graph, &*g); + + auto in = at::randint(1, 10, {1, 4, 4, 4}, {at::kCUDA}); + auto w = at::randint(1, 10, {4, 3, 2, 2}, {at::kCUDA}); + auto b = at::randint(1, 10, {3}, {at::kCUDA}); + + auto jit_in = at::clone(in); + auto jit_w = at::clone(w); + auto jit_b = at::clone(b); + + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {jit_w, jit_b}); + auto jit_results = trtorch::tests::util::RunGraph(g, params, {jit_in}); + + auto trt_in = at::clone(in); + auto trt_w = at::clone(w); + auto trt_b = at::clone(b); + params = trtorch::core::conversion::get_named_params(g->inputs(), {trt_w, trt_b}); + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {trt_in}); + + auto trt = trt_results[0].reshape(jit_results[0].sizes()); + + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); +} + // TEST(Converters, ATenConvolutionWithDialationConvertsCorrectly) { // const auto graph = R"IR( // graph(%0 : Tensor, diff --git a/tests/util/run_graph_engine.cpp b/tests/util/run_graph_engine.cpp index f9a3e3f388..76349a916e 100644 --- a/tests/util/run_graph_engine.cpp +++ b/tests/util/run_graph_engine.cpp @@ -65,7 +65,9 @@ std::vector RunGraphEngine(std::shared_ptr& g, std::vector inputs) { LOG_DEBUG("Running TRT version"); auto in = toInputRanges(inputs); - std::string eng = core::conversion::ConvertBlockToEngine(g->block(), in, named_params); + auto info = core::conversion::ConversionInfo(in); + info.engine_settings.workspace_size = 1 << 20; + std::string eng = core::conversion::ConvertBlockToEngine(g->block(), info, named_params); return RunEngine(eng, inputs); }