[checkpoint] Execute affine transfer plans with bounded peer staging (#8809)
The merged #8623 planner describes affine shard copies. This PR executes
those plans directly into existing frozen target shards with bounded
peer staging, without reconstructing the full logical tensor.
Refs #8230, #8252 and 0z5a/DeepSpeed#1. This is the executor portion of
that work; #8800 supplies live AutoEP metadata separately. The diff is
limited to **4 files, 1014 added lines**: executor, contract tests, a
new API documentation page and its toctree entry. Historical benchmark
drivers and evidence remain in the fork and are linked below.
`execute_transfer` / `execute_transfers` accept explicit source and
target rank bindings, preserve strided regions and storage offsets, and
collectively reject invalid buffers, aliases or request-order
disagreement before writes. Shared plans reuse their schedule within a
call. On accelerators that are not synchronized with the host
(`is_synchronized_device()` is false), work handles order the caller
stream and drain every 32 rounds and before return; on synchronized
devices such as CPU each handle is waited immediately.
Review fixes, first round: valid scalar plans now execute; the unrelated
`new_group(timeout=...)` changes are removed, preserving the existing
CCL interface.
Review fixes, second round: stream ordering is gated on
`is_synchronized_device()` rather than the device type; the multi-rank
tests are no longer confined to CUDA and rely on the harness's
device-count gate before launch; the disjoint-endpoint case uses 2 or 4
ranks so it fits the two-GPU PR runners and the four-rank CPU nightly;
the documentation moved from the AutoEP page to an *Affine Shard
Transfers* page under Checkpointing API, and records that the staging
arena and `StagingBudget` belong to the current torch point-to-point
transport.
Validation on this exact executor and test source:
| Run | Result |
|---|---|
| macOS arm64, Python 3.12.13, Torch 2.14.1, CPU/gloo, `LOCAL_SIZE=4
DS_MULTIRANK_ONLY=1 DS_DISABLE_REUSE_DIST_ENV=1 --forked`, on current
master | 11 multi-rank cases selected, 11 passed |
| Same, `LOCAL_SIZE=2 DS_DISABLE_REUSE_DIST_ENV=1 --forked` | 48 passed,
the 4-rank case skipped before launch |
| Same, no `LOCAL_SIZE`, `--forked` | 38 passed, 11 multi-rank cases
skipped before launch |
| CPU planner and shard-map regression | 178 passed on this branch's
base, 186 on current master |
| Linux, 2 H100, Python 3.12.1, Torch 2.12.1+cu130, CUDA 13.0, driver
595.91.07, previous head 4a4bee9 | 47 passed, 1 eight-device case
skipped before launch |
| Changed-file pre-commit | All applicable hooks passed |
The second review round was not rerun on GPU: on CUDA the capability
predicate selects the same branches as the device-type check it
replaces, so the H100 row still describes the executor code, but the
reshaped disjoint-endpoint test has run only on CPU.
```bash
cd tests
LOCAL_SIZE=4 DS_MULTIRANK_ONLY=1 DS_DISABLE_REUSE_DIST_ENV=1 DS_ACCELERATOR=cpu PYTHONPATH=.. python -m pytest --forked unit/checkpoint/test_affine_transfer_executor.py -q
LOCAL_SIZE=2 DS_DISABLE_REUSE_DIST_ENV=1 DS_ACCELERATOR=cpu PYTHONPATH=.. python -m pytest --forked unit/checkpoint/test_affine_transfer_executor.py -q
DS_ACCELERATOR=cpu PYTHONPATH=.. python -m pytest --forked unit/checkpoint/test_affine_transfer_executor.py -q
cd ..
DS_ACCELERATOR=cpu PYTHONPATH=tests python -m pytest tests/unit/checkpoint/test_affine_transfer_plan.py tests/unit/checkpoint/test_affine_shard_map.py -q
PYTHONPATH=tests python -m pytest --forked tests/unit/checkpoint/test_affine_transfer_executor.py -q
pre-commit run --files deepspeed/checkpoint/affine_transfer_executor.py tests/unit/checkpoint/test_affine_transfer_executor.py docs/code-docs/source/affine-transfer.rst docs/code-docs/source/index.rst
```
On the same two H100s, restoring the original scalar predicate causes
all four scalar regressions (single/batched, local/cross-process) to
fail with the dimension-rejection defect. The fixed full file passes,
including FP32/FP16/BF16 transfer, mixed storage windows, collective
refusal, request ordering and a shared-plan batch spanning 48 rounds.
The final pytest run exits zero and the assigned GPU contexts are gone.
Startup/resource failures are retained separately.
[Historical eight-H100 non-scalar correctness
evidence](https://github.com/0z5a/DeepSpeed/blob/3cdc69ae1c4de9ebed8bfe57d02c2640785a5af2/tests/distributed/checkpoint/evidence/affine_handoff_gpu8_wait32_20261011.json)
records 304 BF16/FP32 checks plus mixed-layout and shared-plan checks.
[Historical paired
performance](https://github.com/0z5a/DeepSpeed/blob/3cdc69ae1c4de9ebed8bfe57d02c2640785a5af2/tests/distributed/checkpoint/evidence/affine_handoff_gpu8_wait32_performance_20261012.json)
reports 1.289x geometric speedup, 95% CI [1.2703, 1.3080], for a 1-GiB
synthetic frozen-weight handoff. These are prior non-scalar runs, not a
new eight-GPU qualification of this rebased and reduced branch or a
full-model performance claim.
Scope: scale-1 plans and frozen packed weights. No optimizer migration,
live AutoEP swap, CPU/NVMe offload integration, training
convergence/resumption, serving or non-CUDA accelerator qualification.
CPU/gloo runs the contract tests only; `Work.block_current_stream()`
orders the device stream on NCCL and XCCL, while other non-synchronized
backends that do not override it are untested. The staging budget
applies per peer direction; a payload-time transport failure may
partially modify targets. Maintenance contact: @0z5a.
AI assistance was used to prepare this change, its tests and this
description. I reviewed every changed line and ran the tests listed
above.
---------
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>