vllm.models.minimax_m3.common.ops.dspark_context_kv
¶
Fused DSpark context-KV write for all draft layers in one CUDA kernel.
Replaces the permute copy, per-layer K-norm launches + stack, positions.repeat,
rotary_embedding and per-layer reshape_and_cache_flash calls in
DFlashQwen3Model.precompute_and_store_context_kv. K/V are read straight
from the fused projection output all_kv [num_ctx, L, 2, nkv, 128] and
written into each layer's paged cache (FLASH_ATTN, FLASHINFER_TS)
[num_blocks, nkv, block_size, 2 * 128] (K at [..., :128], V at
[..., 128:]), matching reshape_and_cache_flash: fp8 e4m3 of
x / scale for kv_cache_dtype fp8, raw bf16 otherwise; slots < 0 are padding
and are not written.
K gets the Gemma RMSNorm of its layer (x * rsqrt(mean(x^2) + eps) * (1 + w)
in fp32, materialized to bf16 like the unfused flashinfer path) followed by
partial NeoX RoPE with the token's position (see
fused_minimax_m3_dspark_context_kv). Each layer's cache is a separate
allocation, addressed as layer 0's cache plus a per-layer element offset, and
each fp8 scale as layer 0's k scale plus a float offset; the offset tables are
built once and cached (keyed by the data_ptrs) so the call stays CUDA-graph
safe.
Classes:
-
DSparkContextKVWriter–Writes precomputed context K/V into every draft layer's KV cache.
Functions:
-
rotary_dims_supported–The kernel rotates the leading 16, 32 or 64 dims of a 128-dim head.
DSparkContextKVWriter
¶
Writes precomputed context K/V into every draft layer's KV cache.
Built from the draft's Attention layers; the cache- and scale-offset
tables are cached, keyed by their data_ptrs, so calls captured in a CUDA
graph keep addressing the same memory.
Source code in vllm/models/minimax_m3/common/ops/dspark_context_kv.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 | |
rotary_dims_supported(rotary_dim, head_dim)
¶
The kernel rotates the leading 16, 32 or 64 dims of a 128-dim head.