{"record":{"id":"9669429336dfc7f9","repo":"docling-project/docling","slug":"failed-to-load-label-mapping-from-model-config-at","errorCode":null,"errorMessage":"Failed to load label mapping from model config at {model_folder}: {exc}","messagePattern":"Failed to load label mapping from model config at (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/common/hf_vision_base.py","lineNumber":104,"sourceCode":"            _log.debug(\"Loading image processor from %s\", model_folder)\n            return AutoImageProcessor.from_pretrained(str(model_folder))\n        except Exception as exc:\n            raise RuntimeError(\n                f\"Failed to load image processor from {model_folder}: {exc}\"\n            )\n\n    def _load_label_mapping(self, model_folder: Path) -> Dict[int, str]:\n        \"\"\"Load label mapping from HuggingFace model config.\"\"\"\n        try:\n            from transformers import AutoConfig\n\n            config = AutoConfig.from_pretrained(str(model_folder))\n            return {\n                int(label_id): label_name\n                for label_id, label_name in config.id2label.items()\n            }\n        except Exception as exc:\n            raise RuntimeError(\n                f\"Failed to load label mapping from model config at {model_folder}: {exc}\"\n            )\n\n    def get_label_mapping(self) -> Dict[int, str]:\n        \"\"\"Get the label mapping for this model.\"\"\"\n        return self._id_to_label\n\n    @staticmethod\n    def _as_float(value: Any) -> float:\n        if isinstance(value, Real):\n            return float(value)\n\n        if isinstance(value, np.ndarray):\n            if value.size != 1:\n                raise TypeError(\n                    f\"Expected scalar-like ndarray with size 1, got shape={value.shape}\"\n                )\n            return float(value.reshape(-1)[0])","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/common/hf_vision_base.py#L86-L122","documentation":"Raised as RuntimeError by HfVisionModelMixin._load_label_mapping when loading the HF config fails or config.id2label is missing/malformed. Vision layout models map predicted class ids to label names via config.id2label; without it predictions cannot be interpreted.","triggerScenarios":"AutoConfig.from_pretrained(model_folder) raises (missing/corrupt config.json), or config.id2label does not exist / is not a mapping of int->str in the model's config.","commonSituations":"Model artifacts copied without config.json; a repo revision whose config lacks id2label; custom fine-tuned repos where the label mapping was not saved into the config.","solutions":["Check the ': {exc}' suffix for the root cause (usually FileNotFoundError on config.json or AttributeError on id2label).","Ensure config.json is present in the model folder and re-download artifacts if incomplete.","For fine-tuned models, re-save the model with save_pretrained so id2label is serialized into config.json."],"exampleFix":"# before: model folder missing config.json\n# after: restore it from the base repo\n# huggingface-cli download <repo_id> config.json --local-dir /models/layout","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nassert (Path(model_folder) / 'config.json').exists(), 'config.json missing'","typeGuard":null,"tryCatchPattern":"try:\n    model = MyVisionModel(...)\nexcept RuntimeError as e:\n    if 'label mapping' in str(e):\n        raise RuntimeError('model artifacts incomplete: config.json/id2label missing') from e\n    raise","preventionTips":["Ship complete model artifacts (config.json with id2label) when self-hosting fine-tunes.","Save fine-tuned models with save_pretrained so id2label is serialized.","Validate artifacts with a load smoke test during deployment, not at request time."],"tags":["huggingface","model-loading","labels","configuration"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}