[Bugfix] Fix default MM LoRA alignment for single str prompts (#29140)

Signed-off-by: Alex-Brooks <Alex.Brooks@ibm.com>
This commit is contained in:
Alex Brooks 2025-11-20 22:32:30 -07:00 committed by GitHub
parent 30b9c67743
commit b4734b9550
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View File

@ -5,7 +5,9 @@ Tests for applying default registered multimodal loras.
"""
import os
import unittest.mock as mock
import pytest
from huggingface_hub import snapshot_download
from vllm.lora.request import LoRARequest
@ -114,3 +116,36 @@ def test_default_mm_lora_fails_with_overridden_lora_request(
default_mm_loras={"audio": IMAGE_LORA_PATH},
expected_suffix=RESPONSE_SUFFIX_WITH_LORA,
)
def test_default_mm_lora_does_not_expand_string_reqs(vllm_runner):
class MockEngineException(Exception):
pass
# Regression test for ensuring default multimodal lora resolution
# does not expand the lora req if the prompt type is a string.
vllm_runner_kwargs = {
**VLLM_RUNNER_BASE_KWARGS,
**{"default_mm_loras": {"audio": AUDIO_LORA_PATH}},
}
# Avoid the full generation call since these tests are expensive;
# just check what lora request is actually submitted to the engine
mock_err = "Engine is mocked for this test"
with (
mock.patch(
"vllm.v1.engine.llm_engine.LLMEngine.add_request",
side_effect=MockEngineException(mock_err),
) as mock_add_request,
vllm_runner(**vllm_runner_kwargs) as vllm_model,
):
# Die once we actually submit the request to the engine
with pytest.raises(MockEngineException):
vllm_model.llm.generate(prompts=AUDIO_PROMPT)
# Then check to make sure the submitted lora request
# and text prompt were zipped together correctly
engine_args, engine_kwargs = mock_add_request.call_args
assert engine_kwargs["lora_request"] is None
assert engine_kwargs["prompt_text"] == AUDIO_PROMPT

View File

@ -466,7 +466,7 @@ class LLM:
):
return lora_request
if not isinstance(prompts, Sequence):
if not isinstance(prompts, Sequence) or isinstance(prompts, str):
prompts = [prompts]
optional_loras = (