[AffineIR] Fused copies, symmetric-memory window and staging release for prepared affine transfers #9118
Thanks for the review. Rebased onto the current #9094 (on #9093) and addressed each point in 95e799dd4:
1. 16-byte elements. fused_copies now sends any element size outside {1, 2, 4, 8} to copy_, and the kernel asserts ELEMENT == 8 in the last branch. The fused test covers complex64 and complex128; complex128 fails without the fix.
2. Window copies and region aliases. _validate_aliases also takes the window operations of this process: a pulled/pushed target counts as a write, a pulled/pushed source as a read. New 2-process test: each rank's source shard and a target the peer writes are the same window tensor; every process refuses with "a source and a target overlap" and the shard is unchanged (pull/push × prepared/one-shot). The four cases do not raise without the fix.
3. Partial window / construction failure. Documented in TransferWindow and in the docs: pass the same window on every process or none.
4. release_staging. Relaxed the docstring: a process may release on its own; use check=True if re-allocation can fail. Added a test for that.
5. check=True restage failure. New test: the last rank fails to re-stage, every process raises "could not allocate the released staging", targets are unchanged, and the next run succeeds.
6. PR body. Fixed the pytest line.
CPU (gloo): 94 passed, 27 skipped. 4× B70 (xccl): all pass at 2 and 4 processes.
<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"2725eb4d2ea167529290755747f2feffeab6c14d","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->
<details>
<summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-26T07:02:45.398233Z">2026-11-26T07:02:45.398233Z</relative-time> | 2725eb4 | Draft marked ready |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
</details>
</details>
<sub><sub>!P1 Badge</sub></sub> Fold all copier build failures into collective rejection
When a user-supplied copier raises an exception not in this whitelist (for example AssertionError or OSError) on just one rank while _round_copiers/copier(...) is being built, that rank exits _agree before the decision all-gather while the other ranks block in it. PreparedTransfer.run repeats the same narrow catch when rebuilding after release_staging, so the documented collective-refusal behavior also fails there; catch ordinary Exception from the copier boundary and turn it into the shared rejected/failed flag.
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
<sub><sub>!P1 Badge</sub></sub> Resolve one-shot peer mappings before moving data
_mapped_copy_views is a generator, so in the one-shot execute_transfers(..., window=...) path this line does not call TransferWindow.peer until _run_mapped, after _run_rounds has already sent data and written staged/local targets. If peer-tensor construction fails on only one process (for example a backend cannot map that peer/dtype), that process raises outside _agree while the others wait at the final window barrier, and the advertised preflight/no-write rejection is lost. Materialize these views during agreement, as the prepared path does.
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
<sub><sub>!P2 Badge</sub></sub> Account for registered buffers in reported schedules
When a request buffer belongs to any live TransferWindow that is not passed as window, _agree supplies _registered_locations(requests) to _lanes so that side is staged rather than used as a direct NCCL buffer, but schedule_transfers calls _lanes here with registered=None. The public schedule therefore reports direct=True and no arena even though execution allocates and uses an arena; window_locations cannot represent this because it removes those operations as mapped copies. Add a registered-location input/state so memory and cost policies see the schedule that actually runs.
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
<!-- codex-review-receipt:v1 -->
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2725eb4d2e
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
</details>
Fixed in 3eb069b6a and 70f40973b. Caller copiers are wrapped with _safe_copier, and both _agree and PreparedTransfer.run (when restaging after release_staging) now catch Exception so any build or restaging failure folds into the collective refusal. Added multi-rank regressions for AssertionError and OSError across both prepare_transfers and release_staging rebuilds.
Fixed in 3eb069b6a and 70f40973b. _agree now materializes both _local_copy_views and _mapped_copy_views during agreement for the one-shot path as well, and catches Exception so a rank-local TransferWindow.peer failure of any kind refuses the batch collectively before any data moves (test_a_one_shot_refuses_whole_before_data_moves_when_a_map_fails_on_one_rank).
Fixed in 3eb069b6a. schedule_transfers now accepts per-process window_registered locations and forwards them to _lanes, reporting direct=False and the staging arena size whenever a round touches registered window memory (test_schedule_stages_a_round_that_starts_in_a_registered_window).
jinyouzhi
Stacked on #9094, which is itself rebased on #9093 (RFC #9026, step after "prepare once, run per step"). Until both merge, only the last four commits belong to this PR:
[checkpoint] Fused region copies for prepared affine transfers[comm] Expose symmetric-memory rendezvous and peer tensors[checkpoint] Copy window shards in place and release staging between runs[checkpoint] Check window copies for aliases and keep 16-byte elements off the tile kernelAs agreed with @0z5a on #9026, the fused copy and the window transport share one PR and one copy-table format.
copy_stays the default everywhere.What changes
Fused copies (opt-in
copier=)prepare_transfers(..., copier=fused_copies)replaces each round's pack, unpack and local-copy lists with a single Triton kernel launch (copy_tiles). The kernel reads a table of addresses, strides and extents for each region.sequential_copies(onecopy_per view) is the default and keeps current behaviour.fused_copiesfalls back tocopy_for views it cannot tile, for elements that are not 1, 2, 4 or 8 bytes (complex128), for host tensors, and when Triton is unavailable._agree. If building it fails, every process refuses the batch.Symmetric-memory window (opt-in
window=)deepspeed.commgainssymm_mem_rendezvousandsymm_mem_peer_tensor, sotorch.distributedstays behinddeepspeed/comm.TransferWindoware copied directly into or out of the peer's window,pullorpush, and skip the staged rounds.TransferStats.mapped_bytesreports how many bytes went through the window.check, a run with window copies starts with a group barrier, so peers never read a shard its owner is still writing.execute_transfer,execute_transfersandprepare_transfers.Staging lifecycle
PreparedTransfer.release_staging()frees the staging arenas, round views and copier tables between runs, for example during training steps.run()re-stages them. Withcheck=True, a failure while re-staging refuses on every process.Why this is not a duplicate
#9094 adds the prepared handle with
copy_only. This PR is the follow-up proposed in #9026 §5: the fused copy, the window transport andrelease_staging(). No other open PR touchesaffine_transfer_executor.pybeyond #9094.Tests
| Platform | Result |
|---|---|
| CPU, gloo (
DS_ACCELERATOR=cpu), current head | 94 passed, 27 skipped (window and Triton tests need a GPU) || 4× Intel Arc Pro B70, xe driver (kernel 6.19.10), torch 2.14.0.dev20260804+xpu, triton 3.8.0 (xpu), xccl, current head | all pass at 2 and 4 processes |
| 4× NVIDIA L20, torch 2.14.1+cu130, NCCL 2.30.7, current head | 125 passed |
New tests:
copy_for every region shape (strided, transposed, misaligned, 0-d, empty);check=True;window=is staged, never sent in place (fails without the fix);Performance
Workload: Qwen3-4B, 398 bf16 tensors. 2-D weights move from a row split to a column split over N processes, and 1-D weights move between shifted even splits. Each cell is the median of 5 warm
PreparedTransfer.run()calls in ms (lower is better);copy_vsfused_copies.8× Arc Pro B70 (cards 8–15, xccl):
| N | staging |
copy_| fused | Δ ||---|---|---|---|---|
| 2 | 8 MiB | 162.6 | 171.6 | +5.5% |
| 2 | 64 MiB | 123.7 | 124.2 | +0.5% |
| 4 | 8 MiB | 164.9 | 165.0 | 0.0% |
| 4 | 64 MiB | 137.6 | 136.7 | −0.7% |
| 8 | 8 MiB | 103.2 | 99.6 | −3.6% |
| 8 | 64 MiB | 109.0 | 104.7 | −4.0% |
4× L20:
| N | staging |
copy_| fused | Δ ||---|---|---|---|---|
| 2 | 64 MiB | 103.5 | 102.1 | −1.4% |
| 4 | 8 MiB | 84.4 | 81.5 | −3.4% |
| 4 | 64 MiB | 86.1 | 80.4 | −6.6% |
prepare_transferswithfused_copiescosts an extra 50–75 ms once, to build the tables and compile the kernel. This is whycopy_stays the default.run()median at 64 MiB staging:| Platform | N | staged | window pull | window push |
|---|---|---|---|---|
| L20 | 4 | 83.6 | 83.8 | 79.2 |
| B70 | 2 | 123.7 | 90.5 | 98.3 |
release_staging()frees all staging buffers between runs. Without it, memory use is the same as #9094.Compatibility
torch.distributed._symmetric_memory.AI assistance was used for this change.