vllm.models.muse_spark.nvidia.specialized_decode.runtime.draft
¶
The specialized decode of the Muse Spark DSpark draft.
With decode_backend=latency_specialized the draft model's forward runs
DraftDecode.run over its stock layers: the first layer's input norm is a
CuTe kernel (cutedsl/draft/input_norm.py) and each residual boundary
(post-norm, gated fp32 residual, next pre-norm) is one CuTe kernel
(cutedsl/common/draft_boundary.py), at TP4 and TP8 one with the branch's
all-reduce in it (cutedsl/oproj/draft_all_reduce_boundary.py). These are
bitwise equal to the stock eager layers; a boundary (or the first norm) the
kernels do not cover keeps its stock modules (plan_fused_boundaries). On 1
to 16 tokens each layer's QKV projection, QK-norm, RoPE and KV insert are the
QKV front CuTe kernel (cutedsl/attention/qkv_front.py), equal to the stock
layers up to the projection GEMM's summation order. At TP8 the o_proj and
down_proj partials run on the package GEMM (cutedsl/gemm/unpooler.py), which
publishes them into the boundary's mailbox: not bitwise to cuBLAS (summation
order).
The draft model builds it once its weights are loaded (build_draft_decode).
Classes:
-
ContextKV–MuseSparkDSparkModel.precompute_and_store_context_kvas two CuTe -
DraftAllReduce–The draft's residual boundaries with their branch's all-reduce fused in
-
DraftDecode–The forward of the DSpark draft's layers with the fused boundaries and,
-
DraftPlan–The draft's fused forward as planned at build (
plan_fused_boundaries):
Functions:
-
all_reduce_boundaries_unsupported–Why the fused all-reduce boundary does not take every boundary of the
-
all_reduce_unsupported–Why the draft's residual boundaries keep the stock all-reduce of their
-
build_draft_decode–The draft's specialized decode once its weights are loaded, or None
-
context_kv_unsupported–Why the fused context K/V chain is not bitwise the stock one for this
-
may_fuse_qkv_front–Whether this draft layer's QKV projection, QK-norm, RoPE and KV insert
-
plan_context_kv–(chain, None): the fused context K/V chain, bound to its norms -
plan_fused_boundaries–(plan, None)with every residual boundary that the CuTe boundary
ContextKV
¶
MuseSparkDSparkModel.precompute_and_store_context_kv as two CuTe
kernels around its K/V projection (cutedsl/draft/context.py), bitwise
equal to it: the hidden norm, the layers' input norms and the stack before
the stock torch.bmm; the K-norm, RoPE and every layer's cache insert
after it. prepare binds and compiles them (at build, before CUDA graph
capture).
Methods:
-
prepare–Bind and compile the kernels every covered call launches; raise
-
store–The stock method's work, or False (nothing done) where the kernels
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
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 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 | |
_project(context_states)
¶
The stock K/V projection of the fused norms: [L, T, 2 * kv].
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
prepare()
¶
Bind and compile the kernels every covered call launches; raise
ValueError for a model whose rows or KV heads are not the kernels'
(context_kv_unsupported refuses them).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
store(context_states, context_positions, context_slot_mapping)
¶
The stock method's work, or False (nothing done) where the kernels
do not cover the call. A strided context_states is not covered:
the stock hidden norm takes its torch path for it, not the
single-tile kernel the fused norms reproduce.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
396 397 398 399 400 401 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 | |
DraftAllReduce
¶
The draft's residual boundaries with their branch's all-reduce fused in (TP4 and TP8, as the target's attention boundary).
Each boundary is one CuTe kernel (DraftAllReduceBoundary): every rank
multicasts its branch partial into a Lamport mailbox over the TP group, sums
the ranks' rows in the order of the stock all-reduce (the backend it
resolved to, flashinfer_ops.stock_sum_order, as the target's attention
boundary) and runs the boundary on the sum, bit for bit the stock
all-reduce followed by the boundary. Construction is collective over the TP
group; bind_gemms and then prepare set up every boundary before CUDA
graph capture.
Methods:
-
bind_gemms–At
policy.PACKAGE_GEMM_TPS, run each boundary's branch GEMM (a -
prepare–Bind the draft's boundaries (one per
bind_gemmsGEMM) to their -
project–Boundary
index's branch partialx @ linear.weight^T: on its -
run–DraftBoundary.runof boundaryindex(prepare) on -
takes–Whether this call fuses the all-reduce: on the row count alone, the
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
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 | |
bind_gemms(layers)
¶
At policy.PACKAGE_GEMM_TPS, run each boundary's branch GEMM (a
layer's o_proj, then its down_proj) on the package GEMM at its role's
launch shape (DRAFT_GEMMS), whose epilogue multicasts the partial
into the mailbox; its boundary then only consumes it. Returns how many
boundaries do. Call before prepare.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
prepare(boundaries, constants)
¶
Bind the draft's boundaries (one per bind_gemms GEMM) to their
constants (all_reduce_boundaries_unsupported takes them) and
compile the kernel variants DraftDecode.run launches (the first
boundary also on a BF16 stream, for a BF16 embedding).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
project(index, linear, x)
¶
Boundary index's branch partial x @ linear.weight^T: on its
package GEMM, which also publishes it, where it has one and the call
fuses the all-reduce, else the stock GEMM.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
run(index, partial, stream, store_stream)
¶
DraftBoundary.run of boundary index (prepare) on
the all-reduced partial; where its GEMM published it, the kernel
only consumes.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
takes(partial)
¶
Whether this call fuses the all-reduce: on the row count alone, the same on every rank (the others would wait for this rank's rows).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
DraftDecode
¶
The forward of the DSpark draft's layers with the fused boundaries and,
per layer, the fused QKV front, as planned (DraftPlan: a part the
kernels do not reproduce runs its stock modules); with all_reduce,
each boundary also takes its branch's all-reduce. prepare binds the
first layer's input norm and the boundaries' kernels before CUDA graph
capture.
Methods:
-
prepare–Bind the first layer's input norm and every planned boundary's
-
run–MuseSparkDSparkModel.forwardafter the embedding: the layers -
store_context_kv–MuseSparkDSparkModel.precompute_and_store_context_kvwith the
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
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 1029 1030 1031 1032 1033 | |
_projection(index)
¶
Boundary index's branch GEMM before the all-reduce, or None
(the branch is all-reduced unfused).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_residual_boundary(branch, stream, index, store_stream)
¶
Boundary index of branch, or of its all-reduce where it is
this rank's partial.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
prepare()
¶
Bind the first layer's input norm and every planned boundary's
kernel to their constants and compile the variants run launches:
the QKV front of every layer on it, the first boundary also on a BF16
stream (a BF16 embedding), every boundary for both row regimes of
DraftBoundary.late_rows.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
run(positions, hidden_states)
¶
MuseSparkDSparkModel.forward after the embedding: the layers
and the final norm.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
store_context_kv(context_states, context_positions, context_slot_mapping)
¶
MuseSparkDSparkModel.precompute_and_store_context_kv with the
fused context K/V chain; False where it does not cover the call (the
stock method runs).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
DraftPlan
¶
Bases: NamedTuple
The draft's fused forward as planned at build (plan_fused_boundaries):
every residual boundary with the constants of its CuTe kernel, and the
first layer's input norm's. A None keeps that part's stock modules;
refused says why, per part.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_Partial
¶
Bases: NamedTuple
A residual branch before its all-reduce: this rank's partial and whether its GEMM has already published it into the boundary's mailbox.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_attention(layer, fused_qkv, positions, hidden_states, project=None)
¶
Attention over the normalized input: the fused QKV front where it
covers the call, else the stock attention module. Returns the all-reduced
output; with project the fused front's output is this rank's o_proj
partial instead, from project(o_proj, x).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_boundary_constants(boundary, hidden_size)
¶
The constants of the CuTe boundary kernel of this boundary, or
(None, why) where it does not reproduce it (the boundary keeps its
stock modules).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_connection_unsupported(conn, hidden_size)
¶
Why the fused boundary does not take this residual connection, or
None: the stock norm-preserving connection with materialized contiguous
FP32 [hidden_size] coefficients.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_constants(build, *args, **kwargs)
¶
(build(*args, **kwargs), None), or (None, why) where it raises
ValueError: a kernel's constants function refusing what the kernel does
not reproduce.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_context_norm_constants(model)
¶
The constants of the fused context chain's norms kernel where the
chain is bitwise the stock one for this draft, else (None, why) (the
draft keeps the stock method).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_draft_unsupported(model)
¶
Why no part of the draft's forward runs fused (it keeps its stock layers), or None: it needs CUDA, the boundary kernels' hidden size (8192: the single-tile norm of fused_rmsnorm_fwd), and a bf16 compute and fp32 residual dtype in every layer.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_ffn_partial(mlp, x, project)
¶
LlamaMLP.forward without the down projection's all-reduce, the down
projection run by project.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_fused_qkv_projection(layer, positions, hidden_states)
¶
The projection with QK-norm/RoPE applied and K/V inserted, or None when the call is outside what the fused kernel covers.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_layer_boundaries(model)
¶
Each layer with its two residual boundaries: after attention, and after the feed-forward into the next layer's (or the final) norm.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_norm_params(norm)
¶
What the fused norms read of a stock norm, besides its weight.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_norm_unsupported(norm, hidden_size)
¶
Why the fused kernels do not take this norm as the stock one, or None:
the stock MuseSpark1xRMSNorm forward over all hidden_size columns,
its weight (if any) a contiguous [hidden_size].
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_own_context_rope(model, fused_qkv)
¶
Give the context keys their own copy of the first layer's RoPE, its table already in the keys' dtype, where a layer on the QKV front shares it.
The context keys are rotated with the first layer's RoPE, and that call casts the module's table to bf16 for good, which would make the first layer fail the front's fp32-table check. The copy holds the same cast, so the context cache is unchanged and the first layer keeps its fp32 table.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_package_gemm_weight(linear, shape)
¶
The weight of a plain row-parallel draft projection where the package
GEMM runs it at launch shape shape (on the GPU, every feature of the
rows the boundary's mailbox holds, and nothing Unpooler.unsupported
refuses), else None: cuBLAS.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_partial(linear, x)
¶
A plain RowParallelLinear's output before its all-reduce: the GEMM its
forward runs (_plain_row_parallel).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_plain_row_parallel(linear, tp, width)
¶
Whether linear is the stock RowParallelLinear forward over a bf16
GEMM without bias into width features, whose output is all-reduced
over the TP group.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_slot_groups(slot_mapping, num_layers)
¶
The context store's calls: (first layer, slots of each layer) for
every run of consecutive layers whose slot mappings have one shape. A
layer without slots (None in a per-layer list) stores nothing.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
_stock_rope(rotary_emb, head_dim)
¶
Whether the context keys' RoPE is the stock CUDA op on GPT-J pairs over the whole head, which the store kernel reproduces.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
all_reduce_boundaries_unsupported(plan)
¶
Why the fused all-reduce boundary does not take every boundary of the plan (the draft all-reduces its branches unfused), or None.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
all_reduce_unsupported(model)
¶
Why the draft's residual boundaries keep the stock all-reduce of their
branch, or None when every one takes it fused (DraftAllReduce).
Reads the configuration only, the same on every rank: the fused form builds a mailbox collectively.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
build_draft_decode(model, compilation_mode)
¶
The draft's specialized decode once its weights are loaded, or None where the draft keeps its stock layers (and says why).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
context_kv_unsupported(model)
¶
Why the fused context K/V chain is not bitwise the stock one for this draft (the draft keeps the stock method), or None.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
may_fuse_qkv_front(attn)
¶
Whether this draft layer's QKV projection, QK-norm, RoPE and KV insert may run as one kernel (the QKV front) on 1 to 16 tokens.
The deployment checks (SM100, no LoRA, no batch-invariant mode) are the
specialized decode's own (unsupported); its draft adds the kernel's.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
plan_context_kv(model)
¶
(chain, None): the fused context K/V chain, bound to its norms
kernel's constants, where it is bitwise the stock one; else (None,
why).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/draft.py
plan_fused_boundaries(model)
¶
(plan, None) with every residual boundary that the CuTe boundary
kernel reproduces as one kernel and the first norm on the CuTe input
norm where it reproduces it; (None, why) where no part runs fused.
A boundary runs fused with the stock norms and norm-preserving connection
(materialized coefficients) and norms draft_boundary_constants
takes; the first norm where input_norm_constants takes it (its
weight aligned). Any other part keeps its stock modules.