PaddlePaddle/PaddleOCR · error · RuntimeError

Configuration Error: 'trt_dynamic_shapes' must be defined in

Error message

Configuration Error: 'trt_dynamic_shapes' must be defined in 'inference.yml' for Paddle Inference TensorRT.

What it means

When TensorRT is enabled with Paddle Inference, create_predictor needs the dynamic shape ranges (min/opt/max per input) to build TRT engines. These are expected in inference.yml under Hpi.backend_configs.paddle_infer.trt_dynamic_shapes. If that section is missing (or the yml has no Hpi block), this RuntimeError is raised — it is a configuration error in the model package, not a code bug. The values cannot be guessed safely because wrong ranges produce silently wrong TRT engines.

Source

Thrown at tools/infer/utility.py:305

                    trt_dynamic_shapes = {}
                    trt_dynamic_shape_input_data = {}
                    if os.path.exists(f"{model_dir}/inference.yml"):
                        model_config = load_config(f"{model_dir}/inference.yml")
                        trt_dynamic_shapes = (
                            model_config.get("Hpi", {})
                            .get("backend_configs", {})
                            .get("paddle_infer", {})
                            .get("trt_dynamic_shapes", {})
                        )
                        trt_dynamic_shape_input_data = (
                            model_config.get("Hpi", {})
                            .get("backend_configs", {})
                            .get("paddle_infer", {})
                            .get("trt_dynamic_shapes_input_data", {})
                        )

                    if not trt_dynamic_shapes:
                        raise RuntimeError(
                            "Configuration Error: 'trt_dynamic_shapes' must be defined in 'inference.yml' for Paddle Inference TensorRT."
                        )

                    trt_save_path = f"{model_dir}/.cache/trt/{file_name}"
                    trt_model_file_path = trt_save_path + ".json"
                    trt_params_file_path = trt_save_path + ".pdiparams"
                    if not os.path.exists(trt_model_file_path) or not os.path.exists(
                        trt_params_file_path
                    ):
                        _convert_trt(
                            {},
                            model_file_path,
                            params_file_path,
                            trt_save_path,
                            args.gpu_id,
                            trt_dynamic_shapes,
                            trt_dynamic_shape_input_data,
                        )

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Download a current model package whose inference.yml includes Hpi.backend_configs.paddle_infer.trt_dynamic_shapes
  2. Add the section manually, e.g. Hpi: {backend_configs: {paddle_infer: {trt_dynamic_shapes: {x: [[1,3,48,320],[1,3,48,640],[1,3,48,1280]]}}}}
  3. Disable TensorRT (--use_tensorrt=false) and use GPU Paddle Inference, which needs no shape ranges

Example fix

# inference.yml — before
Global: {model_name: PP-OCRv5_mobile_det}

# after
Global: {model_name: PP-OCRv5_mobile_det}
Hpi:
  backend_configs:
    paddle_infer:
      trt_dynamic_shapes:
        x:
          - [1, 3, 64, 640]   # min
          - [1, 3, 640, 640]  # opt
          - [1, 3, 960, 960]  # max
Defensive patterns

Strategy: validation

Validate before calling

import os, yaml
yml = os.path.join(model_dir, 'inference.yml')
if args.use_tensorrt and os.path.exists(yml):
    shapes = (yaml.safe_load(open(yml)).get('Hpi', {})
              .get('backend_configs', {}).get('paddle_infer', {}).get('trt_dynamic_shapes'))
    assert shapes, 'enable TRT only with trt_dynamic_shapes defined in inference.yml'

Try / catch

try:
    utility.create_predictor(args, mode, logger)
except RuntimeError as e:
    if 'trt_dynamic_shapes' in str(e):
        args.use_tensorrt = False  # fall back to plain GPU inference
        utility.create_predictor(args, mode, logger)
    else:
        raise

Prevention

When it happens

Trigger: Running with --use_tensorrt against a model whose inference.yml lacks Hpi.backend_configs.paddle_infer.trt_dynamic_shapes; enabling TRT on old model packages that predate the metadata format.

Common situations: Turning on TensorRT for speed on Jetson/GPU deployments with zoo models downloaded before the yml metadata was introduced; hand-written inference.yml files that omit the Hpi section.

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/fb6e204797ac5eda. Report an issue: GitHub.