vllm.model_executor.models.llava
LlavaImageInputs
module-attribute
¶
LlavaImageInputs = Union[
LlavaImagePixelInputs,
PixtralHFImagePixelInputs,
LlavaImageEmbeddingInputs,
]
BaseLlavaMultiModalProcessor
¶
Bases: BaseMultiModalProcessor[_I]
Source code in vllm/model_executor/models/llava.py
_get_mm_fields_config
abstractmethod
¶
_get_prompt_updates
¶
_get_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
out_mm_kwargs: MultiModalKwargs,
) -> Sequence[PromptUpdate]
Source code in vllm/model_executor/models/llava.py
BaseLlavaProcessingInfo
¶
Bases: BaseProcessingInfo
Source code in vllm/model_executor/models/llava.py
_apply_feature_select_strategy
¶
Source code in vllm/model_executor/models/llava.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/llava.py
get_supported_mm_limits
¶
LlavaDummyInputsBuilder
¶
Bases: BaseDummyInputsBuilder[_I]
Source code in vllm/model_executor/models/llava.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/llava.py
get_dummy_text
¶
LlavaForConditionalGeneration
¶
Bases: Module
, SupportsMultiModal
, SupportsPP
Source code in vllm/model_executor/models/llava.py
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 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 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 |
|
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 = LlavaMultiModalProjector(
vision_hidden_size=hidden_size,
text_hidden_size=hidden_size,
projector_hidden_act=projector_hidden_act,
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/llava.py
_image_pixels_to_features
¶
_image_pixels_to_features(
vision_tower: Union[
CLIPVisionModel,
SiglipVisionModel,
PixtralHFVisionModel,
],
pixel_values: Union[Tensor, list[Tensor]],
) -> Union[Tensor, tuple[Tensor, ...]]
Source code in vllm/model_executor/models/llava.py
_parse_and_validate_image_input
¶
_parse_and_validate_image_input(
**kwargs: object,
) -> Optional[LlavaImageInputs]
Source code in vllm/model_executor/models/llava.py
_process_image_input
¶
_process_image_input(
image_input: LlavaImageInputs,
) -> Union[Tensor, tuple[Tensor, ...]]
Source code in vllm/model_executor/models/llava.py
_process_image_pixels
¶
_process_image_pixels(
inputs: Union[
LlavaImagePixelInputs, PixtralHFImagePixelInputs
],
) -> Union[Tensor, tuple[Tensor, ...]]
Source code in vllm/model_executor/models/llava.py
_select_image_features
¶
Source code in vllm/model_executor/models/llava.py
_validate_pixel_values
¶
Source code in vllm/model_executor/models/llava.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 LLaVA-1.5.
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
[LlavaImageInputs][]
Source code in vllm/model_executor/models/llava.py
get_input_embeddings
¶
get_input_embeddings(
input_ids: Tensor,
multimodal_embeddings: Optional[
MultiModalEmbeddings
] = None,
) -> Tensor
Source code in vllm/model_executor/models/llava.py
get_multimodal_embeddings
¶
get_multimodal_embeddings(
**kwargs: object,
) -> MultiModalEmbeddings
get_placeholder_str
classmethod
¶
load_weights
¶
LlavaImagePixelInputs
¶
Bases: TypedDict
Source code in vllm/model_executor/models/llava.py
LlavaLikeProcessor
¶
LlavaMultiModalProcessor
¶
Bases: BaseLlavaMultiModalProcessor[LlavaProcessingInfo]
Source code in vllm/model_executor/models/llava.py
LlavaMultiModalProjector
¶
Bases: Module
Source code in vllm/model_executor/models/llava.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",
)
__init__
¶
__init__(
vision_hidden_size: int,
text_hidden_size: int,
projector_hidden_act: str,
multimodal_projector_bias: bool,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/llava.py
forward
¶
LlavaProcessingInfo
¶
Bases: BaseLlavaProcessingInfo
Source code in vllm/model_executor/models/llava.py
get_hf_processor
¶
get_hf_processor(**kwargs: object)
Source code in vllm/model_executor/models/llava.py
MantisForConditionalGeneration
¶
MantisMultiModalProcessor
¶
Bases: LlavaMultiModalProcessor
Source code in vllm/model_executor/models/llava.py
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 |
|
apply
¶
apply(
prompt: Union[str, list[int]],
mm_data: MultiModalDataDict,
hf_processor_mm_kwargs: Mapping[str, object],
tokenization_kwargs: Optional[
Mapping[str, object]
] = None,
return_mm_hashes: bool = False,
) -> MultiModalInputs
Source code in vllm/model_executor/models/llava.py
MantisProcessingInfo
¶
Bases: LlavaProcessingInfo
Source code in vllm/model_executor/models/llava.py
get_hf_processor
¶
get_hf_processor(**kwargs: object)
Source code in vllm/model_executor/models/llava.py
PixtralHFImagePixelInputs
¶
Bases: TypedDict
Source code in vllm/model_executor/models/llava.py
pixel_values
instance-attribute
¶
Shape: (batch_size * num_images, num_channels, height, width)
Note that height
or width
may be different per batch and image,
in which case the data is passed as a list instead of a batched tensor.
PixtralHFMultiModalProcessor
¶
Bases: BaseMultiModalProcessor[PixtralHFProcessingInfo]
Source code in vllm/model_executor/models/llava.py
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 |
|
_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/llava.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/llava.py
_get_prompt_updates
¶
_get_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
out_mm_kwargs: MultiModalKwargs,
) -> Sequence[PromptUpdate]
Source code in vllm/model_executor/models/llava.py
PixtralHFProcessingInfo
¶
Bases: BaseLlavaProcessingInfo
Source code in vllm/model_executor/models/llava.py
_build_llava_or_pixtral_hf_info
¶
_build_llava_or_pixtral_hf_info(
ctx: InputProcessingContext,
) -> BaseLlavaProcessingInfo
Source code in vllm/model_executor/models/llava.py
_build_llava_or_pixtral_hf_processor
¶
_build_llava_or_pixtral_hf_processor(
info: _I,
dummy_inputs: BaseDummyInputsBuilder[_I],
*,
cache: Optional[ProcessingCache] = None,
) -> BaseMultiModalProcessor
Source code in vllm/model_executor/models/llava.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/llava.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/llava.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 = "",
) -> Union[
CLIPVisionModel, SiglipVisionModel, PixtralHFVisionModel
]