Skip to content

glm/cuda: TF_GLM_KDA_PAD tells unset from 0 across the ranks; unset stays off (for #3516) - #3519

Closed
ultradaoto wants to merge 3 commits into
ashhart:mainfrom
ultradaoto:glm-kda-pad-default
Closed

ultradaoto wants to merge 3 commits into
ashhart:mainfrom
ultradaoto:glm-kda-pad-default

Conversation

@ultradaoto

@ultradaoto ultradaoto commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

For #3516. After review, an unset TF_GLM_KDA_PAD stays off; this lands everything else and leaves the default to the maintainers' ruling there.

  • Settings.kda_pad is now ?bool, so unset is distinct from 0. The rank fingerprint carries 0 for unset, 1 for on and 2 for off, so ranks still have to agree.
  • The new kdaPadded(settings, uneven) decides. One constant, pad_uneven_unset, holds what unset means where some rank's KDA head count, and so its row width (384 a head plus 256), is not a multiple of 8 (worlds 3, 5, 6 and 7 on GLM-5.3-Flash's 64 heads). It is false, so unset is unpadded on every world. TF_GLM_KDA_PAD=1 and =0 force it either way, as on main.
  • So with the variable unset or 0, pad_to is 0 on every world and every byte is main's; with 1 the stack is main's TF_GLM_KDA_PAD=1.
  • The existing settings test checks the tri-state. A new test walks worlds 1, 2, 3, 4, 5 and 8 against the shard's per-rank head counts: uneven is worlds 3 and 5 of those, unset is unpadded on all six, and 1 and 0 are as set.
  • CHANGELOG, under Unreleased.

zig build test-cuda-host with the pushed Zig files: 4,261 of the 4,274 tests it ran pass and 12 skip (steps unchanged since the first push reused their cached passes). The one failure, cli_config_test's serve --config: expand reads the file ..., fails the same way on main on this host. zig fmt --check is clean on the family's folder; pr_check: 0 errors, 0 new lean findings.

The receipts below were measured on the first push, where unset padded at world 3. On this head that path is TF_GLM_KDA_PAD=1 (the code under the switch is unchanged) and unset is main's path; I have not run them again on this head. Main (cf45553) against the first push (the same diff on cf45553) on three GB10s, --parallel 4 --kv-cache fp8, greedy, thinking off, two starts each, tools/bench_openai.py --tokens 256 --reps 3 and tools/bench_concurrent.py --tokens 256 --reps 3 --levels 1,4 --alone --serial, plus cold first-token times. One number per start:

build first token, 7.2K / 28.8K (s) bench_openai decode, code / chat (tok/s) bench_concurrent code, 1 / 4 streams chat, 4 streams
main, bf16 5.04, 5.05 / 19.33, 19.29 44.2, 45.9 / 35.0, 35.0 45.1, 45.8 / 94.8, 91.4 73.6, 72.7
padded, bf16 4.63, 4.64 / 17.53, 17.57 44.8, 43.7 / 35.0, 35.9 44.3, 44.8 / 91.4, 93.4 74.8, 75.9
padded, TF_GLM_DENSE_BITS=8 TF_GLM_HEAD_BITS=8 4.67 / 17.66 56.0 / 46.9 59.0 / 109.5 91.2

At bf16 the padded stack also tiles in prompt passes, so cold prompts' first tokens come 8–9% sooner; bf16 decode is level within the noise of these tools (bench16 measured +2.1%). With dense bits the padded stack logs glm: 290 linears packed (8/8 bits) (unpadded: 188). Padded replies differ from unpadded ones (0 of 36 hashes equal; each run repeats its own), because the stack's kernel changes and with dense bits so does its precision; see #3516 for quality.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @ultradaoto, this is a clean piece of work. The tri-state setting, the fingerprint carrying unset apart from on and off, and the world walk in the test are all as they should be, and at worlds 1, 2, 4 and 8 every byte stays as before. The measurements read well too: bf16 first tokens 8 to 9 percent sooner with decode level, and the dense bits arm faster again.

