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
7 changes: 7 additions & 0 deletions core/conversion/converters/impl/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ auto reduce_registrations TORCHTRT_UNUSED =
auto in_dims = util::toVec(in_tensor->getDimensions());
LOG_WARNING("Sum Converter disregards dtype");

if (in_tensor->getType() == nvinfer1::DataType::kBOOL) {
LOG_DEBUG(
"Found type " << in_tensor->getType() << " in aten::sum, casting to "
<< nvinfer1::DataType::kINT32 << " for compatibility.");
in_tensor = castITensor(ctx, in_tensor, nvinfer1::DataType::kINT32);
}

uint32_t axis_mask = (uint32_t)(((uint64_t)1 << in_dims.size()) - 1);

auto sum_layer = ctx->net->addReduce(*in_tensor, nvinfer1::ReduceOperation::kSUM, axis_mask, false);
Expand Down
10 changes: 10 additions & 0 deletions tests/core/conversion/converters/test_reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ converts_keepdims_correctly(mean, Mean);

#undef converts_keepdims_correctly

TEST(Converters, ATenSumBoolConvertsCorrectly) {
const auto graph = R"IR(
graph(%0 : Tensor):
%4 : None = prim::Constant()
%5 : Tensor = aten::sum(%0, %4)
return (%5))IR";
auto in = at::randint(-1, 2, {4, 4, 4}, at::kCUDA).to(at::kBool);
test_body(graph, in);
}

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