-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(aten::stack): Added test for aten::stack
Signed-off-by: Abhiram Iyer <[email protected]> Signed-off-by: Abhiram Iyer <[email protected]>
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <string> | ||
#include "gtest/gtest.h" | ||
#include "torch/csrc/jit/ir/irparser.h" | ||
#include "tests/util/util.h" | ||
#include "core/compiler.h" | ||
|
||
TEST(Converters, ATenStackPureTensorConvertsCorrectly) { | ||
const auto graph = R"IR( | ||
graph(%0 : Tensor, | ||
%1 : Tensor): | ||
%2 : Tensor[] = prim::ListConstruct(%0, %1) | ||
%3 : int = prim::Constant[value=3]() | ||
%4 : Tensor = aten::stack(%2, %3) | ||
return (%4))IR"; | ||
|
||
auto g = std::make_shared<torch::jit::Graph>(); | ||
torch::jit::parseIR(graph, &*g); | ||
|
||
auto in1 = at::randint(1, 10, {4, 4, 4}, {at::kCUDA}); | ||
auto in2 = at::randint(1, 10, {4, 4, 4}, {at::kCUDA}); | ||
|
||
auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); | ||
auto jit_results = trtorch::tests::util::RunGraph(g, params, {in1, in2}); | ||
|
||
params = trtorch::core::conversion::get_named_params(g->inputs(), {}); | ||
auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in1, in2}); | ||
|
||
ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt_results[0].reshape_as(jit_results[0]), 2e-6)); | ||
} | ||
|
||
TEST(Converters, ATenStackDiffTensorConvertsCorrectly) { | ||
const auto graph = R"IR( | ||
graph(%0 : Tensor, | ||
%1 : Float(4, 4, 4)): | ||
%2 : Tensor[] = prim::ListConstruct(%0, %1) | ||
%3 : int = prim::Constant[value=1]() | ||
%4 : Tensor = aten::stack(%2, %3) | ||
return (%4))IR"; | ||
|
||
auto g = std::make_shared<torch::jit::Graph>(); | ||
torch::jit::parseIR(graph, &*g); | ||
|
||
auto in1 = at::randint(1, 10, {4, 4, 4}, {at::kCUDA}); | ||
auto in2 = at::randint(1, 10, {4, 4, 4}, {at::kCUDA}); | ||
|
||
auto params = trtorch::core::conversion::get_named_params(g->inputs(), {in2}); | ||
auto jit_results = trtorch::tests::util::RunGraph(g, params, {in1}); | ||
|
||
params = trtorch::core::conversion::get_named_params(g->inputs(), {in2}); | ||
auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in1}); | ||
|
||
ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt_results[0].reshape_as(jit_results[0]), 2e-6)); | ||
} |