Skip to content

Commit 3ef4525

Browse files
ryyhandolfim-ibm
andauthored
fix: transformers models lazy-loaded (#2826)
* fix(#2785): correct type hint for table_structure_options in PdfPipelineOptions Signed-off-by: ryyhan <dayel.rehan@gmail.com> * fix: make VLM dependencies optional and lazy load them Signed-off-by: ryyhan <dayel.rehan@gmail.com> * revert: remove accidental TableStructureOptions change from this branch Signed-off-by: ryyhan <dayel.rehan@gmail.com> * remove import exceptions Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> --------- Signed-off-by: ryyhan <dayel.rehan@gmail.com> Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> Co-authored-by: Michele Dolfi <dol@zurich.ibm.com>
1 parent cbc6537 commit 3ef4525

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

docling/models/code_formula_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from docling_core.types.doc.labels import CodeLanguageLabel
1515
from PIL import Image
1616
from pydantic import BaseModel
17-
from transformers import AutoModelForImageTextToText, AutoProcessor
1817

1918
from docling.datamodel.accelerator_options import AcceleratorDevice, AcceleratorOptions
2019
from docling.datamodel.base_models import ItemAndImageEnrichmentElement
@@ -105,6 +104,8 @@ def __init__(
105104
else:
106105
artifacts_path = artifacts_path / self._model_repo_folder
107106

107+
from transformers import AutoModelForImageTextToText, AutoProcessor
108+
108109
self._processor = AutoProcessor.from_pretrained(
109110
artifacts_path,
110111
)

docling/models/picture_description_vlm_model.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Optional, Type, Union
66

77
from PIL import Image
8-
from transformers import AutoModelForImageTextToText
98

109
from docling.datamodel.accelerator_options import AcceleratorOptions
1110
from docling.datamodel.pipeline_options import (
@@ -56,7 +55,11 @@ def __init__(
5655

5756
try:
5857
import torch
59-
from transformers import AutoModelForVision2Seq, AutoProcessor
58+
from transformers import (
59+
AutoModelForImageTextToText,
60+
AutoModelForVision2Seq,
61+
AutoProcessor,
62+
)
6063
except ImportError:
6164
raise ImportError(
6265
"transformers >=4.46 is not installed. Please install Docling with the required extras `pip install docling[vlm]`."

0 commit comments

Comments
 (0)