Skip to content

cuda glm: mHC's pre-side bodies move to common/mhc.cuh, the finish taking the mix's RMS step from its caller - #5164

Merged
ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/mhc-core
Nov 26, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/mhc-core

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

GLM's mHC pre side (tf_glm_hc_partial, tf_glm_hc_partial8, tf_glm_hc_finish and tf_glm_hc_finish_f32w) takes its bodies from a new zig/kernels/cuda/common/mhc.cuh (namespace tf_mhc), so that another family can instantiate them with its own mix RMS step. tf_mhc::finish takes that step from its caller as MixRms::inv; GLM's, 1 / sqrt_approx(eps + mean) with Triton's division, stays in glm_glue_hc.cuh as glm_hc::MixRms. GLM keeps its entries, their names, widths and factors, and glm_pdl::enter() in glm_glue_hc.cuh. GLM-5.3-Flash's token ids and logits bits are main's over four launches an arm (below), and every glm_glue function's SASS is main's at sm_80, 86, 89, 120 and 121.

  • tf_glm_hc_partial's body is a macro its entry expands (TF_MHC_PARTIAL_BODY); partial8 and finish are device functions. As a device function reading threadIdx.x itself, the entry got other SASS at sm_120 and sm_121 (nvcc 13.0.88 kept a & 7 that main's entry drops from its launch bound of 128), and taking threadIdx.x from the entry or assuming its bound gave other SASS at all five SMs. The macro form has upstream precedents in qwen4_hc.cu's TF_HC_KERNEL and qmmf.cu's TF_QMMF_GROUP_ENTRY.

  • The post side (glm_glue_rows.cuh's hc_post_tail) stays in GLM: ERNIE's post side sums in another fp32 order, so a shared body would not serve it.

  • zig/tests/fixtures/gradient-serving.tsv re-pins glm_glue_hc.cuh and pins common/mhc.cuh, since the bodies leave the pinned file.

  • Issue: Refs ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926. This is the mHC move agreed at ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment) ("mHC: yes, as you describe. The core body takes the RMS step from its caller, with glm's step in glm's instantiation and ERNIE's in ERNIE's. GLM-5.3-Flash token ids and logits bits stay equal to main's, over four launches an arm.").

  • Stacked on: main (920fe22c97); one commit, cc447c218a: 4 files, 236 insertions, 205 deletions. Main has since moved on to 84d9b6ba13; git merge-tree --write-tree of this head with it merges without a conflict, and main has not changed zig/kernels/cuda/glm_glue*, zig/kernels/cuda/common/ or zig/src/families/glm/ since 920fe22c97.

  • atc overlap --json: atc 0.9.4 with ATC_READ_ONLY=1 and --base 920fe22c97, run in this tree on 2026-11-26 at 04:15 UTC: complete: false (otherPullRequestsLimit, pullFilesUnavailable, pullRequestsLimit, timeLimit), 22 pull requests in its working tree's rows, 9 conflicts, 1 clean and 12 unknown. For each of those and the other open pull requests that share a file with this commit, 200 in all that share a file with this commit, git merge-tree --write-tree of the pull request's head (checked against its headRefOid) with 920fe22c97 and with this head: 173 conflict with 920fe22c97 already, and all but one keep the same conflicting files and hunks; 27 merge cleanly with both. The one is glm cuda decode: opt-in shared fn loads across rows in hc_partial #4559, which gains a hunk in gradient-serving.tsv (five to six): it re-pins glm_glue_hc.cuh too.

