{"record":{"id":"49f5b21ce4c35261","repo":"PaddlePaddle/PaddleOCR","slug":"please-set-inference-model-dir-in-global-inference","errorCode":null,"errorMessage":"Please set inference model dir in Global.inference_model or Global.pretrained_model for post-quantization","messagePattern":"Please set inference model dir in Global\\.inference_model or Global\\.pretrained_model for post-quantization","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"deploy/slim/quantization/quant_kl.py","lineNumber":147,"sourceCode":"        config[\"Eval\"][\"loader\"][\"num_workers\"] = 0\n        valid_dataloader = build_dataloader(config, \"Eval\", device, logger)\n        if is_layoutxlm_ser:\n            train_dataloader = valid_dataloader\n    else:\n        valid_dataloader = None\n\n    paddle.enable_static()\n    exe = paddle.static.Executor(device)\n\n    if \"inference_model\" in global_config.keys():  # , 'inference_model'):\n        inference_model_dir = global_config[\"inference_model\"]\n    else:\n        inference_model_dir = os.path.dirname(global_config[\"pretrained_model\"])\n        if not (\n            os.path.exists(os.path.join(inference_model_dir, \"inference.pdmodel\"))\n            and os.path.exists(os.path.join(inference_model_dir, \"inference.pdiparams\"))\n        ):\n            raise ValueError(\n                \"Please set inference model dir in Global.inference_model or Global.pretrained_model for post-quantization\"\n            )\n\n    if is_layoutxlm_ser:\n        generator = sample_generator_layoutxlm_ser(train_dataloader)\n    else:\n        generator = sample_generator(train_dataloader)\n\n    paddleslim.quant.quant_post_static(\n        executor=exe,\n        model_dir=inference_model_dir,\n        model_filename=\"inference.pdmodel\",\n        params_filename=\"inference.pdiparams\",\n        quantize_model_path=global_config[\"save_inference_dir\"],\n        sample_generator=generator,\n        save_model_filename=\"inference.pdmodel\",\n        save_params_filename=\"inference.pdiparams\",\n        batch_size=1,","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/deploy/slim/quantization/quant_kl.py#L129-L165","documentation":"ValueError from deploy/slim/quantization/quant_kl.py during post-training quantization setup. When Global.inference_model is not set, the script derives a directory from Global.pretrained_model and requires inference.pdmodel + inference.pdiparams to exist there; if either file is missing it aborts asking you to set an inference model dir.","triggerScenarios":"Slim config sets only pretrained_model pointing at a checkpoint prefix (e.g. best_accuracy) instead of a saved inference model; inference model saved under different filenames; relative paths resolved against the wrong working directory.","commonSituations":"Users assuming a trained checkpoint can be quantized directly — KL post-quantization needs an exported inference model produced by paddle.jit.save / export tools; path typos; running from a different cwd so relative pretrained_model paths miss.","solutions":["Export an inference model first (paddleocr export or tools/export_model.py) so inference.pdmodel and inference.pdiparams exist in a directory.","Set `Global.inference_model: <dir>` in the quantization config to that directory.","Or point Global.pretrained_model at a prefix whose directory contains inference.pdmodel/inference.pdiparams.","Use absolute paths in the config to avoid cwd-dependent resolution."],"exampleFix":"// before\nGlobal:\n  pretrained_model: ./output/best_accuracy\n\n// after\n# after running the model export step:\nGlobal:\n  inference_model: ./output/inference","handlingStrategy":"validation","validationCode":"import os\n\ndef inference_model_ready(global_config: dict) -> bool:\n    d = global_config.get(\"inference_model\") or os.path.dirname(\n        global_config.get(\"pretrained_model\", \"\")\n    )\n    return os.path.isfile(os.path.join(d, \"inference.pdmodel\")) and os.path.isfile(\n        os.path.join(d, \"inference.pdiparams\")\n    )","typeGuard":null,"tryCatchPattern":"try:\n    run_quant_kl(global_config)\nexcept ValueError as e:\n    if \"inference model dir\" in str(e):\n        log.error(\"export an inference model first, then set Global.inference_model\")\n    raise","preventionTips":["Always run the model export step before KL post-quantization; checkpoints alone are not quantizable here.","Prefer Global.inference_model with an absolute path over inferring directories from pretrained_model.","Verify inference.pdmodel and inference.pdiparams both exist in the target dir as a CI precheck."],"tags":["paddle","quantization","config","inference-model"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}