Repository navigation
cuda ernie5_5: the router, two sigmoid scores and the top 10 of score + bias, under the kernel contract - #5368
Conversation
e9b17eb to
6da578b
Compare
|
Thank you, @Bizuayeu. The unlaunched router looks safe to A/B. I confirmed the two FP32 sigmoids, explicitly rounded additions, exact lower-ID tie handling, ascending-ID score sum, denominator clamp, and final division and multiplication. I also confirmed that only the CUDA contract runner imports this module, so serving output is unchanged today. The planted controls cover two meaningful routing mistakes. The remaining evidence limit is important. The near-tie allowance can accept a different expert set, and the weight allowance can accept different FP32 values. Also, the host function named The supplied live run names an older head, so the final integrated tree still needs the synthetic CUDA contracts on GB10
|
|
@Bizuayeu, one small thing: this PR is still marked as a draft, so our landing train skips it. Mark it ready for review when you're happy with it and it goes straight into the next train.
|
29ea2e3 to
8503c62
Compare
ef455a1 to
fa89489
Compare
fa89489 to
3fc06c7
Compare
The five commits under the router are on main now through #5538, so this branch conflicts with main and only the router commit ( |
|
Thanks, @Bizuayeu. Five of the six kernels in this branch are already on main, with the same messages: the DSA indexer's keys, the mHC post side, hc_head, the mHC broadcast and the HCA compressor. Main has had a few fixes on top of them since. The one piece not on main yet is the router commit: two sigmoid scores and the top 10 of score + bias. It reads well to us. The summation order is fixed, ties go to the lower id, a NaN ranks last, and
|
3fc06c7 to
f3c4eeb
Compare
|
READY to land on this head. Reviewed at this head, restacked by us onto main from the router commit (authorship kept). On a GB10 (sm_121) the ernie5_5-moe contract passed every gate with both planted controls red, and the ernie5_5 kernel contract passed. Nothing launches the router yet, so served output is unchanged. This head's CI passed.
|
f3c4eeb to
25bddc9
Compare
|
READY to land on this head. Reviewed at this head, rebased onto main by us after #5794 landed (registrations only; authorship kept). On a GB10 (sm_121) the ernie5_5-moe contract passed every gate with both planted controls red, and the ernie5_5 kernel contract passed. Nothing launches the router yet, so served output is unchanged. This head's CI passed.
|
25bddc9 to
e8fce1a
Compare
|
READY to land on this head. Rebased onto main beside #5851 (the two test registrations in zig/tests/cuda/main.zig kept side by side); the router commit is unchanged. Its previous train passed local CI and device cells before the landing conflict, and its kernel contract run was clean.
|
… + bias, under the kernel contract tf_ernie55_route, in a new ernie5_5_moe image, routes a row as vLLM-ERNIE's ernie5_5_routing does: each of the 512 experts scored from its two routers' fp32 logits as sigmoid(l0) + sigmoid(l1), the top 10 of score + bias by core's row select (tf_topk::select_row: ties to the lower id, the picks in ascending ids, as the vendor's slots but for ties at the k-th value, which it puts last), and each pick's weight its score over the picks' sum, at least 1e-20, times the expert's learned scale. It writes the int32 picks and fp32 weights core's combine takes. moe_glue's sigmoid routes sum the logits before one sigmoid and scale by one factor, so ERNIE's router is a family kernel (ashhart#4926). The picks and weights are checked against float64 (ernie5_5/route.zig, whose host test holds it to the vendor's torch routing): the same ranks with only near-ties swapped and exact ties to the lower id, and the weights within 2^-20. Two controls: one sigmoid of the two logits summed, and weights from score + bias.
e8fce1a to
ed77972
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_route, in a newernie5_5_moeimage: ERNIE 5.5's router, as vLLM-ERNIE'sernie5_5_routingforms a row's picks, one row a block of 64 threads. Each of the 512 experts is scored from its two routers' fp32 logits (gate.weight's row, thenweight_1's) as sigmoid(l0) + sigmoid(l1); the top 10 of score + correction bias are picked by core's row select (tf_topk::select_row: ties to the lower id, a NaN never picked ahead of a number, the picks in ascending ids); and each pick's weight is its score (without the bias) over the picks' summed scores, at least 1e-20, times the expert's learned scale. It writes the int32 picks and fp32 weights core's combine takes. Nothing launches it yet, so served output is unchanged.This is the router your answer 2 on #4926 asked for: an ERNIE kernel that produces the picks and weights core's combine consumes, with the two-sigmoid score, the bias-only selection, the normalization and the per-expert scale together, not another
moe_glueroute mode (moe_glue's sigmoid routes take one sigmoid of the summed logits and one scale factor).Three places differ from the vendor's torch routing in bits, not in the rule:
The sigmoid is core's
tf_sigmoid,1 / (1 + tf_exp(-x))with round-to-nearest steps, where torch takes its own fp32sigmoid; a score can differ in its last bit, so two experts a bit apart may swap ranks. The check allows only such near-ties to swap.The picks' scores are summed in ascending id order, one fp32 add at a time; torch sums its slots in its own reduction order. The weights are checked within 2^-20 of float64's.
Ties at the 10th value: the slots are in ascending ids here, as the vendor's are, but for experts tied at the 10th value, which the vendor puts last.
zig/src/families/ernie5_5/route.zigis the host's float64 router (score, rank, the picks and the weights).route_test.zigholds it to vLLM-ERNIE's_ernie5_5_routing_torch, written out (experts by score + bias, then id, the first k, weighed without the bias), and checks the shapes it refuses.The contract (
zig/tests/cuda/contract_ernie5_5_moe.zig,tf-cuda-test ernie5_5-moe, also inkernel-contract) is check-based, as the row top-k's is: each row's picks must be in range and ascending, rank asroute.rankdoes with only near-ties (within 2^-20 of the rank) swapped and exact ties to the lower id, and the weights must be within 2^-20 of float64's. The shapes are a 16-row verify window, a decode row and a 300-row prompt chunk, each 512 experts and 10 picks; the logits are N(0, 2) with every 7th expert copying its neighbour in both routers (exact ties) and a bias of 0.25 on every 5th. Two planted controls: one sigmoid of the two logits summed, and weights from score + bias.The record (
ernie5_5_records.zig),cuda_moe.zig's launch, the image incuda_kernels.zigandkernels.zig, the runner's module,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 router in the slicing there, and the owner's answer 2 (ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment): "write an ERNIE kernel producing the picks and weights consumed by core's combine").
Stacked on: the ERNIE stack below it, rebased here onto cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's head
55a5d64aa5: cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's commit (c100a00a31, the HCA compressor) on cuda ernie5_5: the mHC broadcast, the first layer's pre from one row, under the kernel contract #5324's (fb10090607) on cuda ernie5_5: hc_head, the last layer's 4 streams into one row, under the kernel contract #5318's (1f6706396e) on cuda ernie5_5: the mHC post side, a layer's output into its 4 streams, under the kernel contract #5311's (9dbc07b69c) on cuda ernie5_5: the mHC pre side, a row's mixes, Sinkhorn and the collapse's RMSNorm, under the kernel contract #5301's (148f975a14) on cuda ernie5_5: the DSA indexer's keys, k's LayerNorm then NeoX RoPE, under the kernel contract #5243's (3d051ede55) on cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211 (55a5d64aa5) on main8b1eaff2c7. Each of those commits' own lines is the one on its pull request's branch (the same patch id without context); I left those branches as they are, for your rebase. This commit adds lines beside theirs in the family's lists, and is the eighth on the branch: 17 files, 484 insertions, 2 deletions. Once they land, it rebases onto main.atc overlap --json: atc 0.9.4 withATC_READ_ONLY=1, run in this tree on 2026-11-27 at 11:41 UTC with--base c100a00a31(so this commit alone):complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 32 pull requests in its working tree's rows, 5conflicts, 5cleanand 22unknown.conflict_delta: each open pull request merged bygit merge-treewithc100a00a31and with this head, and the conflicting files and hunks compared. Over the 387 open pull requests on 2026-11-27 at 11:16 UTC, this commit adds a conflict to two, the stack below it, whose branches hold its commits before this rebase: cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326 (13 more hunks, in the lists this commit adds a line to:CHANGELOG.md,kernels.zig, the family'shost_test.zig, and the contract runner'scontract_family_sets.zig,contract_limits.zig,main.zigandmain_usage.zig) and cuda ernie5_5: the mHC broadcast, the first layer's pre from one row, under the kernel contract #5324 (one more hunk).Checks on this head
fa89489b0f, onbfc564cb6a), 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-moe: SUMMARY ernie5_5 moe: 1 kernels, 1 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed;tf-cuda-test kernel-contract ernie5_5: SUMMARY 14 kernels: 14 pass gates 1-4, 0 fail, 0 known findings; 19 controls: 19 red as planted, 0 missed; 0 limit problems. Against its parentbfc564cb6a(your earlier restack of cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326, on main388ec8c487), 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_routelines (PASS ... (record current)); the one fatbin change is the added imageernie5_5_moe; the other 205 are the parent's to the byte. Host (zig build -Dfixed-cpu):test-ernie5_5-host44/46 tests passed (2 skipped),test-gradient-serving1/1 tests passed,test-kernel-contract368/368 tests passed. The items below are from before your rebase.6da578b2eacuda ernie5_5: the router, two sigmoid scores and the top 10 of score + bias, under the kernel contract.6da578b2eadiffers frome9b17eb8dconly in the CHANGELOG line's pull request number. The GB10 gate below ran on3b53b1fb58, this commit's code on cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's earlier heade2b9fb5d63(main469f1f7fd8); since, the stack was rebased onto main8b1eaff2c7and then onto cuda ernie5_5: the DSA key lists, top-k picks then the window, under the kernel contract #5211's fixed head, and this commit's own lines are unchanged (the same patch id without context). One9b17eb8dc, on Windows,zig build compile-cuda-tests,test-kernel-contractandtest-gradient-serving, andpr_check(below).tools/pr_check.py --base c100a00a31 --pr 5368, this commit against cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's here): 123 problems on both, 0 new; 0 errors. The 123 are inherited from main.e2b9fb5d63) and then3b53b1fb58, 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_routelinesPASS ... (record current)(40 registers at sm_80, 45 at 86 and 89, 50 at 120 and 121, 5,272 static shared bytes, bound 64), and its other lines are the base's but one:tf_nemo_router_tilesat sm_89, 196 registers (record stale) in the base's build and 184 (record current) in this one, the router-tiles entries whose compiles give more than one form (cuda: the shared router tiles read their shared-memory rows as 32-bit words #5360), which this commit does not touch.tf-cuda-test ernie5_5-moepasses gates 1-3 (gate 3 at 3 shapes, exact by its own check; gate 4 n/a, no sums) with both controls red as planted, andkernel-contract ernie5_5passes its 14 kernels with all 19 controls red (the base's 13 and 17; below).zig build test-ernie5_5-host42 of 44, 2 skipped;test-kernel-contract353 of 353;test-gradient-serving1 of 1.moe.cu's PTX: 33 compiles at each of compute_80, 86, 120 and 121 (3 with address randomization off, 30 on), one form at each.883a7e8b42(this commit on cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326'se2b9fb5d63),zig build test-ernie5_5-host42 of 44 passed, 2 skipped (main's), andtest-kernel-contract46 of 46 steps, 353 of 353 tests;pr_check0 errors. One9b17eb8dc, this head but for the CHANGELOG line's number:zig build compile-cuda-tests12 of 12 steps;test-kernel-contract46 of 46 steps, 356 of 356 tests;test-gradient-serving1 of 1;pr_check --base c100a00a310 errors.ptxas -vofmoe.cuat the five SMs (13.0.88):tf_ernie55_routetakes 40, 45, 45, 50 and 50 registers and 5,272 static shared bytes; at sm_80 it has a 16-byte stack frame with 12 bytes of spills, and none at the other SMs (the PTX has no calls; core'stopk_rows.cu, which takes the sameselect_rowwith a row length it reads at run time, has none at sm_80). On this head:git diff --checkagainst cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's commit here clean;zig build compile-cuda-tests12 of 12 steps;test-ernie5_5-host43 of 45, 2 skipped;test-kernel-contract46 of 46 steps, 356 of 356 tests;test-gradient-serving1 of 1;tools/zig/check_cuda_sources.pyonmoe.cuwith clang++ 6 of 6;host_tests_testOK; CI's pytest from the root (-q -rs) 861 passed, 116 skipped, 827 subtests passed, the same skips as main8b1eaff2c7's.Receipt
tf_ernie55_route, so no served token or byte can change. On the GB10, against cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326's head then built the same way, the fatbins that differ are the newernie5_5_moeandnemotron_route(the router-tiles entries, cuda: the shared router tiles read their shared-memory rows as 32-bit words #5360); every other image is byte-equal.3b53b1fb58on cuda ernie5_5: the HCA compressor, a block's softmax pool, RMSNorm and RoPE, under the kernel contract #5326'se2b9fb5d63on main469f1f7fd8(this head is the same change on the stack above8b1eaff2c7); Zig 0.17.0, nvcc 13.0.88; one GB10 (sm_121); no checkpoint (synthetic logits; the expert count and top-k 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_route(new; replaces none), records for sm_80, 86, 89, 120 and 121 inzig/src/core/contract/ernie5_5_records.zig.tf_ctl_ernie55_route_one_sigmoid(one sigmoid of the two logits summed), red atshapes("at 16x512x10: row 0: expert 170 ranks 1.55702725, unpicked expert 31 1.95733346"), andtf_ctl_ernie55_route_biased_weights(weights from score + bias), red atshapes("at 16x512x10: row 0 slot 0: weight 0.13486953 where float64 gives 0.13309110").SUMMARYline and exit status:SUMMARY ernie5_5 moe: 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 14 kernels: 14 pass gates 1-4, 0 fail, 0 known findings; 19 controls: 19 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).