From bbc837ee72cc57e089c4e13f610ac5aae1fa81b6 Mon Sep 17 00:00:00 2001 From: Shang Zhizhou Date: Tue, 13 Oct 2020 08:53:11 +0800 Subject: [PATCH] add info log for trt input dynamic shape check (#27796) * add info log for trt input dynamic shape check * fix error msg error --- .../fluid/inference/tensorrt/convert/op_converter.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/paddle/fluid/inference/tensorrt/convert/op_converter.h b/paddle/fluid/inference/tensorrt/convert/op_converter.h index ac0a04b9a11..4a386ac1d81 100644 --- a/paddle/fluid/inference/tensorrt/convert/op_converter.h +++ b/paddle/fluid/inference/tensorrt/convert/op_converter.h @@ -164,6 +164,7 @@ class OpConverter { const std::unordered_set& parameters, const std::vector& outputs, TensorRTEngine* engine) { engine->InitNetwork(); + bool all_dynamic_shape_set = true; for (auto& input : inputs) { if (parameters.count(input)) continue; auto* var = block_desc->FindVar(input); @@ -181,6 +182,13 @@ class OpConverter { auto max_input_shape = engine->max_input_shape()[input]; auto optim_input_shape = engine->optim_input_shape()[input]; size_t ranks = min_input_shape.size(); + if (ranks == 0) { + all_dynamic_shape_set = false; + LOG(INFO) << "trt input [" << input.c_str() + << "] dynamic shape info not set, please check and retry."; + // check other input + continue; + } std::vector input_shape; input_shape.push_back(-1); for (size_t i = 1; i < ranks; i++) { @@ -207,6 +215,10 @@ class OpConverter { Vec2TRT_Dims(var_shape, input)); } } + PADDLE_ENFORCE_EQ(all_dynamic_shape_set, true, + platform::errors::InvalidArgument( + "some trt inputs dynamic shape info not set, " + "check the INFO log above for more details.")); framework::proto::BlockDesc* block_proto = block_desc->Proto(); ConvertBlock(*block_proto, parameters, scope, engine); for (auto& output : outputs) { -- GitLab