Skip to content

glm cuda: --mtp-confidence sizes MTP windows by each draft's chance, as Nemotron's does - #1585

Merged
ashhart merged 5 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-mtp-chance
Oct 30, 2026
Merged

ashhart merged 5 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-mtp-chance

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

On GB10 at TP=3 (GLM-5.3-Flash XSFP4, the drafts on, one binary served without the flag and with
--mtp-confidence 0.5, two launches each, the same tokens in every launch):

no flag (as main) --mtp-confidence 0.5 change
Decode, bench_openai, mean of its two prompts' medians (tok/s) 51.51, 51.64 54.10, 54.11 +4.90%
Greedy chat, one stream (bench_concurrent, tok/s) 45.0, 45.0 47.9, 48.0 +6.56%
Greedy code, one stream 57.7, 57.9 59.8, 59.9 +3.55%
Greedy chat / code, four streams 118.3, 118.4 / 149.4, 149.5 118.8, 118.9 / 150.3, 150.8 +0.42% / +0.74%
Four distinct prompts at once, greedy (tok/s together) 70.59, 70.59 75.00, 75.00 +6.25%
Eight distinct prompts at once, greedy 90.44, 90.44 93.44, 94.23 +3.75%
Sampled chat / code, four streams 73.6, 73.6 / 79.6, 80.3 76.1, 76.2 / 80.3, 81.1 +3.46% / +0.94%
Sampled chat / code, one stream 43.1, 43.1 / 43.5, 44.7 41.8, 43.0 / 43.3, 44.6 −1.62% / −0.34%

The sampled one-stream rows draft the same windows with and without the flag (1.855 and 2.000 tokens a round in all
six launches); their spread is the launches', as the no-flag code row's 43.5 and 44.7 show.

