Skip to content

Prepare window transfers once and run them per step - #8

Open
jinyouzhi wants to merge 4 commits into
affine-symm-windowfrom
affine-window-prepared
Open

jinyouzhi wants to merge 4 commits into
affine-symm-windowfrom
affine-window-prepared

Conversation

@jinyouzhi

@jinyouzhi jinyouzhi commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #7 (affine-symm-window).

Why

At executor level, PR #7's window path lost to staging for small messages: every call paid ~1 ms of control plane (an all_gather_object of window offsets plus a group barrier), not data movement. Rollout weight refresh repeats the same plan on the same buffers every step, so that work only needs to happen once.

What

  • prepare_transfers(...) -> PreparedTransfer: validation, digest agreement, window offset exchange, arena allocation and peer views, done once. PreparedTransfer.run() only moves data. execute_transfer(s) = prepare + one run, so existing callers are unchanged.
  • Peer signals instead of barriers (CUDA, XPU): each run, a window owner raises READY to its copiers (ordered after its writes on the current stream), and copiers raise DONE back after their copies. No host collective per run. Other devices keep group barriers.
  • One side stream for window copies, still in staggered peer order, so they overlap staged messages. Per-peer streams were tried and rejected: concurrent reads contend for links (4x4 bipartite pull 66 vs 92 GB/s).
  • Moved-buffer check: run(requests) compares the batch rebuilt from the live state with the buffers it was prepared with (data_ptr, numel, dtype, device, plan). If any moved on any process, e.g. after ZeRO-3 offload_states / reload_states, which move every weight partition and an aliased master to new storage, every process raises before data moves (one int64 all-reduce). run() without arguments skips the check.
  • Docs: affine-transfer.rst prepare/run section. Test: the window test now prepares once and runs twice, rewriting sources between runs, at 2 and 4 ranks.

Policy stays outside: when to re-prepare, pull/push, staging vs window are caller choices.

Results: 8x L20 (PCIe, CUDA 13, NCCL 2.30), executor-only deepspeedai#8966 scenarios

Aggregate GB/s, median of 5, all bitwise exact. Upstream = origin/master execute_transfer (staging). prep = prepared once, run() timed.

pattern w MiB upstream PR #7 pull staging prep pull prep push prep pull prep / upstream
peer (median of 56 pairs) 1 64 19.2 16.8 22.9 25.7 25.4 1.34x
fan_out 7 4 15.8 11.4 21.4 24.6 22.4 1.55x
fan_out 7 256 23.7 25.8 24.8 26.8 26.2 1.13x
fan_in 7 4 17.1 10.7 23.1 22.8 24.2 1.34x
fan_in 7 256 24.0 25.6 25.0 26.5 26.4 1.11x
pairs 4 4 22.2 9.9 47.7 48.6 50.0 2.19x
pairs 4 256 61.4 59.1 66.0 66.5 69.7 1.08x
bipartite 2x2 2 4 15.5 8.2 26.2 38.2 39.5 2.47x
bipartite 2x2 2 256 35.0 48.0 38.1 52.9 52.2 1.51x
bipartite 4x4 4 4 40.4 26.2 61.1 76.2 68.8 1.89x
bipartite 4x4 4 64 66.7 76.5 72.8 91.4 75.1 1.37x
bipartite 4x4 4 256 69.2 84.5 74.2 92.3 75.4 1.33x

Prepared pull beats upstream staging in all 38 pattern/width/size cells (1.08x-2.65x). Prepared staging alone also gains (no per-call preflight).

Results: 8x Arc Pro B70 (PCIe, torch 2.14 XPU), same scenarios

GB/s; up = upstream master staging per call, _p = prepared, median of 5 runs. All results exact. Best prepared method beats upstream in all 40 cells (1.12-2.97x).

pattern MiB w up staging_p pull_p push_p
peer (median of 56) 64 1 23.4 25.6 38.7 51.7
pairs 4 1 7.7 12.1 19.7 22.8
fan_in 4 7 19.8 22.2 33.9 46.5
bipartite 4 4 36.7 42.5 47.3 52.1
fan_in 64 7 30.8 30.8 40.9 55.4
pairs 256 1 25.2 27.5 40.6 55.2
fan_out 256 7 45.5 46.5 54.9 56.2
bipartite 256 4 51.1 52.0 52.0 57.0

On B70, push beats pull (on L20 pull is equal or slightly better), so direction stays a caller choice. Aggregate tops out around 56-57 GB/s.

