vllm.models.inkling2.nvidia.ops.attention
¶
Inkling2 attention kernels: FA4 relative attention, gate/sink, log-scaling.
Classes:
-
Inkling2FA4RelAttentionKernel–tml_fa4 paged relative attention with fp32 output and the natural-log LSE.
Functions:
-
block_decode_attention–Write the bf16
(T, H * D)attention of eachblock-token request -
compute_log_scaling_tau–Return fp32
1 + alpha * log(max((positions + 1) / n_floor, 1)). -
gate_sink–Write bf16
output * sigmoid(gate) * sigmoid(lse - sink)per head to -
plan_attention–Return
(num_splits, use_scheduler)for one FA4 launch over requests -
plan_decode_attention–Return the split count of
rel_decode_attention(or -
rel_decode_attention–Write the gated bf16
(T, H * D)attention output for small batches.
Inkling2FA4RelAttentionKernel
¶
Bases: VllmJitKernel['Inkling2FA4RelAttentionKernel.CompileKey']
tml_fa4 paged relative attention with fp32 output and the natural-log LSE.
The relative bias is added before scaling: (qk + bias / scale) * scale.
It comes sheared ((T + 128, H, rel_extent + 256), as written by
attention_prologue), which skips tml_fa4's shearing prepass.
Methods:
-
kernel–Write
outand the(num_heads, num_tokens)LSElse.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 207 208 209 210 211 212 213 214 215 216 217 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 | |
kernel(q, key_cache, value_cache, *, block_table, cache_seqlens, cu_seqlens_q, max_seqlen_q, softmax_scale, window_size, sheared_bias, num_splits, use_scheduler, out, lse)
staticmethod
¶
Write out and the (num_heads, num_tokens) LSE lse.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
_decode_attention(q, key_cache, value_cache, out, rel_gate_sinks, block_table, cache_seqlens, cu_seqlens_q, max_query_len, num_actual_tokens, softmax_scale, window, num_splits)
¶
Launch _rel_verify_kernel (and the combine for several splits);
rel_gate_sinks None is the draft mode, window 0 a full layer.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 | |
_gl_sigmoid(x)
¶
_sigmoid (non-ftz ex2/rcp approximations).
Source code in vllm/models/inkling2/nvidia/ops/attention.py
_rel_decode_combine_kernel(OPart, LsePart, Gate, Sink, Y, num_tokens, num_actual_tokens, stride_gate, stride_sink, H, D, NUM_SPLITS, BLOCK_S, BLOCK_D, GATED)
¶
Merge the split partials, then apply the output gate and attention sink
if GATED.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
_rel_verify_kernel(Q, kv_desc, Rel, BlockTable, SeqLens, CuSeqlensQ, OPart, LsePart, Gate, Sink, Y, softmax_scale, stride_q_t, stride_rel_t, stride_bt, stride_gate, stride_sink, page_rows, head_rows, head_cols, num_splits, num_tokens, H, HKV, D, REL, REL_PAD, PAGE, IS_LOCAL, BLOCK_M, BLOCK_N, FA_BLOCK, STAGES, FUSE_GATE, DRAFT, WINDOW)
¶
One split of one request and KV head: fp32 partial output, log2 LSE.
One CTA holds all of a request's queries for one KV head (M = 64 rows of
tokens x GQA group): a TMA warp streams K/V, an MMA warp runs tcgen05
S = Q K^T into double-buffered tensor memory and O += P V, and the
default warps run the softmax and write the partials. Split s takes
key blocks s, s + num_splits, ... (of the window, for local layers).
Rel holds the sheared relative logits of attention_prologue: key
k of a request is column k - (cdiv(seqlen_k, 128) * 128 - REL_PAD).
DRAFT is plain block attention (the DSpark drafter): no relative
logits, gate or sink, and every query of a request sits at its last
position. Local layers see WINDOW keys up to a query's position.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
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 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 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 | |
_verify_load(kv_desc, k_smem, v_smem, kv_ready, kv_empty, BlockTable, req, kv_head, stride_bt, n_first, num_splits, num_pre, num_iters, page_rows, head_rows, head_cols, PAGE, BLOCK_N, D, STAGES)
¶
Stream the split's K/V blocks after the first num_pre.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
_verify_load_block(kv_desc, k_smem, v_smem, kv_ready, BlockTable, req, kv_head, stride_bt, n_first, num_splits, i, page_rows, head_rows, head_cols, PAGE, BLOCK_N, D, STAGES)
¶
TMA-load K and V of the split's block i, one page-sized slab at a time.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
_verify_mma(q_smem, k_smem, v_smem, s_tmem, o_tmem, kv_ready, kv_empty, s_ready, p_ready, o_done, o_final, num_iters, BLOCK_M, BLOCK_N, STAGES)
¶
Issue S = Q K^T for block i, then O += P V for block i - 1.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
_verify_p(s_tmem, b, BLOCK_M, BLOCK_N)
¶
Alias bf16 P over the first half of S buffer b.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
_verify_softmax(s_tmem, o_tmem, s_ready, p_ready, o_done, o_final, Rel, OPart, LsePart, Gate, Sink, Y, stride_gate, stride_sink, q_start, q_len, seqlen_k, pos0, kv_head, split, num_splits, num_tokens, n_first, n_bias, num_iters, fa_mask_left, fa_mask_right, softmax_scale, stride_rel_t, rel_base, H, G, D, REL, REL_PAD, IS_LOCAL, BLOCK_M, BLOCK_N, FA_BLOCK, FUSE_GATE, DRAFT, WINDOW)
¶
Online softmax following FA4 per element.
qk + bias / scale as an FMA, lazy rescaling (threshold 8),
ex2(qk * scale_log2 - max * scale_log2) with FA4's ex2 emulation
columns on blocks without causal or window masking, bf16 P, fp32 row sums.
O is rescaled in tensor memory only when some row's max moved by more
than the lazy-rescale threshold, after the previous P @ V completed.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
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 | |
block_decode_attention(q, key_cache, value_cache, out, *, block_table, cache_seqlens, cu_seqlens_q, block, window, num_splits)
¶
Write the bf16 (T, H * D) attention of each block-token request
to out: every query sees the request's keys up to its last one, or the
last window of them if window (the DSpark draft block attention).
Runs _rel_verify_kernel like rel_decode_attention, without the
relative logits, gate and sink.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
compute_log_scaling_tau(positions, n_floor, alpha)
¶
Return fp32 1 + alpha * log(max((positions + 1) / n_floor, 1)).
Source code in vllm/models/inkling2/nvidia/ops/attention.py
gate_sink(output, gate, lse, sinks, result)
¶
Write bf16 output * sigmoid(gate) * sigmoid(lse - sink) per head to
result.
gate and result are (T, H * D), sinks and lse are
(T, H) and output is (T, H, D).
Source code in vllm/models/inkling2/nvidia/ops/attention.py
plan_attention(is_local, query_lens, seq_lens, num_heads, num_kv_heads)
¶
Return (num_splits, use_scheduler) for one FA4 launch over requests
of query_lens new tokens and seq_lens keys.
Window layers never split KV. FA4's split scheduler only pays off for the
smallest launches. Larger ones split the keys of every query tile s
ways, minimizing the estimated time: the larger of the wave-quantized
time of the longest CTAs and the total CTA time spread over the SMs plus
half the longest CTA, plus the merge of s fp32 partials (within
256 MiB). Split counts within 2% of the best estimate resolve to the
smallest.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
plan_decode_attention(is_local, num_reqs, max_query_len, num_heads, num_kv_heads, rel_extent)
¶
Return the split count of rel_decode_attention (or
block_decode_attention), or 0 to use FA4.
Each CTA holds all queries of one request for one KV head. Local layers
(rel_extent: the window) give each split one key block of the
window, or a few blocks for larger batches (a single split writes the
gated output without the combine kernel); decode keeps one block per
split up to twice the work of verify. Full layers give each request and
KV head num_sms / 8 splits, fewer once that exceeds 6 CTAs per SM,
but never less than one CTA per SM. The count depends only on the batch,
not the KV lengths, so it holds for every replay of a CUDA graph.
Source code in vllm/models/inkling2/nvidia/ops/attention.py
rel_decode_attention(q, key_cache, value_cache, rel_logits, gate, sinks, out, *, block_table, cache_seqlens, cu_seqlens_q, max_query_len, num_actual_tokens, softmax_scale, is_local, num_splits)
¶
Write the gated bf16 (T, H * D) attention output for small batches.
Split-KV relative attention on _rel_verify_kernel (see
plan_decode_attention) reading the sheared relative logits. With more
than one split, a second launch merges the fp32 partials and applies the
output gate and attention sink. Tokens from num_actual_tokens on are
zeroed.