Skip to content

cuda: tf_situ_rows, SiTU in the core act_rows, sharing one body with the MXFP4 experts in common/act.cuh - #5817

Merged
ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/situ-act-rows
Dec 1, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/situ-act-rows

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

tf_situ_rows, a SiTU entry in core's act_rows, as #4926's answer asked: bf16 gate and up rows and the two betas as arguments, bf16 rows of beta tanh(g / beta) sigmoid(g) times lin tanh(u / lin) out, with #5385's arithmetic. Served bits do not change: the MXFP4 experts image is byte-identical at all five SMs, and act_rows gains only the new function, its 60 other functions' SASS unchanged. Nothing calls the entry yet; ERNIE 5.5's shared expert and layer 0's dense MLP will.

  • situ's body moves from experts.cuh to common/act.cuh as tf_common::situ; experts.cuh's situ rounds the sums to bf16 and calls it in the same statement order, so the routed epilogue and the dense rows run one body.
  • act_rows.cu's gated rows share glu_rows with an op: SiluMul for tf_swiglu_rows and tf_swiglu_rows_expf, Situ for the new entry, 8 values a thread and the 64-value sums as tf_swiglu_rows has them. ActRows.situ launches it through glu, which now takes the betas or null.
  • contract_act_situ.zig holds it to act_ref.situ within the contract's bound (20 fp32 steps, as the experts' up) at ERNIE's betas 4 and 25 and at 2 and 8, on ERNIE 5.5's widths 2,048 (the shared expert) and 14,336 (layer 0's dense MLP), its sums bit-equal to the fp32 tree. Three planted controls launch it with wrong arguments: the rows swapped, the up unclamped (linear beta 1e30), the betas swapped. Its launch records (256 threads, and 128 at 16 rows or fewer) are nvcc 13.0's, in act_situ_records.zig; docs/kernel-contract.md gains a paragraph.
  • MOSS-Image's and Inkling 2's SiTU-shaped forms stay where they are, as the answer says.

Searched first: no open pull request or issue adds a SiTU entry to act_rows or moves experts.cuh's situ (open pull requests and issues searched for "situ", "act_rows", "swiglu_rows" and "experts.cuh" on 2026-12-01; the one hit for "SiTU" is my #5578, the synthetic weights).

Checks on this head

  • Head commit: 29ccb771f8 (one commit on main 93a3172b5d). The GPU steps below ran on 220b23c636, which has this head's kernels: this head differs from it in a test's set initialization, the gradient-serving fixture's hash of experts.cuh, and two comments.
  • Lean checker (tools/pr_check.py --base 93a3172b5d): 88 problems on both, 0 new; import cycle edges 25 against 25, 0 new; cross-family edges 11 against 11 (1 allowed); 0 errors.
  • Tests run, with the command and pass, fail and skip counts (Zig 0.17.0, nvcc 13.0.88):
    • GB10 (sm_121): 220b23c636 and main 93a3172b5d, each checked out with an empty global cache and built alike, zig build compile-cuda-tests fatbins kernel-contract-fatbins -Dnvcc=... -Dsm=80,86,89,120,121 with address randomization off: 0 errors on both. Of 212 fatbins, 207 are byte-identical, experts_mxfp4 among them; act_rows gains tf_situ_rows at each SM with its 60 other functions' SASS unchanged (cuobjdump -sass); four (ernie5_5_hca, ernie5_5_index, glm_glue, glm_index) differ in bytes with no SASS function changed. tf-cuda-test kernel-contract-limits zig-out/fatbin: the ten tf_situ_rows lines PASS ... (record current) (35 registers at sm_80, sm_86 and sm_89, 34 at sm_120 and sm_121, 0 static shared bytes, bound 256); every other line is main's, where it reports 205 record stale launches in other families, the same on both. kernel-contract situ SiTU: 6 kernels pass gates 1-4, 5 controls red as planted; kernel-contract "cuda act": 16 kernels pass gates 1-4. On this head, from a checkout path of 40 characters (shorter ones trip the load-prefetch test, which load prefetch: the allocation-failure test refuses resizes, so it passes at any checkout path length #5772 fixes) with empty global and local caches, zig build -Dfixed-cpu: test-gradient-serving 1 of 1; test-kernel-contract 49 of 49 steps, 383 of 383 tests; test-inc4-rows-host 5 of 5; test-ernie5_5-contract-host 27 of 27; test-cuda-host 590 of 590 steps, 11,221 of 11,275 tests, 54 skipped.
    • Windows: zig fmt --check and zig ast-check on the 6 changed Zig files and git diff --check, clean; zig build -Dfixed-cpu compile-cuda-tests 12 of 12 steps; test-kernel-contract 49 of 49 steps, 383 of 383 tests (empty global and local caches); test-inc4-rows-host 5 of 5.
    • WSL 2 (x86-64): a fresh clone of this head: git diff --check clean; compile-cuda-tests 12 of 12; test-ernie5_5-host 58 of 60, 2 skipped; test-kernel-contract 49 of 49 steps, 383 of 383 tests; test-inc4-rows-host 5 of 5; test-gradient-serving 1 of 1; test-ernie5_5-contract-host 27 of 27; test-cuda-host 590 of 590 steps, 10,983 of 11,035 tests, 52 skipped (with an empty local cache; its first run, while this PC was also compiling, timed two health_test exchanges out at their 5-second poll); tools/zig/check_cuda_sources.py on act_rows.cu and experts_mxfp4.cu with clang++ 12 of 12; host_tests_test OK; CI's pytest -q -rs from the root: 1,030 passed, 122 skipped on this head and on main, the same skips.
  • CI: every job passes or is skipped on this head: fmt, zig, pytest, benchmark-clients and comfyui-moss-installer pass (runs 46615190832, No GPU, and 46615190946, Zig format); the rest are skipped.
  • Not run, and why: the contract on GPUs other than the GB10 (sm_121); the other four SMs by their limits records only; nvcc 13.3.

Receipt

  • Main against branch: no served path changes. The MXFP4 experts image is byte-identical at all five SMs, act_rows gains only tf_situ_rows with its other functions' SASS unchanged, and nothing calls the new entry yet.
  • Boxes it reaches: none served yet; written for ERNIE 5.5's shared expert and dense MLP (refs ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926), and Kimi K3's betas are the same.
  • New switch? None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: 29ccb771f8 (GPU steps on 220b23c636, the same kernels) on main 93a3172b5d; Zig 0.17.0, nvcc 13.0.88; a GB10 (sm_121), Windows and WSL 2 (x86-64); no checkpoint.
  • Paths and platforms the change reaches, which I ran and which I could not: the CUDA steps on the GB10 (sm_121); the host steps on the GB10, Windows and WSL 2; not the other four SMs on hardware (their limits records only), not nvcc 13.3, not macOS.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: n/a (the served experts image is byte-identical; the new entry is not served).
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): n/a (no served path changes).
  • Decode speed before and after, from tools/bench_openai.py: n/a (no served path changes).
  • Prompt speed before and after: n/a (no served path changes).
  • Licence of any new weights or drafter, or "n/a": n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: tf_situ_rows at ERNIE's betas 4 and 25 and at 2 and 8 (new; it replaces none, and the MXFP4 experts' SiTU ups keep their entries).
  • A planted control for each new kernel, and each one fails as planted: the rows swapped, the up unclamped (linear beta 1e30) and the betas swapped, all red as planted; the experts' up-unclamped control and MOSS-Image's stay red.
  • Each backend's SUMMARY line and exit status: SUMMARY 6 kernels: 6 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems (kernel-contract situ SiTU: the new entry's two, the MXFP4 experts' two SiTU ups and MOSS-Image's two) and SUMMARY 16 kernels: 16 pass gates 1-4, 0 fail, 0 known findings; 0 controls (kernel-contract "cuda act"), each exit 0 (CUDA on the GB10).
  • Chips I could not run: sm_80, sm_86, sm_89 and sm_120 (built, held to their limits records only).

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (the contract entries and their controls are new, the controls red as planted; a host test without a GPU checks the two served pairs of betas and one control a fault).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off (no served path changes).
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo (no served path changes).
  • No precision traded for speed. If the bits change, the description says which sums change and why (no served bits change: the experts image is byte-identical).
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled (no served path changes).

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu for doing this the way #4926 settled it, and for the full receipt. I read the head 29ccb771f8 against main.

  • The moved body is the old one. tf_common::situ (zig/kernels/cuda/common/act.cuh:25-29) has the same statements in the same order as the old situ, and sigmoid_rn (common/act.cuh:20) is the same expression the old body wrote out by hand. experts.cuh:96-99 still rounds g and u to bf16 before calling it, so epilogue_situ runs the same arithmetic. act_rows and experts_mxfp4 both build with -O3 alone (zig/build/cuda_kernels.zig:102 and :137), so expf and tanhf are compiled under the same flags in both images.
  • glu_rows (zig/kernels/cuda/act_rows.cu:46-66) keeps swiglu_rows's loads, the 8-value loop and the 64-value sums. tf_swiglu_rows and tf_swiglu_rows_expf pass SiluMul<false> and SiluMul<true> (act_rows.cu:75 and :83), which call silu_mul as before. The launcher adds the betas after n (zig/src/cuda/act_rows.zig:104), in the kernel's parameter order (act_rows.cu:87-90), and every other entry passes null, so their argument lists match main's.
  • Reach: nothing serves tf_situ_rows yet. Only the contract calls ActRows.situ (act_rows.zig:48). It's there for ERNIE 5.5's shared expert and layer 0's dense MLP, and a CUDA port of Kimi K3 could call it as it is.
  • experts.cuh now includes common/act.cuh (experts.cuh:6), so every experts image sees the new header. None of those files declares a name that clashes with tf_common's.
  • Rules: the lean check reports nothing in the changed files, and every touched Zig file is under 600 lines (contract_tests.zig is the largest at 574). There's no new switch. The experts.cuh pin (zig/tests/fixtures/gradient-serving.tsv:9) matches the file; act_rows.cu and common/act.cuh aren't pinned. The records are joined at registry_joins.zig:13, the group is registered at contract_tests.zig:376, and the host test is listed at cuda_row_contracts.zig:15. Each of the three controls goes red for its own reason, and the rows use common/reduce.cuh's helpers.
  • Provenance: this is your cuda experts: the mxfp4 format's up, a stored gate and up under SiTU, for ERNIE 5.5 #5385 body and our act_rows template, rearranged. I found nothing from another engine.
  • It merges cleanly with current main.

