Repository navigation
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
Merged
Conversation
Bizuayeu
force-pushed
the
pr/mhc-core
branch
from
November 26, 2026 05:06
02f3261 to
cc447c2
Compare
Bizuayeu
marked this pull request as ready for review
November 26, 2026 06:49
This was referenced Nov 26, 2026
…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.
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. |
8 tasks 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
GLM's mHC pre side (
tf_glm_hc_partial,tf_glm_hc_partial8,tf_glm_hc_finishandtf_glm_hc_finish_f32w) takes its bodies from a newzig/kernels/cuda/common/mhc.cuh(namespacetf_mhc), so that another family can instantiate them with its own mix RMS step.tf_mhc::finishtakes that step from its caller asMixRms::inv; GLM's,1 / sqrt_approx(eps + mean)with Triton's division, stays inglm_glue_hc.cuhasglm_hc::MixRms. GLM keeps its entries, their names, widths and factors, andglm_pdl::enter()inglm_glue_hc.cuh. GLM-5.3-Flash's token ids and logits bits are main's over four launches an arm (below), and everyglm_gluefunction'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);partial8andfinishare device functions. As a device function readingthreadIdx.xitself, the entry got other SASS at sm_120 and sm_121 (nvcc 13.0.88 kept a& 7that main's entry drops from its launch bound of 128), and takingthreadIdx.xfrom the entry or assuming its bound gave other SASS at all five SMs. The macro form has upstream precedents inqwen4_hc.cu'sTF_HC_KERNELandqmmf.cu'sTF_QMMF_GROUP_ENTRY.The post side (
glm_glue_rows.cuh'shc_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.tsvre-pinsglm_glue_hc.cuhand pinscommon/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 to84d9b6ba13;git merge-tree --write-treeof this head with it merges without a conflict, and main has not changedzig/kernels/cuda/glm_glue*,zig/kernels/cuda/common/orzig/src/families/glm/since920fe22c97.atc overlap --json: atc 0.9.4 withATC_READ_ONLY=1and--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, 9conflicts, 1cleanand 12unknown. 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-treeof the pull request's head (checked against itsheadRefOid) with920fe22c97and with this head: 173 conflict with920fe22c97already, 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 ingradient-serving.tsv(five to six): it re-pinsglm_glue_hc.cuhtoo.Checks on this head
zig build native fatbins -Dnvcc="$NVCC" -Dsm=121($NVCCis nvcc 13.0.88; undersetarch -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): main920fe22c97'stensorfold-native, sha256281581b41a1f7fedb43183b132efd8ef1cadc519bfea20b5d8292a33a39fc436, 132,605,384 bytes, and this tree's,6a016f2e40d32dfc6f2a04d43bf9423d7e37bc9f11a98275d7305e2404179b90, 132,735,920 bytes. Each launch checked the running executable's sha256 on both ranks.zig-out/fatbinimages, 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(maind60e6544659758ee…, this treefa00fa24fd6f4f28…, 53 of 53 functions at sm_121) andglm_index.fatbin(2 of 2; this commit does not reach its sources, and its bytes differ from build to build).golden_http.py's three prompts (dc.json fromdocs/receipts/glm-fp4local-80517fc3/tools/, 2,066 to 2,108 ids, 512 tokens greedy withignore_eos) gave drafted replies equal to"draft": falseand the sametoken_sha256as every other launch on that checkpoint: FP4-Localdb45a54eb863ca46…(code),ba28cfb7c5b94418…(count),dae7e2a5c84e5b6f…(prose); NVFP4ddd42119a8be799e…,6faafd98ec90322f…,b82116bdbaa49958….prompt_logprobs: 20on 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 refusedlogprobsfor generated tokens (logprobs are not supported by this model or backend), so the generated tokens are covered by their ids.cc447c218aon main920fe22c97. The runs above, on the GB10s and in WSL 2, are on02f3261c5c, which differs from this head only in text: itsCHANGELOG.mdline and twogradient-serving.tsvnotes read#TBDwhere this head names this pull request. On this head in WSL 2:git diff --checkclean,test-gradient-serving1 of 1,test-glm-pdl-scan3 of 3 andcompile-cuda-tests12 of 12;tools/pr_check.py --base 920fe22c97 --pr 5164, 0 errors.python3 tools/zig/lean_check.py, on the base and on this head: 164 problems on main920fe22c97and 164 on this head, 0 new (tools/zig/lean_new.py). The 164 are inherited from main.glm_glue_hc.cuhgoes from 246 lines to 52;common/mhc.cuhhas 222.tensorfold-native serve SNAPSHOT --tp 2 --rank R --master ADDRESS --master-port 29583 --context 40960 --parallel 4 --port 8197 --name local-model --no-update-checkwithTF_GLM_EXPERT_FORM=classic(every launch reportedexperts 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; nodisabled,fallbackorcompile failedoutside NCCL's lines; before each launch both hosts passedtf-preflight, and no heat-cap switch was logged during the launches. FP4-Local reportedmodel 90.20 GiBand NVFP4model 93.45 GiB.glm_glue.cucompiled twice from each tree with the build's own nvcc line for sm_80, 86, 89, 120 and 121 (fatbins main1c5dec9f23a6682c…, this tree769ae42d111f40d9…, the same bytes each time):cuobjdump -sasssplit by (SM, function), 265 of 265 equal between the trees and within each.920fe22c97:git diff --checkclean;zig build -Dfixed-cpu compile-cuda-tests12 of 12 steps,test-gradient-serving1 of 1 test andtest-glm-pdl-scan3 of 3 (this tree);tools/zig/check_cuda_sources.py zig/kernels/cuda/glm_glue.cuwith clang++ 0 of 6 checks on both trees with the same errors;host_tests_test.pyOK on both; CI's pytest,python -m pytest -q -rsfrom the root: 853 passed, 116 skipped and 827 subtests passed on both, with the same skips.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-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. The head also merges cleanly with main67ae36c4dc, and everygradient-serving.tsvpin matches its file in that merged tree.tools/bench_openai.pyandtools/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:Boxes it reaches: CUDA GLM-5.3-Flash's mHC pre side (full GLM-5.3's layers take
rmsnormByinstead):tf_glm_hc_partialon prompts of 64 rows or more,tf_glm_hc_partial8on decode windows,tf_glm_hc_finishwhere a layer's norm weight is stored as bf16 andtf_glm_hc_finish_f32wwhere it is f32.New switch? None.
Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main
920fe22c97and 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-Localat76348ddb2be2e35e39ecfc00e75dc07703f4f3d5andnvidia/GLM-5.3-Flash-NVFP4atda920bb0b9f4a06727223a349e55468e38352348(the revision on these hosts; the recipe's runs read423acf37).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'shcPre:partial8under 64 rows,partialfrom 64; the finish by the norm weight's stored type) and the checkpoints' stored types (FP4-Local:input_layernormbf16 in all 46 layers,post_attention_layernormf32 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 --serialortoken_shaagainst"draft": false:token_sha256against"draft": falsein 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
"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).--drafter, no slower than without it, greedy and sampled (the SASS of every changed function is main's).