Skip to content

[fix] Fix output dimensions of aten::unbind converter #1373

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
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/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ bool add_split(ConversionCtx* ctx, const torch::jit::Node* n, args& args, bool s
auto gather_layer = ctx->net->addGather(*in, *indicesTensor, axis);
auto gather_out = gather_layer->getOutput(0);

if (unbind) { // unbind removes the split dimension
auto squeeze_layer = ctx->net->addShuffle(*gather_out);
squeeze_layer->setReshapeDimensions(util::squeezeDims(gather_out->getDimensions(), axis));
TORCHTRT_CHECK(squeeze_layer, "Unable to create squeeze_layer layer from node: " << *n);
gather_out = squeeze_layer->getOutput(0);
}

auto tensor_holder = TensorContainer();
tensor_holder.hold_tensor(gather_out);
auto ival = c10::IValue(std::move(c10::make_intrusive<TensorContainer>(tensor_holder)));
Expand Down
4 changes: 2 additions & 2 deletions tests/core/conversion/converters/test_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ TEST(Converters, ATenUnbindConvertsCorrectly) {
auto trt_results = torch_tensorrt::tests::util::RunGraphEngine(g, params, {trt_in});

for (size_t i = 0; i < jit_results.size(); i++) {
auto trt = trt_results[i].reshape(jit_results[i].sizes());
auto trt = trt_results[i];
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results[i], trt, 2e-6));
}
}
Expand All @@ -1001,7 +1001,7 @@ TEST(Converters, ATenUnbindNegativeAxisConvertsCorrectly) {
auto trt_results = torch_tensorrt::tests::util::RunGraphEngine(g, params, {trt_in});

for (size_t i = 0; i < jit_results.size(); i++) {
auto trt = trt_results[i].reshape(jit_results[i].sizes());
auto trt = trt_results[i];
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results[i], trt, 2e-6));
}
}
Expand Down