Skip to main content

Module f32ref

Module f32ref 

Source
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§

F32LinearAccumulation
Reduction order used by linear_with_accumulation.
F32RmsNormArithmetic
Arithmetic used by rms_norm_with_arithmetic to form RMSNorm’s scale.
F32SiluArithmetic
Association used by silu_mul_in_place_with_arithmetic.
F32SoftmaxArithmetic
Normalization form used by softmax_rows_with_arithmetic.
F32Transcendental
Which sin/exp implementation an elementwise parity probe evaluates.

Functions§

apply_rope_in_place
Apply rotary embeddings to one head row in the rotate_half layout.
exp_with
Fills out with exp(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 Linear stores.
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/sin row 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 into gate.
silu_mul_in_place_with_arithmetic
Same operation as silu_mul_in_place, with an explicitly chosen f32 association.
sin_with
Fills out with sin(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.