|
| 1 | +#include <torch/torch.h> |
| 2 | +#include <string> |
| 3 | +#include "core/compiler.h" |
| 4 | +#include "gtest/gtest.h" |
| 5 | +#include "tests/util/util.h" |
| 6 | +#include "torch/csrc/jit/ir/irparser.h" |
| 7 | + |
| 8 | +TEST(Converters, ATenResizeDynamicInputCorrectly) { |
| 9 | + const auto graph = R"IR( |
| 10 | + graph(%x : Tensor): |
| 11 | + %3 : int = prim::Constant[value=0]() |
| 12 | + %2 : int = prim::Constant[value=-1]() |
| 13 | + %28 : int = aten::size(%x, %3) |
| 14 | + %30 : int[] = prim::ListConstruct(%28, %2) |
| 15 | + %6 : Tensor = aten::reshape(%x, %30) |
| 16 | + return (%6))IR"; |
| 17 | + |
| 18 | + auto g = std::make_shared<torch::jit::Graph>(); |
| 19 | + |
| 20 | + torch::jit::parseIR(graph, g.get()); |
| 21 | + |
| 22 | + auto in = at::randint(1, 10, {16, 3, 2}, {at::kCUDA}); |
| 23 | + |
| 24 | + auto jit_in = at::clone(in); |
| 25 | + auto params = torch_tensorrt::core::ir::get_static_params(g->inputs(), {}); |
| 26 | + auto jit_results = torch_tensorrt::tests::util::RunGraph(g, params, {jit_in}); |
| 27 | + |
| 28 | + auto trt_in = at::clone(in); |
| 29 | + params = torch_tensorrt::core::ir::get_static_params(g->inputs(), {}); |
| 30 | + auto trt_results = torch_tensorrt::tests::util::RunGraphEngineDynamic(g, params, {in}, true); |
| 31 | + |
| 32 | + auto trt = trt_results[0].reshape(jit_results[0].sizes()); |
| 33 | + |
| 34 | + ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results[0], trt, 2e-6)); |
| 35 | +} |
0 commit comments