Repository navigation
cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract - #5301
Conversation
e588459 to
6bd6331
Compare
6bd6331 to
01f035e
Compare
01f035e to
d87710b
Compare
|
Thanks, @Bizuayeu. The Sinkhorn sequencing, collapse rounding and declared operation bounds are consistent, and the DSA key work underneath shows no static blocker. Keeping the mHC mixes as fp32 products, rather than rounding inputs to TF32 the way the vendor's GEMM does, is the right choice here: we don't add rounding below what the checkpoint gives us, and the description states the difference plainly. No change is needed for that. This one lands after #5211 and #5243 below it in the stack; #5211 has one malformed-count fix requested. No rebase is requested, and no device run is promised here.
|
d87710b to
de335c8
Compare
|
Thank you, @Bizuayeu. The mHC pre-side arithmetic looks right: the FP32 mixes, the Sinkhorn sequence, the collapse rounding and the declared operation bounds are consistent, and no change is needed to the FP32-product choice. This branch still carries an older copy of #5211. The interior-count case there (for example After the restack, the remaining checks are on our side:
|
de335c8 to
0336d79
Compare
Thanks for the restack. In case it saves you a run, I took those four on a GB10 at the restacked head
The description has the lines, with |
0336d79 to
80f8280
Compare
9b788b5 to
a749ab3
Compare
a749ab3 to
ed56fcb
Compare
…apse's RMSNorm, under the kernel contract tf_ernie55_mhc_pre, in a new ernie5_5_mhc image, runs a row of ERNIE 5.5's 4 residual streams through vLLM-ERNIE's mHC pre step: the 24 mixes against fn's float32 rows (a thread's 64 terms in one fma chain, the warp's butterfly, the 8 warps' partials in order) times ERNIE's mix RMS, 1 / (sqrt(mean) + eps); pre, post (2 sigmoid) and comb (each row's softmax plus hc_eps, then hc_sinkhorn_iters rounds of column and row sums); then the collapse sum_s pre_s x_s, its RMSNorm from the unrounded sums' squares, and the norm's weight times the bf16 collapse, rounded to bf16 once. GLM's finish in common/mhc.cuh takes the mix RMS from its caller, but it also reads fn in bf16, squares the rounded collapse and rounds the normed value before the weight, so ERNIE's rounding points need their own body. The vendor's mixes are a TF32 GEMM; these are fp32 products of bf16 x and fp32 fn. Each output is checked alone against float64 (ernie5_5/mhc.zig), as GLM's float32-weight finish is, with two controls: the plain mix RMS, 1 / sqrt(mean + eps), on rows below 1e-6, and comb's softmax over a column.
ed56fcb to
3045578
Compare
|
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. |
What this changes
tf_ernie55_mhc_pre, in a newernie5_5_mhcimage: the mHC pre step ERNIE 5.5 runs before each attention and each FFN, as vLLM-ERNIE'smhc_pre_big_fuse_with_norm_tilelangdefines it, one row a block of 256 threads. From a row's 4 bf16 residual streams (4 × 4,096) and fn's 24 float32 rows, it forms the 24 mixes and the streams' sum of squares (a thread's 64 terms in one fma chain, the warp's butterfly, then the 8 warps' partials in order), scales the mixes by ERNIE's mix RMS1 / (sqrt(mean) + eps), and gives pre (sigmoid(m s0 + b) + hc_eps), post (2 sigmoid(m s1 + b)) and comb (each row's softmax plushc_eps, thenhc_sinkhorn_itersrounds of column and row sums withhc_epsin each divisor). It then collapses the streams,sum_s pre_s x_sfrom stream 0 in fma, takes the RMSNorm's sum of squares over the unrounded collapse, and writesbf16((bf16(collapse) · rsqrt) · w)with the layer's norm weight, rounded to bf16 once. Every step is an explicit round-to-nearest operation (__fmaf_rn,__fdiv_rn,__fsqrt_rn,expf). Nothing launches it yet, so served output is unchanged.Why a family kernel and not
common/mhc.cuh(#5164): the mix RMS is not the only difference from GLM's pre side. ERNIE's fn is float32 (the shared partial reads bf16), its norm squares the collapse before rounding it (the shared finish squares the rounded collapse), and it rounds the normed value once, after the weight (the shared finish also roundsrinv·cbefore it). I asked on #4926 (#4926 (comment)) whether you would rather have the shared bodies widened; this pull request leavescommon/mhc.cuhand GLM untouched.One choice differs from the vendor: the mixes are fp32 products of bf16 x and fp32 fn, where the vendor uses DeepGEMM's TF32 GEMM (
tf32_hc_prenorm_gemm, split-k), which rounds fn and x to TF32 first. Nothing here is rounded below fp32 before the outputs.zig/src/families/ernie5_5/mhc.zigis the host's float64 pre side (its sums through asum.ofthe contract's simulations share).mhc_test.zigholds it to vLLM'smhc_pre_torch, written from it with ERNIE's mix RMS and the fused RMSNorm, at a typical scale and on a row of values below 1e-6 (where the mix RMS's eps outweighs sqrt(mean)), plus the shapes it refuses.The contract (
zig/tests/cuda/contract_ernie5_5_mhc.zig,tf-cuda-test ernie5_5-mhc, also inkernel-contract) checks each of the kernel's three outputs alone, as GLM's float32-weight finish is checked: the normed rows (bf16), post and comb (fp32). The sums are at depth 76 (64, 5 and 7). Each output's magnitude takes a mix's |terms| times the mix RMS (1.5 for the RMS's own error) through sigmoid' (1/4) or the softmax (2) and the scale, and for the normed rows the collapse's terms with pre's error and the square root's half. The fp32 operations after the sums are 16 for the normed rows and post and 256 for comb (Sinkhorn's 20 rounds), and one bf16 rounding before the last for the normed rows. The shapes are 6 rows (rows near unit RMS, rows offset by 8, and rows 2 and 5 below 1e-6; gates 1 and 4 and the controls take it), a decode row, and a 64-row chunk. Gate 4 sets pre's fn rows, base andhc_epsto 0, so pre is exactly 1/2, and stream 0 to 2v with the others 0, so the collapse is v and every sum is exact in fp32. Two planted controls: the plain mix RMS1 / sqrt(mean + eps)(red on the tiny rows), and comb's softmax over a column.The record (
ernie5_5_records.zig),cuda_mhc.zig's launch, the image incuda_kernels.zigandkernels.zig,docs/kernel-contract.md, the usage line, and thegradient-serving.tsvpin forkernels.zig.Issue: Refs ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926: the mHC kernels in the slicing there (ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment)), under the gate set for each ERNIE kernel (ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment)).
Stacked on: cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211 (
ba13f19e08, its rebased head) on main044703688d, from the restack in cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301 (comment); cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243 is no longer below. This pull request's own commit is the third on the branch, after cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's commit and the rebase commit: 17 files, 755 insertions, 3 deletions. Once cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211 lands, it rebases onto main.atc overlap --json: atc 0.9.4 withATC_READ_ONLY=1and cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243's head as the base (so this commit alone), run on 2026-11-27 at 01:28 UTC with--base 3668301bbd, before the stack's rebase (the files this commit touches are the same):complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 34 pull requests in its working tree's rows, 4conflicts, 6cleanand 24unknown.conflict_delta: each open pull request merged bygit merge-treewith cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243's head and with this head, conflicting files and hunks compared: over the 402 open pull requests on 2026-11-27 at 01:00 UTC, before the rebase, this commit adds a conflict to none.Checks on this head
0336d7958dcuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract, the restack of this commit onto cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211'sba13f19e08. The GB10 run andpr_checkbelow are on this head; the Windows and WSL runs are on the earlier heads named in them, the same source (mhc.cutook core'swarp_sumfromcommon/reduce.cuhon01f035e6f4, with cubins the same as before at the five SMs in every section of every entry).tools/pr_check.py --base ba13f19e08 --pr 5301, this commit against cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's head): 93 problems on both, 0 new; 0 errors. The 93 are inherited from main.ba13f19e08), then this head, each in its own worktree 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/fatbingives the fivetf_ernie55_mhc_prelinesPASS ... (record current)(40 registers and 948 static shared bytes at every SM, bound 256), and its other lines are cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's head's, line for line (the same 201 stale records, 10REDand 2FAILlines).tf-cuda-test ernie5_5-mhcpasses the three outputs' gates 1-4: gate 1, the non-finite and finite outputs in their float64 classes; gate 2, five runs byte-identical; gate 3, 3 shapes within the FP64 bound, the worst at 0.912 of it for the normed rows and 0.001 for post and comb; gate 4, exact sums at k 16,384, where bf16 sums would miss by 6,152x (post) and 1,646x (comb), and for the normed rows fp16 by 128x and bf16 by 0.5x (registered as not provable there: pre is 1/2 under stress, so only the squares' sums reach the output). Both controls are red (below).ernie5_5-indexpasses cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's window merge with both its controls red, andkernel-contract ernie5_5passes the five ERNIE kernels on this branch with all six controls red (the earlier heads' six and nine counted cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243's keys and controls).zig build test-kernel-contract46 of 46 steps, 359 of 359 tests,test-ernie5_5-host30 of 32 (2 skipped, main's),test-gradient-serving1 of 1.mhc.cu's PTX (ond05feb3bcf, the same source): 33 compiles at each of compute_80, 86, 120 and 121 with address randomization on and off: one form at each.pr_checkon01f035e6f4, 0 errors; before that head's rebase (the same files),zig fmt --checkandzig ast-checkon the 13 changed Zig files,zig build test-ernie5_5-host25 of 27 passed, 2 skipped,compile-cuda-tests12 of 12 steps andtest-kernel-contract46 of 46 steps, 343 of 343 tests.git diff --checkclean;zig build compile-cuda-tests12 of 12 steps;test-gradient-serving1 of 1;test-ernie5_5-host30 of 32, 2 skipped;test-kernel-contract46 of 46 steps (338 tests run);tools/zig/check_cuda_sources.pyonmhc.cuwith clang++ 6 of 6;host_tests_testOK; CI's pytest from the root (-q -rs) 856 passed, 116 skipped, 827 subtests passed on this tree and on main's, the same skips.No GPU46053219749,Zig format46053219997): every job passed.Receipt
tf_ernie55_mhc_pre, so no served token or byte can change. On the GB10, against cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's head built the same way, the imageernie5_5_mhcis added;glm_glueandglm_indexdiffer in bytes but in none of their SASS functions (265 and 10, none changed), and every other fatbin is byte-identical.ba13f19e08on main044703688d(the GB10 run);c50d9d9feaon cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243's23a8aa97a4on cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's0e0286db5con main77eae824e4(the earlier Windows and WSL runs); Zig 0.17.0, nvcc 13.0.88; one GB10 (sm_121); no checkpoint (synthetic rows;hc_eps,hc_sinkhorn_iters,rms_norm_epsand the widths from the released config).tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: n/a (no served path).tools/bench_openai.py: n/a (no served path).Kernel contract, only when a GPU kernel is new or changed
tf_ernie55_mhc_pre(new; replaces none), its three outputs each registered alone, records for sm_80, 86, 89, 120 and 121 inzig/src/core/contract/ernie5_5_records.zig.tf_ctl_ernie55_mhc_pre_plain_rms(the plain mix RMS), red atshapeson post ("at 6x4x16384 output 8 is 8.578284e-1 where float64 gives 1.334888e0: 2194.21 of its bound");tf_ctl_ernie55_mhc_pre_column_softmax(comb's softmax over a column), red atshapeson comb (222.30 of its bound).SUMMARYline and exit status:SUMMARY ernie5_5 mhc: 3 kernels, 3 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 5 kernels: 5 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems, exit 0. CUDA only (no HIP, Metal or XPU image).Checklist
-Dnvccthe CUDA steps are not built, as for every image)."draft": false, a resumed prompt equals a fresh one, and concurrent equals solo (no served path changes).--drafter, no slower than without it, greedy and sampled (no served path changes).