From 34051ad7145104e73ba3a7f5b39506ad0949bb8d Mon Sep 17 00:00:00 2001 From: Harshal Janjani Date: Mon, 5 Oct 2026 11:51:15 +0400 Subject: [PATCH] feat: Add video support for the Transformers backend (#57441) Signed-off-by: Harshal Janjani Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) --- docs/models/supported_models.md | 4 +- .../generation/test_transformers_audio.py | 16 +- .../generation/test_transformers_video.py | 100 ++++ .../processing/test_transformers_video.py | 277 +++++++++++ tests/models/transformers/test_backend.py | 19 +- vllm/config/model.py | 24 +- .../models/transformers/multimodal.py | 432 +++++++++++++++--- .../models/transformers/utils.py | 10 +- vllm/transformers_utils/config.py | 8 +- 9 files changed, 775 insertions(+), 115 deletions(-) create mode 100644 tests/models/multimodal/generation/test_transformers_video.py create mode 100644 tests/models/multimodal/processing/test_transformers_video.py diff --git a/docs/models/supported_models.md b/docs/models/supported_models.md index e461379bcb..a55559b0d6 100644 --- a/docs/models/supported_models.md +++ b/docs/models/supported_models.md @@ -19,12 +19,10 @@ vLLM also supports model implementations that are available in Transformers. We Currently, the Transformers modeling backend works for the following: -- Modalities: embedding models, language models, vision-language models* and audio-language models +- Modalities: embedding models, language models, vision-language models and audio-language models - Architectures: encoder-only, decoder-only, mixture-of-experts - Attention types: full attention and/or sliding attention -_*Vision-language models currently accept only image inputs. Support for video inputs will be added in a future release._ - If the Transformers model implementation follows all the steps in [writing a custom model](#writing-custom-models) then, when used with the Transformers modeling backend, it will be compatible with the following features of vLLM: - All the features listed in the [compatibility matrix](../features/README.md#feature-x-feature) diff --git a/tests/models/multimodal/generation/test_transformers_audio.py b/tests/models/multimodal/generation/test_transformers_audio.py index 9195579877..230cbc910c 100644 --- a/tests/models/multimodal/generation/test_transformers_audio.py +++ b/tests/models/multimodal/generation/test_transformers_audio.py @@ -69,13 +69,8 @@ AUDIO_MODEL_SETTINGS: dict[str, dict[str, Any]] = { } -@pytest.mark.parametrize("model_id", list(AUDIO_MODEL_SETTINGS)) -def test_transformers_audio_generation( - hf_runner: type[HfRunner], - vllm_runner: type[VllmRunner], - monkeypatch, - model_id: str, -): +@pytest.fixture(autouse=True) +def use_spawn_for_audio_models(monkeypatch): """Single-process workaround for V1 fork safety deadlock issue (vllm-project/vllm/issues/17676). Running multiple audio models together under pytest can cause (possibly flaky) hangs, so they are grouped under @@ -87,6 +82,13 @@ def test_transformers_audio_generation( disable_envs_cache() monkeypatch.setenv("VLLM_WORKER_MULTIPROC_METHOD", "spawn") + +@pytest.mark.parametrize("model_id", list(AUDIO_MODEL_SETTINGS)) +def test_transformers_audio_generation( + hf_runner: type[HfRunner], + vllm_runner: type[VllmRunner], + model_id: str, +): settings = AUDIO_MODEL_SETTINGS[model_id] audio_lora_path = settings.get("audio_lora_path") diff --git a/tests/models/multimodal/generation/test_transformers_video.py b/tests/models/multimodal/generation/test_transformers_video.py new file mode 100644 index 0000000000..bbb31b7be8 --- /dev/null +++ b/tests/models/multimodal/generation/test_transformers_video.py @@ -0,0 +1,100 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project + +from typing import Any + +import pytest +from transformers import AutoModelForImageTextToText + +from vllm.assets.video import VideoAsset +from vllm.envs import disable_envs_cache + +from ....conftest import HfRunner, VllmRunner +from ...utils import check_logprobs_close +from .vlm_utils import model_utils + +VIDEO_ASSET = VideoAsset("baby_reading", num_frames=8) + +VIDEO_MODEL_SETTINGS: dict[str, dict[str, Any]] = { + "Qwen/Qwen3-VL-2B-Instruct": { + "prompt": ( + "<|im_start|>user\n" + "<|vision_start|><|video_pad|><|vision_end|>" + "Describe this video.<|im_end|>\n" + "<|im_start|>assistant\n" + ), + }, + "llava-hf/llava-onevision-qwen2-0.5b-ov-hf": { + "prompt": ( + "<|im_start|>user