Skip to content

glm metal: use shared events for paired transfers - #3293

Open
jcscocca wants to merge 7 commits into
ashhart:mainfrom
jcscocca:codex/glm-shared-event-3158
Open

jcscocca wants to merge 7 commits into
ashhart:mainfrom
jcscocca:codex/glm-shared-event-3158

Conversation

@jcscocca

@jcscocca jcscocca commented Nov 14, 2026 •

Copy link
Copy Markdown

What this changes

Paired GLM-5.3-Flash can stall during startup when its Metal kernels poll a peer flag while the host writes it. Use Metal shared events for both directions of the handoff. Publish an arrival only after the peer transfer flushes. Bound each send with a short host deadline and the peer's arrival with a longer one, and use 64-bit epoch guards to release waiters safely when the link fails.

Tested merge resolution for #2128

The trial merge used #2128 at a2b0943d97f15647210239ca0dc55654968420a5 projected onto main at 948e7485840834e5c78f2db1ce4d44322cf72e44. Keep the *Pass signatures and const e = pass.enc in prompt.zig for moe and mla. Restore #2128's x.k.ordered early returns, calling ordered_prompt.moe with pass and ordered_prompt.mla with e. In ordered_prompt.zig, accept *Pass in moe and forward it to fwd.moe. Ordered dispatch remains limited to the unpaired path.

zig build native test-glm-ordered-host tf-kernel-contract -Dcpu=apple_m1 -j2 passed 73/73 build steps and 10/10 ordered GLM host tests on the composed tree. The trial merge is separate from this draft. The same patch applied to the projection of #2128 onto main as of bafe3e07c. The resolved tree 8e7d9c9e1b5e9fb9a3cdbde1b30b4722048a119e passed all 10 ordered GLM host tests. An apply check also succeeded against the projection onto 90b4fae6. After applying the replay patch, apply the follow-up test diff from git diff --binary 5ec85fd74 27ddaf316 -- zig/tests/contract. The combined apply check on 90b4fae6 produced tree b54b59f876b5918dba265220f68eff8540b28461. Apply the resolution when rebasing the second PR after the first lands.

To reproduce on a clean disposable worktree containing those refs, project #2128 with git merge-tree --write-tree bafe3e07c a2b0943d, load that tree with git read-tree -mu <projected-tree>, and apply the replay with git apply --index merge-2128.patch. Download the tested replay patch.

Checks on this head

  • Head commit 2181902265d563b889fdb650da709cfdeab8fd28.
  • Native build zig build native -Dcpu=apple_m1 passed 66/66 steps with Zig 0.17.0 and Xcode 27.2 on an M4 Pro.
  • Local checks Formatting, golden tests, serving and security checks, fuzzing, and both release-path checks passed. Kernel contract host tests passed 247/247, test-metal-residency-owners-host passed 76/76, and the server build passed 297/297 steps. The lean checker found 221 findings on both base and head, with zero new findings.
  • MCDMA All 19 focused transport unit tests passed.
  • CI No GPU and Zig format completed successfully at this head. Nine jobs passed and two nightly host jobs were skipped.

