vllm.models.hy_v4.nvidia.mtp ¶
Multi-token prediction (MTP) head for HY V4 (NVIDIA).
Classes:
-
HYV4MTP–HY V4 MTP draft head.
-
HYV4MultiTokenPredictor–Owns the MTP draft blocks and their shared embedding / logits path.
-
HYV4MultiTokenPredictorLayer–A single MTP draft block.
-
HYV4SharedHead–Holds the draft LM head shared with the target model.
HYV4MTP ¶
Bases: Module
HY V4 MTP draft head.
Not a pipeline-parallel stage: the draft head always runs on a single rank, matching DeepseekV32MTP / KimiK3MTP / HYV3MTP.
Methods:
-
set_topk_indices_buffer–Share the target sparse-index buffer with every draft consumer.
Source code in vllm/models/hy_v4/nvidia/mtp.py
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 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 | |
_load_expert_weight(name, loaded_weight, params_dict, loaded_params, split_expert_params_mapping, fused_expert_param_names, num_experts) ¶
Load one routed-expert weight in either checkpoint layout.
Parameters:
-
(name¶str) –Weight name already rewritten to draft-module naming.
-
(loaded_weight¶Tensor) –The checkpoint tensor.
-
(params_dict¶dict) –The draft model's named parameters.
-
(loaded_params¶set[str]) –Set updated with the parameters that received a value.
-
(split_expert_params_mapping¶list[tuple[str, str, int, str]]) –Mapping for the per-expert layout.
-
(fused_expert_param_names¶dict[tuple[str, str], str]) –(mlp_prefix, tag) -> param namefor the all-experts-packed layout. -
(num_experts¶int) –Total number of routed experts.
Returns:
-
bool–True when the weight was consumed (even if this rank holds none of
-
bool–the addressed experts).
Source code in vllm/models/hy_v4/nvidia/mtp.py
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 | |
set_topk_indices_buffer(topk_indices_buffer) ¶
Share the target sparse-index buffer with every draft consumer.
Proposers that walk named_modules() instead of calling this reach the same consumers via HYV4MLAAttention.topk_indices_buffer.
Source code in vllm/models/hy_v4/nvidia/mtp.py
HYV4MultiTokenPredictor ¶
Bases: Module
Owns the MTP draft blocks and their shared embedding / logits path.
Methods:
-
compact_topk_indices–Move the top-k rows at
slot_idsto the front of the buffer. -
set_skip_topk–Toggle the draft indexer for
index_share_for_mtp_iteration.
Source code in vllm/models/hy_v4/nvidia/mtp.py
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 | |
compact_topk_indices(slot_ids) ¶
Move the top-k rows at slot_ids to the front of the buffer.
Step 0 writes one row per query token of the multi-token batch, while steps 1+ decode a single token per request and index the buffer from 0. Without this gather they would read another token's rows.
Source code in vllm/models/hy_v4/nvidia/mtp.py
set_skip_topk(skip) ¶
Toggle the draft indexer for index_share_for_mtp_iteration.
The proposer clears the flag for draft step 0 so the MTP layer builds its own top-k indices, then sets it for steps 1+ so they reuse what step 0 wrote into the shared buffer instead of re-running the indexer.
Source code in vllm/models/hy_v4/nvidia/mtp.py
HYV4MultiTokenPredictorLayer ¶
Bases: Module
A single MTP draft block.
Source code in vllm/models/hy_v4/nvidia/mtp.py
HYV4SharedHead ¶
Bases: Module
Holds the draft LM head shared with the target model.
Source code in vllm/models/hy_v4/nvidia/mtp.py
_create_mtp_quant_config(hf_config, backbone_quant_config=None) ¶
Create the quantization config for the MTP layers.
The MTP quantization algorithm is given by the mtp_quant_algo field in config.json, independently of the backbone's quantization. Supported values are "FP8", "NONE" (inherit the backbone) and "BF16" / "FP16" (unquantized). A missing or "NONE" value falls back to the backbone config.
Parameters:
-
(hf_config¶PretrainedConfig) –The draft model's HF config.
-
(backbone_quant_config¶QuantizationConfig | None, default:None) –The target model's quantization config.
Returns:
-
QuantizationConfig | None–The quantization config to use for the MTP layers, or None when the MTP
-
QuantizationConfig | None–layers are unquantized.
Source code in vllm/models/hy_v4/nvidia/mtp.py
_extend_layer_types(layer_types, layer_idx, fallback) ¶
Pad a per-layer config list solayer_idx is addressable.
Source code in vllm/models/hy_v4/nvidia/mtp.py
_get_spec_layer_idx_from_weight_name(config, weight_name) ¶
Return the MTP layer index a checkpoint weight belongs to, or None.
Compatible withnum_nextn_predict_layers of 1 and 2 for a single MTP head, matching how the HY V4 checkpoints are exported.
Source code in vllm/models/hy_v4/nvidia/mtp.py
_prepare_mtp_fp8_expert_scale(quant_config, name, loaded_weight) ¶
Normalize block-wise FP8 expert scale names and dtypes.
Source code in vllm/models/hy_v4/nvidia/mtp.py
_remap_mtp_quant_exclusions(quant_config, mtp_start_layer_idx, num_mtp_layers) ¶
Translate checkpoint-named MTP quant exclusions to draft prefixes.
modules_to_not_convert / exclude_modules name MTP modules the way the checkpoint does (model.mtp_layers.0.self_attn.linear_gate), while the draft model builds them under model.layers.<num_hidden_layers + i>. is_layer_skipped compares prefixes for exact equality, so without this translation an excluded MTP module gets a quant method even though its checkpoint weight is BF16 with no weight_scale / weight_scale_inv companion: the scale then keeps its finfo(float32).min sentinel and the layer silently produces garbage.
The list lives under a different attribute per config class, hence the lookup over _MTP_QUANT_EXCLUSION_ATTRS.
Parameters:
-
(quant_config¶QuantizationConfig | None) –The MTP quantization config to widen.
-
(mtp_start_layer_idx¶int) –Index of the first MTP layer in the draft model.
-
(num_mtp_layers¶int) –Number of MTP layers.
Returns:
-
QuantizationConfig | None–A shallow copy with the translated exclusions, or the input unchanged.
Source code in vllm/models/hy_v4/nvidia/mtp.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 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 | |
_resolve_fused_expert_param(param_base, ckpt_suffix, params_dict) ¶
Map a fused expert checkpoint suffix onto a draft parameter name.
Fused checkpoints pack every expert into one tensor and name the companion scales by suffixing the projection (experts.gate_up_proj_scale_inv), while the draft model owns experts.routed_experts.w13_weight plus a separate ..._scale_inv parameter. Dropping the suffix would push the scale into the weight parameter and leave the scale at its sentinel init.
Parameters:
-
(param_base¶str) –Draft parameter holding the packed weight.
-
(ckpt_suffix¶str) –Checkpoint text following the projection name.
-
(params_dict¶dict) –The draft model's named parameters.
Returns:
-
str | None–The matching draft parameter name, or None when there is none.
Source code in vllm/models/hy_v4/nvidia/mtp.py
_should_skip_missing_mtp_scale_param(quant_config, name) ¶
Whether an unmatched scale parameter can be silently ignored.