Skip to content
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

fix tensorrt output shape error #29308

Merged
merged 3 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ void TensorRtSubgraphPass::CreateTensorRTOp(

std::set<std::string> output_names;
std::set<std::string> output_names_with_id;
std::vector<int> origin_output_dims;
for (auto *x : node->outputs) {
output_names.insert(x->Name());
output_names_with_id.insert(x->Name() + std::to_string(x->id()));
origin_output_dims.push_back(x->Var()->GetShape().size());
}

std::unordered_map<std::string, std::string> output_name_map;
Expand Down Expand Up @@ -224,6 +226,7 @@ void TensorRtSubgraphPass::CreateTensorRTOp(
op_desc->SetAttr("workspace_size", Get<int>("workspace_size"));
op_desc->SetAttr("gpu_id", Get<int>("gpu_device_id"));
op_desc->SetAttr("output_name_mapping", output_mapping);
op_desc->SetAttr("origin_output_dims", origin_output_dims);
op_desc->SetAttr("parameters", params);

// we record all inputs' shapes in attr to check if they are consistent
Expand Down
4 changes: 4 additions & 0 deletions paddle/fluid/operators/tensorrt/tensorrt_engine_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ class TensorRTEngineOp : public framework::OperatorBase {

// Bind output tensor to TRT.
int output_index = 0;
std::vector<int> origin_output_dims =
Attr<std::vector<int>>("origin_output_dims");
VLOG(4) << "TensorRT Engine Op Outputs:";
for (const auto &y : Outputs("Ys")) {
const int bind_index =
Expand All @@ -307,6 +309,8 @@ class TensorRTEngineOp : public framework::OperatorBase {
int nb_dims = dims.nbDims;
for (; nb_dims > 0; nb_dims--) {
if (dims.d[nb_dims - 1] != 1) break;
// some 'x 1' of shape is normal, no need to remove it
if (nb_dims == origin_output_dims[output_index]) break;
}
for (int i = 0; i < nb_dims; i++) ddim.push_back(dims.d[i]);
#endif
Expand Down