chore: bump docling

This commit is contained in:
Alex committed 2026-08-12 09:05:00 +01:00
1 parent 0d7fd529ef
commit ca53a3ac4b
7 files changed
+214 -1

No files matched your search

+120
View File
@@ -891,3 +891,123 @@ class TestTabularGateSeam:
with pytest.raises(DocumentParseError):
DoclingCSVParser().parse_file(path)
# =====================================================================
# torch.compile inference setting
# =====================================================================
@pytest.mark.unit
class TestApplyInferenceSettings:
"""_apply_inference_settings governs docling's torch.compile of its models.
docling >= 2.92 compiles its layout/OCR models with torch.compile by
default, which hard-fails TorchInductor's Metal codegen on Apple Silicon
and buys nothing for one-shot parses.
"""
def test_disables_torch_compile_by_default(self, monkeypatch):
from application.parser.file.docling_parser import _apply_inference_settings
class Inference:
compile_torch_models = True
class DoclingSettings:
inference = Inference()
docling_settings = DoclingSettings()
monkeypatch.setattr(
"docling.datamodel.settings.settings", docling_settings, raising=False
)
_apply_inference_settings()
assert docling_settings.inference.compile_torch_models is False
def test_opt_in_reenables_torch_compile(self, monkeypatch):
from application.core.settings import settings
from application.parser.file.docling_parser import _apply_inference_settings
monkeypatch.setattr(
settings, "DOCLING_COMPILE_TORCH_MODELS", True, raising=False
)
class Inference:
compile_torch_models = False
class DoclingSettings:
inference = Inference()
docling_settings = DoclingSettings()
monkeypatch.setattr(
"docling.datamodel.settings.settings", docling_settings, raising=False
)
_apply_inference_settings()
assert docling_settings.inference.compile_torch_models is True
def test_noop_on_docling_without_inference_settings(self, monkeypatch):
"""Builds predating the inference settings must be a silent no-op."""
from application.parser.file.docling_parser import _apply_inference_settings
class DoclingSettings:
pass
monkeypatch.setattr(
"docling.datamodel.settings.settings", DoclingSettings(), raising=False
)
_apply_inference_settings() # must not raise
def test_create_converter_applies_inference_settings(self, monkeypatch):
"""The cap is worthless unless the converter path actually calls it."""
from application.parser.file.docling_parser import DoclingParser
called = []
monkeypatch.setattr(
"application.parser.file.docling_parser._apply_inference_settings",
lambda: called.append(True),
)
monkeypatch.setattr(
"docling.document_converter.DocumentConverter",
MagicMock(),
)
DoclingParser(ocr_enabled=False)._create_converter()
assert called == [True]
def test_inference_settings_applied_before_options_are_built(self, monkeypatch):
"""Ordering is load-bearing, not incidental.
``compile_model`` is a ``default_factory`` that reads docling's global
at *option construction* time, so flipping the global after building
``PdfPipelineOptions`` is silently ignored. Pin the order.
"""
import docling.datamodel.pipeline_options as dpo
from application.parser.file.docling_parser import DoclingParser
events = []
monkeypatch.setattr(
"application.parser.file.docling_parser._apply_inference_settings",
lambda: events.append("settings"),
)
real_options = dpo.PdfPipelineOptions
def _tracking_options(*args, **kwargs):
events.append("options")
return real_options(*args, **kwargs)
monkeypatch.setattr(dpo, "PdfPipelineOptions", _tracking_options)
monkeypatch.setattr("docling.document_converter.DocumentConverter", MagicMock())
DoclingParser(ocr_enabled=False)._create_converter()
assert events == ["settings", "options"], (
"torch.compile must be disabled before PdfPipelineOptions is "
f"constructed, got {events}"
)
+48
View File
@@ -516,3 +516,51 @@ def test_bound_parse_payload_small_content_not_flagged():
out = bound_parse_payload({"output": "text", "content": "hi"}, max_chars=10)
assert out["content"] == "hi"
assert out["truncated"] is False
# ---------------------------------------------------------------------------
# vanilla-converter fallback honors the torch.compile toggle
# ---------------------------------------------------------------------------
@pytest.mark.unit
def test_vanilla_converter_applies_inference_settings(monkeypatch, tmp_path):
"""The fallback builds its own DocumentConverter, so it must disable
torch.compile itself — the configured-parser path can't do it for it."""
import sys
import types
called = []
monkeypatch.setattr(
"application.parser.file.docling_parser._apply_inference_settings",
lambda: called.append(True),
)
class _Doc:
texts = []
tables = []
pages = {}
def export_to_markdown(self):
return "# md"
def export_to_dict(self):
return {"texts": []}
class _Converter:
def convert(self, *a, **k):
assert called == [True], "converter built before torch.compile was disabled"
return types.SimpleNamespace(document=_Doc())
fake_docling = types.ModuleType("docling")
fake_dc_module = types.ModuleType("docling.document_converter")
fake_dc_module.DocumentConverter = _Converter
fake_docling.document_converter = fake_dc_module
monkeypatch.setitem(sys.modules, "docling", fake_docling)
monkeypatch.setitem(sys.modules, "docling.document_converter", fake_dc_module)
path = tmp_path / "doc.pdf"
path.write_bytes(b"%PDF")
out = dr._docling_structured(path, ocr_enabled=False, include_tables=False, parser=None)
assert out["markdown"] == "# md"
assert called == [True]