Skip to content

tp: an opt-in four-rank ring relay for gathers on a switchless ring (#1971) - #2352

Merged
ashhart merged 5 commits into
mainfrom
lead/tp-ring-relay
Nov 8, 2026
Merged

ashhart merged 5 commits into
mainfrom
lead/tp-ring-relay

Conversation

@ashhart

@ashhart ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Part of #1971, item 2: an opt-in relay in fabric/tp/roce_multi for a ring of four with no opposite links. Today that ring is refused, and the ranks fall back to NCCL.

How it works. TF_TP_ROCE_RELAY=1 is opt-in and requires exactly four ranks.

  • Each rank posts its data to both neighbours. A neighbour keeps it and forwards one half along each direction to the opposite rank, so a consumer waits for six flags.
  • One proxy owns every queue pair, with no new locks. Flow control needs no credits: a rank posts sequence s only after consuming s-2 and seeing every source's s-1. Forwards are reaped in order.
  • Errors and waits name the rank, the sequence, the flag seen and the stage. A dropped flag, a late rank and a wrong sequence each fail by name within the bound.
  • The settings digest and the four-rank bootstrap agree on the switch, and a distinct record tag refuses mixed protocols. The whole ring table is validated before any queue pair changes. The existing all-rank NCCL probe still decides whether the wire is used.
  • Only gathers are relayed. Reductions and exchanges stay on NCCL, as on main. Two- and three-rank behaviour, both CUDA kernels, mesh pairing and native collective routing are byte-identical to main.

Tests, host only. They run on the in-memory fake ring and the shared-memory wire.

  • 200,000 random variable-size collectives (100,000 a wire, rotating gather, f32 sum, bf16 sum and opposite-rank exchange). Every received word is checked against its sequence, sender and index, and against the existing mesh result.
  • A held final-piece reader and a deferred-read fake wire, which expose early buffer reuse.
  • All 65,536 padded sizes through 1 MiB, 2,097,152 segment plans, and sequence wrap.
  • Four real proxy threads with four producers, 1,000 varying-length gathers per rank.
  • Planted faults (no custody, bf16 rounded per input, a first-vote-only probe) each fail.
  • 84 protocol tests pass, the Linux ARM64 runner compiles, zig fmt --check passes, and every file is at 600 lines or under.

Not covered. No four-box ring has timed it yet, which is #1971's last item. On two GB10s we'll also run a payload-pattern stress of today's two-rank wire, which checks whether the proxy needs an explicit outer-shareable barrier before posting.

Found along the way, not changed here: main's reference.reduce rounds bf16 after each rank (through reduceHalf), despite its round-once comment. That's for a separate look.

Based on design facts from a public four-GB10 ring engine (blaesus/dsgx10, via Picom-code/pico-dgx-ds4's ring notes), summarised on #1971. This is our own implementation.

@Bizuayeu

Bizuayeu commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Rather than a second relay, could you run #2352 on your ring and say there what doesn't fit? The terms stand: opt-in, bounded waits, the failing rank and sequence named in errors, and NCCL unless every probe matches. When you post the timing, please put main's NCCL numbers and the branch's side by side on the same ring, at the same sizes.

#1971 (comment)

I ran it on four GB10s cabled as a switchless ring: two QSFP ports a box, ranks 0-1-2-3 along the cables, no link between 0–2 or 1–3. NCCL 2.30.7, head fed475cf8 and its base 34d42fcc8. For GLM-5.3-Flash (XSFP4, TP=4, TF_GLM_PREFILL_REDUCE=gather) both carry the gather warm-up change I describe on #1971, without which GLM doesn't get past its start-up warm-up on this ring (main's baseline is there too). NCCL runs everywhere with NCCL_CUMEM_ENABLE=1, NCCL_RUNTIME_CONNECT=1, NCCL_ALGO=Ring and a graph per rank; the #1971 comment says why. The relay runs with TF_TP_ROCE_HCA naming each box's two neighbour ports.

What doesn't fit

  1. GLM's wire never asks for the relay. families/glm/cuda_roce_multi.zig fills Roce.init's options itself and leaves relay false; only roce_multi_session.zig passes cfg.roce_relay. With TF_GLM_ROCE_MULTI=1 TF_TP_ROCE_RELAY=1 TF_TP_WORLD=4, every rank opened both neighbour HCAs, asked for the mesh's three queue pairs and stopped with tp roce: rank N connect failed: BadRecord, then RoceUnavailable. With .relay = cfg.roce_relay, added to that call, the relay opens.
  2. GLM also needs TF_TP_WORLD=4. Config.parse checks TF_TP_ROCE_RELAY against TF_TP_WORLD (default 2) before cuda_roce_multi.open sets cfg.world from GLM's world. Without it every rank loaded the weights and stopped with TF_TP_ROCE_RELAY=1 needs TF_TP_WORLD=4 (given 2). Roce.init already refuses a relay outside four ranks.
  3. tf-tp-test suite stops before its sweep on this ring. Its NCCL reference for send/recv (ranks 0 and 1) and for the paired exchange (rank ^ 1) is NCCL point-to-point, and NCCL picks a receive's port by channel rather than by peer. Rank 1 tried the port toward rank 2 for rank 0's queue pair (ibv_modify_qp failed with 110 Connection timed out, on dev rocep1s0f0:1 … local GID ::ffff:10.41.57.1, remote GID ::ffff:10.41.46.1), and the fate channel stopped all four. A local TF_TP_TEST_SKIP_P2P=1 that leaves out those two checks let the rest run.
  4. The default slot is past the relay's break-even on this ring. GLM sends every gather up to the slot (256 KiB) to the wire. The relay is faster than NCCL up to 128 KiB and slower at 256 KiB (table below), and four concurrent streams decoded 2–4% slower than on NCCL. With TF_TP_MAILBOX_MAX_KB=64 that loss was gone and one stream kept its gain, so the gathers between 64 and 256 KiB look like the cause.

Everything below that says "with items 1 and 2 in place" is the head plus that one line, built locally; it isn't a branch or a pull request.

The terms

  • Opt-in: with items 1 and 2 in place, TF_GLM_ROCE_MULTI=1 and TF_TP_ROCE_RELAY=1 on every rank. Each rank paired one HCA with each neighbour and none with the opposite rank (rank 0 -> rank 2: HCA pairs { }).
  • NCCL unless every probe matches: the 4 KiB probe equalled NCCL's on all four ranks before the wire was lent. I didn't plant a mismatch on the hardware.
  • Bounded waits, rank and sequence named: with TF_TP_MAILBOX_TIMEOUT_S=20, I stopped rank 2 with SIGSTOP five seconds into a 4,096-token greedy reply. 20.3 s later ranks 0, 1 and 3 had logged and exited:
    error: [tensorfold] tp roce proxy: relay rank 0: rank 2 sequence 15411 (receive, seen 15409): Timeout
    error: [tensorfold] tp roce proxy: relay rank 1: rank 2 sequence 15411 (forwarding, seen 15409): Timeout
    warning: tp roce: rank 1's wait for seq 15411 from rank 3 failed (timed out after 20000011 us; HCA 1, flag held 15409, now 15411); doorbell 15411, posted 15411, completed 15410, abort 1, proxy failed 1
    error: [tensorfold] tp roce proxy: relay rank 3: rank 2 sequence 15411 (forwarding, seen 15409): Timeout
    
  • Exactness: tf-tp-test suite with item 3's switch: 328 passed, 0 failed on every rank, NCCL and RoCE, graph replays included, twice. In GLM, the greedy token_sha of two decode prompts and four concurrent cells is the same with the relay at every slot as on base's NCCL and on main's, and concurrent equals alone and serial in every cell.

Same ring, same sizes

tf-tp-test suite's sweep: all-gather, one rank's bytes, µs a call in a CUDA graph. Main's NCCL is base's runner (34d42fcc8 with the switch, TF_COMM_BACKEND=nccl). The head's runner (TF_COMM_BACKEND=roce) sweeps its NCCL and the relay in one process; I ran it twice. The relay's times moved by under 4% between runs, NCCL's by up to a fifth.

Bytes NCCL, base NCCL, head (two runs) Relay, head (two runs) Relay ÷ base's NCCL
4 KiB 30.2 33.4 / 27.3 22.1 / 22.0 0.73
8 KiB 44.7 44.6 / 41.8 24.1 / 23.2 0.53
16 KiB 46.5 50.4 / 43.2 27.1 / 27.2 0.58
32 KiB 54.3 65.3 / 51.0 33.9 / 33.9 0.62
64 KiB 58.1 54.9 / 55.1 42.2 / 42.3 0.73
128 KiB 68.6 65.0 / 65.0 58.9 / 59.1 0.86
256 KiB 78.4 74.8 / 74.9 93.7 / 94.7 1.20
1 MiB 213.8 204.2 / 195.8 196.6 / 196.6 (NCCL past the slot)
decode window (86 gathers of 8 KiB, a gather) 46.2 45.8 / 42.1 23.3 / 23.3 0.50

All-reduce goes to NCCL on both, and its numbers matched within NCCL's own spread.

GLM at TP=4

Same prompts (bench_cache.py --require-cold, bench_openai.py 256 tokens median of 3, bench_concurrent.py --levels 1,4 --alone --serial), drafts at their default. "NCCL" is head + the line with the wire off; base's NCCL run matched it within 0.6% on every row but cold 2K (3%).

NCCL Relay, slot 256 KiB (two runs) Relay, slot 64 KiB Relay, slot 16 KiB
Decode, code / chat, t=0 (tok/s) 69.7 / 58.0 68.8, 71.4 / 59.4, 59.5 71.9 / 60.0 68.0 / 56.5
1 stream, code / chat 69.8 / 58.0 70.8, 71.5 / 59.8, 59.7 71.9 / 60.0 69.9 / 58.1
4 concurrent, code / chat (total) 172.7 / 142.7 166.2, 167.7 / 136.8, 139.4 174.0 / 143.6 173.1 / 142.9
Cold 8K / 64K (s) 5.54 / 43.82 6.13, 5.53 / 43.93, 43.76 5.53 / 43.80 5.55 / 43.91
Rank 0's wire account — 415,464 gathers, 26.6 GB 351,654, 14.1 GB 95,100, 1.1 GB

At 128 KiB it sat between 64 and 256 KiB: one stream +2%, four streams equal. Cold prompts are the same everywhere (the 6.13 s was one run). At 16 KiB one stream decodes 2–3% slower than on NCCL alone; I haven't looked at why.

So on this ring the relay does what #2352 says once GLM reaches it, and its gain in GLM is about 3% on one stream with a 64 KiB slot. A default slot nearer the break-even would avoid the four-stream loss.

@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Thank you @Bizuayeu. This is the run we couldn't do ourselves. Exactness held on every rank and in GLM, and the bounded wait named the stopped rank and its sequence within the timeout. The table puts both NCCL runs and the relay side by side, as we asked.

We agree with all four, and we'll fix them on this branch:

  1. GLM's cuda_roce_multi.zig will pass cfg.roce_relay to Roce.init, as roce_multi_session.zig does.
  2. The relay will be checked against the world the family opens with, so GLM won't need TF_TP_WORLD=4. The refusal outside four ranks stays.
  3. On a relay ring, tf-tp-test suite will leave out only the NCCL point-to-point references (send/recv and the paired exchange). It will say in its output that it did, and why.
  4. The relay will take gathers up to a ceiling, 64 KiB by default (your best: one stream +3%, four streams level), and NCCL takes the rest. The ceiling is a setting checked by name. The bytes are the same either way.

Each fix gets a host test that fails on fed475cf8. Once they're pushed, we'll ask you for one more run on your ring, if you can: GLM at TP=4 with only TF_GLM_ROCE_MULTI=1 TF_TP_ROCE_RELAY=1, no local patch and the default ceiling, at one and four streams, beside NCCL.

@Bizuayeu

Bizuayeu commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Once they're pushed, we'll ask you for one more run on your ring, if you can: GLM at TP=4 with only TF_GLM_ROCE_MULTI=1 TF_TP_ROCE_RELAY=1, no local patch and the default ceiling, at one and four streams, beside NCCL.

#2352 (comment)

Yes, I can run it once the fixes are in.

One thing before then: on this ring GLM at TP=4 doesn't start without the gather warm-up change from #1971 (#1971 (comment)). Without it, main (964f98b0b, TF_GLM_PREFILL_REDUCE=gather) stopped in the peer warm-up on all four ranks within two minutes, as that comment says, and this branch has the same warm-up. So I'll run your new head twice:

  1. As pushed, to show where it stops on this ring.
  2. With only that warm-up change on top, for the numbers: the two settings above and the default ceiling, at one and four streams, beside NCCL on the same binary.

Everything else stays as in my last run: NCCL_CUMEM_ENABLE=1, NCCL_RUNTIME_CONNECT=1, NCCL_ALGO=Ring, a graph per rank, and TF_TP_ROCE_HCA naming each box's two neighbour ports. If you'd rather take the warm-up change into this branch, or have it as its own pull request first, say so and I'll do it that way.

@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

@Bizuayeu, the four fixes are pushed as 0243541ee1, one commit on fed475cf8:

  1. GLM passes cfg.roce_relay (and the new ceiling) to Roce.init through one options helper (families/glm/cuda_roce_multi.zig), with a host test that the relay stays on.
  2. GLM checks the relay against its own world and rank before startup opens and before any weights load (Config.fromEnvFor), so TF_TP_WORLD=4 isn't needed. Worlds 2 and 3 are still refused, and Roce.init keeps its own four-rank check.
  3. On a four-rank verbs relay with no opposite-rank link, tf-tp-test suite leaves out only the NCCL send/recv and paired-exchange references, including the paired graph node. It prints the reason, the two reference types and how many comparisons it left out. Other topologies run the whole suite.
  4. TF_TP_ROCE_RELAY_MAX_KB (4 to 1024, default 64) is the relay's ceiling, separate from the slot size. Gathers above it go to NCCL, the chunked route can't bypass it, and the ranks agree on it in the settings digest. A host test forces both paths at 64 KiB ± 16 B, 128 KiB and 256 KiB and compares every byte.

Each fix has a host test that fails on fed475cf8. The host suites pass, and the CUDA host and tests compile for Linux.

When you have the ring free, could you run the head once, with no local patch: GLM at TP=4 with only TF_GLM_ROCE_MULTI=1 TF_TP_ROCE_RELAY=1 and the default ceiling, at one and four streams beside NCCL, plus tf-tp-test suite without TF_TP_TEST_SKIP_P2P? The startup line should now say 64 KiB, and four streams should be level with NCCL.

@Bizuayeu

Bizuayeu commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

When you have the ring free, could you run the head once, with no local patch: GLM at TP=4 with only TF_GLM_ROCE_MULTI=1 TF_TP_ROCE_RELAY=1 and the default ceiling, at one and four streams beside NCCL, plus tf-tp-test suite without TF_TP_TEST_SKIP_P2P? The startup line should now say 64 KiB, and four streams should be level with NCCL.

#2352 (comment)

Done on 0243541ee, and both hold: the startup line says 64 KiB, and four streams are level with NCCL.

GLM at TP=4

As pushed, GLM doesn't start on this ring. All four ranks stopped in the start-up warm-up within about two minutes, after 26 to 35 ibv_modify_qp timeouts a rank (rank 0 from its port toward rank 3 to rank 2, rank 1 from its port toward rank 2 to rank 0's port toward rank 3), then ncclGroupEnd: unhandled system error. That is the gather warm-up from my last comment, not the relay. It goes in as its own pull request, as you asked on #1971; I'm taking its receipts on main now.

With only that warm-up change on top (0243541ee plus three files), every rank started with TF_GLM_ROCE_MULTI=1 TF_TP_ROCE_RELAY=1, the default ceiling, TF_TP_ROCE_HCA naming each box's two neighbour ports, the ring's NCCL lines as before, and no TF_TP_WORLD:

info: rank 0: TF_GLM_ROCE_MULTI: gathers up to 64 KiB a rank on the wire, its probe equal to NCCL's: HCA 0 QP RTS; posted 3, completed 3; HCA 1 QP RTS; posted 3, completed 3; reaped 0 (flushed 0), still posted 0

Same binary with the wire on and off, two runs each, alternating, on the same prompts and drafts as before:

Relay (two runs) NCCL (two runs) Relay ÷ NCCL
Decode, code / chat, t=0 (tok/s) 71.1, 70.9 / 59.3, 59.4 69.6, 69.7 / 57.9, 58.0 1.02 / 1.02
1 stream, code / chat 71.5, 71.4 / 59.7, 59.5 69.8, 69.7 / 58.0, 58.0 1.02 / 1.03
4 concurrent, code / chat (total) 173.2, 172.9 / 143.2, 142.8 172.4, 172.6 / 142.6, 142.6 1.00 / 1.00
Cold 8K / 64K (s) 5.53, 5.52 / 43.98, 43.68 5.55, 5.54 / 43.82, 43.77 1.00 / 1.00
Rank 0's wire account 351,654 gathers, 14.1 GB —

The greedy token_sha of two decode prompts and four concurrent cells is the same in all four runs and as in my earlier runs on this ring, and concurrent equals alone and serial in every cell. The wire account is the same as my earlier run with a 64 KiB slot.

tf-tp-test suite

Without TF_TP_TEST_SKIP_P2P, the head's runner left out the point-to-point references by itself and passed on every rank:

SKIP rank 0: 2 NCCL point-to-point reference types (send/recv and paired exchange, including graphs): four-rank relay has no opposite-rank link; NCCL receive ports are channel-selected
SUMMARY rank 0: 328 passed, 0 failed; 74 point-to-point comparison checks left out

Ranks 1 to 3: 328 passed, 0 failed, with 74, 72 and 72 left out.

@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Thank you, @Bizuayeu. That settles the relay on your ring: the startup line at 64 KiB, decode and one stream 2–3% ahead of NCCL, four streams and cold prompts level, the same token_sha in every run, concurrent equal to alone and serial, and tf-tp-test suite passing on every rank with only the point-to-point references left out, by itself and with the reason printed.

The relay stays opt-in, and the warm-up fix it needed to start on your ring is independent of it, so we won't hold this for that PR. We're running our own two-GB10 check now, main against this head with the relay off, to confirm the default path is unchanged. If it is, this goes into the landing queue, and your warm-up PR is welcome whenever its receipts are in.

@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Our check of the default path is in: GLM-5.3-Flash NVFP4 at TP=2 on two GB10s, main against this head's tree with the relay off, alternated base, new, new, base, plus a chat pass on each.

  • Every prompt row's token_sha256 is equal across all four runs (12 rows: 2K, 8K and 32K at three offsets, plus a repeat), and the chat passes qualify with the same cached counts.
  • 8K and 32K prompts, and chat and code decode at one and two streams, are level (within ±0.1%).
  • The summary's pp2k −2.5% comes from one slow row in one new run (1,002 tok/s at one offset); the other new run matches main on every 2K row (1,606–1,617 tok/s against main's 1,603–1,620).

