Skip to content

Commit abf3d47

Browse files
authored
Merge pull request #1286 from mfeliz-cruise/michael.feliz/square
feat: Add support for aten::square
2 parents 09a857f + 6b77b72 commit abf3d47

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

core/conversion/converters/impl/element_wise.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,18 @@ auto element_wise_registrations TORCHTRT_UNUSED =
390390
LOG_DEBUG("Output tensor shape: " << out->getDimensions());
391391
return true;
392392
}})
393+
.pattern(
394+
{"aten::square(Tensor self) -> Tensor",
395+
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
396+
auto self = args[0].ITensorOrFreeze(ctx);
397+
auto mul = add_elementwise(ctx, nvinfer1::ElementWiseOperation::kPROD, self, self, util::node_info(n));
398+
TORCHTRT_CHECK(mul, "Unable to create mul layer from node: " << *n);
399+
400+
mul->setName(util::node_info(n).c_str());
401+
auto out = ctx->AssociateValueAndTensor(n->outputs()[0], mul->getOutput(0));
402+
LOG_DEBUG("Output tensor shape: " << out->getDimensions());
403+
return true;
404+
}})
393405
.pattern(
394406
{"aten::mul.Tensor(Tensor self, Tensor other) -> Tensor",
395407
[](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {

tests/core/conversion/converters/test_element_wise.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ TEST(Converters, ATenMulConvertsCorrectly) {
145145
pointwise_test_helper(graph, false, true, {5}, {5}, false, at::kInt, at::kFloat);
146146
}
147147

148+
TEST(Converters, ATenSquareConvertsCorrectly) {
149+
const auto graph = R"IR(
150+
graph(%0 : Tensor):
151+
%1 : Tensor = aten::square(%0)
152+
return (%1))IR";
153+
pointwise_test_helper(graph, true);
154+
}
155+
148156
TEST(Converters, ATenMulWithScalarConvertsCorrectly) {
149157
const auto graph = R"IR(
150158
graph(%0 : Tensor):

0 commit comments

Comments
 (0)