vllm.model_executor.models.mistral3
¶
Classes:
-
Mistral3ForConditionalGeneration– -
Mistral3ImageEmbeddingInputs–Projected features with shape (num_images, feature_size, hidden_size).
-
Mistral3ImagePixelInputs–Dimensions:
-
Mistral3PatchMerger–Learned merging of spatial_merge_size ** 2 patches.
Mistral3ForConditionalGeneration
¶
Bases: Module, SupportsLoRA, SupportsMultiModal, SupportsPP, SupportsEagle, SupportsEagle3, PixtralEncoderCudaGraphMixin
Methods:
-
forward–Run forward pass for Mistral3.
-
get_mm_mapping–Get the module prefix in multimodal models.
Source code in vllm/model_executor/models/mistral3.py
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 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 | |
forward(input_ids, positions, intermediate_tensors=None, inputs_embeds=None, **kwargs)
¶
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:
-
(input_ids¶Tensor | None) –Flattened (concatenated) input_ids corresponding to a batch.
-
(positions¶Tensor) –Position indices for the input tokens.
-
(intermediate_tensors¶IntermediateTensors | None, default:None) –Intermediate tensors from prior forward pass.
-
(inputs_embeds¶Tensor | None, default:None) –Optional tensor of input embeddings.
-
(**kwargs¶object, default:{}) –Multimodal inputs for this batch, forwarded to the multimodal embedding path.
Source code in vllm/model_executor/models/mistral3.py
get_mm_mapping()
¶
Get the module prefix in multimodal models.
Source code in vllm/model_executor/models/mistral3.py
Mistral3ImageEmbeddingInputs
¶
Bases: TensorSchema
Projected features with shape (num_images, feature_size, hidden_size).
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
Mistral3PatchMerger
¶
Bases: Module
Learned merging of spatial_merge_size ** 2 patches.
Methods:
-
forward_packed–Same as
forward, gathering blocks with_make_merge_indices
Source code in vllm/model_executor/models/mistral3.py
forward_packed(image_features, merge_indices)
¶
Same as forward, gathering blocks with _make_merge_indices
(None when spatial_merge_size is 1).
Source code in vllm/model_executor/models/mistral3.py
_get_num_hidden_layers(hf_config)
¶
Determine the number of hidden layers to initialize up to in the visual encoder.
Parameters:
-
(hf_config¶Mistral3Config) –Model config with vision feature layer(s).