Repository navigation
Conversation
…d MLX's rounded rows addRmsTail extends addRmsH for Gemma 4's sandwich tails: an optional RMS norm on the branch before the residual add, an optional bf16 scalar on the sum (rounded first), and a rounding flag that gives each norm MLX's bf16(w * bf16(x * inv)). With no option set it is addRmsH itself, and the existing kernels' code is unchanged. The kernels are registered with the kernel contract: their own check compares every output with float64's value at the rounding points (a range over the fp32 inverse's spread), the 64-value sums bit for bit with the fp32 tree, and four controls each drop one rounding point.
|
Thanks @jschmied, the rounding order matches our Metal tails and the default path still calls I found two reference/checker fixes before we carry this onto 1.1.2. In
Please wrap the two new trailing comments over 120 columns, at Posted by Ash's AI Assistant Synthena |
bf16(-2^-135) gave +0 where bf16 rounding gives -0 (0x8000). The tests now compare u16 bits: signed zeros from underflow, subnormal ties, the normal boundary, overflow to both infinities, and the random fp32 sweep against the fp32 path's bits.
…or one-value ranges A range with an infinite end fell back to the float64 point's class: it accepted a zero below a finite lower end and refused the infinite end itself. Every range is now checked by its ordered ends (-0 below +0), a one-value range by its bits, NaN only for NaN. The control is the 64-value input-norm row whose first output's range is [largest bf16, +Inf].
|
Thanks @ashhart, both fixed in two new commits on top (
The receipt in the description is updated. |
…dits The 1.1.2 section had no entries for the contributed pull requests carried into this release, so neither their changes nor their authors reached the release notes. Add an entry for each, written from its commits: Flash Next's CUDA prompt tiles and structured output (#1046, #1062), --thinking-reserve, the long-loop guard and the --vision template diagnostic (#1064, #1075, #1076), GLM's Metal eh_proj tile and CUDA waiting ranks (#1066, #1053), M1's simdgroup cap (#1055), Nemotron's CUDA image and shared-window fixes (#1057, #1058), Qwen's live-row expert routing (#1047), the shared CUDA operators and contract fixture (#1056, #1068, #1070, #1071, #1073), the ROCm receipt, drafter and draft-count work (#1043, #1044, #1045), the ModelOpt recipe numbers (#1042), the Windows host build (#1034) and the session store's allocation-free rollback (#637). Thank #643's and #1060's reporters as the other entries thank theirs.
|
The CUDA bf16 residual-tail operators are included in 1.1.2 (https://github.com/ashhart/TensorFold/releases/tag/v1.1.2), with your original authorship retained. They support an optional branch norm, a layer scalar and MLX-style rounding steps. Closing this as carried, and thank you. It landed as 265d851, 159ae69 and 38cd73a. - Synthema, Ash's AI Assistant. |
What this changes
Step 1 of #1048 (agreed there: the rounding points are options on the shared operator, off by default):
normsgets what Gemma 4's layer tails need, as shared options of the bf16-residual norm(
addRmsH). Nothing calls them yet.Norms.addRmsTail(x, r, w, h, y, xs, rows, width, eps, .{ .round, .branch, .scalar }):branch: a weighted RMS norm onxbefore the residual add,h = bf16(r + bf16(norm(x) wb))(
post_attention_layernorm/post_feedforward_layernorm);scalar: one bf16 the rounded sum is multiplied by,h = bf16(bf16(r + b) * scalar)(layer_scalar);round: each norm in MLX's two roundings,bf16(w * bf16(x * inv)), asgemma4/glue.metal'sgemma_rms_looped,gemma_attn_tailandgemma_dense_tailcompute it; without it, one roundingbf16(x * inv * w).y = norm(h) wand the 64-value sums of the storedy(the next affine projection's group sums), asaddRmsH.addRmsTailisaddRmsH: the same kernel and the same launch.tf_add_rms_rows_bf16h_tail(one rounding a norm, a torch-style sandwich) andtf_add_rms_rows_bf16h_tail_round(MLX's), from one template inzig/kernels/cuda/norms_tail.cuhwhose bits areits rounding points.
norms.cu's existing code is unchanged, so are its kernels' SASS.core/norms_ref.zig: the tail in float64 at its rounding points (bf16_round.zigrounds float64 to bf16 once).Gemma 4 uses
round, withbranchand withoutscalarfor the attention tail, with both for the dense tail, andwith neither (no residual) for layer 0's input norm.
Receipt
b7ce8121(1.1.0) plus this branch (head2b6cab85); one DGX Spark (GB10, sm_121, CUDA 13.0, nvcc 13.0.88).No checkpoint needed; widths from
families/gemma4/config.zig(12B hidden 3,840, 31B 5,376, the 12B assistant's1,024). The weights' and scalars' ranges in the tests follow
mlx-community/gemma-4-12B-it-4bit(norm weights-143 to 193, layer scalars 0.0045 to 0.89).
tf-cuda-test norm-tail: six forms (input norm, attention tail, dense tail, scalar alone, all MLX; dense tail andbranch alone rounded once) at 3,840, 5,376 and 1,024, and the input norm and dense tail at the 16-byte tiles'
edges 64, 1,984, 2,048, 2,112 and 8,192, each at 1, 3, 17 and 64 rows. 9,963,516 outputs bit-equal to float64's
value at the rounding points; 10,244 (0.1 %) where an fp32 inverse RMS within its proven spread of float64's
can round a point either way, each within that range; 90,240 group sums bit-equal to the fp32 tree of the stored
outputs; every smaller row count's bits equal the 64-row call's; no options gives
addRmsH's bytes.gamma(42)/2 + 8 * 2^-24of float64's (the sum's tree halved by the root,four fp32 steps, the products by it); every other step of the tail is exact in fp32 or a sum of two bf16 values,
so the output is float64's at the rounding points evaluated at the two ends of that range.
docs/kernel-contract.md),tf-cuda-test kernel-contract(built-Dnvcc, ReleaseFast) on the GB10:SUMMARY 59 kernels: 59 pass gates 1-4, 0 fail, 0 known findings; 9 controls: 9 red as planted, 0 missed; 0 limit problems(main: 55 kernels, 5 controls).
zig/tests/cuda/contract_norms_tail.zig): each kernel checked on its outputyand on itsresidual
h, at Gemma 4 12B's and 31B's widths and the 2,048-value tile edges (7 shapes each).by its bits, so -0 and +0 differ; a range with an infinite end by its ordered ends; NaN only for NaN), the sums
bit-equal to the fp32 tree. The checker's own controls (
norms_tail_check.zig): a planted zero below a range[largest bf16, +Inf]is refused and its+Infend accepted (the 64-value input-norm row), and the negative,signed-zero and NaN ends likewise.
bf16_round.zigkeeps the sign of an underflow to zero (bf16(-2^-135)is0x8000), checked by raw bits atthe zero, subnormal, normal-boundary and overflow edges and over 100,000 random fp32 values.
the four rounding points), bf16 sums stay within it, so the spec states both (
sums.f16 = 40,sums.bf16 = 0).before the scalar, the output's normalized row), each red at gate 3 on its first shape.
tf-cuda-test kernel-contract-limitsover fatbins for sm_80, 86, 89, 120 and 121(94-95 registers, 147 on sm_120/121, 64 static shared bytes): every record current, 0 problems.
cuobjdump -sassof all ten existingnorms.cukernels (tf_rms_rows,tf_rms_rows_sums,tf_add_rms_rows,tf_rms_rows_bf16,tf_add_rms_rows_bf16,tf_add_rms_rows_bf16h,tf_add_rms_rows_bf16h_f32w,tf_gated_rms_rows_64/128/256) is identical tomain's on sm_80, 86, 89, 120 and121 (50 of 50), and their launchers are untouched.
2b6cab85thenormsandcontract_controlsfatbins for sm_80, 86, 89, 120and 121 are byte-identical to
88fd80f9's, and so is the SASS of every function in them (the twelvenorms.cukernels, the two tails included: 60 of 60; the controls: 55 of 55).
zig build testfrom an empty cache: 154/154 steps, 2,421 of 2,430 tests passed, 9 skipped (main:152/152, 2,413 of 2,422).
tf-cuda-test norms,norm-rows,norm-tail,act-rowspass.zig fmt --checkclean.lean_check.py: 503 findings, as onmain.no model calls it yet (step 8 of Proposal: Gemma 4 on CUDA, built on the shared CUDA operators (shared extensions first) #1048).
tf-cuda-test kernel-contractbuilt ReleaseSafe or Debug panics onmaintoo, incontract_ck_lane.zig:108(
zeros[0..self.x.len]past itspadded(n) * kbytes at the 128-row shape); ReleaseFast runs it. Not touched here.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Noserving path changes.)
SUMMARYline is in the receipt.