Skip to content

feat: add dolphin #1772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docling/datamodel/pipeline_options_vlm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TransformersModelType(str, Enum):
AUTOMODEL = "automodel"
AUTOMODEL_VISION2SEQ = "automodel-vision2seq"
AUTOMODEL_CAUSALLM = "automodel-causallm"
AUTOMODEL_IMAGETEXTTOTEXT = "automodel-imagetexttotext"


class InlineVlmOptions(BaseVlmOptions):
Expand Down
12 changes: 12 additions & 0 deletions docling/models/vlm_models_inline/hf_transformers_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from transformers import (
AutoModel,
AutoModelForCausalLM,
AutoModelForImageTextToText,
AutoModelForVision2Seq,
AutoProcessor,
BitsAndBytesConfig,
Expand Down Expand Up @@ -91,6 +92,11 @@
== TransformersModelType.AUTOMODEL_VISION2SEQ
):
model_cls = AutoModelForVision2Seq
elif (

Check warning on line 95 in docling/models/vlm_models_inline/hf_transformers_model.py

View check run for this annotation

Codecov / codecov/patch

docling/models/vlm_models_inline/hf_transformers_model.py#L95

Added line #L95 was not covered by tests
self.vlm_options.transformers_model_type
== TransformersModelType.AUTOMODEL_IMAGETEXTTOTEXT
):
model_cls = AutoModelForImageTextToText

Check warning on line 99 in docling/models/vlm_models_inline/hf_transformers_model.py

View check run for this annotation

Codecov / codecov/patch

docling/models/vlm_models_inline/hf_transformers_model.py#L99

Added line #L99 was not covered by tests

self.processor = AutoProcessor.from_pretrained(
artifacts_path,
Expand Down Expand Up @@ -175,6 +181,12 @@
_log.debug(f"prompt for {self.vlm_options.repo_id}: {prompt}")

return prompt
if self.vlm_options.repo_id.lower().startswith("bytedance/dolphin"):
_log.debug("Using specialized prompt for dolphin")
# more info here https://huggingface.co/ByteDance/Dolphin
prompt = f"<s>{self.vlm_options.prompt} <Answer/>"

Check warning on line 187 in docling/models/vlm_models_inline/hf_transformers_model.py

View check run for this annotation

Codecov / codecov/patch

docling/models/vlm_models_inline/hf_transformers_model.py#L185-L187

Added lines #L185 - L187 were not covered by tests
_log.debug(f"prompt for {self.vlm_options.repo_id}: {prompt}")
return prompt

Check warning on line 189 in docling/models/vlm_models_inline/hf_transformers_model.py

View check run for this annotation

Codecov / codecov/patch

docling/models/vlm_models_inline/hf_transformers_model.py#L189

Added line #L189 was not covered by tests

messages = [
{
Expand Down