Skip to content

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

Draft
Bizuayeu wants to merge 1 commit into
ashhart:mainfrom
Bizuayeu:pr/mla-v256-sink
Draft

Bizuayeu wants to merge 1 commit into
ashhart:mainfrom
Bizuayeu:pr/mla-v256-sink

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 with hy4_flash's arithmetic:

  • tf_mla_expand_v_256: tf_mla::expand_v at 256-wide v heads. The body is already in common/mla.cuh, and hy4_flash instantiates it as tf_hy4_expand_v in its own image. Mla.expandV takes 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 is hy4_flash's tf_hy4_attend_merge, moved to common/mla.cuh as tf_mla::merge_sink, with one change: each entry passes its thread's column (threadIdx.x * 4) in, so that tf_hy4_attend_merge's SASS stays main's (below). tf_hy4_attend_merge now calls it, in its own image, with its entry name and --fmad=false. Mla.mergeSink launches the new entry.
  • geometry() takes the widths the kernels take: q_nope 128 or 192 (both absorbs exist) and v 128 or 256. Nothing outside mla.zig calls it today.

GLM's path uses neither entry. GLM expands with its own tf_glm_expand_v and merges with tf_glm_merge, and the mla image'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).

Checks on this head

  • Head commit: b3fca7fcf3 on main 8e0548f715. The GB10's runs below are on 5e47d70a19, which differs from this head only in text: its CHANGELOG.md line reads #TBD where this head names this pull request. CI's pytest and the other runs in WSL 2 are on 33f5a3c9fa, which also has the two new launch records at zero.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 164 problems on main 8e0548f715 and 164 on this head, 0 new (tools/zig/lean_new.py). The 164 are inherited from main. common/mla.cuh grows from 342 to 365 lines and mla.zig from 188 to 210; the new test has 131.
  • Tests run, with the command and pass, fail and skip counts (Zig 0.17.0, nvcc 13.0.88, one GB10, sm_121):
    • On the GB10, this tree and main 8e0548f715, each built from an empty global cache with zig 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 bound and PASS sink merge: tf_hy4_attend_merge gives the other build's bytes at all 18 shapes. The 18 shapes are hy4_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, plus 2^-20 of the summed magnitude over the denominator. tf-cuda-test kernel-contract mla: exit 0 (its SUMMARY is below).
    • On the GB10, this tree: zig build -Dfixed-cpu test-cuda-host --summary all failed 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 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 --check and zig ast-check on the 8 Zig files, and git diff --check, clean; zig build -Dfixed-cpu compile-cuda-tests without nvcc, 12 of 12 steps; tools/zig/check_cuda_sources.py with a clang++ on the four CUDA sources that this changes or that include common/mla.cuh, 18 of 24 checks passed, as on 8e0548f715 (the 6 that fail stop at glm_index_rope.cuh's memcpy, 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:cacheprovider from the root, with pytest 9.2.0 and PyYAML 6.0.4 and a clang++ on PATH: 821 passed, 106 skipped, 826 subtests passed, the same counts and skip reasons as 8e0548f715.
  • CI: running on b3fca7fcf3 (pushed at 18:07 UTC); this line will carry the jobs' results.
  • Not run, and why: other GPUs than the GB10 (sm_121) for the gates; the new launch records are nvcc 13.0's for sm_80, 86, 89, 120 and 121 (13.3's are pending, as for the image's other entries); Metal and HIP (no change there); a served model (no checkpoint calls the new entries yet, and 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.

  • Main against branch: cuobjdump -sass of each tree's hy4_mla_attention, mla and glm_glue fatbins above, compared function by function at all five SMs (tools/zig/sass_compare.sh counts 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, and tf_mla_expand_v_256 and tf_mla_merge_sink added at each SM; glm_glue, 250 of 250 equal. With the column read inside the moved body instead (3c7185694f), nvcc 13.0.88 gave tf_hy4_attend_merge other 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.
  • Boxes it reaches: CUDA MLA, when a family calls the new entries; hy4_flash's CUDA attention merge.
  • New switch? None.
  • Environment: TensorFold main 8e0548f715 and this head, Zig 0.17.0, nvcc 13.0.88, one GB10 (sm_121).
  • Exactness: tf_hy4_attend_merge gives main's bytes and tf_mla_merge_sink gives tf_hy4_attend_merge's, at hy4_flash's shapes, as above.
  • Decode and prompt speed: n/a, no served path changes.
  • Licence of any new weights or drafter: n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: tf_mla_expand_v_256 (contract_mla_proj.zig, rows 1, 8 and 70 at 32 and 64 heads) and tf_mla_merge_sink (contract_mla_chunks.zig, through tf_mla_chunks_r16 at 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 by expf(m - top) and sums mass and output in chunk order with explicit fmas, starting from the sink's expf(sink - top), and rounds once to bf16.
  • A planted control for each new kernel, and each one fails as planted: tf_mla_expand_v_256 reading each head's weights from the next head, and tf_mla_merge_sink with 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).
  • Each backend's SUMMARY line and exit status: tf-cuda-test kernel-contract mla on 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 and tf_mla_merge_sink's at 1.26 times. Limits: tf-cuda-test kernel-contract-limits zig-out/fatbin on the same builds: the 10 records of the two new launches (sm_80, 86, 89, 120 and 121) are current, tf_mla_expand_v_256 at 96 or 95 registers and 128 static shared bytes, tf_mla_merge_sink at 31 to 40 registers; the other images' records are 154 stale on this tree and the same 154 on main 8e0548f715, none of them this pull request's, so both exit 1 with 154 problems; the 10 RED lines are the limits tool's own planted controls, the same on main.
  • Chips I could not run: every CUDA GPU but the GB10.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (the GPU test and the contract need the new entries; the host test needs the new widths).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

…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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant