Archived
ParoQuant int5/int4: review fixes -- docs, the w5 layout pinned and inverted, zero points checked, int4 import tested
* docs/OPS.md: the dtypes w5a16, w4a16_asym, w5a8i8, w4a8i8_asym, givens_quant_act_i8g, and which rows read pb1/pb2. * r4d_gemm_w5a16_nt_m64: drop the unused two's-complement dequant copied from w4; the errors name this kernel. * r4d_layout: r4d_rad_unrelayout_w5 (the inverse, wired to both w5 rows; the int4 rows take w4's); a zero point that is not a 4-/5-bit code is refused at load (the int8 prefill kernel reads five bits of it, the f16 one all). * rad_fp8.h: one linear_is_givens predicate (table dtypes checked for both formats, the zero plane's u8 too); declare_rotation declares the tables and rot_stages only, decl_rot_op the op in front of each GEMM. * tests: relayout_parity pins the w5 stored form and its refusal; checkpoint_test imports z-lab's int4 as a fused gate|up (two rotated parts); the selftest's asymmetric planes and part bounds come from one helper each. * checkpoint: the ParoQuant refusal names both readable forms.
This commit is contained in:
1 parent
3491aca6fe
commit
a19cbcae85
10 files changed
+312
-187
No files matched your search
@@ -327,6 +327,18 @@ void sz_write(const WGeom& g, const RadTensor* pl, int zfixed, uint32_t* sz) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Every zero point a code of `bits` bits: what an asymmetric grid's zero is, and what the int8
|
||||
* prefill kernel reads back out of the scale dword (r4d_gemm_wpa8i8_tiled.hip takes five bits of it,
|
||||
* where the f16 kernel takes the whole value -- a larger zero would make the two disagree). */
|
||||
bool sz_zeros_fit(const WGeom& g, const RadTensor& zp, int bits) {
|
||||
const long long nz = g.N * (g.K / g.group);
|
||||
for (long long i = 0; i < nz; ++i) {
|
||||
const int z = zero_at(zp, i);
|
||||
if (z < 0 || z >= (1 << bits)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void sz_read(const WGeom& g, const uint32_t* sz, const RadTensor* pl, bool asym) {
|
||||
const long long nt = g.N / R4D_NTILE, nsz = g.K / g.group;
|
||||
for (long long t = 0; t < nt; ++t)
|
||||
@@ -416,6 +428,9 @@ extern "C" int r4d_rad_relayout_w4(const RadParam* p, int n_p, int operand, cons
|
||||
if (dst_bytes != L.bytes) return RAD_E_SHAPE;
|
||||
std::memset(dst, 0, (size_t)dst_bytes);
|
||||
if (operand == Q_BSCALE) {
|
||||
/* a ROTATED (ParoQuant) grid's zero is a 4-bit code */
|
||||
if (w4_asym(p, n_p) && std::strncmp(enc->transform, "givens", RAD_ENC_STR) == 0 &&
|
||||
!sz_zeros_fit(g, pl[1], 4)) return RAD_E_FORMAT;
|
||||
sz_write(g, pl, w4_asym(p, n_p) ? -1 : 8, (uint32_t*)dst);
|
||||
return RAD_OK;
|
||||
}
|
||||
@@ -501,6 +516,7 @@ extern "C" int r4d_rad_relayout_w5(const RadParam* p, int n_p, int operand, cons
|
||||
if (dst_bytes != L.bytes) return RAD_E_SHAPE;
|
||||
std::memset(dst, 0, (size_t)dst_bytes);
|
||||
if (operand == Q_BSCALE) {
|
||||
if (!sz_zeros_fit(g, pl[1], 5)) return RAD_E_FORMAT;
|
||||
sz_write(g, pl, -1, (uint32_t*)dst);
|
||||
return RAD_OK;
|
||||
}
|
||||
@@ -526,6 +542,35 @@ extern "C" int r4d_rad_relayout_w5(const RadParam* p, int n_p, int operand, cons
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_unrelayout_w5(const RadParam* p, int n_p, int operand, const RadEncoding* enc,
|
||||
const int* sel, const void* src, int64_t src_bytes,
|
||||
const RadTensor* pl, int n) {
|
||||
RadLayout L;
|
||||
WGeom g;
|
||||
const int rc = w5_enc_layout(p, n_p, operand, enc, sel, pl, n, &L, &g);
|
||||
if (rc != RAD_OK) return rc;
|
||||
if (src_bytes != L.bytes) return RAD_E_SHAPE;
|
||||
if (operand == Q_BSCALE) {
|
||||
sz_read(g, (const uint32_t*)src, pl, true);
|
||||
return RAD_OK;
|
||||
}
|
||||
const uint32_t* wq = (const uint32_t*)src;
|
||||
const uint32_t* hi = wq + g.N * g.K / 8;
|
||||
const long long rb = (g.K * 5 + 7) / 8;
|
||||
uint8_t* d = (uint8_t*)pl[0].data;
|
||||
std::memset(d, 0, (size_t)(g.N * rb));
|
||||
for (long long nn = 0; nn < g.N; ++nn)
|
||||
for (long long k = 0; k < g.K; ++k) {
|
||||
long long w;
|
||||
int nib;
|
||||
w4_slot(g, nn, k, &w, &nib);
|
||||
const int e = nib % 2 == 0 ? nib / 2 : 4 + nib / 2; /* as r4d_rad_relayout_w5 */
|
||||
const uint32_t q = ((wq[w] >> (4 * nib)) & 15u) | (((hi[w / 4] >> (8 * (w % 4) + e)) & 1u) << 4);
|
||||
rad_store_bits(d + nn * rb, 5, k, q);
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ---- w8: i8 codes, symmetric about zero, an f16 scale a group. The f16 kernel (a16) reads the
|
||||
* code offset binary with zero 128 in the shared dword; the int8 kernel (a8) reads it signed with a
|
||||
* bare f16 scale plane. */
|
||||
|
||||
Reference in new issue
Block a user