I have no asks. It's ready for our device check on a DGX Spark (GB10, sm_121):

  1. Build every fatbin from main and from this head at sm_80, 86, 89, 120 and 121, then compare the SASS of every image. experts_mxfp4 and the other images that include experts.cuh should match exactly. In act_rows, the existing functions should match too, with tf_situ_rows as the only addition. The four images whose bytes changed in your build (ernie5_5_hca, ernie5_5_index, glm_glue, glm_index) include none of the touched files, so we'll check whether a second build of main changes them the same way.
  2. Run the kernel contract for tf_situ_rows and the MXFP4 experts' SiTU ups, and "cuda act", with every control red, plus kernel-contract-limits on the new records.
  3. Run tf_swiglu_rows, tf_swiglu_rows_expf and the MXFP4 SiTU up on main and on this head with the same inputs, and check that the outputs match byte for byte.
  • Synthena

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Reviewed at this head on a GB10 (sm_121): every existing function in all 176 fatbins (sm_80, 86, 89, 120 and 121) has the same SASS as main, and tf_situ_rows is the only addition. The kernel contract for tf_situ_rows and the MXFP4 SiTU ups passed with its controls red, the act-rows test kept every row count's bits equal, and the new records match their live launch limits. This head's CI passed.

  • Synthena

Bizuayeu and others added 2 commits December 1, 2026 15:12
…iTU body moved to common/act.cuh

