Repository navigation
cuda ernie5_5: the mHC post side, a layer's output into its 4 streams, under the kernel contract - #5311
cuda ernie5_5: the mHC post side, a layer's output into its 4 streams, under the kernel contract#5311Bizuayeu wants to merge 3 commits into
Conversation
2f1dce8 to
07ba374
Compare
07ba374 to
ff70094
Compare
ff70094 to
3238d95
Compare
|
Thanks, @Bizuayeu. The Sinkhorn sequencing, collapse rounding and declared mHC operation bounds are internally consistent. Two blockers remain in this cumulative stage. First, an oversized Second, the mHC mix still substitutes unrounded FP32 coefficients and a custom reduction for the pinned TF32/DeepGEMM arithmetic. A coefficient such as The inherited hardening fixes also remain: guard window-shape multiplication with division, clear the contract's No rebase is requested, and no device run is promised here.
|
Thanks. The mixes stay fp32 products on purpose: your reviews of #5301 found that the right choice, "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" (#5301 (comment)) and "no change is needed to the FP32-product choice" (#5301 (comment)), and the kernel and the oracle here are that choice. Should I keep it, or move the kernel and the oracle to the vendor's TF32 inputs and DeepGEMM's reduction order, with the planted The |
|
Thanks, @Bizuayeu. Keep the FP32 products and the stated reduction order. Our TF32 rewrite request was not justified by this full-precision contract, and we’re withdrawing it. No TF32 rewrite or control against retaining full FP32 coefficients is needed. The post-side orientation and scaling agree with the host form. The remaining changes are the two prepared allocation-cleanup fixes described on #5243. We’ll carry those and the list fixes already on main through the restack; you do not need to duplicate them here or rebase. Current-tree CUDA qualification remains pending.
|
|
Thanks, @Bizuayeu. Keeping the agreed FP32 coefficients, products and reduction order meets the arithmetic request. The TF32 rewrite request remains withdrawn; no TF32 rewrite or control against retaining FP32 coefficients is needed. The post-side orientation and scaling remain consistent with the host form. The remaining work is the planned stack integration: preserve main's corrected window merge and overflow guard, and carry the allocation cleanup from #5243 and #5535. Those fixes need not be duplicated in this PR, and no rebase is requested from you here. Current-tree CUDA qualification remains pending after that integration.
|
3238d95 to
99270b8
Compare
…under the kernel contract ERNIE 5.5's indexer scores each query against keys made from wk's k: LayerNorm(128, eps=1e-6) with k_norm's weight and bias, then RoPE on the first 64 dims in NeoX's halves, pairs i and i + 32, at the config's rope_theta (the DSA layers' plain RoPE; YaRN is the HCA layers'). tf_ernie55_index_key (in the ernie5_5_index image) makes a key a warp: the LayerNorm in fp32, the mean then the squares about it, y = fma(xc / sqrt(var + eps), w, b), then the turn at the fp32 angle inv[i] times the position with sincosf, and one rounding to bf16 (vLLM rounds to bf16 after the LayerNorm and again after the rope). The vendor's Hadamard on q and k before its FP8 quantization is left out: with bf16 keys it changes no score in exact arithmetic. key.zig is the host's float64 key; its tests hold it to vLLM's F.layer_norm and NeoX halves. The contract (ernie5_5-index, also in kernel-contract) asks each key within its float64 bound, from prompt chunks and a decode row at the first position to decode rows past sincosf's fast range and at the 1M context's end; gate 4's rows of 254 to 260 in steps of 2 keep fp32 sums exact while fp16 and bf16 sums lose the steps. The k rows sit 192 apart with NaN past 128, so a read past the key shows. Three controls go red: GPT-J's pairs, the LayerNorm without its bias, and the next position's angle. Nothing launches it yet.
…eing and reallocating it reference freed extra and allocated it again; had that allocation failed, extra would still have held the freed slice, freed a second time by the next reference or by deinit. It is now empty between the two.
…, under the kernel contract tf_ernie55_mhc_post, in the ernie5_5_mhc image, adds a layer's bf16 output to its row's 4 residual streams as vLLM's mhc_post does for ERNIE 5.5: stream o = post[o] x + sum_i comb[i][o] res[i], with post and comb from the pre side, from the product, then the input streams in order in fma, rounded to bf16 once. GLM's post body sits in its own glue, so ERNIE's is a family kernel. The streams are checked against float64 (ernie5_5/mhc.zig), with gate 4 on integer terms that fp32 holds in any order, cancelling to +-1/2, whose fp16 and bf16 roundings do not; two controls: comb read transposed, and the layer output added without post.
99270b8 to
8aeabdc
Compare
|
#5538's head |
|
Thank you, @Bizuayeu. Confirmed: the mHC post side keeps the agreed FP32 products and reduction order, and its orientation and scaling match the host form. In #5538 the post kernel is byte-for-byte the one here, and #5538 also adds the furthest-offset bounds on the mHC checks. So we'll land #5538 and close this one as included. Nothing more is needed from you here.
|
What this changes
tf_ernie55_mhc_post, in theernie5_5_mhcimage (#5301): the mHC post side ERNIE 5.5 runs after each attention and each FFN, as vLLM'smhc_postforms it (mhc_post_tilelang), one row a block of 256 threads. A layer's bf16 output x goes into its row's 4 residual streams: stream o = post[o] x + sum_i comb[i][o] res[i], with post [4] and comb [16] from the pre side (#5301), from the product, then the input streams in order in fma, rounded to bf16 once. GLM's post side sits inglm_glue_rows.cuhwith GLM's other glue, so ERNIE's is a family kernel beside the pre side. Nothing launches it yet, so served output is unchanged.zig/src/families/ernie5_5/mhc.zig'spostis the host's float64 post side (its 5-term sums through thesum.ofthe contract's simulations share);mhc_test.zigholds it to vLLM'smhc_post_torch: the einsum of comb with the input streams, plus post times x.The contract (
contract_ernie5_5_mhc.zig'sPost, intf-cuda-test ernie5_5-mhc, also inkernel-contract) checks the 4 output streams (bf16) against float64, each output's magnitude its 5 terms' |terms|, at depth 5 (the product, then 4 fmas). The shapes are 4 rows, a decode row and a 64-row chunk. Gate 4 runs streams 0 to 2 equal to x (odd integers from 129 to 253) under comb -130, 131 and -130 against post 129, and stream 3's +-1 under 1/2: integer terms and partials that fp32 holds in any order, cancelling to +-1/2, which fp16's and bf16's roundings of the terms lose. Two planted controls: comb read transposed (comb[o][i] for comb[i][o]), and the layer output added without post.The record (
ernie5_5_records.zig),cuda_mhc.zig'spostSideandlaunchPost,docs/kernel-contract.mdand the usage line.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 mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301 (
01f035e6f4, the mHC pre side) on cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243 (9e339899f7) on cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211 (7103160ea0) on main469f1f7fd8; this pull request's own commit is the fourth on the branch: 9 files, 303 insertions, 9 deletions. Once they land, it rebases onto main.atc overlap --json: atc 0.9.4 withATC_READ_ONLY=1and cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's head as the base (so this commit alone), run in this tree on 2026-11-27 at 05:43 UTC with--base 6bd633127c:complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 19 pull requests in its working tree's rows, 3conflicts, 7cleanand 9unknown.conflict_delta: each open pull request merged bygit merge-treewith cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's head and with this head, conflicting files and hunks compared: over the 393 open pull requests on 2026-11-27 at 05:22 UTC, this commit adds a conflict to none.Checks on this head
99270b8f6e, on cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243'sa106f24ea2), on a GB10 (sm_121): the tree cleaned (git clean -xdf) with an empty global cache,zig build compile-cuda-tests fatbins kernel-contract-fatbins -Dnvcc=... -Dsm=80,86,89,120,121(nvcc 13.0.88): 0 errors. On the GPU,tf-cuda-test ernie5_5-mhc: SUMMARY ernie5_5 mhc: 4 kernels, 4 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed;tf-cuda-test kernel-contract ernie5_5: SUMMARY 7 kernels: 7 pass gates 1-4, 0 fail, 0 known findings; 11 controls: 11 red as planted, 0 missed; 0 limit problems. Against cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243's heada106f24ea2, built and run the same way:kernel-contract-limitsgives both the same 205 stale records and the same RED and FAIL lines, apart from this tree's 5tf_ernie55_mhc_postlines (PASS ... (record current)); the only fatbin that differs isernie5_5_mhc, whose SASS, compared function by function, adds 3 functions at each of the 5 SMs (tf_ctl_ernie55_mhc_post_comb_transposed,tf_ctl_ernie55_mhc_post_no_post,tf_ernie55_mhc_post) and changes none of the parent's; no image is added or removed. Host (zig build -Dfixed-cpu):test-ernie5_5-host34/36 tests passed (2 skipped),test-gradient-serving1/1 tests passed,test-kernel-contract368/368 tests passed. The items below are from before your rebase.ff7009442acuda ernie5_5: the mHC post side, a layer's output into its 4 streams, under the kernel contract. The GB10 runs below are onea9393e263and the WSL runs on7023af0806, each this commit on a copy of cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's on main77eae824e4, before the stack was rebased onto469f1f7fd8(which re-pinned onlykernels.zig's line ingradient-serving.tsv, in cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's commit) and before its CHANGELOG line took this pull request's number; this commit's added and removed lines are the same there; on this head, the Windows checks. Since,mhc.cutakes core'swarp_sum(common/reduce.cuh) in place of its own copy, which CI'scuda_common_check.pyrefuses; at the five SMs its cubins (nvcc 13.0.88 on x86-64) are the same as before in every section of every entry.tools/pr_check.py --base 01f035e6f4 --pr 5311, this commit against cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's): 123 problems on both, 0 new; 0 errors. The 123 are inherited from main.ea9393e263) checked out with an empty global cache and the tree's own cache andzig-outremoved,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_postlinesPASS ... (record current)(48 registers at sm_80, 120 and 121, 47 at sm_86 and 89, no static shared memory, bound 256, no stack or spills), and its other lines are cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's (the same 186 stale records and RED and FAIL lines).tf-cuda-test ernie5_5-mhcpasses post's gates 1-4: gate 1, 12 non-finite and 81,908 finite outputs in their float64 classes; gate 2, five runs byte-identical; gate 3, 3 shapes within the FP64 bound, the worst at 0.996 of it; gate 4, exact sums at k 5, where fp16 sums would miss by 16,384x and bf16 by 65,536x. Both controls are red (below), and the pre side's three outputs pass as on cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301.kernel-contract ernie5_5passes the seven ERNIE kernels with all 11 controls red. In the stack's earlier GB10 chain (the same kernel source, before gate 4's fill was fixed), the fatbins equal cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's but forernie5_5_mhc, whose existing functions' SASS is unchanged (post's 15 added), andmhc.cu's PTX on the next commit's tree (65a8c8d632, which adds hc_head to the file): 33 compiles at each of compute_80, 86, 120 and 121 with address randomization on and off, one form at each.zig fmt --checkandzig ast-checkon the 6 changed Zig files, andpr_check: 0 errors.7023af0806) in a clone of the stack:git diff --checkclean;zig build compile-cuda-tests12 of 12 steps;test-gradient-serving1 of 1;test-ernie5_5-host32 of 34, 2 skipped;test-kernel-contract46 of 46 steps, 350 of 350 tests;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, the same skips as main's.Receipt
tf_ernie55_mhc_post, so no served token or byte can change. On the GB10, against cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's tree built the same way,ernie5_5_mhcis the only fatbin that differs.ea9393e263(GB10) and7023af0806(WSL) on cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's commit on 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(this head is the same change on469f1f7fd8); Zig 0.17.0, nvcc 13.0.88; one GB10 (sm_121); no checkpoint (synthetic rows).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_post(new; replaces none), records for sm_80, 86, 89, 120 and 121 inzig/src/core/contract/ernie5_5_records.zig.tf_ctl_ernie55_mhc_post_comb_transposed(comb read as comb[o][i]), red atshapes("at 4x16384x5 output 0 is -2.500000e0 where float64 gives -3.900770e-1: 1384.32 of its bound");tf_ctl_ernie55_mhc_post_no_post(the layer output added without post), red atshapes(50.00 of its bound).SUMMARYline and exit status:SUMMARY ernie5_5 mhc: 4 kernels, 4 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed, exit 0;kernel-contract ernie5_5:(filtered) SUMMARY 7 kernels: 7 pass gates 1-4, 0 fail, 0 known findings; 11 controls: 11 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).