vllm.models.hy_v4.nvidia.flashmla_sparse ¶
Sink-capable FlashMLA sparse backend for HY V4 (NVIDIA).
HY V4 adds a per-head learnable attention sink on top of sparse MLA. The vendored FlashMLA kernels already accept an attn_sink argument, but vLLM's shared FLASHMLA_SPARSE backend neither advertises sink support nor forwards the tensor, so the bias would be silently dropped.
This module supplies the missing wiring inside the model package, mirroring how vllm.models.deepseek_v4.nvidia.flashinfer_sparse hands sinks to the FlashInfer sparse MLA kernels: subclass the platform backend, declare supports_sink, and thread the sink into every kernel call.
The subclass intentionally keeps the inherited get_name() ("FLASHMLA_SPARSE"). Several shared code paths key off that exact string — _canonicalize_sparse_mla_kv_cache_dtype promotes a quantized KV cache to fp8_ds_mla for it, and FlashMLASparseImpl asserts that layout — so a new name would silently change KV cache behaviour. Onlysupports_sink and the two kernel wrappers differ from the parent.
Classes:
-
HYV4FlashMLASparseBackend–FLASHMLA_SPARSEwith attention-sink support for HY V4. -
HYV4FlashMLASparseImpl–FlashMLA sparse impl that applies HY V4's per-head learnable sink.
HYV4FlashMLASparseBackend ¶
Bases: FlashMLASparseBackend
FLASHMLA_SPARSE with attention-sink support for HY V4.
Keeps the parent's name, metadata and builder; only the impl class and the sink capability differ. See the module docstring for why the name is reused.
Source code in vllm/models/hy_v4/nvidia/flashmla_sparse.py
HYV4FlashMLASparseImpl ¶
Bases: FlashMLASparseImpl
FlashMLA sparse impl that applies HY V4's per-head learnable sink.
The sink enters as the sinks impl kwarg of vllm.model_executor.layers.attention.MLAAttention and is consumed by the FlashMLA kernels, which fold it into the softmax denominator: out *= exp(lse) / (exp(lse) + exp(sink)).
Source code in vllm/models/hy_v4/nvidia/flashmla_sparse.py
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 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
_sinks_for_query(q, head_dim, kernel_heads) ¶
Return the sink laid out for the kernel's query head count.
Parameters:
-
(q¶Tensor) –Query tensor, before any head padding.
-
(head_dim¶int) –Axis of
qholding the query heads. -
(kernel_heads¶int) –Head count the kernel is invoked with, which may exceed the query head count because of padding.
Returns:
-
Tensor | None–The sink tensor padded to
kernel_headswith-inf(a no-op -
Tensor | None–sink) for the padded lanes, or None when the layer has no sink.
Raises:
-
ValueError–If the sink and query head layouts disagree, or if they live on different devices.
Source code in vllm/models/hy_v4/nvidia/flashmla_sparse.py
_validate_sinks(sinks, num_heads) staticmethod ¶
Reject sink tensors the FlashMLA kernels cannot consume.
Parameters:
-
(sinks¶Tensor | None) –Candidate sink tensor, or None when the layer has no sink.
-
(num_heads¶int) –Local (TP-sharded) query head count of this layer.
Raises:
-
ValueError–If the dtype is not float32 or the shape is not
(num_heads,).