vllm.model_executor.models.pixtral ¶
Attention ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
__init__ ¶
__init__(args: VisionEncoderArgs)
Source code in vllm/model_executor/models/pixtral.py
forward ¶
Source code in vllm/model_executor/models/pixtral.py
FeedForward ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
__init__ ¶
__init__(args: VisionEncoderArgs)
Source code in vllm/model_executor/models/pixtral.py
PatchMerger ¶
Bases: Module
Learned merging of spatial_merge_size ** 2 patches
Source code in vllm/model_executor/models/pixtral.py
merging_layer instance-attribute ¶
merging_layer = Linear(
mlp_input_dim, vision_encoder_dim, bias=use_mlp_bias
)
__init__ ¶
Source code in vllm/model_executor/models/pixtral.py
forward ¶
Source code in vllm/model_executor/models/pixtral.py
permute ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | (N, D) where N is flattened and concatenated patch tokens for all images | required |
image_sizes | list[tuple[int, int]] | list of tuple of (height, width) in tokens for each image | required |
Returns: image_features: reorders patch tokens so each grid of (spatial_merge_size, spatial_merge_size) is contiguous. now (N / spatial_merge_size ** 2, D * spatial_merge_size ** 2)
Source code in vllm/model_executor/models/pixtral.py
PixtralDummyInputsBuilder ¶
Bases: BaseDummyInputsBuilder[PixtralProcessingInfo]
Source code in vllm/model_executor/models/pixtral.py
get_dummy_mm_data ¶
get_dummy_mm_data(
seq_len: int,
mm_counts: Mapping[str, int],
mm_options: Mapping[str, BaseDummyOptions]
| None = None,
) -> MultiModalDataDict
Source code in vllm/model_executor/models/pixtral.py
get_dummy_processor_inputs ¶
get_dummy_processor_inputs(
seq_len: int,
mm_counts: Mapping[str, int],
mm_options: Mapping[str, BaseDummyOptions]
| None = None,
) -> ProcessorInputs
Source code in vllm/model_executor/models/pixtral.py
PixtralForConditionalGeneration ¶
Bases: Module, SupportsLoRA, SupportsMultiModal, SupportsPP
Source code in vllm/model_executor/models/pixtral.py
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 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 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 | |
language_model instance-attribute ¶
language_model = init_vllm_registered_model(
vllm_config=vllm_config,
hf_config=text_config,
prefix=maybe_prefix(prefix, "language_model"),
)
make_empty_intermediate_tensors instance-attribute ¶
patch_merger instance-attribute ¶
patch_merger = (
PatchMerger(
vision_encoder_dim=hidden_size,
spatial_merge_size=spatial_merge_size,
use_mlp_bias=False,
)
if mm_projector_id == PATCH_MERGE
else None
)
pre_mm_projector_norm instance-attribute ¶
pre_mm_projector_norm = (
RMSNorm(hidden_size, eps=1e-05)
if add_pre_mm_projector_layer_norm
else None
)
vision_language_adapter instance-attribute ¶
vision_language_adapter = VisionLanguageAdapter(
vision_args, dim=hidden_size
)
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/pixtral.py
_parse_and_validate_image_input ¶
_parse_and_validate_image_input(
**kwargs: object,
) -> PixtralImagePixelInputs | None
Source code in vllm/model_executor/models/pixtral.py
_process_image_input ¶
_process_image_input(
image_input: PixtralImagePixelInputs,
) -> tuple[Tensor, ...]
Source code in vllm/model_executor/models/pixtral.py
compute_logits ¶
embed_multimodal ¶
embed_multimodal(**kwargs: object) -> MultiModalEmbeddings
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: IntermediateTensors | None = None,
inputs_embeds: Tensor | None = None,
**kwargs: object,
) -> Tensor | IntermediateTensors
Run forward pass for pixtral.
Source code in vllm/model_executor/models/pixtral.py
get_mm_mapping ¶
get_mm_mapping() -> MultiModelKeys
get_num_mm_connector_tokens ¶
Source code in vllm/model_executor/models/pixtral.py
get_num_mm_encoder_tokens ¶
Source code in vllm/model_executor/models/pixtral.py
get_placeholder_str classmethod ¶
load_weights ¶
Source code in vllm/model_executor/models/pixtral.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 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 | |
PixtralHFAttention ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 | |
o_proj instance-attribute ¶
o_proj = RowParallelLinear(
input_size=hidden_size,
output_size=hidden_size,
bias=False,
quant_config=quant_config,
prefix=f"{prefix}.o_proj",
disable_tp=use_data_parallel,
)
qkv_proj instance-attribute ¶
qkv_proj = QKVParallelLinear(
hidden_size=hidden_size,
head_size=head_dim,
total_num_heads=total_num_heads,
bias=False,
quant_config=quant_config,
prefix=f"{prefix}.qkv_proj",
disable_tp=use_data_parallel,
)
tp_size instance-attribute ¶
tp_size = (
1
if use_data_parallel
else get_tensor_model_parallel_world_size()
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: QuantizationConfig | None = None,
multimodal_config: MultiModalConfig | None = None,
*,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/pixtral.py
forward ¶
forward(
hidden_states: Tensor,
attention_mask: Tensor,
position_embeddings: Tensor,
) -> tuple[Tensor, Tensor | None]
Source code in vllm/model_executor/models/pixtral.py
PixtralHFEncoderInfo ¶
Bases: VisionEncoderInfo[PixtralVisionConfig]
Source code in vllm/model_executor/models/pixtral.py
get_num_image_tokens ¶
Source code in vllm/model_executor/models/pixtral.py
get_patch_grid_length ¶
get_patch_grid_length() -> int
Source code in vllm/model_executor/models/pixtral.py
get_patch_grid_size ¶
Source code in vllm/model_executor/models/pixtral.py
PixtralHFMLP ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
down_proj instance-attribute ¶
down_proj = RowParallelLinear(
input_size=intermediate_size,
output_size=hidden_size,
bias=False,
quant_config=quant_config,
prefix=f"{prefix}.down_proj",
disable_tp=use_data_parallel,
)
gate_up_proj instance-attribute ¶
gate_up_proj = MergedColumnParallelLinear(
input_size=hidden_size,
output_sizes=[intermediate_size] * 2,
bias=False,
quant_config=quant_config,
prefix=f"{prefix}.gate_up_proj",
disable_tp=use_data_parallel,
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: QuantizationConfig | None = None,
multimodal_config: MultiModalConfig | None = None,
*,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/pixtral.py
PixtralHFTransformer ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
layers instance-attribute ¶
layers = ModuleList(
[
(
PixtralHFTransformerBlock(
config=config,
quant_config=quant_config,
multimodal_config=multimodal_config,
prefix=f"{prefix}.layers.{layer_idx}",
)
)
for layer_idx in (range(num_hidden_layers))
]
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: QuantizationConfig | None = None,
multimodal_config: MultiModalConfig | None = None,
*,
num_hidden_layers_override: int | None = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/pixtral.py
forward ¶
forward(
x: Tensor,
attention_mask: Tensor,
position_embeddings: Tensor,
return_all_hidden_states: bool,
) -> Tensor
Source code in vllm/model_executor/models/pixtral.py
PixtralHFTransformerBlock ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
attention instance-attribute ¶
attention = PixtralHFAttention(
config,
quant_config=quant_config,
multimodal_config=multimodal_config,
prefix=f"{prefix}.attention",
)
feed_forward instance-attribute ¶
feed_forward = PixtralHFMLP(
config,
quant_config=quant_config,
multimodal_config=multimodal_config,
prefix=f"{prefix}.feed_forward",
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: QuantizationConfig | None = None,
multimodal_config: MultiModalConfig | None = None,
*,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/pixtral.py
forward ¶
Source code in vllm/model_executor/models/pixtral.py
PixtralHFVisionModel ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 | |
patch_conv instance-attribute ¶
patch_conv = Conv2dLayer(
in_channels=num_channels,
out_channels=hidden_size,
kernel_size=patch_size,
stride=patch_size,
bias=False,
)
patch_positional_embedding instance-attribute ¶
transformer instance-attribute ¶
transformer = PixtralHFTransformer(
config,
quant_config=quant_config,
multimodal_config=multimodal_config,
num_hidden_layers_override=num_hidden_layers_override,
prefix=f"{prefix}.transformer",
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: QuantizationConfig | None = None,
multimodal_config: MultiModalConfig | None = None,
*,
num_hidden_layers_override: int | None = None,
require_post_norm: bool | None = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/pixtral.py
forward ¶
forward(
pixel_values: list[Tensor],
*,
select_layers: list[int] | None = None,
feature_select_strategy: VisionFeatureSelectStrategy
| None = None,
) -> tuple[Tensor, ...]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pixel_values | list[Tensor] | Each image to be processed will be a separate tensor in pixel_values. This means it will be a list of tensors because multiple requests batched can have multiple images, each with their own shape potentially | required |
select_layers | list[int] | None | Layer indices whose features should be concatenated and used as the visual encoder output. If none are provided, the last layer is used. | None |
Returns:
| Name | Type | Description |
|---|---|---|
image_features | tuple[Tensor, ...] | tensor of token features for all tokens of all images of shape (N_toks, D) |
Source code in vllm/model_executor/models/pixtral.py
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 | |
load_weights ¶
Source code in vllm/model_executor/models/pixtral.py
PixtralImagePixelInputs ¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- c: Number of channels (3)
- h: Height of each image
- w: Width of each image
The result of stacking ImageEncoding.tokens from each prompt.
Source code in vllm/model_executor/models/pixtral.py
PixtralMultiModalProcessor ¶
Bases: BaseMultiModalProcessor[PixtralProcessingInfo]
Source code in vllm/model_executor/models/pixtral.py
_cached_apply_hf_processor ¶
_cached_apply_hf_processor(
prompt: str | list[int],
mm_data_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
tokenization_kwargs: Mapping[str, object],
mm_uuids: MultiModalUUIDDict | None = None,
) -> tuple[list[int], MultiModalProcessingInfo, bool]
Source code in vllm/model_executor/models/pixtral.py
_get_mm_fields_config ¶
_get_mm_fields_config(
hf_inputs: Mapping[str, NestedTensors],
hf_processor_mm_kwargs: Mapping[str, object],
) -> Mapping[str, MultiModalFieldConfig]
_get_prompt_updates ¶
_get_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
out_mm_kwargs: MultiModalKwargsItems,
) -> Sequence[PromptUpdate]
Source code in vllm/model_executor/models/pixtral.py
PixtralProcessingInfo ¶
Bases: BaseProcessingInfo
Source code in vllm/model_executor/models/pixtral.py
get_hf_processor ¶
get_hf_processor() -> PixtralProcessorAdapter
get_image_size_with_most_features ¶
get_image_size_with_most_features() -> ImageSize
Source code in vllm/model_executor/models/pixtral.py
get_num_image_tokens ¶
get_num_image_tokens(
*,
image_width: int,
image_height: int,
processor: PixtralProcessorAdapter | None = None,
) -> int
Source code in vllm/model_executor/models/pixtral.py
get_supported_mm_limits ¶
get_tokenizer ¶
get_tokenizer() -> MistralTokenizer
Source code in vllm/model_executor/models/pixtral.py
get_vision_config ¶
get_vision_config(
processor: PixtralProcessorAdapter | None = None,
)
Source code in vllm/model_executor/models/pixtral.py
PixtralProcessorAdapter ¶
Provide a HF-compatible interface for mistral_common.tokens.tokenizers.multimodal.ImageEncoder.
Source code in vllm/model_executor/models/pixtral.py
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 | |
__call__ ¶
__call__(
text: TextInput | list[TextInput] | None = None,
images: ImageInput | list[ImageInput] | None = None,
return_tensors: str | TensorType | None = None,
**kwargs,
) -> Mapping[str, NestedTensors]
Source code in vllm/model_executor/models/pixtral.py
Transformer ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
__init__ ¶
__init__(args: VisionEncoderArgs)
forward ¶
TransformerBlock ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
forward ¶
Source code in vllm/model_executor/models/pixtral.py
VisionEncoderArgs dataclass ¶
Source code in vllm/model_executor/models/pixtral.py
add_pre_mm_projector_layer_norm class-attribute instance-attribute ¶
add_pre_mm_projector_layer_norm: bool = False
__init__ ¶
__init__(
hidden_size: int,
num_channels: int,
image_size: int,
patch_size: int,
intermediate_size: int,
num_hidden_layers: int,
num_attention_heads: int,
rope_theta: float,
image_token_id: int,
adapter_bias: bool = True,
spatial_merge_size: int = 1,
add_pre_mm_projector_layer_norm: bool = False,
mm_projector_id: str = "",
) -> None
VisionLanguageAdapter ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
__init__ ¶
__init__(args: VisionEncoderArgs, dim: int)
Source code in vllm/model_executor/models/pixtral.py
VisionTransformer ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
patch_conv instance-attribute ¶
patch_conv = Conv2dLayer(
in_channels=num_channels,
out_channels=hidden_size,
kernel_size=patch_size,
stride=patch_size,
bias=False,
)
__init__ ¶
__init__(args: VisionEncoderArgs)
Source code in vllm/model_executor/models/pixtral.py
forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images | list[Tensor] | list of N_img images of variable sizes, each of shape (C, H, W) | required |
Returns: image_features: tensor of token features for all tokens of all images of shape (N_toks, D)
Source code in vllm/model_executor/models/pixtral.py
_reshape_for_broadcast ¶
freqs_cis: complex - (seq_len, head_dim / 2) x: complex - (bsz, seq_len, head_dim / 2)
Source code in vllm/model_executor/models/pixtral.py
apply_rotary_emb_vit ¶
Source code in vllm/model_executor/models/pixtral.py
get_sub_grids ¶
get_sub_grids(
x: Tensor,
image_sizes: list[tuple[int, int]],
spatial_merge_size: int,
) -> list[Tensor]
Source code in vllm/model_executor/models/pixtral.py
position_meshgrid ¶
Source code in vllm/model_executor/models/pixtral.py
precompute_freqs_cis_2d ¶
2D complex tensor of shape (height, width, dim // 2)
to be indexed by (height, width) position tuples