Skip to content

feat(cuda): one communicator interface for two-rank engines (transports over NCCL) - #219

Closed
jayleaton wants to merge 2 commits into
ashhart:mainfrom
jayleaton:pr1-interfaces
Closed

jayleaton wants to merge 2 commits into
ashhart:mainfrom
jayleaton:pr1-interfaces

Conversation

@jayleaton

@jayleaton jayleaton commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Two-rank CUDA engines get one place to plug in a faster or different transport. tensorfold.cuda.comm gains a small
communicator interface, and the three engines that built NCCL(rank, 2, master, port) themselves (GLM-5.3, Flash
Next, Nemotron) open it with open_comm(rank, 2, master, port). With TF_COMM_BACKEND unset, nothing changes.

  • Comm: what every engine may assume (rank, world, all_gather, barrier).
  • fast_gather(comm, send, recv): the transport's all_gather_fast if it has one, else all_gather.
  • exchange(comm, sends, recvs, peer=None): NCCL.exchange (one ncclSend / ncclRecv group on the current
    stream). Without it, two ranks trade bytes through the all-gather.
  • check(comm): raises a failure the transport recorded.
  • Transport: a base that wraps NCCL and forwards whatever a subclass does not define (store, ready,
    all_gather, and later NCCL methods), so a transport overrides only what it speeds up.
  • register_backend(name, wrap) / open_comm(...): TF_COMM_BACKEND picks a registered transport; unset, it
    builds the same NCCL as NCCL(...). The ranks compare the name through the rendezvous store and refuse to start
    if they differ, since a transport on one rank only would hang the first exchange. An unknown name is refused
    before NCCL is set up.
  • NCCL gathers uint8, int8 and float16 too, and takes the rendezvous timeout and store key (defaults
    unchanged: 600 s and tf_nccl_uid).

