[Multimodal] Type dummy options per modality (#57576)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
56cac80b14
commit
8a5cf54387
@@ -25,6 +25,7 @@ import torch
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
from tests.models.registry import HF_EXAMPLE_MODELS
|
||||
from vllm.config.multimodal import MultiModalDummyOptions
|
||||
|
||||
|
||||
class MockAudioFlamingo3Config(PretrainedConfig):
|
||||
@@ -127,7 +128,7 @@ def test_dummy_data_generation(mock_ctx):
|
||||
builder = AudioFlamingo3DummyInputsBuilder(info)
|
||||
|
||||
mm_counts = {"audio": 2}
|
||||
dummy_data = builder.get_dummy_mm_data(100, mm_counts, {})
|
||||
dummy_data = builder.get_dummy_mm_data(100, mm_counts, MultiModalDummyOptions())
|
||||
|
||||
assert "audio" in dummy_data
|
||||
assert len(dummy_data["audio"]) == 2
|
||||
|
||||
@@ -13,6 +13,7 @@ from vllm.config.multimodal import (
|
||||
AudioDummyOptions,
|
||||
BaseDummyOptions,
|
||||
ImageDummyOptions,
|
||||
MultiModalDummyOptions,
|
||||
VideoDummyOptions,
|
||||
)
|
||||
from vllm.inputs import MultiModalDataDict, MultiModalInput
|
||||
@@ -174,7 +175,7 @@ def get_token_prompt(
|
||||
inputs = dummy_inputs.get_dummy_processor_inputs(
|
||||
model_config.max_model_len,
|
||||
mm_counts,
|
||||
mm_options={},
|
||||
mm_options=MultiModalDummyOptions(),
|
||||
# Assume all Mistral models define this extra argument
|
||||
mm_data=mm_data, # type: ignore[call-arg]
|
||||
)
|
||||
@@ -182,7 +183,7 @@ def get_token_prompt(
|
||||
inputs = dummy_inputs.get_dummy_processor_inputs(
|
||||
model_config.max_model_len,
|
||||
mm_counts,
|
||||
mm_options={},
|
||||
mm_options=MultiModalDummyOptions(),
|
||||
)
|
||||
|
||||
if not isinstance(inputs.prompt, list):
|
||||
@@ -278,10 +279,12 @@ def _test_processing_correctness(
|
||||
return BaseDummyOptions(count=count)
|
||||
|
||||
# Assign normalized DummyOptions to the model config
|
||||
model_config.get_multimodal_config().limit_per_prompt = {
|
||||
modality: _to_dummy_options(modality, count)
|
||||
for modality, count in limit_mm_per_prompt_ints.items()
|
||||
}
|
||||
model_config.get_multimodal_config().limit_per_prompt = MultiModalDummyOptions(
|
||||
{
|
||||
modality: _to_dummy_options(modality, count)
|
||||
for modality, count in limit_mm_per_prompt_ints.items()
|
||||
}
|
||||
)
|
||||
|
||||
baseline_processor = factories.build_processor(ctx, cache=None)
|
||||
cached_processor = factories.build_processor(ctx, cache=cache)
|
||||
|
||||
@@ -6,7 +6,7 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from vllm.config.multimodal import VideoDummyOptions
|
||||
from vllm.config.multimodal import MultiModalDummyOptions, VideoDummyOptions
|
||||
from vllm.model_executor.models.molmo2 import (
|
||||
Molmo2DummyInputsBuilder,
|
||||
build_flat_image_bool_length,
|
||||
@@ -83,7 +83,9 @@ def test_dummy_video_num_frames_override_honors_min_of_two(
|
||||
data = builder.get_dummy_mm_data(
|
||||
seq_len=128,
|
||||
mm_counts={"image": 0, "video": 1},
|
||||
mm_options={"video": VideoDummyOptions(num_frames=num_frames_override)},
|
||||
mm_options=MultiModalDummyOptions(
|
||||
video=VideoDummyOptions(num_frames=num_frames_override)
|
||||
),
|
||||
)
|
||||
|
||||
video, _metadata = data["video"][0]
|
||||
|
||||
@@ -12,6 +12,7 @@ import numpy as np
|
||||
import pytest
|
||||
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.config.multimodal import MultiModalDummyOptions
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
|
||||
from ...registry import HF_EXAMPLE_MODELS
|
||||
@@ -339,7 +340,9 @@ def test_dummy_video_spreads_budget_when_frame_cap_enabled(model_id: str) -> Non
|
||||
limit_mm_per_prompt={"image": 0, "video": 1},
|
||||
)
|
||||
capped = MULTIMODAL_REGISTRY.create_processor(capped_ctx.model_config)
|
||||
capped_dummy = capped.dummy_inputs.get_dummy_mm_data(1024, {"video": 1}, {})
|
||||
capped_dummy = capped.dummy_inputs.get_dummy_mm_data(
|
||||
1024, {"video": 1}, MultiModalDummyOptions()
|
||||
)
|
||||
capped_frames = capped_dummy["video"][0][0].shape[0]
|
||||
assert capped_frames == 16, (
|
||||
f"Expected the dummy to spread the budget over 16 frames, got {capped_frames}"
|
||||
@@ -351,7 +354,9 @@ def test_dummy_video_spreads_budget_when_frame_cap_enabled(model_id: str) -> Non
|
||||
limit_mm_per_prompt={"image": 0, "video": 1},
|
||||
)
|
||||
uncapped = MULTIMODAL_REGISTRY.create_processor(uncapped_ctx.model_config)
|
||||
uncapped_dummy = uncapped.dummy_inputs.get_dummy_mm_data(1024, {"video": 1}, {})
|
||||
uncapped_dummy = uncapped.dummy_inputs.get_dummy_mm_data(
|
||||
1024, {"video": 1}, MultiModalDummyOptions()
|
||||
)
|
||||
uncapped_frames = uncapped_dummy["video"][0][0].shape[0]
|
||||
assert uncapped_frames == 2, (
|
||||
f"Expected the uncapped dummy to keep 2 frames, got {uncapped_frames}"
|
||||
|
||||
@@ -18,6 +18,7 @@ from vllm.config.multimodal import (
|
||||
AudioDummyOptions,
|
||||
BaseDummyOptions,
|
||||
ImageDummyOptions,
|
||||
MultiModalDummyOptions,
|
||||
VideoDummyOptions,
|
||||
)
|
||||
from vllm.distributed import (
|
||||
@@ -98,7 +99,7 @@ def create_batched_mm_kwargs(
|
||||
processor_inputs = dummy_inputs.get_dummy_processor_inputs(
|
||||
seq_len=model_config.max_model_len,
|
||||
mm_counts=mm_counts,
|
||||
mm_options={},
|
||||
mm_options=MultiModalDummyOptions(),
|
||||
)
|
||||
mm_items = processor_inputs.mm_data_items
|
||||
resized_mm_data = {
|
||||
@@ -248,10 +249,12 @@ def test_model_tensor_schema(model_id: str):
|
||||
return AudioDummyOptions(count=count)
|
||||
return BaseDummyOptions(count=count)
|
||||
|
||||
model_config.get_multimodal_config().limit_per_prompt = {
|
||||
modality: _to_dummy_options(modality, count)
|
||||
for modality, count in limit_mm_per_prompt.items()
|
||||
}
|
||||
model_config.get_multimodal_config().limit_per_prompt = MultiModalDummyOptions(
|
||||
{
|
||||
modality: _to_dummy_options(modality, count)
|
||||
for modality, count in limit_mm_per_prompt.items()
|
||||
}
|
||||
)
|
||||
processor = factories.build_processor(ctx, cache=None)
|
||||
|
||||
with initialize_dummy_model(model_cls, model_config) as model:
|
||||
|
||||
Reference in New Issue
Block a user