One thing holds it, and it is the default. With the setting unset, worlds 3, 5, 6 and 7 change their replies, and our rule is that a change keeps every token unless the maintainers rule otherwise, and #3516's quality case is waiting on exactly that ruling, so please keep unset meaning off for now, with TF_GLM_KDA_PAD=1 as the opt in, until that ruling is made. Everything else can land as it is.

Please also post CI green for the head. We will run the device check on our side once the default is off: GLM-5.3-Flash on GB10s at world 4 unset (every hash equal main's) and at world 3 with the setting on.

  • Synthena

…hart#3516

Review asked that unset keep serving unpadded until the maintainers rule on the reply change at worlds 3, 5, 6 and 7.
One constant holds what unset means there, and it is off; the tri-state setting and its fingerprint are unchanged.
@ultradaoto ultradaoto changed the title glm/cuda: pad the KDA input stack by default where a rank's row is not 8-aligned glm/cuda: TF_GLM_KDA_PAD tells unset from 0 across the ranks; unset stays off (for #3516) Nov 16, 2026
@ultradaoto

Copy link
Copy Markdown
Contributor Author

Thanks. Done in 9d63fcd: an unset TF_GLM_KDA_PAD stays off on every world, and TF_GLM_KDA_PAD=1 is the opt-in.

  • One constant in cuda_ranks.zig, pad_uneven_unset, holds what unset means on worlds 3, 5, 6 and 7, and it is false; kdaPadded reads it, so the ruling on glm/cuda: at TP=3 the KDA input stack never tiles or packs (8,726/8,341-column rows); TF_GLM_KDA_PAD is off by default #3516 is that one word either way.
  • The tri-state setting, the fingerprint (0 unset, 1 on, 2 off) and the engine's world walk are as reviewed.
  • The world-walk test now expects unset to be unpadded on all six worlds, and checks that the uneven ones are 3 and 5.
  • The CHANGELOG line and the PR's title and description say the same; the description's receipts are marked as measured on the first push, where unset padded (on this head that path is TF_GLM_KDA_PAD=1).

On CI: the runs for this branch stop at action_required (No GPU and Zig format, for each head I have pushed), as they did on #3495 before you approved them there; a fork's first runs wait for a maintainer and I cannot start them. Locally, with the pushed Zig files: zig fmt --check clean, pr_check 0 errors and 0 new lean findings, and zig build test-cuda-host with the one failure main has on this host (cli_config_test's serve --config: expand ...). I will post the links once the runs for 9d63fcd have gone through.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @ultradaoto for turning this round so quickly. 9d63fcd does what we asked: unset is unpadded on every world, and the world walk in cuda_ranks_test.zig checks that the uneven worlds are 3 and 5.

Looking again at what is left at this head, we are going to close the PR. I'm sorry this goes back on our earlier "everything else can land" note. Here is the reasoning:

  1. glm/cuda: at TP=3 the KDA input stack never tiles or packs (8,726/8,341-column rows); TF_GLM_KDA_PAD is off by default #3516's question is now settled. We don't take modes that change replies, not even as an opt-in, and padding changes them: by your own count, 0 of 36 hashes were equal at world 3. So an unset TF_GLM_KDA_PAD can never mean padded. That makes pad_uneven_unset (cuda_ranks.zig:198) a constant that is always false. The uneven loop it gates in cuda_engine.zig:154-155 then runs at every load but never changes pad_to.
  2. With unset and 0 now the same stack, carrying them apart in the fingerprint (0 against 2, cuda_ranks.zig:307) adds only a new refusal. One rank unset and another at TF_GLM_KDA_PAD=0 load identical weights and would agree on main, but here they refuse each other.

The measurements are still useful. If the padded stack can be made to give the unpadded stack's exact bytes (same sum order and the same precision in the tiled path, so every reply hash equals main's), the 8–9% first-token gain would be welcome as a new PR. It would also need no switch at all.

  • Synthena

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