Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 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
5 changes: 5 additions & 0 deletions docs/features/multimodal_inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ You must enable this feature via `enable_mm_embeds=True`.
The vLLM engine may crash if incorrect shape of embeddings is passed.
Only enable this flag for trusted users!

!!! note
The [Transformers modeling backend](../models/supported_models.md#transformers) does not support this feature.
Passing pre-computed embeddings skips the Hugging Face processor, which is what provides the extra fields
the backend needs to locate the placeholders in the prompt.

#### Image Embeddings

??? code
Expand Down
23 changes: 23 additions & 0 deletions tests/models/multimodal/processing/test_transformers_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from vllm.assets.image import ImageAsset
from vllm.config import ModelConfig
from vllm.multimodal import MULTIMODAL_REGISTRY
from vllm.multimodal.cache import MultiModalProcessorOnlyCache


@pytest.mark.parametrize("model_id", ["llava-hf/llava-onevision-qwen2-0.5b-ov-hf"])
Expand Down Expand Up @@ -77,3 +78,25 @@ def test_image_multiple_inputs():

assert len(result["mm_placeholders"]["image"]) == 2
assert len(result["mm_kwargs"]["image"]) == 2


@pytest.mark.parametrize(
"model_id",
["google/gemma-3-4b-it", "llava-hf/llava-onevision-qwen2-0.5b-ov-hf"],
)
def test_image_cached_apply(model_id):
model_config = ModelConfig(model=model_id, model_impl="transformers")
cache = MultiModalProcessorOnlyCache(model_config)
mm_processor = MULTIMODAL_REGISTRY.create_processor(model_config, cache=cache)

image = ImageAsset("cherry_blossom").pil_image
image_token = mm_processor.info.get_hf_processor().image_token
prompt = f"{image_token} What is the content of this image?"

for _ in range(2):
result = mm_processor(
prompt=prompt,
mm_items=mm_processor.info.parse_mm_data({"image": image}),
hf_processor_mm_kwargs={},
)
assert len(result["mm_placeholders"]["image"]) == 1
Comment thread
hmellor marked this conversation as resolved.
Loading
Loading