Repository navigation
Conversation
tf_geglu_rows computes mlx_lm's gelu_approx(gate) * up as MLX's bf16 ops (Gemma 4's MLP), and tf_swiglu_rows_round SwiGLU in tf_draft_swiglu's bf16 steps (Gemma 4's DFlash drafter), both with the 64-value group sums of the stored outputs. swiglu keeps its kernel and launch. Both are registered with the kernel contract: every output against float64's value at the rounding points (a range over tanhf's or expf's ulps), the sums bit for bit with the fp32 tree, and twelve controls each drop one rounding point.
jschmied
force-pushed
the
cuda-act-gelu
branch
from
October 19, 2026 15:29
ac645ef to
9f98fd9
Compare
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.
This was referenced Oct 19, 2026
ashhart
added a commit
that referenced
this pull request
Oct 21, 2026
…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.
Owner
|
The shared CUDA act_rows GeGLU and rounded SwiGLU operators are included in 1.1.2 (https://github.com/ashhart/TensorFold/releases/tag/v1.1.2), with your original authorship retained. They follow MLX-style bf16 rounding steps. Closing this as carried, and thank you. It landed as 42a7f76 and 8ef345b. - Synthema, Ash's AI Assistant. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Includes
core/bf16_round.zigwith #1056's sign fix (an underflow to zero keeps its sign, checked by raw bits), so the four steps share one identical file.Step 2 of #1048 (beside #1056; the rounding steps are options on the shared operator, off by default, as agreed there):
act_rowsgets the two activations Gemma 4 needs in MLX's bf16 steps. Nothing calls them yet.ActRows.geglu:bf16(gelu_tanh(gate) * up)as mlx_lm'sgelu_approx(gate) * upin MLX's bf16 ops, thearithmetic of
gemma4/glue.metal'sgemma_geglu(Gemma 4's MLP):x^3,c1 x^3,x + c1 x^3,c0 (...),tanh,0.5 x,1 + tanh, their product, each rounded to bf16, withc0andc1as bf16.ActRows.swigluRound: SwiGLU intf_draft_swiglu's bf16 steps (exp(|g|),1 + e, its reciprocal, the sigmoid,g * sigmoid, each rounded), asgemma_draft_swiglucomputes it for Gemma 4 31B's DFlash drafter(
families/gemma4/dflash.zig).swiglu's rows (gate and up at their strides,[gate | up]as a fused projection writes them) and writethe 64-value sums of the stored outputs.
swiglukeeps its kernel and its launch.tf_geglu_rowsandtf_swiglu_rows_round, fromzig/kernels/cuda/act_round.cuh, whosekeepmaskholds the rounding points (a constant in the served kernels).
act_rows.cu's existing code is unchanged.core/act_ref.zig: both in float64 at their rounding points (bf16_round.zigrounds float64 to bf16 once).Not here: the Metal kernel's interleaved 16-column gate/up layout (
IL); a CUDA family lays gate and up out as halves.Receipt
d1018b31(1.1.1) plus this commit; one DGX Spark (GB10, sm_121, CUDA 13.0, nvcc 13.0.88).No checkpoint; widths from
families/gemma4(12B MLP 15,360, 31B 21,504, the 31B DFlash drafter's 10,752, the 12Bassistant's 8,192).
tf-cuda-test act-rows: GeGLU at 15,360 and 21,504 (fused and padded rows) and 8,192, the SwiGLU steps at10,752 (both layouts), both at the block edges 64, 960, 1,024, 1,088, 2,048 and 2,112, each at 1, 3, 17 and 64 rows
(128- and 256-thread blocks). 7,553,014 outputs bit-equal to float64's value at the rounding points, 10 within
the range
tanhf's orexpf's 2 ulps allow; 118,016 group sums bit-equal to the fp32 tree; every smaller rowcount's bits equal the 64-row call's.
tanhf,expfand the division is exact in fp32 for bf16 operands (x^3and each product oftwo bf16 values) or a sum of two bf16 values, so the output is float64's at the rounding points with those three
values taken at the ends of their ulps (2^-21 either way).
docs/kernel-contract.md),tf-cuda-test kernel-contract(built-Dnvcc, ReleaseFast) on the GB10:SUMMARY 87 kernels: 87 pass gates 1-4, 0 fail, 0 known findings; 19 controls: 19 red as planted, 0 missed; 1533 limit problems(main: 85 kernels, 7 controls, the same 1,533 limit problems: main's own records, such as the pending ones of
act_rows' existing kernels; this change adds none).zig/tests/cuda/contract_act_round.zig) at the four Gemma widths, the row edge at 16 (the blocksize switch) and the 1,024-value block edges (12 shapes each).
infinities as float64's), the sums bit-equal to the fp32 tree. Gate 4 is N/A (no sum in an output; the group sums
are checked bit for bit instead).
tf_ctl_act_round, run with every rounding point but one, twelve times (seven GeGLU points,five SwiGLU points;
0.5 xis exact for a bf16x, so it has none): each red at gate 3 on its first shape.tf-cuda-test kernel-contract-limitsoverfatbins for sm_80, 86, 89, 120 and 121 (30-34 registers), in
core/contract/gemma_cuda_records.zig(registry.zigwould pass 600 lines): every record current; the run's other output is main's line for line (877 stale records).
cuobjdump -sassoftf_swiglu_rows,tf_gate_rows,tf_group_sums_rowsandtf_dconv_rowsis identical tomain's on sm_80, 86, 89, 120 and 121 (20 of 20);swiglu's launch passes thesame arguments to the same kernel.
zig build testfrom an empty cache: 213/213 steps, 2,964 of 2,978 tests passed, 14 skipped (main:211/211, 2,959 of 2,973).
tf-cuda-test act-rows,norm-rows,normspass.zig fmt --checkclean.lean_check.py: 444 findings, as onmain.no model calls it yet (steps 8 and 11 of Proposal: Gemma 4 on CUDA, built on the shared CUDA operators (shared extensions first) #1048).
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Noserving path changes.)
SUMMARYline is in the receipt.