libxe2, arch/common: silu_mul for 4-bit down projections, float exp at the tie rule; head-row norms vectorized; attention SLM by gqa

- Under Geom::plain_norm a down projection that reads the bf16 plane and no codes (w4a16 /
  w4a8i8 quantise their own activation) takes `silu_mul` instead of gated_quant_fp8 (the E4M3
  pass nobody read: 17 us a call, 64 a round).
- silu_mul: float exp, libref's double chain again only near a bf16 tie (near_bf16_tie, as the
  gdn activations): op oracle 300/300 bit-identical at tolerance 0.
- rmsnorm's bf16 head rows (n = 128..512): a lane its contiguous slice by 16-byte loads (16 us ->
  a few us a q / k norm call). rad-kbench rmsnorm 240/240.
- the flash kernel's staged queries sized for gqa <= 8 (24 of 64 KiB a work-group).

Greedy decode proxy (depth 5, mtp4, draft vocab 131072): 74.3 -> 81.2 tok/s. KL against the
exact reference 0.00231 (was 0.00239), top-1 96.70%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-11-02 02:32:05 +01:00
1 parent 2d2356ad4b
commit f26eec2633
4 files changed
+63 -7

No files matched your search

+47
View File
@@ -168,6 +168,53 @@ int rmsnorm(const RadArgs* a, RadStream st) {
* decode norm's ~40); XE2_EXACT=1 keeps it (below). Rows up to 512 wide (the per-head q / k
* norms) take a sub-group each, wider ones a work-group. */
if (!exact_only()) {
/* bf16 head rows (n = 128 .. 512, a multiple of 128): a lane its n / 16 contiguous
* elements by 16-byte loads, a sub-group a row (the generic form below issues a dependent
* load an element: ~16 us for Qwen3.8's q / k norms at a verify step). */
if (n <= 512 && n % 128 == 0 && x.dtype == RAD_BF16 && y.dtype == RAD_BF16 && x.pitch % 8 == 0 &&
y.pitch % 8 == 0 && rad_ptr_aligned(x.base, 16) && rad_ptr_aligned(y.base, 16) &&
(!g.base || ((g.dtype == RAD_F32 || g.dtype == RAD_BF16) && g.stride == 1))) {
using V8 = sycl::vec<uint16_t, 8>;
constexpr int64_t kRowsWg = (int64_t)kWg / kSub;
const int nv = (int)(n / 128); /* 16-byte vectors a lane: 1 .. 4 */
return submit([&] {
syclex::nd_launch(*q, sycl::nd_range<1>{(size_t)((rows + kRowsWg - 1) / kRowsWg) * kWg, kWg},
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
const sycl::sub_group sg = it.get_sub_group();
const int64_t r = (int64_t)it.get_group(0) * kRowsWg + (int64_t)sg.get_group_linear_id();
if (r >= rows) return; /* uniform over the sub-group */
const int64_t l = (int64_t)sg.get_local_linear_id();
float v[32];
float ss = 0.0f;
#pragma unroll
for (int u = 0; u < 4; ++u) {
if (u >= nv) break;
const V8 w = *(const V8*)((const uint16_t*)x.base + r * x.pitch + (l * nv + u) * 8);
#pragma unroll
for (int j = 0; j < 8; ++j) {
v[u * 8 + j] = sycl::bit_cast<float>((uint32_t)w[j] << 16);
ss += v[u * 8 + j] * v[u * 8 + j];
}
}
ss = sycl::reduce_over_group(sg, ss, sycl::plus<float>());
const float s = 1.0f / sycl::sqrt(ss / (float)n + eps);
#pragma unroll
for (int u = 0; u < 4; ++u) {
if (u >= nv) break;
V8 o;
#pragma unroll
for (int j = 0; j < 8; ++j) {
const int64_t i = (l * nv + u) * 8 + j;
const float gw = !g.base ? 1.0f
: (g.dtype == RAD_F32 ? ((const float*)g.base)[i]
: sycl::bit_cast<float>((uint32_t)((const uint16_t*)g.base)[i] << 16)) + wadd;
o[j] = rad_f32_to_bf16(v[u * 8 + j] * s * gw * mult);
}
*(V8*)((uint16_t*)y.base + r * y.pitch + (l * nv + u) * 8) = o;
}
});
});
}
if (n <= 512) {
constexpr int64_t kRowsWg = (int64_t)kWg / kSub;
return submit([&] {