Repository navigation
cuda mla: 256-wide v heads and a per-head sink merge, the merge's body moved from hy4_flash to common/mla.cuh - #5084
Merged
Conversation
Bizuayeu
force-pushed
the
pr/mla-v256-sink
branch
from
November 25, 2026 18:07
5e47d70 to
b3fca7f
Compare
Bizuayeu
marked this pull request as ready for review
November 25, 2026 22:04
Owner
|
Thank you, @Bizuayeu. The 256-wide expansion keeps the existing reduction and BF16 rounding sequence. The sink contributes once per row and head, empty chunks have zero mass, and Hy4-flash's entry, launch shape and disabled-FMA behavior are preserved. GLM remains on its own kernels. The supplied contract evidence covers exact new/old merge comparisons, planted sink omission and unchanged existing-kernel SASS. The branch merges cleanly on today's main, and no new serving dispatch requires another checkpoint run. SAFE TO LAND.
|
…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.
ashhart
force-pushed
the
pr/mla-v256-sink
branch
from
November 26, 2026 04:24
b3fca7f to
c91319b
Compare
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. |
1 task done
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 the expand_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), which has since landed, changeddocs/kernel-contract.md,zig/tests/cuda/main.zigandzig/tests/cuda/main_usage.zigin other places; this head merges with maine639122210, which holds it, without a conflict.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 that I did not push, 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 maine639122210, this commit has no conflict and itsCHANGELOG.mdline stays under Unreleased;python3 tools/pr_check.py --base origin/main --pr 5084there: 0 errors, 0 warnings.Checks on this head
mla-sinkandkernel-contract mla, from this tree's second build (below): sha2562b69a44ff145022dee383cb6182ae319f12bcc19e93156e788593ea6b744406a, 519,188,712 bytes. It embedsmla.fatbin, sha2565f1ceaf89db7380d0476deb1208fddfe02d038eb0f2e6293986d247d2cacef28,hy4_mla_attention.fatbin,a779939acc8f33b36c68e7b1f87e95e3cab00bc9412c1f27df51fa70f6a97858, andglm_glue.fatbin,7b8ead2250df343be0e8a2898b743d680aa2e595902229a5d1f777c054d1b868: each file inzig-out/fatbin, which the limits and the SASS comparison read, is found byte for byte once inside the runner.tf-cuda-test kernel-contract mla, exit 0:(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 mstf-cuda-test kernel-contract-limits zig-out/fatbin: the two new launches' 10 records (sm_80, 86, 89, 120 and 121) are current; exit 1 with154 problems, the same 154 as on main, none of them this pull request's.8e0548f715's images:hy4_mla_attention.fatbin, whichmla-sinkloads from its path, has the same sha256 as this tree's;mla.fatbinis620ec31e3299374eacdf653e23e029f001ce46ed691e32cd4bb3c13f5a1a0925andglm_glue.fatbinfddc0e248769be4bdde544c779102d2dea4319423463b0e8e4df03ff355b037f(other bytes than this tree's, with the same SASS function by function, under Receipt).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. The runs in WSL 2, CI's pytest command among them, are on33f5a3c9fa, a form I did not push, 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" -Dsm=80,86,89,120,121($NVCCis nvcc 13.0.88) (exit 0 both); this tree was built once more in the same cache after its two new launch records were filled from the first build's limits, and the runs below use that build.tf-cuda-test mla-sink "$MAIN/zig-out/fatbin/hy4_mla_attention.fatbin"($MAINis main's tree): 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 in the first item).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 (3c7185694f, not pushed, with 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:fmt,zig,zig-b,zig-windows,zig-macos-dev-tools,pytest(822 passed, 105 skipped, 826 subtests passed; the run in WSL 2 above has 821 and 106, and the CI log does not print skip reasons),release-paths (ubuntu-24.04),comfyui-moss-installerand bothbenchmark-clientsjobs passed;host-nightly-linuxandhost-nightly-macoswere skipped. The annotations are GitHub's Node.js 20 deprecation warnings and a macOS runner queue notice.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 (the first form,3c7185694f, not pushed), 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, and the limits: under "Checks on this head", first, with the images tested (the contract exits 0; the limits exit 1 with the same 154 stale records of other images as main8e0548f715; the 10REDlines are the limits tool's own planted controls, the same on main). 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; the new records holdtf_mla_expand_v_256at 96 or 95 registers and 128 static shared bytes,tf_mla_merge_sinkat 31 to 40 registers.The GB10 run's lines
From the runs and the images named under "Checks on this head", as the runner printed them; the
FAILlines are the planted controls' own.tf-cuda-test mla-sink "$MAIN/zig-out/fatbin/hy4_mla_attention.fatbin", exit 0:tf-cuda-test kernel-contract mla, exit 0:tf-cuda-test kernel-contract-limits zig-out/fatbin, the two new launches' 10 lines (exit 1 with154 problems, as on main):Checklist