mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
metal moe: instantiate IQ1_M's expert gate/up (the GSQ packs' experts)
The GSQ IQ2_XS packs hold the experts' gate/up in IQ1_M (GGUF type 29). The moe decode kernels were not instantiated for it, so any run of such a pack failed at kernel load: no function moe_gu_29_32_1_4 (decode) and, once the prompts hit the matrix units, mm_gu2_29_16_64_16_2. Ported from the 0.1.45 line's matching instantiations: - moe.metal: GU_SET(T_IQ1_M); - moe_mm.metal: MM_GU_SET(T_IQ1_M) and MM_GU2_SET(T_IQ1_M) (the v1/v2 prompt paths stage the weights through stage_w's generic DW, which decodes via quant.metal's deq); - quant.metal: deq<T_IQ1_M>. The 0.1.45 kernel read the grid from a packed uint32 constant (nibble j = grid-row byte j + 1, the rows' bytes are -1/0/1); this tree already carries the C-side uint64 iq1s_grid in the module (the W8<T_IQ1_M> tile reads it), so deq takes the values straight from it: same scale/delta arithmetic, nibble j minus one is the signed byte j. fmt<T_IQ1_M>'s TAB = 1 stays (load_tab is a no-op, no threadgroup table). Verified on M4 Pro 48 GB, Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS, with STRATA_METAL_KERNELS at this tree, --batch and the official v0.2.9 slots: - batch_test --batch 2 --max-new 24 and --batch 4 --max-new 8: every slot IDENTICAL to its solo; - the slot tokens' dump matches the 0.1.45 branch's run of the same test (solo and batch both MATCH - the decode is bit-equal to our validated reference); - batch_interleave_test: 10/10 IDENTICAL (slots A/B/C, next-turn from a slot, BYIELD, F/F2 checkpoints; the 4888-token prompt C reads through mm_gu2_29); - serve_load --clients 2: 0 errors.
This commit is contained in:
1 parent
30ce30b18d
commit
88c4e79398
3 files changed
+27
-1
No files matched your search
@@ -447,6 +447,7 @@ GU_SET(T_IQ2_XS)
|
||||
GU_SET(T_IQ2_S)
|
||||
GU_SET(T_IQ3_S)
|
||||
GU_SET(T_IQ4_XS) // the IQ3_S pack's gate/up in one layer
|
||||
GU_SET(T_IQ1_M) // IQ1_M's expert gate/up in the GSQ packs (ported from the 0.1.45 line)
|
||||
GU_SET(T_Q4_K) GU_SET(T_Q5_K) GU_SET(T_Q6_K) GU_SET(T_Q8_0) // the UD-Q4/5/6_K_XL packs
|
||||
DN_SET(T_Q5_1) DN_SET(T_Q8_0)
|
||||
DN_SET(T_Q5_0) // the UD-IQ2_XS / Q2_K_XL / Q3_K_XL / IQ4_XS packs' down experts (generic Dec: d * (code - 16))
|
||||
|
||||
@@ -267,7 +267,7 @@ kernel void mm_combine(device const float* YE [[buffer(0)]], device const int* p
|
||||
#define MMDN(F, M, N, K, S) MMDN_(F, M, N, K, S)
|
||||
#define MM_GU_SET(F) MMGU(F, 32, 64, 64, 4) MMGU(F, 64, 64, 64, 4) MMGU(F, 16, 64, 64, 2) MMGU(F, 32, 32, 64, 2)
|
||||
#define MM_DN_SET(F) MMDN(F, 32, 64, 64, 4) MMDN(F, 64, 64, 64, 4) MMDN(F, 16, 64, 64, 2) MMDN(F, 32, 32, 64, 2)
|
||||
MM_GU_SET(T_Q2_0) MM_GU_SET(T_IQ3_XXS) MM_GU_SET(T_IQ2_XXS) MM_GU_SET(T_IQ2_XS) MM_GU_SET(T_IQ2_S) MM_GU_SET(T_IQ3_S)
|
||||
MM_GU_SET(T_Q2_0) MM_GU_SET(T_IQ3_XXS) MM_GU_SET(T_IQ2_XXS) MM_GU_SET(T_IQ2_XS) MM_GU_SET(T_IQ2_S) MM_GU_SET(T_IQ3_S) MM_GU_SET(T_IQ1_M)
|
||||
MM_DN_SET(T_Q2_0) MM_DN_SET(T_IQ4_NL) MM_DN_SET(T_Q5_0)
|
||||
|
||||
// ---- v2: activations gathered once per layer as fp16 rows, read by matmul2d from device memory ---------------------
|
||||
@@ -413,6 +413,7 @@ MMDN2(T_IQ3_S, 16, 64, 16, 2) MMDN2(T_IQ3_S, 16, 64, 32, 2) MMDN2(T_IQ3_S, 16, 3
|
||||
MMGU2(T_IQ4_XS, 16, 64, 32, 2) MMGU2(T_IQ4_XS, 16, 64, 64, 2) MMGU2(T_IQ4_XS, 32, 64, 32, 2) MMGU2(T_IQ4_XS, 16, 32, 32, 2)
|
||||
MMGU2(T_IQ4_XS, 64, 64, 32, 4)
|
||||
MM_GU2_SET(T_Q2_0) MM_GU2_SET(T_IQ3_XXS) MM_GU2_SET(T_IQ2_XXS) MM_GU2_SET(T_IQ2_XS) MM_GU2_SET(T_IQ2_S) MM_GU2_SET(T_IQ3_S)
|
||||
MM_GU2_SET(T_IQ1_M) // IQ1_M's expert gate/up in the GSQ packs (ported from the 0.1.45 line)
|
||||
MM_GU2_SET(T_TQK6) MM_GU2_SET(T_TQ2T) // Gyro: the trellis gate/up (units of 16 weights: TK 16 or a multiple)
|
||||
MM_GU2_SET(T_TQP5) MM_GU2_SET(T_TQP6) MM_GU2_SET(T_TQP7) // the pair trellis gate/up (same 16-weight units)
|
||||
MM_DN2_SET(T_Q2_0)
|
||||
|
||||
@@ -518,6 +518,30 @@ template <> inline float deq<T_IQ2_S>(device const uchar* b, int ui, thread floa
|
||||
return rdh(b) * (0.5f + float((sc >> (4 * h)) & 15)) * 0.25f;
|
||||
}
|
||||
|
||||
// IQ1_M: qs[32], qh[16], scales[8] (56 bytes); the fp16 scale is packed in the four u16 scales' nibbles. One unit =
|
||||
// one 32-group half of 16 (grids l = 2h, 2h + 1 of group ib = ui >> 1, h = ui & 1), each grid's delta bit in qh. The
|
||||
// delta (+-1/8) folds into q[j], the unit's scale is dl (dl1's nibble for the first unit half, dl2's for the second).
|
||||
// Ported from the 0.1.45 line's deq<T_IQ1_M>: there a packed grid_iq1m constant stores nibble j = grid-row byte j + 1
|
||||
// (the rows' bytes are -1/0/1), so here the same value is the row's signed byte straight out of the module's
|
||||
// iq1s_grid constant (the 0.1.45 threadgroup-table path is gone: TAB = 1, and load_tab<T_IQ1_M> is a no-op).
|
||||
template <> inline float deq<T_IQ1_M>(device const uchar* b, int ui, thread float* q, threadgroup const uint*) {
|
||||
const int ib = ui >> 1, h = ui & 1;
|
||||
device const ushort* sc = (device const ushort*)(b + 48);
|
||||
const float d = float(as_type<half>(ushort((sc[0] >> 12) | ((sc[1] >> 8) & 0x0f0) | ((sc[2] >> 4) & 0x0f00) | (sc[3] & 0xf000))));
|
||||
const float dl = d * (2 * ((sc[ib >> 1] >> (6 * (ib & 1) + 3 * h)) & 7) + 1);
|
||||
const uint qh = b[32 + 2 * ib + h];
|
||||
const int qb = 4 * ib + 2 * h;
|
||||
const ulong g0 = iq1s_grid[uint(b[qb]) | ((qh << 8) & 0x700u)];
|
||||
const ulong g1 = iq1s_grid[uint(b[qb + 1]) | ((qh << 4) & 0x700u)];
|
||||
const float d0 = (qh & 0x08) ? -0.125f : 0.125f, d1 = (qh & 0x80) ? -0.125f : 0.125f;
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
const uint b0 = uint((g0 >> (8 * j)) & 0xffu), b1 = uint((g1 >> (8 * j)) & 0xffu);
|
||||
q[j] = float(int(b0) - ((b0 & 0x80u) ? 256 : 0)) + d0;
|
||||
q[8 + j] = float(int(b1) - ((b1 & 0x80u) ? 256 : 0)) + d1;
|
||||
}
|
||||
return dl;
|
||||
}
|
||||
|
||||
// IQ3_S: qs[64] low 8 bits of 9-bit indices, qh[8], signs[32], scales[4] (nibble per 32).
|
||||
template <> inline float deq<T_IQ3_S>(device const uchar* b, int ui, thread float* q, threadgroup const uint* tab) {
|
||||
const int ib = ui >> 1, h = ui & 1;
|
||||
|
||||
Reference in new issue
Block a user