vllm.model_executor.models.qwen_vl ¶
Inference-only Qwen-VL model compatible with HuggingFace weights.
QwenImageInputs module-attribute
¶
QwenImageInputs = Union[
QwenImagePixelInputs, QwenImageEmbeddingInputs
]
QwenImageEmbeddingInputs ¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- ifs: Image feature size (256)
- hs: Hidden size
hidden_size
must match the hidden size of the language model backbone and is stored in the visual config of the model if we have one.
Source code in vllm/model_executor/models/qwen_vl.py
QwenImagePixelInputs ¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- c: Number of channels (3)
- h: Height
- w: Width
Note that image_size is the value in the vision config to which we resize the image to in the normalization transform. Currently multi-image support can only be leveraged by passing image embeddings directly.
Source code in vllm/model_executor/models/qwen_vl.py
QwenVLDummyInputsBuilder ¶
Bases: BaseDummyInputsBuilder[QwenVLProcessingInfo]
Source code in vllm/model_executor/models/qwen_vl.py
get_dummy_mm_data ¶
get_dummy_mm_data(
seq_len: int,
mm_counts: Mapping[str, int],
mm_options: Optional[
Mapping[str, BaseDummyOptions]
] = None,
) -> MultiModalDataDict
Source code in vllm/model_executor/models/qwen_vl.py
get_dummy_text ¶
Source code in vllm/model_executor/models/qwen_vl.py
QwenVLForConditionalGeneration ¶
Bases: QWenBaseModel
, SupportsPP
, SupportsLoRA
, SupportsMultiModal
Source code in vllm/model_executor/models/qwen_vl.py
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 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 |
|
packed_modules_mapping class-attribute
instance-attribute
¶
__init__ ¶
__init__(
*,
vllm_config: VllmConfig,
prefix: str = "",
transformer_type: type[QwenVLModel] = QwenVLModel,
) -> None
Source code in vllm/model_executor/models/qwen_vl.py
_parse_and_validate_image_input ¶
_parse_and_validate_image_input(
**kwargs: object,
) -> Optional[QwenImageInputs]
Source code in vllm/model_executor/models/qwen_vl.py
_process_image_input ¶
_process_image_input(
image_input: QwenImageInputs,
) -> Tensor
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: Optional[
IntermediateTensors
] = None,
inputs_embeds: Optional[Tensor] = None,
**kwargs: object,
) -> Union[Tensor, IntermediateTensors]
Source code in vllm/model_executor/models/qwen_vl.py
get_mm_mapping ¶
get_mm_mapping() -> MultiModelKeys
Get the module prefix in multimodal models
Source code in vllm/model_executor/models/qwen_vl.py
get_multimodal_embeddings ¶
get_multimodal_embeddings(
**kwargs: object,
) -> MultiModalEmbeddings
Source code in vllm/model_executor/models/qwen_vl.py
get_placeholder_str classmethod
¶
QwenVLMLP ¶
Bases: Module
MLP for the visual component of the Qwen model.
Source code in vllm/model_executor/models/qwen_vl.py
c_fc instance-attribute
¶
c_fc = ColumnParallelLinear(
hidden_size,
intermediate_size,
bias=True,
quant_config=quant_config,
)
c_proj instance-attribute
¶
c_proj = RowParallelLinear(
intermediate_size,
hidden_size,
bias=True,
quant_config=quant_config,
)
__init__ ¶
__init__(
hidden_size: int,
intermediate_size: int,
quant_config: Optional[QuantizationConfig] = None,
)
Source code in vllm/model_executor/models/qwen_vl.py
QwenVLModel ¶
Bases: QWenModel
Source code in vllm/model_executor/models/qwen_vl.py
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/qwen_vl.py
QwenVLMultiModalProcessor ¶
Bases: BaseMultiModalProcessor[QwenVLProcessingInfo]
Source code in vllm/model_executor/models/qwen_vl.py
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 |
|
_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/qwen_vl.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/qwen_vl.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/qwen_vl.py
QwenVLProcessingInfo ¶
Bases: BaseProcessingInfo
Source code in vllm/model_executor/models/qwen_vl.py
QwenVLProcessor ¶
This model doesn't define its own HF processor, so we implement our own one here.
We call the wrapped tokenizer to automatically insert image pad tokens: https://huggingface.co/Qwen/Qwen-VL/blob/main/tokenization_qwen.py#L245
The image processor is defined here: https://huggingface.co/Qwen/Qwen-VL/blob/main/visual.py#L354
Source code in vllm/model_executor/models/qwen_vl.py
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 |
|
image_transform instance-attribute
¶
image_transform = Compose(
[
Resize(
(image_size, image_size), interpolation=BICUBIC
),
ToTensor(),
Normalize(
mean=(0.48145466, 0.4578275, 0.40821073),
std=(0.26862954, 0.26130258, 0.27577711),
),
]
)
__call__ ¶
__call__(
text: Optional[
Union[TextInput, list[TextInput]]
] = None,
images: Optional[
Union[ImageInput, list[ImageInput]]
] = None,
return_tensors: Optional[Union[str, TensorType]] = None,
) -> BatchFeature
Source code in vllm/model_executor/models/qwen_vl.py
__init__ ¶
Source code in vllm/model_executor/models/qwen_vl.py
TransformerBlock ¶
Bases: Module
Source code in vllm/model_executor/models/qwen_vl.py
resblocks instance-attribute
¶
resblocks = ModuleList(
[
(
VisualAttentionBlock(
width,
heads,
mlp_ratio,
norm_layer=norm_layer,
quant_config=quant_config,
)
)
for _ in (range(layers))
]
)
__init__ ¶
__init__(
width: int,
layers: int,
heads: int,
mlp_ratio: float = 4.0,
norm_layer: Callable[[int], Module] = LayerNorm,
quant_config: Optional[QuantizationConfig] = None,
)
Source code in vllm/model_executor/models/qwen_vl.py
forward ¶
VisionTransformer ¶
Bases: Module
Source code in vllm/model_executor/models/qwen_vl.py
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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
conv1 instance-attribute
¶
conv1 = Conv2d(
in_channels=3,
out_channels=width,
kernel_size=patch_size,
stride=patch_size,
bias=False,
)
grid_size instance-attribute
¶
positional_embedding instance-attribute
¶
positional_embedding = Parameter(scale * randn(256, width))
transformer instance-attribute
¶
transformer = TransformerBlock(
width,
layers,
heads,
mlp_ratio,
norm_layer=norm_layer,
quant_config=quant_config,
)
__init__ ¶
__init__(
image_size: int,
patch_size: int,
width: int,
layers: int,
heads: int,
mlp_ratio: float,
n_queries: int = 256,
output_dim: int = 512,
image_start_id: int = 151857,
quant_config: Optional[QuantizationConfig] = None,
**kwargs,
)
Source code in vllm/model_executor/models/qwen_vl.py
forward ¶
Source code in vllm/model_executor/models/qwen_vl.py
VisualAttention ¶
Bases: Module
self-attention layer class. Self-attention layer takes input with size [s, b, h] and returns output of the same size.
Source code in vllm/model_executor/models/qwen_vl.py
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 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 199 200 201 202 203 204 205 206 |
|
_qkv_same_embed_dim instance-attribute
¶
hidden_size_per_attention_head instance-attribute
¶
num_attention_heads_per_partition instance-attribute
¶
__init__ ¶
__init__(
embed_dim: int,
num_heads: int,
bias: bool = True,
kdim: Optional[int] = None,
vdim: Optional[int] = None,
)
Source code in vllm/model_executor/models/qwen_vl.py
forward ¶
Source code in vllm/model_executor/models/qwen_vl.py
VisualAttentionBlock ¶
Bases: Module
Source code in vllm/model_executor/models/qwen_vl.py
mlp instance-attribute
¶
mlp = QwenVLMLP(
hidden_size=d_model,
intermediate_size=mlp_width,
quant_config=quant_config,
)
__init__ ¶
__init__(
d_model: int,
n_head: int,
mlp_ratio: float = 4.0,
norm_layer: Callable[[int], Module] = LayerNorm,
quant_config: Optional[QuantizationConfig] = None,
)
Source code in vllm/model_executor/models/qwen_vl.py
attention ¶
forward ¶
_get_tokenizer_without_image_pad cached
¶
The logic of adding image pad tokens should only be applied in QwenVLProcessor
, so they are patched out here.
The definition of the wrapped tokenizer can be found here: https://huggingface.co/Qwen/Qwen-VL/blob/main/tokenization_qwen.py