vllm.model_executor.kernels.linear.mixed_precision.rdna_hybrid_w4a16
¶
Hybrid W4A16 kernel: Triton for prefill, HIP skinny for decode.
Routes based on batch size M
M <= MAX_SKINNY_BATCH_SIZE: HIP skinny GEMM (wvSplitK_int4_g) M > MAX_SKINNY_BATCH_SIZE: Triton W4A16 fused dequant GEMM
Stores the weights ONCE as int8 [N, K//2] (ExLlama shuffle packed). Both paths read this single buffer: the HIP skinny kernel uses it directly, and the triton kernel reinterprets it as int32 [N, K//8] via a view (and transposes tiles in-register). No dual weight storage.
Classes:
-
RDNAHybridW4A16LinearKernel–Hybrid W4A16 kernel: HIP skinny for decode, Triton for prefill.
Functions:
-
pack_int4_exllama_shuffle–Pack uint4 values into ExLlama shuffle format: [N, K] -> [N, K//8] int32.
-
pack_skinny_int4–Pack [N, K] uint4 into the skinny weight layout the kernels consume.
-
triton_w4a16_skinny_fmt_gemm–Fused W4A16 GEMM reading from skinny weight format [N, K//8].
RDNAHybridW4A16LinearKernel
¶
Bases: MPLinearKernel
Hybrid W4A16 kernel: HIP skinny for decode, Triton for prefill.
Stores the weights once as int8 [N, K//2] (ExLlama shuffle packed). The HIP skinny kernel reads it directly; the triton kernel reinterprets the same buffer as int32 [N, K//8] via a view, so there is no dual weight storage.
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
_act_pad_bytes(row_bytes)
¶
Bytes to add to an activation row stride to move it off the cliff.
_pad_activation_rows(x_2d)
¶
Copy x_2d into a row-padded buffer when its row stride is on the cliff.
The packed weight is padded once at load time, but activations are produced fresh every step, so this materialises a padded copy.
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
_rdna_hybrid_w4a16_apply_impl(x_2d, w_q, w_s, w_zp, bias, cu_count, group_size)
¶
Dispatch between skinny GEMM and Triton based on batch size M.
w_zp is [N//8, K//G] int32 for asymmetric layers, None for symmetric.
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
_triton_w4a16_skinny_fmt_kernel(a_ptr, b_ptr, scales_ptr, zp_ptr, c_ptr, M, N, K, K8, num_groups, stride_bn, stride_am, group_size, ZP_BIAS, HAS_ZP, BLOCK_M, BLOCK_N, BLOCK_K)
¶
Fused W4A16 GEMM reading weights from skinny format [N, K//8].
B is stored as [N, K//8] int32 using ExLlama shuffle packing: each int32 packs 8 K-values with interleave [0,2,4,6,1,3,5,7]: packed = val[0] | (val[2]<<4) | (val[4]<<8) | (val[6]<<12) | (val[1]<<16) | (val[3]<<20) | (val[5]<<24) | (val[7]<<28)
Scales are [N, K//G] (skinny layout, NOT transposed). When HAS_ZP=True, zp_ptr holds [N//8, K//G] int32 with row n's raw zero-point at word[n//8] bits 4*(n%8), and dequant is (nibble - zp_raw) * scale. When HAS_ZP=False, only the constant ZP_BIAS is subtracted (symmetric).
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
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 | |
_weight_pad_bytes(row_bytes)
¶
Bytes to add to a packed weight row stride to move it off the cliff.
Only strides that are a multiple of _WEIGHT_CLIFF_BYTES are moved, and
only by one cache line; padding a stride that is already off the cliff
costs memory and measures slower.
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
pack_int4_exllama_shuffle(w_uint4)
¶
Pack uint4 values into ExLlama shuffle format: [N, K] -> [N, K//8] int32.
Each int32 packs 8 K-values with interleave order [0,2,4,6,1,3,5,7].
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
pack_skinny_int4(unpacked)
¶
Pack [N, K] uint4 into the skinny weight layout the kernels consume.
ExLlama shuffle to [N, K//8] int32, viewed as int8 [N, K//2]. On gfx1151
the row stride is nudged off the cliff (see _weight_pad_bytes).
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
triton_w4a16_skinny_fmt_gemm(a, b_q, scales, group_size, zp_bias=8, zp=None)
¶
Fused W4A16 GEMM reading from skinny weight format [N, K//8].
Parameters:
-
(a¶Tensor) –Activation matrix [M, K], float16 or bfloat16.
-
(b_q¶Tensor) –Packed weight matrix [N, K//8], int32 (ExLlama shuffle).
-
(scales¶Tensor) –Per-group scales [N, K//G], same dtype as a.
-
(group_size¶int) –Quantization group size (resolved from -1 to K by caller).
-
(zp_bias¶int, default:8) –Constant zero bias (default 8 for unsigned int4).
-
(zp¶Tensor | None, default:None) –Raw per-group zero-points [N//8, K//G] int32, row n at word[n//8] bits 4*(n%8) (asymmetric). When provided, dequant is (nibble - zp_raw) * scale.
Returns:
-
Tensor–Output matrix [M, N], same dtype as a.
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
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 339 340 341 342 343 344 345 346 347 348 349 | |