Skip to content

Commit cdffb47

Browse files
authored
feat: Support for Python 3.14 (#2530)
* fix dependencies for py314 Signed-off-by: Michele Dolfi <[email protected]> * add metadata and CI tests Signed-off-by: Michele Dolfi <[email protected]> * add back gliner Signed-off-by: Michele Dolfi <[email protected]> * update error message about python 3.14 availability Signed-off-by: Michele Dolfi <[email protected]> * skip tests which cannot run on py 3.14 Signed-off-by: Michele Dolfi <[email protected]> * fix lint Signed-off-by: Michele Dolfi <[email protected]> * remove vllm from py 3.14 deps Signed-off-by: Michele Dolfi <[email protected]> * safe import for vllm Signed-off-by: Michele Dolfi <[email protected]> * update lock Signed-off-by: Michele Dolfi <[email protected]> * remove torch.compile() Signed-off-by: Michele Dolfi <[email protected]> * update checkbox results after docling-core changes Signed-off-by: Michele Dolfi <[email protected]> * cannot run mlx example in CI Signed-off-by: Michele Dolfi <[email protected]> * add test for rapidocr backends and skip onnxruntime on py3.14 Signed-off-by: Michele Dolfi <[email protected]> * fix other occurances of torch.compile() Signed-off-by: Michele Dolfi <[email protected]> * allow torch.compile for Python <3.14. proper support will be introduced with new torch releases Signed-off-by: Michele Dolfi <[email protected]> --------- Signed-off-by: Michele Dolfi <[email protected]>
1 parent 9a6fdf9 commit cdffb47

File tree

13 files changed

+2294
-1377
lines changed

13 files changed

+2294
-1377
lines changed

.github/workflows/checks.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ env:
2020
tests/test_asr_pipeline.py
2121
tests/test_threaded_pipeline.py
2222
PYTEST_TO_SKIP: |-
23-
EXAMPLES_TO_SKIP: '^(batch_convert|compare_vlm_models|minimal|minimal_vlm_pipeline|minimal_asr_pipeline|export_multimodal|custom_convert|develop_picture_enrichment|rapidocr_with_custom_models|offline_convert|pictures_description|pictures_description_api|vlm_pipeline_api_model|granitedocling_repetition_stopping)\.py$'
23+
EXAMPLES_TO_SKIP: '^(batch_convert|compare_vlm_models|minimal|minimal_vlm_pipeline|minimal_asr_pipeline|export_multimodal|custom_convert|develop_picture_enrichment|rapidocr_with_custom_models|offline_convert|pictures_description|pictures_description_api|vlm_pipeline_api_model|granitedocling_repetition_stopping|mlx_whisper_example)\.py$'
2424

2525
jobs:
2626
lint:
@@ -62,7 +62,7 @@ jobs:
6262
strategy:
6363
fail-fast: false
6464
matrix:
65-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
65+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
6666
steps:
6767
- uses: actions/checkout@v5
6868

@@ -129,7 +129,7 @@ jobs:
129129
strategy:
130130
fail-fast: false
131131
matrix:
132-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
132+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
133133
steps:
134134
- uses: actions/checkout@v5
135135

@@ -201,7 +201,7 @@ jobs:
201201
strategy:
202202
fail-fast: false
203203
matrix:
204-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
204+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
205205
steps:
206206
- uses: actions/checkout@v5
207207

docling/cli/main.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,15 @@ def convert( # noqa: C901
738738

739739
pipeline_options.vlm_options = SMOLDOCLING_MLX
740740
except ImportError:
741-
_log.warning(
742-
"To run SmolDocling faster, please install mlx-vlm:\n"
743-
"pip install mlx-vlm"
744-
)
741+
if sys.version_info < (3, 14):
742+
_log.warning(
743+
"To run SmolDocling faster, please install mlx-vlm:\n"
744+
"pip install mlx-vlm"
745+
)
746+
else:
747+
_log.warning(
748+
"You can run SmolDocling faster with MLX support, but it is unfortunately not yet available on Python 3.14."
749+
)
745750

746751
elif vlm_model == VlmModelType.GRANITEDOCLING:
747752
pipeline_options.vlm_options = GRANITEDOCLING_TRANSFORMERS
@@ -751,10 +756,16 @@ def convert( # noqa: C901
751756

752757
pipeline_options.vlm_options = GRANITEDOCLING_MLX
753758
except ImportError:
754-
_log.warning(
755-
"To run GraniteDocling faster, please install mlx-vlm:\n"
756-
"pip install mlx-vlm"
757-
)
759+
if sys.version_info < (3, 14):
760+
_log.warning(
761+
"To run GraniteDocling faster, please install mlx-vlm:\n"
762+
"pip install mlx-vlm"
763+
)
764+
else:
765+
_log.warning(
766+
"You can run GraniteDocling faster with MLX support, but it is unfortunately not yet available on Python 3.14."
767+
)
768+
758769
elif vlm_model == VlmModelType.SMOLDOCLING_VLLM:
759770
pipeline_options.vlm_options = SMOLDOCLING_VLLM
760771

docling/models/picture_description_vlm_model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import threading
23
from collections.abc import Iterable
34
from pathlib import Path
@@ -75,7 +76,10 @@ def __init__(
7576
else "sdpa"
7677
),
7778
)
78-
self.model = torch.compile(self.model) # type: ignore
79+
if sys.version_info < (3, 14):
80+
self.model = torch.compile(self.model) # type: ignore
81+
else:
82+
self.model.eval()
7983

8084
self.provenance = f"{self.options.repo_id}"
8185

docling/models/vlm_models_inline/hf_transformers_model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import importlib.metadata
22
import logging
3+
import sys
34
import time
45
from collections.abc import Iterable
56
from pathlib import Path
@@ -129,7 +130,10 @@ def __init__(
129130
trust_remote_code=vlm_options.trust_remote_code,
130131
revision=vlm_options.revision,
131132
)
132-
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
133+
if sys.version_info < (3, 14):
134+
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
135+
else:
136+
self.vlm_model.eval()
133137

134138
# Load generation config
135139
self.generation_config = GenerationConfig.from_pretrained(

docling/models/vlm_models_inline/mlx_model.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ def __init__(
5050
from mlx_vlm.prompt_utils import apply_chat_template # type: ignore
5151
from mlx_vlm.utils import load_config # type: ignore
5252
except ImportError:
53-
raise ImportError(
54-
"mlx-vlm is not installed. Please install it via `pip install mlx-vlm` to use MLX VLM models."
55-
)
53+
if sys.version_info < (3, 14):
54+
raise ImportError(
55+
"mlx-vlm is not installed. Please install it via `pip install mlx-vlm` to use MLX VLM models."
56+
)
57+
else:
58+
raise ImportError(
59+
"mlx-vlm is not installed. It is not yet available on Python 3.14."
60+
)
5661

5762
repo_cache_folder = vlm_options.repo_id.replace("/", "--")
5863

docling/models/vlm_models_inline/nuextract_transformers_model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import sys
23
import time
34
from collections.abc import Iterable
45
from pathlib import Path
@@ -153,7 +154,10 @@ def __init__(
153154
),
154155
trust_remote_code=vlm_options.trust_remote_code,
155156
)
156-
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
157+
if sys.version_info < (3, 14):
158+
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
159+
else:
160+
self.vlm_model.eval()
157161

158162
# Load generation config
159163
self.generation_config = GenerationConfig.from_pretrained(artifacts_path)

docling/models/vlm_models_inline/vllm_model.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import sys
23
import time
34
from collections.abc import Iterable
45
from pathlib import Path
@@ -100,7 +101,18 @@ def __init__(
100101
return
101102

102103
from transformers import AutoProcessor
103-
from vllm import LLM, SamplingParams
104+
105+
try:
106+
from vllm import LLM, SamplingParams
107+
except ImportError:
108+
if sys.version_info < (3, 14):
109+
raise ImportError(
110+
"vllm is not installed. Please install it via `pip install vllm`."
111+
)
112+
else:
113+
raise ImportError(
114+
"vllm is not installed. It is not yet available on Python 3.14."
115+
)
104116

105117
# Device selection
106118
self.device = decide_device(

docling/pipeline/asr_pipeline.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import re
4+
import sys
45
import tempfile
56
from io import BytesIO
67
from pathlib import Path
@@ -117,9 +118,15 @@ def __init__(
117118
try:
118119
import whisper # type: ignore
119120
except ImportError:
120-
raise ImportError(
121-
"whisper is not installed. Please install it via `pip install openai-whisper` or do `uv sync --extra asr`."
122-
)
121+
if sys.version_info < (3, 14):
122+
raise ImportError(
123+
"whisper is not installed. Please install it via `pip install openai-whisper` or do `uv sync --extra asr`."
124+
)
125+
else:
126+
raise ImportError(
127+
"whisper is not installed. Unfortunately its dependencies are not yet available for Python 3.14."
128+
)
129+
123130
self.asr_options = asr_options
124131
self.max_tokens = asr_options.max_new_tokens
125132
self.temperature = asr_options.temperature

pyproject.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ classifiers = [
3030
"Programming Language :: Python :: 3.11",
3131
"Programming Language :: Python :: 3.12",
3232
"Programming Language :: Python :: 3.13",
33+
"Programming Language :: Python :: 3.14",
3334
]
3435
readme = "README.md"
3536
authors = [
@@ -63,7 +64,7 @@ dependencies = [
6364
'pandas (>=2.1.4,<3.0.0)',
6465
'marko (>=2.1.2,<3.0.0)',
6566
'openpyxl (>=3.1.5,<4.0.0)',
66-
'lxml (>=4.0.0,<6.0.0)',
67+
'lxml (>=4.0.0,<7.0.0)',
6768
'pillow (>=10.0.0,<12.0.0)',
6869
'tqdm (>=4.65.0,<5.0.0)',
6970
'pluggy (>=1.0.0,<2.0.0)',
@@ -95,19 +96,19 @@ ocrmac = ['ocrmac (>=1.0.0,<2.0.0) ; sys_platform == "darwin"']
9596
vlm = [
9697
'transformers (>=4.46.0,<5.0.0)',
9798
'accelerate (>=1.2.1,<2.0.0)',
98-
'mlx-vlm (>=0.3.0,<1.0.0) ; python_version >= "3.10" and sys_platform == "darwin" and platform_machine == "arm64"',
99-
'vllm (>=0.10.0,<1.0.0) ; python_version >= "3.10" and sys_platform == "linux" and platform_machine == "x86_64"',
99+
'mlx-vlm (>=0.3.0,<1.0.0) ; python_version >= "3.10" and python_version < "3.14" and sys_platform == "darwin" and platform_machine == "arm64"',
100+
'vllm (>=0.10.0,<1.0.0) ; python_version >= "3.10" and python_version < "3.14" and sys_platform == "linux" and platform_machine == "x86_64"',
100101
"qwen-vl-utils>=0.0.11",
101102
]
102103
rapidocr = [
103-
'rapidocr (>=3.3,<4.0.0) ; python_version < "3.14"',
104-
'onnxruntime (>=1.7.0,<2.0.0)',
104+
'rapidocr (>=3.3,<4.0.0)',
105+
'onnxruntime (>=1.7.0,<2.0.0) ; python_version < "3.14"',
105106
# 'onnxruntime (>=1.7.0,<2.0.0) ; python_version >= "3.10"',
106107
# 'onnxruntime (>=1.7.0,<1.20.0) ; python_version < "3.10"',
107108
]
108109
asr = [
109-
'mlx-whisper>=0.4.3 ; python_version >= "3.10" and sys_platform == "darwin" and platform_machine == "arm64"',
110-
"openai-whisper>=20250625",
110+
'mlx-whisper>=0.4.3 ; python_version >= "3.10" and python_version < "3.14" and sys_platform == "darwin" and platform_machine == "arm64"',
111+
'openai-whisper>=20250625 ; python_version < "3.14"',
111112
]
112113

113114
[dependency-groups]
@@ -146,10 +147,10 @@ examples = [
146147
"langchain-milvus~=0.1",
147148
"langchain-text-splitters~=0.2",
148149
"modelscope>=1.29.0",
149-
"gliner>=0.2.21",
150+
'gliner>=0.2.21 ; python_version < "3.14"', # gliner depends on onnxruntime which is not available on py3.14
150151
]
151152
constraints = [
152-
'onnxruntime (>=1.7.0,<2.0.0) ; python_version >= "3.10"',
153+
'onnxruntime (>=1.7.0,<2.0.0) ; python_version >= "3.10" and python_version < "3.14"',
153154
'onnxruntime (>=1.7.0,<1.20.0) ; python_version < "3.10"',
154155
]
155156

tests/data/groundtruth/docling_v2/right_to_left_03.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
استاندارد اجباری است؟
1818

19-
بلی
19+
- [ ] بلی
2020

21-
خير
21+
- [x] خير
2222

2323
مرجع صادرکننده استاندارد
2424

2525
سازمان ملی استاندارد ايران
2626

2727
آيا توليدکننده محصول، استاندارد مذکور را اخذ نموده است؟
2828

29-
بلی خير
29+
- [x] بلی خير
3030

3131
## -3 پذيرش در بورس
3232

0 commit comments

Comments
 (0)