Tests: test_affine_transfer_executor.py + test_affine_transfer_executor_external_group.py on 8x L20: 54 passed, 1 skipped. test_affine_transfer_executor.py on 8x Arc Pro B70 (torch 2.14 XPU, oneCCL with oneccl#1053): 54 passed, with both barrier and signal paths.

Not yet

  • Contract: every process must call run the same number of times. A moved buffer is caught only when run is given the rebuilt requests; the check does not see a buffer that was freed and reallocated at the same address with different contents meaning.

prepare_transfers does the validation, schedule agreement, window offset
exchange and arena allocation of execute_transfers once; PreparedTransfer.run
moves only data. On CUDA, window owners and copiers order each run with
symmetric-memory signals instead of group barriers; other devices keep the
barriers. Window copies run on one side stream, in staggered peer order, so
they overlap staged messages.

Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
jinyouzhi and others added 2 commits November 11, 2026 23:24
Each peer's staging arena is now a 256-byte aligned slice of one allocation per
direction instead of its own allocation. With oneCCL on XPU, peer buffers are
mapped through IPC handles, and allocating them again after a release cost about
0.1-0.4 s per batch at 2-4 processes on B70; one allocation brings that to 5-36 ms.
Run time and the bytes moved are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
ZeRO-3 offload_states / reload_states move every weight partition, and a
master that aliases it, to new storage. The plans still hold, but a
prepared transfer keeps its buffers and peer views and would go on
writing into the old storage without error. run(requests) now compares
the batch rebuilt from the live state with the layout it was prepared
with and, agreed across processes, raises everywhere before data moves.

Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
0z5a added a commit to 0z5a/DeepSpeed that referenced this pull request Nov 16, 2026
A weight sync moves the same batch every step, and every
execute_transfers call repeats validation, the alias check, scheduling,
the digest agreement, arena allocation and region views before the
first byte moves.

prepare_transfers does that work once and returns a PreparedTransfer
whose run only moves data. The handle keeps the arenas that deepspeedai#9027's
schedule reports, and for each round one list of (destination, source)
views: the packs before a send and the unpacks after a receive, plus
one list of local copies. execute_transfers is now prepare_transfers
followed by one run, with the same collectives as before. Python's
cyclic collector is paused while the views are built: tens of
thousands stay alive together, and the collections their allocation
triggered made a one-shot call at 8 processes on CPU about a third
slower than master.

A buffer that moves after prepare, as reload_states moves offloaded
ZeRO-3 partitions, would leave those views writing into the old storage. So
run checks by default: each process compares its buffers (the held
tensors, or requests rebuilt from the live state) with what it
prepared, and one small all-gather refuses on every process, before
data moves, if a buffer moved on any of them or the processes are not
running the same handle for the same time.

The shape of prepare_transfers and the buffer layout check follow
jinyouzhi#8 (a8c34e3); this is its staged half, without the
window transport.

Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Co-authored-by: Jin, Youzhi <youzhi.jin@intel.com>
0z5a added a commit to 0z5a/DeepSpeed that referenced this pull request Nov 20, 2026
A weight sync moves the same batch every step, and every
execute_transfers call repeats validation, the alias check, scheduling,
the digest agreement, arena allocation and region views before the
first byte moves.

prepare_transfers does that work once and returns a PreparedTransfer
whose run only moves data. The handle keeps the arenas that deepspeedai#9027's
schedule reports, and for each round one list of (destination, source)
views: the packs before a send and the unpacks after a receive, plus
one list of local copies. execute_transfers is now prepare_transfers
followed by one run, with the same collectives as before. Python's
cyclic collector is paused while the views are built: tens of
thousands stay alive together, and the collections their allocation
triggered made a one-shot call at 8 processes on CPU about a third
slower than master.

A buffer that moves after prepare, as reload_states moves offloaded
ZeRO-3 partitions, would leave those views writing into the old storage. So
run checks by default: each process compares its buffers (the held
tensors, or requests rebuilt from the live state) with what it
prepared, and one small all-gather refuses on every process, before
data moves, if a buffer moved on any of them or the processes are not
running the same handle for the same time.

The shape of prepare_transfers and the buffer layout check follow
jinyouzhi#8 (a8c34e3); this is its staged half, without the
window transport.

Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Co-authored-by: Jin, Youzhi <youzhi.jin@intel.com>
jinyouzhi added a commit that referenced this pull request Nov 23, 2026
A weight sync moves the same batch every step, and every
execute_transfers call repeats validation, the alias check, scheduling,
the digest agreement, arena allocation and region views before the
first byte moves.

prepare_transfers does that work once and returns a PreparedTransfer
whose run only moves data. The handle keeps the arenas that deepspeedai#9027's
schedule reports, and for each round one list of (destination, source)
views: the packs before a send and the unpacks after a receive, plus
one list of local copies. execute_transfers is now prepare_transfers
followed by one run, with the same collectives as before. Python's
cyclic collector is paused while the views are built: tens of
thousands stay alive together, and the collections their allocation
triggered made a one-shot call at 8 processes on CPU about a third
slower than master.

A buffer that moves after prepare, as reload_states moves offloaded
ZeRO-3 partitions, would leave those views writing into the old storage. So
run checks by default: each process compares its buffers (the held
tensors, or requests rebuilt from the live state) with what it
prepared, and one small all-gather refuses on every process, before
data moves, if a buffer moved on any of them or the processes are not
running the same handle for the same time.

The shape of prepare_transfers and the buffer layout check follow
#8 (a8c34e3); this is its staged half, without the
window transport.

Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Co-authored-by: Jin, Youzhi <youzhi.jin@intel.com>
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.

1 participant