{"record":{"id":"fb6e204797ac5eda","repo":"PaddlePaddle/PaddleOCR","slug":"configuration-error-trt-dynamic-shapes-must-be","errorCode":null,"errorMessage":"Configuration Error: 'trt_dynamic_shapes' must be defined in 'inference.yml' for Paddle Inference TensorRT.","messagePattern":"Configuration Error: 'trt_dynamic_shapes' must be defined in 'inference\\.yml' for Paddle Inference TensorRT\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/infer/utility.py","lineNumber":305,"sourceCode":"                    trt_dynamic_shapes = {}\n                    trt_dynamic_shape_input_data = {}\n                    if os.path.exists(f\"{model_dir}/inference.yml\"):\n                        model_config = load_config(f\"{model_dir}/inference.yml\")\n                        trt_dynamic_shapes = (\n                            model_config.get(\"Hpi\", {})\n                            .get(\"backend_configs\", {})\n                            .get(\"paddle_infer\", {})\n                            .get(\"trt_dynamic_shapes\", {})\n                        )\n                        trt_dynamic_shape_input_data = (\n                            model_config.get(\"Hpi\", {})\n                            .get(\"backend_configs\", {})\n                            .get(\"paddle_infer\", {})\n                            .get(\"trt_dynamic_shapes_input_data\", {})\n                        )\n\n                    if not trt_dynamic_shapes:\n                        raise RuntimeError(\n                            \"Configuration Error: 'trt_dynamic_shapes' must be defined in 'inference.yml' for Paddle Inference TensorRT.\"\n                        )\n\n                    trt_save_path = f\"{model_dir}/.cache/trt/{file_name}\"\n                    trt_model_file_path = trt_save_path + \".json\"\n                    trt_params_file_path = trt_save_path + \".pdiparams\"\n                    if not os.path.exists(trt_model_file_path) or not os.path.exists(\n                        trt_params_file_path\n                    ):\n                        _convert_trt(\n                            {},\n                            model_file_path,\n                            params_file_path,\n                            trt_save_path,\n                            args.gpu_id,\n                            trt_dynamic_shapes,\n                            trt_dynamic_shape_input_data,\n                        )","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/tools/infer/utility.py#L287-L323","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Download a current model package whose inference.yml includes Hpi.backend_configs.paddle_infer.trt_dynamic_shapes","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]]}}}}","Disable TensorRT (--use_tensorrt=false) and use GPU Paddle Inference, which needs no shape ranges"],"exampleFix":"# inference.yml — before\nGlobal: {model_name: PP-OCRv5_mobile_det}\n\n# after\nGlobal: {model_name: PP-OCRv5_mobile_det}\nHpi:\n  backend_configs:\n    paddle_infer:\n      trt_dynamic_shapes:\n        x:\n          - [1, 3, 64, 640]   # min\n          - [1, 3, 640, 640]  # opt\n          - [1, 3, 960, 960]  # max","handlingStrategy":"validation","validationCode":"import os, yaml\nyml = os.path.join(model_dir, 'inference.yml')\nif args.use_tensorrt and os.path.exists(yml):\n    shapes = (yaml.safe_load(open(yml)).get('Hpi', {})\n              .get('backend_configs', {}).get('paddle_infer', {}).get('trt_dynamic_shapes'))\n    assert shapes, 'enable TRT only with trt_dynamic_shapes defined in inference.yml'","typeGuard":null,"tryCatchPattern":"try:\n    utility.create_predictor(args, mode, logger)\nexcept RuntimeError as e:\n    if 'trt_dynamic_shapes' in str(e):\n        args.use_tensorrt = False  # fall back to plain GPU inference\n        utility.create_predictor(args, mode, logger)\n    else:\n        raise","preventionTips":["Smoke-test the exact model + TRT flag combination in CI before deployment","Keep a non-TRT fallback path configured so missing shape metadata degrades instead of crashing"],"tags":["tensorrt","dynamic-shapes","inference-yml","gpu"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}