docling-project/docling · error · RuntimeError

ONNX model exposes no outputs

Error message

ONNX model exposes no outputs

What it means

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.

Source

Thrown at docling/models/inference_engines/image_classification/onnxruntime_engine.py:95

        """Determine which ONNX filename to load."""
        filename = self.options.model_filename
        extra_filename = self._model_config.extra_config.get("model_filename")
        if extra_filename and isinstance(extra_filename, str):
            filename = extra_filename
        return filename

    def _resolve_input_name(self, session: ort.InferenceSession) -> str:
        """Resolve ONNX input name from the loaded model graph."""
        input_nodes = session.get_inputs()
        if not input_nodes:
            raise RuntimeError("ONNX model exposes no inputs")
        return input_nodes[0].name

    def _resolve_output_name(self, session: ort.InferenceSession) -> str:
        """Resolve ONNX output name from the loaded model graph."""
        output_nodes = session.get_outputs()
        if not output_nodes:
            raise RuntimeError("ONNX model exposes no outputs")
        return output_nodes[0].name

    def initialize(self) -> None:
        """Initialize ONNX session and preprocessor."""
        import onnxruntime as ort

        _log.info("Initializing ONNX Runtime image-classification engine")

        model_folder, self._model_path = self._resolve_model_artifacts()
        _log.debug("Using ONNX model at %s", self._model_path)

        self._processor = self._load_preprocessor(model_folder)
        self._id_to_label = self._load_label_mapping(model_folder)

        sess_options = ort.SessionOptions()
        sess_options.intra_op_num_threads = self._accelerator_options.num_threads
        sess_options.graph_optimization_level = ort.GraphOptimizationLevel(
            self.options.graph_optimization_level

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Inspect the model independently with the onnx package (onnx.load + m.graph.output) to confirm outputs exist; re-export or re-download if empty.
  2. Verify file integrity (size/checksum) against the source repo and replace corrupted artifacts.
  3. Ensure onnxruntime is new enough for the model's opset; upgrade if session loading silently degrades.

Example fix

# before
model_path = corrupt_path  # session.get_outputs() == []

# after
import onnx
m = onnx.load(str(model_path))
assert m.graph.output, "ONNX graph has no outputs — obtain a valid export"
Defensive patterns

Strategy: validation

Validate before calling

import onnx

m = onnx.load(str(model_path))
if not m.graph.output:
    raise ValueError(f"{model_path} declares no graph outputs — corrupt or invalid export")

Try / catch

try:
    engine.initialize()
except RuntimeError as e:
    if "exposes no outputs" in str(e):
        raise RuntimeError(f"invalid ONNX artifact: {e}") from e
    raise

Prevention

When it happens

Trigger: OnnxRuntimeImageClassificationEngine.initialize() -> _resolve_output_name(session) when session.get_outputs() returns an empty list.

Common situations: 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.

Related errors


AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14). Data as JSON: /api/errors/ea711e93d29f6477. Report an issue: GitHub.