Skip to content

cuda ernie5_5: MultiMax on the head's fp32 logits, under the kernel contract - #5202

Merged
ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/ernie55-multimax
Nov 27, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/ernie55-multimax

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

A new ernie5_5_head image with ERNIE 5.5's MultiMax, tf_ernie55_multimax, which rewrites the head's fp32 logits in place as x + t0 relu(r0 - x) + t1 relu(x - r1) + t2 relu(r2 - x)^2 + t3 relu(x - r3)^2, with the four ranges and weights stored bf16 in the checkpoint (model.lm_head.multimax_ranges, multimax_ts). The vendor's Triton kernel turns fp fusion off (enable_fp_fusion=False), so each subtract, square, multiply and add rounds once, in its order (__fsub_rn, __fmul_rn, __fadd_rn), and relu keeps NaN and makes -0 a +0, as torch.relu does. Nothing launches it yet, so served output is unchanged.

  • zig/src/families/ernie5_5/multimax.zig replays those fp32 steps on the host (apply) and gives float64's value and magnitude (reference). multimax_test.zig pins the rules: an input where an fma would round differently, NaN and -0, the non-finite classes, and the bf16 widening.

  • The contract (zig/tests/cuda/contract_ernie5_5_head.zig, tf-cuda-test ernie5_5-head, also in kernel-contract) asks each output to be the replay's value, at a decode row and a 16-row verify window over the 201,216-logit vocabulary and over a TP=2 rank's half. Float64's bound covers eight roundings. Gate 4 runs whole logits with whole ranges and power-of-two weights, where every step is exact (sums f16 0, bf16 0: five terms a logit is no sum long enough to tell fp32 from half). There are two planted controls: each term's multiply and add fused into an fma, and the last term's square dropped.

  • The records (zig/src/core/contract/ernie5_5_records.zig), the image in cuda_kernels.zig and kernels.zig, and gradient-serving.tsv's re-pin of zig/src/cuda/kernels.zig.

  • Issue: Refs ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926. The gate is the one set there for each ERNIE kernel (ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment): "Each kernel also comes one to a PR, registered with the kernel contract, with its rounding points and sum order written down, an FP64 bound for that order and planted controls.").

  • Stacked on: main (eff4e5b754); one commit: 19 files, 423 insertions, 2 deletions.

  • atc overlap --json: atc 0.9.4 with ATC_READ_ONLY=1 and --base c21d201714, run in this tree on 2026-11-26 at 14:39 UTC: complete: false (otherPullRequestsLimit, pullFilesUnavailable, pullRequestsLimit, timeLimit), 40 pull requests in its working tree's rows, 5 conflicts, 5 clean and 30 unknown. conflict_delta (each open pull request merged by git merge-tree with main and with this head, conflicting files and hunks compared): over the 256 open pull requests on 2026-11-26, this commit with its two registration lines where they first stood added a conflict to 9, 7 of them at the image's line in zig/build/cuda_kernels.zig. That line now follows hy4_ihc_fused, and the image() line in zig/tests/cuda/contract_limits.zig follows zonos3's: there a 3-way merge of the file against every open pull request that touches it adds no conflict. Rerun after the move for those 9 only (not a new pass over every open pull request), it adds one to 3, CUDA: native TFQ3 (3/4/5-bit 2D-FWHT) runtime + drafters for Qwen3.8-27B, GLM-5.3-Flash, and Flash Next #4986 and cuda: sparse gather attention over listed cache rows (Kolibri 1.1, slice 1 of #4846) #5166 (both since landed) and Inkling-2-Mini: Serve on two GB10s with images and 1M context window #5059, each on gradient-serving.tsv's one pin line for zig/src/cuda/kernels.zig, which each of them re-pins too (Inkling-2-Mini: Serve on two GB10s with images and 1M context window #5059's head had moved between the two runs).

Checks on this head

  • Head commit: 648f48ec3b cuda ernie5_5: MultiMax on the head's fp32 logits, under the kernel contract. It was rebased onto main c21d201714 after cuda: sparse gather attention over listed cache rows (Kolibri 1.1, slice 1 of #4846) #5166 landed and again onto eff4e5b754 after CUDA: native TFQ3 (3/4/5-bit 2D-FWHT) runtime + drafters for Qwen3.8-27B, GLM-5.3-Flash, and Flash Next #4986 landed; each time the one conflict was gradient-serving.tsv's pin line for zig/src/cuda/kernels.zig, re-pinned with both notes. The GB10 and WSL runs below are on 65eca9a14d, the head before the second rebase, and the code has not changed since; on this head, zig build compile-cuda-tests 12 of 12 steps, test-gradient-serving 1 of 1 and pr_check 0 errors (Windows).
  • Lean checker (tools/pr_check.py --base eff4e5b754 --pr 5202): 123 problems on main and 123 on this head, 0 new; 0 errors. The 123 are inherited from main.
  • Tests run, with the command and pass, fail and skip counts (Zig 0.17.0, nvcc 13.0.88):
    • GB10 (sm_121), this commit checked out with an empty global cache, zig build compile-cuda-tests fatbins kernel-contract-fatbins -Dnvcc=... -Dsm=80,86,89,120,121: 0 errors. On the GPU, tf-cuda-test kernel-contract-limits zig-out/fatbin gives the five tf_ernie55_multimax lines PASS ... 12 registers, 0 static shared bytes, bound 256 (record current) (its other lines are main's: see the receipt); tf-cuda-test ernie5_5-head passes gates 1-4 with both controls red as planted, and kernel-contract ernie5_5 the same (below); zig build test-kernel-contract 343 of 343 passed; test-ernie5_5-host 16 of 18, 2 skipped; test-gradient-serving 1 of 1; head.cu's PTX, 33 compiles at each of compute_80 and compute_86 with address randomization on and off, one form at each.
    • Windows: zig fmt --check and zig ast-check on the 15 changed Zig files; zig build test-ernie5_5-host 16 of 18 passed, 2 skipped (the skips are main's).
    • WSL 2 (x86-64), on this tree and on main c21d201714: git diff --check clean; zig build compile-cuda-tests 12 of 12 steps; test-gradient-serving 1 of 1; test-ernie5_5-host 16 of 18, 2 skipped; tools/zig/check_cuda_sources.py on head.cu with clang++ 6 of 6; host_tests_test OK; CI's pytest from the root (-q -rs) 856 passed, 116 skipped, 827 subtests passed on both trees, the same skips as main's.
  • CI: green on 648f48ec3b: fmt, zig, zig-b, zig-windows, zig-macos-dev-tools, pytest (857 passed, 115 skipped, 827 subtests passed; the run in WSL 2 above has 856 and 116, and the CI log does not print skip reasons), release-paths (ubuntu-24.04), comfyui-moss-installer and both benchmark-clients jobs passed; host-nightly-linux and host-nightly-macos were skipped. The annotations are GitHub's Node.js 20 deprecation warnings and a macOS runner queue notice.
  • Not run, and why: the contract on GPUs other than the GB10 (sm_121); the other four SMs are covered by their limits records only. No served path, since nothing launches the kernel.

Receipt

  • Main against branch: n/a. Nothing launches tf_ernie55_multimax, so no served token or byte can change; the new image is the only fatbin added. On the GB10, main's tree (c21d201714) and this one built the same way (empty global cache, five SMs): the fatbins that differ are glm_glue and glm_index, which differ between any two builds (and moe can, whose router tiles' PTX follows address randomization, CUDA build: nvcc 13.0.88 gives the router-tiles entries different PTX between identical compiles, about one in ten #5123; it did not this time); ernie5_5_head is the image this commit adds. kernel-contract-limits gives both trees the same 186 stale records and the same RED and FAIL lines, apart from this tree's five tf_ernie55_multimax lines.
  • Boxes it reaches: none served yet; it is written for ERNIE 5.5's head (refs ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926).
  • New switch? None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: 65eca9a14d on main c21d201714 (this head is the same change on eff4e5b754); Zig 0.17.0, nvcc 13.0.88; one GB10 (sm_121); no checkpoint (synthetic logits).
  • Paths and platforms the change reaches, which I ran and which I could not: the kernel on sm_121 through the contract; sm_80, 86, 89 and 120 by their limits records only.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: n/a (no served path).
  • 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).
  • Decode speed before and after, from tools/bench_openai.py: n/a (no served path).
  • Prompt speed before and after: n/a (no served path).
  • 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_ernie55_multimax (new; replaces none), records for sm_80, 86, 89, 120 and 121 in zig/src/core/contract/ernie5_5_records.zig.
  • A planted control for each new kernel, and each one fails as planted: tf_ctl_ernie55_multimax_fma (each term's multiply and add fused) and tf_ctl_ernie55_multimax_drop_square (the last term's square dropped), both red at shapes ("output leaves its signed pointwise interval").
  • Each backend's SUMMARY line and exit status: SUMMARY ernie5_5 head: 1 kernels, 1 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed, exit 0; kernel-contract ernie5_5: (filtered) SUMMARY 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems, exit 0. CUDA only (no HIP, Metal or XPU image).
  • Chips I could not run: sm_80, 86, 89 and 120 GPUs (their limits records come from the fatbins).

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 host tests need only Zig; the contract's controls go red as planted; without a GPU or -Dnvcc the CUDA steps are not built, as for every image).
  • 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 (nothing launches the kernel yet).
  • 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 (each step rounds once in the vendor's order; no sums change).
  • 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).

Bizuayeu and others added 2 commits November 27, 2026 01:31
…ontract

ERNIE 5.5 rewrites its head's fp32 logits in place as x + t0 relu(r0 - x) + t1 relu(x - r1) + t2 relu(r2 - x)^2 +
t3 relu(x - r3)^2, with the four ranges and weights stored bf16. The vendor's Triton kernel turns fp fusion off, so
tf_ernie55_multimax (ernie5_5/head.cu, a new ernie5_5_head image) rounds each subtract, square, multiply and add once
in its order (__fsub_rn, __fmul_rn, __fadd_rn), and relu keeps NaN and makes -0 a +0 as torch.relu does.
ernie5_5/multimax.zig replays those fp32 steps on the host and gives float64's value; the contract asks each output
to be the replay's value at a decode row and a 16-row verify window over the 201,216-logit vocabulary and over a TP=2
rank's half, and gate 4 runs whole logits with whole ranges and power-of-two weights, where every step is exact. Two
planted controls, each term's multiply and add fused into an fma and the last term's square dropped, go red. Nothing
launches it yet. gradient-serving.tsv re-pins zig/src/cuda/kernels.zig.
@ashhart
ashhart force-pushed the pr/ernie55-multimax branch from 648f48e to 7add436 Compare November 27, 2026 01:31
@ashhart
ashhart merged commit 89e47f7 into ashhart:main Nov 27, 2026
2 of 12 checks passed
@ashhart

ashhart commented Nov 27, 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