vllm.multimodal.utils
global_thread_pool module-attribute
¶
global_thread_pool = ThreadPoolExecutor(
max_workers=VLLM_MEDIA_LOADING_THREAD_COUNT
)
MediaConnector ¶
Source code in vllm/multimodal/utils.py
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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
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 ¶
load_from_url(
url: str,
media_io: MediaIO[_M" backlink-type="used-by" backlink-anchor="vllm.multimodal.utils.MediaConnector.load_from_url" optional hover>_M],
*,
fetch_timeout: Optional[int] = None,
) -> _M
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
argsort_mm_positions ¶
argsort_mm_positions(
mm_positions: MultiModalPlaceholderDict,
) -> list[tuple[str, int]]
Given a MultiModalPlaceholderDict
, output a sequence of keys to sort the dictionary by offset
(starting index in the input sequence) in ascending order.
Returns:
Type | Description |
---|---|
list[tuple[str, int]] | A list of |
list[tuple[str, int]] | by |
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
get_load_balance_assignment ¶
get_load_balance_assignment(
sizes: list[int], num_gpus: int = 2
) -> tuple[list[int], list[int], list[int]]
Generate load balancing assignment and metadata for distributing data across GPUs. The load is determined by the total image sizes, not the number of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sizes | list[int] | The size of each image | required |
num_gpus | int | Number of GPUs to balance across | 2 |
Returns:
Name | Type | Description |
---|---|---|
shuffle_indices | list[int] | Indices to reorder data for balanced loading |
gpu_sample_counts | list[int] | Number of samples assigned to each GPU |
grouped_sizes_per_gpu | list[int] | Total size assigned to each GPU |
Source code in vllm/multimodal/utils.py
group_mm_inputs_by_modality ¶
group_mm_inputs_by_modality(
mm_inputs: list[MultiModalKwargsItems],
) -> list[list[MultiModalKwargsItems]]
Source code in vllm/multimodal/utils.py
group_mm_kwargs_by_modality ¶
group_mm_kwargs_by_modality(
mm_kwargs: list[MultiModalKwargsItem],
*,
device: Device = None,
pin_memory: bool = False,
) -> Iterable[tuple[str, int, BatchedTensorInputs]]
Group consecutive MultiModalKwargsItem
s from mm_kwargs
with the same modality together into the same MultiModalKwargs
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mm_inputs | List of | required |
Yields:
Type | Description |
---|---|
Iterable[tuple[str, int, BatchedTensorInputs]] | A tuple |
Source code in vllm/multimodal/utils.py
run_dp_sharded_mrope_vision_model ¶
run_dp_sharded_mrope_vision_model(
vision_model: Module,
pixel_values: Tensor,
grid_thw_list: list[list[int]],
) -> tuple[Tensor, ...]
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. This function is used to run the vision model with mrope.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vision_model | Module | Vision model. | required |
pixel_values | Tensor | Image/Video input tensor. | required |
grid_thw_list | list[list[int]] | List of grid dimensions for each image | required |
Returns: torch.Tensor: Output image embeddings
Example
Source code in vllm/multimodal/utils.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
|
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 |