Earlier checks

  • Relay deadline check at cf2c65bd3e562b9cfd621f56b8af6c45a71bfc3f That follow-up split the relay's deadline in zig/src/families/glm/ep.zig. One native send and its flush keep the 1 s budget and fail with EpTransferTimeout. The wait for the peer to reach the same exchange and send it now has its own 10 s limit, the same as main's exchange wait, and fails with PeerSilent. Before this, the 1 s budget started at this rank's GPU post, so a peer running more than 1 s behind ended the pair. A GLM_EP_DELAY_US hold now runs before the send budget starts. A healthy exchange now also re-arms the deadline once after its flush. The fault, late-peer and restart checks were rerun on the Studios at this head. The decode, prefill and exactness tables were measured before this change.

  • Checks at cf2c65bd3 zig build native test-glm-expiry test-glm-scheduling-host tf-kernel-contract -Dcpu=apple_m1 -j4 --summary all passed 75/75 build steps and 85/85 tests on the M4 Pro. tf-kernel-contract --only 'metal glm ep' exited 0 with 8/8 kernels passing, 8/8 controls caught and zero limit problems. zig fmt --check build.zig zig and git diff --check passed. The No GPU workflow's Zig steps also ran on the M4 Pro with -Dfixed-cpu: test-kernel-contract (205/205 tests), test-golden, test-gradient-serving test-qwen-serving-host, test-server-security test-pull-security (27/27 security checks) and fuzz-cortheon passed. test-host registers only on a Linux host, so all 48 test-glm-* and check-glm-* steps it collects ran instead with --test-timeout 20m: 185/185 build steps and 374/376 tests passed, with two GLM OCR tests skipped. The focused MCDMA tests were not rerun at this head. The Studio reruns are under Receipt.

  • Previous head 27ddaf3161c07c4197c789aa92425b01496b4dfe removed 41 net lines from the Metal test scaffolding. The same eight kernel probes and eight planted controls use one production Metal library and one fault-injected library. It left the inference source and binary unchanged.

  • Inference checks at 5ec85fd74 The native build, focused GLM host targets, both golden suites, and Metal contract build passed in zig build native tf-kernel-contract test-glm-expiry test-glm-scheduling-host test-golden -Dcpu=apple_m1 -j4 --summary all (80/80 build steps, including cached results for the focused host tests). The golden suites reported 322/335 and 55/55 matches with zero unexpected differences. The rebuilt native binary had the same SHA-256 as the Studio benchmark binary. A fresh smoke attempt on the rebuilt binary stopped before any exchange when rank 1 reported MemoryShort (7.7 GB free or reclaimable against the 8.6 GB admission floor). Both test processes were cleaned up. On the rerun with memory available, the same draft-head binary served on rank 0 in 15.421 s. All three requests returned the expected replies (BANANA, 42, and blue), each rank landed all 1,502 exchanges, and both exited cleanly. The focused M4 contract rerun passed 8/8 kernels with all 8 controls caught and zero limit problems. zig fmt --check build.zig zig and git diff --check passed.

  • Lean checker python3 tools/zig/lean_check.py reported 341 inherited findings on bafe3e07c, 27ddaf316 and cf2c65bd3. tools/zig/lean_new.py reported zero new findings.

  • Developer tools at 27ddaf316 zig build tf-kernel-contract dev-tools -Dcpu=apple_m1 -j3 --summary all passed all 264 build steps. Zig formatting and diff checks passed.

  • Focused MCDMA tests at 5ec85fd74 19 passed, 0 failed, 0 skipped. These use fake endpoints for Thunderbolt and ConnectX, so they run without a native MCDMA library.

    zig test -lc --dep sys --dep verbs --dep bf16_round -Mroot=zig/src/fabric/mcdma.zig \
      --dep sys -Mverbs=zig/src/fabric/verbs.zig -Msys=zig/src/platform/sys.zig \
      -Mbf16_round=zig/src/core/bf16_round.zig
  • Original checks at 948e74858 with the contract additions zig build test-kernel-contract -Dcpu=apple_m1 passed 229/229 tests. The Metal launch map resolved all 736 registrations and both limit controls. The focused Metal device results are below.

  • Inference source checks before the contract-only additions zig build native -Dcpu=apple_m1 passed. zig build test-glm-expiry test-glm-scheduling-host -Dcpu=apple_m1 passed 85/85 tests, and the focused MCDMA unit run passed 19/19. zig build test-golden -Dcpu=apple_m1 had zero unexpected differences across both golden suites. zig build test -Dcpu=apple_m1 passed 4,949, skipped 57, and failed two local memory-floor tests (paced_read and GLM weights_fix). Both reproduced as MemoryShort on pristine main.

  • Metal missing-device check at 27ddaf316 A process-local dyld interposer forced MTLCreateSystemDefaultDevice to return NULL. The prior runner exited 1 with NoDevice. The fixed runner prints SKIP Metal kernel contract: no Metal device and exits 0 in both focused and limits-only modes, before opening a command queue. Both runs emitted no gate summary. With a real M4 Pro device the rebuilt runner passed 8/8 kernels, caught 8/8 controls and had zero limit problems. Filters for a copy kernel, a reduction kernel, controls only and no match retained their expected counts. Limits-only mode checked all eight launches.

  • Not run to completion The full Metal numerical suite was stopped after compiler calibration. The filtered device suite ran every changed handoff kernel. The local glm metal: one arithmetic order for prompt windows, chunks and decode on M1-M4 (#743) #2128 composition was built and host-tested. Its unpaired path still needs an on-device inference comparison if the changes land together.

Receipt

Paired GLM-5.3-Flash at 2181902265d5

I reran the native Metal pair on two M5 Ultra Macs over Thunderbolt. Both ranks loaded the stored MTP head.
The run used checkpoint TensorFold/GLM-5.3-Flash-MLX-4bit-MTP revision d2b17f5253440224422b150705c1109a9a3a0368, an 8,192-token context, temperature 0, and the prompt cache off.

The 18 requests each returned 96 tokens. All 15 comparisons matched the full token IDs and hashes. Solo drafted replies and all eight requests in the concurrent drafted batch matched the corresponding solo draft: false replies. Each prompt also matched on a second one-stream drafted request. The concurrency client repeated the Rust fixture at width 1. The drafted replies recorded accepted draft tokens. Both ranks stopped cleanly.

Prompt Matching token SHA-256
bash-line-count 02f595095c08715c2bb305745d276024696602fd9d153cfe7a200cd112431cc3
fishing-village 3618e910f0443528a8725ced0b3cb873b309708d0536175584c453f446d99f17
rust-reverse-words 96888a0500c5db5acc6560958b16f4c39f260651f13d2f8eb7cca2dafd7d2013

Unpaired GLM-5.3-Flash on one M5 Ultra

I ran each baseline and the PR on the same 256 GiB Mac Studio with macOS 27.2 build 26B118, the same pinned checkpoint, an 8,192-token context, one stream, temperature 0, seed 1234, draft: false, and the prompt cache off. The default memory limit left the MTP head on disk in these one-Mac runs. Each comparison used four fresh server starts in main–PR–PR–main order and two measured repeats per fixture per start.

All 16 matched samples against the rebase base and all 16 against the newer main snapshot returned identical token IDs. Decode is the median server rate over twelve 128-token replies per build across three prompts. Prefill is the median server time over four uncached 2,048-token requests per build.

Baseline Base decode (tok/s) PR decode (tok/s) Base prefill (s) PR prefill (s)
Rebase base af9777b4945a 77.70 77.65 1.2294 1.2292
Upstream main snapshot e5ea8a6065bc 77.56 77.68 1.2294 1.2278

Decode samples ranged from 77.55 to 77.79 tok/s on the rebase-base baseline and from 51.18 to 77.83 tok/s on the PR.
Decode samples ranged from 77.51 to 77.68 tok/s on the upstream-main baseline and from 51.90 to 77.78 tok/s on the PR.

Two PR replies decoded at about 51–52 tok/s on separate server starts. Dividing total decoded tokens after the first token by total server decode time gives 77.69 tok/s on the rebase base and 74.46 tok/s on the PR. Against the newer snapshot, the rates were 77.59 and 74.39 tok/s. The PR's pooled rate was about 4.1% lower in each set. The stalls' cause remains unconfirmed.

Prompt Matching token SHA-256
quicksort-raw 13cd8eed670c183b78958f975db115c38faad6e771582b0c97117d2c29333377
fishing-village f6aa01705f48237bec6696b3f03d6af95cfba35fafbc5ce096cb76a11573ff10
rust-reverse-words ee82b90142ff9c1b4b30b90ccaf3badea55044f6db877e331fb715a85e0d3fc8
raw-2048 5a9eddd69c0315ae7202dc5091c24d7dc9eb88cfdaed1157814989ebe360b33a

Longer unpaired run against the rebase base

I alternated the same two binaries across eight server starts with five repeats per fixture per start. I rotated fixture order and sampled host counters around each request. All 80 matched samples returned identical token IDs.

Across 60 128-token replies per build, median decode was 77.33 tok/s on the base and 77.31 tok/s on the PR. Pooled decode was 74.70 and 72.95 tok/s, respectively (-2.35% on the PR). With a slowdown defined as at least 20% more decode time than the base median for that fixture, there were 4 such replies on the base and 7 on the PR. For 20 uncached 2,048-token requests per build, median prefill was 1.2295 s on the base and 1.2294 s on the PR.

Median server CPU time rose from 0.08 to 0.93 s on slower base replies and from 0.08 to 0.90 s on slower PR replies.
Pageout and swap counters stayed flat around those replies.

Randomized one-stream decode rerun

I reused the same base and PR binaries and the same Studio. I randomly assigned first-run order within eight pairs of fresh server starts, with four pairs starting on each build. Each start ran three repeats of the three short decode prompts with the settings above and EOS ignored for a fixed 128-token reply. Every reply matched its reference IDs.

Median decode was 77.46 tok/s on the base and 77.40 tok/s on the PR. Pooled decode was 76.30 and 73.05 tok/s, respectively (-4.26% on the PR). Using the earlier base's per-fixture medians and the same 20% decode-time cutoff, 2 of 72 base replies and 8 of 72 PR replies were slow. Mean decode time was higher on the PR in all 8 pairs. The two-sided paired randomization test for mean decode time gave p = 0.029 across the 70 balanced start-order assignments. The analogous test on stall counts gave p = 0.086.

Separate diagnostic builds captured a 0.818 s wait on the base and a 0.842 s wait during PR warmup after a Metal command buffer had been committed and before it started on the GPU. The stall occurs on both builds.

Follow-up unpaired production reruns

I reused the uninstrumented binaries at af9777b4945a (main before this PR) and 2181902265d5 (PR). Each comparison used the same machine, checkpoint, one-stream settings, and three short fixtures described above. The original Studio ran three balanced blocks with one fresh start per condition in each block (base, PR, and PR with residency disabled). The second Studio repeated the eight randomized pairs. The table shows default residency in both builds. All generated token IDs matched their references.

Studio Replies per build Base stalls PR stalls Base median decode (tok/s) PR median decode (tok/s) Base pooled decode (tok/s) PR pooled decode (tok/s)
Original Studio 36 1 0 77.37 77.58 76.24 77.38
Second Studio 72 1 0 77.68 77.61 77.05 77.59

Both reruns used the original per-fixture stall cutoff of at least 20% above the earlier base median decode time and excluded warmups. Median prefill differences across the three short fixtures were at most 1.4 ms on the original Studio and about 0.2 ms on the second.

The unmodified main binary stalled on both Studios, so the stall predates this PR. The earlier 4.26% pooled decode drop and higher PR stall count did not recur in either production follow-up. Additional diagnostic builds with default residency stalled on 5 of 32 measured replies on each build. The long delays appeared in CPU-side Metal scheduling of the first decode command buffer, around 0.8–1.05 s. The trigger remains unresolved.

The full fix for the shared stall is tracked in #3902. The broader performance checklist item remains open.

Earlier Studio receipts

  • Main against this branch Both ranks connected on pristine main at 948e74858. Rank 1 failed with PeerSilent at exchange 2, and rank 0 did not become ready within 65 seconds with tracing off. The patched rank 0 became ready in 21.126 seconds and served requests. Both runs used the same Studios, checkpoint, MCDMA library and 66,560-token context, with the prompt cache disabled and tracing off. The startup failure prevented measuring baseline decode throughput or cold prompt time to first token at any width.
  • Boxes and paths Native Metal GLM-5.3-Flash over a two-rank Thunderbolt 5 link. The full matrix used the default paired split. A separate smoke run exercised the expert split at one and four streams. CUDA, HIP, and XPU are outside this change.
  • Environment Two M5 Ultra Mac Studios, 256 GiB each, macOS 27.2 RC build 26B118, one Thunderbolt 5 link, and Zig 0.17.0. Checkpoint and integrated MTP weights from TensorFold/GLM-5.3-Flash-MLX-4bit-MTP revision d2b17f5253440224422b150705c1109a9a3a0368. Both ranks used the same MCDMA dylib SHA-256 ae63dd35624573a647d8fd23b0a29c436a5d3d3de97d40c29d880ce179ac7679. The original Studio inference benchmark used binary SHA-256 54594cc1ec9d2d46d4da484e7b64bd2b3747de58ac1118262a9fcbfaf50f7aa8, built on 948e74858 with this production diff.
  • New switch and profile entry None.
  • License of new weights or drafter N/A. Both ranks used the existing checkpoint and its integrated MTP weights.
  • Sampling Benchmark requests used temperature 0 and seed 1234. A request at temperature 0.7 returned HTTP 400, as expected for this greedy-only path.
  • Exactness All 201 independent full token-ID comparisons matched across 197 successful requests. The default split covered drafting on and off, and solo versus concurrent at every admitted width from 1 to 8. Cold runs covered 2,048 through 65,536 tokens. The expert split contributed 12 comparisons across four fixtures. Cache replay restored 11,178 of 11,226 prompt tokens, with identical 256-token replies in fresh, resumed draft, and resumed plain requests.
  • Timeout and clean restart An injected 1.6 s stall inside a native MCDMA call during startup caused both ranks to report EpTransferTimeout at exchange 183. The stalled rank reported the timeout before the native call returned. Both ranks exited without a GPU watchdog. A fresh pair answered BANANA, 42, and blue and completed 1,502 exchanges on each rank. That run predates cf2c65bd3.
  • Timeout at cf2c65bd3 Same Studios, checkpoint and MCDMA library, with a test-only shim that re-exports the MCDMA library and holds rank 1's 183rd payload mcdma_fabric_write_signal call for 1.6 s. Rank 1 reported EpTransferTimeout for exchange 181 after 1.001 s, before the stalled call returned. Rank 0 accepted that late payload, then reported PeerDown at exchange 182 when rank 1 closed the link. Both exited with status 1 about 2 s after the stall began, without a GPU watchdog. A fresh pair answered BANANA, 42, and Blue, each rank completed 29,460 exchanges, and both stopped with status 0 on SIGTERM.
  • Late peer at cf2c65bd3 With GLM_EP_DELAY_US=1500000 on rank 1, each prompt-chunk send over 1 MiB waited 1.5 s. The pair completed all 180 held exchanges and answered a 392-token prompt with BANANA. The previous 1 s budget would have failed the first held exchange. With GLM_EP_DELAY_US=12000000, both ranks' command buffers failed with kIOGPUCommandBufferCallbackErrorTimeout about 5 s into the first hold, before the 10 s arrival limit. Both reported GpuFailed and exited with status 1. On these Macs a peer more than about 5 s late therefore ends the pair through the GPU timeout rather than PeerSilent.

The public receipt preserves exact prompt fixtures, full output IDs, cache counts, timing data and settings. Download both files into the same folder and run python3 verify_studio.py to verify the comparisons and reproduce the medians. Raw Studio receipt · Verification script

Decode and cold prefill

Median of three runs per cell with tracing off and the prompt cache disabled. Decode uses 256-token replies across public repository fixtures. Aggregate decode is the total tokens after each stream's first token divided by the time between the first and last emitted tokens across the group. Cold prefill reports client time to first token and uses 16-token replies. Every cold run reported zero cached prompt tokens.

Measurement Drafting on Drafting off
1 stream decode 107.61 tok/s 24.16 tok/s
4 streams aggregate decode 114.08 tok/s 73.79 tok/s
8 streams aggregate decode 151.31 tok/s 115.59 tok/s
2,048 prompt tokens 1.441 s 1.424 s
8,192 prompt tokens 4.421 s 4.380 s
32,768 prompt tokens 17.578 s 17.548 s
65,536 prompt tokens 35.545 s 35.451 s

To reproduce startup on each rank, build with zig build native -Dcpu=apple_m1, then use the same checkpoint and the respective rank's settings file. Start rank 1 before rank 0.

tensorfold-native serve "$CHECKPOINT" --name glm-paired --host 127.0.0.1 --port 8153 \
    --speed-up "$RANK_SETTINGS" --context 66560 --prompt-cache-gib 0 \
    --temperature 0 --no-thinking --no-update-check

For the timing and equality measurements, stream the same requests through rank 0 with draft set to true and false, and compare the full output IDs alongside the token SHA. For cold prefill, send exact-length token-ID prompts with a fresh KV cache for each request. For cache replay, enable the default prompt cache and repeat the same chat prefix.

Kernel contract
  • Kernels ep_pack, ep_unpack, ep_rcombine, ep_rfinal, ep_rsend, ep_rsum, ep_amax_send, and ep_amax_merge replace their same-named flag-based implementations. Cases exercise live and stale epochs, repeatability, guarded buffers, non-finites, launch shapes, and FP32 accumulation and BF16 rounding where applicable.
  • Controls Each kernel has a planted low-32-bit epoch comparison. All eight were caught on each machine.
  • Commands zig build tf-kernel-contract -Dcpu=apple_m1 and tf-kernel-contract --only 'metal glm ep'. The M4 run also used --offline to check M1/M2 launches.
  • Coverage Live M5 Ultra on both Studios and M4 Pro on macOS 26.7.1 build 25G241. M1 and M2 launch limits were checked offline with Xcode 26.6 and Apple Metal 32023.883. Live execution on M1, M2, and M3 was unavailable.
Studio rank 0 (M5 Ultra), exit 0
SUMMARY 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problems; gates 4410 ms, limits 195 ms
Studio rank 1 (M5 Ultra), exit 0
SUMMARY 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problems; gates 4374 ms, limits 195 ms
M4 Pro, exit 0
SUMMARY 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problems; gates 5849 ms, limits 1318 ms

M4 Pro rerun at 27ddaf316, exit 0

SUMMARY 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problems; gates 5552 ms, limits 1189 ms

M4 Pro rerun at cf2c65bd3, exit 0

SUMMARY 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problems; gates 5611 ms, limits 227 ms

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.
    • Before and after Pristine main reproduced the startup failure. On this patch the Studio smoke test passed, all eight Metal probes passed, and all eight low-word epoch mutations failed their intended checks. The new probes bind the new shader ABI, so their negative GPU evidence comes from the planted mutations.
    • Dependency behavior The 19 transport unit tests passed without the native MCDMA library using simulated endpoints. For the Metal runner, injected device absence now skips cleanly with exit 0. The prior runner failed the same check with exit 1.
  • 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.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • 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
    • Main comparison Rechecked pristine main at 90b4fae6 on the same Studios and checkpoint. The default TP2 split at a 66,560-token context and GLM_EP_SPLIT=experts at an 8,192-token context both connected and then reported PeerSilent on rank 1 at exchange 2. Both ran with tracing off and the prompt cache disabled. Rank 0 reached neither HTTP readiness deadline of 65 s. The table reports candidate timings. A relative performance result needs a pair on which pristine main serves the same workload.
    • Drafter comparison Integrated MTP raised median greedy decode from 24.16 to 107.61 tok/s at one stream and from 115.59 to 151.31 aggregate tok/s at eight streams. Median server-side cold prefill at 65,536 tokens was 35.485 s with MTP and 35.402 s with drafting off, a measured difference of +0.23% over three runs per mode. Paired GLM Metal uses integrated MTP and supports greedy decoding. External --drafter and positive temperature do not apply.

@jcscocca

Copy link
Copy Markdown
Author

Decode check against #601 on the same pair and checkpoint, at this head (cf2c65bd3). Settings as in that report: one cable, --context 8192, default streams, FZ_LANE=1 FZ_GDN=2 MCDMA_FABRIC_QOS=1, greedy, 256-token replies, prompt cache off. Medians of three.

Prompt Plain MTP + copies First token
Quicksort, 14 tokens 26.3 tok/s 105.1 tok/s 0.08 s
Summary, 780 tokens 25.6 tok/s 49.2 tok/s 0.79 s
Summary, 5,998 tokens 24.6 tok/s 48.5 tok/s 3.40 s
  • Prompt processing is in line with FYI: GLM-5.3-Flash on two M5 Ultra Mac Studios, one cable vs two bonded #601 (0.82 s at about 0.8k, 4.48 s at about 6.2k). Decode on the summary prompts is about a third of its 137 to 142 tok/s.
  • Rank 0 logged 390,212 decode exchanges, with the peer's entries landing 116.5 us after its post on average.
  • With GLM_EP_SPLIT=experts the same prompts decode at 33 to 36 tok/s plain and 76 to 85 with drafts, and reach the first token in 4.0 s and 29.7 s.
  • One of these Macs alone decodes this checkpoint at about 78 tok/s plain, without the MTP head under its load limit.

Not isolated: macOS 27.2 against 27.0, and the shared-event handoff against the in-kernel wait, which cannot run on these machines. The summary prompt is a licence-text summary, since #601's prompt is not published. Posting in case the per-exchange cost is useful for the fix planned in #3158.

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @jcscocca. The separate send and arrival budgets, full-width epoch guards and joined cleanup look sound. The 19 transport tests, GLM host checks and macOS compile checks pass, with no new lean findings. Removing the admission guards also makes the expired-send test fail as expected.

This now waits on the focused M5 kernel check; we will run the device check on our side. No source changes requested from you. We’ll track the historical summary-decode gap separately, since the different OS and prompt do not establish a matched performance regression.

  • Synthena (Ash's Agent)

@danrudy33

Copy link
Copy Markdown

Independent short-run confirmation on two M5 Ultra Studios

Thanks @jcscocca for this patch. We built and tested PR head cf2c65bd3e562b9cfd621f56b8af6c45a71bfc3f on two 256 GB M5 Ultra Mac Studios.

  • Checkpoint: TensorFold/GLM-5.3-Flash-MLX-4bit-MTP, revision d2b17f5253440224422b150705c1109a9a3a0368 (4-bit/group-64).
  • Settings: native paired row-split path; 2,048-token context capacity; prompt cache disabled; thinking off; default integrated MTP + history-copy drafts; fresh logical HOME/TMP and no-learn.
  • Observed: both ranks connected, rank 0 served three successive requests, and PeerSilent was not observed during this run. A simple capital question returned the expected answer, Paris.
  • Short timing sample: a 57-input/256-output-token coding-text request completed in 5.049 s, with 52.448 tokens/s server-reported decode. The preceding warmup and measured response were byte-identical. Output was deliberately capped (finish_reason: length); this is not a complete/tested program or a substantive coding-quality result.
  • Cleanup: both native ranks were stopped, with independent post-run checks confirming their absence.

This is a bounded independent inference smoke test, not a focused M5 kernel-contract/fault-injection result, a long-context reliability result, or a matched one-/two-Mac speedup measurement. We did not rerun a matched pristine-main control, so this is confirmation of successful operation at the tested PR head, not an independent isolation of the defect's cause. Higher-input and substantive repeatability/benchmark tests remain outstanding.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@jcscocca, the focused M5 Ultra check passes at this head: all eight changed kernels pass gates 1-4, all eight planted controls are caught, and there are no limit problems. The 19 transport tests pass too, along with 451 host tests and the Metal compile checks; one host test is skipped. There are no new lean findings.

This settles the local kernel check we promised. We did not rerun a two-Mac pair, so real-link fault, late-peer, cleanup/restart and served-token checks keep their separate receipts. Exact-head CI still needs confirmation before landing.

  • Synthena

@jcscocca

Copy link
Copy Markdown
Author

@ashhart, thanks for running the M5 Ultra kernel check. On the two things you left with me:

Checks at this head, run locally

The hosted workflows for cf2c65bd3 have not started (fork approval), so I ran the pull-request jobs at this exact head, clean tree, merge base bafe3e07c: on an M4 Pro (macOS 26.7.1, Zig 0.17.0), and the Linux steps in an ubuntu:24.04 container on the same Mac (arm64, 4 cores, 8 GB; the hosted runner is x86_64).

Workflow job Step Result
Zig format zig fmt --check build.zig zig pass
No GPU, benchmark-clients test_bench*.py, test_evidence*.py pass on macOS (Python 3.14) and Linux (3.12); the workflow uses 3.11
No GPU, pytest python -m pytest -q -p no:cacheprovider from the root Linux container: 452 passed, 93 skipped
No GPU, zig CUDA primitive copies and their test pass
lean check against the merge base 0 new
zig build -Dfixed-cpu test-kernel-contract 242/242 tests on macOS, 205/205 on Linux
zig build -Dfixed-cpu test-golden pass on both
zig build -Dfixed-cpu test-gradient-serving test-qwen-serving-host 3/3 tests
zig build -Dfixed-cpu test-server-security test-pull-security 45/45 tests, 27 security checks
zig build -Dfixed-cpu fuzz-cortheon 22/22 tests
Flash Next gate regressions, NFKD tables and generator tests, build options pass on macOS; on Linux the NFKD steps need Python 3.14, which the image lacks
zig build -Dfixed-cpu test-host --test-timeout 20m Linux container: 18,662 of 18,798 tests passed, 136 skipped, 0 failed; 3 of 2,051 steps failed for container reasons (no C compiler for test-video-layout-linux, FileBusy spawning a just-written binary in test-release-directory-host, the compiler killed for memory in compile-modelopt-startup), and all three pass when rerun with gcc and 14 GB. On macOS, every test, test-* and check-* step minus the workflow's exclusions: 24,184 of 24,356 tests passed, 169 skipped; 2 failed (core.paced_read and GLM weights_fix, the two memory-floor tests that also fail on the base here), 1 timed out at 20 minutes (DeepSeek aot-needs, outside this change), and 1 target did not build (below)
No GPU, release-paths zig build -Dfixed-cpu check-release-paths Linux container: pass (10/10 steps). macOS arm64 server: pass (68/68) with -Ddist-macos-sdk set to this Mac's SDK; without it the build looks for an SDK path this Mac no longer has
No GPU, zig-macos-dev-tools zig build dev-tools -Doptimize=Debug pass

One real problem turned up. This change breaks the build of test-metal-residency-owners-host: zig/src/families/glm/ep.zig:285 and :380 call dispatchType() on the compute encoder, and the recording Metal stand-in in zig/residency_recording_metal.zig has no such method (no field or member function named 'dispatchType'). On bafe3e07c that target builds and passes 73/73 here; at this head it stops with those two compile errors. Pull-request CI does not see it, because the Linux test-host excludes that target and the macOS deferred suite runs only nightly. A three-line commit that gives the stand-in dispatchType() (returning .serial) makes it build and pass 73/73 at this head, and 74/74 on #3380's head. I can push it here if you want it in this pull request.

Not run: the Windows job, and the Linux steps on x86_64. Exact-head CI on the hosted runners is still needed.

Pair receipts at this head

The fault, late-peer and restart runs in the description were made at this head on 13 November; their rank logs are in the attached tf3293-pair-receipts.tar.gz under 2026-11-13/. The binary on both ranks was SHA-256 5bec81f3…db09, built right after cf2c65bd3 was committed. No build record was kept with it, so I rebuilt this head from a clean tree today: code and data are the same byte for byte, and the two files differ in 158 bytes, all in the UUID, three system library version stamps from a newer Xcode SDK, the debug map and the ad-hoc signature.

The served-token check at this head covered one stream only, so I ran the missing part today on the same pair, checkpoint and binary (2026-11-16-served-tokens/): one fresh start, --context 66560 --prompt-cache-gib 0 --no-thinking, eight streams.

  • Eight prompts from tools/bench_prompts.json, up to 256 tokens: plain, drafted and drafted again alone, then drafted four at once (four of the prompts) and eight at once. All 28 drafted replies have the same token IDs as that prompt's plain reply. Bodies, whole replies and IDs are in the bundle.
  • tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4,8 --alone --serial: 0 failed. At 1, 4 and 8 streams every reply equals its request alone (3/3, 12/12 and 24/24, for the code prompt and for the chat prompt), and the alone replies equal "draft": false.
  • Three one-line requests return BANANA, 42 and Blue, with the reply token hashes the 13 November restart log shows (77421dd61b56, c65731c43fc4, 247ab9c78d51); that log has the hashes but not the texts.
  • 123 requests in that start, 640,963 exchanges on each rank, and both ranks exit 0 on SIGTERM.

Not rerun today: the injected stall and the two late-peer cases. Their receipts are the 13 November logs, one run each. Those logs show the stall line, the errors, the exchange counts and the exit statuses, but they do not record the GLM_EP_DELAY_US values (1.5 s and 12 s, as I set them) or the reply texts.

tf3293-pair-receipts.tar.gz

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @jcscocca, and good catch on test-metal-residency-owners-host. The pull-request jobs skip that target, so only the nightly macOS suite would have caught it. Yes, please push the three-line dispatchType() stand-in (returning .serial) here.

Main has moved since your base, so the branch needs a rebase:

  • forward.zig and mtp.zig: main added headWith so MTP drafts can use a stored shared_head.head. Give headWith the *Pass (with const e = pass.enc), have headOver forward pass, and call fwd.headWith(x, pass, x.w.draft_head orelse x.w.head, ...) from mtp.drafts.
  • checks.zig: main's new promptNll merges without a text conflict, but it still passes b.enc to prompt_mod.backbone. It needs var b = e.begin(); and &b, and should read b.enc only after the backbone call.

Once the rebased head is up, please mark the pull request ready for review. We'll approve the fork workflows then, and landing waits on green CI for that head. Thank you for the eight-stream served-token run and the receipts bundle. They answer the exactness question we had left open at this head.

  • Synthena

@jcscocca
jcscocca force-pushed the codex/glm-shared-event-3158 branch from cf2c65b to 2181902 Compare November 18, 2026 02:33
@jcscocca
jcscocca marked this pull request as ready for review November 18, 2026 02:33
@jcscocca

Copy link
Copy Markdown
Author

@ashhart, rebased onto af9777b49 and pushed, with the dispatchType() stand-in as its own commit (returning .serial).

Resolutions, all in the first commit; the other four apply unchanged:

  • forward.zig: headWith takes the *Pass (const e = pass.enc), and headOver forwards pass.
  • mtp.zig: drafts calls fwd.headWith(x, pass, x.w.draft_head orelse x.w.head, ...).
  • checks.zig: promptNll uses var b = e.begin();, passes &b to prompt_mod.backbone, and reads b.enc only after that call.

Run locally at the new head on an M4 Pro: format, lean check (0 new), test-kernel-contract 247/247, test-golden, serving pins, security, fuzz-cortheon, NFKD and build-options tests, check-release-paths, dev-tools, a full zig build, and test-metal-residency-owners-host 76/76. Not run at this head: pytest, the full host suite, Linux, Windows, and any pair run; the pair receipts in the bundle are from cf2c65bd3, before the rebase.

tools/pr_check.py reports no Unreleased line for this pull request as an advisory; I can add one if you want it.

Marked ready for review. I'll rebase #3380 onto this head next.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @jcscocca for the quick rebase and the separate stand-in commit.

All three asks from our last comment are resolved at this head:

  • test-metal-residency-owners-host: the recording encoder now has dispatchType() returning .serial (zig/residency_recording_metal.zig:280).
  • headWith takes the *Pass, headOver forwards it (zig/src/families/glm/forward.zig:525-531), and mtp.drafts calls fwd.headWith(x, pass, x.w.draft_head orelse x.w.head, ...) (zig/src/families/glm/mtp.zig:74).
  • promptNll uses var b = e.begin(), passes &b to the backbone and reads b.enc after it (zig/src/families/glm/checks.zig:250-255).

The patch applies cleanly to current main, every touched file is under 600 lines, and the unpaired path only threads the encoder through Pass. You don't need to add the Unreleased line; we settle CHANGELOG at landing.

What remains:

  1. A short pair run at this head. The rebase brought main's stored MTP draft head into the paired path (mtp.zig:74), and the pair receipts are from cf2c65bd3. Please post token hashes for drafted against "draft": false, and for concurrent against solo at 1 and 8 streams. A few prompts is enough.
  2. One-Mac (unpaired) GLM, main against this branch on the same machine: token hashes for a few prompts and decode and prefill timings at one stream. This PR touches that path (moe.zig, prompt.zig, engine.zig), so we want to see identical tokens and no slowdown. If you are unable to run it, please say why.
  3. Please update the description's head and checks to 2181902265d5. It still describes cf2c65bd3.
  4. Please add a line to the description for the mcdma.zig change. writeSignalFrom and signal now check the deadline again after taking the port lock (zig/src/fabric/mcdma.zig:256-264, :476). Other paired paths share them (flashnext TP, core/pair.zig). This only affects timeouts, but it isn't mentioned.

Landing also waits on green CI for this exact head.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I reran the exact 2181902265d5 head on M5 Max with Zig 0.17.0. The host command below passed 163/163. The documented standalone MCDMA command passed 19/19 with the fake endpoints.

zig build test-metal-residency-owners-host test-glm-expiry \
  test-glm-scheduling-host -Dcpu=apple_m1 -j5 --summary all
zig build tf-kernel-contract -Dcpu=apple_m1 -j5 --summary all
zig-out/bin/tf-kernel-contract --only 'metal glm ep'

The Metal contract run passed all eight exchange kernels, eight planted controls and the launch limits. This used one Mac and covers the kernel and transport fixtures. The live pair and one-Mac inference comparisons Ash asked for remain open.

The trial merge into b7298b4e now conflicts in six files. The first semantic conflict is in forward.zig: main's moeBlock produces the branch state used by its newer fused mixing path, while the PR's corresponding arm calls moe with a *Pass. The rebase needs to preserve main's branch state while threading the pass through the exchange. The contract registry conflict can keep both the new upstream launch suite and this PR's exchange suite.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the codex/glm-shared-event-3158 branch from 2181902 to 7830de0 Compare November 22, 2026 00:53
@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged the current head 7830de02f into main 2ce240cf0 on M5 Max with Zig 0.17.0. The merge applies cleanly, but the rebase dropped the recording encoder's dispatchType() stand-in. test-metal-residency-owners-host fails to compile at both calls in zig/src/families/glm/ep.zig (lines 284 and 379). The GLM scheduling and expiry targets still pass their 92 tests.

I restored the same three-line method from the previous head inside ComputeEncoder in zig/residency_recording_metal.zig:

pub fn dispatchType(_: @This()) DispatchType {
    return .serial;
}

Rerunning the command below passed all 13 build steps, including all 76 residency-owner tests. The 92 scheduling and expiry tests were cached from the preceding run on the same trial tree.

zig build test-metal-residency-owners-host test-glm-expiry \
  test-glm-scheduling-host -Dcpu=apple_m1 -j3 --summary all

Igor Lessio - AIFLOW LABS

The GLM exchange handoff reopens an encoder with the closing one's dispatch type, so the recording Metal fake needs it to compile test-metal-residency-owners-host.
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

@jcscocca Our earlier rebase of this branch dropped three of your commits: the shared GLM exchange probe, the separate send and peer-arrival deadlines, and the recording mock's dispatchType(). They're back with your authorship, and nothing is needed from you. The paired transport and Metal checks haven't been rerun yet.

  • 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.

GLM-5.3-Flash --speed-up on two M5 Ultras (macOS 27.2): ranks connect, then rank 1 fails exchange 2: PeerSilent and rank 0 never serves

4 participants