libxe2: chain-parallel gdn_chunk_scan and an fp16 m2xfp4 prefill -- 27B prefill 68 -> 91 tok/s

- gdn_chunk_scan for head_k = 128, chunk 64: a work-group of 256 a (sequence, head, block of 32
  value columns), the chunk's k, q (rows padded), the block's slices of v, S, W, V' and the sA rows
  in local memory (~124 KB); every phase of a chunk is thousands of independent chains -- W[j][e],
  V'[i][e], R[i][j], O[i][e], S[d][e] -- each one work-item's, in libref's order, A staged in local
  memory, the decays e^{g_i - g_j} (libref's double exp) once a call. Still bit-identical (rel_l2 0,
  the 27B's geometry, 1..32 rows and multi-chunk). 233 -> 96 ms a call at 1792 tokens.
- m2xfp4 at M >= 17 now fp16 on XMX: the weight times 2^(127 - e_max(n)), exact in fp16; the
  activation fp16(a * a_scale / R_m); y = acc * R_m * 2^(e_max - 127) in a new scaled fp16 XMX
  kernel (xmx_f16_scaled). fp16's 2^-11 step instead of bf16's 2^-8.

KL on the 27B against an XE2_EXACT=1 reference (every kernel exact, each matched to libref bit for
bit; 250 positions, full vocabulary): mean 0.0041 -> 0.0035, p99 0.027 -> 0.021, top-1 96.8% ->
95.6%, PPL ratio 0.998. The fast set's KL is dominated by the model's own fp8 activation quantiser
re-rounding small upstream differences.

27B prefill of 1792 tokens: 26.3 -> 19.7 s (68 -> 91 tok/s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
pascallinxweilerandClaude Opus 5.5 committed 2026-10-24 05:33:08 +02:00
1 parent 0376adeb92
commit e0bfeb54f8
6 files changed
+264 -32

No files matched your search

+10 -5
View File
@@ -269,16 +269,21 @@ int rmsnorm_quant_fp8(const RadArgs* a, RadStream st) {
* knows), a memory round trip an element. */
constexpr int kPer = (int)(kRowMax / kWg);
float xv[kPer], rv[kPer], wv[kPer];
/* fully unrolled and predicated (no early exit), so every load is in flight
* before the first is used */
#pragma unroll
for (int j = 0; j < kPer; ++j) {
const int64_t i = t + (int64_t)j * kWg;
if (i >= n) break;
xv[j] = rad_load_f32(x.base, x.dtype, r * x.pitch + i);
rv[j] = has_res ? rad_load_f32(res.base, res.dtype, r * res.pitch + i) : 0.0f;
wv[j] = rad_load_f32(gw.base, gw.dtype, i * gw.stride) + wadd;
const bool ok = i < n;
const int64_t ii = ok ? i : 0;
xv[j] = rad_load_f32(x.base, x.dtype, r * x.pitch + ii);
rv[j] = has_res ? rad_load_f32(res.base, res.dtype, r * res.pitch + ii) : 0.0f;
wv[j] = rad_load_f32(gw.base, gw.dtype, ii * gw.stride) + wadd;
}
#pragma unroll
for (int j = 0; j < kPer; ++j) {
const int64_t i = t + (int64_t)j * kWg;
if (i >= n) break;
if (i >= n) continue;
float v = xv[j];
if (has_res) {
const float s0 = v + rv[j];