Checks on this head

  • The GB10 runs' identities (TP=2 on two GB10s, rank 0 and rank 1 over their direct link, NCCL over RoCE):
    • Both natives built for these runs from an empty global cache and a fresh tree each, with zig build native fatbins -Dnvcc="$NVCC" -Dsm=121 ($NVCC is nvcc 13.0.88; under setarch -R, since CUDA build: nvcc 13.0.88 gives the router-tiles entries different PTX between identical compiles, about one in ten #5123 found nvcc 13.0.88's front end varying under address randomization on the GB10): main 920fe22c97's tensorfold-native, sha256 281581b41a1f7fedb43183b132efd8ef1cadc519bfea20b5d8292a33a39fc436, 132,605,384 bytes, and this tree's, 6a016f2e40d32dfc6f2a04d43bf9423d7e37bc9f11a98275d7305e2404179b90, 132,735,920 bytes. Each launch checked the running executable's sha256 on both ranks.
    • The two builds' 152 zig-out/fatbin images, each found byte for byte in its native: 150 are the same bytes; two differ in bytes with every function's SASS equal: glm_glue.fatbin (main d60e6544659758ee…, this tree fa00fa24fd6f4f28…, 53 of 53 functions at sm_121) and glm_index.fatbin (2 of 2; this commit does not reach its sources, and its bytes differ from build to build).
    • The gate, the owner's ("token ids and logits bits stay equal to main's, over four launches an arm"): equal. FP4-Local: eight launches, main and this head alternating, four an arm; NVFP4: four more, two an arm. In each launch, golden_http.py's three prompts (dc.json from docs/receipts/glm-fp4local-80517fc3/tools/, 2,066 to 2,108 ids, 512 tokens greedy with ignore_eos) gave drafted replies equal to "draft": false and the same token_sha256 as every other launch on that checkpoint: FP4-Local db45a54eb863ca46… (code), ba28cfb7c5b94418… (count), dae7e2a5c84e5b6f… (prose); NVFP4 ddd42119a8be799e…, 6faafd98ec90322f…, b82116bdbaa49958…. prompt_logprobs: 20 on the first prompt (/v1/completions, "draft": false), 2,066 rows, came back the same in every launch on a checkpoint, compared as parsed numbers: 41,484 logprobs on FP4-Local and 41,621 on NVFP4, each one an f32 exactly (the server widens the f32 and prints the double, so equal numbers are equal bits). The engine refused logprobs for generated tokens (logprobs are not supported by this model or backend), so the generated tokens are covered by their ids.
  • Head commit: cc447c218a on main 920fe22c97. The runs above, on the GB10s and in WSL 2, are on 02f3261c5c, which differs from this head only in text: its CHANGELOG.md line and two gradient-serving.tsv notes read #TBD where this head names this pull request. On this head in WSL 2: git diff --check clean, test-gradient-serving 1 of 1, test-glm-pdl-scan 3 of 3 and compile-cuda-tests 12 of 12; tools/pr_check.py --base 920fe22c97 --pr 5164, 0 errors.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 164 problems on main 920fe22c97 and 164 on this head, 0 new (tools/zig/lean_new.py). The 164 are inherited from main. glm_glue_hc.cuh goes from 246 lines to 52; common/mhc.cuh has 222.
  • Tests run, with the command and pass, fail and skip counts (Zig 0.17.0, nvcc 13.0.88):
    • GLM-5.3-Flash on two GB10s (sm_121) at TP=2, the natives above, each launch a fresh pair of containers (the same CUDA 13.0 runtime image for both arms), rank 1 then rank 0, each rank tensorfold-native serve SNAPSHOT --tp 2 --rank R --master ADDRESS --master-port 29583 --context 40960 --parallel 4 --port 8197 --name local-model --no-update-check with TF_GLM_EXPERT_FORM=classic (every launch reported experts classic (TF_GLM_EXPERT_FORM); each native timed its windows on its first launch and read them kept after), NCCL over RoCE on the hosts' direct link: 12 of 12 launches served (54 to 139 s to /health) and stopped with rank 0's exit 0 (rank 1 exits 143 on the SIGTERM that stops it, in every launch of both arms); 36 of 36 drafted-against-plain checks passed; 12 of 12 logprobs replies all exact f32s; no disabled, fallback or compile failed outside NCCL's lines; before each launch both hosts passed tf-preflight, and no heat-cap switch was logged during the launches. FP4-Local reported model 90.20 GiB and NVFP4 model 93.45 GiB.
    • SASS on the GB10: glm_glue.cu compiled twice from each tree with the build's own nvcc line for sm_80, 86, 89, 120 and 121 (fatbins main 1c5dec9f23a6682c…, this tree 769ae42d111f40d9…, the same bytes each time): cuobjdump -sass split by (SM, function), 265 of 265 equal between the trees and within each.
    • WSL 2 (x86-64), on this tree and on main 920fe22c97: git diff --check clean; zig build -Dfixed-cpu compile-cuda-tests 12 of 12 steps, test-gradient-serving 1 of 1 test and test-glm-pdl-scan 3 of 3 (this tree); tools/zig/check_cuda_sources.py zig/kernels/cuda/glm_glue.cu with clang++ 0 of 6 checks on both trees with the same errors; host_tests_test.py OK on both; CI's pytest, python -m pytest -q -rs from the root: 853 passed, 116 skipped and 827 subtests passed on both, with the same skips.
  • CI: green on cc447c218a: fmt, zig, zig-b, zig-windows, zig-macos-dev-tools, pytest (854 passed, 115 skipped, 827 subtests passed), release-paths (ubuntu-24.04), comfyui-moss-installer and both benchmark-clients jobs passed; host-nightly-linux and host-nightly-macos were skipped. The annotations are GitHub's Node.js 20 deprecation warnings and a macOS runner queue notice. The head also merges cleanly with main 67ae36c4dc, and every gradient-serving.tsv pin matches its file in that merged tree.
  • Not run, and why: other GPUs than the GB10 (sm_121) for the launches; the other SMs' SASS is compared above but not run. The kernel contract and its limits (no entry is new, and the four entries' SASS is main's, so their records hold); tools/bench_openai.py and tools/bench_cache.py (the same reason; the golden replies' seconds are below); resumed, concurrent and sampled replies.

