vllm.multimodal.media.base
¶
Classes:
-
DecodeSpec–Canonical snapshot of the decode settings included in a media key.
-
MediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
MediaRef–A reference to one piece of fetched media.
Functions:
-
derive_media_key–Derive a cache key from encoded bytes and the decode spec.
DecodeSpec
dataclass
¶
Canonical snapshot of the decode settings included in a media key.
Methods:
-
canonical_bytes–Return the canonical JSON bytes used for key derivation.
-
extend–Return a copy with
settingsmerged over the current ones.
Attributes:
Source code in vllm/multimodal/media/base.py
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_decode_spec–Return the decode configuration to fold into a ref's cache key.
-
get_max_bytes–Return the maximum encoded payload size accepted by this media IO.
-
load_base64–List of media types:
-
load_base64_ref–Ref variant of
load_base64; the base64 decoding stays eager. -
load_bytes_ref–Return a reference that decodes
dataon first access. -
load_file_ref–Ref variant of
load_file; the file read stays eager. -
merge_kwargs–Merge config-level kwargs and request-level kwargs.
Source code in vllm/multimodal/media/base.py
get_decode_spec()
¶
Return the decode configuration to fold into a ref's cache key.
None when this IO has no settings that affect the decoded media.
get_max_bytes()
¶
load_base64(media_type, data)
abstractmethod
¶
List of media types: https://www.iana.org/assignments/media-types/media-types.xhtml
load_base64_ref(media_type, data)
¶
Ref variant of load_base64; the base64 decoding stays eager.
load_bytes_ref(data)
¶
Return a reference that decodes data on first access.
Decoding errors surface at the use site (e.g. inside the multi-modal processor) instead of at the fetch site.
Source code in vllm/multimodal/media/base.py
load_file_ref(filepath)
¶
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.
Source code in vllm/multimodal/media/base.py
MediaRef
¶
Bases: Generic[_T]
A reference to one piece of fetched media.
This is the single value type for media that vLLM fetched and has not (yet) decoded. It carries three things:
key: the cache identity, derived from the encoded bytes andspecwithout decoding, so hashing never pays a decode cost.spec: the decode configuration that parameterized or mutated the media, already folded intokey.decode(): the decoded media, produced at most once and thread-safely.
Methods:
-
decode–Return the decoded media, decoding at most once.
-
fork–Borrow this ref through an independently releasable wrapper.
-
map–Return a ref decoding to
transform(self.decode()). -
release–Drop this ref's encoded bytes and decode closure.
Attributes:
Source code in vllm/multimodal/media/base.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
data
property
¶
The encoded bytes; b"" once release() has run.
decode()
¶
Return the decoded media, decoding at most once.
Thread-safe. Exceptions from the decoder propagate unchanged; wrapping them is the caller's job.
Raises:
-
RuntimeError–If the ref was released before being decoded.
Source code in vllm/multimodal/media/base.py
fork()
¶
map(transform, **settings)
¶
Return a ref decoding to transform(self.decode()).
Shares this ref's bytes (no copy) so the parse layer can stack
transforms (e.g. audio resampling) onto the decode step. settings
extend the spec -- and therefore the key -- so the transform's own
parameters stay part of the cache identity. The new key is derived
from this ref's key rather than by re-digesting the payload.
With no settings, the key is preserved: use this only for transforms that preserve cache identity. Output-changing transforms must supply settings identifying the transform and every output-affecting parameter.
Source code in vllm/multimodal/media/base.py
release()
¶
Drop this ref's encoded bytes and decode closure.
Call once hashing is done and the item is either decoded or known to be a cache hit, after any in-flight decode has finished. Decoded media remains readable; an undecoded ref cannot decode after release.
Other owners can retain the payload: a mapped ref does not release a separately retained parent, and decoded media may contain encoded bytes.
Source code in vllm/multimodal/media/base.py
_media_ref_from_pickle(media, key, spec)
¶
Rebuild a ref pickled by MediaRef.__reduce__.
Neither the decode closure nor the lock is picklable, so a ref pickles as its decoded media: the result is already decoded, keeps its key and spec, and carries no encoded bytes.
Source code in vllm/multimodal/media/base.py
derive_media_key(data, spec)
¶
Derive a cache key from encoded bytes and the decode spec.
Header-only parsing at most: this never decodes pixels, frames or PCM, so the cost of keying media is independent of the cost of decoding it. It is still linear in the payload, so callers on an event loop should offload it.
sha256 rather than the configured MMHasherAlgorithm: the key must not
depend on which optional hash packages happen to be installed.