From cca05c45eaec154ae8470f9eb3577852d17773cd Mon Sep 17 00:00:00 2001 From: Christoph Auer <60343111+cau-git@users.noreply.github.com> Date: Fri, 18 Jul 2025 15:14:36 +0200 Subject: [PATCH 1/2] fix: Safe pipeline init, use device_map in transformers models (#1917) * Use device_map for transformer models Signed-off-by: Christoph Auer * Add accelerate Signed-off-by: Christoph Auer * Relax accelerate min version Signed-off-by: Christoph Auer * Make pipeline cache+init thread-safe Signed-off-by: Christoph Auer --------- Signed-off-by: Christoph Auer --- docling/document_converter.py | 25 +++++++++++-------- .../models/picture_description_vlm_model.py | 3 ++- pyproject.toml | 1 + uv.lock | 2 ++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docling/document_converter.py b/docling/document_converter.py index 1a0a9d75..f3bcb89e 100644 --- a/docling/document_converter.py +++ b/docling/document_converter.py @@ -1,6 +1,7 @@ import hashlib import logging import sys +import threading import time from collections.abc import Iterable, Iterator from functools import partial @@ -49,6 +50,7 @@ from docling.pipeline.standard_pdf_pipeline import StandardPdfPipeline from docling.utils.utils import chunkify _log = logging.getLogger(__name__) +_PIPELINE_CACHE_LOCK = threading.Lock() class FormatOption(BaseModel): @@ -315,17 +317,18 @@ class DocumentConverter: # Use a composite key to cache pipelines cache_key = (pipeline_class, options_hash) - if cache_key not in self.initialized_pipelines: - _log.info( - f"Initializing pipeline for {pipeline_class.__name__} with options hash {options_hash}" - ) - self.initialized_pipelines[cache_key] = pipeline_class( - pipeline_options=pipeline_options - ) - else: - _log.debug( - f"Reusing cached pipeline for {pipeline_class.__name__} with options hash {options_hash}" - ) + with _PIPELINE_CACHE_LOCK: + if cache_key not in self.initialized_pipelines: + _log.info( + f"Initializing pipeline for {pipeline_class.__name__} with options hash {options_hash}" + ) + self.initialized_pipelines[cache_key] = pipeline_class( + pipeline_options=pipeline_options + ) + else: + _log.debug( + f"Reusing cached pipeline for {pipeline_class.__name__} with options hash {options_hash}" + ) return self.initialized_pipelines[cache_key] diff --git a/docling/models/picture_description_vlm_model.py b/docling/models/picture_description_vlm_model.py index 63c0af8a..a2d2f290 100644 --- a/docling/models/picture_description_vlm_model.py +++ b/docling/models/picture_description_vlm_model.py @@ -65,6 +65,7 @@ class PictureDescriptionVlmModel( self.processor = AutoProcessor.from_pretrained(artifacts_path) self.model = AutoModelForVision2Seq.from_pretrained( artifacts_path, + device_map=self.device, torch_dtype=torch.bfloat16, _attn_implementation=( "flash_attention_2" @@ -72,7 +73,7 @@ class PictureDescriptionVlmModel( and accelerator_options.cuda_use_flash_attention2 else "eager" ), - ).to(self.device) + ) self.provenance = f"{self.options.repo_id}" diff --git a/pyproject.toml b/pyproject.toml index 65919200..3450458d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,7 @@ dependencies = [ 'scipy (>=1.6.0,<2.0.0)', # 'scipy (>=1.6.0,<2.0.0) ; python_version >= "3.10"', # 'scipy (>=1.6.0,<1.14.0) ; python_version < "3.10"', + "accelerate>=1.0.0,<2", ] [project.urls] diff --git a/uv.lock b/uv.lock index 76e71334..e3312cbb 100644 --- a/uv.lock +++ b/uv.lock @@ -809,6 +809,7 @@ name = "docling" version = "2.41.0" source = { editable = "." } dependencies = [ + { name = "accelerate" }, { name = "beautifulsoup4" }, { name = "certifi" }, { name = "docling-core", extra = ["chunking"] }, @@ -902,6 +903,7 @@ examples = [ [package.metadata] requires-dist = [ + { name = "accelerate", specifier = ">=1.0.0,<2" }, { name = "accelerate", marker = "extra == 'vlm'", specifier = ">=1.2.1,<2.0.0" }, { name = "beautifulsoup4", specifier = ">=4.12.3,<5.0.0" }, { name = "certifi", specifier = ">=2024.7.4" }, From 7561be537a518a55cdec5cf558133b60ed73ecf4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 18 Jul 2025 15:34:59 +0000 Subject: [PATCH 2/2] chore: bump version to 2.42.0 [skip ci] --- CHANGELOG.md | 17 +++++++++++++++++ pyproject.toml | 2 +- uv.lock | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c01e9538..6a39a319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## [v2.42.0](https://github.com/docling-project/docling/releases/tag/v2.42.0) - 2025-07-18 + +### Feature + +* Add option to control empty clusters in layout postprocessing ([#1940](https://github.com/docling-project/docling/issues/1940)) ([`a436be7`](https://github.com/docling-project/docling/commit/a436be73676101cc9461a17ae7a9ae72316a5096)) + +### Fix + +* Safe pipeline init, use device_map in transformers models ([#1917](https://github.com/docling-project/docling/issues/1917)) ([`cca05c4`](https://github.com/docling-project/docling/commit/cca05c45eaec154ae8470f9eb3577852d17773cd)) +* Fix HTML table parser and JATS backend bugs ([#1948](https://github.com/docling-project/docling/issues/1948)) ([`e1e3053`](https://github.com/docling-project/docling/commit/e1e305369552b82d3f09f0c113ea8b54d5c90658)) +* KeyError: 'fPr' when processing latex fractions in DOCX files ([#1926](https://github.com/docling-project/docling/issues/1926)) ([`95e7096`](https://github.com/docling-project/docling/commit/95e70962f1d7cf1f339a88fde9c907111e194726)) +* Change granite vision model URL from preview to stable version ([#1925](https://github.com/docling-project/docling/issues/1925)) ([`c5fb353`](https://github.com/docling-project/docling/commit/c5fb353f109dfe79b51c201ebb1ff33fceeae34a)) + +### Documentation + +* Fix typos ([#1943](https://github.com/docling-project/docling/issues/1943)) ([`d6d2dbe`](https://github.com/docling-project/docling/commit/d6d2dbe2f99bd965c1bc8eec3d332d0acf731189)) + ## [v2.41.0](https://github.com/docling-project/docling/releases/tag/v2.41.0) - 2025-07-10 ### Feature diff --git a/pyproject.toml b/pyproject.toml index 3450458d..72a8bfa2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "docling" -version = "2.41.0" # DO NOT EDIT, updated automatically +version = "2.42.0" # DO NOT EDIT, updated automatically description = "SDK and CLI for parsing PDF, DOCX, HTML, and more, to a unified document representation for powering downstream workflows such as gen AI applications." license = "MIT" keywords = [ diff --git a/uv.lock b/uv.lock index e3312cbb..6fb6e572 100644 --- a/uv.lock +++ b/uv.lock @@ -806,7 +806,7 @@ wheels = [ [[package]] name = "docling" -version = "2.41.0" +version = "2.42.0" source = { editable = "." } dependencies = [ { name = "accelerate" },