Skip to content

[fix] Disambiguate element-wise cast layer names #1630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
8 changes: 4 additions & 4 deletions core/conversion/converters/converter_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ nvinfer1::ILayer* add_elementwise(
const std::string& name) {
if (self->getType() == nvinfer1::DataType::kFLOAT && other->getType() == nvinfer1::DataType::kINT32) {
LOG_DEBUG("Type mismatch, casting other to " << self->getType());
other = castITensor(ctx, other, self->getType());
other = castITensor(ctx, other, self->getType(), name);
} else if (self->getType() == nvinfer1::DataType::kINT32 && other->getType() == nvinfer1::DataType::kFLOAT) {
LOG_DEBUG("Type mismatch, casting self to " << other->getType());
self = castITensor(ctx, self, other->getType());
self = castITensor(ctx, self, other->getType(), name);
}
// ensure self to have larger number of dimension
bool swapSelfOther = false;
Expand All @@ -106,13 +106,13 @@ nvinfer1::ILayer* add_elementwise(
LOG_DEBUG(
"Element-wise op type promotion adding cast from " << self->getType() << " to " << promo_type << " for layer "
<< name);
self = castITensor(ctx, self, promo_type);
self = castITensor(ctx, self, promo_type, name);
}
if (other->getType() != promo_type) {
LOG_DEBUG(
"Element-wise op type promotion adding cast from " << other->getType() << " to " << promo_type
<< " for layer " << name);
other = castITensor(ctx, other, promo_type);
other = castITensor(ctx, other, promo_type, name);
}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/core/conversion/converters/test_add_sub_mul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,14 @@ TEST(Converters, ATenPowScalarConvertsCorrectly) {
return (%3))IR";
pointwise_test_helper(graph, true);
}

TEST(Converters, ElementWiseTypePromotionDisambiguatesCastNames) {
const auto graph = R"IR(
graph(%0 : Tensor, %1 : Tensor):
%2 : int = prim::Constant[value=1]()
%3 : Tensor = aten::add(%0, %1, %2)
%4 : Tensor = aten::add(%0, %1, %2)
%5 : Tensor = aten::add(%3, %4, %2)
return (%5))IR";
pointwise_test_helper(graph, false, false, {4, 3, 3, 3}, {4, 3, 3, 3}, false, at::kInt, at::kFloat);
}