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]
) -> 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]
) -> ProcessorInputs
Source code in vllm/model_executor/models/pixtral.py
PixtralForConditionalGeneration ¶
Bases: Module
, SupportsMultiModal
, SupportsPP
Source code in vllm/model_executor/models/pixtral.py
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 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 |
|
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,
)
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,
) -> Optional[PixtralImagePixelInputs]
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 ¶
compute_logits(
hidden_states: Tensor,
sampling_metadata: SamplingMetadata,
) -> Optional[Tensor]
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: Optional[
IntermediateTensors
] = None,
inputs_embeds: Optional[Tensor] = None,
**kwargs: object,
) -> Union[Tensor, IntermediateTensors]
Run forward pass for pixtral.
Source code in vllm/model_executor/models/pixtral.py
get_input_embeddings ¶
get_input_embeddings(
input_ids: Tensor,
multimodal_embeddings: Optional[
MultiModalEmbeddings
] = None,
) -> Tensor
Source code in vllm/model_executor/models/pixtral.py
get_multimodal_embeddings ¶
get_multimodal_embeddings(
**kwargs: object,
) -> MultiModalEmbeddings
get_placeholder_str classmethod
¶
load_weights ¶
Source code in vllm/model_executor/models/pixtral.py
PixtralHFAttention ¶
Bases: Module
Source code in vllm/model_executor/models/pixtral.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
|
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",
)
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",
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: Optional[QuantizationConfig] = 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, Optional[Tensor]]
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 ¶
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",
)
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",
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: Optional[QuantizationConfig] = 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,
prefix=f"{prefix}.layers.{layer_idx}",
)
)
for layer_idx in (range(num_hidden_layers))
]
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: Optional[QuantizationConfig] = None,
*,
num_hidden_layers_override: Optional[int] = 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,
prefix=f"{prefix}.attention",
)
feed_forward instance-attribute
¶
feed_forward = PixtralHFMLP(
config,
quant_config=quant_config,
prefix=f"{prefix}.feed_forward",
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: Optional[QuantizationConfig] = 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
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 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 |
|
patch_conv instance-attribute
¶
patch_conv = Conv2d(
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,
num_hidden_layers_override=num_hidden_layers_override,
prefix=f"{prefix}.transformer",
)
__init__ ¶
__init__(
config: PixtralVisionConfig,
quant_config: Optional[QuantizationConfig] = None,
*,
num_hidden_layers_override: Optional[int] = None,
require_post_norm: Optional[bool] = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/pixtral.py
forward ¶
forward(
pixel_values: list[Tensor],
feature_sample_layers: Optional[list[int]] = 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 |
feature_sample_layers | Optional[list[int]] | 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
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 |
|
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: Union[str, list[int]],
mm_data_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
tokenization_kwargs: Mapping[str, object],
) -> 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: Optional[PixtralProcessorAdapter] = 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: Optional[PixtralProcessorAdapter] = 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
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 |
|
__call__ ¶
__call__(
text: Optional[
Union[TextInput, list[TextInput]]
] = None,
images: Optional[
Union[ImageInput, list[ImageInput]]
] = None,
return_tensors: Optional[Union[str, TensorType]] = 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
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 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 |
|
patch_conv instance-attribute
¶
patch_conv = Conv2d(
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