{"record":{"id":"ea711e93d29f6477","repo":"docling-project/docling","slug":"onnx-model-exposes-no-outputs","errorCode":null,"errorMessage":"ONNX model exposes no outputs","messagePattern":"ONNX model exposes no outputs","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/image_classification/onnxruntime_engine.py","lineNumber":95,"sourceCode":"        \"\"\"Determine which ONNX filename to load.\"\"\"\n        filename = self.options.model_filename\n        extra_filename = self._model_config.extra_config.get(\"model_filename\")\n        if extra_filename and isinstance(extra_filename, str):\n            filename = extra_filename\n        return filename\n\n    def _resolve_input_name(self, session: ort.InferenceSession) -> str:\n        \"\"\"Resolve ONNX input name from the loaded model graph.\"\"\"\n        input_nodes = session.get_inputs()\n        if not input_nodes:\n            raise RuntimeError(\"ONNX model exposes no inputs\")\n        return input_nodes[0].name\n\n    def _resolve_output_name(self, session: ort.InferenceSession) -> str:\n        \"\"\"Resolve ONNX output name from the loaded model graph.\"\"\"\n        output_nodes = session.get_outputs()\n        if not output_nodes:\n            raise RuntimeError(\"ONNX model exposes no outputs\")\n        return output_nodes[0].name\n\n    def initialize(self) -> None:\n        \"\"\"Initialize ONNX session and preprocessor.\"\"\"\n        import onnxruntime as ort\n\n        _log.info(\"Initializing ONNX Runtime image-classification engine\")\n\n        model_folder, self._model_path = self._resolve_model_artifacts()\n        _log.debug(\"Using ONNX model at %s\", self._model_path)\n\n        self._processor = self._load_preprocessor(model_folder)\n        self._id_to_label = self._load_label_mapping(model_folder)\n\n        sess_options = ort.SessionOptions()\n        sess_options.intra_op_num_threads = self._accelerator_options.num_threads\n        sess_options.graph_optimization_level = ort.GraphOptimizationLevel(\n            self.options.graph_optimization_level","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/image_classification/onnxruntime_engine.py#L77-L113","documentation":"The loaded ONNX session reports zero output nodes in its graph. The engine needs outputs[0].name to fetch the logits tensor, so a graph without outputs cannot serve classification. As with the no-inputs case, this indicates a defective or non-classification ONNX artifact.","triggerScenarios":"OnnxRuntimeImageClassificationEngine.initialize() -> _resolve_output_name(session) when session.get_outputs() returns an empty list.","commonSituations":"Truncated/corrupted ONNX download; a metadata-only or malformed export; a model exported with all outputs pruned; onnxruntime parsing a graph it only partially supports.","solutions":["Inspect the model independently with the onnx package (onnx.load + m.graph.output) to confirm outputs exist; re-export or re-download if empty.","Verify file integrity (size/checksum) against the source repo and replace corrupted artifacts.","Ensure onnxruntime is new enough for the model's opset; upgrade if session loading silently degrades."],"exampleFix":"# before\nmodel_path = corrupt_path  # session.get_outputs() == []\n\n# after\nimport onnx\nm = onnx.load(str(model_path))\nassert m.graph.output, \"ONNX graph has no outputs — obtain a valid export\"","handlingStrategy":"validation","validationCode":"import onnx\n\nm = onnx.load(str(model_path))\nif not m.graph.output:\n    raise ValueError(f\"{model_path} declares no graph outputs — corrupt or invalid export\")","typeGuard":null,"tryCatchPattern":"try:\n    engine.initialize()\nexcept RuntimeError as e:\n    if \"exposes no outputs\" in str(e):\n        raise RuntimeError(f\"invalid ONNX artifact: {e}\") from e\n    raise","preventionTips":["Validate graph inputs AND outputs during artifact ingestion.","Re-export models from the original framework rather than patching broken files.","Test ONNX artifacts in CI before deploying to inference hosts."],"tags":["onnx","model-graph","corrupt-model","onnxruntime"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}