Archived
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:
1 parent
0376adeb92
commit
e0bfeb54f8
6 files changed
+264
-32
No files matched your search
@@ -151,3 +151,62 @@ int logits_gemm_xmx(const RadArgs* a, RadStream s) {
|
||||
}
|
||||
|
||||
} // namespace xe2
|
||||
|
||||
/* ------------------------------------------------------------------ the fp16 form, scaled */
|
||||
/* The same tiling over fp16 operands with a per-row and per-column factor on the way out:
|
||||
* y[m][n] = acc * rs[m] * cs[n]. For the m2xfp4 prefill (xe2_gemv_m2.cpp), whose weight is exact
|
||||
* in fp16 once scaled by its column's largest exponent and whose activation is fp16(a / R): fp16's
|
||||
* 2^-11 step beside bf16's 2^-8. A is [mpad, K] with mpad a multiple of 8 (padding rows zero);
|
||||
* rows past M are not written. N a multiple of 64, K of 16. */
|
||||
namespace xe2 {
|
||||
|
||||
int xmx_f16_scaled(sycl::queue& q, const sycl::half* ab, int64_t ars, const sycl::half* bb, int64_t brs,
|
||||
char* yb, uint32_t ydt, int64_t yrs, int64_t ycs, int64_t M, int64_t mpad, int64_t N,
|
||||
int64_t K, const float* rs, const float* cs) {
|
||||
using hf = sycl::half;
|
||||
const size_t gm = (size_t)((mpad + kTm * kSgs - 1) / (kTm * kSgs));
|
||||
const size_t gn = (size_t)(N / (kTn * kTiles));
|
||||
return submit([&] {
|
||||
q.submit([&](sycl::handler& h) {
|
||||
sycl::local_accessor<float, 1> stage(sycl::range<1>((size_t)kSgs * kTm * kTn), h);
|
||||
h.parallel_for(sycl::nd_range<2>{{gm, gn * kWg}, {1, kWg}},
|
||||
[=](sycl::nd_item<2> it) [[sycl::reqd_sub_group_size(kSub)]] {
|
||||
const sycl::sub_group sg = it.get_sub_group();
|
||||
const int s = (int)sg.get_group_linear_id();
|
||||
const int64_t m0 = ((int64_t)it.get_group(0) * kSgs + s) * kTm;
|
||||
const int64_t n0 = (int64_t)it.get_group(1) * kTn * kTiles;
|
||||
if (m0 >= mpad) return;
|
||||
auto ga = sycl::address_space_cast<sycl::access::address_space::global_space,
|
||||
sycl::access::decorated::no>(ab + m0 * ars);
|
||||
jm::joint_matrix<sycl::sub_group, hf, jm::use::a, kTm, kTk, jm::layout::row_major> ma;
|
||||
jm::joint_matrix<sycl::sub_group, hf, jm::use::b, kTk, kTn, jm::layout::col_major> mb;
|
||||
jm::joint_matrix<sycl::sub_group, float, jm::use::accumulator, kTm, kTn> mc[kTiles];
|
||||
for (int t = 0; t < kTiles; ++t) jm::joint_matrix_fill(sg, mc[t], 0.0f);
|
||||
for (int64_t k = 0; k < K; k += kTk) {
|
||||
jm::joint_matrix_load(sg, ma, ga + k, (size_t)ars);
|
||||
for (int t = 0; t < kTiles; ++t) {
|
||||
auto gb = sycl::address_space_cast<sycl::access::address_space::global_space,
|
||||
sycl::access::decorated::no>(bb + (n0 + t * kTn) * brs + k);
|
||||
jm::joint_matrix_load(sg, mb, gb, (size_t)brs);
|
||||
jm::joint_matrix_mad(sg, mc[t], ma, mb, mc[t]);
|
||||
}
|
||||
}
|
||||
float* mine = &stage[(size_t)s * kTm * kTn];
|
||||
auto ls = sycl::address_space_cast<sycl::access::address_space::local_space,
|
||||
sycl::access::decorated::no>(mine);
|
||||
const int lane = (int)sg.get_local_linear_id();
|
||||
for (int t = 0; t < kTiles; ++t) {
|
||||
jm::joint_matrix_store(sg, mc[t], ls, kTn, jm::layout::row_major);
|
||||
sycl::group_barrier(sg);
|
||||
for (int e = lane; e < kTm * kTn; e += kSub) {
|
||||
const int64_t r = e / kTn, c = e % kTn, m = m0 + r, n = n0 + t * kTn + c;
|
||||
if (m < M) rad_store_f32(yb, ydt, m * yrs + n * ycs, mine[e] * rs[m] * cs[n]);
|
||||
}
|
||||
sycl::group_barrier(sg);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace xe2
|
||||
Reference in new issue
Block a user