So the default path is unchanged, and this goes into the landing queue, rebased onto today's main with only the CHANGELOG moved.

Validate every neighbour before connecting. Carry source half lengths, alternate completed forwards, and retain two-slot custody under the existing sequential producer contract. Keep default mesh and legacy two-rank posts separate, and retain NCCL reductions and exchange.

Exercise deferred fake DMA and the shared-memory wire against existing mesh posts over 200000 random collectives, plus live host consumers, bounded named faults, held readers, full decode boundaries and sequence wrap. RDMA qualification remains pending.

Refs #1971.
Consumer half flags are not physical HCA stripes. Report a connected neighbour for each HCA and refuse mesh posts on an opted-in relay before any verb.
Pass the relay options through GLM and validate its actual family world before weight loading. Keep a separate configurable 64 KiB relay ceiling so larger gathers stay on NCCL.

Omit the two NCCL point-to-point reference types only on verified four-rank verbs rings without opposite links, reporting the reason and comparison count. Add host regressions for the wiring, placement, topology and byte-exact routes.
@ashhart
ashhart force-pushed the lead/tp-ring-relay branch from 615f16c to 8e99c51 Compare November 8, 2026 20:06
@ashhart
ashhart merged commit b4db863 into main Nov 8, 2026
3 of 10 checks passed
@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Merged into main. Thank you, @Bizuayeu: the relay's evidence on a real four-rank switchless ring is all from your runs, the 64 KiB startup line, decode ahead of NCCL, every token_sha equal and tf-tp-test suite passing on each rank. It stays opt-in (TF_TP_ROCE_RELAY=1), and your warm-up PR is welcome whenever its receipts are in.

