vllm.models.glm5next.nvidia.specialized_decode.dsa_attention
¶
DSA attention stage (dsa_attn): the MLA half of the DSA layer around the
indexer and the TRTLLM-Gen sparse attention kernel, in CuTe kernels.
Stock decode runs the q/kv a-norm (Triton), then after the indexer's top-k the MLA KV cache write, the cuBLAS absorb bmm (query x W_UK), the query FP8 quant and a zero fill of the attention kernel's multi-CTA counters, all between the top-k and the attention, then the cuBLAS W_UV bmm. Here:
normisfused_q_kv_rmsnormin CuTe;head_gemvwithcacheis the absorb bmm with the static FP8 query quant as its epilogue, and M more CTAs write the normed latent into the FP8 KV cache (concat_and_cache_mla). It runs right afterq_b_proj, before the indexer, so only the index remap separates the top-k from the attention;- the attention kernel gets one caller-owned counter buffer (it resets the counters itself), so FlashInfer zero-fills none per call;
head_gemvis the W_UV bmm (and, for the KDA stage, the output gate's g_b_proj).
The bmms are per-head x @ W products with W row-major [I, J]: a thread
holds RPT rows of eight consecutive columns, loaded before the PDL wait, and
the row groups are summed across lanes and warps in a fixed order. Their FP32
sums differ from cuBLAS's only in summation order; the BF16 rounding and the
FP8 conversions follow the stock kernels.
Classes:
-
DsaAttentionStage–MultiHeadLatentAttentionWrapper.forwardof a DSA layer inside planned
Functions:
-
head_gemv–out[t, h] = x[t, h] @ weight[h]withx[M, H, I] BF16 (any token -
norm–fused_q_kv_rmsnorm(qkv[:, :q_size], qkv[:, q_size:], ...): the normed
DsaAttentionStage
¶
MultiHeadLatentAttentionWrapper.forward of a DSA layer inside planned
steps of up to MAX_TOKENS tokens. Installed as the wrapper's forward;
every other call runs the stock forward.
Source code in vllm/models/glm5next/nvidia/specialized_decode/dsa_attention.py
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 | |
_HeadGemvKernel
¶
out[t, h] = x[t, h] @ W[h] for heads row-major [I, J] weights.
CTA (h, tile) owns J columns tile * cols ...; thread (g, c) holds rows
g * rpt ... of columns 8c ..., loaded before the PDL wait. Lanes of
one column group sum their row groups with butterflies, then the warps' sums
add in warp order. fp8: the BF16 product times the inverse of
scale[0], clamped and converted as the stock static FP8 quant.
cache (latent width): CTA gemv CTAs + t writes token t's latent row
into the FP8 KV cache as concat_and_cache_mla (kv / k_scale, padded
slots skipped).
Source code in vllm/models/glm5next/nvidia/specialized_decode/dsa_attention.py
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 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 296 297 298 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 | |
_NormKernel
¶
fused_q_kv_rmsnorm of the a-projection's q and kv parts (CTA (t, 0)
and (t, 1)). A thread owns eight values; the sum of squares adds the
thread's, then the lanes' and then the warps' partials.
Methods:
-
row–The thread's eight columns of the
size-wide part atstart.
Source code in vllm/models/glm5next/nvidia/specialized_decode/dsa_attention.py
row(qkv, weight, out, partial, t, tid, start, size, eps)
¶
The thread's eight columns of the size-wide part at start.
Source code in vllm/models/glm5next/nvidia/specialized_decode/dsa_attention.py
_clamp_fp8(value)
¶
scaled_fp8_conversion's clamp before the saturating conversion.
_div_full(a, b)
¶
_flat(tensor)
¶
tensor's storage span as a 1-D view.
_rsqrt(value)
¶
head_gemv(x, weight, out, scale=None, cache=None)
¶
out[t, h] = x[t, h] @ weight[h] with x [M, H, I] BF16 (any token
stride) and weight [H, I, J] BF16 (J contiguous); out [M, H, J] is
BF16, or FP8 (statically quantized by scale, a one-element FP32 tensor)
when scale is given.
Parameters:
-
(x¶Tensor) –[M, H, I] BF16 activations.
-
(weight¶Tensor) –[H, I, J] BF16 weights.
-
(out¶Tensor) –[M, H, J] BF16 or FP8 output.
-
(scale¶Tensor | None, default:None) –the static FP8 scale of an FP8
out. -
(cache¶tuple[Tensor, Tensor, Tensor, Tensor] | None, default:None) –optionally (kv [M, L] BF16, kv_cache [blocks, block size, L] FP8, slots int64, k_scale), written as
concat_and_cache_mla.
Source code in vllm/models/glm5next/nvidia/specialized_decode/dsa_attention.py
norm(qkv, q_weight, kv_weight, eps, q_size)
¶
fused_q_kv_rmsnorm(qkv[:, :q_size], qkv[:, q_size:], ...): the normed
(q [M, q_size], kv [M, kv_size]) BF16 parts of qkv.