-
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.
feat(//core/conversion/converters/impl/shuffle): Implement aten::resize
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
- Loading branch information
1 parent
a51c7b6
commit 353f2d2
Showing
8 changed files
with
95 additions
and
8 deletions.
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
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,33 @@ | ||
#include "core/conversion/converters/converters.h" | ||
|
||
namespace trtorch { | ||
namespace core { | ||
namespace conversion { | ||
namespace converters { | ||
namespace impl { | ||
namespace { | ||
|
||
static auto shuffle_registrations = RegisterNodeConversionPatterns() | ||
.pattern({ | ||
"aten::reshape(Tensor self, int[] shape) -> (Tensor)", | ||
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool { | ||
auto in = args[0].ITensor(); | ||
auto new_shape = util::toDimsPad(args[1].unwrapToIntList(), 2); | ||
|
||
auto shuffle = ctx->net->addShuffle(*in); | ||
TRTORCH_CHECK(shuffle, "Unable to create shuffle layer from node: " << *n); | ||
shuffle->setReshapeDimensions(new_shape); | ||
shuffle->setName(util::node_info(n).c_str()); | ||
|
||
auto out_tensor = ctx->AssociateValueAndTensor(n->outputs()[0], shuffle->getOutput(0)); | ||
LOG_DEBUG("Output tensor shape: " << out_tensor->getDimensions()); | ||
|
||
return true; | ||
} | ||
}); | ||
} // namespace | ||
} // namespace impl | ||
} // namespace converters | ||
} // namespace conversion | ||
} // namespace core | ||
} // namespace trtorch |
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
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
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,29 @@ | ||
#include <string> | ||
#include "gtest/gtest.h" | ||
#include "torch/csrc/jit/ir/irparser.h" | ||
#include "tests/util/util.h" | ||
#include "core/compiler.h" | ||
|
||
TEST(Converters, ATenReshapeConvertsCorrectly) { | ||
const auto graph = R"IR( | ||
graph(%0 : Tensor): | ||
%1 : int = prim::Constant[value=3]() | ||
%2 : int = prim::Constant[value=2]() | ||
%3 : int[] = prim::ListConstruct(%1, %2) | ||
%4 : Tensor = aten::reshape(%0, %3) | ||
return (%4))IR"; | ||
|
||
auto g = std::make_shared<torch::jit::Graph>(); | ||
torch::jit::parseIR(graph, &*g); | ||
|
||
auto in = at::randint(0, 5, {2, 3}, {at::kCUDA}); | ||
auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); | ||
auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); | ||
|
||
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)); | ||
} |