Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/conversion/converters/impl/element_wise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,18 @@ auto element_wise_registrations TORCHTRT_UNUSED =
LOG_DEBUG("Output tensor shape: " << out->getDimensions());
return true;
}})
.pattern(
{"aten::square(Tensor self) -> Tensor",
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
auto self = args[0].ITensorOrFreeze(ctx);
auto mul = add_elementwise(ctx, nvinfer1::ElementWiseOperation::kPROD, self, self, util::node_info(n));
TORCHTRT_CHECK(mul, "Unable to create mul layer from node: " << *n);

mul->setName(util::node_info(n).c_str());
auto out = ctx->AssociateValueAndTensor(n->outputs()[0], mul->getOutput(0));
LOG_DEBUG("Output tensor shape: " << out->getDimensions());
return true;
}})
.pattern(
{"aten::mul.Tensor(Tensor self, Tensor other) -> Tensor",
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions tests/core/conversion/converters/test_element_wise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ TEST(Converters, ATenMulConvertsCorrectly) {
pointwise_test_helper(graph, false, true, {5}, {5}, false, at::kInt, at::kFloat);
}

TEST(Converters, ATenSquareConvertsCorrectly) {
const auto graph = R"IR(
graph(%0 : Tensor):
%1 : Tensor = aten::square(%0)
return (%1))IR";
pointwise_test_helper(graph, true);
}

TEST(Converters, ATenMulWithScalarConvertsCorrectly) {
const auto graph = R"IR(
graph(%0 : Tensor):
Expand Down