tf_situ_rows(gate, g_ld, up, u_ld, out, xs, n, beta, lin) turns bf16 gate and up rows into bf16 SiTU rows, beta tanh(g
/ beta) sigmoid(g) times lin tanh(u / lin), with the betas as arguments (ERNIE 5.5's 4 and 25, which Kimi K3 shares), 8
values a thread and the 64-value sums as tf_swiglu_rows has them. Its arithmetic is ashhart#5385's: the body moved from
experts.cuh to common/act.cuh as tf_common::situ, and experts.cuh's situ rounds the sums to bf16 and calls it in the
same statement order, so the MXFP4 experts image is byte-identical at all five SMs. act_rows' gated rows share
glu_rows with an op (SiluMul for tf_swiglu_rows and tf_swiglu_rows_expf, Situ for the new entry), and its other 60
functions' SASS is unchanged. ActRows.situ launches it through glu, which now takes the betas or null.

contract_act_situ.zig holds it to act_ref.situ within the contract's bound (20 fp32 steps, as the experts' up) at
ERNIE's betas and at 2 and 8, on ERNIE 5.5's widths 2,048 (the shared expert) and 14,336 (layer 0's dense MLP), its
sums bit-equal to the fp32 tree; three controls launch it with wrong arguments (the rows swapped, the up unclamped at
linear beta 1e30, the betas swapped). Its records are nvcc 13.0's, in act_situ_records.zig.
@ashhart
ashhart merged commit b0230d0 into ashhart:main Dec 1, 2026
0 of 2 checks passed
@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thank you @Bizuayeu. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants