Skip to content

glm dsa: wait for the pair peer on the host, between command buffers - #3380

Draft
jcscocca wants to merge 5 commits into
ashhart:mainfrom
jcscocca:codex/glm-dsa-shared-event
Draft

jcscocca wants to merge 5 commits into
ashhart:mainfrom
jcscocca:codex/glm-dsa-shared-event

Conversation

@jcscocca

Copy link
Copy Markdown

What this changes

Full GLM-5.3 (EXLR8, --speed-up) never serves on two M5 Ultra Mac Studios: rank 0 hangs while loading and rank 1 then needs kill -9. The cause is the one confirmed in #3158: pair_post_wait in core/pair.metal waits for the peer inside a running command buffer by polling memory the host writes. This change removes that GPU-side wait. Each exchange now retires its producer command buffer, waits for the peer on the host, and encodes the consumer into a new command buffer only after the host has published the exact 64-bit receive epoch. A silent or dead peer ends in a controlled PairLinkFailed on both ranks.

Why not shared events inside one command buffer, as in #3293

The first build of this change did that, and it passed one start. On the second start a command buffer accumulated enough handoffs to sit in an event wait for about 5 s and the GPU watchdog killed it (kIOGPUCommandBufferCallbackErrorTimeout). The build in this pull request has no GPU peer waiter at all, so there is nothing for the watchdog to kill.

Shared code

core/pair.metal and core/pair.zig are used in production only by the full GLM-5.3 engine and model, and both callers are converted together. core/pair_rows.* and the existing metal pair contracts are unchanged.

Checks on this head

  • Head commit 786950bc62be9e9fd32c51fb700c0c56a1d55034.
  • Lean checker python3 tools/zig/lean_check.py with the head's checker: 341 findings on the base cf2c65bd3, 341 on this head. tools/zig/lean_new.py reports 0 new.
  • Tests run on an M4 Pro (macOS 26.7.1), Zig 0.17.0:
    • zig build test-glm-dsa-pair -Dcpu=apple_m1 -j4 --summary all: 43/43 steps, 73/73 tests passed, 0 skipped.
    • zig build test test-golden -Dcpu=apple_m1 -j4 --summary all: 851/853 steps; 13,791 of 13,902 tests passed, 109 skipped, 2 failed. The same command on the base: 13,771 of 13,882 passed, 109 skipped, the same 2 failed (core.paced_read.test.aligned spans copy the bytes asked for, at any offset and length and families.glm.weights_fix_test.test.GLM copies and transforms join before shard eviction; errors and duplicate opens retain ownership). Both failures are inherited. This head adds 20 passing tests.
    • zig fmt --check build.zig zig and git diff --check pass.
    • python3 tools/pr_check.py --base cf2c65bd3: 25 changed files, lean 341 vs 341, 0 new; 0 errors, 1 advisory warning (the Unreleased line, which needs this pull request's number).
    • Kernel contract: see the section below.
  • CI Not started. Fork workflows need maintainer approval.
  • Not run, and why
    • The full Metal kernel contract (zig build kernel-contract -Dcpu=apple_m1) exits 1 on this M4 Pro with UnrecordedRotaryCompiler before reaching any kernel, on the base as well as on this head. The filtered device runs below cover every changed kernel and the other metal pair kernels.
    • Pristine main was not run on the Studios. The "before" run used the glm metal: use shared events for paired transfers #3293 head build; core/pair.metal, core/pair.zig, families/glm_dsa and native/glm_dsa_host.zig are identical between that commit and main at 2ba55ec7d.
    • CUDA, HIP and XPU: outside this change.
    • M1 to M4 pairs: not run. I have one M4 Pro and two M5 Ultras.

Receipt

  • Main against branch Same two Studios, checkpoint and flags (--context 8192 --parallel 4).
    • Before (build of cf2c65bd3): rank 1 loaded in 396 s (159.6 GB) and reported serving. Rank 0 never finished loading; after 20 minutes its main thread was in families.glm_dsa.engine.Engine.chunk > Engine.finish > -[_MTLCommandBuffer waitUntilCompleted]. After rank 0 was stopped, rank 1 did not exit on SIGTERM within 30 s and needed kill -9.
    • After (this head): API ready after 519 to 531 s on seven separate starts of the same binary (SHA-256 0470bd50ca3ad67d88bf04076a5e7c0362a4afcb4b8dbbae20b2cdd0fdf4b4eb), every start stopped both ranks on SIGTERM with no kill -9 and no GPU watchdog message.
  • Boxes it reaches Native Metal full GLM-5.3 over a two-rank Thunderbolt 5 MCDMA link. One-Mac serving of this family does not exist. Other families do not use core/pair.*.
  • New switch? None. The host wait is the default and only behaviour in pair mode.
  • Environment TensorFold 786950bc6 on cf2c65bd3; Zig 0.17.0; two Mac Studio M5 Ultra, 256 GB, macOS 27.2, rdma_en3 over Thunderbolt 5; checkpoint kindlingai/glm-5.3-exlr8-k2-k3-k4@f459f5d0272a529403dd9b3fd32f771f4250a0d4; greedy, integrated drafts.
  • Paths and platforms Ran: M5 Ultra pair (serving, exactness, failure paths) and M4 Pro (host tests, filtered kernel contract). Could not run: M1 to M4 pairs, other backends.
  • Exactness tools/bench_concurrent.py http://127.0.0.1:18792 glm-5.3 --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serial: 0 failed. One stream: 3/3 replies equal to the request alone, and equal to "draft": false. Four streams: 12/12 equal to the request alone, and equal to "draft": false. The same holds with thinking off. Separately, two prompts sent with drafts on and off, two repeats each, returned identical 128-token visible replies and token hashes, and both ranks logged equal pick counts and pick hashes on every run (for example 17,273 picks, hash 08dd0396…d56a, on the 75-request run).
  • Main against this branch, same machine and checkpoint See the first line: main's path does not serve on these machines, so there is no decode number to compare with.
  • Decode speed tools/bench_openai.py … --tokens 256 --reps 3 --temperatures 0, median of three, one stream: 8.92 tok/s (fibonacci-raw), 7.85 tok/s (gpu-chat-no-think). bench_concurrent.py at four streams: 33.9 tok/s aggregate, 8.7 per stream; 30.4 aggregate with thinking off. Round gap p50 is 314 to 324 ms at about 2.5 to 2.7 tokens per round. This is below the 21 and 31 to 32 tok/s in docs/glm-5.3-exlr8.md. I do not know how much of the gap is this change (each exchange now pays a command-buffer boundary) and how much is these machines; there is no working baseline here to separate them. Server-reported decode on other prompts ranged from 6 to 31 tok/s and was episodic within a run, with no established cause.
  • Prompt speed tools/bench_cache.py … --require-cold, 2,570 prompt tokens, zero cached tokens reported: ttft_s 13.21, 13.12 and 12.99 across the first and two repeated requests. No before number, for the same reason.
  • Failure paths, on the Studios SIGTERM to rank 1 during a streamed request: rank 0 logged PeerDown and returned PairLinkFailed in 0.55 s, then stopped normally. SIGSTOP to rank 0 while rank 1 was idle: rank 1's follower returned PairLinkFailed 2 s later. A 75-request run including 60 consecutive mixed requests completed with no error.
  • Licence of any new weights or drafter n/a.
Kernel contract
  • Kernels pair_stage is new. pair_add_rms, pair_argmax and pair_pick replace their same-named versions, which called the polling pair_post_wait; that function is removed. Each consumer now takes the host-published 64-bit epoch and refuses a slot whose epoch does not match.
  • Controls One planted control per kernel under metal glm dsa pair; each fails as planted.
  • Commands zig build tf-kernel-contract -Dcpu=apple_m1, then tf-kernel-contract --only 'metal glm dsa pair' and tf-kernel-contract --only 'metal pair'.
  • Apple M4 Pro (applegpu_g16), exit 0 each
SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 0 limit problems; gates 604 ms, limits 66 ms
SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 62 ms, limits 113 ms
  • Apple M5 Ultra, both Studios, --only 'metal glm dsa pair', exit 0 each
SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 0 limit problems

Not done

  • No explanation for the decode speed gap against the guide, or for the episodic slow requests.
  • Six small allocations per rank (about 59 KB) are reported leaked at exit. They come from GLM DSA cleanup paths this change does not touch; I confirmed that by reading the source, not by running the base, which cannot reach a clean exit here.
  • Raw benchmark JSON (decode.json, concurrent.json, cache.json) and the run logs are available on request; they are not attached yet.

@jcscocca

Copy link
Copy Markdown
Author

A correction to the exactness line in the description, and a separate finding from the same runs.

The exactness results above were all measured on short prompts, up to about 2,600 prompt tokens. On longer prompts the pair's replies are not exact. I do not think this change is the cause, for the reason in the second point.

Setup: fresh server each time, --context 32768 --parallel 1 --prompt-cache-gib 0, greedy, thinking off, 300-token replies. The same request is sent three times in a row: drafted, drafted again, then "draft": false. Every reply reports zero cached tokens.

Prompt tokens Send 1 (drafted) Send 2 (drafted) Send 3 ("draft": false) Text
2,067 4468c94a 4468c94a 4468c94a sensible
3,049 a409f02f 33e4b590 a30ddbba sensible, three different replies
4,039 7c141aec 089d205b b8b8122e sensible, three different replies
6,011 bf379c21 468835d9 bab101cc degenerate
7,975 74aece2b 1471bfc3 91ecfb68 degenerate

Cells are the first eight hex digits of the SHA-256 of the visible reply. "Degenerate" means text such as The urgent care, the care, the shared register. The register the follows the register, …. A 19,825-token prompt gives digit strings.

  1. At 2,067 prompt tokens the three sends are identical. From 3,049 tokens the same greedy request gives a different reply on each send, and from about 6,000 tokens the replies are no longer usable.
  2. The three replies at 3,049 tokens are the same three on three separate starts, and on both builds of this change: this head, which waits on the host between command buffers, and the earlier build mentioned in the description, which kept the wait on the GPU with shared events. The 2,067-token reply is also the same on both. So the reply depends on what the server processed before the request, not on timing and not on which handoff is used.
  3. Both ranks log equal pick counts and pick hashes in every one of these runs.

This looks like the family's long-context path, which docs/glm-5.3-exlr8.md says was not checked against a whole-model reference past 2,048 tokens. I cannot run main on these machines, so I cannot show it on an unmodified build. I can open a separate issue with the request bodies and replies if that is useful.

One more observation from the same comparison: on the earlier GPU-wait build the repeated sends took 194 s and 126 s where the first took 46 s; on this head all sends took 38 to 57 s.

@jcscocca

Copy link
Copy Markdown
Author

Two more data points on the long-prompt behaviour above, in case they help narrow it.

  1. Same setup, 3,049 prompt tokens, but with the "draft": false send first on a fresh server: the plain reply is 98f6ebdb, and the two drafted sends after it are dab98d8b and 286c2eb1. With a drafted send first, as in the table above, the replies were a409f02f, 33e4b590 and then a30ddbba for the plain one. So at this length the reply depends on the draft mode even for the first request after a start, as well as on the requests before it. The drafted-first sequence reproduced on three starts; the plain-first sequence was run once.

  2. Possibly related: exo fixed wrong output past 2,048 tokens for this architecture on 1 November (pull request 2512 in exo-explore/exo). Its write-up says only 21 of the 78 layers carry an indexer and the other 57 reuse the previous indexer layer's top-2,048 selection, and that its two-machine pipeline split also had to pass that selection between ranks. families/glm_dsa/config.zig here does implement the shared layers, so this is not the same mistake, but the threshold is the same.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@jcscocca, the host wait removes the GPU polling path, but the reported different replies from identical 3,049-token requests and the degenerate 6,011-token results block landing. Whether the cause predates this change is still unresolved.

Please attach the exact request bodies, complete output token IDs, fresh-start and repeated-request logs, and the raw benchmark files you offered. We also need the request-order dependence resolved and evidence separating the decode-time and exit-leak causes. A matched working baseline would help where one can run; the guide's figures alone do not establish a regression caused by this PR.

We will handle the prerequisite sequencing, main rebase and changelog. The admitted path must return exact repeated, drafted/plain and concurrent/solo output before it can leave draft.

  • Synthena

@jcscocca

jcscocca commented Nov 17, 2026 •

Copy link
Copy Markdown
Author

@ashhart, thanks. The two blocking findings come from the DSA index scan on main, not from this change, and a one-line correction removes them on the pair. The files are in the attached bundle (tf3380-evidence.tar.gz; file list and SHA-256 inside).

Cause

indexScoresBlock (zig/src/families/glm_dsa/kernels.zig:216) dispatches last_pos / 512 + 1 threadgroups, but one threadgroup of glm_index_scores_block covers 256 keys (128 threads, BLOCK 2). Past 2,048 positions only the keys below 256 * (last_pos / 512 + 1) are scored, about half of the visible ones. glm_index_topk then reads the rest from a score buffer that is never cleared: zeros after a start, later whatever an earlier window in a higher range left there. The line is from aa6fbd8 (24 October) and is unchanged on main at 25de9d7. This pull request does not touch index.metal, kernels.zig, layer.zig or the score buffers in gpu.zig; in model.zig it changes only how the encoder is passed through the layer loop.

  • Kernel check on main, no checkpoint needed. On an M4 Pro, tf-glm-dsa-index-check built from 25de9d7 passes as it is, because the row scan and the blocked scan write one buffer and the half the blocked scan skips still holds the row scan's scores. With that buffer filled with a marker between the scans, the blocked scan leaves 4,090 of 9,210 visible scores unwritten at 2,304 keys, 8,186 of 16,378 at 4,096 and 16,378 of 32,762 at 8,192, starting at key 256 * (last_pos / 512 + 1) each time. With last_pos / 256 + 1, none is unwritten, and scores and top-k lists equal the row scan's bit for bit from 2,304 to 32,768 keys (index-scan/).
  • Request-order dependence. The scored range follows the highest position in a window, in steps of 512. A decode that stays inside one 512-position range reads the same unscored columns every time; one that crosses a boundary changes its scored range with the rows in each window and leaves scores behind for the next request. Every measured case fits:
Prompt + reply tokens Decode positions Crosses a multiple of 512 Saved replies
2,067 + 259 2,067 to 2,325 no repeats and drafted/plain equal
2,570 + 64 2,570 to 2,633 no three drafted sends equal
3,049 + 287 3,049 to 3,335 3,072 three sends differ
4,039 + 265 4,039 to 4,303 4,096 three sends differ
6,011 + 300 6,011 to 6,310 6,144 three sends differ
7,975 + 300 7,975 to 8,274 8,192 three sends differ
11,919 + 300 11,919 to 12,218 no drafted and plain equal (both degenerate)
19,825 + 300 19,825 to 20,124 19,968 drafted and plain differ
  • Not this change's handoff. The 2,067-token reply and all three 3,049-token replies have the same token hashes on this head and on the earlier build with GPU shared-event waits, on separate starts. On a fourth fresh start of this head (16 November, with token IDs) the 3,049-token sends again give 57f115a5, d0c5b282, 86e9a29a; the 6,011-token sends are degenerate again, with different hashes, since the requests before them differed.

The correction on the pair

The same two Studios, this head plus only the dispatch change (index-scan/index-dispatch-fix.patch), --context 12288 --parallel 4 --prompt-cache-gib 0, greedy, thinking off, 300-token limit, every request with return_token_ids. At each length: drafted, drafted again, "draft": false, then four drafted copies at once.

Prompt tokens Replies Equal token IDs Reply
2,067 7 7 254 tokens, ends by itself
3,049 7 7 269 tokens, ends by itself
6,011 7 7 257 tokens, ends by itself
7,975 7 7 250 tokens, ends by itself

All 28 are readable summaries of the record; both ranks logged 22,544 picks with the same pick hash. The 2,067-token reply changes (534ef718, was ecb217f2), as expected, since keys from 1,280 up were not scored before. Bodies as sent, replies and both ranks' logs: runs/2026-11-16-index-fix/.

The change belongs on main, not in this pull request, so I have it as its own commit there: the dispatch line, and the index check marking the buffer between the two scans so that it fails on a skipped key (8,186 unwritten before the fix, 0 after; tools/pr_check.py 0 errors, lean 221 vs 221). I can open it as a pull request if that suits your sequencing.

Matched baseline

Unmodified main does not serve on these Macs (#3158), and one Mac cannot serve this checkpoint. The closest match I can run is this head with and without the one-line correction, same Macs, checkpoint and requests, which isolates the scan; the GPU-wait build is the second handoff with equal replies.

Exit leak and decode time

They are separate, and neither comes from this change.

  • Leak. Every start of both builds reports the same six allocations on a rank, whatever it served (0 to 75 requests, 430 to 92,046 picks; the three path strings are two bytes longer on rank 1): 3,732 bytes, the config.json text (engine.zig:79); 54,912, m.layers (78 layers of 704 bytes, model.zig:51); 72 a stream, e.slots (engine.zig:86); and three path strings (engine.zig:79, model.zig:52, model.zig:83). None is freed in Engine.deinit or Model.deinit; all six lines are from 7327f9d. Per-start table: analysis/exit-leaks.tsv.
  • Decode. I timed every exchange on both ranks in a diagnostic build (this head + the index fix + per-phase timing, runs/2026-11-16-timing-before/). A plain one-row round takes 137.5 ms for 157 exchanges: per exchange on average 641 us of GPU execution, 116 us from commit to GPU start, 76 us from GPU end to the host seeing it, 48 us waiting for the peer and 31 us for the relay's send. So about 100 ms of a round is GPU work and about 30 ms is the command-buffer boundaries this change introduced; the link costs little. Wired memory stays at 155 to 157 GiB on both Macs throughout. The guide's 45 ms of GPU time for a one-row round is less than half of what these Macs spend; their M5 Ultra has 64 GPU cores against the guide's 80, which covers at most a factor of 1.25.
  • Load-time calibration. Backend.time() runs before residency.hold (glm_dsa_host.zig), so rank 0 times its windows while the model is not yet resident: 1.8 to 2.4 s a window, against 77 ms once it is. Holding first takes about 130 s off each load and gives the lane planner real costs; with that and a few host-side spins instead of 20 us sleeps, the same requests give identical token IDs (16 of 16 replies, 4,064 tokens) and run at 134 ms a plain round (was 137.5) and 10.2 to 13.8 tok/s drafted (was 6.5 to 11.1), runs/2026-11-16-timing-after/. Those are separate commits I can offer after this lands or fold in, as you prefer.

What you asked for

  • Request bodies: exactly as sent in runs/2026-11-16-*/**/*.body.json. For the 14 November ladders, requests/ holds bodies rebuilt by the same client code from the saved source request; the prompt token counts match.
  • Output token IDs: every reply in runs/2026-11-16-* (tensorfold.token_ids). The 14 November replies carry token_sha256 and text only.
  • Fresh-start and repeated-request logs: both ranks' complete logs for ten starts (runs/*/rank0.log and rank1.log, and benchmarks/).
  • Raw benchmark files: benchmarks/decode.json, concurrent.json, cache.json.

Still open

  • With the correction, repeated, drafted/plain and concurrent/solo are exact on these runs up to 7,975 tokens; nothing past 8,192 has been rerun.
  • The GPU time per round against the guide is not explained beyond the core count.

tf3380-evidence.tar.gz

@jcscocca

Copy link
Copy Markdown
Author

Neither of the two original Zig CI failures reproduced locally. The unranked-manifest and sampled early-stop tests passed in both local Ubuntu x86-64 server-suite runs and in the full ARM64 test-host run. All runs used CI merge commit 48c8d3d and Zig 0.17.0.

The second x86-64 run had a separate Ctrl-C startup failure, and the ARM64 host run reported other failures. The cause of the original two failures remains unknown. Failed Zig job

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @jcscocca. The scan diagnosis and reported 28 matching replies with the separate correction address the request-order finding, and the evidence bundle is linked. That correction is still absent from current main and this head, so we need the integrated-source exactness gate, including the unrerun range above 8192. The timing breakdown also identifies command-buffer overhead; it does not yet clear the remaining performance gap. We will handle prerequisite sequencing and main integration, then check the bundle against that source.

  • Synthena

This branch has not been deployed

No deployments
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