Skip to content

glm cuda: agree settings across every rank and give each follower its own doorbell - #765

Closed
Kurcide wants to merge 1 commit into
ashhart:mainfrom
Kurcide:fix/tp-all-rank-coordination
Closed

Kurcide wants to merge 1 commit into
ashhart:mainfrom
Kurcide:fix/tp-all-rank-coordination

Conversation

@Kurcide

@Kurcide Kurcide commented Oct 13, 2026

Copy link
Copy Markdown

Two coordination gaps in the GLM CUDA engine that show up only above two ranks (e.g. --tp 4).

1. Startup agreement checked only ranks 0 and 1. GlmEngine.__init__ all-gathers every rank's settings row, but compared only both[0] with both[1] and took the kept-prompt budget as min(both[0][-1], both[1][-1]). A rank 2 or 3 started with different flags (draft model, context, TF_GLM_*) went through unnoticed. Kept-prompt caches could also be sized above what a later rank reported room for (budgets [100, 100, 10, 20] MiB gave 100 MiB instead of 10).
Fix: a small agree(rows) helper compares every rank with rank 0, raises the existing "different settings" error naming each mismatched rank, and returns the smallest budget across all ranks.

2. The idle doorbell could lose a wakeup. _ring set one store key per request, tf_glm_request_{n}, and every follower deleted that key after its wait. With more than one follower, a fast follower could wait and delete the key before a slower follower started waiting. The slower follower then blocked on a key that no longer existed.
Fix: the leader sets one key per follower (bell_key(rank, n)), and only that follower deletes it. Rank 1 keeps the existing tf_glm_request_{n} name, so two-rank behaviour and the existing tests are unchanged.

Tests (CPU only, no GPU needed)

  • tests/test_glm_rank_agreement.py (new): budgets [100, 100, 10, 20] agree on 10; a settings mismatch on rank 1, 2 or 3 is refused and the error names that rank.
  • tests/test_glm_idle_bell.py: four ranks on an in-memory store, with ranks 1 and 3 consuming their wakeups before rank 2 waits. Every follower wakes for each request and no key is left behind. Before the fix this fails with the lost wakeup. The new agreement test fails before the fix because the helper does not exist yet.
  • pytest tests/cuda tests/test_cuda_*.py tests/test_glm*.py on CPU PyTorch 2.14: 1233 passed, 31 skipped, 5 failed. The same 5 tests fail without this change: 4 in test_cuda_geometry because triton is missing, and 1 lock test in test_cuda_build.

Not run: GPU or multi-rank hardware. The change touches only startup agreement and the store doorbell, not kernels or arithmetic, so decode output and speed are unaffected.

… own doorbell

Startup gathered every rank's settings but compared only ranks 0 and 1, and took
the kept-prompt budget from those two alone, so on four ranks a mismatched rank 2
or 3 started anyway and the cache could exceed what a later rank had room for.
Every rank is now checked against rank 0 (the error names each mismatched rank)
and the budget is the least across all ranks.

The idle doorbell rang one store key per request that every follower deleted
after waiting, so on more than two ranks a fast follower could delete it before
a slower one began to wait, and that follower missed the request. The leader now
sets one key per follower, which only that follower deletes; rank 1 keeps the
existing key name, so two-rank behaviour is unchanged.
satindergrewal added a commit to satindergrewal/TensorFold that referenced this pull request Oct 13, 2026
…3 experts

Checked ash hart PRs open+closed (read-only). Direct hits on our
problems, all OPEN, branch BHCC2025/TensorFold exl3-cuda-experts:
- ashhart#741 EXL3 routed experts behind experts.Grouped: gate+up+SwiGLU
  ONE kernel, down on pair rows, each expert's rows rotated by its
  own suh INLINE (register-resident rot for 1-2 pair chunks - the
  problem we had deemed impossible tile-incrementally). Rides on
  grouped.zig's Plan (in our tree). 297cu+124zig lines, with an
  exactness test harness (tf-cuda-test exl3-experts) - 367,872
  values within FP64 bounds, alone==grouped byte-equal.
