Repository navigation
Conversation
…y moved from hy4_flash to common/mla.cuh The mla image gains tf_mla_expand_v_256 (tf_mla::expand_v at 256-wide v heads, which hy4_flash already instantiates as tf_hy4_expand_v) and tf_mla_merge_sink, which merges the chunk tiles' partials with each head's fp32 sink counted once as a zero-value key. The merge's body is hy4_flash's tf_hy4_attend_merge, moved to common/mla.cuh as tf_mla::merge_sink, which takes each thread's column from its entry: with the column read inside the moved body, nvcc 13.0 gave tf_hy4_attend_merge other SASS at sm_120 and sm_121. hy4_flash keeps its image, entry name and --fmad=false and calls it there, so its outputs are unchanged. Mla.expandV takes 128- or 256-wide heads, Mla.mergeSink launches the merge, and geometry() takes the widths the kernels take (q_nope 128 or 192, v 128 or 256). Both entries are under the kernel contract against float64, with a planted control each, and tf-cuda-test mla-sink checks that the mla merge gives tf_hy4_attend_merge's bytes at hy4_flash's shapes, and that tf_hy4_attend_merge gives another build's bytes when given its hy4_mla_attention fatbin. GLM's path uses neither entry.
Bizuayeu
force-pushed
the
pr/mla-v256-sink
branch
from
November 25, 2026 18:07
5e47d70 to
b3fca7f
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Core's CUDA MLA image (
mla.cu,cuda.mla) gains the two pieces ERNIE 5.5's DSA layers need beyond what it has (latent 512, q_nope 192, 64 roped columns, v 256, and a per-head sink), both withhy4_flash's arithmetic:tf_mla_expand_v_256:tf_mla::expand_vat 256-wide v heads. The body is already incommon/mla.cuh, andhy4_flashinstantiates it astf_hy4_expand_vin its own image.Mla.expandVtakes 128 or 256.tf_mla_merge_sink: the chunk tiles' partials merged with each head's fp32 sink counted once as a zero-value key, a block of 128 per (row, head), bf16 out. Its body ishy4_flash'stf_hy4_attend_merge, moved tocommon/mla.cuhastf_mla::merge_sink, with one change: each entry passes its thread's column (threadIdx.x * 4) in, so thattf_hy4_attend_merge's SASS stays main's (below).tf_hy4_attend_mergenow calls it, in its own image, with its entry name and--fmad=false.Mla.mergeSinklaunches the new entry.geometry()takes the widths the kernels take: q_nope 128 or 192 (both absorbs exist) and v 128 or 256. Nothing outsidemla.zigcalls it today.GLM's path uses neither entry. GLM expands with its own
tf_glm_expand_vand merges withtf_glm_merge, and themlaimage's existing entries are unchanged (SASS below).hy4_flash's latent experts stay as they are: they are only core calls, which ERNIE can make too (agreed in the comment below).hy4_flashmove agreed at ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment) ("MLA andhy4_flashas one PR: yes. Movetf_hy4_attend_merge's body tocommon/mla.cuh, add theexpand_v<256>and sink-mergemlaentries, and keephy4_flash's images, entry names and--fmad=false."). Overlaps named there: attention: guarded identity online-softmax rescale skip on CUDA and Metal #4520 (yours) adds the identity-rescale guard totf_hy4_attend_merge's body, which this moves tocommon/mla.cuh, and tocommon/mla.cuh's chunk bodies andcontract_mla_chunks.zig. It conflicts with main already (5 files, 8 hunks); with this head it also conflicts in those three files (11 hunks in all). Whichever lands second carries the other's change: the guard intotf_mla::merge_sink, which both merges then call, or this move onto the guarded body. glm cuda: full GLM-5.3 (glm_moe_dsa) at TP=3 with a bf16 cache, drafts, slots and prompt steps #4900 (another contributor's) also changesdocs/kernel-contract.md,zig/tests/cuda/main.zigandzig/tests/cuda/main_usage.zig, in other places:git merge-treemerges it cleanly with this head, as with main.8e0548f715); one commit,b3fca7fcf3.atc overlap --json: atc 0.9.4 withATC_READ_ONLY=1and--base 8e0548f715, run in this tree on 2026-11-25 at 15:35 UTC with main atc328b353a1, head3c7185694f(an earlier form of this commit, with the same 13 files):complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 19 pull requests sharing a file with it: 3conflicts(idol: BiRefNet background removal and preprocessing on Metal, so tf-idol-generate takes a raw photo (stacked on #1780) #1787, app: control vector picker and strength in Engine advanced #1951, test(cuda): opt-in --jobs and --shard for kernel-contract #3093), 7cleanand 9unknown. It did not reach attention: guarded identity online-softmax rescale skip on CUDA and Metal #4520 or glm cuda: full GLM-5.3 (glm_moe_dsa) at TP=3 with a bf16 cache, drafts, slots and prompt steps #4900. So I took every open pull request that, by GitHub's file lists at 17:58 UTC, changes one of this commit's 13 files (153; 116 of them changeCHANGELOG.md), or whose list GitHub cuts at 100 files, 177 in all:git merge-tree --write-treeof each one's head (checked against itsheadRefOid) with8e0548f715and with5e47d70a19, this head but for its number, gives the same conflicting files and number of conflict hunks for 176 of them (151 conflict with8e0548f715already, 25 merge cleanly with both). The one where this adds a conflict is attention: guarded identity online-softmax rescale skip on CUDA and Metal #4520, named above. Merged with mainb92aebe9e9, this commit has no conflict and itsCHANGELOG.mdline stays under Unreleased.Checks on this head
b3fca7fcf3on main8e0548f715. The GB10's runs below are on5e47d70a19, which differs from this head only in text: itsCHANGELOG.mdline reads#TBDwhere this head names this pull request. CI's pytest and the other runs in WSL 2 are on33f5a3c9fa, which also has the two new launch records at zero.python3 tools/zig/lean_check.py, on the base and on this head: 164 problems on main8e0548f715and 164 on this head, 0 new (tools/zig/lean_new.py). The 164 are inherited from main.common/mla.cuhgrows from 342 to 365 lines andmla.zigfrom 188 to 210; the new test has 131.8e0548f715, each built from an empty global cache withzig build compile-cuda-tests fatbins kernel-contract-fatbins -Dnvcc=<nvcc 13.0.88> -Dsm=80,86,89,120,121(exit 0 both).tf-cuda-test mla-sink <main's zig-out/fatbin/hy4_mla_attention.fatbin>: exit 0,PASS sink merge: 18 shapes, tf_mla_merge_sink gives tf_hy4_attend_merge's bytes; at most 9.958750745463797e-1 of the float64 boundandPASS sink merge: tf_hy4_attend_merge gives the other build's bytes at all 18 shapes. The 18 shapes arehy4_flash's (64 heads of one chunk, 32 and 16 of one, 32, 16 and 8 of four) at 1, 17 and 64 rows, on synthetic partials and sinks; the bound is bf16's rounding of the float64 result,|want| * 2^-8, plus2^-20of the summed magnitude over the denominator.tf-cuda-test kernel-contract mla: exit 0 (itsSUMMARYis below).zig build -Dfixed-cpu test-cuda-host --summary allfailed one test the first time, 501 of 503 steps succeeded, 9,527 of 9,572 tests passed, 44 skipped, 1 failed:start_cli_test's "start CLI: Ctrl-C during a deferred download has its normal process effect" (expect(W.IFSIGNALED(status))); run again at once in the same tree, 503 of 503 steps succeeded (3,617 of 3,628 tests passed, 11 skipped, in the steps that ran again). That test reads none of the files this changes; on this branch's first form (3c7185694fwith the same two records filled), whose Zig files are this head's, the same command passed 503 of 503 steps, 9,528 of 9,572 tests, 44 skipped.test-kernel-contract: 43 of 43 steps, 323 of 323 tests passed;test-gradient-serving: 4 of 4 steps, 1 of 1 test passed. In WSL 2 (x86-64 Ubuntu 24.04),33f5a3c9fa:zig fmt --checkandzig ast-checkon the 8 Zig files, andgit diff --check, clean;zig build -Dfixed-cpu compile-cuda-testswithout nvcc, 12 of 12 steps;tools/zig/check_cuda_sources.pywith aclang++on the four CUDA sources that this changes or that includecommon/mla.cuh, 18 of 24 checks passed, as on8e0548f715(the 6 that fail stop atglm_index_rope.cuh'smemcpy, the same on both);python3 -m unittest discover -s tools/zig -p host_tests_test.py, 14 tests OK;python -m pytest -q -rs -p no:cacheproviderfrom the root, with pytest 9.2.0 and PyYAML 6.0.4 and aclang++onPATH: 821 passed, 106 skipped, 826 subtests passed, the same counts and skip reasons as8e0548f715.b3fca7fcf3(pushed at 18:07 UTC); this line will carry the jobs' results.hy4_flash's attention has no served CUDA path on main).Receipt
n/a for serving: no served checkpoint's tokens or speed change. The receipt is
hy4_flash's bytes, the SASS and the contract below.cuobjdump -sassof each tree'shy4_mla_attention,mlaandglm_gluefatbins above, compared function by function at all five SMs (tools/zig/sass_compare.shcounts the two added entries as a difference):hy4_mla_attention, 10 of 10 (SM, function) pairs equal,tf_hy4_attend_merge's among them;mla, all 40 of main's pairs equal, andtf_mla_expand_v_256andtf_mla_merge_sinkadded at each SM;glm_glue, 250 of 250 equal. With the column read inside the moved body instead (3c7185694f), nvcc 13.0.88 gavetf_hy4_attend_mergeother SASS at sm_120 and sm_121 (the same at sm_80, 86 and 89, and the same bytes on the GB10 at the 18 shapes); with each entry passing it, as here, the SASS is main's at all five.hy4_flash's CUDA attention merge.8e0548f715and this head, Zig 0.17.0, nvcc 13.0.88, one GB10 (sm_121).tf_hy4_attend_mergegives main's bytes andtf_mla_merge_sinkgivestf_hy4_attend_merge's, athy4_flash's shapes, as above.Kernel contract, only when a GPU kernel is new or changed
tf_mla_expand_v_256(contract_mla_proj.zig, rows 1, 8 and 70 at 32 and 64 heads) andtf_mla_merge_sink(contract_mla_chunks.zig, throughtf_mla_chunks_r16at four chunks of 32 heads, one of 64 and two of 32), new, against float64. Rounding points and sum order: the expand is the 128-wide entry's chain at 256 columns; the merge rescales each chunk byexpf(m - top)and sums mass and output in chunk order with explicit fmas, starting from the sink'sexpf(sink - top), and rounds once to bf16.tf_mla_expand_v_256reading each head's weights from the next head, andtf_mla_merge_sinkwith every sink left out (each head's sink drawn from -2 to 8, so it holds from a few percent to most of the merge's mass).SUMMARYline and exit status:tf-cuda-test kernel-contract mlaon the GB10:(filtered) SUMMARY 10 kernels: 10 pass gates 1-4, 0 fail, 0 known findings; 11 controls: 11 red as planted, 0 missed; 0 limit problems; gates 32619 ms, limits 2 ms, exit 0. The two new controls go red at the shapes gate,tf_mla_expand_v_256's at 616 times its bound andtf_mla_merge_sink's at 1.26 times. Limits:tf-cuda-test kernel-contract-limits zig-out/fatbinon the same builds: the 10 records of the two new launches (sm_80, 86, 89, 120 and 121) are current,tf_mla_expand_v_256at 96 or 95 registers and 128 static shared bytes,tf_mla_merge_sinkat 31 to 40 registers; the other images' records are 154 stale on this tree and the same 154 on main8e0548f715, none of them this pull request's, so both exit 1 with154 problems; the 10REDlines are the limits tool's own planted controls, the same on main.Checklist