Archived
tools: a w2a8 recipe in the fallback shape table -- rad-tune can now size the draft head it serves
rad-tune skips a (kernel, shape) pair it cannot size: a schema names operands, not extents, and a tool has to allocate the bytes the kernel will read. For gemm_nt_q the reference describes the fp8 and the symmetric integer grids and declines every grid with a zero point, because ref_planes.h joins scale and zero into one operand a RadOpdDesc cannot state. w2a8 is such a grid, and it is the one the DFlash2 draft head serves, so both of its bands were skipped at every tune and the served card ran the axis defaults for them. The extents are not a guess. r4d_rad_layout_w2a8 owns them: codes to fragment order, N*K/4 bytes (r4d.w2a8.frag.g128), and one dword per row and 128 of K joining that group's f16 scale and integer zero, tile-major, N*K/128 of them (r4d.w2a8.sz.g128). The activation triple is quant_act_i8's own output -- int8 codes, one f32 scale a row, and the group-major code sums with rows padded to 16 -- and the grid is asymmetric, so the kernel refuses the case without the sums. b_ref stays absent; the reference exponent is mxfp4's. relayout_parity_test is where both sides exist, so the claim goes there: the table's byte total for b and b_scale against the same hooks' RadLayout.bytes, over libquant's planes, for w2a8 and for mxfp4a8, whose sizes the table has carried untested since it was written. Writing the table's K/4 as K/2 fails it with "the table sizes 32768 byte(s), the kernel stores 16384". The kernel's own guards -- K a whole number of 128-column blocks, N a whole number of 16-row tiles, the group the stored form has -- are pinned as refusals, and the shape a two-rank draft head tunes at (M 8, N 124160, K 2560, group 128) is pinned as accepted.
This commit is contained in:
1 parent
2af1079415
commit
d0c44cf5a3
3 files changed
+118
-6
No files matched your search
+27
-5
@@ -154,11 +154,15 @@ int rad_operand_shapes(const std::string& op, const Geometry& g, int n_opd, int6
|
||||
add((uint32_t)RAD_F32, {M, (n + group - 1) / group});
|
||||
}
|
||||
else if (op == "gemm_nt_q") {
|
||||
/* Block-scaled fp8 and mxfp4 only. `gemm_nt_q` covers six weight formats whose scale grids
|
||||
* (per row, per row-group, per output-row-block, e8m0 exponents, zero points, reference
|
||||
* exponents) belong to the reading kernel, not the schema. The fp8 grid is fixed by the
|
||||
* checkpoint: E4M3 [N][K] with a bf16 [ceil(N/128)][ceil(K/128)] scale plane, `group`
|
||||
* being the 128. Other formats are skipped and counted.
|
||||
/* Block-scaled fp8, mxfp4 and the 2-bit asymmetric grid. `gemm_nt_q` covers six weight
|
||||
* formats whose scale grids (per row, per row-group, per output-row-block, e8m0 exponents,
|
||||
* zero points, reference exponents) belong to the reading kernel, not the schema. The fp8
|
||||
* grid is fixed by the checkpoint: E4M3 [N][K] with a bf16 [ceil(N/128)][ceil(K/128)]
|
||||
* scale plane, `group` being the 128. libref describes the symmetric integer grids, so a
|
||||
* tool takes those from its hook and never reaches this table for them; every grid with a
|
||||
* zero point is declined there (ref_planes.h joins scale and zero into one operand a
|
||||
* description cannot state), and the ones named here are sized from the kernel's own
|
||||
* stored layout instead. Anything else is skipped and counted.
|
||||
*
|
||||
* `a_sum` and `b_ref` belong to the asymmetric-integer and mxfp4 grids. */
|
||||
const char* q = g.get_s("dtype");
|
||||
@@ -175,6 +179,24 @@ int rad_operand_shapes(const std::string& op, const Geometry& g, int n_opd, int6
|
||||
add((uint32_t)RAD_BF16, {M, N}); /* y */
|
||||
skip_opd(); /* a_sum */
|
||||
add((uint32_t)RAD_U8, {N}); /* b_ref -- the per-row reference */
|
||||
} else if (q && std::strcmp(q, "w2a8") == 0) {
|
||||
/* The DFlash2 draft head's grid (libr4d/r4d_gemm_w2a8_nt.hip): unsigned 2-bit codes in
|
||||
* the kernel's fragment order, N*K/4 bytes (`r4d.w2a8.frag.g128`), and one dword per
|
||||
* row and `group` of K holding that group's f16 scale and integer zero, tile-major,
|
||||
* N*K/group of them (`r4d.w2a8.sz.g128`) -- both extents owned by
|
||||
* libr4d/r4d_layout.cpp's r4d_rad_layout_w2a8, which is what sizes the real weight.
|
||||
* The activation pair and the group sums are quant_act_i8's own outputs above, and the
|
||||
* grid is asymmetric, so the kernel refuses the case without `a_sum`. `b_ref` is
|
||||
* mxfp4's. Sizes are the stored bytes; random bytes suffice for timing. */
|
||||
if (N <= 0 || K <= 0 || group != 128 || (K % 128) || (N % 16))
|
||||
return RAD_E_UNSUPPORTED;
|
||||
add((uint32_t)RAD_I8, {M, K}); /* a -- int8 codes */
|
||||
add((uint32_t)RAD_F32, {M, 1}); /* a_scale -- one f32 per row */
|
||||
add((uint32_t)RAD_U8, {N, K / 4}); /* b -- u2 codes, fragment order */
|
||||
add((uint32_t)RAD_U32, {N, K / group}); /* b_scale -- scale+zero dwords */
|
||||
add((uint32_t)RAD_BF16, {M, N}); /* y */
|
||||
add((uint32_t)RAD_F32, {K / group, (M + 15) / 16 * 16}); /* a_sum, group-major */
|
||||
skip_opd(); /* b_ref */
|
||||
} else {
|
||||
const bool a8 = q && std::strcmp(q, "fp8a8") == 0;
|
||||
const bool a16 = q && std::strcmp(q, "fp8a16") == 0;
|
||||
|
||||
Reference in new issue
Block a user