At TP=2 (two GB10 joined by one QSFP cable, the same binary and benches, two runs of four launches, the same tokens
in all eight; each cell is the lowest and highest of an arm's four launches):

no flag --mtp-confidence 0.5 change
Decode, mean of the two prompts' medians (tok/s) 40.30–40.54 41.48–41.64 +2.91%
Greedy chat, one stream 36.1–36.3 38.3–38.7 +6.28%
Greedy code, one stream 43.8–44.3 43.9–44.2 +0.06%
Greedy chat / code, four streams 93.9–95.0 / 117.6–118.2 97.3–99.0 / 112.0–115.2 +4.16% / −3.65%
Four distinct prompts at once, greedy 55.12–55.63 58.66–59.85 +7.15%
Eight distinct prompts at once, greedy 68.62–69.91 72.63–73.34 +5.71%
Sampled chat / code, four streams 57.6–57.9 / 68.6–68.9 58.4–59.7 / 69.6–70.0 +2.73% / +1.53%
Sampled chat / code, one stream 35.1–35.2 / 42.4–42.7 34.9–35.2 / 42.5–42.7 −0.14% / 0.00%

Four greedy code streams at TP=2 lose with the flag: every 0.5 launch was slower than every no-flag launch, −4.32% in
the first run and −2.98% in the second. I have not looked into why. Code's drafts are accepted more often than chat's
(the code prompt's decode is 44.2 to 44.6 tok/s with and without the flag), so a floor of 0.5 may cut rows that would
have been accepted, and four streams verify extra rows for little. The flag stays opt-in, and a code-heavy server at
TP=2 is better off without it or with a lower floor (not measured at TP=2).

What this changes

GLM's MTP head gave the lanes no chance for its drafts, so every drafted row went to verify. At TP=3 a verify row
costs about 5.6 ms (TF_GLM_PROF, a window of 2, 3 and 4 rows: 37.64, 42.84 and 48.82 ms), and on mixed text many
deep drafts miss: over eight prose prompts at one stream, 563 of the drafted rows were refused in 970 rounds.

With --mtp-confidence F, GLM serves the flag Nemotron already takes. Every rank picks an MTP draft with
tf_glm_top1_sums, tf_glm_top1's scan with its vocabulary slice's sum of exp(logit - max) in the third word of the
16-byte pair the greedy gather already moves, so the gather and its count do not change. Rank 0 reads the pick's
softmax probability over the whole vocabulary, 1 / sum over ranks of sum_r * exp(max_r - max), and the lanes chain
the drafts' probabilities and stop a chain where its chance falls under F (the lane core's draft_confidence, as for
Nemotron). Leader.draft tells the other ranks to sum with a bit in its step's flags. Sampled and structured drafts
keep chance 1; the flag is refused beside --drafter (DFlash2's chances size those windows) and GLM still refuses
--mtp-drafts. Without the flag every path is main's, and tf_glm_top1's records stay current.

One lane core change comes with it. A confidence floor made every stream draft the most and left the cut to the head's
chances, so a sampled stream, whose drafts carry none, verified the deepest window every round: in a first run of
this branch a sampled chat stream took 2.33 tokens a round in those windows against 1.86 in its rates' ones, with
rounds of 55 against 41 ms, and lost 1.7 to 2.0%. headDepth and depth now keep the rates' depth for a sampled
stream under a floor; greedy streams draft the most as before. This reaches Nemotron's sampled streams under
--mtp-confidence too.

0.5 is the floor I would suggest for GLM: at TP=3, in the first run 0.2 gained less everywhere (decode +1.57%, four
distinct prompts +3.97%, eight +2.46%), and 0.7 gained less at every greedy row and lost 2.83% at four greedy chat
streams. At TP=2 only 0.5 ran.

Receipt

  • Environment: TensorFold 4cea13a40 (main 7c0688951 and four commits, the fourth only the contract test below); the
    launches ran 05c433b45, whose tree differs only in where the lane core's new test sits and in that test. Three GB10
    (sm_121) at TP=3 in a ring of three QSFP cables with no switch, on NCCL, and two GB10 at TP=2 joined by one QSFP
    cable; GLM-5.3-Flash XSFP4; --parallel 8, --prompt-cache-gib 0, zig build native for sm_121 with nvcc 13.0.88.
    At TP=3, launches no flag, 0.5, 0.7, 0.7, 0.5, no flag; at TP=2, no flag, 0.5, 0.5, no flag, twice. Each ran
    bench_openai (256 tokens, 3 repeats, temperature 0), bench_concurrent --alone --serial (one and four streams,
    temperatures 1.0 and 0) and four and eight distinct prompts at once (300 tokens, greedy). An earlier TP=3 run of the
    first two commits (no flag, 0.2, 0.5) found the sampled loss that the third commit fixes.
  • Exactness: at each TP, rank 0's done lines without ids and times are the same in every launch (65 each), the bench's
    token hashes and each distinct prompt's reply hash agree across them, and --alone --serial found every drafted
    reply equal to its "draft": false twin and every concurrent one equal to it alone, greedy and seeded sampled, in
    all 48 cells at TP=3 and 64 at TP=2 (eight a launch). The flag changes which drafted rows are verified, never a sum.
  • Decode speed before and after: the tables above. Rank 0's done lines at TP=3: 10,548 drafted rows with the flag
    against 13,264 without, 7,657 accepted against 7,825 (72.6% against 59.0%); at TP=2: 10,814 against 13,121, 7,810
    against 7,977 (72.2% against 60.8%). At TP=3 every 0.5 launch beat both no-flag launches in every greedy row and in
    the four-stream sampled chat row; at TP=2 every 0.5 launch beat every no-flag launch in decode, greedy chat at one
    and four streams, the distinct prompts and the four-stream sampled rows, and lost to every one in four greedy code
    streams. No launch waited on the heat guard.
  • Prompt speed before and after: n/a, the flag acts on MTP draft rounds alone; a prompt runs main's path.
  • Kernel contract (CUDA): zig/tests/cuda/contract_glm_top1.zig runs tf_glm_top1_sums through gates 1-4 as two specs.
    Its pick (words 0 and 1) must equal tf_glm_top1's words on the same logits bit for bit, and the host's scan (the
    first logit above every earlier one from -inf, so a NaN never wins; none above -inf gives -inf and the slice's first
    row); it declares no sums. Its sum (word 2) is held to float64's sum of exp(a), a = x - max, within the fp32 bound
    plus __expf's error (CUDA's 2 + 1.173|a| ulp, taken as 2 + 1.2|a|). The served shapes are the TP=2, 3 and 4 slices
    of the 154,880-row vocabulary (77,440, 51,648, 51,584 and 38,720 rows), k tiled by 1,024. kernel-contract-limits on
    nvcc 13.0.88's fatbins for sm_80, 86, 89, 120 and 121: tf_glm_top1 stays current on every SM (29, 30, 30, 36 and 36
    registers), and tf_glm_top1_sums has its new records, 32, 31, 31, 39 and 39 registers, 8,192 static shared bytes,
    bound 1024. On the GB10, zig build kernel-contract with kernel contract: the CUDA runner maps fp8_experts' image, so a run reaches its summary #1579's mapping (without it the run stops at fp8_experts):
    SUMMARY 435 kernels: 435 pass gates 1-4, 0 fail, 6 known findings; 316 controls: 316 red as planted, 0 missed; 183 limit problems, in 5,076 s with the build. Both new specs pass every gate they run: the pick's nonfinite, repeat and
    shapes (8 shapes exact), and all four of the sum's (8 shapes within the float64 bound, the worst at 0.034 of it; exact
    sums at k 77,440, where fp16 would miss by 16,270,016x and bf16 by 39,625x). The live limits pass tf_glm_top1_sums
    (1024 threads, 39 registers, 8,192 + 0 shared bytes, as recorded) and tf_glm_top1 (36, 8,192). The 183 are the same
    lines as on main with kernel contract: the CUDA runner maps fp8_experts' image, so a run reaches its summary #1579's mapping alone, none of them touched here. tools/zig/cuda_sass_identity.py against
    main: none of glm_glue's 235 functions changed and five were added (tf_glm_top1_sums on each SM), so
    tf_glm_top1's SASS is main's on every SM.
  • Tests run (Linux x86_64): zig build test 436/439 steps and test-cuda-host 268/270 (in both the one failure
    Qwen3.5's timing-dependent cuda_cost_identity, which fails the same way on main; a run before the third commit
    passed both whole), compile-cuda-tests 10/10, compile-config-server 7/7, zig fmt --check, and
    tools/zig/lean_check.py with nothing new (425 against main's 425). New host tests: the ranks' pick and its softmax
    (cuda_mtp_chance.zig), GLM's refusals of --mtp-drafts and of the flag beside --drafter, GLM's facts with a floor
    through lanes.Config.init, and a sampled stream's depth under a floor (depth.zig, which fails on main with 3 for
    1). New GPU tests: the kernel contract's two specs for tf_glm_top1_sums (built by compile-cuda-tests, run on the
    GB10 above).
  • Not run, and why: Metal and HIP (CUDA's GLM engine and kernel only); Nemotron with the flag (the lane core change
    reaches its sampled streams; no Nemotron checkpoint here); floors other than 0.5 at TP=2.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (The flag
    only shortens drafted windows inside the lane rounds.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
    (--alone --serial in every cell of every launch at both TPs; the prompt cache was off, and resuming is untouched.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No sum
    changes: the chance only decides which drafted rows are verified.)
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's
    SUMMARY line is in the receipt. (tf_glm_top1_sums has nvcc 13.0 records and gate 1-4 specs in
    contract_glm_top1.zig; the GB10 run's SUMMARY, both specs passing and the live check are in the receipt;
    tf_glm_top1's SASS is unchanged; CUDA is the only backend it touches.)
  • Prompt processing is no slower than the last release. (A prompt runs main's path.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (CUDA on GB10 at
    TP=3 and TP=2, the host tests on Linux; the rest not run, as above.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (Each host test needs
    no device; the depth test fails on main, the refusal and facts tests fail without GLM's option; the contract specs run
    on a GPU and name a kernel main does not have.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@Bizuayeu
Bizuayeu marked this pull request as ready for review October 29, 2026 09:22
Bizuayeu and others added 5 commits October 30, 2026 04:31
…as Nemotron's does

GLM's MTP head gave the lanes no chances, so every drafted row went to verify; a row costs about 5.6 ms at TP=3
and many deep drafts miss. With --mtp-confidence, every rank picks an MTP draft with tf_glm_top1_sums, which adds its
slice's softmax sum to the 16-byte word the greedy gather already moves; rank 0 turns the ranks' sums into the pick's
probability, and the lanes chain them and stop a chain where its chance falls under the floor (the lane core's
draft_confidence, as for Nemotron). Sampled and structured drafts keep chance 1. Without the flag every path is main's.
…ernel

The MTP draft's pick under --mtp-confidence: tf_glm_top1's scan and its slice's softmax sum. nvcc 13.0 usage measured on the five targets; later compilers pending, as for tf_glm_top1.
A confidence floor made every stream draft the most and left the cut to the head's chances. A sampled stream's drafts carry no head chance (GLM gives them 1), so it verified the deepest window each round: at TP=3 a sampled chat reply drafted 3 a round where its rates chose fewer, and lost 1.7 to 2.0% at one stream. headDepth and depth now keep the rates' depth for a sampled stream under a floor; greedy streams draft the most as before.
@ashhart
ashhart merged commit f350cd3 into ashhart:main Oct 30, 2026
8 of 9 checks passed
@Bizuayeu

Copy link
Copy Markdown
Contributor Author

Thank you for landing it! I'll keep measuring the floor on real requests and report back if a different default looks better.

ashhart added a commit that referenced this pull request Oct 30, 2026
…t_tests.zig under 600 lines)

#1585's two contract lines took contract_tests.zig to 602 lines once #1562
had landed beside it, and CI's lean check stops at 600. The seven gradient
suite calls and their PASS line move to contract_back_suites.zig, called from
the same place in the same order.
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thank you @Bizuayeu. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0

It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog.

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