Archived
libref, libavx, core/format: gemm_nt_q at m2xfp4 -- a libref arm of its own over the codes and meta concatenated as the weight
libref serves gemm_nt_q at dtype m2xfp4 against the E4M3 activation and its per-128 scales, from ref_m2xfp4.cpp: libref keeps one row an op, so the gemm_nt_q row takes its launch, shape and layout hooks from there, each answering m2xfp4 and passing every other dtype to the hook it had. The layout joins the codes and meta planes into one U8 operand (codes rows, then meta rows) and the GEMM decodes it element by element. libavx refuses the encoding, so the host backend falls through to libref. The core's selection reader hands out the same codes+meta form for an m2xfp4 encoding, so the oracle and fixtures can build the operand. quant_m2xfp_test runs the row over the quantiser's planes; OPS.md gains the operand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a323b76bca
commit
21c01f9930
6 files changed
+375
-7
No files matched your search
@@ -434,6 +434,40 @@ int enc_selection_logical(const RadEncoding& e, const int* sel, int n_sel, const
|
||||
return RAD_OK;
|
||||
}
|
||||
}
|
||||
/* An m2xfp4 weight's codes with its meta plane, without the scale: the selected planes'
|
||||
* canonical bytes concatenated, as stored (the codes rows, then the meta rows). Read by a
|
||||
* kernel that decodes the scheme itself beside the E8M0 exponent plane its b_scale operand
|
||||
* carries; there is nothing to decode here, because the scale is what the selection leaves
|
||||
* out. */
|
||||
if (rad_enc_is(&e, "m2xfp4") && dt == RAD_U8) {
|
||||
int codes = -1;
|
||||
bool meta = true;
|
||||
for (int k = 0; k < n_sel && meta; ++k) {
|
||||
const RadEncPlane& p = e.plane[sel[k]];
|
||||
if (p.kind != RAD_PLANE_TILED || p.block[0] != 1 || p.block[1] < 1 ||
|
||||
rad_enc_role_in_chain(p.role, "scale"))
|
||||
meta = false;
|
||||
else if (!std::strcmp(p.role, "codes")) {
|
||||
if (codes >= 0 || p.block[1] != 1) meta = false; /* one code a value */
|
||||
else codes = k;
|
||||
}
|
||||
}
|
||||
if (meta && codes >= 0) {
|
||||
int64_t bytes = 0;
|
||||
for (int k = 0; k < n_sel; ++k)
|
||||
bytes += rows[k] * rad_enc_row_bytes(e.plane[sel[k]].dtype, cols[k]);
|
||||
if (bytes != n)
|
||||
return refuse("its planes hold " + std::to_string(bytes) +
|
||||
" bytes and the reader wants " + std::to_string(n));
|
||||
uint8_t* dst = (uint8_t*)out;
|
||||
for (int k = 0; k < n_sel; ++k) {
|
||||
const int64_t rb = rad_enc_row_bytes(e.plane[sel[k]].dtype, cols[k]);
|
||||
std::memcpy(dst, data[k], (size_t)(rows[k] * rb));
|
||||
dst += rows[k] * rb;
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
}
|
||||
if (n_sel != e.n_planes)
|
||||
return refuse("it takes " + std::to_string(n_sel) + " of its encoding's " +
|
||||
std::to_string(e.n_planes) + " planes, which decode to nothing on their own");
|
||||
|
||||
Reference in new issue
Block a user