@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 10214b6935
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 05:30 UTC

[FEATURE]: Use pydantic validation in `multimodal.py` config (#26629)

Signed-off-by: Anand Roy <86306690+andycandy@users.noreply.github.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Anand Roy committed Oct 13, 2025 at 20:26 UTC 10214b69359530c4c5cb8a0a7d33ecdf402789a2
1 file changed +18 -7
vllm/config/multimodal.py
+18 -7
@@ -3,10 +3,9 @@
3
4 import hashlib
5 from collections.abc import Mapping
6 -from dataclasses import field
6 from typing import Any, Literal, TypeAlias
7
9 -from pydantic import ConfigDict, Field, field_validator
8 +from pydantic import ConfigDict, Field, field_validator, model_validator
9 from pydantic.dataclasses import dataclass
10
11 from vllm.config.utils import config
@@ -55,7 +54,7 @@ DummyOptions: TypeAlias = (
54 class MultiModalConfig:
55 """Controls the behavior of multimodal models."""
56
58 - limit_per_prompt: dict[str, DummyOptions] = field(default_factory=dict)
57 + limit_per_prompt: dict[str, DummyOptions] = Field(default_factory=dict)
58 """The maximum number of input items and options allowed per
59 prompt for each modality.
60 Defaults to 999 for each modality.
@@ -71,7 +70,7 @@ class MultiModalConfig:
70 {"image": 16, "video": {"count": 1, "num_frames": 32, "width": 512,
71 "height": 512}}
72 """
74 - media_io_kwargs: dict[str, dict[str, Any]] = field(default_factory=dict)
73 + media_io_kwargs: dict[str, dict[str, Any]] = Field(default_factory=dict)
74 """Additional args passed to process media inputs, keyed by modalities.
75 For example, to set num_frames for video, set
76 `--media-io-kwargs '{"video": {"num_frames": 40} }'`"""
@@ -84,7 +83,7 @@ class MultiModalConfig:
83
84 For example, for Phi-3-Vision:
85 `{"num_crops": 4}`."""
87 - mm_processor_cache_gb: float = 4
86 + mm_processor_cache_gb: float = Field(default=4, ge=0)
87 """The size (in GiB) of the multi-modal processor cache, which is used to
88 avoid re-processing past multi-modal inputs.
89
@@ -96,7 +95,7 @@ class MultiModalConfig:
95 mm_processor_cache_type: MMCacheType = "lru"
96 """Type of cache to use for the multi-modal preprocessor/mapper. If `shm`,
97 use shared memory FIFO cache. If `lru`, use mirrored LRU cache."""
99 - mm_shm_cache_max_object_size_mb: int = 128
98 + mm_shm_cache_max_object_size_mb: int = Field(default=128, ge=0)
99 """Size limit (in MiB) for each object stored in the multi-modal processor
100 shared memory cache. Only effective when `mm_processor_cache_type` is
101 `"shm"`."""
@@ -123,7 +122,7 @@ class MultiModalConfig:
122 This reduces engine startup time but shifts the responsibility to users for
123 estimating the peak memory usage of the activation of multimodal encoder and
124 embedding cache."""
126 - video_pruning_rate: float | None = None
125 + video_pruning_rate: float | None = Field(default=None, ge=0.0, lt=1.0)
126 """Sets pruning rate for video pruning via Efficient Video Sampling.
127 Value sits in range [0;1) and determines fraction of media tokens
128 from each video to be pruned.
@@ -149,6 +148,18 @@ class MultiModalConfig:
148 value[k] = BaseDummyOptions(**v)
149 return value
150
151 + @model_validator(mode="after")
152 + def _validate_multimodal_config(self):
153 + if self.mm_processor_cache_type != "shm" and (
154 + self.mm_shm_cache_max_object_size_mb
155 + != MultiModalConfig.mm_shm_cache_max_object_size_mb
156 + ):
157 + raise ValueError(
158 + "'mm_shm_cache_max_object_size_mb' should only be set when "
159 + "'mm_processor_cache_type' is 'shm'."
160 + )
161 + return self
162 +
163 def compute_hash(self) -> str:
164 """
165 WARNING: Whenever a new field is added to this config,