mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-11 22:28:31 +00:00
feat: Support for Python 3.14 (#2530)
* fix dependencies for py314 Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * add metadata and CI tests Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * add back gliner Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * update error message about python 3.14 availability Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * skip tests which cannot run on py 3.14 Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * fix lint Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * remove vllm from py 3.14 deps Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * safe import for vllm Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * update lock Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * remove torch.compile() Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * update checkbox results after docling-core changes Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * cannot run mlx example in CI Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * add test for rapidocr backends and skip onnxruntime on py3.14 Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * fix other occurances of torch.compile() Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * allow torch.compile for Python <3.14. proper support will be introduced with new torch releases Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> --------- Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
This commit is contained in:
@@ -738,10 +738,15 @@ def convert( # noqa: C901
|
||||
|
||||
pipeline_options.vlm_options = SMOLDOCLING_MLX
|
||||
except ImportError:
|
||||
_log.warning(
|
||||
"To run SmolDocling faster, please install mlx-vlm:\n"
|
||||
"pip install mlx-vlm"
|
||||
)
|
||||
if sys.version_info < (3, 14):
|
||||
_log.warning(
|
||||
"To run SmolDocling faster, please install mlx-vlm:\n"
|
||||
"pip install mlx-vlm"
|
||||
)
|
||||
else:
|
||||
_log.warning(
|
||||
"You can run SmolDocling faster with MLX support, but it is unfortunately not yet available on Python 3.14."
|
||||
)
|
||||
|
||||
elif vlm_model == VlmModelType.GRANITEDOCLING:
|
||||
pipeline_options.vlm_options = GRANITEDOCLING_TRANSFORMERS
|
||||
@@ -751,10 +756,16 @@ def convert( # noqa: C901
|
||||
|
||||
pipeline_options.vlm_options = GRANITEDOCLING_MLX
|
||||
except ImportError:
|
||||
_log.warning(
|
||||
"To run GraniteDocling faster, please install mlx-vlm:\n"
|
||||
"pip install mlx-vlm"
|
||||
)
|
||||
if sys.version_info < (3, 14):
|
||||
_log.warning(
|
||||
"To run GraniteDocling faster, please install mlx-vlm:\n"
|
||||
"pip install mlx-vlm"
|
||||
)
|
||||
else:
|
||||
_log.warning(
|
||||
"You can run GraniteDocling faster with MLX support, but it is unfortunately not yet available on Python 3.14."
|
||||
)
|
||||
|
||||
elif vlm_model == VlmModelType.SMOLDOCLING_VLLM:
|
||||
pipeline_options.vlm_options = SMOLDOCLING_VLLM
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
import threading
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
@@ -75,7 +76,10 @@ class PictureDescriptionVlmModel(
|
||||
else "sdpa"
|
||||
),
|
||||
)
|
||||
self.model = torch.compile(self.model) # type: ignore
|
||||
if sys.version_info < (3, 14):
|
||||
self.model = torch.compile(self.model) # type: ignore
|
||||
else:
|
||||
self.model.eval()
|
||||
|
||||
self.provenance = f"{self.options.repo_id}"
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import importlib.metadata
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
@@ -129,7 +130,10 @@ class HuggingFaceTransformersVlmModel(BaseVlmPageModel, HuggingFaceModelDownload
|
||||
trust_remote_code=vlm_options.trust_remote_code,
|
||||
revision=vlm_options.revision,
|
||||
)
|
||||
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
|
||||
if sys.version_info < (3, 14):
|
||||
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
|
||||
else:
|
||||
self.vlm_model.eval()
|
||||
|
||||
# Load generation config
|
||||
self.generation_config = GenerationConfig.from_pretrained(
|
||||
|
||||
@@ -50,9 +50,14 @@ class HuggingFaceMlxModel(BaseVlmPageModel, HuggingFaceModelDownloadMixin):
|
||||
from mlx_vlm.prompt_utils import apply_chat_template # type: ignore
|
||||
from mlx_vlm.utils import load_config # type: ignore
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"mlx-vlm is not installed. Please install it via `pip install mlx-vlm` to use MLX VLM models."
|
||||
)
|
||||
if sys.version_info < (3, 14):
|
||||
raise ImportError(
|
||||
"mlx-vlm is not installed. Please install it via `pip install mlx-vlm` to use MLX VLM models."
|
||||
)
|
||||
else:
|
||||
raise ImportError(
|
||||
"mlx-vlm is not installed. It is not yet available on Python 3.14."
|
||||
)
|
||||
|
||||
repo_cache_folder = vlm_options.repo_id.replace("/", "--")
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
@@ -153,7 +154,10 @@ class NuExtractTransformersModel(BaseVlmModel, HuggingFaceModelDownloadMixin):
|
||||
),
|
||||
trust_remote_code=vlm_options.trust_remote_code,
|
||||
)
|
||||
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
|
||||
if sys.version_info < (3, 14):
|
||||
self.vlm_model = torch.compile(self.vlm_model) # type: ignore
|
||||
else:
|
||||
self.vlm_model.eval()
|
||||
|
||||
# Load generation config
|
||||
self.generation_config = GenerationConfig.from_pretrained(artifacts_path)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
@@ -100,7 +101,18 @@ class VllmVlmModel(BaseVlmPageModel, HuggingFaceModelDownloadMixin):
|
||||
return
|
||||
|
||||
from transformers import AutoProcessor
|
||||
from vllm import LLM, SamplingParams
|
||||
|
||||
try:
|
||||
from vllm import LLM, SamplingParams
|
||||
except ImportError:
|
||||
if sys.version_info < (3, 14):
|
||||
raise ImportError(
|
||||
"vllm is not installed. Please install it via `pip install vllm`."
|
||||
)
|
||||
else:
|
||||
raise ImportError(
|
||||
"vllm is not installed. It is not yet available on Python 3.14."
|
||||
)
|
||||
|
||||
# Device selection
|
||||
self.device = decide_device(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
@@ -117,9 +118,15 @@ class _NativeWhisperModel:
|
||||
try:
|
||||
import whisper # type: ignore
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"whisper is not installed. Please install it via `pip install openai-whisper` or do `uv sync --extra asr`."
|
||||
)
|
||||
if sys.version_info < (3, 14):
|
||||
raise ImportError(
|
||||
"whisper is not installed. Please install it via `pip install openai-whisper` or do `uv sync --extra asr`."
|
||||
)
|
||||
else:
|
||||
raise ImportError(
|
||||
"whisper is not installed. Unfortunately its dependencies are not yet available for Python 3.14."
|
||||
)
|
||||
|
||||
self.asr_options = asr_options
|
||||
self.max_tokens = asr_options.max_new_tokens
|
||||
self.temperature = asr_options.temperature
|
||||
|
||||
Reference in New Issue
Block a user