Receipt

  • Main against branch: the twelve launches above, alternating on one pair of GB10s. Token ids and prompt logprobs are main's in every launch. golden_http.py's seconds, the mean of each arm's launches (each a ~2,100-token prompt and 512 tokens; FP4-Local four launches an arm, NVFP4 two), for the record only:

    checkpoint reply main this head
    FP4-Local plain: code, count, prose 22.08, 22.07, 22.00 s 21.98, 21.94, 22.00 s
    FP4-Local drafted: code, count, prose 12.96, 11.12, 15.99 s 13.01, 11.16, 15.99 s
    NVFP4 plain: code, count, prose 29.48, 29.34, 29.52 s 29.60, 29.67, 29.52 s
    NVFP4 drafted: code, count, prose 16.41, 14.19, 19.01 s 16.10, 14.60, 19.27 s
  • Boxes it reaches: CUDA GLM-5.3-Flash's mHC pre side (full GLM-5.3's layers take rmsnormBy instead): tf_glm_hc_partial on prompts of 64 rows or more, tf_glm_hc_partial8 on decode windows, tf_glm_hc_finish where a layer's norm weight is stored as bf16 and tf_glm_hc_finish_f32w where it is f32.

  • New switch? None.

  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main 920fe22c97 and this head; Zig 0.17.0, nvcc 13.0.88, the release image's CUDA runtime; two GB10 (sm_121) at TP=2; nvidia/GLM-5.3-Flash-FP4-Local at 76348ddb2be2e35e39ecfc00e75dc07703f4f3d5 and nvidia/GLM-5.3-Flash-NVFP4 at da920bb0b9f4a06727223a349e55468e38352348 (the revision on these hosts; the recipe's runs read 423acf37).

  • Paths and platforms the change reaches, which I ran and which I could not: all four entries on sm_121, by the launch sites (cuda_glue.zig's hcPre: partial8 under 64 rows, partial from 64; the finish by the norm weight's stored type) and the checkpoints' stored types (FP4-Local: input_layernorm bf16 in all 46 layers, post_attention_layernorm f32 in 45 and bf16 in the MTP layer; NVFP4: bf16 in all), not by a kernel count; the other SMs by SASS only.

  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: token_sha256 against "draft": false in each of the 12 launches (36 of 36 equal), and equal to main's across launches, as above.

  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): above.

  • Decode speed before and after, from tools/bench_openai.py: not run; every changed function's SASS is main's, and the golden replies' seconds above differ between the arms by no more than between an arm's own launches.

  • Prompt speed before and after: n/a for the same reason (the SASS of tf_glm_hc_partial, the prompt entry, is main's at all five SMs).

  • Licence of any new weights or drafter, or "n/a": n/a.

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 (no new tests: the bodies move, and the gate is main's ids, logits and SASS).
  • 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.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off (no change outside the kernels' source).
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo (drafted against plain in every launch above; resumed and concurrent not run: the SASS is main's).
  • No precision traded for speed. If the bits change, the description says which sums change and why (no bits change).
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled (the SASS of every changed function is main's).

Bizuayeu and others added 2 commits November 26, 2026 14:50
…king the mix's RMS step from its caller

glm_glue_hc.cuh's hc_partial, hc_partial8 and hc_finish bodies move to common/mhc.cuh (namespace tf_mhc), so that
another family can instantiate them with its own mix RMS: tf_mhc::finish takes it as MixRms::inv, and glm's,
1 / sqrt_approx(eps + mean) with Triton's division, stays in glm_glue_hc.cuh. The entries, their names, widths and
glm_pdl::enter() stay there too. tf_glm_hc_partial's body is a macro its entry expands: as a device function,
reading threadIdx.x itself, the entry got other SASS at sm_120 and sm_121 (nvcc 13.0.88), and taking threadIdx.x
from the entry or assuming its bound gave other SASS at all five SMs. As a macro, every glm_glue function's SASS is
main's at sm_80, 86, 89, 120 and 121. The mHC post side stays in glm_glue_rows.cuh. gradient-serving.tsv re-pins
glm_glue_hc.cuh and pins common/mhc.cuh.
@ashhart
ashhart merged commit cc7d2e8 into ashhart:main Nov 26, 2026
11 of 12 checks passed
@ashhart

ashhart commented Nov 26, 2026

Copy link
Copy Markdown
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.

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.

2 participants