vllm.model_executor.models.vision ΒΆ
VisionFeatureSelectStrategy module-attribute
ΒΆ
VisionFeatureSelectStrategy = Union[
Literal["class", "default", "full"],
Callable[[Tensor], Tensor],
]
VisionEncoderInfo ΒΆ
Source code in vllm/model_executor/models/vision.py
VisionLanguageConfig ΒΆ
_get_vision_feature_selector ΒΆ
_get_vision_feature_selector(
strategy: VisionFeatureSelectStrategy,
) -> Callable[[Tensor], Tensor]
Source code in vllm/model_executor/models/vision.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/model_executor/models/vision.py
get_vision_encoder_info ΒΆ
get_vision_encoder_info(
hf_config: VisionLanguageConfig,
) -> VisionEncoderInfo
Source code in vllm/model_executor/models/vision.py
get_vit_attn_backend ΒΆ
Get the available attention backend for Vision Transformer.
Source code in vllm/model_executor/models/vision.py
resolve_visual_encoder_outputs ΒΆ
resolve_visual_encoder_outputs(
encoder_outputs: Union[Tensor, list[Tensor]],
post_layer_norm: Optional[LayerNorm],
*,
select_layers: Optional[list[int]] = None,
max_possible_layers: Optional[int] = None,
feature_select_strategy: Optional[
VisionFeatureSelectStrategy
] = None,
) -> Tensor
Given the outputs a visual encoder module that may correspond to the output of the last layer, or a list of hidden states to be stacked, handle post normalization and resolve it into a single output tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoder_outputs | Union[Tensor, list[Tensor]] | Output of encoder's last layer or all hidden states. | required |
post_layer_norm | Optional[LayerNorm] | Post norm to apply to the output of the encoder. | required |
select_layers | Optional[list[int]] | Optional layer indices to grab from the encoder outputs; if provided, encoder outputs must be a list. | None |
max_possible_layers | Optional[int] | Total layers in the fully loaded visual encoder. | None |
feature_select_strategy | Optional[VisionFeatureSelectStrategy] | Defines how to select the hidden states from each layer. | None |
Source code in vllm/model_executor/models/vision.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]],
*,
rope_type: Literal["rope_3d", "rope_2d"],
) -> 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 |
rope_type | Literal['rope_3d', 'rope_2d'] | Type of rope used in the vision model. Different rope types have different dimension to do ViT. "rope_3d" for 3D rope (e.g., Qwen2.5-VL) "rope_2d" for 2D rope (e.g., Kimi-VL) | required |
Returns: torch.Tensor: Output image embeddings
Example
Source code in vllm/model_executor/models/vision.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
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: torch.Tensor: Output image embeddings