Add pydocstyle to the ruff rules (#52136)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Signed-off-by: Harry Mellor <hej.mellor@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -23,11 +23,9 @@ NONINTERLEAVED_PROMPT = base_prompt("<image><image><video>\n")
|
||||
@pytest.mark.parametrize("dtype", ["float16"])
|
||||
@pytest.mark.parametrize("max_tokens", [128])
|
||||
def test_models(vllm_runner, model, dtype: str, max_tokens: int) -> None:
|
||||
"""
|
||||
This is a simple test to check if interleaved and non-interleaved prompts
|
||||
"""This is a simple test to check if interleaved and non-interleaved prompts
|
||||
give the same result.
|
||||
"""
|
||||
|
||||
image_cherry = convert_image_mode(ImageAsset("cherry_blossom").pil_image, "RGB")
|
||||
image_stop = convert_image_mode(ImageAsset("stop_sign").pil_image, "RGB")
|
||||
images = [image_cherry, image_stop]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Create a reduced-layer version of the Maverick model for testing purposes.
|
||||
"""Create a reduced-layer version of the Maverick model for testing purposes.
|
||||
|
||||
This script creates a new model with fewer layers by:
|
||||
1. Loading the original Maverick model configuration
|
||||
@@ -39,7 +38,6 @@ def run_maverick_serving(model: str):
|
||||
"""Test Llama-4-Maverick model with vLLM LLM class using CLI equivalent
|
||||
options with reduced layers.
|
||||
"""
|
||||
|
||||
try:
|
||||
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
||||
|
||||
@@ -71,8 +69,7 @@ def run_maverick_serving(model: str):
|
||||
|
||||
|
||||
def get_rope_layers_config(model_path: str) -> list[int]:
|
||||
"""
|
||||
Get the interleaved RoPE configuration from HuggingFace config
|
||||
"""Get the interleaved RoPE configuration from HuggingFace config.
|
||||
|
||||
Args:
|
||||
model_path: Path to the local directory containing the reduced
|
||||
@@ -81,6 +78,7 @@ def get_rope_layers_config(model_path: str) -> list[int]:
|
||||
Returns:
|
||||
List of 0 or 1 indicating whether each layer uses RoPE and local attn
|
||||
0 indicates that RoPE is not used while 1 indicates that RoPE is used.
|
||||
|
||||
"""
|
||||
config_path = Path(model_path) / "config.json"
|
||||
model_config = json.loads(config_path.read_text())
|
||||
@@ -98,8 +96,7 @@ def create_reduced_maverick_model(
|
||||
vision_layers: int = 2,
|
||||
force_recreate: bool = False,
|
||||
) -> str:
|
||||
"""
|
||||
Create a reduced-layer version of the Maverick model.
|
||||
"""Create a reduced-layer version of the Maverick model.
|
||||
|
||||
Args:
|
||||
original_model_name: Name of the original Maverick model
|
||||
@@ -111,8 +108,8 @@ def create_reduced_maverick_model(
|
||||
|
||||
Returns:
|
||||
Path to the created reduced model directory
|
||||
"""
|
||||
|
||||
"""
|
||||
print(
|
||||
f"Creating reduced Maverick model with {text_layers} text layers and "
|
||||
f"{vision_layers} vision layers..."
|
||||
@@ -178,7 +175,6 @@ def create_reduced_config(
|
||||
original_config: Any, text_layers: int, num_experts: int, vision_layers: int
|
||||
) -> dict[str, Any]:
|
||||
"""Create a reduced configuration based on the original."""
|
||||
|
||||
# Convert config to dictionary
|
||||
config_dict = original_config.to_dict()
|
||||
|
||||
@@ -220,7 +216,6 @@ def create_reduced_config(
|
||||
|
||||
def copy_tokenizer_files(original_model_name: str, output_path: Path) -> None:
|
||||
"""Copy tokenizer files from the original model."""
|
||||
|
||||
try:
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
original_model_name, trust_remote_code=True
|
||||
@@ -233,7 +228,6 @@ def copy_tokenizer_files(original_model_name: str, output_path: Path) -> None:
|
||||
|
||||
def create_preprocessor_config(original_config: Any, output_path: Path) -> None:
|
||||
"""Create preprocessor_config.json for multimodal model."""
|
||||
|
||||
# Try to load the original preprocessor config
|
||||
try:
|
||||
processor = AutoProcessor.from_pretrained(
|
||||
@@ -253,7 +247,6 @@ def create_reduced_safetensors(
|
||||
original_config: Any, reduced_config: dict[str, Any], output_path: Path
|
||||
) -> None:
|
||||
"""Create safetensors files with weights for the reduced model."""
|
||||
|
||||
print("Generating synthetic weights for reduced model...")
|
||||
|
||||
text_config = reduced_config["text_config"]
|
||||
@@ -276,7 +269,6 @@ def create_reduced_safetensors(
|
||||
|
||||
def create_text_model_weights(text_config: dict[str, Any]) -> dict[str, torch.Tensor]:
|
||||
"""Create synthetic weights for the text model with MoE structure."""
|
||||
|
||||
weights = {}
|
||||
|
||||
vocab_size = text_config["vocab_size"]
|
||||
@@ -405,7 +397,6 @@ def create_vision_model_weights(
|
||||
vision_config: dict[str, Any],
|
||||
) -> dict[str, torch.Tensor]:
|
||||
"""Create synthetic weights for the vision model."""
|
||||
|
||||
weights = {}
|
||||
|
||||
hidden_size = vision_config["hidden_size"]
|
||||
@@ -473,8 +464,7 @@ def create_vision_model_weights(
|
||||
def create_shared_weights(
|
||||
text_config: dict[str, Any], vision_config: dict[str, Any]
|
||||
) -> dict[str, torch.Tensor]:
|
||||
"""Create weights for shared components (vision-language connector)"""
|
||||
|
||||
"""Create weights for shared components (vision-language connector)."""
|
||||
weights = {}
|
||||
|
||||
text_hidden_size = text_config["hidden_size"]
|
||||
@@ -492,7 +482,6 @@ def save_weights_to_safetensors(
|
||||
weights: dict[str, torch.Tensor], output_path: Path
|
||||
) -> None:
|
||||
"""Save weights to safetensors files and create index."""
|
||||
|
||||
# Determine how to shard the weights
|
||||
max_shard_size = 5 * 1024 * 1024 * 1024 # 5GB per shard
|
||||
|
||||
@@ -655,7 +644,6 @@ def test_dummy_maverick(
|
||||
|
||||
def main():
|
||||
"""Main function to create and test the reduced model."""
|
||||
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
|
||||
@@ -33,7 +33,8 @@ NUM_TOKENS = 3
|
||||
|
||||
class _StubGate(torch.nn.Module):
|
||||
"""Router stand-in, so the test does not depend on platform-specific
|
||||
``ReplicatedLinear`` weight post-processing."""
|
||||
``ReplicatedLinear`` weight post-processing.
|
||||
"""
|
||||
|
||||
def __init__(self, hidden_size: int, num_experts: int):
|
||||
super().__init__()
|
||||
|
||||
@@ -31,8 +31,7 @@ def mask_bbox_tokens(
|
||||
output: tuple[list[int], str, SampleLogprobs],
|
||||
tokenizer: TokenizerLike,
|
||||
) -> tuple[list[int], str, SampleLogprobs]:
|
||||
"""
|
||||
Always pass check_logprobs_close check for bounding box tokens
|
||||
"""Always pass check_logprobs_close check for bounding box tokens
|
||||
because it is reasonable for them to differ slightly.
|
||||
"""
|
||||
ignore_pattern = r"<[xy]_[\d.]+>"
|
||||
|
||||
@@ -97,7 +97,7 @@ def batch_make_image_embeddings(
|
||||
processor,
|
||||
llm: VllmRunner,
|
||||
) -> list[Qwen2VLPromptImageEmbeddingInput]:
|
||||
"""batched image embeddings for Qwen2-VL
|
||||
"""Batched image embeddings for Qwen2-VL.
|
||||
|
||||
This will infer all images' embeddings in a single batch,
|
||||
and split the result according to input batches.
|
||||
@@ -108,7 +108,6 @@ def batch_make_image_embeddings(
|
||||
|
||||
returns: `list[Qwen2VLPromptImageEmbeddingInput]`
|
||||
"""
|
||||
|
||||
image_batches_: list[Any] = image_batches[:]
|
||||
|
||||
# convert single-image batches to multiple-image batches
|
||||
@@ -183,7 +182,7 @@ def batch_make_image_embeddings(
|
||||
def batch_make_video_embeddings(
|
||||
video_batches: PromptVideoInput, processor, llm: VllmRunner
|
||||
) -> list[Qwen2VLPromptVideoEmbeddingInput]:
|
||||
"""batched video embeddings for Qwen2-VL
|
||||
"""Batched video embeddings for Qwen2-VL.
|
||||
|
||||
A NDArray represents a single video's all frames.
|
||||
|
||||
@@ -194,7 +193,6 @@ def batch_make_video_embeddings(
|
||||
- Single-video batches: `list[NDArray]`
|
||||
- Multiple-video batches: `list[list[NDArray]]`
|
||||
"""
|
||||
|
||||
video_batches_: list[Any] = video_batches[:]
|
||||
|
||||
for idx in range(len(video_batches_)):
|
||||
|
||||
@@ -81,7 +81,8 @@ def test_transformers_audio_generation(
|
||||
under pytest can cause (possibly flaky) hangs, so they are grouped under
|
||||
the same config. Using VLLM_WORKER_MULTIPROC_METHOD=spawn avoids the
|
||||
deadlock and allows worker processes to terminate cleanly, and release
|
||||
GPU memory between test runs until the issue is fixed."""
|
||||
GPU memory between test runs until the issue is fixed.
|
||||
"""
|
||||
# TODO: Remove monkeypatch once
|
||||
# https://github.com/vllm-project/vllm/issues/17676 is fixed.
|
||||
disable_envs_cache()
|
||||
|
||||
@@ -204,7 +204,6 @@ def test_variable_length_audio_batching(
|
||||
@pytest.mark.asyncio
|
||||
async def test_online_serving(client, audio_assets: AudioTestAssets):
|
||||
"""Exercises online serving with/without chunked prefill enabled."""
|
||||
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
|
||||
@@ -78,7 +78,6 @@ def test_online_serving(vllm_runner, audio_assets: AudioTestAssets):
|
||||
|
||||
Steps run sequentially so each releases the GPU before the next starts.
|
||||
"""
|
||||
|
||||
question = f"What's happening in these {len(audio_assets)} audio clips?"
|
||||
max_tokens = 10
|
||||
audio_data = [asset.audio_and_sample_rate for asset in audio_assets]
|
||||
|
||||
@@ -294,7 +294,8 @@ def sample_frames_with_video_metadata(
|
||||
|
||||
def apply_image_size_scaling(image, size: float | tuple[int, int], size_type: SizeType):
|
||||
"""Applies a size scaler to one image; this can be an image size factor,
|
||||
which scales the image while maintaining the aspect ratio"""
|
||||
which scales the image while maintaining the aspect ratio
|
||||
"""
|
||||
# Special case for embeddings; if it's a tensor, it's only valid if we
|
||||
# are considering size factors at constant scale, i.e., we just clone
|
||||
# the tensor
|
||||
|
||||
@@ -156,6 +156,7 @@ def get_wrapped_test_sizes(
|
||||
Args:
|
||||
test_info: Test configuration to be expanded.
|
||||
test_type: The type of test being filtered for.
|
||||
|
||||
"""
|
||||
# If it is an embedding test, we always use the EMBEDDING_SIZE_FACTORS
|
||||
if test_type == VLMTestType.EMBEDDING:
|
||||
|
||||
@@ -200,7 +200,7 @@ def process_runner_outputs(
|
||||
|
||||
|
||||
def process_outputs(output_processor, model, outputs_per_image):
|
||||
"""Applies a model specific post-processor function to a runner's output"""
|
||||
"""Applies a model specific post-processor function to a runner's output."""
|
||||
return [
|
||||
[output_processor(res, model) for res in outputs]
|
||||
for outputs in outputs_per_image
|
||||
|
||||
@@ -22,6 +22,7 @@ def multi_image_multi_aspect_ratio_inputs(formatter: Callable[[str], str]):
|
||||
|
||||
Args:
|
||||
formatter: model-specific prompt formatter.
|
||||
|
||||
"""
|
||||
stop_sign = IMAGE_ASSETS[0].pil_image
|
||||
cherry_blossom = IMAGE_ASSETS[1].pil_image
|
||||
@@ -65,6 +66,7 @@ def multi_video_multi_aspect_ratio_inputs(
|
||||
|
||||
Args:
|
||||
formatter: model-specific prompt formatter.
|
||||
|
||||
"""
|
||||
video = sample_frames_from_video(VIDEO_ASSETS[0].np_ndarrays, num_frames)
|
||||
# Apply the selected formatter to the base prompts
|
||||
|
||||
@@ -252,6 +252,7 @@ def qwen_prompt_path_encoder(
|
||||
tmp_path: Tempdir for test under consideration.
|
||||
prompt: Prompt with image placeholders.
|
||||
assets: list of image assets whose len equals the num placeholders.
|
||||
|
||||
"""
|
||||
# Ensure that the number of placeholders matches the number of assets;
|
||||
# If this is not true, the test is probably written incorrectly.
|
||||
@@ -507,15 +508,12 @@ def isaac_patch_hf_runner(hf_model: HfRunner) -> HfRunner:
|
||||
2) Ensure IsaacModel.forward returns hidden_states
|
||||
for compatibility with hidden_states_to_seq_logprobs()
|
||||
"""
|
||||
|
||||
from perceptron.tensorstream import TextType
|
||||
from perceptron.tensorstream.ops import compute_mrope_pos_tensor, modality_mask
|
||||
from transformers.modeling_outputs import BaseModelOutputWithPast
|
||||
|
||||
def compute_position_ids_input_ids(input_ids: torch.Tensor) -> torch.Tensor:
|
||||
"""
|
||||
Create 3D positional indices for token input.
|
||||
"""
|
||||
"""Create 3D positional indices for token input."""
|
||||
batch_size, seq_length = input_ids.shape
|
||||
position_ids = torch.arange(seq_length, device=input_ids.device)
|
||||
position_ids = position_ids.view(1, -1).expand(batch_size, -1)
|
||||
@@ -570,8 +568,7 @@ def isaac_patch_hf_runner(hf_model: HfRunner) -> HfRunner:
|
||||
cache_position=None,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Forward pass with MRoPE position embeddings.
|
||||
"""Forward pass with MRoPE position embeddings.
|
||||
Computes position embeddings once and passes them through all layers.
|
||||
"""
|
||||
output_hidden_states = (
|
||||
@@ -1184,7 +1181,6 @@ def voxtral_patch_hf_runner(hf_model: "HfRunner") -> "HfRunner":
|
||||
HfRunner.generate calls batch_decode on the full sequence (prompt +
|
||||
generated).
|
||||
"""
|
||||
|
||||
import io
|
||||
|
||||
import pybase64 as base64
|
||||
|
||||
@@ -87,7 +87,7 @@ def _run_test(
|
||||
*,
|
||||
dtype: str,
|
||||
) -> None:
|
||||
"""SET PYTHONPATH"""
|
||||
"""SET PYTHONPATH."""
|
||||
# NOTE: take care of the order. run vLLM first, and then run HF.
|
||||
# vLLM needs a fresh new process without cuda initialization.
|
||||
# if we run HF first, the cuda initialization will be done and it
|
||||
|
||||
@@ -108,8 +108,7 @@ def _normalize_image(image_val: str) -> str:
|
||||
def create_score_multimodal_param(
|
||||
content_parts: list[dict],
|
||||
) -> list[ScoreMultiModalParam]:
|
||||
"""
|
||||
Create a ScoreMultiModalParam from a list of content dictionaries.
|
||||
"""Create a ScoreMultiModalParam from a list of content dictionaries.
|
||||
|
||||
Each dict supports the following formats:
|
||||
- Text: {'text': 'content'}
|
||||
@@ -257,7 +256,7 @@ def test_model_text_image(
|
||||
model: str,
|
||||
dtype: str,
|
||||
) -> None:
|
||||
"""Visual Documents Reranking"""
|
||||
"""Visual Documents Reranking."""
|
||||
_run_test(
|
||||
hf_runner,
|
||||
vllm_runner,
|
||||
@@ -280,7 +279,7 @@ def test_model_text_text(
|
||||
model: str,
|
||||
dtype: str,
|
||||
) -> None:
|
||||
"""Textual Documents Reranking"""
|
||||
"""Textual Documents Reranking."""
|
||||
_run_test(
|
||||
hf_runner,
|
||||
vllm_runner,
|
||||
@@ -303,7 +302,7 @@ def test_model_image_text(
|
||||
model: str,
|
||||
dtype: str,
|
||||
) -> None:
|
||||
"""Image Querying for Textual Documents"""
|
||||
"""Image Querying for Textual Documents."""
|
||||
_run_test(
|
||||
hf_runner,
|
||||
vllm_runner,
|
||||
@@ -326,7 +325,7 @@ def test_model_image_image(
|
||||
model: str,
|
||||
dtype: str,
|
||||
) -> None:
|
||||
"""Image Querying for Image Documents"""
|
||||
"""Image Querying for Image Documents."""
|
||||
_run_test(
|
||||
hf_runner,
|
||||
vllm_runner,
|
||||
@@ -349,7 +348,7 @@ def test_model_text_mixed_documents(
|
||||
model: str,
|
||||
dtype: str,
|
||||
) -> None:
|
||||
"""Text Query for Mixed Text and Image Documents"""
|
||||
"""Text Query for Mixed Text and Image Documents."""
|
||||
_run_test(
|
||||
hf_runner,
|
||||
vllm_runner,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Tests for the LlamaNemotronVL model family:
|
||||
"""Tests for the LlamaNemotronVL model family:
|
||||
- nvidia/llama-nemotron-embed-vl-1b-v2 (LlamaNemotronVLForCausalLM / embed)
|
||||
- nvidia/llama-nemotron-rerank-vl-1b-v2
|
||||
(LlamaNemotronVLForSequenceClassification / rerank)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Regression tests for Qwen2.5-Omni and Qwen3-Omni audio-in-video processor
|
||||
"""Regression tests for Qwen2.5-Omni and Qwen3-Omni audio-in-video processor
|
||||
caching.
|
||||
|
||||
Tests the use_audio_in_video feature where audio is extracted from video and
|
||||
@@ -50,8 +49,7 @@ def create_mm_data(num_videos: int) -> dict[str, list]:
|
||||
@pytest.mark.parametrize("model_id", MODELS)
|
||||
@pytest.mark.parametrize("num_videos", [1, 2])
|
||||
def test_audio_in_video_cache_correctness(model_id: str, num_videos: int) -> None:
|
||||
"""
|
||||
Regression test for https://github.com/vllm-project/vllm/pull/36800
|
||||
"""Regression test for https://github.com/vllm-project/vllm/pull/36800.
|
||||
|
||||
MultiModalProcessorSenderCache.get_and_update_item returns (None, updates)
|
||||
on a cache hit, so mm_kwargs["video"] items become None on the second call.
|
||||
@@ -117,8 +115,7 @@ def test_audio_in_video_cache_correctness(model_id: str, num_videos: int) -> Non
|
||||
|
||||
@pytest.mark.parametrize("model_id", MODELS)
|
||||
def test_use_audio_in_video_without_audio_track(model_id: str) -> None:
|
||||
"""
|
||||
A video with no audio track, combined with `use_audio_in_video=True`,
|
||||
"""A video with no audio track, combined with `use_audio_in_video=True`,
|
||||
must raise a clear `ValueError` naming the mismatch, rather than an
|
||||
opaque `StopIteration`-derived error from the underlying HF processor.
|
||||
"""
|
||||
|
||||
@@ -33,9 +33,7 @@ from ...registry import (
|
||||
|
||||
|
||||
def add_video_metadata(mm_data: MultiModalDataDict) -> MultiModalDataDict:
|
||||
"""
|
||||
Add metadata to video mm_data
|
||||
"""
|
||||
"""Add metadata to video mm_data."""
|
||||
|
||||
def create_metadata(frames: np.ndarray):
|
||||
num_frames = len(frames)
|
||||
@@ -61,8 +59,7 @@ def add_video_metadata(mm_data: MultiModalDataDict) -> MultiModalDataDict:
|
||||
|
||||
|
||||
def glmasr_patch_mm_data(mm_data: MultiModalDataDict) -> MultiModalDataDict:
|
||||
"""
|
||||
Patch the multimodal data for GLM-ASR model.
|
||||
"""Patch the multimodal data for GLM-ASR model.
|
||||
GLM-ASR requires text and audio to match 1:1, so we limit audio to 1.
|
||||
"""
|
||||
if "audio" in mm_data:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Regression test for DeepSeek-OCR TensorSchema validation with empty images_crop.
|
||||
"""Regression test for DeepSeek-OCR TensorSchema validation with empty images_crop.
|
||||
|
||||
When using the Gundam preset (BASE_SIZE=1024, IMAGE_SIZE=640, CROP_MODE=True),
|
||||
images that are small enough to not require cropping produce an empty
|
||||
@@ -109,7 +108,8 @@ class TestDeepseekOCREmptyImagesCrop:
|
||||
|
||||
def test_mismatched_image_size_raises(self, processor):
|
||||
"""Deliberately wrong image_size binding should still be caught
|
||||
by TensorSchema validation."""
|
||||
by TensorSchema validation.
|
||||
"""
|
||||
small_image = Image.new("RGB", (100, 100), color="green")
|
||||
|
||||
result = processor(
|
||||
@@ -143,7 +143,8 @@ class TestDeepseekOCRInputValidation:
|
||||
def test_mismatched_image_count_raises_value_error(self, processor):
|
||||
"""Two ``<image>`` tokens with one image must raise ValueError, not
|
||||
AssertionError (which would yield HTTP 500 and, under ``-O``, silently
|
||||
drop the middle text segment)."""
|
||||
drop the middle text segment).
|
||||
"""
|
||||
image = Image.new("RGB", (100, 100), color="red")
|
||||
with pytest.raises(ValueError, match="does not match number of images"):
|
||||
processor(prompt="<image> and <image>", images=[image])
|
||||
|
||||
@@ -152,8 +152,7 @@ def test_video_loader_consistency(
|
||||
fps: int,
|
||||
backend: str,
|
||||
):
|
||||
"""
|
||||
Ensure dynamic video loader (pre-sampled by loader) and normal video
|
||||
"""Ensure dynamic video loader (pre-sampled by loader) and normal video
|
||||
loader (post-sampled by processor) produce same video processing outputs.
|
||||
"""
|
||||
ctx = build_model_context(
|
||||
|
||||
@@ -116,8 +116,7 @@ def _test_image_prompt_replacements(
|
||||
num_imgs: int,
|
||||
image_sizes: list[ImageSize],
|
||||
) -> None:
|
||||
"""
|
||||
Ensure LlavaNextMultiModalProcessor
|
||||
"""Ensure LlavaNextMultiModalProcessor
|
||||
handles prompt replacement properly for input images.
|
||||
"""
|
||||
failed_size_excs = list[tuple[ImageSize, Exception]]()
|
||||
|
||||
@@ -16,7 +16,8 @@ from ...utils import build_model_context
|
||||
class _StubModel:
|
||||
"""Carries only the attributes the token-count method reads from
|
||||
`self`, so the real methods can be exercised without constructing
|
||||
the full `nn.Module` (vision tower, language model, etc.)."""
|
||||
the full `nn.Module` (vision tower, language model, etc.).
|
||||
"""
|
||||
|
||||
patch_grid_length: int
|
||||
pooled_grid_length: int
|
||||
@@ -31,7 +32,8 @@ get_mm_lora_token_counts = (
|
||||
def test_num_mm_tokens_match_real_config(model_id):
|
||||
"""The stored grid lengths must match what `__init__` derives from
|
||||
the real HF config, and the LoRA token counts must preserve the
|
||||
frame-level scaling exactly."""
|
||||
frame-level scaling exactly.
|
||||
"""
|
||||
ctx = build_model_context(model_id, limit_mm_per_prompt={"video": 1})
|
||||
config = ctx.model_config.hf_config
|
||||
|
||||
|
||||
@@ -122,8 +122,7 @@ def _test_image_prompt_replacements(
|
||||
num_imgs: int,
|
||||
image_sizes: list[ImageSize],
|
||||
) -> None:
|
||||
"""
|
||||
Ensure LlavaOnevisionMultiModalProcessor
|
||||
"""Ensure LlavaOnevisionMultiModalProcessor
|
||||
handles prompt replacement properly for input images.
|
||||
"""
|
||||
failed_size_excs = list[tuple[ImageSize, Exception]]()
|
||||
|
||||
@@ -70,7 +70,8 @@ def test_dummy_video_num_frames_override_honors_min_of_two(
|
||||
):
|
||||
"""A ``num_frames`` override below 2 must be ignored (the model needs at
|
||||
least 2 frames), matching the "cannot be less than 2, will be ignored"
|
||||
warning."""
|
||||
warning.
|
||||
"""
|
||||
builder = object.__new__(Molmo2DummyInputsBuilder)
|
||||
builder.info = SimpleNamespace(
|
||||
get_hf_processor=lambda: SimpleNamespace(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Unit tests for Qwen2.5-Omni embed_input_ids to verify embeddings are
|
||||
"""Unit tests for Qwen2.5-Omni embed_input_ids to verify embeddings are
|
||||
correctly assigned to audio/image/video token positions.
|
||||
|
||||
Regression test for: https://github.com/vllm-project/vllm/issues/34506
|
||||
@@ -40,8 +39,7 @@ def _mm_embed(shape: tuple[int, ...], value: float, modality: str) -> torch.Tens
|
||||
def make_token_seq(
|
||||
audio_n: int, image_n: int, video_n: int, text_prefix: int = 3, text_sep: int = 2
|
||||
):
|
||||
"""
|
||||
Build a flat token sequence:
|
||||
"""Build a flat token sequence:
|
||||
[text_prefix] [AUDIO * audio_n] [text_sep] [IMAGE * image_n]
|
||||
[text_sep] [VIDEO * video_n] [text_sep]
|
||||
Returns (input_ids tensor, is_multimodal mask, positions dict).
|
||||
@@ -67,9 +65,8 @@ def make_token_seq(
|
||||
def make_interleaved_seq(
|
||||
video_chunks: list[int], audio_chunks: list[int], text_prefix: int = 2
|
||||
):
|
||||
"""
|
||||
Build an interleaved sequence like use_audio_in_video:
|
||||
[text] [V*v0] [A*a0] [V*v1] [A*a1] ...
|
||||
"""Build an interleaved sequence like use_audio_in_video:
|
||||
[text] [V*v0] [A*a0] [V*v1] [A*a1] ...
|
||||
"""
|
||||
tokens = [TEXT_TOKEN_ID] * text_prefix
|
||||
for v, a in zip(video_chunks, audio_chunks):
|
||||
@@ -140,8 +137,7 @@ class TestCheckInterleavedAudioVideo:
|
||||
)
|
||||
|
||||
def test_batched_non_interleaved_no_false_positive(self):
|
||||
"""
|
||||
Regression test for https://github.com/vllm-project/vllm/issues/35394.
|
||||
"""Regression test for https://github.com/vllm-project/vllm/issues/35394.
|
||||
|
||||
5 identical non-interleaved mixed-modality requests batched together:
|
||||
each has [audio][image][video] in separate blocks with text between them.
|
||||
@@ -172,8 +168,7 @@ class TestCheckInterleavedAudioVideo:
|
||||
|
||||
|
||||
def make_mock_model(hidden: int = 8):
|
||||
"""
|
||||
Return a minimal mock of Qwen2_5OmniThinkerForConditionalGeneration
|
||||
"""Return a minimal mock of Qwen2_5OmniThinkerForConditionalGeneration
|
||||
that has enough structure to run embed_input_ids.
|
||||
"""
|
||||
from vllm.model_executor.models.qwen2_5_omni_thinker import (
|
||||
@@ -236,8 +231,7 @@ def make_mock_model(hidden: int = 8):
|
||||
def build_mm_embeds(
|
||||
audio_n, image_n, video_n, hidden, audio_val=10.0, image_val=20.0, video_val=30.0
|
||||
):
|
||||
"""
|
||||
Build multimodal_embeddings list in position order (audio, image, video).
|
||||
"""Build multimodal_embeddings list in position order (audio, image, video).
|
||||
Each embedding is filled with a distinct constant so we can verify placement.
|
||||
"""
|
||||
embs = []
|
||||
@@ -252,8 +246,7 @@ def build_mm_embeds(
|
||||
|
||||
class TestEmbedInputIds:
|
||||
def _run(self, audio_n, image_n, video_n, hidden=8):
|
||||
"""
|
||||
Run embed_input_ids for a non-interleaved mixed-modality sequence.
|
||||
"""Run embed_input_ids for a non-interleaved mixed-modality sequence.
|
||||
Returns (result_embeds, input_ids, is_multimodal).
|
||||
"""
|
||||
input_ids, is_multimodal = make_token_seq(audio_n, image_n, video_n)
|
||||
@@ -288,8 +281,7 @@ class TestEmbedInputIds:
|
||||
)
|
||||
|
||||
def test_mixed_modalities_audio_goes_to_audio_pos(self):
|
||||
"""
|
||||
Regression test for GitHub issue #34506:
|
||||
"""Regression test for GitHub issue #34506:
|
||||
With audio + image + video (non-interleaved), audio positions must
|
||||
receive audio embeddings (not image or video embeddings).
|
||||
"""
|
||||
@@ -329,8 +321,7 @@ class TestEmbedInputIds:
|
||||
)
|
||||
|
||||
def test_interleaved_use_audio_in_video(self):
|
||||
"""
|
||||
Interleaved (use_audio_in_video): video chunks interleaved with audio.
|
||||
"""Interleaved (use_audio_in_video): video chunks interleaved with audio.
|
||||
Video embeddings must go to video positions, audio to audio positions.
|
||||
"""
|
||||
hidden = 8
|
||||
|
||||
@@ -232,7 +232,6 @@ def test_mm_device_do_normalize(
|
||||
num_imgs: int,
|
||||
):
|
||||
"""Ensure that enable mm_device_do_normalize yields the correct result."""
|
||||
|
||||
ctx = build_model_context(
|
||||
model_id,
|
||||
limit_mm_per_prompt={"image": num_imgs},
|
||||
|
||||
@@ -25,8 +25,7 @@ def test_processor_with_audio_sample_rate(
|
||||
audio_sample_rate: int,
|
||||
audio_duration_sec: float,
|
||||
) -> None:
|
||||
"""
|
||||
Test that vLLM's processor generates expected outputs with audio_sample_rate.
|
||||
"""Test that vLLM's processor generates expected outputs with audio_sample_rate.
|
||||
|
||||
This validates that the processor correctly handles audio_sample_rate
|
||||
passed via hf_processor_mm_kwargs and generates audio tokens.
|
||||
@@ -70,8 +69,7 @@ def test_processor_with_audio_sample_rate(
|
||||
|
||||
@pytest.mark.parametrize("model_id", ["Qwen/Qwen3-Omni-30B-A3B-Instruct"])
|
||||
def test_longer_audio_generates_more_tokens(model_id: str) -> None:
|
||||
"""
|
||||
Test that longer audio generates more tokens than shorter audio.
|
||||
"""Test that longer audio generates more tokens than shorter audio.
|
||||
|
||||
This validates that audio_sample_rate is being used correctly by checking
|
||||
that audio duration affects token count as expected.
|
||||
|
||||
@@ -31,7 +31,8 @@ def _build_video_mm_data(
|
||||
|
||||
``total_num_frames`` is set equal to the ndarray frame count so
|
||||
that HF's ``sample_frames`` indices stay within bounds of the
|
||||
actual tensor that is passed."""
|
||||
actual tensor that is passed.
|
||||
"""
|
||||
video = np.zeros((num_frames, height, width, 3), dtype=np.uint8)
|
||||
metadata = {
|
||||
"fps": original_fps,
|
||||
@@ -237,7 +238,8 @@ def _build_video_embeds_mm_data(
|
||||
grid_thw: tuple[int, int, int] = (2, 4, 4),
|
||||
) -> dict[str, Any]:
|
||||
"""Create an embeds-only video item as an EPD consumer receives it:
|
||||
pre-computed embeddings plus the metadata published by the encoder."""
|
||||
pre-computed embeddings plus the metadata published by the encoder.
|
||||
"""
|
||||
import torch
|
||||
|
||||
t, h, w = grid_thw
|
||||
@@ -256,7 +258,8 @@ def test_processor_video_embeds_with_timestamps(model_id: str) -> None:
|
||||
"""Embeds-only video input must size the placeholder range from the
|
||||
grid and the real timestamps published by the encoder (EC consumer
|
||||
path); synthesized or missing timestamps would change the token count
|
||||
and break embedding merging downstream."""
|
||||
and break embedding merging downstream.
|
||||
"""
|
||||
# `build_model_context` forces enable_mm_embeds off, so build the
|
||||
# config directly; keep the same online-availability skip behavior.
|
||||
HF_EXAMPLE_MODELS.find_hf_info(model_id).check_available_online(on_fail="skip")
|
||||
@@ -301,7 +304,8 @@ def test_processor_video_embeds_with_timestamps(model_id: str) -> None:
|
||||
def test_processor_video_embeds_missing_timestamps(model_id: str) -> None:
|
||||
"""Timestamps are required metadata for video embeds: they size the
|
||||
placeholder range, so omitting them must fail loudly at parse time
|
||||
instead of silently producing a wrong prompt."""
|
||||
instead of silently producing a wrong prompt.
|
||||
"""
|
||||
ctx = build_model_context(
|
||||
model_id,
|
||||
limit_mm_per_prompt={"image": 0, "video": 1},
|
||||
|
||||
@@ -116,7 +116,8 @@ def test_audio_multimodal_processor(model_id, processor_cls):
|
||||
@pytest.mark.parametrize("separator", [" and ", ""])
|
||||
def test_audio_multiple_inputs(separator, processor_cls):
|
||||
"""Multiple audios per prompt are each detected as a separate placeholder
|
||||
and multi-modal item by the Transformers modelling backend."""
|
||||
and multi-modal item by the Transformers modelling backend.
|
||||
"""
|
||||
model_id = "ibm-granite/granite-speech-3.3-2b"
|
||||
mm_processor = create_processor(model_id, processor_cls)
|
||||
|
||||
|
||||
@@ -83,7 +83,8 @@ def _process_two_images(processor_cls, separator: str):
|
||||
@pytest.mark.parametrize("processor_cls", PROCESSOR_CLASSES)
|
||||
def test_image_multiple_inputs(processor_cls):
|
||||
"""Multiple images per prompt are each detected as a separate placeholder
|
||||
and multi-modal item by the Transformers modelling backend."""
|
||||
and multi-modal item by the Transformers modelling backend.
|
||||
"""
|
||||
result = _process_two_images(processor_cls, separator="\n and ")
|
||||
|
||||
assert len(result["mm_placeholders"]["image"]) == 2
|
||||
@@ -102,7 +103,8 @@ def test_image_adjacent_inputs(processor_cls):
|
||||
@pytest.mark.parametrize("processor_cls", PROCESSOR_CLASSES)
|
||||
def test_batch_padding_removed_from_image_items(processor_cls):
|
||||
"""Emu3 pads every image up to the largest in the batch, which would leave an
|
||||
item's data dependent on what it was processed with and so uncacheable."""
|
||||
item's data dependent on what it was processed with and so uncacheable.
|
||||
"""
|
||||
mm_processor = create_processor("BAAI/Emu3-Chat-hf", processor_cls)
|
||||
image_token = mm_processor.info.get_hf_processor().image_token
|
||||
|
||||
@@ -144,7 +146,8 @@ def _process_one_gemma3_image(processor_cls):
|
||||
@offsets_only
|
||||
def test_non_embedding_tokens_excluded_from_placeholders():
|
||||
"""Gemma3 wraps each image in text that carries no embeddings, which must be
|
||||
inside the placeholder range but masked out of it."""
|
||||
inside the placeholder range but masked out of it.
|
||||
"""
|
||||
_, result = _process_one_gemma3_image(OffsetsMultiModalProcessor)
|
||||
|
||||
(placeholder,) = result["mm_placeholders"]["image"]
|
||||
@@ -156,7 +159,8 @@ def test_legacy_placeholders_hold_only_image_tokens():
|
||||
"""The legacy path spans whatever `mm_token_type_ids` attributes to the image,
|
||||
which for Gemma3 excludes the text wrapping it, unlike the replacement the offsets
|
||||
path spans. Gemma3 is also the sharp case for the mask: its `image_token_id` is the
|
||||
marker in the unexpanded prompt, not the token the expansion repeats."""
|
||||
marker in the unexpanded prompt, not the token the expansion repeats.
|
||||
"""
|
||||
hf_processor, result = _process_one_gemma3_image(LegacyMultiModalProcessor)
|
||||
|
||||
(placeholder,) = result["mm_placeholders"]["image"]
|
||||
@@ -172,7 +176,8 @@ def test_tokens_structuring_an_image_are_masked_not_dropped(processor_cls):
|
||||
embeddings. Those belong inside the placeholder and masked out, because the token
|
||||
count the processor reports is over the whole span. Idefics3 also refuses a prompt
|
||||
holding `<image>` when no images are passed, which is how the offsets path has to
|
||||
tokenize it before splicing in the expansion."""
|
||||
tokenize it before splicing in the expansion.
|
||||
"""
|
||||
mm_processor = create_processor(
|
||||
"HuggingFaceTB/SmolVLM-256M-Instruct", processor_cls
|
||||
)
|
||||
@@ -192,7 +197,8 @@ def test_tokens_structuring_an_image_are_masked_not_dropped(processor_cls):
|
||||
@offsets_only
|
||||
def test_missing_replacement_offsets_names_the_processor():
|
||||
"""A processor that reports no replacement offsets cannot be served, which must
|
||||
be said plainly rather than surfacing later as a field config mismatch."""
|
||||
be said plainly rather than surfacing later as a field config mismatch.
|
||||
"""
|
||||
model_id = "llava-hf/llava-onevision-qwen2-0.5b-ov-hf"
|
||||
mm_processor = create_processor(model_id, OffsetsMultiModalProcessor)
|
||||
hf_processor_cls = type(mm_processor.info.get_hf_processor())
|
||||
@@ -276,7 +282,8 @@ def test_repeated_image_hits_the_processor_cache():
|
||||
def test_spliced_prompt_matches_hf_expansion(model_id, prompt):
|
||||
"""The offsets path splices the expansion into a prompt tokenized without any
|
||||
multi-modal data, so its token ids have to come out the same as the ones the HF
|
||||
processor produces itself, which is what the legacy path returns."""
|
||||
processor produces itself, which is what the legacy path returns.
|
||||
"""
|
||||
prompt_ids = []
|
||||
for processor_cls in (LegacyMultiModalProcessor, OffsetsMultiModalProcessor):
|
||||
mm_processor = create_processor(model_id, processor_cls)
|
||||
@@ -298,7 +305,8 @@ def test_spliced_prompt_matches_hf_expansion(model_id, prompt):
|
||||
def test_nested_image_fields_split_per_image(processor_cls):
|
||||
"""Idefics3 returns image fields with a leading batch dimension, putting the rows
|
||||
belonging to each image one dimension further in. Slicing the batch dimension
|
||||
instead handed the first image every row and the second an empty tensor."""
|
||||
instead handed the first image every row and the second an empty tensor.
|
||||
"""
|
||||
mm_processor = create_processor(
|
||||
"HuggingFaceTB/SmolVLM-256M-Instruct", processor_cls
|
||||
)
|
||||
|
||||
@@ -29,7 +29,8 @@ PROCESSOR_CLASSES = [
|
||||
|
||||
def create_processor(model_id: str, processor_cls):
|
||||
"""Build a processor directly, because the registry only ever builds the one the
|
||||
installed transformers version selects, leaving the other path untested."""
|
||||
installed transformers version selects, leaving the other path untested.
|
||||
"""
|
||||
model_config = ModelConfig(model=model_id, model_impl="transformers")
|
||||
ctx = InputProcessingContext(
|
||||
model_config, cached_tokenizer_from_config(model_config)
|
||||
@@ -40,7 +41,8 @@ def create_processor(model_id: str, processor_cls):
|
||||
|
||||
def create_cached_processor(model_id: str, processor_cls):
|
||||
"""Build a processor backed by a real multi-modal processor cache, and hand the
|
||||
cache back so a test can check it was actually used."""
|
||||
cache back so a test can check it was actually used.
|
||||
"""
|
||||
model_config = ModelConfig(model=model_id, model_impl="transformers")
|
||||
model_config.multimodal_config.mm_processor_cache_gb = 4
|
||||
ctx = InputProcessingContext(
|
||||
|
||||
@@ -18,7 +18,8 @@ from vllm.model_executor.models.cohere_asr import CohereAsrForConditionalGenerat
|
||||
def test_get_num_audio_tokens_streaming_estimate(audio_duration_s, expected_tokens):
|
||||
"""The duration-based estimate must convert ``window_stride`` (seconds) to a
|
||||
sample hop and divide by the encoder subsampling factor. Values are pinned to
|
||||
concrete numbers so a rounding regression is actually caught."""
|
||||
concrete numbers so a rounding regression is actually caught.
|
||||
"""
|
||||
model_config = SimpleNamespace(
|
||||
hf_config=SimpleNamespace(
|
||||
preprocessor={"window_stride": 0.01, "sample_rate": 16000},
|
||||
|
||||
@@ -78,7 +78,8 @@ def test_cosmos3_modelopt_quantizer_weights_mapper():
|
||||
"""ModelOpt/Diffusers FP8 checkpoints ship native fake-quant buffers
|
||||
(``*_quantizer._amax`` / ``._scale``) alongside the vLLM-consumable
|
||||
``weight_scale`` / ``input_scale`` sidecars. vLLM must drop the former
|
||||
(it has no parameter for them) while keeping the latter."""
|
||||
(it has no parameter for them) while keeping the latter.
|
||||
"""
|
||||
from vllm.model_executor.models.cosmos3 import Cosmos3ForConditionalGeneration
|
||||
|
||||
mapper = Cosmos3ForConditionalGeneration.hf_to_vllm_mapper
|
||||
@@ -215,7 +216,7 @@ def test_bailing_vl_mapper_handles_module_and_parameter_names():
|
||||
|
||||
|
||||
def create_repo_dummy_weights(repo: str) -> Iterable[tuple[str, torch.Tensor]]:
|
||||
"""Create weights from safetensors checkpoint metadata"""
|
||||
"""Create weights from safetensors checkpoint metadata."""
|
||||
metadata = try_get_safetensors_metadata(repo)
|
||||
weight_names = list(metadata.weight_map.keys())
|
||||
with torch.device("meta"):
|
||||
@@ -223,9 +224,7 @@ def create_repo_dummy_weights(repo: str) -> Iterable[tuple[str, torch.Tensor]]:
|
||||
|
||||
|
||||
def create_dummy_base_model(repo: str, model_arch: str) -> PreTrainedModel:
|
||||
"""
|
||||
Create weights from a dummy meta deserialized hf base model with name conversion
|
||||
"""
|
||||
"""Create weights from a dummy meta-deserialized HF base model, with renaming."""
|
||||
config = AutoConfig.from_pretrained(repo)
|
||||
with torch.device("meta"):
|
||||
model = AutoModel.from_config(config)
|
||||
@@ -233,9 +232,7 @@ def create_dummy_base_model(repo: str, model_arch: str) -> PreTrainedModel:
|
||||
|
||||
|
||||
def create_dummy_model(repo: str, model_arch: str) -> PreTrainedModel:
|
||||
"""
|
||||
Create weights from a dummy meta deserialized hf model with name conversion
|
||||
"""
|
||||
"""Create weights from a dummy meta deserialized hf model with name conversion."""
|
||||
model_cls: PreTrainedModel = getattr(transformers, model_arch)
|
||||
config = AutoConfig.from_pretrained(repo)
|
||||
with torch.device("meta"):
|
||||
|
||||
@@ -81,7 +81,8 @@ class _FakeTensor:
|
||||
"""Sentinel stand-in for torch.Tensor in load_weights tests. Supports the
|
||||
.detach().clone() chain used by load_weights for buffered mm weights;
|
||||
both methods return self so identity (and the existing equality
|
||||
assertions) are preserved through cloning."""
|
||||
assertions) are preserved through cloning.
|
||||
"""
|
||||
|
||||
def detach(self):
|
||||
return self
|
||||
@@ -165,7 +166,8 @@ def _make_mm_items_with_video_bytes(
|
||||
|
||||
def test_extract_audio_from_videos_passes_max_duration():
|
||||
"""_extract_audio_from_videos must forward VLLM_MAX_AUDIO_DECODE_DURATION_S
|
||||
to load_audio_pyav so decompression-bomb audio is rejected."""
|
||||
to load_audio_pyav so decompression-bomb audio is rejected.
|
||||
"""
|
||||
dummy_audio = (np.zeros(16000, dtype=np.float32), 16000.0)
|
||||
mm_items = _make_mm_items_with_video_bytes(b"\x00" * 64)
|
||||
|
||||
@@ -185,7 +187,8 @@ def test_extract_audio_from_videos_passes_max_duration():
|
||||
|
||||
def test_extract_audio_from_videos_rejects_oversized_audio():
|
||||
"""When load_audio_pyav raises due to duration limit the video is
|
||||
marked as having no audio instead of crashing the server."""
|
||||
marked as having no audio instead of crashing the server.
|
||||
"""
|
||||
mm_items = _make_mm_items_with_video_bytes(b"\x00" * 64)
|
||||
|
||||
processor = object.__new__(NanoNemotronVLMultiModalProcessor)
|
||||
|
||||
Reference in New Issue
Block a user