- ashhart#740 EXL3 projections behind qlinear (the stacked base).
- ashhart#718 branch-free trellis window extraction (perf).
- ashhart#729 share decoded weights across prefill rows (perf).
- ashhart#728 MiMo-V2.6 CUDA EXL3 two-GPU (another full CUDA EXL3 family).
- ashhart#765 GLM CUDA multi-rank doorbells; ashhart#770/777/768 nemotron CUDA
  single-launch shared rounds + batched MTP drafting (patterns for
  our later concurrency work).
PLAN: vendored exl3_experts.cu/.zig + exl3.cuh into our tree (this
commit, unwired). Next: build wiring (fatbin + mod), port moeBlock
to Grouped.decode with the router->plan plumbing from grouped.zig,
run their exl3-experts test on our checkpoint, parity, bench. Our
own grouped kernels (stage-1 parity) stay as fallback.
@SvangenStudios

Copy link
Copy Markdown

A TP=4 GPU data point from a related implementation, rather than this PR: I tested the tp4 branch of MiaAI-Lab/GLM-5.3-Flash-EXL3-2x-DGX-Sparks-TensorFold at d220030 (TensorFold v0.6.0 with additional patches) on four DGX Sparks (GB10) in a switchless ring.

Its doorbell uses the same key naming and per-follower set/delete design. Startup agreement uses odd_ranks() and takes the minimum reported kept-prompt budget in the constructor, whereas this PR puts both operations in agree(). The branch also compares a larger settings row and has a longer error message; TF_GLM_SHARED_PREFIX, used below, is not part of this PR's settings row.

For the single-rank overrides, I used the launcher's DRY_RUN commands and inserted one additional Docker -e before the image name.

Test Observation
TF_GLM_SHARED_PREFIX=0 on rank 2 only Rank 0 had exited by the 10-second check. The error showed rank 0 and rank 2, whose settings rows differed at one index. All four containers exited with code 1.
Same override on rank 3 only Rank 0 had exited by the 10-second check. The error showed rank 0 and rank 3. All four containers exited with code 1.
TF_GLM_CACHE_GIB=8 on rank 3, 32 elsewhere Started; reported pool: 2,033,664 tokens.
8 on every rank Reported pool: 2,033,664 tokens.
32 on every rank Reported pool: 5,834,752 tokens.

The mixed-budget run matched the all-8-GiB control. This is indirect evidence for sizing to the limiting rank, rather than a direct measurement of the agreed kept-prompt budget: the run used --parallel 8 and reported kept_bytes_cap=0.

With rank 3 at 8 GiB, six requests completed in 0.18–0.27 s. The first was sent immediately after the startup check; the remaining five followed idle gaps of 5, 10, 15, 20 and 25 s.

This is a TP=4 smoke test consistent with the per-follower doorbell design. I did not trace each follower's wakeup or deliberately delay a follower. It does not exercise this PR's agree() or tests, and these few requests cannot rule out a lost-wakeup race.

@ashhart
ashhart changed the base branch from python-0.6 to main October 14, 2026 07:02
@ashhart

ashhart commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Hello @Kurcide,

Thank you for agree(rows) and the per-follower doorbell.

Above two ranks, startup compared only rank 0 with rank 1. Budgets of 100, 100, 10 and 20 MiB kept 100 MiB. agree compares every rank with rank 0 and keeps the smallest budget. One shared key, tf_glm_request_{n}, let a fast follower delete a slower one's wakeup. The leader now sets one key per follower. Rank 1 keeps the old name. Your CPU tests pin the budget, a mismatch on rank 2 or 3, and four ranks that still wake. Those three cases are the bar we keep.

This cannot merge. The Python engine is frozen, and no Python pull request merges any more.

The native home is #593, once GLM CUDA serves more than two ranks. Please say so there before a native pull request. You are welcome back with those two checks.

Thank you again.

@ashhart ashhart closed this Oct 14, 2026
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.

3 participants