Skip to content
2 changes: 1 addition & 1 deletion tests/models/multimodal/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# longer re-exports the typing aliases, so executing that module raises NameError.
# TODO: Remove once the checkpoint fixes its imports.
if not hasattr(F, "List"):
F.List = list
F.List = list # type: ignore[attr-defined]
6 changes: 3 additions & 3 deletions tests/models/multimodal/generation/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def _granite4_vision_vllm_to_hf_output(vllm_output, model):
img_idx_to_prompt=lambda idx: "(<image>./</image>)\n",
max_model_len=4096,
max_num_seqs=2,
get_stop_token_ids=lambda tok: [tok.eos_id, tok.eot_id],
get_stop_token_ids=lambda tok: [getattr(tok, "eos_id"), getattr(tok, "eot_id")], # noqa: B009
hf_output_post_proc=model_utils.minicpmv_trunc_hf_output,
patch_hf_runner=model_utils.minicpmv_25_patch_hf_runner,
),
Expand Down Expand Up @@ -927,7 +927,7 @@ def _granite4_vision_vllm_to_hf_output(vllm_output, model):
auto_cls=AutoModelForImageTextToText,
vllm_output_post_proc=model_utils.llava_image_vllm_to_hf_output,
marks=multi_gpu_marks(num_gpus=2),
**COMMON_BROADCAST_SETTINGS, # type: ignore
**COMMON_BROADCAST_SETTINGS,
),
"llava_next-broadcast": VLMTestInfo(
models=["llava-hf/llava-v1.6-mistral-7b-hf"],
Expand All @@ -936,7 +936,7 @@ def _granite4_vision_vllm_to_hf_output(vllm_output, model):
auto_cls=AutoModelForImageTextToText,
vllm_output_post_proc=model_utils.llava_image_vllm_to_hf_output,
marks=multi_gpu_marks(num_gpus=2),
**COMMON_BROADCAST_SETTINGS, # type: ignore
**COMMON_BROADCAST_SETTINGS,
),
### Custom input edge-cases for specific models
"intern_vl-diff-patches": VLMTestInfo(
Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/generation/test_granite_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_models(
hf_runner,
vllm_runner,
[
([HF_AUDIO_PROMPT], [audio]),
([HF_AUDIO_PROMPT], [(audio, int(sr))]),
],
model,
dtype=dtype,
Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/generation/test_maverick.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def save_weights_to_safetensors(
print(f"Saved shard {i + 1}/{len(shards)}: {filename}")

# Create index file
index_data = {
index_data: dict[str, Any] = {
"metadata": {
"total_size": sum(
tensor.numel() * tensor.element_size() for tensor in weights.values()
Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/generation/test_mm_prefix_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _get_hf_prefill_hidden(hf_model: HfRunner, image: Any):
inputs = hf_model.get_inputs([PROMPT], images=[image])[0]
with torch.no_grad():
outputs = hf_model.model.model(
**hf_model.wrap_device(inputs),
**hf_model.wrap_device(dict(inputs)),
use_cache=False,
)
return outputs.last_hidden_state[0].detach().float().cpu()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_hf_logprobs_from_logits(
outputs = []
for model_inputs in inputs:
generated = hf_model.model.generate(
**hf_model.wrap_device(model_inputs),
**hf_model.wrap_device(dict(model_inputs)),
do_sample=False,
max_new_tokens=max_tokens,
output_logits=True,
Expand All @@ -51,7 +51,9 @@ def generate_hf_logprobs_from_logits(
}
)
token_ids = generated.sequences[0, -len(logprobs) :].tolist()
outputs.append((token_ids, hf_model.tokenizer.decode(token_ids), logprobs))
decoded = hf_model.tokenizer.decode(token_ids)
assert isinstance(decoded, str)
outputs.append((token_ids, decoded, logprobs))
return outputs


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@


def test_parse_mtp_config_routes_only_causal_prefix_architecture() -> None:
config = PreTrainedConfig(
architectures=["RadioMBartPrefixForCausalLM"],
decoder=PreTrainedConfig(causal_vision_prefix=True, vocab_size=8, d_model=4),
)
config = PreTrainedConfig(architectures=["RadioMBartPrefixForCausalLM"])
config.decoder = PreTrainedConfig()
config.decoder.causal_vision_prefix = True
config.decoder.vocab_size = 8
config.decoder.d_model = 4

draft = SpeculativeConfig.hf_config_override(config)

Expand Down
2 changes: 2 additions & 0 deletions tests/models/multimodal/generation/test_qwen2_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def batch_make_image_embeddings(
image_processor = processor.image_processor

mm_config = llm.get_llm().model_config.multimodal_config
assert mm_config is not None
mm_kwargs = mm_config.merge_mm_processor_kwargs({})
preprocess_result = image_processor.preprocess(
images=images, return_tensors="pt", **mm_kwargs
Expand Down Expand Up @@ -211,6 +212,7 @@ def batch_make_video_embeddings(
video_processor = processor.video_processor

mm_config = llm.get_llm().model_config.multimodal_config
assert mm_config is not None
mm_kwargs = mm_config.merge_mm_processor_kwargs({})
preprocess_result = video_processor.preprocess(
videos=videos, return_tensors="pt", **mm_kwargs
Expand Down
4 changes: 2 additions & 2 deletions tests/models/multimodal/generation/test_ultravox.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

MULTI_AUDIO_PROMPT = "Describe each of the audios above."

AudioTuple = tuple[np.ndarray, int]
AudioTuple = tuple[np.ndarray, float]

VLLM_PLACEHOLDER = "<|audio|>"
HF_PLACEHOLDER = "<|audio|>"
Expand Down Expand Up @@ -92,7 +92,7 @@ def _get_prompt(audio_count, question, placeholder):

def run_multi_audio_test(
vllm_runner: type[VllmRunner],
prompts_and_audios: list[tuple[str, list[AudioTuple]]],
prompts_and_audios: list[tuple[str | list[int], list[AudioTuple]]],
model: str,
*,
dtype: str,
Expand Down
5 changes: 3 additions & 2 deletions tests/models/multimodal/generation/test_vit_cudagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class VitCudagraphTestConfig:

def params_with_marks(
configs: dict[str, VitCudagraphTestConfig],
) -> list[pytest.param]:
) -> list[object]:
return [
pytest.param(model_id, marks=cfg.marks) for model_id, cfg in configs.items()
]
Expand Down Expand Up @@ -520,6 +520,7 @@ def test_vit_cudagraph_video(model_id, vllm_runner, video_assets):
"baby_reading": config.video_prompt, # type: ignore[typeddict-item]
}
)
sampled_vids: list
if config.needs_video_metadata:
sampled_vids = [
sample_frames_with_video_metadata(
Expand Down Expand Up @@ -576,7 +577,7 @@ def _check_eonly_encoder_outputs(worker, batches):
for batch in batches:
kwargs = {key: value.to(runner.device) for key, value in batch.items()}
actual = manager.execute(kwargs)
expected = runner.model.embed_multimodal(**kwargs)
expected = getattr(runner.model, "embed_multimodal")(**kwargs) # noqa: B009
assert len(actual) == len(expected)
for output, reference in zip(actual, expected):
assert torch.isfinite(output).all()
Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/generation/test_voxtral.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_models_with_multiple_audios(
vllm_prompt = _get_prompt(audio_assets, MULTI_AUDIO_PROMPT)
run_multi_audio_test(
vllm_runner,
[(vllm_prompt, [a.audio_and_sample_rate for a in audio_assets])], # type: ignore[list-item]
[(vllm_prompt, [a.audio_and_sample_rate for a in audio_assets])],
MODEL_NAME,
dtype=dtype,
max_tokens=max_tokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def async_engine(request):
def _build_inputs(
audio_assets: list[AudioAsset], tokenizer: MistralTokenizer
) -> tuple[list[dict], list[SamplingParams]]:
audio_config = tokenizer.instruct_tokenizer.tokenizer.audio
audio_config = getattr(tokenizer.instruct_tokenizer.tokenizer, "audio") # noqa: B009
inputs = []
sampling_params = []
for audio_asset in audio_assets:
Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/generation/vlm_utils/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def build_embedding_inputs_from_test_info(
images = [asset.pil_image for asset in image_assets]
embeds = test_info.convert_assets_to_embeddings(image_assets)
if test_info.dtype != "auto":
dtype = getattr(torch, test_info.dtype) # type: ignore
dtype = getattr(torch, test_info.dtype)
embeds = [e.to(dtype=dtype) for e in embeds]
assert len(images) == len(model_prompts)

Expand Down
26 changes: 17 additions & 9 deletions tests/models/multimodal/generation/vlm_utils/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
GenerationMixin,
)
from transformers.masking_utils import create_causal_mask
from transformers.utils import ModelOutput
from transformers.video_utils import VideoMetadata

from vllm.logprobs import SampleLogprobs
Expand Down Expand Up @@ -105,7 +106,9 @@ def _llava_vllm_to_hf_output(
hf_output_str = output_str[1:] if output_str[0] == " " else output_str

if hf_output_ids[-1] == eos_token_id:
hf_output_str = hf_output_str + tokenizer.decode(eos_token_id)
decoded_eos = tokenizer.decode(eos_token_id)
assert isinstance(decoded_eos, str)
hf_output_str = hf_output_str + decoded_eos

return hf_output_ids, hf_output_str, out_logprobs

Expand Down Expand Up @@ -137,7 +140,9 @@ def llava_onevision_vllm_to_hf_output(

hf_output_str = output_str
if hf_output_ids[-1] == eos_token_id:
hf_output_str = hf_output_str + tokenizer.decode(eos_token_id)
decoded_eos = tokenizer.decode(eos_token_id)
assert isinstance(decoded_eos, str)
hf_output_str = hf_output_str + decoded_eos

return hf_output_ids, hf_output_str, out_logprobs

Expand Down Expand Up @@ -179,7 +184,9 @@ def paligemma_vllm_to_hf_output(vllm_output: RunnerOutput, model: str) -> Runner
hf_output_str = output_str

if hf_output_ids[-1] == eos_token_id:
hf_output_str = hf_output_str + tokenizer.decode(eos_token_id)
decoded_eos = tokenizer.decode(eos_token_id)
assert isinstance(decoded_eos, str)
hf_output_str = hf_output_str + decoded_eos

return hf_output_ids, hf_output_str, out_logprobs

Expand Down Expand Up @@ -286,7 +293,9 @@ def gemma3_vllm_to_hf_output(vllm_output: RunnerOutput, model: str) -> RunnerOut

hf_output_str = output_str
if hf_output_ids[-1] == eos_token_id:
hf_output_str = hf_output_str + tokenizer.decode(eos_token_id)
decoded_eos = tokenizer.decode(eos_token_id)
assert isinstance(decoded_eos, str)
hf_output_str = hf_output_str + decoded_eos

return hf_output_ids, hf_output_str, out_logprobs

Expand Down Expand Up @@ -572,11 +581,10 @@ def patched_forward(
# Prepare attention mask
attention_mask = create_causal_mask(
config=self.config,
input_embeds=inputs_embeds,
inputs_embeds=inputs_embeds,
attention_mask=attention_mask,
past_key_values=past_key_values,
position_ids=position_ids,
cache_position=cache_position,
)

# Initialize and collect hidden states
Expand Down Expand Up @@ -800,7 +808,7 @@ def _internvl_generate(
input_ids: torch.FloatTensor,
attention_mask: torch.LongTensor | None = None,
**generate_kwargs,
) -> torch.LongTensor:
) -> torch.Tensor | ModelOutput:
"""Generate method for InternVL2 model without fixed use_cache."""
assert self.img_context_token_id is not None
target_dtype = next(self.parameters()).dtype
Expand Down Expand Up @@ -828,7 +836,7 @@ def _internvl_generate(
if not isinstance(self.language_model, GenerationMixin):
pytest.skip("HF impl is not compatible with current transformers")

outputs = self.language_model.generate(
outputs = getattr(self.language_model, "generate")( # noqa: B009
**forward_kwargs,
**generate_kwargs,
)
Expand Down Expand Up @@ -1207,7 +1215,7 @@ def patched_generate(*args, **kwargs):
return output

hf_model.get_inputs = patched_get_inputs # type: ignore[method-assign]
hf_model.model.generate = patched_generate # type: ignore[method-assign]
hf_model.model.generate = patched_generate
return hf_model


Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/generation_ppl_test/ppl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
PPL_TOL = 0.01


@torch.inference_mode
@torch.inference_mode()
def vqa_ppl_test(
hf_runner,
vllm_runner,
Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/pooling/test_dse_qwen2_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_models_text(
hf_runner,
vllm_runner,
input_texts,
input_images, # type: ignore
input_images,
embed_texts,
model,
dtype=dtype,
Expand Down
6 changes: 6 additions & 0 deletions tests/models/multimodal/pooling/test_embedding_gemma2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import pytest
import torch

from vllm.multimodal.video import EmbeddingGemma2VideoBackend

MODEL = os.environ.get("EG2_MODEL_PATH")
needs_model = pytest.mark.skipif(not MODEL, reason="EG2_MODEL_PATH not set")
TEXT_COS, MM_COS = 0.999, 0.999
Expand Down Expand Up @@ -348,6 +350,7 @@ def test_video_loader_real_video(vllm_runner, st_model):

video_path = "/projects/gemma4-vllm/videos/test_intel.mp4"
backend_cls = VIDEO_LOADER_REGISTRY.name2class["embedding_gemma2"]
assert issubclass(backend_cls, EmbeddingGemma2VideoBackend)
with open(video_path, "rb") as f:
data = f.read()

Expand Down Expand Up @@ -396,6 +399,7 @@ def test_video_loader_duplicate_expansion_e2e(vllm_runner, st_model):
from vllm.multimodal.video import VIDEO_LOADER_REGISTRY

backend_cls = VIDEO_LOADER_REGISTRY.name2class["embedding_gemma2"]
assert issubclass(backend_cls, EmbeddingGemma2VideoBackend)
# 4s clip at 0.5 fps = 2 unique frames
lowfps_path = "/tmp/test_lowfps_05.mp4"
_ensure_synthetic_video(lowfps_path, duration=4.0, fps=0.5, width=64, height=48)
Expand Down Expand Up @@ -436,6 +440,7 @@ def test_video_loader_indices():
)

backend_cls = VIDEO_LOADER_REGISTRY.name2class["embedding_gemma2"]
assert issubclass(backend_cls, EmbeddingGemma2VideoBackend)
hf_proc = EmbeddingGemma2VideoProcessor()

# Case 1: clip shorter than 32s (e.g. 5s @ 24fps = 120 frames)
Expand Down Expand Up @@ -521,6 +526,7 @@ def test_video_loader_duplicate_expansion():
)

backend_cls = VIDEO_LOADER_REGISTRY.name2class["embedding_gemma2"]
assert issubclass(backend_cls, EmbeddingGemma2VideoBackend)
hf_proc = EmbeddingGemma2VideoProcessor()

# 4s clip @ 0.5fps = 2 frames total. Requested target fps = 1.0 -> 4 frames.
Expand Down
4 changes: 2 additions & 2 deletions tests/models/multimodal/pooling/test_intern_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def _patched_init(self, *args, **kwargs):
_orig_init(self, *args, **kwargs)
self.all_tied_weights_keys = {}

PreTrainedModel.__init__ = _patched_init
PreTrainedModel.__init__ = _patched_init # type: ignore[method-assign]

try:
hf_model = AutoModel.from_pretrained(
model, dtype=torch_dtype, trust_remote_code=True
).to(DEVICE_TYPE)
finally:
PreTrainedModel.__init__ = _orig_init
PreTrainedModel.__init__ = _orig_init # type: ignore[method-assign]
hf_outputs_per_image = [
hf_model(pixel_value.to(DEVICE_TYPE)).last_hidden_state
for pixel_value in pixel_values
Expand Down
2 changes: 1 addition & 1 deletion tests/models/multimodal/pooling/test_llava_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_models_text(
hf_runner,
vllm_runner,
input_texts,
input_images, # type: ignore
input_images,
model,
dtype=dtype,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/models/multimodal/pooling/test_phi3v.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_models_text(
hf_runner,
vllm_runner,
input_texts,
input_images, # type: ignore
input_images,
model,
dtype=dtype,
)
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_models_image_special_tokens_processing(
return_tensors="pt",
)

image_token_id = hf_processor.get_special_image_token_id()
image_token_id = getattr(hf_processor, "get_special_image_token_id")() # noqa: B009
hf_prompt_token_ids = [
image_token_id if token_id < 0 else token_id
for token_id in hf_inputs["input_ids"][0].tolist()
Expand Down
Loading
Loading