Why: one-shot RoCE all-gathers on DGX Sparks now exist in three places (ours for two-Spark GLM-5.3-Flash, MiaAI-Lab's
RoceComm, and the one inside #159), each switched into one engine by its own variable. On our pair a 16 KiB
graph-captured gather takes 11.7 us against NCCL's 45.3 us, and decode gains 4-11% with the same bits. Point-to-point
trades (MiaAI-Lab's NCCL.exchange, #159's all-to-all) have the same problem. A transport written once under this
interface can serve any two-rank family. A roce transport would be a separate pull request on top of this one.

Rebased onto 0.6.3. comm.py and the three call sites had not changed upstream, and no new direct NCCL(...)
construction was added (#159 is still open). Qwen3.8-27B's torch.distributed process group is not an NCCL
object and is left as is. The optional CUDA_SERVE commit from the first version was dropped to keep one change in
this pull request; it was the only part that conflicted.

Receipt

  • Environment: TensorFold 0.6.3 (9356df5) plus these two commits. Linux x86_64, Python 3.14.7, PyTorch 2.14.1+cpu,
    no GPU, no MLX, no Triton. No checkpoint was loaded.
  • Exactness: not run. With TF_COMM_BACKEND unset, open_comm builds the same NCCL object with the same
    arguments and the engines make the same exchanges in the same order; the only new step is one store round trip at
    start in which the ranks compare the backend name. The new functions have no caller in the tree yet.
  • Decode speed: not run, for the same reason; the decode path is unchanged.
  • Prompt speed: not run, for the same reason; no prefill path, kernel or family exchange changes.
  • Tests run, with pass, fail and skip counts:
    • tests/test_cuda_comm.py (new, 10 tests) and tests/test_cuda_capacity.py, with tests/test_cuda_comm_ready.py:
      61 passed on this branch. On 0.6.3 with these test files: 27 failed, 34 passed. The 10 comm tests fail because
      the interface does not exist; the 17 two-rank GLM-5.3 and Flash Next capacity tests fail because the stand-in for
      tensorfold.cuda.comm now offers only open_comm, which 0.6.3's engines do not call.
    • Without PyTorch, the same two files collect and skip cleanly: 12 passed, 37 skipped.
    • Full suite, python -m pytest -q -n 4 --timeout 300 --continue-on-collection-errors tests, same session:
      this branch 3,442 passed, 208 skipped, 148 failed, 14 errors; clean 0.6.3 3,432 passed, 208 skipped, 148 failed,
      14 errors. The 162 failing and erroring ids are identical. They are 0.6.3's own on a Linux box without MLX,
      Triton or a GPU (MLX server, prompt fill and reasoning tests).
  • Not run, and why: no GPU here, so the CUDA runtime, tests/cuda, and the two-rank NCCL start were not run. The GPU
    tests that replace tensorfold.cuda.comm.NCCL with a fake (tests/cuda/test_flashnext_tp.py,
    tests/cuda/test_flashnext_nvfp4_loader.py) reach it through open_comm unchanged. Nothing was run on Metal; this
    change touches no Metal path. If you want a GPU receipt, I can run tools/bench_concurrent.py --alone --serial,
    tools/bench_openai.py and tools/prefill_cold.py on two DGX Sparks, before and after.

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.
    (Not measured here; the exchanges are the same NCCL calls as before.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release. (Not measured here; no prompt path changes.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • 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.

Jay Leaton added 2 commits October 3, 2026 13:15
…rts over NCCL, byte gathers, peer exchanges

Two-rank engines reach for faster or different transports (one-shot RoCE all-gathers on DGX Sparks, point-to-point
exchanges for split work, ashhart#159's all-to-all), and each one is wired into one engine by hand today. This gives them one
place to plug in:

- Comm states what every engine assumes of a communicator (rank, world, all_gather, barrier). Module functions
  cover the optional capabilities, each with a fallback: fast_gather (a model exchange takes the communicator's
  all_gather_fast where there is one, else all_gather), exchange (NCCL.exchange: each send lands in the peer's
  matching receive, one ncclSend / ncclRecv group on the current stream; a communicator without exchange trades
  through its all-gather, two ranks only) and check (raise a failure the transport recorded).
- Transport is a base that wraps NCCL and forwards whatever a subclass does not define (all_gather, store, ready,
  and later NCCL methods such as all_reduce or all_to_all), so a transport overrides only what it speeds up.
- register_backend / open_comm: TF_COMM_BACKEND names a registered transport; unset (or nccl), open_comm builds the
  same NCCL as NCCL(...) does. The ranks compare the name through the rendezvous store and refuse to start with
  different ones (a transport on one rank only would hang the first exchange). NCCL stays the control channel.
- NCCL gathers uint8, int8 and float16 too, and takes the rendezvous timeout and store key (defaults: 600 s and
  "tf_nccl_uid", as before).

Same bits: nothing in the tree calls the new functions yet; NCCL's existing methods, and its constructor with the
defaults, are unchanged. The next commit opens the two-rank engines through open_comm.

Tests: tests/test_cuda_comm.py (CPU, a two-rank fake): fast_gather and check with and without the optional methods;
exchange through the all-gather for float32, bfloat16 and int32 with unequal sizes, through a communicator's own
exchange with the default peer and a named one, refused past two ranks without one; backends wrap NCCL, unknown
names are refused, ranks naming different backends are refused; a Transport forwards store, ready and the
all-gather. docs/recipes/cuda.md: the communicator paragraph.
…communicator with open_comm

The three engines that built NCCL(rank, 2, master, port) themselves call open_comm(rank, 2, master, port), so a
transport registered for TF_COMM_BACKEND reaches them without a change to any family. Unset, open_comm builds that
same NCCL, plus one store round trip at start in which the ranks compare the backend name: same exchanges, same
bits. A name no transport registered stops the start with a ValueError that lists the registered ones, before NCCL
is set up.

Tests: the GPU tests that replace tensorfold.cuda.comm.NCCL with a fake (tests/cuda/test_flashnext_tp.py,
test_flashnext_nvfp4_loader.py) go through open_comm unchanged (the TP fake's real TCP store carries the backend
check); tests/test_cuda_comm.py covers open_comm itself. tests/test_cuda_capacity.py's stand-in for
tensorfold.cuda.comm answers open_comm only, so its two-rank GLM-5.3 and Flash Next constructors fail if they
build NCCL themselves.
@jayleaton jayleaton changed the title feat(cuda): one communicator interface for two-rank engines (transports over NCCL), plus an optional CUDA_SERVE hook feat(cuda): one communicator interface for two-rank engines (transports over NCCL) Oct 3, 2026
@ashhart

ashhart commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Thank you, @jayleaton. The communicator interface (tensorfold.cuda.comm, open_comm, TF_COMM_BACKEND) is in TensorFold 0.6.4 as your two commits from this PR's current head, under your name: https://github.com/ashhart/TensorFold/releases/tag/v0.6.4

We left out the CUDA_SERVE hook, as your update did. GLM-5.3, Flash Next and Nemotron now open their two-rank link through it, and it passed the two-Spark exactness run with #141 and #180. We look forward to the first transport built on it.

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