From b4734b9550eb85cb8e38e3d93ef8fccb83ddf8fe Mon Sep 17 00:00:00 2001 From: Alex Brooks Date: Thu, 20 Nov 2025 22:32:30 -0700 Subject: [PATCH] [Bugfix] Fix default MM LoRA alignment for single str prompts (#29140) Signed-off-by: Alex-Brooks --- tests/lora/test_default_mm_loras.py | 35 +++++++++++++++++++++++++++++ vllm/entrypoints/llm.py | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/lora/test_default_mm_loras.py b/tests/lora/test_default_mm_loras.py index dfc45e78e464f..407b29fdd1d58 100644 --- a/tests/lora/test_default_mm_loras.py +++ b/tests/lora/test_default_mm_loras.py @@ -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 diff --git a/vllm/entrypoints/llm.py b/vllm/entrypoints/llm.py index b0786bd355aa6..7421eb8b8abc9 100644 --- a/vllm/entrypoints/llm.py +++ b/vllm/entrypoints/llm.py @@ -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 = (