Skip to content

glm cuda: each decode window width keeps its faster expert form - #3249

Merged
ashhart merged 3 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-expert-form-width
Nov 20, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-expert-form-width

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

GLM's CUDA load now races its classic and factored NVFP4 expert forms, which give the same bits, at each of its ten timed window widths and keeps the faster form at each, where it kept one form for every width. This is not a complete fix: where factored's lead at a width sits near the race's 1% margin, two launches of one build can keep different forms there. On four GB10s at TP=4 this receipt's two racing launches did so at 12 and 32 rows (factored, classic at 3, 4, 6 and 24 rows and classic, factored at 1, 2, 8 and 16 rows; across the two records, factored's time there is 1.1 and 1.2% under classic's), and two launches of a diagnostic build of the same race did at 8, 12, 16 and 32 rows. At 8 rows the two forms' decode rounds differ by about 2% in serving (the first table's 8-stream cell below), so a launch that keeps classic there gives that back. TF_GLM_EXPERT_FORM (#3151) names one form for every width when a comparison needs one.

Main's race sums the 2-, 4- and 8-row windows and one draft step on each form and runs every decode window on the winner. A sum hides the widths it loses: on TP=4, #3151's receipt timed each form on its own, and against classic, factored's rounds are 4.82% shorter at one stream, 1.67% longer at four and 2.18% shorter at eight. This head times both forms at 1, 2, 3, 4, 6, 8, 12, 16, 24 and 32 rows, keeps classic at a width unless factored is more than 1% faster there, and prices each width at its kept form's time. A window runs on the form of the narrowest timed width that holds it: rank 0 sends the forms to every rank as a bit a row count, and the price record keeps a bit a width. The record's key carries the build's hash, so no single-form build's record is read for its forms.

The race sweeps every width five times on both forms, untimed, before it times a window; then each width's timed windows take the two forms in turn, classic first on even rounds and factored first on odd ones. Timed one form after the other, the order picked the form: on TP=4, a log of every run showed classic's narrow widths up to 60% over their later time in a load's first 4 s, and a 4 to 6% drift through the race on one form. From an empty price cache, this head's two racing loads loaded in 57.9 and 58.1 s, and #3151's head's first launch in #3151's receipt, on the same ring and racing as main does, in 56.7 s; loads that read a record loaded in 43.0 to 43.8 s here. TF_GLM_EXPERT_FORM now names one form for every width: the warm-up sweeps that form ten times, the load times the windows and the draft step at it, and a load that times nothing sends it to every rank for every row count. The startup line names one form when every width shares it, else the more common form and the widths where the other runs, as in glm: windows (timed): … experts factored, classic at 4 and 6 rows.

On four GB10s at TP=4 (GLM-5.3-Flash XSFP4, --context 1048576 --parallel 8), round time in ms from our own grid client ("draft": false, greedy, 256 tokens, each launch's median of six reps), lower is faster, two launches each:

Cell (a 4,096-token prompt) #3151's head this head this head's form there, against #3151's
1 stream 27.699, 27.809 26.407, 26.397 factored, classic
4 streams 46.898, 47.196 46.919, 46.861 classic, classic
8 streams 73.277, 73.321 71.675, 71.591 factored, classic

Here #3151's head raced to classic for every width (glm: windows (timed): … experts classic), and this head's launches read the second race's record, factored at 1, 2, 8 and 16 rows. Taking a cell as different only where both launch pairs lean the same way by more than the larger of the two builds' launch-to-launch gaps, this head's rounds are 4.87% shorter at one stream and 2.27% shorter at eight, where the forms differ, and at four streams, where both keep classic, the two can't be separated (-0.33%). In #3151's receipt main and #3151's head raced to factored, and against that draw the forms differ at four streams instead, where that receipt timed factored's rounds 1.67% longer than classic's. So the grid ran again: #3151's head with TF_GLM_EXPERT_FORM=factored, which runs factored at every width, and two more launches of this head, which read the second race's record:

Cell (a 4,096-token prompt) #3151's head, factored named this head this head's form there, against #3151's
1 stream 26.666, 26.405 26.381, 26.380 factored, factored
4 streams 47.917, 48.642 46.989, 46.954 classic, factored
8 streams 71.676, 71.774 71.761, 71.703 factored, factored

By the same rule, this head's rounds are 2.70% shorter at four streams, where it keeps classic against factored: #3151's head's two launches there sit 1.5% apart, and every rep of this head's two is under every rep of theirs. At one and eight streams, where both run factored, the two can't be separated (-0.58% and +0.01%). Every launch's replies are the same.

Tests:

  • New (glm_lane_costs_host.zig): "each width keeps the form its windows ran faster on, and classic inside the margin", "a dip is timed again at each width's own form, not the last raced one", "a slow start outlasting the old warm-up decides no width's form and sets no price", "a drift through the race falls on both forms alike", "a window run slow right after the other form decides no width's form" and "a window takes the form of the narrowest timed width that holds it"; and in cuda_lane_costs.zig, "a raced line names the more common form and the widths where the other runs".
  • Changed: "DFlash2 races the forms at every width without timing head steps or keeping prices" and "MTP keeps each width's raced time as its price, then the two-level head slope" (were "DFlash2 races expert forms without timing unused windows or head steps" and "MTP retains every timed width and the two-level head slope"); the untimed test now wants every row count's bit for the named form.
  • Red, on the tree before the rebase: one copy of that head a break, each run on test-glm-lane-costs-host (10 tests) unless named. One form for every width, the more common one, as main keeps: "each width keeps…" (expected 998, found 1023) and "a dip is timed again…" fail. The kept forms not set before the prices are smoothed and the rows sent: the same two. No sweeps: "a slow start…" (actual 36, expected 21). Classic first in every round: "a window run slow right after the other form…" (expected 1023, found 0). Each form's table timed in one block, as main times its forms: "a drift through the race…" (expected 0, found 1023). Every width priced at classic's time: the MTP price test and the three others that read prices. Only the 2-, 4- and 8-row widths raced, as main races: six, the DFlash2 and MTP race tests among them. A window on the widest timed width under it instead of the narrowest that holds it: "a window takes the form…" (expected 8, found 24). The startup line's majority counted at half the widths: only "a raced line names the more common form…" fails, in test-cuda-host (6,365 of 6,396). A copy that ignores the name in four places (as glm cuda: TF_GLM_EXPERT_FORM names the expert form, so launches compare at one form #3151's red copy did, at this head's code) fails exactly glm cuda: TF_GLM_EXPERT_FORM names the expert form, so launches compare at one form #3151's four naming tests in test-cuda-host (6,362 of 6,396) and the named-form test in test-glm-lane-costs-host (9 of 10, expected 1, found 241). On the rebased tree, the GLM cost identity tests (11): with glm cuda: TF_GLM_EXPERT_FORM names the expert form, so launches compare at one form #3151's first check back in reuses(), where a record with any factored width reads as the factored form, only "a record kept at one named form is not reused at the other" fails, at the mixed-record line (10 of 11); as written, 11 of 11.

Checks on this head

  • Head commit: cd560c8079, the CHANGELOG line on top of b31a7f4ffc. It changes no code. The gate, the lean checker and the overlap below ran on this head; the receipt ran the change before the first rebase, 4f9832ca00.
  • Lean checker, python3 tools/zig/lean_check.py, on the base (e7ff97e132) and on this head: 221 and 221, no new findings. On main af9777b494 and this head merged with it: 221 and 221, the same findings.
  • Tests run, with the command and pass, fail and skip counts: the whole gate on this head's tree in WSL (x86_64, Zig 0.17.0), zig build with test -Dfixed-cpu, test-kernel-contract, test-golden, test-cuda-host, compile-cuda-tests (x86_64 and aarch64), check-native-cuda-host, test-glm-lane-costs-host, test-glm-window-prices-host, test-glm-fact-contract-host, test-cuda-startup-costs-host, test-glm-startup-host and test-glm-link-transport-host: test 10,237 of 10,315 with 78 skipped, test-kernel-contract 244 of 244, test-glm-lane-costs-host 10 of 10. test-cuda-host first ran 7,117 of 7,151 with 33 skipped and one failure, the server's cortheon fuzz: every reader takes linear time on long inputs, a timing test this change does not reach; run again on the same tree the step passed, the test binaries that had not passed running 1,683 of 1,691 with 8 skipped. pytest from the root with the CI's options plus -rs (-q -rs -p no:cacheprovider): 522 passed, 86 skipped and one failure, tools/zig/zig_cache_restat_test.py's test_prune_keeps_one_build, whose own zig build hit its 300 s limit while another build held this machine's one-build-at-a-time lock; run again alone, that file's two tests passed. Main's CI pytest at e7ff97e132 has 525 passed and 84 skipped, the same 609 tests, and prints no skip reasons. Two of the skips here are tools/zig/test_nfkd_tables.py's, which want Unicode 16.0.0 (this Python 3.12 has 15.0.0).
  • CI: zig, zig-b, zig-windows, zig-macos-dev-tools, pytest (583 passed, 87 skipped), release-paths, both benchmark-clients jobs and fmt passed; the two nightly host jobs report skipped.
  • Not run, and why: Metal, HIP, Vulkan and XPU builds and tests, with no such machine here. Only GLM's CUDA load races the forms (price in families/glm/cuda_lane_costs.zig), and only GLM's CUDA decode windows read them (cuda_moe.zig).

Receipt

T bench_openai fibonacci-raw bench_openai gpu-chat-no-think bench_concurrent 1 stream 4 streams 8 streams
0 53.68, 53.69 → 54.14, 53.91 43.00, 43.02 → 43.48, 43.29 64.9, 65.1 → 65.3, 65.0 108.9, 109.1 → 109.1, 109.0 118.5, 118.5 → 117.0, 118.9
1 70.04, 71.16 → 71.38, 72.05 60.76, 58.02 → 62.01, 61.21 74.5, 74.7 → 77.4, 73.8 102.5, 103.3 → 103.5, 103.3 111.6, 112.7 → 113.5, 112.6

At T=0 the four launches draft the same rounds, accepted and drafted tokens. By the same pair rule, this head's bench_openai gpu-chat-no-think median is 0.87% higher; fibonacci-raw (+0.64%) and the three bench_concurrent cells can't be separated. At eight streams one launch of this head sat at 117.0, every rep of it under every rep of #3151's head's two, and the other at 118.9, over them. At T=1 the drafting differs from launch to launch, so those figures are for the record.

  • Prompt speed before and after: n/a. The form reaches only decode rows (cuda_moe.zig sets it only when the pass is not a prompt's), so prompt passes run the same kernels on either build.
  • Licence of any new weights or drafter: 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. (The red copies above. None needs a GPU, a checkpoint or the process environment, so none skips.)
  • 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. (The forms only pick the kernels a decode window already runs, with drafts or without.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (bench_concurrent --alone --serial on the four drafted launches above; the forms reach only decode rows, which give the same bits on either.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No bits change: every launch's replies equal glm cuda: TF_GLM_EXPERT_FORM names the expert form, so launches compare at one form #3151's head's.)
  • 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. (Without drafts this head's rounds are 4.87% shorter than glm cuda: TF_GLM_EXPERT_FORM names the expert form, so launches compare at one form #3151's head's at one stream and 2.27% shorter at eight, and the two can't be separated at four; against glm cuda: TF_GLM_EXPERT_FORM names the expert form, so launches compare at one form #3151's head naming factored, they are 2.70% shorter at four and can't be separated at one and eight. With drafts at T=0 one figure is 0.87% higher and the other four can't be separated; at eight streams one launch of this head sat 1.3% under glm cuda: TF_GLM_EXPERT_FORM names the expert form, so launches compare at one form #3151's head's two, every rep of it under every rep of theirs, and the other above them. The form reaches only decode rows. Where factored's lead at a width sits near the race's margin, two launches can keep different forms there, as the first paragraph says.)

Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Nov 13, 2026
@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. The host tests cover the width mapping, calibration order and saved cost reuse, and they pass.

We will run the device check on our side for classic, factored and automatic selection at one and two ranks, including first and cached loads. We will check that both ranks receive the same effective mask, complete tokens match the plain target with each drafter, and decode stays within main's measured range. Startup calibration time will be reported separately.

  • Synthena (Ash's Agent)

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

We will run the device check on our side for classic, factored and automatic selection at one and two ranks, including first and cached loads.

#3249 (comment)

Thanks. One note before that run: this head (bc6349146d) sits on #3151's earlier head, and #3151 has since gained 63dcb400ff, which moves the price cache's reuse check into reuses() and adds a test. Once #3151 lands, I'll rebase this onto main: the form check here goes into reuses() as it is, and that test's factored record becomes factored at every width. Nothing else changes, and the same gate runs before the push. If you'd rather run the device check on that head, I can push it as soon as #3151 is in.

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. The 35 focused host checks pass, and no new code ask is open. We will run the device check on our side for automatic, classic and factored selection at one and two ranks, including first and cached loads. We will carry the reuses() integration forward with #3151 before landing.

  • Synthena (Ash's Agent)

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

We will carry the reuses() integration forward with #3151 before landing.

#3249 (comment)

Thanks. One addition you could carry with it: a record raced by width in #3151's test of reuses(). Once a record holds a form per width, it is the case that tells the per-width check from #3151's (pin.? == (kept.fact != 0)): only the race reuses it, while #3151's check also reuses it under factored. The last four lines are the new ones; the every(true) line is the change I noted before:

    var factored = classic;
    factored.fact = measurements.every(true);
    try std.testing.expect(reuses(factored, false, true) and !reuses(factored, false, false));
    // a record raced by width stands for the race alone, not for either named form
    var mixed = classic;
    mixed.fact = 1;
    try std.testing.expect(reuses(mixed, false, null) and !reuses(mixed, false, true) and !reuses(mixed, false, false));

On main 2ba55ec7d3 with #3151's head merged and this change, reuses() checking kept.fact == measurements.every(pin.?), the GLM module's tests filtered to GLM cost identity: pass 11 of 11. With #3151's check put back, 10 of 11 pass: #3151's "a record kept at one named form is not reused at the other" fails at the raced record's line.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Our GB10 check is in: GLM-5.3-Flash NVFP4 at TP=2 on two GB10s, main against bc63491, fresh launches base, new, new, base, plus a chat pair, with automatic expert-form selection.

  • Tokens: equal in all 52 cells, and the chat resume cells cache identically on both arms.
  • Speed: level. Decode moves −1.5% to +0.6%, inside the run spread. The +31% at 2K comes from base's cold first run only (466 to 891 tok/s within that run; both new runs and base's last sit at 848 to 889). The 8K median reads −8.8%, but base's last run slows the same way within its own samples (828 down to 706), and we saw that shape in another PR's GLM pair today. It's the box, not this change.
  • GLM at TP=1 doesn't fit one GB10, so the one-rank cells can't run here. The automatic path above is the one serving takes.

It now conflicts with main and needs a rebase onto main once #3151 lands (#3151 is in the landing queue). With that rebase and CI green, it's ready to queue.

  • Synthena (Ash's Agent)

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

It now conflicts with main and needs a rebase onto main once #3151 lands (#3151 is in the landing queue). With that rebase and CI green, it's ready to queue.

#3249 (comment)

Thanks for the run. I'll do that rebase: once #3151 lands, I'll rebase this onto main with the form check in reuses() and the raced-record lines from my last comment, run the same gate, and push. If you'd rather carry it with #3151 yourself, say so and I'll leave the branch as it is.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. Please go ahead with the rebase once #3151 lands, keeping the full per-width form comparison in reuses() and adding the mixed-record case you supplied: a mixed record must never be reused as either named form.

Our automatic TP=2 run already matched all 52 cells, resumed cache counts included, and that result stands. With the rebase and green CI it's ready to queue; no one-rank run is needed, since the model can't fit on one GB10.

  • Synthena (Ash's Agent)

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

Please go ahead with the rebase once #3151 lands, keeping the full per-width form comparison in reuses() and adding the mixed-record case you supplied

#3249 (comment)

Rebased onto main e7ff97e132; the head is cd560c8079. reuses() keeps the per-width comparison, and #3151's test gains the mixed-record case. CI is green on this head. The description has the conflict's resolution and the test counts.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. Everything we asked on 16 Nov is in:

Our TP=2 GB10 run (tokens equal in all 52 cells, resumed cache counts included) stands. Nothing more from us.

  • Synthena

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

The rebase: the branch is rebased onto main after #3151, and it applies to current main cleanly.

(#3249 (comment))

Since that comment main (6db2561b18) has moved under this branch in one place. 63996caef6 added eight rows to the table in docs/environment.md (TF_GLM_INDEX_CUDA through TF_MINIMAX_WORLD) directly below the TF_GLM_EXPERT_FORM row, which is the row this PR rewrites, so GitHub now reports the PR as conflicting. git merge-tree against 6db2561b18 names docs/environment.md as the only conflict; CHANGELOG.md, docs/recipes/glm-5.3-flash-cuda.md and zig/src/platform/environment.zig merge by themselves.

The resolution is to keep both sides: this PR's TF_GLM_EXPERT_FORM row in place of main's, then main's eight new rows as they stand. No code is involved.

One more thing the merge does without a conflict: this PR's CHANGELOG.md entry was written before the release, so a plain merge leaves it inside the ## 1.2.10 section. It belongs under ## Unreleased.

The branch is left at cd560c8079, the head you checked. If you would rather have it rebased here, say so and we will push it.

@ashhart
ashhart force-pushed the pr/glm-expert-form-width branch from cd560c8 to 8d60877 Compare November 19, 2026 06:18
ashhart pushed a commit to Bizuayeu/TensorFold that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

Bizuayeu and others added 3 commits November 20, 2026 12:00
GLM's load-time race summed the 2-, 4- and 8-row windows and one draft step of its classic and factored NVFP4 expert
forms, then ran every decode window on the winner. A sum hides the widths it loses: at TP=4 the factored form wins at
1 and 8 rows but loses at 4 and 6, so four streams without drafts decode about 2% slower than on classic.

Both forms give the same bits (the NVFP4 fact contract holds the factored tiles and waves to the decode form's sums),
so each window can take either. The race now times both forms at all ten widths, keeps classic at a width unless
factored is more than 1% faster there, and prices each width at its kept form's time instead of timing the table
again. A window runs on the form of the narrowest timed width that holds it: rank 0 sends the forms as a bit a row
count, and the record keeps a bit a width. Records carry the build's hash in their key, so no record of a single-form
build is read for its forms.

The race sweeps every width five times on both forms, untimed, before it times a window, then each width's timed
windows take the two forms in turn, classic first on even rounds and factored first on odd ones. Timed one form after
the other, the order picked the form: on four GB10s at TP=4 a log of every run showed classic's narrow widths up to
60% over their later time in a load's first 4 s, and a 4 to 6% drift through the race on one form, so two launches of
one build kept different forms at 3, 4, 6 and 12 rows. Five sweeps of both forms take about 5.4 s there.

TF_GLM_EXPERT_FORM now names one form for every width: the warm-up sweeps that form ten times and the load times the
windows and the draft step at it, and a load that times nothing sends it to every rank for every row count. The
startup line names one form when every width shares it, else the more common form and the widths where the other runs
(experts factored, classic at 4 and 6 rows).
@ashhart
ashhart force-pushed the pr/glm-expert-form-width branch from 8d60877 to 976ef04 Compare November 20, 2026 12:00
@ashhart
ashhart merged commit 5780a03 into ashhart:main Nov 20, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 20, 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