Skip to content

Run frontier MoE models on hardware you already own β€” pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

fp8: renumber our format fmt 7 -> 8 (#705 claimed 7 for MXFP4)

monotophic388a62dc08c1
diff --git a/c/backend_metal.h b/c/backend_metal.h
index 84baccfa..2c09ba76 100644
--- a/c/backend_metal.h
+++ b/c/backend_metal.h
@@ -29,12 +29,12 @@ int coli_metal_mem_info(size_t *used_bytes, size_t *total_bytes);
/*
* y[S,O] = (x[S,I] @ W[O,I]^T) * scale[o]. fmt=4 (grouped int4) instead folds a
* PER-GROUP scale into the accumulation -- see the shader comment in backend_metal.mm.
- * fmt=7 (fp8 passthrough -- see colibri.c) likewise folds its per-128x128-block
+ * fmt=8 (fp8 passthrough -- see colibri.c) likewise folds its per-128x128-block
* scale into the accumulation.
* fmt matches QT in colibri.c: 0=f32, 1=int8, 2=int4(packed), 3=int2(packed),
* 4=int4(packed, same layout as 2)+per-group scale (gs = group size along I; scale
* array is [O, ceil(I/gs)] floats instead of [O]),
- * 7=fp8-e4m3 (one raw byte/element, same layout as fmt=1) + per-128x128-
+ * 8=fp8-e4m3 (one raw byte/element, same layout as fmt=1) + per-128x128-
* block scale (scale array is [ceil(O/128),ceil(I/128)] floats; no group-size
* parameter needed -- the block is a fixed 128x128, not caller-configurable).
* gs is ignored for fmt!=4 (pass 0).
diff --git a/c/backend_metal.mm b/c/backend_metal.mm
index 3df08c8b..176e99cb 100644
--- a/c/backend_metal.mm
+++ b/c/backend_metal.mm
@@ -13,7 +13,7 @@
// nibble layout as fmt=2, but scale is PER-GROUP (gsz elements of I), buffer(1) holds
// [O, ceil(I/gsz)] floats indexed scale[o*ng+g] -- so unlike fmt 1-3, the group scale is
// folded into the accumulation itself (see the fmt==4 branch), not applied once at the end.
-// fmt=7 (native FP8-e4m3 passthrough -- see colibri.c): raw byte
+// fmt=8 (native FP8-e4m3 passthrough -- see colibri.c): raw byte
// layout identical to fmt=1 (one e4m3 byte per element, no packing), but the scale is
// per-128x128 BLOCK of [O,I] -- buffer(1) holds [ceil(O/128),ceil(I/128)] floats indexed
// scale[(o/128)*nblkI+i/128]. Folded into acc like fmt=4's per-group scale, for the
@@ -85,7 +85,7 @@ kernel void mm_gemv(device const uchar* w [[buffer(0)]], // raw weight by
acc += float(int(b>>4)-8) * xr[i+1] * sc1;
}
}
- } else if (fmt == 7) { // fp8 e4m3 passthrough: one raw byte per
+ } else if (fmt == 8) { // fp8 e4m3 passthrough: one raw byte per
// element (like fmt=1), scale per 128x128
// block folded into acc (like a grouped fmt).
int nblkI = (I + 127) / 128;
@@ -111,9 +111,9 @@ kernel void mm_gemv(device const uchar* w [[buffer(0)]], // raw weight by
for (int i = I8*8 + slane; i < I; i += 32) acc += wr[i] * xr[i];
}
acc = simd_sum(acc);
- // fmt==4 (per-group) and fmt==7 (per-block) already folded their scale into acc
+ // fmt==4 (per-group) and fmt==8 (per-block) already folded their scale into acc
// above -- do not scale again.
- if (slane == 0) y[row] = (fmt == 4 || fmt == 7) ? acc : acc * scale[o];
+ if (slane == 0) y[row] = (fmt == 4 || fmt == 8) ? acc : acc * scale[o];
}
// Batched bindless expert GEMV: each row gr belongs to expert erow[gr], whose weight and
@@ -477,20 +477,20 @@ static size_t fmt_bytes(int fmt, int I, int O) {
if (fmt == 2) return (size_t)O * ((I+1)/2);
if (fmt == 3) return (size_t)O * ((I+3)/4);
if (fmt == 4) return (size_t)O * ((I+1)/2); // grouped int4: identical packed-nibble layout to fmt=2
- if (fmt == 7) return (size_t)O * I; // fp8 e4m3: one raw byte/element, same as fmt=1
+ if (fmt == 8) return (size_t)O * I; // fp8 e4m3: one raw byte/element, same as fmt=1
return (size_t)O * I * sizeof(float);
}
// Grouped-int4 (fmt=4) scale-array size: one f32 per gsz-element group, per row -> O*ceil(I/gsz).
-// fp8 (fmt=7) scale-array size: one f32 per 128x128 BLOCK -> ceil(O/128)*ceil(I/128) (2D,
+// fp8 (fmt=8) scale-array size: one f32 per 128x128 BLOCK -> ceil(O/128)*ceil(I/128) (2D,
// not per-row -- quant.h isn't included here, so the ceil-div is inlined rather than sharing
// colibri.c's qt_scale_bytes/quant.h's fp8_nblk). The block is a fixed 128x128, so gs is
-// ignored for fmt==7. f32 is this build's implemented scale
-// ENCODING for fmt=7 (see quant.h/colibri.c) -- this file has no reason to know that a
+// ignored for fmt==8. f32 is this build's implemented scale
+// ENCODING for fmt=8 (see quant.h/colibri.c) -- this file has no reason to know that a
// UE8M0 encoding exists at all: qt_resolve_fmt refuses it on the CPU read path before any
// tensor in that encoding could ever reach this Metal-side sizing helper.
static size_t fmt_scale_bytes(int fmt, int I, int O, int gs) {
if (fmt == 4) return (size_t)O * ((I + gs - 1) / gs) * sizeof(float);
- if (fmt == 7) return (size_t)((O + 127) / 128) * (size_t)((I + 127) / 128) * sizeof(float);
+ if (fmt == 8) return (size_t)((O + 127) / 128) * (size_t)((I + 127) / 128) * sizeof(float);
return (size_t)O * sizeof(float);
}
@@ -658,9 +658,9 @@ extern "C" int coli_metal_mem_info(size_t *used, size_t *total) {
extern "C" int coli_metal_matmul(ColiMetalTensor **tp, float *y, const float *x,
const void *weights, const float *scales,
int fmt, int S, int I, int O, int gs) {
- /* fmt==7 (fp8 passthrough) is an explicit allow-list entry, not folded into the 0..4
+ /* fmt==8 (fp8 passthrough) is an explicit allow-list entry, not folded into the 0..4
* contiguous range check below: it is not adjacent to it. */
- if (!g_dev || fmt < 0 || (fmt > 4 && fmt != 7)) return 0;
+ if (!g_dev || fmt < 0 || (fmt > 4 && fmt != 8)) return 0;
@autoreleasepool {
ColiMetalTensor *t = *tp;
if (!t) {
diff --git a/c/colibri.c b/c/colibri.c
index 6e733449..173d1c0b 100644
--- a/c/colibri.c
+++ b/c/colibri.c
@@ -104,10 +104,13 @@ typedef struct {
* fmt=2 INT4 -> q4 (2 valori per byte, impacchettati) + scala per riga
* INT4 e' cio' che fa stare la densa residente nei 15 GB (0.5 byte/param). */
/* fmt: 0 F32, 1 INT8, 2 INT4 (2/byte), 3 INT2 (4/byte), 4 INT4-GROUPED, 5 INT3-G64,
- * 6 E8/IQ3 lattice, 7 FP8-E4M3 (native, passthrough -- see quant.h). fmt=7 is a
- * PUBLIC ordinal, assigned by the maintainer on #524; it developed under the
- * PRIVATE ORDINAL BLOCK convention below as fmt=100 and graduated out of that
- * block into this list at the same time this comment was written.
+ * 6 E8/IQ3 lattice, 8 FP8-E4M3 (native, passthrough -- see quant.h). fmt=7 is
+ * MXFP4 (Kimi K3 Vulkan tier, #676/#705, backend_vulkan.c) -- claimed upstream,
+ * never a QT format here, deliberately absent from this struct's dispatch.
+ * fmt=8 is a PUBLIC ordinal: it developed under the PRIVATE ORDINAL BLOCK
+ * convention below as fmt=100, graduated to fmt=7 when the maintainer assigned
+ * that ordinal on #524, and was renumbered to 8 after #705 merged claiming 7
+ * for MXFP4 while this PR was still open (see the convention comment below).
* q4 ospita int4/int2/int3 packed. fmt=4 (grouped int4, #242): per-row nibbles + one f32
* scale per group of `gs` inputs (s has O*ceil(I/gs) entries).
* fmt=6 (E8/IQ3 lattice, #452): 98B per 256 weights = 3.0625 bits/weight, grid
@@ -117,7 +120,7 @@ typedef struct {
* 64-input group as 24 bytes = 16B low plane (2 bits/val, int2 layout) + 8B high plane
* (1 bit/val), plus ONE f32 scale PER GROUP (s has O*ceil(I/64) entries, not O). 3.5
* bits/weight effective β€” the quality/size sweet spot measured in the #132 ablation.
- * fmt=7 (native FP8-e4m3 passthrough, resident/quality-core tier -- see quant.h's
+ * fmt=8 (native FP8-e4m3 passthrough, resident/quality-core tier -- see quant.h's
* FP8_BLOCK/e4m3_decode/matmul_fp8): q8 holds O*I raw e4m3 bytes, ONE byte per weight,
* byte-identical layout to fmt=1's weight bytes (q4 is unused/NULL, same as fmt=1) --
* disambiguated from fmt=1 (and, at small [O,I], from fmt=6 -- see below) purely by
@@ -131,19 +134,23 @@ typedef struct {
* documents why (a DeepSeek-V4 checkpoint ships this identical weight geometry
* with a UE8M0 scale encoding instead) and how an unimplemented encoding is
* recognized and refused by name rather than silently misread.
- * gs is unused (0) for fmt=7, same as fmt 1/2/3. */
+ * gs is unused (0) for fmt=8, same as fmt 1/2/3. */
/* ---- PRIVATE ORDINAL BLOCK CONVENTION ------------------------------------
- * fmt values 0-7 are upstream-assigned, public, stable ordinals -- do not
- * reuse or renumber them (fmt=7 is the newest member: assigned by the
- * maintainer on #524, after developing under this block as fmt=100 -- see
- * "graduated" above). fmt values 100+ remain this repo's PRIVATE/EXPERIMENTAL
+ * fmt values 0-8 are upstream-assigned, public, stable ordinals -- do not
+ * reuse or renumber them (fmt=8 is the newest member -- see "renumbered"
+ * above). fmt values 100+ remain this repo's PRIVATE/EXPERIMENTAL
* block for any OTHER in-flight format proposal: ordinals a branch mints for
* itself during development so it can't collide with a number upstream claims
- * out from under it -- exactly what happened to fmt=7's OWN earlier private
- * number, fmt=6, when #465's E8/IQ3 proposal claimed that ordinal upstream
- * while this branch was still developing against it, forcing a re-mint to
- * fmt=100 (see upstream_contribution/FORMATS_registry_draft.md for the
- * incident that prompted the rule).
+ * out from under it. That collision has now bitten this SAME format twice:
+ * first when #465's E8/IQ3 proposal claimed its original private number,
+ * fmt=6, upstream while this branch was still developing against it (forcing
+ * the re-mint to fmt=100 -- see upstream_contribution/FORMATS_registry_draft.md
+ * for the incident that prompted the rule); and again when #705 merged MXFP4
+ * as fmt=7 while this PR sat open already holding the maintainer-assigned
+ * ordinal 7 from #524, forcing the 7 -> 8 renumber recorded here. Ordinals
+ * are only settled by MERGE into dev, not by assignment on an open PR --
+ * docs/FORMATS.md (PR 2 of this pair) is the registry meant to make the
+ * next claim visible before it lands.
*
* A PRIVATE-BLOCK ordinal is an internal enum value only -- qt_resolve_fmt
* (below) infers format purely from byte arithmetic; the container on disk
@@ -152,17 +159,17 @@ typedef struct {
* see qt_resolve_fmt's own note on where that plumbing would attach -- not
* present in this build.) Nothing outside this binary's own compiled code
* ever observes a 100+ number, so renumbering one later (e.g. when a format
- * is upstreamed and assigned a real public ordinal at merge, as just happened
- * for fmt=7) is a pure find-and-replace with zero on-disk or cross-version
+ * is upstreamed and assigned a real public ordinal, as has now happened twice
+ * for fmt=8) is a pure find-and-replace with zero on-disk or cross-version
* compatibility impact.
*
* Rule for adding a new format to this branch or a future one: claim the next
- * unused 100+ integer, never a number already claimed upstream (check dev
- * before picking one -- this is exactly the mistake that forced fmt=7's own
- * proposal to renumber away from fmt=6) or by another in-flight private
- * format. Never ship a 100+ ordinal as a public default/committed-upstream
- * value -- the real ordinal is assigned by the maintainer at merge time,
- * exactly as fmt=7's was. */
+ * unused 100+ integer, never a number already claimed upstream (check dev AND
+ * open PRs before picking one -- dev alone was not enough to prevent either of
+ * fmt=8's two renumbers) or by another in-flight private format. Never ship a
+ * 100+ ordinal as a public default/committed-upstream value -- the real
+ * ordinal is only settled when the format MERGES into dev, exactly as fmt=8's
+ * two renumbers demonstrate. */
typedef struct {
int fmt; float *qf; int8_t *q8; uint8_t *q4; float *s; int O, I, gs; /* gs=group size (0=per-row, 128=grouped) */
#ifdef COLI_CUDA
@@ -187,7 +194,7 @@ static int64_t qt_bytes(const QT *t){ /* byte residenti del tensore */
return (int64_t)t->O*ng*24 + (int64_t)t->O*ng*4; }
if(t->fmt==6) /* E8/IQ3: 98B per 256 weights, scales in-block, .qs is a 4-byte tag */
return (int64_t)t->O*(((int64_t)t->I+255)/256)*98 + 4;
- if(t->fmt==7){ /* fp8-e4m3 passthrough: O*I raw e4m3 bytes (n, byte-identical layout
+ if(t->fmt==8){ /* fp8-e4m3 passthrough: O*I raw e4m3 bytes (n, byte-identical layout
* to fmt=1's weight bytes) + one f32 scale per 128x128 block
* (FP8_BLOCK in quant.h, included below qt_bytes -- keep the
* arithmetic literal here, same discipline as fmt=5's comment
@@ -209,11 +216,11 @@ static int64_t qt_bytes(const QT *t){ /* byte residenti del tensore */
* scale_b=O*4 at those two call sites -- i.e. assuming PER-ROW scale for every
* format -- is right for fmt 0/1/2/3 but wrong for fmt=4 (grouped,
* O*ceil(I/gs) scales), fmt=5 (int3-g64, O*ceil(I/64) scales), fmt=6 (E8/IQ3,
- * a FIXED 4-byte tag, see below), and fmt=7 (per-128x128-block,
+ * a FIXED 4-byte tag, see below), and fmt=8 (per-128x128-block,
* ceil(O/128)*ceil(I/128) scales): any tensor in one of those four formats
* reaching qt_wire_mmap/qt_unwire_mmap would mlock/munlock the wrong byte
* ranges on BOTH halves (weight_b = qt_bytes(t)-scale_b shifts too). This is
- * not purely a dormant fmt=7-only fix: fmt=4 is the routed-expert
+ * not purely a dormant fmt=8-only fix: fmt=4 is the routed-expert
* "int4-g64" format (qt_resolve_fmt assigns it to ESlot g/u/d the same as
* any other tensor, see expert_load_impl), so any COLI_MMAP +
* mem_should_wire() session pinning fmt=4 experts mlocks the wrong ranges
@@ -221,7 +228,7 @@ static int64_t qt_bytes(const QT *t){ /* byte residenti del tensore */
* arithmetic fix only, see the report).
*
* REVIEW FINDING (maintainer, #528): this function existed correctly (the
- * fmt=7 branch below is right) but neither qt_wire_mmap nor qt_unwire_mmap
+ * fmt=8 branch below is right) but neither qt_wire_mmap nor qt_unwire_mmap
* actually called it -- both independently hardcoded scale_b=(int64_t)t->O*4
* inline, so the "fix" this comment describes was never applied at either
* call site, and the resulting -Wunused-function warning on this then-dead
@@ -252,14 +259,14 @@ static int64_t qt_bytes(const QT *t){ /* byte residenti del tensore */
* which already treat fmt=6's scale as exactly 1 float, not O floats), then
* mlock/munlock'd that many bytes starting at t->s -- past the end of a
* 4-byte allocation. UNVERIFIED at runtime (same static/arithmetic-only
- * caveat as the fmt=4/5/7 fix above -- no model run performed). */
+ * caveat as the fmt=4/5/8 fix above -- no model run performed). */
static int64_t qt_scale_bytes(const QT *t){
if(t->fmt==4){ int ng=(t->I+t->gs-1)/t->gs; return (int64_t)t->O*ng*4; }
if(t->fmt==5){ int64_t ng=((int64_t)t->I+63)/64; return (int64_t)t->O*ng*4; }
if(t->fmt==6) return 4; /* E8/IQ3: FIXED 4-byte tag (qsalloc(1)), not O*4 -- see this
* function's own header comment for why this is reachable and
* load-bearing, not dead code. */
- if(t->fmt==7){ int64_t nblkO=((int64_t)t->O+127)/128, nblkI=((int64_t)t->I+127)/128; return nblkO*nblkI*4; }
+ if(t->fmt==8){ int64_t nblkO=((int64_t)t->O+127)/128, nblkI=((int64_t)t->I+127)/128; return nblkO*nblkI*4; }
return (int64_t)t->O*4; /* fmt 0 (t->s NULL, guarded by callers)/1/2/3: per-row. */
}
/* qt_wire_mmap/qt_unwire_mmap's shared weight/scale byte-range split -- the ONE
@@ -540,11 +547,11 @@ static int vk_matmul_pair_qt(QT *a, float *ya, QT *b, float *yb, const float *x,
static int qt_cuda_upload(QT *t){
if(t->fmt==5) return 0; /* int3-g64: no CUDA kernel yet β€” tensor stays CPU-side */
if(t->fmt==6 && !g_cuda_e8_ready) return 0; /* E8 without its codebook would decode garbage */
- if(t->fmt==7) return 0; /* fp8-e4m3 passthrough: no CUDA kernel yet either (matches the
+ if(t->fmt==8) return 0; /* fp8-e4m3 passthrough: no CUDA kernel yet either (matches the
* fmt=5/6 idiom above; matmul_qt_ex's own caller-side fmt exclusion
* already keeps this from being reached with cuda_eligible tensors
* in the exact-kernel path, but row_bytes()/weight_at() in
- * backend_cuda.cu have no fmt=7 case either -- explicit early-
+ * backend_cuda.cu have no fmt=8 case either -- explicit early-
* return here so a future caller doesn't have to rediscover that by
* tracing through to the CUDA source. UNVERIFIED at runtime: no CUDA
* toolchain on this macOS build host to compile-check. */
@@ -825,7 +832,7 @@ static void matmul_i4_grouped_pair(float *yg, float *yu, const float *x,
* (~+12% perplexity), measured. Every other prefill matmul keeps IDOT as before. */
static void matmul_qt_ex(float *y, const float *x, QT *w, int S, int allow_idot){
#ifdef COLI_METAL
- /* fmt=7 (fp8 passthrough) deliberately absent from this allowlist, same as fmt=5/6:
+ /* fmt=8 (fp8 passthrough) deliberately absent from this allowlist, same as fmt=5/6:
* the S>=g_metal_gemm_min batched prefill GEMM path (coli_metal_gemm) only knows
* fmt 1/2/4 in this build, so it fails CLOSED to the CPU branch below (matmul_fp8)
* rather than being silently misread. coli_metal_gemm() also carries its own
@@ -836,7 +843,7 @@ static void matmul_qt_ex(float *y, const float *x, QT *w, int S, int allow_idot)
}
#endif
#ifdef COLI_CUDA
- /* fmt=7 excluded exactly like fmt=5/6: the CUDA backend's row_bytes()/weight_at()
+ /* fmt=8 excluded exactly like fmt=5/6: the CUDA backend's row_bytes()/weight_at()
* (backend_cuda.cu) have no case for it and fall through to `return 0` / undefined
* weight_at() behavior. row_bytes()==0 already makes coli_cuda_tensor_upload_g
* refuse (defensive fail-closed), but that path is reached only after paying an
@@ -844,7 +851,7 @@ static void matmul_qt_ex(float *y, const float *x, QT *w, int S, int allow_idot)
* excluding it here up front is the same fmt=5/6 idiom, silent and immediate.
* UNVERIFIED on this build (no CUDA toolchain on macOS to compile-check; traced
* from backend_cuda.cu source only). */
- if(g_cuda_enabled && w->cuda_eligible && !w->cuda_failed && w->fmt!=5 && w->fmt!=7 && !omp_in_parallel()){
+ if(g_cuda_enabled && w->cuda_eligible && !w->cuda_failed && w->fmt!=5 && w->fmt!=8 && !omp_in_parallel()){
const void *weights = w->fmt==0 ? (const void*)w->qf
: w->fmt==1 ? (const void*)w->q8 : (const void*)w->q4;
if(coli_cuda_matmul(&w->cuda,y,x,weights,w->s,w->fmt,S,w->I,w->O,w->cuda_device,w->gs)) return;
@@ -870,7 +877,7 @@ static void matmul_qt_ex(float *y, const float *x, QT *w, int S, int allow_idot)
if(w->fmt==1) matmul_q(y,x,w->q8,w->s,S,w->I,w->O);
else if(w->fmt==3) matmul_i2(y,x,w->q4,w->s,S,w->I,w->O);
else if(w->fmt==5) matmul_i3(y,x,w->q4,w->s,S,w->I,w->O);
- else if(w->fmt==7) matmul_fp8(y,x,(const uint8_t*)w->q8,w->s,S,w->I,w->O);
+ else if(w->fmt==8) matmul_fp8(y,x,(const uint8_t*)w->q8,w->s,S,w->I,w->O);
else matmul_i4(y,x,w->q4,w->s,S,w->I,w->O);
}
@@ -1293,7 +1300,7 @@ static int detect_group_size(int O, int I, int64_t ns){
* diventava un int2 valido e il matmul leggeva oltre il buffer (O*I nibble a
* 4/byte). Qui i byte del peso devono corrispondere a un layout noto e i byte
* della scala alla cardinalita' attesa (O per-row, O*ng per-gruppo) β€” altrimenti
- * si termina invece di sforare. Ritorna fmt (1/2/3/4/5/6/7) e scrive *gs.
+ * si termina invece di sforare. Ritorna fmt (1/2/3/4/5/6/8) e scrive *gs.
* No container-level format stamp is consulted here: a self-describing
* __metadata__ stamp that could resolve a genuine byte-collision below
* (instead of refusing it unconditionally) is a follow-up proposal, not
@@ -1318,7 +1325,7 @@ static int qt_resolve_fmt(const char *name, int O, int I, int64_t nb, int64_t ns
* f32 block scales: ns==1*4==4.
* - a FOUR-BLOCK fp8 tensor (fp8_nblk(O)*fp8_nblk(I)==4, e.g. O in
* (384,512] at this I) with UE8M0 (1 byte/block) scales: ns==4*1==4 --
- * the SAME arithmetic collision the fmt=1-vs-fmt=7 landmine below has
+ * the SAME arithmetic collision the fmt=1-vs-fmt=8 landmine below has
* with UE8M0, just against fmt=6's tag instead of fmt=1's per-row
* count; see that landmine's own comment for the general shape.
* - at O==1 specifically, fmt=1's own per-row tag (O*4) is also 4.
@@ -1337,8 +1344,8 @@ static int qt_resolve_fmt(const char *name, int O, int I, int64_t nb, int64_t ns
"(fmt=6, 4-byte tag)%s%s%s; refusing rather than guessing (untrusted "
"container, fmt=6 collision at I=98)\n",
name,O,I,(long long)nb,(long long)ns,
- fp8_blk_f32_also ? " AND per-128x128-block FP8 f32 scales (fmt=7, single block)" : "",
- fp8_blk_ue8m0_also ? " AND per-128x128-block FP8 ue8m0 scales (fmt=7, 4 blocks, recognized-not-implemented)" : "",
+ fp8_blk_f32_also ? " AND per-128x128-block FP8 f32 scales (fmt=8, single block)" : "",
+ fp8_blk_ue8m0_also ? " AND per-128x128-block FP8 ue8m0 scales (fmt=8, 4 blocks, recognized-not-implemented)" : "",
i8_row_also ? " AND plain int8 per-row (fmt=1, O=1)" : "");
exit(1);
}
@@ -1354,10 +1361,10 @@ static int qt_resolve_fmt(const char *name, int O, int I, int64_t nb, int64_t ns
name,(long long)nb,O,I); exit(1); }
*gs=0;
if(fmt==2){ int g=detect_group_size(O,I,ns); if(g>0){ fmt=4; *gs=g; } }
- /* fmt=1 vs fmt=7 (native FP8-e4m3 passthrough): THE DESIGN LANDMINE. Weight
+ /* fmt=1 vs fmt=8 (native FP8-e4m3 passthrough): THE DESIGN LANDMINE. Weight
* bytes are IDENTICAL (O*I raw bytes, both matched exp_i8 above) -- fmt=1
- * and fmt=7 can only be told apart by the SCALE array's geometry: fmt=1 is
- * per-row (ns==O*4 bytes); fmt=7 is per-128x128-BLOCK, ns==ceil(O/128)*
+ * and fmt=8 can only be told apart by the SCALE array's geometry: fmt=1 is
+ * per-row (ns==O*4 bytes); fmt=8 is per-128x128-BLOCK, ns==ceil(O/128)*
* ceil(I/128)*4 bytes for THIS build's implemented f32 scale encoding. For
* most real shapes these two byte counts are distinct and the match is
* unambiguous. But for small O (<=128) and/or small I, ceil(O/128)*
@@ -1381,12 +1388,12 @@ static int qt_resolve_fmt(const char *name, int O, int I, int64_t nb, int64_t ns
* INVERSION: an ambiguous shape resolves to fmt=1 -- the incumbent,
* already-on-disk, decodable format -- instead of refusing. This is sound
* because the WRITER side (tools/repack_fp8_passthrough.py's
- * _check_geometry) now refuses to EMIT an fmt=7 container at any shape
- * satisfying this same collision predicate: no genuine fmt=7 tensor this
+ * _check_geometry) now refuses to EMIT an fmt=8 container at any shape
+ * satisfying this same collision predicate: no genuine fmt=8 tensor this
* engine's own tooling can produce will ever reach this branch, so
- * resolving to fmt=1 here is not a guess against a live fmt=7 candidate --
+ * resolving to fmt=1 here is not a guess against a live fmt=8 candidate --
* it is the only remaining candidate for an UNSTAMPED container. A
- * self-describing __metadata__ stamp that lets a THIRD-PARTY fmt=7
+ * self-describing __metadata__ stamp that lets a THIRD-PARTY fmt=8
* container resolve at this same colliding shape is a separate mechanism
* (see qt_verify_fmt_stamp / the stamped build of this function) -- this
* (unstamped) function has no stamp to consult and always commits to the
@@ -1409,11 +1416,11 @@ static int qt_resolve_fmt(const char *name, int O, int I, int64_t nb, int64_t ns
* wrong candidate) is the whole point -- a future decoder lands into this
* seam rather than a near-duplicate format. Checked for collision against
* every OTHER format's ns arithmetic reachable from this nb==O*I branch
- * (fmt=1 and fmt=7-f32, both above): the byte counts are realistically
+ * (fmt=1 and fmt=8-f32, both above): the byte counts are realistically
* distinct (nblkO*nblkI is orders of magnitude smaller than O*4 for any
* real GLM-sized matrix), but NOT categorically distinct -- the same
- * small-O regime that makes the fmt=1-vs-fmt=7-f32 collision above
- * possible also makes a fmt=1-vs-fmt=7-ue8m0 collision possible (e.g.
+ * small-O regime that makes the fmt=1-vs-fmt=8-f32 collision above
+ * possible also makes a fmt=1-vs-fmt=8-ue8m0 collision possible (e.g.
* O=1, I in (384,512]: nblkO=1, nblkI=4, ue8m0 ns=4=O*4=fmt=1's own
* per-row count) -- handled below by refusing whenever the ue8m0
* signature matches, noting the row collision too when it also applies.
@@ -1443,11 +1450,11 @@ static int qt_resolve_fmt(const char *name, int O, int I, int64_t nb, int64_t ns
is_row ? " -- scale array ALSO matches per-row int8 (fmt=1); refusing either way (untrusted container)" : "");
exit(1);
}
- if(is_blk && !is_row) fmt=7;
+ if(is_blk && !is_row) fmt=8;
}
int64_t exp_scale = (fmt==4)? (int64_t)O*((I+*gs-1)/(*gs))
: (fmt==5)? (int64_t)O*i3_groups(I)
- : (fmt==7)? fp8_nblk(O)*fp8_nblk(I)
+ : (fmt==8)? fp8_nblk(O)*fp8_nblk(I)
: (int64_t)O; /* in FLOAT */
if(ns != exp_scale*4){
fprintf(stderr,"%s: scale array is %lld bytes β€” expected %lld for [%d,%d] fmt=%d, refusing (untrusted container)\n",
@@ -1491,17 +1498,17 @@ static void qt_from_disk(Model *m, const char *name, int O, int I, int bits, int
else if(fmt==6){ /* E8/IQ3: everything in-block, .qs is the 4-byte tag */
if(t->fmt!=6||!t->q4){ t->fmt=6; t->O=O; t->I=I; t->gs=0; t->q4=qalloc(nb); t->s=qsalloc(1); }
st_read_raw(&m->S,name,t->q4,drop); }
- else if(fmt==7){ int64_t nblk=fp8_nblk(O)*fp8_nblk(I); /* fp8-e4m3: raw bytes (q8, like fmt=1)
+ else if(fmt==8){ int64_t nblk=fp8_nblk(O)*fp8_nblk(I); /* fp8-e4m3: raw bytes (q8, like fmt=1)
* + one f32 scale per 128x128 block. BOTH weights and scale via qalloc, not falloc,
* from day one -- the GPU-visibility lesson fmt=4 and fmt=5 each had to learn
* separately (see review round 1 audit history in the report). */
- if(t->fmt!=7||!t->q8){ t->fmt=7; t->O=O; t->I=I; t->gs=0; t->q8=qalloc(nb); t->s=(float*)qalloc((size_t)nblk*sizeof(float)); }
+ if(t->fmt!=8||!t->q8){ t->fmt=8; t->O=O; t->I=I; t->gs=0; t->q8=qalloc(nb); t->s=(float*)qalloc((size_t)nblk*sizeof(float)); }
st_read_raw(&m->S,name,t->q8,drop); }
else { if(t->fmt!=fmt||!t->q4){ t->fmt=fmt; t->O=O; t->I=I; t->gs=0; t->q4=qalloc(nb); t->s=qsalloc(O); } st_read_raw(&m->S,name,t->q4,drop); }
/* cap MUST match the scale cardinality qt_resolve_fmt already validated and
* the falloc above actually reserved, per format: grouped-int4 (fmt=4) keeps
* O*ceil(I/gs) scales, int3-g64 (fmt=5) keeps O*i3_groups(I), E8/IQ3 (fmt=6)
- * keeps the 1-float tag, and fp8-e4m3 (fmt=7) keeps ceil(O/128)*ceil(I/128)
+ * keeps the 1-float tag, and fp8-e4m3 (fmt=8) keeps ceil(O/128)*ceil(I/128)
* block scales; everything else is per-row O. Using the per-row bound for a
* grouped/blocked format would reject a legitimate container (fmt=5 regressed
* exactly that way). */
@@ -1509,7 +1516,7 @@ static void qt_from_disk(Model *m, const char *name, int O, int I, int bits, int
fmt==4 ? (int64_t)O*((I+gs-1)/gs) :
fmt==5 ? (int64_t)O*i3_groups(I) :
fmt==6 ? (int64_t)1 :
- fmt==7 ? fp8_nblk(O)*fp8_nblk(I) : (int64_t)O, drop);
+ fmt==8 ? fp8_nblk(O)*fp8_nblk(I) : (int64_t)O, drop);
} else {
if(!t->qf && !t->q8 && !t->q4) qt_alloc(t,O,I,bits);
if(t->fmt==0) st_read_f32_cap(&m->S,name,t->qf,(int64_t)O*I,drop);
@@ -2653,10 +2660,10 @@ static void qt_addrow(const QT *t, int row, float coef, float *acc){
* a heap OVERREAD, and the untouched fall-through then misreads t->q4's real E8
* lattice bytes as int2-packed data (same bug SHAPE as #298's CUDA absorb-kernel
* fix, and the same one this file's own fmt=4/5 branches above were added to
- * dodge -- fmt=6 was simply missed). fmt=7 (fp8-e4m3-b128): t->s holds
+ * dodge -- fmt=6 was simply missed). fmt=8 (fp8-e4m3-b128): t->s holds
* ceil(O/128)*ceil(I/128) per-block floats, not O -- t->s[row] overreads for
* row>=nblk (e.g. a [130,130] tensor has nblk=4, so every row past 3 already reads
- * out of bounds), AND t->q4 is NULL for fmt=7 (raw bytes live in t->q8 instead,
+ * out of bounds), AND t->q4 is NULL for fmt=8 (raw bytes live in t->q8 instead,
* same convention as fmt=1 -- see the QT struct comment), so the fall-through's
* `t->q4+(int64_t)row*((I+3)/4)` dereferences NULL-plus-offset: SIGSEGV,
* reproduced (see the report's proof-of-bite transcript). Refuse loudly instead --
@@ -2720,8 +2727,8 @@ static void qt_matvec_rows(const QT *t, int r0, int n, const float *x, float *y)
* handles -- fmt 0/4/5 matched above, fmt 1/2 have their own explicit branches
* above too. Same GUARD and same reasoning as qt_addrow's (fix round 2, engine
* defect): fmt=6's t->s is a fixed 4-byte tag (t->s[row] overreads for row>0),
- * fmt=7's t->s holds per-128x128-block floats (t->s[row] overreads for
- * row>=nblk) and t->q4 is NULL for fmt=7 -- both would have silently misread or
+ * fmt=8's t->s holds per-128x128-block floats (t->s[row] overreads for
+ * row>=nblk) and t->q4 is NULL for fmt=8 -- both would have silently misread or
* crashed here exactly like qt_addrow did before its own fix; refuse instead. */
else if(t->fmt==3){ const uint8_t *w=t->q4+(int64_t)row*((I+3)/4); float s=t->s[row]; float acc=0;
for(int i=0;i<I;i++){ uint8_t b=w[i>>2]; acc+=((int)((b>>((i&3)*2))&3)-2)*x[i]; } a=acc*s; }
@@ -2939,16 +2946,16 @@ static void attention_rows(Model *m, Layer *l, int layer, float *x, int S, int p
* would rope every row at position 0 and attend over a 1-token window of the wrong
* cache -> greedy decode hits EOS at token 2 (mux answers truncated to 1 token).
* Ragged rows take the CPU absorb path below, which reads kvs[s]/positions[s].
- * fmt!=7 guards (q_a/q_b/kv_a/o): STALE-COMMENT FIX -- this PR's own mm_gemv
- * Metal shader (backend_metal.mm) DOES have a real fmt==7 branch (fp8-e4m3
+ * fmt!=8 guards (q_a/q_b/kv_a/o): STALE-COMMENT FIX -- this PR's own mm_gemv
+ * Metal shader (backend_metal.mm) DOES have a real fmt==8 branch (fp8-e4m3
* decode + per-128x128-block scale); the shader is not the gap. The actual
* blocker is the WP_() macro two lines below: it picks q8 only for fmt==1,
- * else q4 -- and q4 is NULL/unallocated for fmt=7 (same convention as fmt=1,
- * see the QT struct comment), so an fmt=7 tensor reaching
+ * else q4 -- and q4 is NULL/unallocated for fmt=8 (same convention as fmt=1,
+ * see the QT struct comment), so an fmt=8 tensor reaching
* coli_metal_attn_decode would hand the kernel a NULL weight pointer, not a
* misread-as-f32 shader. Fail closed to the CPU path below instead
- * (matmul_qt_ex there dispatches fmt=7 correctly via matmul_fp8); fixing
- * WP_() and actually wiring fmt=7 through bind_gemv/coli_metal_attn_decode is
+ * (matmul_qt_ex there dispatches fmt=8 correctly via matmul_fp8); fixing
+ * WP_() and actually wiring fmt=8 through bind_gemv/coli_metal_attn_decode is
* a deferred follow-up (see this PR's GPU-path note), not done in this
* round. kv_b is already pinned to fmt==2 above for an unrelated reason (its
* absorb kernel is int4-only); these four checks are the same discipline
@@ -2956,7 +2963,7 @@ static void attention_rows(Model *m, Layer *l, int layer, float *x, int S, int p
if(g_metal_enabled && !kvs && S<=4 && (g_absorb==1||(g_absorb<0&&S<=4)) && m->kv_start[layer]==0
&& D==6144 && H==64 && c->q_lora==2048 && c->kv_lora==512 && c->qk_nope==192
&& c->qk_rope==64 && vh==256 && l->kv_b.fmt==2
- && l->q_a.fmt!=7 && l->q_b.fmt!=7 && l->kv_a.fmt!=7 && l->o.fmt!=7){
+ && l->q_a.fmt!=8 && l->q_b.fmt!=8 && l->kv_a.fmt!=8 && l->o.fmt!=8){
int sel_active = m->has_dsa && layer<c->n_layers && c->idx_type[layer] && (pos_base+S) > c->index_topk;
if(!sel_active){
if(m->has_dsa && layer<c->n_layers && c->idx_type[layer]){ /* index keys for future selection */
@@ -5162,23 +5169,23 @@ static void layer_forward_rows(Model *m, Layer *l, int li, float *x, int S, int
* Fallback: qualsiasi condizione mancante -> percorso CPU intero qui sotto.
* !kvs: ragged mux rows (per-row KV/position) are not expressible in this kernel's
* single Lc/Rc + pos_base contract β€” see the matching guard in attention_rows.
- * fmt!=7 guards (q_a/q_b/kv_a/o/sh_gate/sh_up/sh_down): same fail-closed discipline
+ * fmt!=8 guards (q_a/q_b/kv_a/o/sh_gate/sh_up/sh_down): same fail-closed discipline
* as attention_rows, extended to the shared-expert MLP this fused kernel also
* covers. STALE-COMMENT FIX -- the mm_gemv shader these bind_gemv calls dispatch
- * through DOES have a real fmt==7 branch (this PR's own Metal kernel commit); the
+ * through DOES have a real fmt==8 branch (this PR's own Metal kernel commit); the
* actual gap is the WP_() macro below, which picks q8 only for fmt==1 and q4
- * (NULL/unallocated for fmt=7) otherwise, so none of these seven bind_gemv-routed
- * tensors can safely carry fmt=7 through this fused path yet -- CPU below
- * dispatches fmt=7 correctly via matmul_qt_ex/matmul_fp8. Fixing WP_() and wiring
- * fmt=7 through bind_gemv is the same deferred follow-up noted in attention_rows,
+ * (NULL/unallocated for fmt=8) otherwise, so none of these seven bind_gemv-routed
+ * tensors can safely carry fmt=8 through this fused path yet -- CPU below
+ * dispatches fmt=8 correctly via matmul_qt_ex/matmul_fp8. Fixing WP_() and wiring
+ * fmt=8 through bind_gemv is the same deferred follow-up noted in attention_rows,
* not done in this round. */
if(g_metal_enabled && !kvs && S<=4 && li<c->n_layers && l->sparse
&& (g_absorb==1||(g_absorb<0&&S<=4)) && m->kv_start[li]==0
&& D==6144 && c->n_heads==64 && c->q_lora==2048 && c->kv_lora==512
&& c->qk_nope==192 && c->qk_rope==64 && c->v_head==256 && l->kv_b.fmt==2
&& c->n_experts==256 && c->topk==8 && c->n_shared==1 && c->moe_inter==2048
- && l->q_a.fmt!=7 && l->q_b.fmt!=7 && l->kv_a.fmt!=7 && l->o.fmt!=7
- && l->sh_gate.fmt!=7 && l->sh_up.fmt!=7 && l->sh_down.fmt!=7){
+ && l->q_a.fmt!=8 && l->q_b.fmt!=8 && l->kv_a.fmt!=8 && l->o.fmt!=8
+ && l->sh_gate.fmt!=8 && l->sh_up.fmt!=8 && l->sh_down.fmt!=8){
int sel_active = m->has_dsa && c->idx_type[li] && (pos_base+S) > c->index_topk;
if(!sel_active){
static float *linrm,*lnrm,*lsh,*lw; static int *lidx,*lkeff;
diff --git a/c/quant.h b/c/quant.h
index 7dbf3936..d30ecbc6 100644
--- a/c/quant.h
+++ b/c/quant.h
@@ -402,17 +402,20 @@ static void matmul_i3(float *y, const float *x, const uint8_t *q3, const float *
}
}
-/* ---- fmt=7: native FP8-e4m3 passthrough (Z.ai GLM-5.2-FP8 read path) ------
- * PUBLIC ordinal, assigned by the maintainer on #524. This format was minted
- * fmt=6 during original development, then re-tagged fmt=100 (PRIVATE ORDINAL
- * BLOCK, see colibri.c's QT struct comment) after #465 (E8/IQ3, above) claimed
- * ordinal 6 upstream out from under it; fmt=7 is the number it graduated to at
- * merge, per the private-block convention's own "find-and-replace, zero
- * on-disk impact" promise. See qt_resolve_fmt in colibri.c ("THE DESIGN
+/* ---- fmt=8: native FP8-e4m3 passthrough (Z.ai GLM-5.2-FP8 read path) ------
+ * PUBLIC ordinal. This format was minted fmt=6 during original development,
+ * then re-tagged fmt=100 (PRIVATE ORDINAL BLOCK, see colibri.c's QT struct
+ * comment) after #465 (E8/IQ3, above) claimed ordinal 6 upstream out from
+ * under it; graduated to fmt=7 when the maintainer assigned that ordinal on
+ * #524; renumbered a second time to fmt=8 after #705 merged into dev claiming
+ * fmt=7 for MXFP4 (Kimi K3 Vulkan tier, backend_vulkan.c) while this PR was
+ * still open. Both renumbers were pure retags, per the private-block
+ * convention's own "find-and-replace, zero on-disk impact" promise: nothing
+ * on disk carries the ordinal. See qt_resolve_fmt in colibri.c ("THE DESIGN
* LANDMINE") for the disambiguation this needs against BOTH fmt=1 (int8) and
* fmt=6 (E8/IQ3).
*
- * fmt=7 weight bytes are O*I raw e4m3 bytes -- byte-identical to int8 (fmt=1).
+ * fmt=8 weight bytes are O*I raw e4m3 bytes -- byte-identical to int8 (fmt=1).
* What makes this a DIFFERENT format is the scale: one f32 per 128x128 BLOCK of
* the [O,I] weight matrix (shape [ceil(O/128),ceil(I/128)]), not one f32 per
* output row. Dequant is w[o,i] = e4m3_decode(byte) * scale[o/128, i/128]
@@ -438,7 +441,7 @@ static void matmul_i3(float *y, const float *x, const uint8_t *q3, const float *
* exactly like any other source of a NaN weight (fmt=0/f32 tensors are never
* scrubbed either). The engine already has a dedicated, TESTED safety net for
* NaN reaching the sampler (argmax_v/dist_build, see tests/test_logit_nan.c:
- * "degrade + diagnose, never silently corrupt") -- fmt=7 relies on that existing
+ * "degrade + diagnose, never silently corrupt") -- fmt=8 relies on that existing
* downstream net rather than adding a second, redundant weight-level scrub. */
static const float E4M3_LUT[256] = {
0x0.0p+0f,0x1.0000000000000p-9f,0x1.0000000000000p-8f,0x1.8000000000000p-8f,0x1.0000000000000p-7f,0x1.4000000000000p-7f,0x1.8000000000000p-7f,0x1.c000000000000p-7f,
diff --git a/c/tests/test_backend_metal.mm b/c/tests/test_backend_metal.mm
index 59c0f0cf..fbad5647 100644
--- a/c/tests/test_backend_metal.mm
+++ b/c/tests/test_backend_metal.mm
@@ -10,7 +10,7 @@
#include <cmath>
#include <vector>
-enum { F32=0, I8=1, I4=2, I2=3, I4G=4, FP8=7 };
+enum { F32=0, I8=1, I4=2, I2=3, I4G=4, FP8=8 };
static void cpu_ref(int fmt, const void *W, const float *s, const float *x,
float *y, int S, int I, int O) {
@@ -80,12 +80,12 @@ static void cpu_ref_grouped(const uint8_t *q4, const float *scale, const float *
}
}
-// ---- fmt=7 (native FP8-e4m3 passthrough -- see colibri.c): own CPU reference +
+// ---- fmt=8 (native FP8-e4m3 passthrough -- see colibri.c): own CPU reference +
// harness --------------------------------------------------------------------------
// Independent reference decode (bit manipulation, NOT quant.h's E4M3_LUT -- this file
// stays self-contained like the rest of its CPU references) for OCP E4M3-FN: exp==0 is
// subnormal, exp==0xF&&mant==0x7 is the only NaN code (both signs), else normal with
-// bias 7. Must match quant.h's e4m3_decode AND the mm_gemv fmt==7 branch's in-kernel
+// bias 7. Must match quant.h's e4m3_decode AND the mm_gemv fmt==8 branch's in-kernel
// bit manipulation exactly -- see run_fp8_lut() below for the exhaustive 256-code check
// that proves the GPU kernel agrees with this reference (and by transitivity with the
// CPU LUT, which was cross-checked byte-for-byte against torch.float8_e4m3fn offline).
@@ -231,7 +231,7 @@ static int run_fp8_lut(const char *name) {
}
// Confirms the documented "GEMM path optional this build" claim is actually true, not
-// just asserted in a comment: coli_metal_gemm must refuse fmt=7 (return 0, the CPU-
+// just asserted in a comment: coli_metal_gemm must refuse fmt=8 (return 0, the CPU-
// fallback signal) so matmul_qt_ex's caller-side allowlist exclusion is backed by a
// second, independent gate inside the Metal backend itself.
static int run_fp8_gemm_gate(const char *name) {
@@ -242,20 +242,20 @@ static int run_fp8_gemm_gate(const char *name) {
return ok?0:1;
}
-// colibri.c's moe() has a THIRD fmt=7-adjacent Metal entry point besides the two
+// colibri.c's moe() has a THIRD fmt=8-adjacent Metal entry point besides the two
// guarded above (bind_gemv's attn/layer-decode shaders and coli_metal_gemm) -- the
// batched routed-expert dispatch via coli_metal_moe_block[_begin] (colibri.c's
// MB_BUILD macro). MB_BUILD's own pointer-selection ternary does NOT special-case
-// fmt=7: if a layer's shared expert is fmt=7 and MB_BUILD's TRY_SH path picks it
+// fmt=8: if a layer's shared expert is fmt=8 and MB_BUILD's TRY_SH path picks it
// up with no routed expert already fixing `mfmt`, it would submit the WRONG pointer
-// (q4, NULL/stale for an fmt=7 tensor whose weights live in q8) tagged as fmt=7.
+// (q4, NULL/stale for an fmt=8 tensor whose weights live in q8) tagged as fmt=8.
// This is safe ANYWAY, but only incidentally: moe_submit() (backend_metal.mm) gates
// `fmt != 1 && fmt != 2` as its very FIRST statement, before any of g/u/d/gs/us/ds is
-// dereferenced or even resolve()'d -- so an fmt=7 submission is refused before the
+// dereferenced or even resolve()'d -- so an fmt=8 submission is refused before the
// bad pointer would ever be read, no matter what garbage MB_BUILD packed into it. This
// test uses deliberately-invalid weight/scale pointers (never dereferenced if the gate
// holds) to prove the fence BY TEST rather than leaving it an artifact of moe_submit's
-// fmt allowlist happening not to include 7 (yet) -- same discipline
+// fmt allowlist happening not to include 8 (yet) -- same discipline
// run_fp8_gemm_gate above applies to coli_metal_gemm's analogous exclusion.
static int run_fp8_moe_gate(const char *name) {
const void *bad = (const void*)(uintptr_t)0xdeadbeef; // must NEVER be dereferenced
@@ -599,7 +599,7 @@ int main(void) {
// tail-clipping regime grouped scales exist for), verified end-to-end through the GPU.
fail |= run_grouped(5, 512, 64,3,1, "grouped I=512(mult64) outlier-heavy S=3");
fail |= run_grouped(5, 201, 64,2,1, "grouped I=201(non-mult-64) outlier-heavy S=2");
- printf("Metal fmt=7 native FP8-e4m3 passthrough tests:\n");
+ printf("Metal fmt=8 native FP8-e4m3 passthrough tests:\n");
fail |= run_fp8_lut("fp8 LUT exactness (256/256 codes via GPU kernel)");
fail |= run_fp8(2048,6144,1, "fp8 gate/up-shaped O=2048 I=6144 (spec example) S=1");
fail |= run_fp8(6144,2048,1, "fp8 down-shaped O=6144 I=2048 S=1");
@@ -614,7 +614,7 @@ int main(void) {
// scale and this shape/scale choice makes that numerically loud.
fail |= run_fp8(384, 6144, 3, "fp8 non-square block grid nblkO=3 nblkI=48 (stride audit)");
fail |= run_fp8_gemm_gate("fp8 GEMM entry explicitly gated off (coli_metal_gemm refuses)");
- fail |= run_fp8_moe_gate("fp8 MB_BUILD/moe_submit entry gated off (shared-expert fmt=7 hazard)");
+ fail |= run_fp8_moe_gate("fp8 MB_BUILD/moe_submit entry gated off (shared-expert fmt=8 hazard)");
printf("Metal batched moe_block tests:\n");
fail |= run_moe({1,1,1,1,1,1,1,1}, "moe decode nb=8");
fail |= run_moe({3,1,4,2,1,5}, "moe ragged nb=6");
diff --git a/c/tests/test_fp8_e2e_loader.c b/c/tests/test_fp8_e2e_loader.c
index c2ee9884..0c847877 100644
--- a/c/tests/test_fp8_e2e_loader.c
+++ b/c/tests/test_fp8_e2e_loader.c
@@ -15,7 +15,7 @@
* Usage: test_fp8_e2e_loader <container_dir> [name O I]...
* For every (name,O,I) triple, calls the REAL qt_from_disk (the identical
* function every model load uses) and asserts:
- * (a) fmt==7 resolved (native fp8-e4m3-passthrough, via byte-arithmetic
+ * (a) fmt==8 resolved (native fp8-e4m3-passthrough, via byte-arithmetic
* inference alone -- this PR's repack tool writes no container
* metadata stamp, see repack_fp8_passthrough.py's module docstring);
* (b) the weight (q8) and scale (s) buffers are non-NULL;
@@ -53,12 +53,12 @@ int main(int argc, char **argv){
QT t; memset(&t,0,sizeof t);
qt_from_disk(&gm, name, O, I, 8, 0, &t); /* THE REAL LOADER PATH -- not mocked */
- if(t.fmt != 7){
- printf("FAIL %s: fmt=%d, expected 7 (native fp8-e4m3 passthrough)\n", name, t.fmt);
+ if(t.fmt != 8){
+ printf("FAIL %s: fmt=%d, expected 8 (native fp8-e4m3 passthrough)\n", name, t.fmt);
fails++; continue;
}
if(!t.q8 || !t.s){
- printf("FAIL %s: fmt=7 but q8=%p s=%p (expected both non-NULL)\n",
+ printf("FAIL %s: fmt=8 but q8=%p s=%p (expected both non-NULL)\n",
name, (void*)t.q8, (void*)t.s);
fails++; continue;
}
@@ -77,7 +77,7 @@ int main(int argc, char **argv){
printf("FAIL %s: non-finite dequantized value at flat index %lld\n", name, (long long)bad);
fails++; continue;
}
- printf("ok %s: fmt=7 O=%d I=%d, weights+scale loaded through the real loader, all-finite\n",
+ printf("ok %s: fmt=8 O=%d I=%d, weights+scale loaded through the real loader, all-finite\n",
name, O, I);
}
if(fails){ printf("fp8 e2e repack->load: %d/%d tensor(s) FAILED\n", fails, ntensors); return 1; }
diff --git a/c/tests/test_fp8_e2e_repack_load.py b/c/tests/test_fp8_e2e_repack_load.py
index 4cd5e8e5..024c13a0 100644
--- a/c/tests/test_fp8_e2e_repack_load.py
+++ b/c/tests/test_fp8_e2e_repack_load.py
@@ -18,7 +18,7 @@ test does, end to end:
Makefile's own CFLAGS, asserted to produce zero warnings -- into a
temp binary;
4. run that binary against the REAL repacked output directory, asserting
- every selected tensor loads fmt=7 through the real qt_from_disk with
+ every selected tensor loads fmt=8 through the real qt_from_disk with
finite dequantized values (byte-arithmetic inference alone -- this PR's
repack tool writes no container metadata stamp).
diff --git a/c/tests/test_fp8_load.c b/c/tests/test_fp8_load.c
index b57d9d1a..85878ed1 100644
--- a/c/tests/test_fp8_load.c
+++ b/c/tests/test_fp8_load.c
@@ -1,18 +1,19 @@
-/* fmt=7 (native FP8-e4m3 passthrough) loader-seam tests.
+/* fmt=8 (native FP8-e4m3 passthrough) loader-seam tests.
*
- * fmt=7, PUBLIC ordinal assigned by the maintainer on #524: this format was
- * minted fmt=6 during original development of this branch, before dev's own
- * #465 (E8/IQ3) claimed that ordinal upstream and merged it into dev as a
- * REAL fmt=6 (see quant.h's E8 constants and e8_ helper functions, and
- * qt_resolve_fmt's ns==4-tag early check); re-tagged fmt=100 (PRIVATE ORDINAL
- * BLOCK, see colibri.c's QT struct comment) from that point forward -- there
- * was never a build in this branch's history where this format was reachable
- * as fmt=6 -- and graduated to fmt=7 at merge.
+ * fmt=8, PUBLIC ordinal: this format was minted fmt=6 during original
+ * development of this branch, before dev's own #465 (E8/IQ3) claimed that
+ * ordinal upstream and merged it into dev as a REAL fmt=6 (see quant.h's E8
+ * constants and e8_ helper functions, and qt_resolve_fmt's ns==4-tag early
+ * check); re-tagged fmt=100 (PRIVATE ORDINAL BLOCK, see colibri.c's QT struct
+ * comment) from that point forward -- there was never a build in this branch's
+ * history where this format was reachable as fmt=6 -- graduated to fmt=7 when
+ * the maintainer assigned that ordinal on #524, and renumbered to fmt=8 after
+ * #705 merged claiming 7 for MXFP4 (see colibri.c's QT comment).
*
- * Part A: qt_resolve_fmt disambiguation suite -- THE DESIGN LANDMINE. fmt=7
+ * Part A: qt_resolve_fmt disambiguation suite -- THE DESIGN LANDMINE. fmt=8
* weight bytes are byte-identical to fmt=1 (int8): both are O*I raw bytes.
* The two are told apart ONLY by the scale array's byte count (per-row O*4 for
- * fmt=1, per-128x128-block ceil(O/128)*ceil(I/128)*4 for fmt=7, THIS build's
+ * fmt=1, per-128x128-block ceil(O/128)*ceil(I/128)*4 for fmt=8, THIS build's
* implemented f32 scale encoding). For some shapes those two counts coincide
* exactly -- INVERSION (maintainer review, #528): qt_resolve_fmt used to
* REFUSE (exit(1)) this ambiguous case; it now resolves to fmt=1 (the
@@ -20,8 +21,8 @@
* collision is not hypothetical (GLM-5.2's own self_attn.o_proj.weight hits
* it, see qt_resolve_fmt's own "REVIEW FINDING"/"INVERSION" comment) and the
* writer side (repack_fp8_passthrough.py's _check_geometry) now refuses to
- * ever EMIT an fmt=7 container at this same shape, so an unstamped ambiguous
- * tensor reaching this function is never a genuine fmt=7 candidate. The
+ * ever EMIT an fmt=8 container at this same shape, so an unstamped ambiguous
+ * tensor reaching this function is never a genuine fmt=8 candidate. The
* former refusal-testing convention (fork()+waitpid(), mirroring
* tests/test_st_pread.c's exit(1)-path idiom) is kept for the OTHER
* refusing cases below (Part A2's fmt=6 collision, Part A3's UE8M0
@@ -29,11 +30,11 @@
* refusal) -- only the is_row&&is_blk collision in this Part flipped from
* expect_refuse to expect_fmt(...,1,...).
*
- * Part A2: fmt=6 (E8/IQ3, upstream #465) vs fmt=7 collision at [O<=128 or
+ * Part A2: fmt=6 (E8/IQ3, upstream #465) vs fmt=8 collision at [O<=128 or
* O in a 128-block-count range, I=98] -- SECOND DESIGN LANDMINE. Unchanged by
* the #528 inversion above (a different collision predicate, still refused).
*
- * Part A3: fmt=7's scale ENCODING is a declared property, not a hardcoded
+ * Part A3: fmt=8's scale ENCODING is a declared property, not a hardcoded
* constant -- f32 (Part A/A2 above) is what this build implements. A UE8M0
* (1 byte/block) encoding is a REAL, distinct byte signature (the DeepSeek-V4
* checkpoint format for this identical weight geometry) this build recognizes
@@ -42,13 +43,13 @@
* doesn't have -- see qt_resolve_fmt's own comment).
*
* Part B: qt_from_disk loader-seam -- writes a real single-shard .safetensors
- * file containing an fmt=7 tensor (U8 weight + per-block F32 .qs) next to an
+ * file containing an fmt=8 tensor (U8 weight + per-block F32 .qs) next to an
* int8 control tensor of a DIFFERENT, non-colliding shape, loads both through
- * qt_from_disk, and checks the byte-count/.qs-size inference picks fmt=7 vs
+ * qt_from_disk, and checks the byte-count/.qs-size inference picks fmt=8 vs
* fmt=1 correctly and the loaded weights dequantize identically to a reference.
* Mirrors tests/test_int3_load.c's structure for fmt=5.
*
- * Part C: qt_bytes()/qt_scale_bytes() byte-accounting for fmt=7, plus
+ * Part C: qt_bytes()/qt_scale_bytes() byte-accounting for fmt=8, plus
* qt_wire_split() -- the shared weight/scale byte-range split qt_wire_mmap
* and qt_unwire_mmap both now call (maintainer review, #528: qt_scale_bytes()
* existed correctly but neither call site actually used it, a defect only
@@ -212,8 +213,8 @@ static void test_disambiguation(void){
/* --- non-degenerate golden paths (unambiguous either way) --- */
CHECK(expect_fmt(4096,4096,(int64_t)4096*4096,4096*4,1,"plain int8 4096x4096"));
/* spec's own worked example: [2048,6144] expert -> block scale [16,48] */
- CHECK(expect_fmt(2048,6144,(int64_t)2048*6144,16LL*48*4,7,"fp8 2048x6144 (spec example)"));
- CHECK(expect_fmt(384,6144,(int64_t)384*6144,3LL*48*4,7,"fp8 384x6144 non-square block grid"));
+ CHECK(expect_fmt(2048,6144,(int64_t)2048*6144,16LL*48*4,8,"fp8 2048x6144 (spec example)"));
+ CHECK(expect_fmt(384,6144,(int64_t)384*6144,3LL*48*4,8,"fp8 384x6144 non-square block grid"));
/* --- REGRESSION (maintainer review, #528): GLM-5.2's own
* self_attn.o_proj.weight, [D,H*v_head]=[6144,16384]. nblkO=ceil(6144/128)=48,
@@ -259,17 +260,17 @@ static void test_disambiguation(void){
/* --- boundary-ADJACENT non-degenerate cases: one step past each
* degenerate case above, both interpretations now legitimately resolve. --- */
CHECK(expect_fmt(1,129, 129, 4, 1, "adjacent O=1 I=129 as fmt=1 (ns=row)"));
- CHECK(expect_fmt(1,129, 129, 8, 7, "adjacent O=1 I=129 as fmt=7 (ns=block, nblkI=2)"));
+ CHECK(expect_fmt(1,129, 129, 8, 8, "adjacent O=1 I=129 as fmt=8 (ns=block, nblkI=2)"));
CHECK(expect_fmt(2,257, 2LL*257, 8, 1, "adjacent O=2 I=257 as fmt=1 (ns=row)"));
- CHECK(expect_fmt(2,257, 2LL*257, 12, 7, "adjacent O=2 I=257 as fmt=7 (ns=block, nblkI=3)"));
+ CHECK(expect_fmt(2,257, 2LL*257, 12, 8, "adjacent O=2 I=257 as fmt=8 (ns=block, nblkI=3)"));
/* --- neither interpretation matches: garbage .qs size, must still refuse
- * (the pre-existing generic-mismatch path, exercised through the fmt=7-aware
+ * (the pre-existing generic-mismatch path, exercised through the fmt=8-aware
* function to confirm the new code didn't disturb it). --- */
CHECK(expect_refuse(10,10, 100, 999, "garbage ns matches neither row nor block layout"));
}
-/* ---- Part A2: fmt=6 (E8/IQ3, upstream #465, merged into dev) vs fmt=7
+/* ---- Part A2: fmt=6 (E8/IQ3, upstream #465, merged into dev) vs fmt=8
* (this branch's fp8-e4m3-b128) collision -- SECOND DESIGN LANDMINE, see the
* derivation in qt_resolve_fmt's own comment. e8_rowbytes(I) is the constant
* 98 for every I in (0,256], so dev's fmt=6 tag check (ns==4 &&
@@ -280,31 +281,31 @@ static void test_disambiguation(void){
* same as the E8 tag. An unstamped [I=98] fp8-e4m3-b128 tensor at either of
* those shapes is therefore byte-for-byte indistinguishable from a genuine
* fmt=6 tensor: nb AND ns both coincide, not just ns (contrast the fmt=1/
- * fmt=7 collision in Part A, where only ns ever coincides). O==1 stacks a
+ * fmt=8 collision in Part A, where only ns ever coincides). O==1 stacks a
* THIRD candidate: fmt=1's per-row ns (O*4) is also 4 there. This build has
* no stamp to resolve any of these -- every one refuses. */
static void test_fmt6_fp8_collision(void){
- /* O=64, I=98: nblkO=nblkI=1 (fmt=7, single block, f32 scales) -> ns=4;
+ /* O=64, I=98: nblkO=nblkI=1 (fmt=8, single block, f32 scales) -> ns=4;
* e8_blocks(98)=1 -> nb=O*98=6272 for BOTH interpretations, and fmt=6's
* .qs tag is always exactly one f32 -> ns=4 too. Must refuse. */
int64_t nb64=(int64_t)64*98;
- CHECK(expect_refuse(64,98, nb64, 4, "fmt=6/fmt=7(f32) collision O=64 I=98"));
- /* boundary O=128 variant: still nblkO=1 for fmt=7 (128<=128), same collision. */
+ CHECK(expect_refuse(64,98, nb64, 4, "fmt=6/fmt=8(f32) collision O=64 I=98"));
+ /* boundary O=128 variant: still nblkO=1 for fmt=8 (128<=128), same collision. */
int64_t nb128=(int64_t)128*98;
- CHECK(expect_refuse(128,98, nb128, 4, "fmt=6/fmt=7(f32) collision O=128 I=98"));
+ CHECK(expect_refuse(128,98, nb128, 4, "fmt=6/fmt=8(f32) collision O=128 I=98"));
/* O=1, I=98: a THIRD candidate stacks on (fmt=1 plain int8 per-row, ns==O*4==4
* too) -- a genuine three-way ambiguity. Must refuse. */
int64_t nb1=(int64_t)1*98;
- CHECK(expect_refuse(1,98, nb1, 4, "fmt=1/fmt=6/fmt=7(f32) THREE-way collision O=1 I=98"));
+ CHECK(expect_refuse(1,98, nb1, 4, "fmt=1/fmt=6/fmt=8(f32) THREE-way collision O=1 I=98"));
- /* O in (384,512], I=98: nblkO=4, nblkI=1, product=4 -- a fmt=7 tensor with
+ /* O in (384,512], I=98: nblkO=4, nblkI=1, product=4 -- a fmt=8 tensor with
* UE8M0 (1 byte/block) scales also lands at ns==4*1==4 here, the SAME tag
* fmt=6 uses. Must refuse (and, since this build doesn't implement ue8m0
* decode at all, would refuse on that basis alone even without the fmt=6
* collision -- this case exercises the OUTER fmt=6 guard specifically). */
int64_t nb400=(int64_t)400*98;
- CHECK(expect_refuse(400,98, nb400, 4, "fmt=6/fmt=7(ue8m0, 4-block) collision O=400 I=98"));
+ CHECK(expect_refuse(400,98, nb400, 4, "fmt=6/fmt=8(ue8m0, 4-block) collision O=400 I=98"));
/* regression guard: a GENUINE (non-colliding) fmt=6 fixture -- I!=98, so
* e8_rowbytes(I)==98 does NOT equal O*I -- must keep resolving to fmt=6.
@@ -317,10 +318,10 @@ static void test_fmt6_fp8_collision(void){
"genuine fmt=6 (non-colliding) O=64 I=256 (I!=98, no collision) -> fmt=6"));
}
-/* ---- Part A3: fmt=7's scale ENCODING is a declared property -- UE8M0
+/* ---- Part A3: fmt=8's scale ENCODING is a declared property -- UE8M0
* recognized, refused by name (not implemented in this build). ---- */
static void test_ue8m0_scale_refusal(void){
- /* [2048,6144] (spec example shape, same as Part A's fmt=7/f32 golden
+ /* [2048,6144] (spec example shape, same as Part A's fmt=8/f32 golden
* path): nblkO=16, nblkI=48, product=768 blocks. A UE8M0 sidecar is
* exactly 1 byte/block -> ns=768, distinct from BOTH fmt=1's per-row
* count (O*4=8192) and this build's f32 block-scale count (768*4=3072).
@@ -342,7 +343,7 @@ static void test_ue8m0_scale_refusal(void){
/* ---- Part B: qt_from_disk loader-seam (real safetensors file) ---- */
-static void deq_fmt7(const QT *t, float *dq){
+static void deq_fmt8(const QT *t, float *dq){
int64_t nblkI = fp8_nblk(t->I);
for(int o=0;o<t->O;o++){
int64_t blkO = o/FP8_BLOCK; const float *scl = t->s + blkO*nblkI;
@@ -410,12 +411,12 @@ static void test_loader_seam(void){
QT t7; memset(&t7,0,sizeof t7);
qt_from_disk(&gm,"w7",O7,I7,8,0,&t7);
- CHECK(t7.fmt==7);
+ CHECK(t7.fmt==8);
CHECK(t7.q8!=NULL && t7.s!=NULL); /* both weight and scale allocated (qalloc, not falloc) */
static float dq_load[O7*I7], dq_ref[O7*I7];
- deq_fmt7(&t7,dq_load);
- QT tr7={.fmt=7,.q8=(int8_t*)q7,.s=s7,.O=O7,.I=I7};
- deq_fmt7(&tr7,dq_ref);
+ deq_fmt8(&t7,dq_load);
+ QT tr7={.fmt=8,.q8=(int8_t*)q7,.s=s7,.O=O7,.I=I7};
+ deq_fmt8(&tr7,dq_ref);
CHECK(memcmp(dq_load,dq_ref,sizeof dq_ref)==0);
QT t1; memset(&t1,0,sizeof t1);
@@ -430,13 +431,13 @@ static void test_loader_seam(void){
unlink(path); rmdir(dir);
}
-/* ---- Part C: qt_bytes()/qt_scale_bytes() byte-accounting for fmt=7 ----
+/* ---- Part C: qt_bytes()/qt_scale_bytes() byte-accounting for fmt=8 ----
*
* qt_bytes() must not fall through to the fmt=2 (packed int4, O*ceil(I/2)+O*4)
* default -- for a real fp8 tensor that would undercount the resident byte
* count by roughly half (an AUTOPIN/RAM-budget-feeding hazard). qt_wire_mmap/
* qt_unwire_mmap must not hardcode scale_b=O*4 (per-row) either -- wrong for
- * fmt=7's per-128x128-block scale array -- hence the dedicated
+ * fmt=8's per-128x128-block scale array -- hence the dedicated
* qt_scale_bytes() helper shared by qt_bytes() and both wire functions so
* there is exactly one place that knows each format's scale geometry. This
* test exercises the arithmetic directly (no qt_from_disk/disk I/O, no mlock
@@ -445,7 +446,7 @@ static void test_loader_seam(void){
* the shapes already used elsewhere in this file plus a block-edge
* (non-128-multiple) case. */
static void check_fp8_bytes(int O, int I, const char *tag){
- QT t; memset(&t,0,sizeof t); t.fmt=7; t.O=O; t.I=I; t.gs=0;
+ QT t; memset(&t,0,sizeof t); t.fmt=8; t.O=O; t.I=I; t.gs=0;
int64_t nblkO=fp8_nblk(O), nblkI=fp8_nblk(I), nblk=nblkO*nblkI;
int64_t want_total = (int64_t)O*I + nblk*4;
int64_t want_scale = nblk*4;
@@ -461,9 +462,9 @@ static void check_fp8_bytes(int O, int I, const char *tag){
* O*I raw-byte weight region -- not short (partial mlock) or long (mlock past the
* allocation, undefined behavior) by even one byte. */
CHECK(got_total - got_scale == (int64_t)O*I);
- /* regression guard: the fmt=2 (packed-nibble) formula must NOT be what fmt=7
+ /* regression guard: the fmt=2 (packed-nibble) formula must NOT be what fmt=8
* returns -- confirm the value has actually MOVED off it (catches a silent
- * revert of the fmt==7 branch order/placement, not just a formula typo). For
+ * revert of the fmt==8 branch order/placement, not just a formula typo). For
* O=1,I=1 the two formulas coincide by coincidence (both give 1+4=5), so that
* shape is skipped for this particular guard -- the other three shapes below are
* chosen to avoid the coincidence. */
@@ -483,9 +484,19 @@ static void check_fp8_bytes(int O, int I, const char *tag){
* (fmt=1 per-row unaffected; fmt=4/5 grouped-scale formats qt_scale_bytes'
* own comment names as previously-broken too; fmt=6 (E8/IQ3, FIX ROUND,
* audit finding: a FIXED 4-byte tag, not O*4 -- see qt_scale_bytes' own
- * comment for why this is reachable, not dead code); fmt=7 nblk>O, the
+ * comment for why this is reachable, not dead code); fmt=8 nblk>O, the
* shape this review round is about). */
static void check_wire_split(int fmt, int O, int I, int gs, const char *tag){
+ /* self-guard (fix round 1, reviewer finding): the fmt ARGUMENT is the
+ * load-bearing input here, and a label that says fmt=8 with the argument
+ * left at a stale ordinal turns every assertion below into a tautology
+ * (want and got both fall to the same per-row default together). Pin the
+ * argument to the supported set so label/argument drift dies loudly at
+ * the call site instead. */
+ if(fmt!=1 && fmt!=4 && fmt!=5 && fmt!=6 && fmt!=8){
+ printf("FAIL %s: check_wire_split fmt=%d not in supported set {1,4,5,6,8} -- stale call site?\n", tag, fmt);
+ CHECK(0); return;
+ }
QT t; memset(&t,0,sizeof t); t.fmt=fmt; t.O=O; t.I=I; t.gs=gs;
int64_t want_scale = qt_scale_bytes(&t);
int64_t want_weight = qt_bytes(&t) - want_scale;
@@ -499,17 +510,30 @@ static void check_wire_split(int fmt, int O, int I, int gs, const char *tag){
CHECK(got_weight == want_weight);
/* the regression this test exists to catch: a per-row-only scale_b==O*4
* must NOT be what qt_wire_split returns for a format whose real scale
- * cardinality differs from O (fmt=4/5/6/7 here) -- confirm the value has
+ * cardinality differs from O (fmt=4/5/6/8 here) -- confirm the value has
* actually moved off that old constant, not just matched qt_scale_bytes()
* by coincidence at a degenerate shape. */
int64_t old_wrong_scale = (int64_t)O*4;
- if((fmt==4 || fmt==5 || fmt==6 || fmt==7) && want_scale != old_wrong_scale)
+ if((fmt==4 || fmt==5 || fmt==6 || fmt==8) && want_scale != old_wrong_scale)
CHECK(got_scale != old_wrong_scale);
/* fmt=6's scale is a FIXED 4 bytes regardless of [O,I] -- assert the
* literal value directly too, not just "moved off O*4", since a future
* regression that made it O-dependent in some OTHER wrong way would
* still pass the generic check above. */
if(fmt==6) CHECK(want_scale == 4);
+ /* fmt=8: same independent-pin discipline as the fmt==6 literal above.
+ * want and got BOTH flow through the engine's qt_scale_bytes() (the test
+ * computes want from it, and qt_wire_split() calls it), so a reverted or
+ * deleted fmt==8 branch would move both sides to O*4 TOGETHER: the
+ * got==want checks stay green and the moved-off-O*4 check self-disables
+ * (its want_scale != O*4 guard goes false). Recomputing the expected
+ * block-grid value here, independently of the engine, is what makes a
+ * regression of that branch actually FAIL this test (mutation-proven,
+ * fix round 1). */
+ if(fmt==8){
+ int64_t nblk = (((int64_t)O+127)/128) * (((int64_t)I+127)/128);
+ CHECK(want_scale == nblk*4);
+ }
}
/* ---- Site-level wire regression (FIX ROUND, validator finding: mutation-
@@ -544,7 +568,7 @@ static void test_wire_site_regression(void){
for(int i=0;i<NBLK;i++) s7[i]=0.01f+0.001f*(float)i;
QT t; memset(&t,0,sizeof t);
- t.fmt=7; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q7; t.s=s7;
+ t.fmt=8; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q7; t.s=s7;
int64_t want_scale = qt_scale_bytes(&t);
int64_t want_weight = qt_bytes(&t) - want_scale;
@@ -600,17 +624,17 @@ int main(void){
test_fmt6_fp8_collision();
test_ue8m0_scale_refusal();
test_loader_seam();
- check_fp8_bytes(2048,6144, "qt_bytes fmt=7 gate/up-shaped O=2048 I=6144 (spec example)");
- check_fp8_bytes(6144,2048, "qt_bytes fmt=7 down-shaped O=6144 I=2048");
- check_fp8_bytes(130,200, "qt_bytes fmt=7 block edges O,I both non-mult-128");
- check_fp8_bytes(1,1, "qt_bytes fmt=7 degenerate 1x1");
+ check_fp8_bytes(2048,6144, "qt_bytes fmt=8 gate/up-shaped O=2048 I=6144 (spec example)");
+ check_fp8_bytes(6144,2048, "qt_bytes fmt=8 down-shaped O=6144 I=2048");
+ check_fp8_bytes(130,200, "qt_bytes fmt=8 block edges O,I both non-mult-128");
+ check_fp8_bytes(1,1, "qt_bytes fmt=8 degenerate 1x1");
check_wire_split(1, 4096,4096, 0, "qt_wire_split fmt=1 plain int8 (per-row scale, unaffected by the fix)");
check_wire_split(4, 2048,6144, 64, "qt_wire_split fmt=4 grouped int4 (O*ceil(I/gs) scale, not O*4)");
check_wire_split(5, 2048,6144, 0, "qt_wire_split fmt=5 int3-g64 (O*ceil(I/64) scale, not O*4)");
check_wire_split(6, 2048,6144, 0, "qt_wire_split fmt=6 E8/IQ3 (FIXED 4-byte tag, not O*4=8192B)");
check_wire_split(6, 1,1, 0, "qt_wire_split fmt=6 E8/IQ3 degenerate O=1 (O*4 would coincidentally also be 4 -- exercises the literal-4 assert, not just the moved-off-O*4 one)");
- check_wire_split(7, 2,16384, 0, "qt_wire_split fmt=7 nblk(128) >> O(2): scale=512B, NOT O*4=8B");
- check_wire_split(7, 2048,6144, 0, "qt_wire_split fmt=7 spec example: scale=3072B, NOT O*4=8192B");
+ check_wire_split(8, 2,16384, 0, "qt_wire_split fmt=8 nblk(128) >> O(2): scale=512B, NOT O*4=8B");
+ check_wire_split(8, 2048,6144, 0, "qt_wire_split fmt=8 spec example: scale=3072B, NOT O*4=8192B");
test_wire_site_regression();
if(fails){ printf("fp8 loader-seam tests: %d FAILED\n", fails); return 1; }
printf("fp8 loader-seam tests: ok\n");
diff --git a/c/tests/test_fp8_passthrough.c b/c/tests/test_fp8_passthrough.c
index 61fb3709..e83b638b 100644
--- a/c/tests/test_fp8_passthrough.c
+++ b/c/tests/test_fp8_passthrough.c
@@ -1,4 +1,4 @@
-/* fmt=7 (native FP8-e4m3 passthrough) CPU kernel tests: LUT exactness (all 256
+/* fmt=8 (native FP8-e4m3 passthrough) CPU kernel tests: LUT exactness (all 256
* byte codes, incl. +-0, subnormals, NaN), matmul_fp8 vs a double-precision
* block-scale reference on block-edge (non-128-multiple O/I) shapes, a
* non-square-block-grid case with a distinct scale per block (catches a
@@ -10,12 +10,14 @@
* compute" header comment) -- the loader-seam (qt_resolve_fmt disambiguation,
* qt_from_disk) is covered separately in test_fp8_load.c.
*
- * fmt=7, PUBLIC ordinal assigned by the maintainer on #524: this format was
- * minted fmt=6 during original development of this branch, before dev's own
- * #465 (E8/IQ3) claimed that ordinal upstream; re-tagged fmt=100 (PRIVATE
- * ORDINAL BLOCK, see colibri.c's QT struct comment) from that point forward --
- * there was never a build in this branch's history where this format was
- * reachable as fmt=6 -- and graduated to fmt=7 at merge. */
+ * fmt=8, PUBLIC ordinal: this format was minted fmt=6 during original
+ * development of this branch, before dev's own #465 (E8/IQ3) claimed that
+ * ordinal upstream; re-tagged fmt=100 (PRIVATE ORDINAL BLOCK, see colibri.c's
+ * QT struct comment) from that point forward -- there was never a build in
+ * this branch's history where this format was reachable as fmt=6 -- graduated
+ * to fmt=7 when the maintainer assigned that ordinal on #524, and renumbered
+ * to fmt=8 after #705 merged claiming 7 for MXFP4 (see colibri.c's QT
+ * comment). */
#include "../quant.h"
#include <stdio.h>
#include <string.h>
@@ -92,7 +94,7 @@ static void ref_matmul_fp8(double *y, double *mag, const float *x, const uint8_t
}
/* magnitude-relative Sigma|terms| oracle (the convention test_backend_metal.mm's
- * cpu_ref_grouped/run_grouped established for fmt=4 and reuses for fmt=7 on the
+ * cpu_ref_grouped/run_grouped established for fmt=4 and reuses for fmt=8 on the
* GPU side): compare error against the sum of |terms|, not the (possibly
* near-zero, cancellation-prone) result itself. */
static int check_close(const float *got, const double *ref, const double *mag, int n, double tol, const char *tag){
diff --git a/c/tests/test_fp8_repack.py b/c/tests/test_fp8_repack.py
index e06b60ed..f95366bc 100644
--- a/c/tests/test_fp8_repack.py
+++ b/c/tests/test_fp8_repack.py
@@ -1,10 +1,11 @@
-"""tools/repack_fp8_passthrough.py: fmt=7 repack tool tests.
+"""tools/repack_fp8_passthrough.py: fmt=8 repack tool tests.
-fmt=7 is a PUBLIC ordinal, assigned by the maintainer on #524: see
-repack_fp8_passthrough.py's module docstring for the fmt=6 -> fmt=100 ->
-fmt=7 history (dev's own #465 merged a REAL fmt=6, E8/IQ3, so this tool's
-format moved to the PRIVATE ORDINAL BLOCK as fmt=100 during development
-before graduating to fmt=7 at merge).
+fmt=8 is a PUBLIC ordinal: see repack_fp8_passthrough.py's module docstring
+for the fmt=6 -> fmt=100 -> fmt=7 -> fmt=8 history (dev's own #465 merged a
+REAL fmt=6, E8/IQ3, so this tool's format moved to the PRIVATE ORDINAL BLOCK
+as fmt=100 during development; the maintainer assigned fmt=7 on #524; #705
+then merged MXFP4 as fmt=7 while this PR was open, forcing the renumber
+to fmt=8).
Synthetic fixtures ONLY (tools/glm_fp8_emit.py, the exact real-checkpoint FP8
layout that convert_fp8_to_int4.py's dequant() reads) -- no real Z.ai shard is
@@ -49,7 +50,7 @@ def _make_fixture(path, D=256, I_=384, E=4):
"""One synthetic shard covering every selection case: SELECTED resident
kinds (attn/o/sh/dmlp), the EXCLUDED resident kind kvb (kv_b_proj -- valid
per convert_fp8_to_int4.classify(), but the engine's CPU/CUDA MLA-absorb
- paths have no fmt=7 case yet, so this tool must not select it -- see the
+ paths have no fmt=8 case yet, so this tool must not select it -- see the
module docstring), routed experts (must be excluded), the router and a
norm (f32-kept, never fp8), and embed_tokens (io kind -- excluded by kind
even though glm_fp8_emit's simpler keep_f32() happens to FP8-quantize it,
@@ -115,10 +116,10 @@ class SelectionTest(unittest.TestCase):
def test_kv_b_proj_excluded(self):
"""Regression guard for a gap found in self-review: kv_b_proj is a valid
resident kind per classify(), but colibri.c's CPU absorb path
- (qt_addrow/qt_matvec_rows) and the CUDA absorb kernels have no fmt=7
+ (qt_addrow/qt_matvec_rows) and the CUDA absorb kernels have no fmt=8
case -- selecting it here would produce a container the engine
silently misreads as int2. Must stay excluded until that path gains
- fmt=7 support (separate follow-up work)."""
+ fmt=8 support (separate follow-up work)."""
inv = rp.shard_inventory(self.shard, n_layers=5)
names = {it["name"] for it in inv}
self.assertNotIn("model.layers.0.self_attn.kv_b_proj.weight", names)
@@ -174,8 +175,8 @@ class SelectionTest(unittest.TestCase):
shape family c/tests/test_fp8_load.c's test_disambiguation() sweeps. The
engine's qt_resolve_fmt reader resolves an unstamped collision at this
shape to fmt=1 (int8-row) rather than refusing (see colibri.c's
- INVERSION) -- so this tool refusing to ever EMIT an fmt=7 container here
- is what keeps that reader-side resolution correct: an fmt=7 tensor this
+ INVERSION) -- so this tool refusing to ever EMIT an fmt=8 container here
+ is what keeps that reader-side resolution correct: an fmt=8 tensor this
tool produced at this shape would be silently read back as plain int8."""
amb_path = os.path.join(self.tmp.name, "ambiguous.safetensors")
O, I_ = 2, 256
diff --git a/c/tests/test_qt_addrow.c b/c/tests/test_qt_addrow.c
index cc9f81c5..46c3673c 100644
--- a/c/tests/test_qt_addrow.c
+++ b/c/tests/test_qt_addrow.c
@@ -4,8 +4,8 @@
* fmt 0/4/5 explicitly, then fall through assuming a PER-ROW scale (t->s[row]) followed by
* fmt=1/2/3 (qt_addrow) or fmt=0/1/2/3/4/5 (qt_matvec_rows, via an if/else-if chain ending
* in a bare `else`) -- nothing stopped fmt=6 (E8/IQ3, t->s is a FIXED 4-byte tag, not O
- * floats) or fmt=7 (fp8-e4m3-b128, t->s holds per-128x128-block floats, not O; t->q4 is
- * NULL) from reaching that fall-through. For fmt=7 specifically this SIGSEGVs: t->s[row]
+ * floats) or fmt=8 (fp8-e4m3-b128, t->s holds per-128x128-block floats, not O; t->q4 is
+ * NULL) from reaching that fall-through. For fmt=8 specifically this SIGSEGVs: t->s[row]
* overreads (silently, usually not fatal on its own), then the untouched tail computes
* `t->q4+(int64_t)row*((I+3)/4)` on a NULL t->q4 and dereferences it. For fmt=6 it silently
* misreads the real E8/IQ3 lattice bytes as int2-packed data (same bug SHAPE as #298's CUDA
@@ -14,7 +14,7 @@
* any fmt they don't explicitly handle, matching qt_resolve_fmt's own "refuse rather than
* misread" discipline.
*
- * This file: (1) proves the refusal fires for fmt=6 and fmt=7 through BOTH functions
+ * This file: (1) proves the refusal fires for fmt=6 and fmt=8 through BOTH functions
* (fork+pipe+waitpid, this suite's established house pattern for exit(1)-terminated paths --
* see tests/test_fp8_load.c's expect_refuse/expect_stamp_refuse); (2) proves every format
* BOTH functions still legitimately handle (0/1/2/3/4/5) produces byte-identical results
@@ -24,10 +24,10 @@
* would show up here, not just tautologically re-run the same code). Reachability note (not
* a scope excuse, just context): both functions serve ONLY the kv_b absorb path
* (attention_rows/decode call sites), and tools/repack_fp8_passthrough.py deliberately
- * excludes kv_b_proj from fmt=7 repacking -- so this fires only via a hand-slotted or
+ * excludes kv_b_proj from fmt=8 repacking -- so this fires only via a hand-slotted or
* ambiguous-collision container, not this repo's own tooling's own output. Crash-instead-of-
* refuse is still a real defect (spec I6: loud failure, every refusal names its condition),
- * and the fmt=7 QT surface these functions can now be handed is one this same PR pair
+ * and the fmt=8 QT surface these functions can now be handed is one this same PR pair
* created. */
#define main coli_glm_main_unused
#include "../colibri.c"
@@ -191,13 +191,13 @@ static void test_byte_identity_all_formats(void){
* expect_refuse/expect_stamp_refuse) -- must exit(1) with a "refus"-containing message,
* never reach the caller's continuation, never crash with a signal. ---- */
typedef void (*absorb_fn)(void);
-static void call_addrow_fmt7(void){
+static void call_addrow_fmt8(void){
QT t; memset(&t,0,sizeof t);
enum { O=130, I=130 }; /* the coordinator's own repro shape: nblkO=nblkI=2, nblk=4 */
static uint8_t q8[O*I]; static float s[4];
for(int i=0;i<O*I;i++) q8[i]=rndbyte();
for(int i=0;i<4;i++) s[i]=0.01f;
- t.fmt=7; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q8; t.s=s;
+ t.fmt=8; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q8; t.s=s;
float acc[I]; memset(acc,0,sizeof acc);
qt_addrow(&t,0,1.f,acc); /* must exit(1) inside; must NOT return */
}
@@ -211,13 +211,13 @@ static void call_addrow_fmt6(void){
float acc[I]; memset(acc,0,sizeof acc);
qt_addrow(&t,0,1.f,acc);
}
-static void call_matvec_fmt7(void){
+static void call_matvec_fmt8(void){
QT t; memset(&t,0,sizeof t);
enum { O=130, I=130 };
static uint8_t q8[O*I]; static float s[4];
for(int i=0;i<O*I;i++) q8[i]=rndbyte();
for(int i=0;i<4;i++) s[i]=0.01f;
- t.fmt=7; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q8; t.s=s;
+ t.fmt=8; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q8; t.s=s;
static float x[I]; for(int i=0;i<I;i++) x[i]=rndsmallf();
float y=0.f;
qt_matvec_rows(&t,0,1,x,&y);
@@ -271,9 +271,9 @@ static int expect_refuse_call(absorb_fn fn, const char *tag){
}
static void test_refusals(void){
- CHECK(expect_refuse_call(call_addrow_fmt7, "qt_addrow refuses fmt=7 (was SIGSEGV)"));
+ CHECK(expect_refuse_call(call_addrow_fmt8, "qt_addrow refuses fmt=8 (was SIGSEGV)"));
CHECK(expect_refuse_call(call_addrow_fmt6, "qt_addrow refuses fmt=6"));
- CHECK(expect_refuse_call(call_matvec_fmt7, "qt_matvec_rows refuses fmt=7"));
+ CHECK(expect_refuse_call(call_matvec_fmt8, "qt_matvec_rows refuses fmt=8"));
CHECK(expect_refuse_call(call_matvec_fmt6, "qt_matvec_rows refuses fmt=6"));
}
diff --git a/c/tools/README.md b/c/tools/README.md
index b058556f..5531e54c 100644
--- a/c/tools/README.md
+++ b/c/tools/README.md
@@ -4,7 +4,7 @@ These scripts support model preparation and offline engineering work. They are
not runtime dependencies of the C engine.
- `convert_fp8_to_int4.py`, `download_glm52.py`: model preparation
-- `repack_fp8_passthrough.py`: fmt=7 repack (byte-preserved FP8, resident kinds only;
+- `repack_fp8_passthrough.py`: fmt=8 repack (byte-preserved FP8, resident kinds only;
see the module docstring -- synthetic-fixture-tested only, no real-shard runs yet)
- `make_glm_oracle.py`, `make_glm_bench_model.py`: deterministic fixtures
- `benchmark_cuda_fixture.py`, `eval_glm.py`, `fetch_benchmarks.py`: benchmarks
diff --git a/c/tools/fp8_collision_census.py b/c/tools/fp8_collision_census.py
index 99ea37f6..e6699c2a 100644
--- a/c/tools/fp8_collision_census.py
+++ b/c/tools/fp8_collision_census.py
@@ -29,7 +29,7 @@ Scope: RESIDENT-kind tensor roles only (o_proj, q_a/q_b_proj,
kv_a_proj_with_mqa, kv_b_proj, dense-MLP gate/up/down, shared-expert
gate/up/down) plus routed-expert gate/up/down for completeness -- these are
the only roles tools/repack_fp8_passthrough.py's RESIDENT_KINDS classify()
-taxonomy could ever select for fmt=7 repacking (routed experts are excluded
+taxonomy could ever select for fmt=8 repacking (routed experts are excluded
by that tool's own design and stay on int4-g64/E8, but are included here
anyway since the collision predicate is a pure function of [O,I], independent
of current on-disk format). f32/norm/router/embed/lm_head tensors are not
@@ -100,14 +100,14 @@ def classify_shape(name, cfg):
if name.endswith("self_attn.kv_a_proj_with_mqa.weight"):
return ("self_attn.kv_a_proj_with_mqa", kv_lora + qk_rope, D)
if name.endswith("self_attn.kv_b_proj.weight"):
- return ("self_attn.kv_b_proj (kvb -- excluded from fmt=7 repack, see tool docstring)",
+ return ("self_attn.kv_b_proj (kvb -- excluded from fmt=8 repack, see tool docstring)",
H * (qk_nope + v_head), kv_lora)
if ".mlp.experts." in name and name.endswith("gate_proj.weight"):
- return ("mlp.experts.*.gate_proj (routed -- excluded from fmt=7 repack)", moe_inter, D)
+ return ("mlp.experts.*.gate_proj (routed -- excluded from fmt=8 repack)", moe_inter, D)
if ".mlp.experts." in name and name.endswith("up_proj.weight"):
- return ("mlp.experts.*.up_proj (routed -- excluded from fmt=7 repack)", moe_inter, D)
+ return ("mlp.experts.*.up_proj (routed -- excluded from fmt=8 repack)", moe_inter, D)
if ".mlp.experts." in name and name.endswith("down_proj.weight"):
- return ("mlp.experts.*.down_proj (routed -- excluded from fmt=7 repack)", D, moe_inter)
+ return ("mlp.experts.*.down_proj (routed -- excluded from fmt=8 repack)", D, moe_inter)
if "shared_experts" in name and name.endswith("gate_proj.weight"):
return ("mlp.shared_experts.gate_proj", moe_inter, D)
if "shared_experts" in name and name.endswith("up_proj.weight"):
diff --git a/c/tools/rans_format.py b/c/tools/rans_format.py
index 29033025..7c8a788b 100644
--- a/c/tools/rans_format.py
+++ b/c/tools/rans_format.py
@@ -20,7 +20,7 @@ FORMAT SUMMARY (docs/int4-rans256-g0.md is the full specification):
the format NAME "int4-rans256-g0". THE STAMP IS MANDATORY: entropy-coded
sizes are data-dependent, so no byte-arithmetic inference exists for this
format β€” the stamp is the ONLY signal a U8 tensor is entropy-coded, not a
- cross-check on an inference (unlike fmt=7's optional stamp).
+ cross-check on an inference (unlike fmt=8's optional stamp).
Table construction is the standard largest-remainder frequency quantization
(FSE/rANS convention): scale an empirical histogram to sum exactly to
@@ -42,7 +42,7 @@ N_STREAMS = 256
SCALE_BITS = 14 # M = 16384; generous for a 16-symbol alphabet
M = 1 << SCALE_BITS
TABLE_ID = "g0" # shared-global-table generation 0
-METADATA_KEY = "colibri.fmt" # same key/shape as the fmt=7 stamp convention
+METADATA_KEY = "colibri.fmt" # same key/shape as the fmt=8 stamp convention
TABLE_KEY = "colibri.int4-rans256-g0.table"
RANS_L = 1 << 23
SLACK = 64 # readable bytes past a record buffer (SIMD contract)
diff --git a/c/tools/repack_fp8_passthrough.py b/c/tools/repack_fp8_passthrough.py
index d292270f..15f27c34 100644
--- a/c/tools/repack_fp8_passthrough.py
+++ b/c/tools/repack_fp8_passthrough.py
@@ -1,13 +1,15 @@
-"""fmt=7 repack tool: Z.ai GLM-5.2-FP8 shards -> the engine's native-FP8-passthrough
+"""fmt=8 repack tool: Z.ai GLM-5.2-FP8 shards -> the engine's native-FP8-passthrough
container (byte-preserved, no dequant/requant).
-fmt=7 is a PUBLIC ordinal, assigned by the maintainer on #524. This tool's
-output format was minted fmt=6 during this branch's original development,
-before dev's own #465 (E8/IQ3) claimed that ordinal upstream and merged it
-into dev as a REAL fmt=6 (colibri.c's qt_resolve_fmt, quant.h's E8
-constants); re-tagged fmt=100 (PRIVATE ORDINAL BLOCK, see colibri.c's QT
-struct comment) from that point forward -- this tool has never emitted a
-container claiming ordinal 6 -- and graduated to fmt=7 at merge.
+fmt=8 is a PUBLIC ordinal. This tool's output format was minted fmt=6 during
+this branch's original development, before dev's own #465 (E8/IQ3) claimed
+that ordinal upstream and merged it into dev as a REAL fmt=6 (colibri.c's
+qt_resolve_fmt, quant.h's E8 constants); re-tagged fmt=100 (PRIVATE ORDINAL
+BLOCK, see colibri.c's QT struct comment) from that point forward -- this
+tool has never emitted a container claiming ordinal 6 -- graduated to fmt=7
+when the maintainer assigned that ordinal on #524, and renumbered to fmt=8
+after #705 merged MXFP4 as fmt=7 while this PR was open. Nothing this tool
+writes carries the ordinal, so neither renumber changed its output bytes.
Unlike convert_fp8_to_int4.py (which DEQUANTIZES fp8 -> f32 -> REQUANTIZES to a
different, lossy format), this tool copies the fp8 weight bytes AS-IS and only
@@ -15,9 +17,9 @@ renames/reshapes the scale sidecar to the engine's `.qs` convention. Same 8
bits/weight streaming cost as the source, zero additional quantization loss.
THE DESIGN LANDMINE (see qt_resolve_fmt in colibri.c, c/quant.h's E4M3_LUT
-comment): the engine tells fmt=7 (this tool's output) apart from fmt=1 (plain
+comment): the engine tells fmt=8 (this tool's output) apart from fmt=1 (plain
int8) ONLY by scale-array geometry -- per-row for fmt=1, per-128x128-block for
-fmt=7. This tool must therefore emit .qs sidecars whose byte count is EXACTLY
+fmt=8. This tool must therefore emit .qs sidecars whose byte count is EXACTLY
ceil(O/128)*ceil(I/128)*4, never anything that could coincide with O*4 by
accident for the shapes it targets -- ENFORCED, not just asserted, by
_check_geometry below (maintainer review, #528): it refuses to repack any
@@ -27,7 +29,7 @@ hypothetical: GLM-5.2's own self_attn.o_proj.weight ([6144,16384]) is a real
instance (nblkO=48, nblkI=128, product=6144==O). It matters more now than it
used to, because the engine's UNSTAMPED read-side collision policy resolves an
ambiguous shape to fmt=1 rather than refusing (see qt_resolve_fmt's
-INVERSION) -- so an fmt=7 container this tool emitted at such a shape would be
+INVERSION) -- so an fmt=8 container this tool emitted at such a shape would be
silently read back as plain int8, not caught by a read-side refusal. Avoiding
the collision at write time is therefore load-bearing, not a redundant
belt-and-braces check. At I=98 specifically, a single-block fp8 tensor's raw
@@ -51,25 +53,25 @@ attention projections, dense-MLP first layers, and the generic resident
fallback) -- routed experts (kind "x" in convert_fp8_to_int4.classify) are
EXCLUDED and stay on the existing int4-g64 streaming path; routers/norms/bias
(kind "f32") and embed/lm_head (kind "io", BF16 in source, never FP8) are
-untouched by this tool -- carrying those into a mixed fmt=7+int4 loadout
+untouched by this tool -- carrying those into a mixed fmt=8+int4 loadout
directory is separate, deferred "loadout index-rewrite blending" work.
kv_b_proj (kind "kvb") is ALSO deliberately excluded, despite being a resident
tensor classify() would otherwise select: colibri.c's MLA-absorption CPU path
(qt_addrow/qt_matvec_rows, called only on l->kv_b -- the always-available
-fallback whenever the Metal fused decode kernel isn't used) has no fmt==7
-support. FIX ROUND 2 update: an fmt=7 (or fmt=6) tensor reaching either
+fallback whenever the Metal fused decode kernel isn't used) has no fmt==8
+support. FIX ROUND 2 update: an fmt=8 (or fmt=6) tensor reaching either
function now refuses loudly (exit(1), naming the function and the fmt) --
before that fix it was worse than "misread as int2": qt_addrow SIGSEGV'd
-outright (t->q4 is NULL for fmt=7; the untouched int2 fall-through
+outright (t->q4 is NULL for fmt=8; the untouched int2 fall-through
dereferenced it), and only fmt=6 (t->q4 non-NULL, wrong per-row scale
geometry) actually produced silently-wrong values. Either way, this tool
still does not select kv_b_proj: refusing loudly at the absorb call site is
-not the same as SUPPORTING fmt=7 there (no dequant path exists, whether it
+not the same as SUPPORTING fmt=8 there (no dequant path exists, whether it
now trips a controlled refusal or, before the fix, undefined behavior). The
CUDA absorb kernels (coli_cuda_attention_absorb/_kvdev in backend_cuda.cu)
are similarly int4-specific and unaffected by that fix. Repacking kv_b_proj
-to fmt=7 needs real fmt=7 CPU+CUDA absorb-path support first -- out of scope
+to fmt=8 needs real fmt=8 CPU+CUDA absorb-path support first -- out of scope
for this build, so this tool refuses to produce a container the engine
cannot safely read.
@@ -100,7 +102,7 @@ from convert_fp8_to_int4 import classify, check_or_record_params # reuse: same
# experts ("x"), NOT the always-F32 set ("f32"), NOT embed/lm_head ("io" -- BF16 in
# source, never FP8), NOT sidecars/skips ("consumed"/"skip"). "kvb" (kv_b_proj) is
# ALSO excluded -- see the module docstring: the CPU absorb path (qt_addrow/
-# qt_matvec_rows) and the CUDA absorb kernels have no fmt=7 case yet.
+# qt_matvec_rows) and the CUDA absorb kernels have no fmt=8 case yet.
RESIDENT_KINDS = frozenset({"sh", "o", "attn", "dmlp", "q"})
BLOCK = 128
@@ -112,7 +114,7 @@ def _nblk(n):
def is_repack_target(name, dtype, keys, n_layers):
"""True if `name` is a resident-kind FP8 tensor this tool should byte-preserve
- into the fmt=7 container. `keys` is the full set of tensor names in the shard
+ into the fmt=8 container. `keys` is the full set of tensor names in the shard
(needed to confirm the `_scale_inv` sidecar is actually present -- classify()
alone can't tell FP8 tensors from any other dtype a resident-kind name might
carry in a non-FP8 checkpoint variant)."""
@@ -140,7 +142,7 @@ def _check_geometry(name, O, I, nblkO, nblkI):
own self_attn.o_proj.weight ([6144,16384]) is a REAL, non-hypothetical instance
of this shape. The engine's reader now resolves an unstamped collision to fmt=1
(the incumbent, decodable format) rather than refusing -- which makes it load
- bearing that THIS tool never emits an fmt=7 container at such a shape: this
+ bearing that THIS tool never emits an fmt=8 container at such a shape: this
docstring's own opening promise ("never anything that could coincide with O*4
by accident") is enforced here, not just asserted."""
exp_nblkO, exp_nblkI = _nblk(O), _nblk(I)
@@ -154,9 +156,9 @@ def _check_geometry(name, O, I, nblkO, nblkI):
f"{name}: [{O},{I}] is an AMBIGUOUS fp8-e4m3-b128 shape -- its "
f"block-scale byte count (nblkO*nblkI*4={nblkO*nblkI*4}) exactly "
f"coincides with a per-row int8 scale byte count (O*4={O*4}) for the "
- f"same [O,I]; refusing to emit an fmt=7 container the engine's "
+ f"same [O,I]; refusing to emit an fmt=8 container the engine's "
f"qt_resolve_fmt collision policy would resolve to fmt=1 (int8-row), "
- f"not fmt=7, on an unstamped read (THE DESIGN LANDMINE, colibri.c)")
+ f"not fmt=8, on an unstamped read (THE DESIGN LANDMINE, colibri.c)")
def shard_inventory(path, n_layers):
@@ -232,7 +234,7 @@ def main():
ap = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--indir", required=True, help="directory of Z.ai FP8 *.safetensors shards")
- ap.add_argument("--outdir", required=True, help="destination for repacked fmt=7 container shards")
+ ap.add_argument("--outdir", required=True, help="destination for repacked fmt=8 container shards")
ap.add_argument("--n-layers", type=int, default=78)
ap.add_argument("--dry-run", action="store_true",
help="inventory only: scan headers, print selection counts, write nothing")
diff --git a/docs/int4-rans256-g0.md b/docs/int4-rans256-g0.md
index 2e437226..6d85ac5f 100644
--- a/docs/int4-rans256-g0.md
+++ b/docs/int4-rans256-g0.md
@@ -153,7 +153,7 @@ lets tooling confirm two shards used the identical table without diffing
the base64 blob. `table_id` is provenance metadata (a retuned future table
would ship as `g1`); readers never resolve it externally.
-## THE STAMP IS MANDATORY (the load-bearing difference from fmt=7)
+## THE STAMP IS MANDATORY (the load-bearing difference from fmt=8)
`__metadata__["colibri.fmt"]` maps each entropy-coded **weight** tensor
name (never `.qs`) to the string `int4-rans256-g0`, JSON-encoded with