Expand description
from_qwen_ops — every op of an authored transformer forward, lowered as a COMPOSITION of the closed
compute algebra: chains of ComputeOp::Generic and ComputeOp::MatmulTiles, and nothing else.
★ NOT ONE NEW ComputeOp. Rope, silu, sigmoid, gelu, decay, l2norm, transpose, a causal conv ring, a
Gated-DeltaNet step and GQA attention all lower through this file, and spatial_algebra_lock’s frozen
per-printer arm counts do not move for any of them. That is the campaign’s whole claim, and it holds
because B-P3 made the pieces general: a reduction is an ITERATOR KIND, a broadcast is an ABSENT TERM, a
transform is an SfpuKind, a piecewise region is a Select on an AXIS, and an access map is a signed
FLAT affine offset rather than one term per axis.
── The layout contract of a composed program ────────────────────────────────────────────────────────
★ EVERY ACTIVATION IS FLAT: 1 × n. This is not a convenience, it is what makes composition possible
at all. An ElemAccess is a flat offset into a page read as tile.rows × (page_tiles · tile.cols), so
element p of a 1 × n tensor is at offset p — the SAME number the language’s flat item p uses.
Give the same tensor a 2 × 4 shape in one section and a 1 × 8 shape in the next and the two
sections disagree about where element 4 lives, with no affine map able to reconcile them (the
conversion needs p / cols, which is not affine in p). Flat is the one layout every op can both
produce and consume.
★ A 2-D VIEW IS A BAND, NOT A RESHAPE. Where an op is per-head — rope’s rotations, l2norm across
heads, a GDN head’s memory — the heads are contiguous RANGES of the flat column axis, and a range is
a Pred::AxisLt on a CONSTANT. So one Generic computes every head by nesting one Select per head
(banded), and inside head h’s band an operand that is indexed per-head is read through that
head’s own base (c - h·width), while a per-head SCALAR is read through a CONSTANT map: the
reduction that produced it broadcast it across the whole of its tile row, and inside one band the
row is fixed. No divisibility, no reshape, no gather.
Functions§
- attention_
reads_ dense - Whether an attention of
hquery heads overkvK/V heads, keyshdand valuesvdwide, reads its K and V as DENSE tiles ontarget— the flash form’s cache layout. A table an attention reads dense is written dense too, so this is the one place the two agree. - blocked_
rms_ norm - compute_
shapes - The compute shapes a program uses, named — for a ledger row or a refusal.
- from_
argmax t = argmax(X) + 1— anArgMaxfold (first maximum, ties to the lowest index: the VM’s>scan) onto the integer datapath, then LOGOS’s 1-based count.- from_
attention - GQA attention of a block of query rows over a cache of
lrows:score[j] = (q·k_j)/√hd, row-softmax, then the weighted V sum — THREE sections, because a softmax cannot be oneGeneric(its maximum and its denominator are reductions whose results the next stage broadcasts back). One row is decode’s single query; a causal block ofTrows is a prefill chunk’s queries, rowrattending one position past rowr − 1. - from_
causal_ conv Y[c] = Σ_t CS'[t, c]·WC[t, c]whereCS' = shift(CS) ← X— the depthwise causal conv1d over ataps-deep decode ring, as TWO sections.- from_
decay y[i] = (1 + e^(ar[i] + dt[i]))^(alog[i])— Gated DeltaNet’s forget gate.- from_
full_ attention C = full attention(Q, K, V)overtpositions andhheads —tquery rows ofhheads, each reading its own K/V head and attending over alltpositions. Unmasked, as the vision tower’s block is: every row sees every position.- from_
gated_ delta - The Gated DeltaNet step over
hvvalue heads readinghkkey heads at head dimd:u = S·k,S ← α·S + β·(v − α·u)·kᵀ,o = S·q / √d, RMSNorm’d, scaled byGN, gated bysilu(z). - from_
gelu y = gelu(x)— ggml’s tanh approximation in its one-exponential formx / (1 + e^-2z)withz = √(2/π)·(x + 0.044715·x³), exactly as the parser desugars it (same arrangement, same tails).- from_
head_ matmul Y = X matmul W across H heads— the weighted-sum shape: the folded axis is the ROW (eover a head’sainputs), the flat output columnc = u·b + rfor unitu(rowu / H, headh = u mod H), and each unit’s band readsX[u·a + e]andW[(h·a + e)·b + c − u·b].- from_
head_ slice P = the first|last K of every N of X— groupg’sKelements fromfromland at[g·K, (g+1)·K): one band per group, each an affine readX[c + g·(N − K) + from].- from_
int_ clamp y = min(max(x, LO), HI)— saturation into[LO, HI].- from_
int_ requant y = (x · M) >> S— an int8 model’s requant: the exact product, then an arithmetic shift.- from_
join J = A joined with B across H heads— unitu(rowu / H, headu mod H) holds itshaelements ofAthen itshbofBat[u·(ha + hb), (u+1)·(ha + hb)): two bands per unit,A[c − u·hb]thenB[c − (u+1)·ha].- from_
l2norm y[r, i] = x[r, i] / sqrt(Σ_i x[r, i]² + 1e-6)overrowsheads ofcols— per-head L2 normalization on a FLAT1 × rows·colstensor.- from_
lut_ attention C = lut attention(Q, K, V)— an int8 model’s single-query attention, integer throughout, in THREE sections: the scoress = q·k_jover the cache; per head, the weightsw_j = E[clamp(((max − s_j)·M) >> S, 0, n − 1)]for the positions attended and 0 past them; and the context⌊Σ_j w_j·v_j / Σ_j w_j⌋. A masked position is fenced off only where it could change an answer — the maximum and the weights — and the sums need no mask: a weight of 0 adds nothing. Every value the masked step computes is one the unmasked step could: a masked position folds into the maximum as the head’s first score, which everyP ≥ 1attends, so no sentinel widens what the maximum holds.- from_
moe - The Mixture-of-Experts FFN — route
xto its top-kofneexperts and combine their SwiGLUs by the renormalized router weight: - from_
relu y = max(x, 0), in the tensor’s element kind.- from_
rope - RoPE-NEOX over
hheads ofhddims, rotating each head’s leading2·halfdims as(i, i+half)pairs and passing the remaininghd − 2·halfthrough — Qwen3.8’s partial rotary. - from_
row_ gather x[j] = T[lo + j]— the embedding lookup: rowindex(1-based) of a flatrows·colstable.- from_
row_ norm_ flat - The COMPOSITION-LAYOUT twin of
super::from_tensor_op::from_fused_row’s RMSNorm: the same chain (square → fold → rsqrt-once → rescale → per-column weight), over a FLAT1 × rows·colstensor instead of arows × colsone. - from_
rows_ gather X = rows I of T— the block gather: rowkofXis rowI[k](1-based) of a flatrows·colstable, for every index ofIat once, in ONE section;Xis written as flat rows (the layout pass bridges it once where the program laysXout as a matrix).- from_
scale y = x·C— one multiply by the program’s constant.- from_
set_ row Set row index of T to S— the KV-cache append, as ONE rewrite of the carried table:T'[c] = (lo ≤ c < lo + cols) ? S[c − lo] : T[c].- from_
sigmoid y = sigmoid(x)—1/(1 + e^-x), the reciprocal of the silu denominator. No new SFPU kind:ExpandRecipalready exist and the composition of the two IS the sigmoid.- from_
silu y = silu(x)—x / (1 + e^-x), one fused SFPU kind.- from_
softcap y = C·tanh(x/C)— each element soft-capped (capped’s form: one exponential and one reciprocal).- from_
transpose Kt[j·rows + i] = X[i·cols + j]— a TRANSPOSE IS A MAP, not an operator.- full_
attention_ reads_ dense attention_reads_densefor a full attention, whose query heads read K/V heads one to one.- is_
closed_ algebra - Every compute stage of a composition is one of the CLOSED algebra’s two shapes — the property
each_composition_is_a_chain_of_the_closed_algebraasserts, exposed so a lock and a ledger read the same predicate rather than two copies of it. - row_
needs_ blocking - How many tiles of one row a single site may hold resident. A flat section keeps its whole row in
local memory, which is free while the row is a handful of tiles and impossible once it is not: at
Qwen3.8’s real
d = 5120a row is 160 tiles against an accumulator budget of eight, and the whole-row form is refused asAccTilesExceededlong before local memory is consulted.