docling-project/docling · error · RuntimeError
Expected ONNX model to return at least 1 output containing l
Error message
Expected ONNX model to return at least 1 output containing logits
What it means
After running the ONNX session with the requested output name, the returned list of output tensors is empty. onnxruntime normally returns one array per requested output, so an empty result means the run produced nothing usable — an abnormal state usually tied to a degraded session or mismatched output request.
Source
Thrown at docling/models/inference_engines/image_classification/onnxruntime_engine.py:180
or self._processor is None
or self._input_name is None
or self._output_name is None
):
raise RuntimeError("Engine not initialized. Call initialize() first.")
images = [item.image.convert("RGB") for item in input_batch]
inputs = self._processor(images=images, return_tensors="np")
input_tensor = np.asarray(inputs["pixel_values"], dtype=np.float32)
output_tensors = self._session.run(
[self._output_name],
{
self._input_name: input_tensor,
},
)
if len(output_tensors) < 1:
raise RuntimeError(
"Expected ONNX model to return at least 1 output containing logits"
)
logits_batch = np.asarray(output_tensors[0], dtype=np.float32)
if logits_batch.ndim != 2:
raise RuntimeError(
"Expected ONNX logits output shape [batch_size, num_classes], "
f"got shape={logits_batch.shape}"
)
probs_batch = self._softmax(logits_batch)
return self._build_batch_outputs_from_probabilities(
input_batch=input_batch,
probs_batch=probs_batch,
)
View on GitHub (pinned to 61d76f1ff3)
Solutions
- Re-create the engine (fresh session) via initialize() and retry the batch.
- Update/repair the onnxruntime installation if empty run results persist across fresh sessions.
- Verify the requested output name still matches the loaded graph (re-resolve via session.get_outputs()).
Example fix
# before: stale session after model file swap engine.predict_batch(batch) # empty output_tensors # after: rebuild session and retry engine = OnnxRuntimeImageClassificationEngine(...) engine.initialize() engine.predict_batch(batch)
Defensive patterns
Strategy: retry
Validate before calling
outputs = session.run([output_name], {input_name: tensor})
if len(outputs) < 1:
raise RuntimeError("onnxruntime returned no output tensors — session state suspect") Try / catch
try:
engine.predict_batch(batch)
except RuntimeError as e:
if "at least 1 output" in str(e):
engine.initialize() # fresh session fixes stale-state cases
engine.predict_batch(batch)
else:
raise Prevention
- Do not replace or delete model files while a session is live.
- Recreate sessions after deployment changes instead of reusing them.
- Pin a known-good onnxruntime version in production images.
When it happens
Trigger: OnnxRuntimeImageClassificationEngine.predict_batch() when session.run([output_name], {...}) returns a list shorter than 1 — practically only reachable with an inconsistent session state (e.g. session invalidated after a graph/file change) or an onnxruntime edge case.
Common situations: Session object reused after the underlying model file was replaced/deleted; onnxruntime version regression; exotic execution providers returning empty results on failure.
Related errors
- ONNX model exposes no inputs
- ONNX model exposes no outputs
- Expected OnnxRuntimeImageClassificationEngineOptions, got {t
- ONNX model file '{model_filename}' not found: {model_path}
- Engine not initialized. Call initialize() first.
AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14).
Data as JSON: /api/errors/085327be1fc2d0b4.
Report an issue: GitHub.