vllm.multimodal.media
¶
Modules:
Classes:
-
AudioEmbeddingMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
AudioMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
ImageEmbeddingMediaIO–Image embedding MediaIO implementation.
-
ImageMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
MediaConnector–Configuration values can be user-provided either by --media-io-kwargs or
-
MediaDecodedBudget–Thread-safe decoded-media byte accumulator for one request.
-
MediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
MediaWithBytes–Wrapper that couples a media object with its original encoded bytes.
-
VideoMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
AudioEmbeddingMediaIO
¶
AudioMediaIO
¶
ImageEmbeddingMediaIO
¶
ImageMediaIO
¶
MediaConnector
¶
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Methods:
-
__init__–Args:
-
fetch_audio–Load audio from a URL.
-
fetch_audio_async–Asynchronously fetch audio from a URL.
-
fetch_audio_embedding–Load audio embedding from a URL.
-
fetch_audio_embedding_async–Asynchronously load audio embedding from a URL.
-
fetch_image–Load a PIL image from an HTTP or base64 data URL.
-
fetch_image_async–Asynchronously load a PIL image from an HTTP or base64 data URL.
-
fetch_image_embedding–Load image embedding from a URL.
-
fetch_image_embedding_async–Asynchronously load image embedding from a URL.
-
fetch_video–Load video from an HTTP or base64 data URL.
-
fetch_video_async–Asynchronously load video from an HTTP or base64 data URL.
-
fetch_video_embedding–Load video embedding from a URL.
-
fetch_video_embedding_async–Asynchronously load video embedding from a URL.
__init__(media_io_kwargs=None, connection=global_http_connection, *, allowed_local_media_path='', allowed_media_domains=None, decoded_budget=None, download_budget=None)
¶
media_io_kwargs: Additional args passed to process media
inputs, keyed by modalities. For example,
to set num_frames for video, set
--media-io-kwargs '{"video":{"num_frames":40}}'
connection: HTTP connection client to download media contents.
allowed_local_media_path: A local directory to load media files from.
allowed_media_domains: If set, only media URLs that belong to this
domain can be used for multi-modal inputs.
_get_cached_bytes(url)
¶
Return cached bytes for a URL, or None if not cached/expired.
_maybe_evict(exclude=None)
¶
Evict expired entries first, then LRU until under size limit.
_put_cached_bytes(url, data)
¶
Store downloaded bytes and evict if over budget.
fetch_audio(audio_url)
¶
Load audio from a URL.
fetch_audio_async(audio_url)
async
¶
Asynchronously fetch audio from a URL.
fetch_audio_embedding(data)
¶
Load audio embedding from a URL.
fetch_audio_embedding_async(data)
async
¶
Asynchronously load audio embedding from a URL.
fetch_image(image_url, *, image_mode='RGB')
¶
Load a PIL image from an HTTP or base64 data URL.
By default, the image is converted into RGB format. Set
media_io_kwargs={"image": {"image_mode": None}} to keep the
original image mode (e.g. preserving the alpha channel).
fetch_image_async(image_url, *, image_mode='RGB')
async
¶
Asynchronously load a PIL image from an HTTP or base64 data URL.
By default, the image is converted into RGB format. Set
media_io_kwargs={"image": {"image_mode": None}} to keep the
original image mode (e.g. preserving the alpha channel).
fetch_image_embedding(data)
¶
Load image embedding from a URL.
fetch_image_embedding_async(data)
async
¶
Asynchronously load image embedding from a URL.
fetch_video(video_url, *, image_mode='RGB', video_processor=None, video_io_defaults=None)
¶
Load video from an HTTP or base64 data URL.
fetch_video_async(video_url, *, image_mode='RGB', video_processor=None, video_io_defaults=None)
async
¶
Asynchronously load video from an HTTP or base64 data URL.
By default, the image is converted into RGB format. Set
media_io_kwargs={"image": {"image_mode": None}} to keep the
original image mode (e.g. preserving the alpha channel).
fetch_video_embedding(data)
¶
Load video embedding from a URL.
fetch_video_embedding_async(data)
async
¶
Asynchronously load video embedding from a URL.
MediaDecodedBudget
¶
Thread-safe decoded-media byte accumulator for one request.
Methods:
MediaIO
¶
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Methods:
-
get_max_bytes–Return the maximum encoded payload size accepted by this media IO.
-
load_base64–List of media types:
-
merge_kwargs–Merge config-level kwargs and request-level kwargs.
get_max_bytes()
¶
Return the maximum encoded payload size accepted by this media IO.
load_base64(media_type, data)
abstractmethod
¶
List of media types: https://www.iana.org/assignments/media-types/media-types.xhtml
merge_kwargs(default_kwargs, runtime_kwargs)
classmethod
¶
Merge config-level kwargs and request-level kwargs.
By default this performs a shallow merge where runtime kwargs override keys in default kwargs. Subclasses may override to apply modality- specific behavior.
MediaWithBytes
dataclass
¶
Bases: Generic[_T]
Wrapper that couples a media object with its original encoded bytes.
This ensures the raw bytes and media object remain synchronized, preventing cache corruption from in-place modifications.
The wrapper delegates attribute access to the underlying media object, making it behave transparently like the wrapped type (e.g., PIL.Image).
NOTE: Currently, this wrapper is used only for the image and video modalities.
Methods:
-
__array__–Allow np.array(obj) to return np.array(obj.media).
-
__getattr__–Delegate attribute access to the underlying media object.
-
__getitem__–Allow obj[i] to index obj.media (e.g. video tuples).
-
__iter__–Allow unpacking obj to unpack obj.media (e.g. video tuples).
Attributes:
-
io_config(dict[str, Any] | None) –Decode settings that altered the media relative to
original_bytes
io_config = None
class-attribute
instance-attribute
¶
Decode settings that altered the media relative to original_bytes
(e.g. image_mode conversion), so they participate in cache hashing.
__array__(*args, **kwargs)
¶
Allow np.array(obj) to return np.array(obj.media).
__getattr__(name)
¶
Delegate attribute access to the underlying media object.
__getitem__(index)
¶
Allow obj[i] to index obj.media (e.g. video tuples).
__iter__()
¶
Allow unpacking obj to unpack obj.media (e.g. video tuples).
VideoMediaIO
¶
Bases: MediaIO[MediaWithBytes[tuple[DecodedFrames, dict[str, Any]]]]
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Use --media-io-kwargs '{"video": {"backend": "torchcodec", "device": "cuda"}}' to decode with NVDEC and keep frames on the GPU, which pairs with a device-side multi-modal processor (--mm-processor-device, EPD encode-only instances).