Skip to content

glm cuda: a logit gather broadcasts one block a rank, so TP=3 prompt_logprobs past ~100 tokens no longer hangs - #1571

Merged
ashhart merged 4 commits into
ashhart:mainfrom
gilby:glm-tp3-gather-fix
Nov 14, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
gilby:glm-tp3-gather-fix

Conversation

@gilby

@gilby gilby commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What this changes

Fixes #1559. GLM's logit gather (Sampler.gather, used by prompt logprobs and structured output) queued one ncclBroadcast per row per rank in one NCCL group, and at TP=3 a prompt-logprob pass over ~100 tokens never left ncclGroupEnd. Each rank's columns are already one [rows][span] block, so each rank now broadcasts that block once into a staging buffer and each block lands in full with one cuMemcpy2DAsync: world broadcasts whatever the row count. The bytes are the same, so the output is unchanged. Staging is rows * vocab bf16: 2.5 MB in the sampler (8 rows), 39.6 MB in the prompt-logprob buffers.

Receipt

  • Environment: three DGX Spark (GB10, 128 GB), driver 580, CUDA 13.0, ConnectX-7 RoCE through a switch, NCCL over IB; nvidia/GLM-5.3-Flash-FP4-Local @ 76348ddb, --context 500000 --parallel 4 --kv-cache fp8, TP=3; zig build native -Dsm=121. Measured on main a1e6d34 with this change; the same diff applies unchanged to a881b6f and to this base, and no GLM or NCCL file changed in between.
  • The hang: /v1/completions, max_tokens: 1, prompt_logprobs: 20, prompts as token ids. main: 87 tokens answer in 0.28 s, 128 and 512 tokens give no answer in 300 s (every rank in ncclGroupEnd, stacks in GLM on native CUDA at TP=3: a prompt_logprobs request over ~100 tokens hangs every rank in the gather's NCCL group #1559). This branch: 128 / 512 / 2,048 tokens answer in 0.30 / 0.60 / 1.68 s.
  • Exactness, tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 1.0,0 --alone --serial: 0 unequal and 0 failed in every cell, and every 256-token completion hashes the same as main's.
  • Prompt-logprob KL against a bf16 reference at TP=3, now measurable: 0.0279 over 51,175 positions (TP=2: 0.0286).
  • Decode speed: level with main (the gather runs only for prompt logprobs and structured output).
  • Prompt speed: n/a; a plain prompt does not call the gather.
  • Tests: zig build test-cuda-host on Linux aarch64 (GB10): 270/270 steps, 3,841 of 3,850 tests passed, 9 skipped, the same as main. zig fmt --check clean on the three files. python3 tools/zig/lean_check.py: 425 problems, the same as main.
  • Not run: no new unit test, since the hang needs three ranks on NCCL; Metal is not affected (CUDA-only family path).

Checklist

  • 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. The bits do not change: the same bf16 values are moved.
  • No GPU kernel added or changed (NCCL broadcasts and a driver copy).
  • Prompt processing is no slower than the last release (it does not touch the prompt path).
  • Platforms: CUDA on GB10 at TP=3 (and TP=2 for the KL comparison). Metal not affected.
  • New tests fail before the change, pass after it: none added (needs three NCCL ranks).
  • 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.

@ashhart

ashhart commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Hi @gilby, a status update on #1571.

We read the diff and found nothing unsafe: the spans tile the vocabulary exactly, and every rank posts its
broadcasts in the same order. What's still owed is the device run. The hang it fixes shows only at TP=3, so it
needs three GB10s at once, plus TP=2 for the byte-equal checks and the sampled decode speed. That's why it isn't
in our usual one-machine queue yet. Nothing is needed from you.

@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Hi @gilby, a status note: this is still waiting on us. The code read clean; what's left is our run on three GB10s at
TP=3 (requests with prompt_logprobs at and past ~100 tokens, log-probs equal to TP=2's) plus the TP=2 checks. Nothing
is needed from you. If it falls behind main before we get there, we can do the rebase; just say so here.

@ashhart

ashhart commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hi @gilby, a correction to our status notes here. We said the TP=3 run on three GB10s was ours, but we have no three GB10s linked together, so we can't run the case this fixes, and we're sorry for the wait that caused. Could you run it on your three, on this head rebased onto current main? The cells we'd want: prompt_logprobs at 87, 128, 512 and 2,048 tokens answering, with the times; bench_concurrent --alone --serial at 1 and 4 streams, temperatures 0 and 1, 0 unequal, with completions hashing the same as main's; and the prompt-logprob KL at TP=3 beside TP=2 on the same prompts. With those on the current base, this is ready to land.

@gilby

gilby commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Yes, please go ahead and carry the two small items on our branch, with our authorship: the staging buffers counted in the memory plan, and the host test that the gather posts one broadcast per rank whatever the row count. We accept your plan: you run the TP=2 byte-equal checks on your pair and land it with the TP=3 receipt already in the description, and we will run the TP=3 cells on three GB10s on the landed head when the sparks are free (they are currently carrying a pin; a window is being scheduled). Thank you for the correction on the 5 Nov note — understood that the three-GB10 run is ours.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby, we'll take it from here. We'll add the two items on your branch, with your authorship: the staging buffers counted in the memory plan, and the one-broadcast-per-rank host test across row counts at TP=2 and TP=3. Then we'll run the TP=2 byte-equal checks on our pair and land it with your TP=3 receipt in the description. Main is frozen for the 1.2.7 release this afternoon, so it lands just after. Your TP=3 cells on the landed head, whenever the sparks are free, will close the loop.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@gilby, we've added one commit on top of yours (f6f1d75c89, authored as you) with the two small items from our last read, so this can land without another round on your side:

  1. Staging counted before admission. The prompt-scoring stage and its column and full buffers are now prepared at startup, before a rank's room is read (zig/src/families/glm/cuda_native.zig:272), so the memory check counts them. If any rank can't allocate them, every rank keeps the existing window-row fallback and frees its prompt buffers.
  2. One broadcast a rank, pinned. zig/glm_logit_gather_host.zig checks with the recording driver that the gather sends exactly one block per rank at every height, at TP=2 and TP=3. It also checks the staging sizes, repeated preparation, complete frees and a peer's refusal.

No kernel or arithmetic changes. Main is frozen for today's release. After it ships we'll run GLM-5.3-Flash at TP=2 on two GB10s against main (byte-equal prompt logprobs and replies), and then it lands. If anything in the commit doesn't match what you intended, say so and we'll change it.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The TP=2 run against main is in, on this PR's change (head f6f1d75c89) over main, on two GB10s with the GLM-5.3-Flash release checkpoint, --parallel 2, base-new-new-base:

  • Tokens: 16 of 16 checks equal to main, none unequal or unverified.
  • Speed: level. Aggregate tok/s against main: chat +0.3% at one stream and -0.2% at two; code +0.1% and +0.0%.
  • Startup and memory: the same load time (230.5 s against 230.6 s), and the model takes 93.12 GiB against 93.03 GiB, the staging buffers your change now counts.

That was the last thing on our side, so it's queued to land. #1559 closes when it merges.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Rebased onto today's main and pushed to your branch, keeping your two commits as they were. The landing train's CI failed on this PR's own test, and both causes came from main moving underneath it:

  1. Main raised GLM's window_rows from 8 to 32, so the test's fixed 2,478,080-byte staging figure was the 8-row number. The test now expects vocab * 2 * window_rows, so it follows the window.
  2. Main's DeviceBuffer.download now asks whether the GPU is integrated first. The test's fake driver didn't answer cuCtxGetDevice or cuDeviceGetAttribute, so it read undefined memory. It now reports a discrete GPU, so downloads copy directly as before.

Your code is unchanged. zig build -Dfixed-cpu test-glm-logprobs-host passes (10 of 10), the serving pins pass, and lean is level with main. It's back in the landing queue. Thank you for the fix itself: a TP=3 prompt_logprobs hang is a nasty one.

  • Synthena (Ash's Agent)

gilby and others added 4 commits November 14, 2026 01:49
…logprobs past ~100 tokens no longer hangs

Spread.post queued one ncclBroadcast per row per rank in one NCCL group; at TP=3 a
128-row prompt-logprob pass (381 broadcasts) never left ncclGroupEnd. Each rank's
columns are already one [rows][span] block: broadcast it once into a staging buffer
and place it into the full rows with one cuMemcpy2DAsync. Same bytes, world
broadcasts whatever the rows.

Fixes ashhart#1559
Prepare prompt scoring buffers before rank room is measured and pin one broadcast per rank at every gather height.

Refs ashhart#1559.
…dow_rows and the fake driver answers the integrated-GPU check

Main raised GLM's window_rows from 8 to 32, so the expected staging is vocab x 2 bytes x window_rows rather than the
8-row figure, and main's DeviceBuffer.download now asks cuda/download_stage.zig whether the GPU is integrated: the
test's fake driver answers cuCtxGetDevice and cuDeviceGetAttribute as a discrete GPU, so its downloads copy directly
as before. The PR's code is unchanged.
@ashhart
ashhart merged commit bafe3e0 into ashhart:main Nov 14, 2026
12 of 20 checks passed
@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby! This is in TensorFold 1.2.9, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.9

  • Synthena (Ash's Agent)

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 on native CUDA at TP=3: a prompt_logprobs request over ~100 tokens hangs every rank in the gather's NCCL group

2 participants