From af5d28e5cdefa94df744e2128d86526890fc00e2 Mon Sep 17 00:00:00 2001 From: Naren Dasan Date: Tue, 4 Aug 2020 16:31:45 -0700 Subject: [PATCH] fix(//tests): Add stride to complete tensors Signed-off-by: Naren Dasan Signed-off-by: Naren Dasan --- tests/core/converters/test_batch_norm.cpp | 8 +++---- tests/core/converters/test_concat.cpp | 2 +- tests/core/converters/test_conv_deconv.cpp | 28 +++++++++++----------- tests/core/converters/test_linear.cpp | 6 ++--- tests/core/converters/test_shuffle.cpp | 21 +++++++++------- tests/core/converters/test_stack.cpp | 2 +- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/tests/core/converters/test_batch_norm.cpp b/tests/core/converters/test_batch_norm.cpp index 727d7a17ea..7155fac642 100644 --- a/tests/core/converters/test_batch_norm.cpp +++ b/tests/core/converters/test_batch_norm.cpp @@ -7,10 +7,10 @@ TEST(Converters, ATenBatchNormConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1: Float(5), - %2: Float(5), - %3: Float(5), - %4: Float(5)): + %1: Float(5:1), + %2: Float(5:1), + %3: Float(5:1), + %4: Float(5:1)): %5 : bool = prim::Constant[value=0]() %6 : float = prim::Constant[value=1.0000000000000001e-05]() %7 : float = prim::Constant[value=0.10000000000000001]() diff --git a/tests/core/converters/test_concat.cpp b/tests/core/converters/test_concat.cpp index 359e15eadf..ecb7933845 100644 --- a/tests/core/converters/test_concat.cpp +++ b/tests/core/converters/test_concat.cpp @@ -31,7 +31,7 @@ TEST(Converters, ATenCatPureTensorConvertsCorrectly) { TEST(Converters, ATenCatDiffTensorConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(5)): + %1 : Float(5:1)): %2 : Tensor[] = prim::ListConstruct(%0, %1) %3 : int = prim::Constant[value=0]() %4 : Tensor = aten::cat(%2, %3) diff --git a/tests/core/converters/test_conv_deconv.cpp b/tests/core/converters/test_conv_deconv.cpp index 2c633e4b29..94c4b1d330 100644 --- a/tests/core/converters/test_conv_deconv.cpp +++ b/tests/core/converters/test_conv_deconv.cpp @@ -39,8 +39,8 @@ void conv_test_helper(std::string graph_ir) { TEST(Converters, ATenConvolutionConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(8, 3, 5, 5), - %2 : Float(8)): + %1 : Float(8:45, 3:15, 5:5, 5:1), + %2 : Float(8:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -81,7 +81,7 @@ TEST(Converters, ATenConvolutionConvertsCorrectly) { TEST(Converters, ATenConvolutionNoBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 1, 3, 3)): + %1 : Float(4:9, 1:9, 3:3, 3:1)): %2 : None = prim::Constant() %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() @@ -120,8 +120,8 @@ TEST(Converters, ATenConvolutionNoBiasConvertsCorrectly) { TEST(Converters, ATenConvolutionWithStrideConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 3, 3), - %2 : Float(4)): + %1 : Float(4:27, 3:9, 3:3, 3:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=3]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -163,8 +163,8 @@ TEST(Converters, ATenConvolutionWithStrideConvertsCorrectly) { TEST(Converters, ATenConvolutionWithPaddingConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 4, 4), - %2 : Float(4)): + %1 : Float(4:48, 3:16, 4:4, 4:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=2]() %5 : int = prim::Constant[value=1]() @@ -206,8 +206,8 @@ TEST(Converters, ATenConvolutionWithPaddingConvertsCorrectly) { TEST(Converters, ATenConvTransposeConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(8, 3, 3, 3), - %2 : Float(8)): + %1 : Float(8:27, 3:9, 3:3, 3:1), + %2 : Float(8:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -248,7 +248,7 @@ TEST(Converters, ATenConvTransposeConvertsCorrectly) { TEST(Converters, ATenConvTransposeNoBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 1, 3, 3)): + %1 : Float(4:9, 1:9, 3:3, 3:1)): %2 : None = prim::Constant() %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() @@ -287,8 +287,8 @@ TEST(Converters, ATenConvTransposeNoBiasConvertsCorrectly) { TEST(Converters, ATenConvTransposeWithStrideConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 3, 3), - %2 : Float(4)): + %1 : Float(4:27, 3:9, 3:3, 3:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=3]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -330,8 +330,8 @@ TEST(Converters, ATenConvTransposeWithStrideConvertsCorrectly) { TEST(Converters, ATenConvTransposeWithPaddingConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 4, 4), - %2 : Float(4)): + %1 : Float(4:48, 3:16, 4:4, 4:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=2]() %5 : int = prim::Constant[value=1]() diff --git a/tests/core/converters/test_linear.cpp b/tests/core/converters/test_linear.cpp index c668c03e63..6bbe7ef597 100644 --- a/tests/core/converters/test_linear.cpp +++ b/tests/core/converters/test_linear.cpp @@ -7,7 +7,7 @@ TEST(Converters, ATenLinearNoBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(3, 2)): + %1 : Float(3:2, 2:1)): %2 : None = prim::Constant() %3 : Tensor = aten::linear(%0, %1, %2) return (%3))IR"; @@ -34,8 +34,8 @@ TEST(Converters, ATenLinearNoBiasConvertsCorrectly) { TEST(Converters, ATenLinearBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(2, 3), - %2 : Float(2)): + %1 : Float(2:3, 3:1), + %2 : Float(2:1)): %3 : Tensor = aten::linear(%0, %1, %2) return (%3))IR"; diff --git a/tests/core/converters/test_shuffle.cpp b/tests/core/converters/test_shuffle.cpp index 59f1ef4d32..537e229b0b 100644 --- a/tests/core/converters/test_shuffle.cpp +++ b/tests/core/converters/test_shuffle.cpp @@ -108,18 +108,21 @@ TEST(Converters, ATenPermuteConvertsCorrectly) { return (%3))IR"; auto g = std::make_shared(); - torch::jit::parseIR(graph, &*g); + torch::jit::parseIR(graph, &*g); - auto in = at::randint(0, 5, {2, 3, 2, 3}, {at::kCUDA}); - auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); - auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); + auto in = at::randint(0, 5, {2, 3, 2, 3}, {at::kCUDA}); + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); - in = at::clone(in); - params = trtorch::core::conversion::get_named_params(g->inputs(), {}); - auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in}); - auto trt = trt_results[0].reshape_as(jit_results[0]); + std::cout << "Running JIT" << std::endl; + auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); - ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); + std::cout << "Running TRT" << std::endl; + in = at::clone(in); + params = trtorch::core::conversion::get_named_params(g->inputs(), {}); + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in}); + auto trt = trt_results[0].reshape_as(jit_results[0]); + + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); } TEST(Converters, ATenPermute3DConvertsCorrectly) { diff --git a/tests/core/converters/test_stack.cpp b/tests/core/converters/test_stack.cpp index 38cefd2993..590369a3a5 100755 --- a/tests/core/converters/test_stack.cpp +++ b/tests/core/converters/test_stack.cpp @@ -31,7 +31,7 @@ TEST(Converters, ATenStackPureTensorConvertsCorrectly) { TEST(Converters, ATenStackDiffTensorConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 4, 4)): + %1 : Float(4:16, 4:4, 4:1)): %2 : Tensor[] = prim::ListConstruct(%0, %1) %3 : int = prim::Constant[value=1]() %4 : Tensor = aten::stack(%2, %3)