6 Commits
Author SHA1 Message Date
aneinanderandClaude Opus 5.5 9aef29661b libxe2: fused gated-attention prologue (qk_norm_rope_gate, qk_norm_rope_gate_kv_store)
The one-launch prologue that the qwen35 family (Qwen3.5, Qwen3.8), Qwen4-Exp, FishOmni and the MTP
heads request where a kernel library declares it (libr4d did; libxe2 did not, so those models ran
q_norm, k_norm, rope_q, rope_k and kv_store: five launches an attention layer). It splits the
interleaved [q|gate] projection per head, norms q and k, applies the partial NeoX rotary from the
cos/sin table rope_table already fills each step, and with _kv_store stores k and v.

docs/OPS.md requires it byte-identical to the unfused chain, so each step is libxe2's own:
xe2_rmsnorm's bf16 head-row norm (XE2_EXACT=1: libref's ascending sum, as xe2_rmsnorm then takes),
the bf16 rounding the norm stores, cos/sin as xe2_rope_table wrote them (xe2_rope's arithmetic), and
xe2_kv_store's conversion. A sub-group a (token, head), as qkv_norm_rope; that kernel is untouched.
The schemas are libr4d's. The _kv_store row declares its chain (qk_norm_rope_gate, kv_store) and both
rows describe their operands, so rad-kbench draws them and checks the fold byte for byte.
XE2_NO_FUSED_PROLOGUE=1 now hides these two rows as well: the A/B and an escape hatch.

rad-kbench fusion oracle: 28/28 byte-identical on Qwen3.5-9B and on Qwen3.8-27B; default fixture
2144/2144. Greedy A/B (400-token story, 2.4k and 382-token prompts), twice each, spec off: outputs
identical; Qwen3.5-9B w4a16 decode 58.3 -> 58.9 tok/s, Qwen3.8-27B int4 30.1 -> 30.4. Prefill
unchanged (the fused rows serve steps up to 64 tokens).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 11:50:39 +01:00
aneinanderandClaude Opus 5.5 0c7606423b libxe2: fused attention prologue (qkv_norm_rope, qkv_norm_rope_kv_store)
The one-launch prologue that Gemma 3, Gemma 4, Hunyuan v3 and the DFlash2 drafter use where a
kernel library declares it (libr4d did; libxe2 did not, so those models ran the unfused five or six
launches a layer). docs/OPS.md requires it byte-identical to the unfused ops, so each step is
libxe2's own: xe2_rmsnorm's bf16 head-row norm (its partition and reduce_over_group; XE2_EXACT=1
libref's ascending sum, as xe2_rmsnorm then takes), the bf16 rounding the norm stores, xe2_rope's
arithmetic on its frequency table, xe2_kv_store's conversion. A sub-group a (token, head), the head
staged in local memory for the rotary pairs. The schemas are libr4d's.

XE2_NO_FUSED_PROLOGUE=1 leaves the two rows undeclared, so an architecture takes its unfused chain:
the A/B, and an escape hatch.

Gemma 4 E2B: greedy outputs identical with and without (4 requests), decode 58.0 -> 58.6 tok/s.
A random Gemma 3 (v_norm 0): identical, 1570 -> 1600 tok/s. Default fixture 2144/2144.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 20:29:25 +01:00
aneinanderandClaude Opus 5.5 25c8fbd136 libxe2: qk_norm_rope, conv1d_dw, conv2d, attn_local_rel rows
The encoder towers' ops that had only a host kernel: on the SYCL backend every op runs on the card,
so a container carrying Gemma 4's vision tower (qk_norm_rope, blocks mode, v_norm) or its audio
conformer (conv2d subsampler, conv1d_dw, attn_local_rel) refused to start. qk_norm_rope also serves
GLM's vision tower (axial) and any QK-norm model that declares the fused op.

Each is libref's loop, a work-item an output (a (row, head) for qk_norm_rope and attn_local_rel),
for passes that run once a picture or clip. cu_seqlens stays on the card, so each work-item finds
its own segment.

rad-kbench, Gemma 4 E2B container: qk_norm_rope 80/80, conv1d_dw 64/64, conv2d 34/34,
attn_local_rel 64/64; default fixture 2144/2144. Gemma 4 E2B now serves on Intel: text and an
image request answer correctly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:28:38 +01:00
aneinanderandClaude Opus 5.5 ff4b7c9fb4 libxe2: rmsnorm_p, relu, logit_softcap, rel_sinusoid, pool_rows rows; rope to head_dim 512
Gemma 4 E2B did not start on Intel: five weightless ops had no device row (rmsnorm_p, the bare
value norm, in 15 bands; relu; logit_softcap; rel_sinusoid; pool_rows), and xe2_rope was selected
for its global layers (head_dim 512, proportional rope widened to the full head) and refused them
at launch: the frequency table held head_dim <= 256. It now holds 512, its component index as int8
so the by-value table stays at 1.25 KB.

rmsnorm_p is xe2_rmsnorm with the gain absent; the others are libref's chains (tanh, exp, sin, cos
in double rounded once; pool_rows' f32 sum in row order, rounded, times mult, rounded).

rad-kbench on the Gemma 4 E2B container: rmsnorm_p 20, relu 20, logit_softcap 4, rel_sinusoid 5,
pool_rows 6 cases ok, rope 300/300; default fixture rope 162/162.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:15:31 +01:00
claudeandClaude Opus 5.5 3158324bdb libxe2: every op Qwen3.8-27B-PARO-M2XFP4 needs, correctness first -- the 27B serves on the B65
Kernels, each libref's arithmetic in libref's order:
- gemm_nt_q at m2xfp4 (xe2_gemm_m2.cpp) with libref's m2 layout hooks, and givens_dense_quant
  (xe2_givens.cpp, the rotation in double as libref's)
- the gated delta net (xe2_gdn.cpp): gdn_conv_prep, gdn_conv_update, gdn_kkt_solve, gdn_chunk_scan,
  gdn_recurrent_update (per-candidate and anchor state forms), gdn_gated_rmsnorm,
  gdn_conv_recurrent_update; each work-item one iteration of libref's parallel loop, the
  per-(sequence, head) workspaces in a shared device workspace (xe2_common: workspace())
- rope's multi-component modes (mrope, imrope, axial) and rope_table
- logits_gemm over an fp8 128x128 joined head, gemm_nt_bias with its epilogue
- mul, sigmoid, scatter_rows, layernorm, grid_embed, attn_dense (the vision tower)
- dflash_conv and logit_rerank (plain and joined head) for the DFlash2 drafter

libref's gemm_m2 gains the parts (pb1/pb2) every other ParoQuant grid and libr4d's mx_parts
already define -- weight rows [0, e1), [e1, e2), [e2, N) read activation copies 0, 1, 2 side by
side -- since this model's fused projections are rotated per piece and the oracle declined them;
its shape hook widens a and a_scale by the part count. Both m2 arms now take the stored
codes-then-meta blob as the engine describes it, u8 [N, K], beside the shape hook's rank-1 form
(libref refused the engine's launch; only libr4d had been run on it).

rad-kbench on the fixture: every new row at rel_l2 0 (90 gdn/givens cases, 108 rope, 80
elementwise, 20 attn_dense, the drafter's and the heads'). On the B65 the model starts with every
op on the card and answers "The capital of France is" -> " Paris.\nThe capital of Germany is
Berlin.\nThe capital of Italy is" (greedy), at 0.1 tok/s: the correctness-first kernels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
2026-10-24 00:30:40 +02:00
claudeandClaude Opus 5.5 dc89eb45fb libxe2: rope, embed_lookup, gather_rows, cast
rope builds its frequency ladder on the host per launch exactly as libref's rope_freqs does (a
double pow, then YaRN or llama3 from rad_yarn.h) and takes cos and sin of the f32 angle in double on
the card, as libref does; positions reach 131072 at MiniCPM5's context. neox and gptj with one
position component; the row says so with a mode constraint and the launch refuses anything else by
name.

The gathers write a zero row for an index outside the table, libr4d's rule: libref instead checks
every index on the host before running, which a launch cannot do without waiting on its stream.

rad-kbench against libref: fixture 127/127 and MiniCPM5-2B 94/94, rel_l2 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
2026-10-23 16:05:59 +02:00