From c0847c97a7c9d73cbff1d1c75bc1e1f1b1bb8558 Mon Sep 17 00:00:00 2001 From: Michele Dolfi Date: Mon, 2 Jun 2025 10:45:46 +0200 Subject: [PATCH] use module import and remove MLX from non-darwin Signed-off-by: Michele Dolfi --- docs/examples/compare_vlm_models.py | 44 +++++++++++++-------------- docs/examples/minimal_vlm_pipeline.py | 5 +-- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/examples/compare_vlm_models.py b/docs/examples/compare_vlm_models.py index 5584a699..f9bd2dcd 100644 --- a/docs/examples/compare_vlm_models.py +++ b/docs/examples/compare_vlm_models.py @@ -5,6 +5,7 @@ # Their runtime as well output quality is compared. import json +import sys import time from pathlib import Path @@ -12,21 +13,12 @@ from docling_core.types.doc import DocItemLabel, ImageRefMode from docling_core.types.doc.document import DEFAULT_EXPORT_LABELS from tabulate import tabulate +from docling.datamodel import vlm_model_specs from docling.datamodel.base_models import InputFormat from docling.datamodel.pipeline_options import ( VlmPipelineOptions, ) -from docling.datamodel.vlm_model_specs import ( - GEMMA3_12B_MLX, - GRANITE_VISION_OLLAMA, - GRANITE_VISION_TRANSFORMERS, - PHI4_TRANSFORMERS, - PIXTRAL_12B_MLX, - PIXTRAL_12B_TRANSFORMERS, - QWEN25_VL_3B_MLX, - SMOLDOCLING_MLX, - SMOLDOCLING_TRANSFORMERS, -) +from docling.datamodel.pipeline_options_vlm_model import InferenceFramework from docling.document_converter import DocumentConverter, PdfFormatOption from docling.pipeline.vlm_pipeline import VlmPipeline @@ -117,20 +109,28 @@ if __name__ == "__main__": # pipeline_options.accelerator_options.device = AcceleratorDevice.CUDA # pipeline_options.accelerator_options.cuda_use_flash_attention2 = True - rows = [] - for vlm_options in [ + vlm_models = [ ## DocTags / SmolDocling models - SMOLDOCLING_TRANSFORMERS, - SMOLDOCLING_MLX, + vlm_model_specs.SMOLDOCLING_MLX, + vlm_model_specs.SMOLDOCLING_TRANSFORMERS, ## Markdown models (using MLX framework) - QWEN25_VL_3B_MLX, - PIXTRAL_12B_MLX, - GEMMA3_12B_MLX, + vlm_model_specs.QWEN25_VL_3B_MLX, + vlm_model_specs.PIXTRAL_12B_MLX, + vlm_model_specs.GEMMA3_12B_MLX, ## Markdown models (using Transformers framework) - GRANITE_VISION_TRANSFORMERS, - PHI4_TRANSFORMERS, - PIXTRAL_12B_TRANSFORMERS, - ]: + vlm_model_specs.GRANITE_VISION_TRANSFORMERS, + vlm_model_specs.PHI4_TRANSFORMERS, + vlm_model_specs.PIXTRAL_12B_TRANSFORMERS, + ] + + # Remove MLX models if not on Mac + if sys.platform != "darwin": + vlm_models = [ + m for m in vlm_models if m.inference_framework != InferenceFramework.MLX + ] + + rows = [] + for vlm_options in vlm_models: pipeline_options.vlm_options = vlm_options ## Set up pipeline for PDF or image inputs diff --git a/docs/examples/minimal_vlm_pipeline.py b/docs/examples/minimal_vlm_pipeline.py index 0ace6af9..666c0604 100644 --- a/docs/examples/minimal_vlm_pipeline.py +++ b/docs/examples/minimal_vlm_pipeline.py @@ -1,8 +1,8 @@ +from docling.datamodel import vlm_model_specs from docling.datamodel.base_models import InputFormat from docling.datamodel.pipeline_options import ( VlmPipelineOptions, ) -from docling.datamodel.vlm_model_specs import SMOLDOCLING_MLX from docling.document_converter import DocumentConverter, PdfFormatOption from docling.pipeline.vlm_pipeline import VlmPipeline @@ -26,9 +26,10 @@ print(doc.export_to_markdown()) ###### USING MACOS MPS ACCELERATOR +# For more options see the compare_vlm_models.py example. pipeline_options = VlmPipelineOptions( - vlm_options=SMOLDOCLING_MLX, + vlm_options=vlm_model_specs.SMOLDOCLING_MLX, ) converter = DocumentConverter(