ashhart added a commit that referenced this pull request Nov 10, 2026
Figures corrected to the PRs' measured ones (#2699 head runs, #2509,
#2633, #2436, #2644, #2593, #2430, #2568), scope fixed (#2253, #2287,
#2511, #2569, #2337, #2627, #2351, #2626), unsourced figures dropped
(#2181, #2606, #2257's pricing clauses), the shipped #2176, #2565,
#2548 and gfx12 silu entries and the first #2625 copy removed, and
the #2568 and #2352 entries unwrapped to one line each.
ashhart added a commit that referenced this pull request Nov 10, 2026
The recipe still said gather warms every peer and that there is no
switchless RoCE relay. Gather's warm-up is now one all-gather (#2569),
ring's touches only its neighbours (#2126), and TF_TP_ROCE_RELAY=1
relays gathers on a four-rank ring with no opposite links (#2352).
Add the NCCL settings the ring needs: the engine sets NCCL_CUMEM_ENABLE
and NCCL_RUNTIME_CONNECT to 0 when unset (cuda_native.zig:244,247).
ashhart added a commit that referenced this pull request Nov 10, 2026
The recipe still said gather warms every peer and that there is no
switchless RoCE relay. Gather's warm-up is now one all-gather (#2569),
ring's touches only its neighbours (#2126), and TF_TP_ROCE_RELAY=1
relays gathers on a four-rank ring with no opposite links (#2352).
Add the NCCL settings the ring needs: the engine sets NCCL_CUMEM_ENABLE
and NCCL_RUNTIME_CONNECT to 0 when unset (cuda_native.zig:244,247).
@ashhart
ashhart deleted the lead/tp-ring-relay branch November 10, 2026 16:35
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