vllm.model_executor.models.mistral3
BaseLlavaProcessingInfo ¶
Bases: BaseProcessingInfo
Source code in vllm/model_executor/models/mistral3.py
get_hf_config ¶
get_hf_config() -> LlavaLikeConfig
get_hf_processor abstractmethod
¶
get_hf_processor(**kwargs: object) -> LlavaLikeProcessor
get_num_image_tokens ¶
Source code in vllm/model_executor/models/mistral3.py
get_supported_mm_limits ¶
LlavaLikeProcessor ¶
Mistral3DummyInputsBuilder ¶
Bases: BaseDummyInputsBuilder[_I]
Source code in vllm/model_executor/models/mistral3.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/mistral3.py
get_dummy_text ¶
Mistral3ForConditionalGeneration ¶
Bases: Module
, SupportsLoRA
, SupportsMultiModal
, SupportsPP
Source code in vllm/model_executor/models/mistral3.py
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 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
|
hf_to_vllm_mapper class-attribute
instance-attribute
¶
hf_to_vllm_mapper = WeightsMapper(
orig_to_new_prefix={
"model.language_model.": "language_model.model.",
"model.vision_tower.": "vision_tower.",
"model.multi_modal_projector.": "multi_modal_projector.",
"lm_head.": "language_model.lm_head.",
}
)
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
¶
multi_modal_projector instance-attribute
¶
multi_modal_projector = Mistral3MultiModalProjector(
vision_hidden_size=hidden_size,
text_hidden_size=hidden_size,
projector_hidden_act=projector_hidden_act,
spatial_merge_size=spatial_merge_size,
patch_size=patch_size,
multimodal_projector_bias=multimodal_projector_bias,
quant_config=quant_config,
prefix=maybe_prefix(prefix, "multi_modal_projector"),
)
packed_modules_mapping class-attribute
instance-attribute
¶
packed_modules_mapping = {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
"gate_up_proj": ["gate_proj", "up_proj"],
}
vision_tower instance-attribute
¶
vision_tower = init_vision_tower_for_llava(
config,
quant_config,
require_post_norm=False,
prefix=maybe_prefix(prefix, "vision_tower"),
)
__init__ ¶
__init__(
*, vllm_config: VllmConfig, prefix: str = ""
) -> None
Source code in vllm/model_executor/models/mistral3.py
_parse_and_validate_image_input ¶
_parse_and_validate_image_input(
**kwargs: object,
) -> Optional[Mistral3ImagePixelInputs]
Source code in vllm/model_executor/models/mistral3.py
_process_image_input ¶
_process_image_input(
image_input: Mistral3ImagePixelInputs,
) -> Union[Tensor, tuple[Tensor, ...]]
Source code in vllm/model_executor/models/mistral3.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 Mistral3.
One key thing to understand is the input_ids
already accounts for the positions of the to-be-inserted image embeddings.
Concretely, consider a text prompt: "USER: <image>\nWhat's the content of the image?\nASSISTANT:"
.
Tokenizer outputs: [1, 3148, 1001, 29901, 29871, 32000, 29871, 13, 5618, 29915, 29879, 278, 2793, 310, 278, 1967, 29973, 13, 22933, 9047, 13566, 29901]
.
To reserve space in KV cache, we have to insert placeholder tokens before they are inputted to the model, so the input processor prepends additional image tokens (denoted as 32000
), resulting in: [1, 3148, 1001, 29901, 29871, 32000, ..., 32000, 29871, 13, 5618, 29915, 29879, 278, 2793, 310, 278, 1967, 29973, 13, 22933, 9047, 13566, 29901]
.
We insert 575 tokens so that including the original image token in the input, there are a total of 576 (24 * 24) image tokens, which corresponds to the number of image tokens inputted to the language model, i.e. the number of image tokens outputted by the visual encoder.
This way, the positions
and attn_metadata
are consistent with the input_ids
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids | Tensor | Flattened (concatenated) input_ids corresponding to a batch. | required |
pixel_values | The pixels in each input image. | required |
Info
[Mistral3ImagePixelInputs][]
Source code in vllm/model_executor/models/mistral3.py
get_input_embeddings ¶
get_input_embeddings(
input_ids: Tensor,
multimodal_embeddings: Optional[
MultiModalEmbeddings
] = None,
) -> Tensor
Source code in vllm/model_executor/models/mistral3.py
get_mm_mapping ¶
get_mm_mapping() -> MultiModelKeys
Get the module prefix in multimodal models
Source code in vllm/model_executor/models/mistral3.py
get_multimodal_embeddings ¶
get_multimodal_embeddings(
**kwargs: object,
) -> MultiModalEmbeddings
Source code in vllm/model_executor/models/mistral3.py
get_placeholder_str classmethod
¶
load_weights ¶
Source code in vllm/model_executor/models/mistral3.py
Mistral3ImagePixelInputs ¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- c: Number of channels (3)
- h: Height of each image
- w: Width of each image
Source code in vllm/model_executor/models/mistral3.py
Mistral3MultiModalProcessor ¶
Bases: BaseMultiModalProcessor[Mistral3ProcessingInfo]
Source code in vllm/model_executor/models/mistral3.py
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 309 310 311 |
|
_call_hf_processor ¶
_call_hf_processor(
prompt: str,
mm_data: Mapping[str, object],
mm_kwargs: Mapping[str, object],
tok_kwargs: Mapping[str, object],
) -> BatchFeature
Source code in vllm/model_executor/models/mistral3.py
_get_mm_fields_config ¶
_get_mm_fields_config(
hf_inputs: BatchFeature,
hf_processor_mm_kwargs: Mapping[str, object],
) -> Mapping[str, MultiModalFieldConfig]
Source code in vllm/model_executor/models/mistral3.py
_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/mistral3.py
Mistral3MultiModalProjector ¶
Bases: Module
Source code in vllm/model_executor/models/mistral3.py
linear_1 instance-attribute
¶
linear_1 = ColumnParallelLinear(
vision_hidden_size,
text_hidden_size,
bias=multimodal_projector_bias,
quant_config=quant_config,
prefix=f"{prefix}.linear_1",
)
linear_2 instance-attribute
¶
linear_2 = RowParallelLinear(
text_hidden_size,
text_hidden_size,
bias=multimodal_projector_bias,
quant_config=quant_config,
prefix=f"{prefix}.linear_2",
)
patch_merger instance-attribute
¶
patch_merger = Mistral3PatchMerger(
vision_hidden_size=vision_hidden_size,
spatial_merge_size=spatial_merge_size,
patch_size=patch_size,
)
__init__ ¶
__init__(
vision_hidden_size: int,
text_hidden_size: int,
spatial_merge_size: int,
patch_size: int,
projector_hidden_act: str,
multimodal_projector_bias: bool,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/mistral3.py
forward ¶
Source code in vllm/model_executor/models/mistral3.py
Mistral3PatchMerger ¶
Bases: Module
Learned merging of spatial_merge_size ** 2 patches
Source code in vllm/model_executor/models/mistral3.py
merging_layer instance-attribute
¶
merging_layer = Linear(
vision_hidden_size * spatial_merge_size**2,
vision_hidden_size,
bias=False,
)
__init__ ¶
Source code in vllm/model_executor/models/mistral3.py
forward ¶
Source code in vllm/model_executor/models/mistral3.py
Mistral3ProcessingInfo ¶
Bases: BaseLlavaProcessingInfo
Source code in vllm/model_executor/models/mistral3.py
_build_mistral3_info ¶
_build_mistral3_info(
ctx: InputProcessingContext,
) -> BaseLlavaProcessingInfo
Source code in vllm/model_executor/models/mistral3.py
_build_mistral3_processor ¶
_build_mistral3_processor(
info: _I,
dummy_inputs: BaseDummyInputsBuilder[_I],
*,
cache: Optional[ProcessingCache] = None,
) -> BaseMultiModalProcessor
Source code in vllm/model_executor/models/mistral3.py
_get_layer_index ¶
Given a signed vision feature layer, get the number of hidden layers needed to leverage it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_layer_index | int | Index of a required layer in the visual encoder. | required |
num_hidden_layers | int | The total number of hidden layers in the visual encoder. | required |
Source code in vllm/model_executor/models/mistral3.py
_get_num_hidden_layers ¶
_get_num_hidden_layers(hf_config: LlavaLikeConfig) -> int
Determine the number of hidden layers to initialize up to in the visual encoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hf_config | LlavaLikeConfig | Model config with vision feature layer(s). | required |
Source code in vllm/model_executor/models/mistral3.py
init_vision_tower_for_llava ¶
init_vision_tower_for_llava(
hf_config: LlavaLikeConfig,
quant_config: Optional[QuantizationConfig],
*,
require_post_norm: Optional[bool] = None,
prefix: str = "",
) -> PixtralHFVisionModel