From badaaee6d3a3996c107c121bda463ca90112e703 Mon Sep 17 00:00:00 2001 From: Pei Yang Date: Tue, 3 Dec 2019 10:42:55 +0800 Subject: [PATCH] show shape diff in wrong trt input shape errmsg, test=develop (#21451) (#21470) --- .../operators/tensorrt/tensorrt_engine_op.h | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/operators/tensorrt/tensorrt_engine_op.h b/paddle/fluid/operators/tensorrt/tensorrt_engine_op.h index 22c0c9e9d4..02e272ec35 100644 --- a/paddle/fluid/operators/tensorrt/tensorrt_engine_op.h +++ b/paddle/fluid/operators/tensorrt/tensorrt_engine_op.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "paddle/fluid/framework/executor.h" @@ -212,11 +213,25 @@ class TensorRTEngineOp : public framework::OperatorBase { i_shape.end()); std::vector runtime_input_shape(t_shape.begin() + 1, t_shape.end()); - PADDLE_ENFORCE_EQ(model_input_shape == runtime_input_shape, true, - "Input shapes are inconsistent with the model. TRT 5 " - "or lower version " - "does not support dynamic input shapes. Please check " - "your input shapes."); + auto comma_fold = [](std::string a, int b) { + return std::move(a) + ", " + std::to_string(b); + }; + std::string model_input_shape_str = std::accumulate( + std::next(model_input_shape.begin()), model_input_shape.end(), + std::to_string(model_input_shape[0]), comma_fold); + std::string runtime_input_shape_str = std::accumulate( + std::next(runtime_input_shape.begin()), runtime_input_shape.end(), + std::to_string(runtime_input_shape[0]), comma_fold); + PADDLE_ENFORCE_EQ( + model_input_shape == runtime_input_shape, true, + platform::errors::InvalidArgument( + "Input shapes are inconsistent with the model. Expect [%s] in " + "model description, but got [%s] in runtime. TRT 5 " + "or lower version " + "does not support dynamic input shapes. Please check and " + "modify " + "your input shapes.", + model_input_shape_str, runtime_input_shape_str)); } runtime_batch = t_shape[0]; -- GitLab