vllm.model_executor.models.hunyuan_vision ¶
Inference-only HunYuan-VL model compatible with HuggingFace weights.
HunYuanVLImageInputs module-attribute ¶
HunYuanVLImageInputs: TypeAlias = (
HunYuanVLImagePixelInputs
| HunYuanVLImageEmbeddingInputs
)
HunYuanVLDummyInputsBuilder ¶
Bases: BaseDummyInputsBuilder[HunYuanVLProcessingInfo]
Source code in vllm/model_executor/models/hunyuan_vision.py
get_dummy_mm_data ¶
get_dummy_mm_data(
seq_len: int,
mm_counts: Mapping[str, int],
mm_options: Mapping[str, BaseDummyOptions]
| None = None,
) -> MultiModalDataDict
Source code in vllm/model_executor/models/hunyuan_vision.py
get_dummy_text ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVLForConditionalGeneration ¶
Bases: Module, SupportsMultiModal, SupportsLoRA, SupportsPP, SupportsQuant, SupportsXDRoPE
Source code in vllm/model_executor/models/hunyuan_vision.py
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 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 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 | |
hf_to_vllm_mapper class-attribute instance-attribute ¶
hf_to_vllm_mapper = WeightsMapper(
orig_to_new_prefix={
"vit.vit.": "visual.",
"vit.": "visual.",
"model.": "language_model.model.",
}
)
language_model instance-attribute ¶
language_model = init_vllm_registered_model(
vllm_config=vllm_config,
prefix=maybe_prefix(prefix, "language_model.model"),
architectures=[
"HunYuanDenseV1ForCausalLM",
"HunYuanMoEV1ForCausalLM",
],
)
make_empty_intermediate_tensors instance-attribute ¶
multimodal_cpu_fields class-attribute instance-attribute ¶
visual instance-attribute ¶
visual = HunYuanVisionTransformer(
vision_config,
quant_config=quant_config,
prefix=maybe_prefix(prefix, "visual"),
multimodal_config=multimodal_config,
attn_backend_override=attn_backend_override,
)
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/hunyuan_vision.py
_parse_and_validate_image_input ¶
_parse_and_validate_image_input(
**kwargs: object,
) -> HunYuanVLImageInputs | None
Source code in vllm/model_executor/models/hunyuan_vision.py
_parse_and_validate_multimodal_inputs ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
_process_image_input ¶
_process_image_input(
image_input: HunYuanVLImageInputs,
) -> tuple[Tensor, ...]
Source code in vllm/model_executor/models/hunyuan_vision.py
compute_logits ¶
embed_multimodal ¶
embed_multimodal(**kwargs: object) -> MultiModalEmbeddings
Source code in vllm/model_executor/models/hunyuan_vision.py
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: IntermediateTensors | None,
inputs_embeds: Tensor | None,
**kwargs: object,
) -> Tensor | IntermediateTensors
Source code in vllm/model_executor/models/hunyuan_vision.py
get_mm_mapping ¶
get_mm_mapping() -> MultiModelKeys
Get the module prefix in multimodal models
Source code in vllm/model_executor/models/hunyuan_vision.py
get_placeholder_str classmethod ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
get_xdrope_input_positions ¶
get_xdrope_input_positions(
input_tokens: list[int],
mm_features: list[MultiModalFeatureSpec],
) -> Tensor
Source code in vllm/model_executor/models/hunyuan_vision.py
load_weights ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVLImageEmbeddingInputs ¶
Bases: TensorSchema
Dimensions
- nf: Number of image features
- hs: Hidden size
- ni: Number of images
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVLImagePixelInputs ¶
Bases: TensorSchema
Dimensions
- np: Number of patches
- ni: Number of images
- cps: Number of channels * patch_size * patch_size
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVLMultiModalDataParser ¶
Bases: MultiModalDataParser
Source code in vllm/model_executor/models/hunyuan_vision.py
_parse_image_data ¶
_parse_image_data(
data: dict[str, Tensor] | ModalityData[ImageItem],
)
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVLMultiModalProcessor ¶
Bases: BaseMultiModalProcessor[HunYuanVLProcessingInfo]
Source code in vllm/model_executor/models/hunyuan_vision.py
_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/hunyuan_vision.py
_get_data_parser ¶
_get_data_parser() -> MultiModalDataParser
_get_mm_fields_config ¶
_get_prompt_updates ¶
_get_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, Any],
out_mm_kwargs: MultiModalKwargsItems,
) -> Sequence[PromptUpdate]
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVLProcessingInfo ¶
Bases: BaseProcessingInfo
Source code in vllm/model_executor/models/hunyuan_vision.py
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 | |
_get_vision_info ¶
_get_vision_info(
*,
image_width: int,
image_height: int,
num_frames: int = 1,
do_resize: bool = True,
image_processor: HunYuanVLProcessor | None,
) -> tuple[ImageSize, int]
Source code in vllm/model_executor/models/hunyuan_vision.py
get_hf_config ¶
get_hf_processor ¶
get_hf_processor(**kwargs: object) -> HunYuanVLProcessor
get_image_processor ¶
get_image_processor(**kwargs: object) -> HunYuanVLProcessor
get_max_image_tokens ¶
get_max_image_tokens() -> int
Source code in vllm/model_executor/models/hunyuan_vision.py
get_mm_max_tokens_per_item ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
get_num_image_tokens ¶
get_num_image_tokens(
*,
image_width: int,
image_height: int,
image_processor: HunYuanVLProcessor | None,
) -> int
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVisionAttention ¶
Bases: Module
Source code in vllm/model_executor/models/hunyuan_vision.py
attn instance-attribute ¶
attn = MultiHeadAttention(
num_attention_heads_per_partition,
hidden_size_per_attention_head,
scale,
prefix=f"{prefix}.attn",
multimodal_config=multimodal_config,
)
hidden_size_per_attention_head instance-attribute ¶
hidden_size_per_attention_head = divide(
projection_size, num_heads
)
num_attention_heads_per_partition instance-attribute ¶
num_attention_heads_per_partition = divide(
num_heads, tp_size
)
o_proj instance-attribute ¶
o_proj = RowParallelLinear(
input_size=projection_size,
output_size=embed_dim,
quant_config=quant_config,
prefix=f"{prefix}.o_proj",
disable_tp=use_data_parallel,
)
qkv instance-attribute ¶
qkv = QKVParallelLinear(
hidden_size=embed_dim,
head_size=hidden_size_per_attention_head,
total_num_heads=num_heads,
total_num_kv_heads=num_heads,
bias=True,
quant_config=quant_config,
prefix=f"{prefix}.qkv",
disable_tp=use_data_parallel,
)
tp_size instance-attribute ¶
tp_size = (
1
if use_data_parallel
else get_tensor_model_parallel_world_size()
)
__init__ ¶
__init__(
embed_dim: int,
num_heads: int,
projection_size: int,
quant_config: QuantizationConfig | None = None,
multimodal_config: MultiModalConfig | None = None,
prefix: str = "",
use_data_parallel: bool = False,
) -> None
Source code in vllm/model_executor/models/hunyuan_vision.py
forward ¶
HunYuanVisionBlock ¶
Bases: Module
Source code in vllm/model_executor/models/hunyuan_vision.py
mlp instance-attribute ¶
mlp = HunYuanVisionMLP(
dim,
mlp_hidden_dim,
act_fn=act_fn,
bias=True,
quant_config=quant_config,
prefix=f"{prefix}.mlp",
use_data_parallel=use_data_parallel,
)
self_attn instance-attribute ¶
self_attn = HunYuanVisionAttention(
embed_dim=dim,
num_heads=num_heads,
projection_size=dim,
quant_config=quant_config,
multimodal_config=multimodal_config,
prefix=f"{prefix}.self_attn",
use_data_parallel=use_data_parallel,
)
__init__ ¶
__init__(
dim: int,
num_heads: int,
mlp_hidden_dim: int,
act_fn: Callable[[Tensor], Tensor] = gelu,
norm_layer: Callable[[int], Module] | None = None,
quant_config: QuantizationConfig | None = None,
multimodal_config: MultiModalConfig | None = None,
prefix: str = "",
use_data_parallel: bool = False,
) -> None
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVisionMLP ¶
Bases: Module
Source code in vllm/model_executor/models/hunyuan_vision.py
dense_4h_to_h instance-attribute ¶
dense_4h_to_h = RowParallelLinear(
hidden_features,
in_features,
bias=bias,
quant_config=quant_config,
prefix=f"{prefix}.dense_4h_to_h",
disable_tp=use_data_parallel,
)
dense_h_to_4h instance-attribute ¶
dense_h_to_4h = ColumnParallelLinear(
in_features,
hidden_features,
bias=bias,
quant_config=quant_config,
prefix=f"{prefix}.dense_h_to_4h",
disable_tp=use_data_parallel,
)
__init__ ¶
__init__(
in_features: int,
hidden_features: int,
bias: bool = True,
act_fn: Callable[[Tensor], Tensor] = gelu,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
use_data_parallel: bool = False,
)
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVisionPatchEmbed ¶
Bases: Module
Source code in vllm/model_executor/models/hunyuan_vision.py
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 | |
patch_embedding instance-attribute ¶
patch_embedding = Conv2d(
in_channels=num_channels,
out_channels=embed_dim,
kernel_size=patch_size,
stride=patch_size,
bias=True,
)
__init__ ¶
__init__(config: HunYuanVLVisionConfig)
Source code in vllm/model_executor/models/hunyuan_vision.py
forward ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVisionPatchMerger ¶
Bases: Module
Source code in vllm/model_executor/models/hunyuan_vision.py
proj instance-attribute ¶
proj = Sequential(
Conv2d(
in_channels,
in_channels * 2,
kernel_size=spatial_merge_size,
stride=spatial_merge_size,
),
GELU(),
Conv2d(in_channels * 2, in_channels * 4, kernel_size=1),
)
__init__ ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
forward ¶
Source code in vllm/model_executor/models/hunyuan_vision.py
HunYuanVisionTransformer ¶
Bases: Module
Source code in vllm/model_executor/models/hunyuan_vision.py
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 | |
layers instance-attribute ¶
layers = ModuleList(
[
(
HunYuanVisionBlock(
dim=hidden_size,
num_heads=num_attention_heads,
mlp_hidden_dim=intermediate_size,
act_fn=get_act_fn(hidden_act),
norm_layer=norm_layer,
quant_config=quant_config,
multimodal_config=multimodal_config,
prefix=f"{prefix}.layers.{layer_idx}",
use_data_parallel=use_data_parallel,
)
)
for layer_idx in (range(num_hidden_layers))
]
)
perceive instance-attribute ¶
perceive = HunYuanVisionPatchMerger(
hidden_size,
out_hidden_size,
spatial_merge_size=spatial_merge_size,
rms_norm_eps=rms_norm_eps,
prefix=f"{prefix}.perceive",
)
__init__ ¶
__init__(
vision_config: HunYuanVLVisionConfig,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
use_data_parallel: bool = False,
multimodal_config: MultiModalConfig | None = None,
attn_backend_override: AttentionBackendEnum
| None = None,
) -> None