vllm.models.deepseek_v41.nvidia.specialized_decode.ampere.mhc_projection
¶
The mHC projection of DeepSeek-V4.1 prefill on SM80, in CuTe DSL.
Every mHC boundary (see mhc.py) projects each token's flattened residual
streams, width = 4 x hidden BF16 values (hidden for the first
layer's broadcast embedding), onto 24 FP32 mixes, and needs the row's sum of
squares for their RMS. The stock epilogue (MHC_PRE_NORM_KERNEL) takes
both as n_splits partial sums over equal slices of the width and adds
them up.
Above the 256 rows the SM80 boundary kernels take (mhc.py), the stock path projects with one TileLang kernel on CUDA cores that runs the whole width in one CTA per two rows, since DeepGEMM's split-k tensor-core projection does not run on SM80. It reads the 1.5 MB projection once per two rows: about 0.5 ms per boundary at a 4096-token prefill chunk on A100, 45 ms of a 346 ms chunk.
MhcProjection runs it on mma.sync BF16 tensor cores. The grid is
(splits, row tiles); a CTA projects 128 rows over one width / splits
slice, in steps of 64 columns:
- the rows' 64 columns go to shared memory with
cp.async, two stages, so the next step's load flies during this step's MMAs; rows past the last are not loaded, and their outputs are not written; - the projection's
[24, 64]FP32 slice is read into registers one step ahead and split into two BF16 terms,hi = bf16(w)andlo = bf16(w - hi), which go to shared memory beside the rows; - each of the 8 warps multiplies its 16 rows by both terms (
ldmatrixoperands, FP32 accumulation) and adds the squares of its row fragments to the rows' sums of squares.
A CTA writes its slice's 24 partial mixes and the partial sum of squares of
each row, mixes[split, row] and sqrsum[split, row].
Numerics: the rows are exact in BF16, and hi + lo keeps about 16 of the
weight's 24 significand bits (TF32, the precision of DeepGEMM's projection
on SM90 and SM100, keeps 11). Products and sums are FP32, so the result
differs from the FP32 CUDA-core projection by about 2^-17 of each
product plus FP32 rounding of a different summation order.
Classes:
-
MhcProjection–Split-k mHC projection and sums of squares; see the module docstring.
Functions:
-
mhc_projection–SPLITSpartial sums of the mHC projection of the BF16 rowsx -
supports–Whether
MhcProjectiontakes rowswidthvalues wide.
MhcProjection
¶
Split-k mHC projection and sums of squares; see the module docstring.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mhc_projection.py
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 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 | |
_kernel(device_index, width)
cached
¶
MhcProjection compiled for a device and row width.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mhc_projection.py
mhc_projection(x, fn)
¶
SPLITS partial sums of the mHC projection of the BF16 rows x
[rows, width] by the FP32 fn [24, width] (both contiguous and
16-byte aligned) and of the rows' sums of squares: mixes [SPLITS,
rows, 24] and sqrsum [SPLITS, rows], as MHC_PRE_NORM_KERNEL
takes them.