mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-11 22:28:31 +00:00
feat: Add granite-docling model (#2272)
* adding granite-docling preview Signed-off-by: Peter Staar <taa@zurich.ibm.com> * updated the model specs Signed-off-by: Peter Staar <taa@zurich.ibm.com> * typo Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * use granite-docling and add to the model downloader Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * update docs and README Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * Update final repo_ids for GraniteDocling Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * Update final repo_ids for GraniteDocling Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * Fix model name in CLI usage example Signed-off-by: Christoph Auer <60343111+cau-git@users.noreply.github.com> * Fix VLM model name in README.md Signed-off-by: Christoph Auer <60343111+cau-git@users.noreply.github.com> --------- Signed-off-by: Peter Staar <taa@zurich.ibm.com> Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> Signed-off-by: Christoph Auer <cau@zurich.ibm.com> Signed-off-by: Christoph Auer <60343111+cau-git@users.noreply.github.com> Co-authored-by: Peter Staar <taa@zurich.ibm.com> Co-authored-by: Michele Dolfi <dol@zurich.ibm.com>
This commit is contained in:
@@ -64,6 +64,8 @@ from docling.datamodel.vlm_model_specs import (
|
||||
GOT2_TRANSFORMERS,
|
||||
GRANITE_VISION_OLLAMA,
|
||||
GRANITE_VISION_TRANSFORMERS,
|
||||
GRANITEDOCLING_MLX,
|
||||
GRANITEDOCLING_TRANSFORMERS,
|
||||
SMOLDOCLING_MLX,
|
||||
SMOLDOCLING_TRANSFORMERS,
|
||||
SMOLDOCLING_VLLM,
|
||||
@@ -334,7 +336,7 @@ def convert( # noqa: C901
|
||||
vlm_model: Annotated[
|
||||
VlmModelType,
|
||||
typer.Option(..., help="Choose the VLM model to use with PDF or image files."),
|
||||
] = VlmModelType.SMOLDOCLING,
|
||||
] = VlmModelType.GRANITEDOCLING,
|
||||
asr_model: Annotated[
|
||||
AsrModelType,
|
||||
typer.Option(..., help="Choose the ASR model to use with audio/video files."),
|
||||
@@ -684,6 +686,18 @@ def convert( # noqa: C901
|
||||
"To run SmolDocling faster, please install mlx-vlm:\n"
|
||||
"pip install mlx-vlm"
|
||||
)
|
||||
elif vlm_model == VlmModelType.GRANITEDOCLING:
|
||||
pipeline_options.vlm_options = GRANITEDOCLING_TRANSFORMERS
|
||||
if sys.platform == "darwin":
|
||||
try:
|
||||
import mlx_vlm
|
||||
|
||||
pipeline_options.vlm_options = GRANITEDOCLING_MLX
|
||||
except ImportError:
|
||||
_log.warning(
|
||||
"To run GraniteDocling faster, please install mlx-vlm:\n"
|
||||
"pip install mlx-vlm"
|
||||
)
|
||||
elif vlm_model == VlmModelType.SMOLDOCLING_VLLM:
|
||||
pipeline_options.vlm_options = SMOLDOCLING_VLLM
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ class _AvailableModels(str, Enum):
|
||||
CODE_FORMULA = "code_formula"
|
||||
PICTURE_CLASSIFIER = "picture_classifier"
|
||||
SMOLVLM = "smolvlm"
|
||||
GRANITEDOCLING = "granitedocling"
|
||||
GRANITEDOCLING_MLX = "granitedocling_mlx"
|
||||
SMOLDOCLING = "smoldocling"
|
||||
SMOLDOCLING_MLX = "smoldocling_mlx"
|
||||
GRANITE_VISION = "granite_vision"
|
||||
@@ -108,6 +110,8 @@ def download(
|
||||
with_code_formula=_AvailableModels.CODE_FORMULA in to_download,
|
||||
with_picture_classifier=_AvailableModels.PICTURE_CLASSIFIER in to_download,
|
||||
with_smolvlm=_AvailableModels.SMOLVLM in to_download,
|
||||
with_granitedocling=_AvailableModels.GRANITEDOCLING in to_download,
|
||||
with_granitedocling_mlx=_AvailableModels.GRANITEDOCLING_MLX in to_download,
|
||||
with_smoldocling=_AvailableModels.SMOLDOCLING in to_download,
|
||||
with_smoldocling_mlx=_AvailableModels.SMOLDOCLING_MLX in to_download,
|
||||
with_granite_vision=_AvailableModels.GRANITE_VISION in to_download,
|
||||
|
||||
@@ -12,7 +12,7 @@ from pydantic import (
|
||||
)
|
||||
from typing_extensions import deprecated
|
||||
|
||||
from docling.datamodel import asr_model_specs
|
||||
from docling.datamodel import asr_model_specs, vlm_model_specs
|
||||
|
||||
# Import the following for backwards compatibility
|
||||
from docling.datamodel.accelerator_options import AcceleratorDevice, AcceleratorOptions
|
||||
@@ -290,7 +290,7 @@ class VlmPipelineOptions(PaginatedPipelineOptions):
|
||||
)
|
||||
# If True, text from backend will be used instead of generated text
|
||||
vlm_options: Union[InlineVlmOptions, ApiVlmOptions] = (
|
||||
smoldocling_vlm_conversion_options
|
||||
vlm_model_specs.GRANITEDOCLING_TRANSFORMERS
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,35 @@ from docling.datamodel.pipeline_options_vlm_model import (
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Granite-Docling
|
||||
GRANITEDOCLING_TRANSFORMERS = InlineVlmOptions(
|
||||
repo_id="ibm-granite/granite-docling-258M",
|
||||
prompt="Convert this page to docling.",
|
||||
response_format=ResponseFormat.DOCTAGS,
|
||||
inference_framework=InferenceFramework.TRANSFORMERS,
|
||||
transformers_model_type=TransformersModelType.AUTOMODEL_IMAGETEXTTOTEXT,
|
||||
supported_devices=[
|
||||
AcceleratorDevice.CPU,
|
||||
AcceleratorDevice.CUDA,
|
||||
],
|
||||
scale=2.0,
|
||||
temperature=0.0,
|
||||
max_new_tokens=8192,
|
||||
stop_strings=["</doctag>", "<|end_of_text|>"],
|
||||
)
|
||||
|
||||
GRANITEDOCLING_MLX = InlineVlmOptions(
|
||||
repo_id="ibm-granite/granite-docling-258M-mlx",
|
||||
prompt="Convert this page to docling.",
|
||||
response_format=ResponseFormat.DOCTAGS,
|
||||
inference_framework=InferenceFramework.MLX,
|
||||
supported_devices=[AcceleratorDevice.MPS],
|
||||
scale=2.0,
|
||||
temperature=0.0,
|
||||
max_new_tokens=8192,
|
||||
stop_strings=["</doctag>", "<|end_of_text|>"],
|
||||
)
|
||||
|
||||
# SmolDocling
|
||||
SMOLDOCLING_MLX = InlineVlmOptions(
|
||||
repo_id="ds4sd/SmolDocling-256M-preview-mlx-bf16",
|
||||
@@ -272,3 +301,4 @@ class VlmModelType(str, Enum):
|
||||
GRANITE_VISION_VLLM = "granite_vision_vllm"
|
||||
GRANITE_VISION_OLLAMA = "granite_vision_ollama"
|
||||
GOT_OCR_2 = "got_ocr_2"
|
||||
GRANITEDOCLING = "granite_docling"
|
||||
|
||||
@@ -10,6 +10,8 @@ from docling.datamodel.pipeline_options import (
|
||||
)
|
||||
from docling.datamodel.settings import settings
|
||||
from docling.datamodel.vlm_model_specs import (
|
||||
GRANITEDOCLING_MLX,
|
||||
GRANITEDOCLING_TRANSFORMERS,
|
||||
SMOLDOCLING_MLX,
|
||||
SMOLDOCLING_TRANSFORMERS,
|
||||
)
|
||||
@@ -34,6 +36,8 @@ def download_models(
|
||||
with_code_formula: bool = True,
|
||||
with_picture_classifier: bool = True,
|
||||
with_smolvlm: bool = False,
|
||||
with_granitedocling: bool = False,
|
||||
with_granitedocling_mlx: bool = False,
|
||||
with_smoldocling: bool = False,
|
||||
with_smoldocling_mlx: bool = False,
|
||||
with_granite_vision: bool = False,
|
||||
@@ -86,6 +90,24 @@ def download_models(
|
||||
progress=progress,
|
||||
)
|
||||
|
||||
if with_granitedocling:
|
||||
_log.info("Downloading GraniteDocling model...")
|
||||
download_hf_model(
|
||||
repo_id=GRANITEDOCLING_TRANSFORMERS.repo_id,
|
||||
local_dir=output_dir / GRANITEDOCLING_TRANSFORMERS.repo_cache_folder,
|
||||
force=force,
|
||||
progress=progress,
|
||||
)
|
||||
|
||||
if with_granitedocling_mlx:
|
||||
_log.info("Downloading GraniteDocling MLX model...")
|
||||
download_hf_model(
|
||||
repo_id=GRANITEDOCLING_MLX.repo_id,
|
||||
local_dir=output_dir / GRANITEDOCLING_MLX.repo_cache_folder,
|
||||
force=force,
|
||||
progress=progress,
|
||||
)
|
||||
|
||||
if with_smoldocling:
|
||||
_log.info("Downloading SmolDocling model...")
|
||||
download_hf_model(
|
||||
|
||||
Reference in New Issue
Block a user