vllm.multimodal.utils
MediaConnector
¶
Source code in vllm/multimodal/utils.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
media_io_kwargs
instance-attribute
¶
__init__
¶
__init__(
media_io_kwargs: Optional[
dict[str, dict[str, Any]]
] = None,
connection: HTTPConnection = global_http_connection,
*,
allowed_local_media_path: str = "",
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
media_io_kwargs
|
Optional[dict[str, dict[str, Any]]]
|
Additional args passed to process media
inputs, keyed by modalities. For example,
to set num_frames for video, set
|
None
|
connection
|
HTTPConnection
|
HTTP connection client to download media contents. |
global_http_connection
|
allowed_local_media_path
|
str
|
A local directory to load media files from. |
''
|
Source code in vllm/multimodal/utils.py
_load_data_url
¶
_load_data_url(
url_spec: ParseResult, media_io: MediaIO[_M]
) -> _M
Source code in vllm/multimodal/utils.py
_load_file_url
¶
_load_file_url(
url_spec: ParseResult, media_io: MediaIO[_M]
) -> _M
Source code in vllm/multimodal/utils.py
fetch_audio
¶
Load audio from a URL.
Source code in vllm/multimodal/utils.py
fetch_audio_async
async
¶
Asynchronously fetch audio from a URL.
Source code in vllm/multimodal/utils.py
fetch_image
¶
Load a PIL image from a HTTP or base64 data URL.
By default, the image is converted into RGB format.
Source code in vllm/multimodal/utils.py
fetch_image_async
async
¶
Asynchronously load a PIL image from a HTTP or base64 data URL.
By default, the image is converted into RGB format.
Source code in vllm/multimodal/utils.py
fetch_image_embedding
¶
Load image embedding from a URL.
fetch_video
¶
Load video from a HTTP or base64 data URL.
Source code in vllm/multimodal/utils.py
fetch_video_async
async
¶
Asynchronously load video from a HTTP or base64 data URL.
By default, the image is converted into RGB format.
Source code in vllm/multimodal/utils.py
load_from_url
¶
Source code in vllm/multimodal/utils.py
load_from_url_async
async
¶
load_from_url_async(
url: str,
media_io: MediaIO[_M],
*,
fetch_timeout: Optional[int] = None,
) -> _M
Source code in vllm/multimodal/utils.py
encode_audio_base64
¶
encode_image_base64
¶
Encode a pillow image to base64 format.
By default, the image is converted into RGB format before being encoded.
Source code in vllm/multimodal/utils.py
encode_video_base64
¶
fetch_audio
¶
fetch_audio(
audio_url: str,
audio_io_kwargs: Optional[dict[str, Any]] = None,
) -> tuple[ndarray, Union[int, float]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio_url
|
str
|
URL of the audio file to fetch. |
required |
audio_io_kwargs
|
Optional[dict[str, Any]]
|
Additional kwargs passed to handle audio IO. |
None
|
Source code in vllm/multimodal/utils.py
fetch_image
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_url
|
str
|
URL of the image file to fetch. |
required |
image_io_kwargs
|
Optional[dict[str, Any]]
|
Additional kwargs passed to handle image IO. |
None
|
Source code in vllm/multimodal/utils.py
fetch_video
¶
fetch_video(
video_url: str,
video_io_kwargs: Optional[dict[str, Any]] = None,
) -> tuple[NDArray, dict[str, Any]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
video_url
|
str
|
URL of the video file to fetch. |
required |
video_io_kwargs
|
Optional[dict[str, Any]]
|
Additional kwargs passed to handle video IO. |
None
|
Source code in vllm/multimodal/utils.py
group_mm_inputs_by_modality
¶
group_mm_inputs_by_modality(
mm_inputs: list[MultiModalKwargs],
) -> list[list[MultiModalKwargs]]
Group consecutive MultiModalKwargs from mm_inputs with the same modality together into the same list for batching purpose. For MultiModalKwargs with multiple modalities, put them into their own list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mm_inputs
|
list[MultiModalKwargs]
|
List of MultiModalKwargs. |
required |
Returns:
Type | Description |
---|---|
list[list[MultiModalKwargs]]
|
list[list[vllm.multimodal.MultiModalKwargs]]: List of list of |
list[list[MultiModalKwargs]]
|
|
list[list[MultiModalKwargs]]
|
|
Source code in vllm/multimodal/utils.py
merge_and_sort_multimodal_metadata
¶
merge_and_sort_multimodal_metadata(
mm_positions: MultiModalPlaceholderDict,
mm_hashes: Optional[MultiModalHashDict],
) -> tuple[
list[str], list[PlaceholderRange], Optional[list[str]]
]
Given a MultiModalPlaceholderDict, merge all PlaceholderRange objects from all available modalities into a single list of PlaceholderRange, sorted by their offset (starting index in the input sequence) in the ascending order.
Optionally if a MultiModalHashDict
is given, same operation will be
applied to the object and the sorted list of hashes will be returned.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of item modalities in order of their positions in the |
list[PlaceholderRange]
|
input sequence. |
Optional[list[str]]
|
list[PlaceholderRange]: Sorted list of all PlaceholderRanges from |
tuple[list[str], list[PlaceholderRange], Optional[list[str]]]
|
mm_positions. |
tuple[list[str], list[PlaceholderRange], Optional[list[str]]]
|
Optional[list[str]]: Sorted list of all hashes from mm_hashes if given, |
tuple[list[str], list[PlaceholderRange], Optional[list[str]]]
|
None otherwise. |
Source code in vllm/multimodal/utils.py
run_dp_sharded_vision_model
¶
Run a vision model with data parallelism (DP) sharding. The function will shard the input image tensor on the first dimension and run the vision model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_input
|
Tensor
|
Image input tensor. |
required |
vision_model
|
Module
|
Vision model. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Output image embeddings |