Skip to content

Commit

Permalink
fix(//tests): Add stride to complete tensors
Browse files Browse the repository at this point in the history
Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
  • Loading branch information
narendasan committed Aug 4, 2020
1 parent 378690b commit af5d28e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
8 changes: 4 additions & 4 deletions tests/core/converters/test_batch_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down
2 changes: 1 addition & 1 deletion tests/core/converters/test_concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions tests/core/converters/test_conv_deconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down
6 changes: 3 additions & 3 deletions tests/core/converters/test_linear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Expand Down
21 changes: 12 additions & 9 deletions tests/core/converters/test_shuffle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,21 @@ TEST(Converters, ATenPermuteConvertsCorrectly) {
return (%3))IR";

auto g = std::make_shared<torch::jit::Graph>();
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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/core/converters/test_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit af5d28e

Please sign in to comment.