Expand description
f32 reference kernels: the correctness baseline every optimized tier must reproduce.
These are deliberately the obvious implementations. They exist so that a SIMD or int8 kernel has something bit-comparable to be judged against (G1 > G2 — parity first, speed second), and so the first end-to-end forward can be brought up without any unsafe at all. Nothing here is on the hot path yet; nothing here should be “optimized” in place. When a fast tier lands it lands beside these, with a test asserting the two agree.
Accumulation is f32 to match the reference stack’s CPU fp32 tier. In particular, RMSNorm widens BF16 inputs to f32 and accumulates its variance in f32, exactly as the resolved QK-Norm contract requires.
Enums§
- F32Linear
Accumulation - Reduction order used by
linear_with_accumulation. - F32Rms
Norm Arithmetic - Arithmetic used by
rms_norm_with_arithmeticto form RMSNorm’s scale. - F32Silu
Arithmetic - Association used by
silu_mul_in_place_with_arithmetic. - F32Softmax
Arithmetic - Normalization form used by
softmax_rows_with_arithmetic. - F32Transcendental
- Which
sin/expimplementation an elementwise parity probe evaluates.
Functions§
- apply_
rope_ in_ place - Apply rotary embeddings to one head row in the
rotate_halflayout. - exp_
with - Fills
outwithexp(x)under the selected implementation. - gqa_
attention - Grouped-query attention for row-major f32 tensors.
- gqa_
attention_ head_ range_ with_ arithmetic - The scalar GQA loop restricted to
q_head_range, writing only those heads’ output spans. - gqa_
attention_ with_ arithmetic - Same operation as
gqa_attention, with selected softmax and dot-product reduction forms. - gqa_
attention_ with_ softmax - Same operation as
gqa_attention, with an explicitly selected softmax normalization form. - linear
- Row-major matrix-vector/matrix-matrix product in the layout PyTorch
Linearstores. - linear_
with_ accumulation - Same operation as
linear, with an explicitly chosen f32 dot-product reduction order. - mrope_
interleave - Collapse the three mRoPE axes into one
cos/sinrow using the checkpoint’s INTERLEAVED rule. - rms_
norm - Qwen3 RMSNorm:
x * rsqrt(mean(x^2) + eps) * weight, weight-only, no centering. - rms_
norm_ with_ arithmetic - Same operation as
rms_norm, with an explicitly selected reduction and scale calculation. - silu_
mul_ in_ place - SwiGLU’s elementwise half:
silu(gate) * up, written intogate. - silu_
mul_ in_ place_ with_ arithmetic - Same operation as
silu_mul_in_place, with an explicitly chosen f32 association. - sin_
with - Fills
outwithsin(x)under the selected implementation. - softmax_
rows - In-place row-wise softmax in f32, max-subtracted for stability.
- softmax_
rows_ with_ arithmetic - Same operation as
softmax_rows, with an explicitly selected normalization form. - torch_
cascade_ sum - The reference stack’s contiguous-inner-dimension f32 sum, transcribed operation for operation.