[AffineIR] Analyze affine transfer batches before execution (Plan analysis & calibration Part-1) (#8967)
## Analyze affine transfer batches before execution
Builds on #8809 (executor) and #8966 (calibration path labels), both
merged.
### Why
Plans that move the same bytes can differ a lot in time (up to 1.75× on
8× B70 between replica choices), and executor measurements show that the
round count under a `StagingBudget` dominates sync time. A policy
(#8935/#8936) or cost model (#8252) needs these facts before it runs a
plan.
### What
`deepspeed/checkpoint/affine_transfer_analysis.py`:
- `analyze_transfers(plans, endpoints, element_size, budget, path_of)`
is a pure function with no communication. It reads the schedule from the
executor's public `schedule_transfers`, so it reports what
`execute_transfers` will run:
- volume;
- segment, chunk and message size distributions;
- rounds;
- per process: sent/received bytes, peers, messages, pack/unpack bytes,
staging arena;
- per-pair and per-path bytes.
- `expected_stats(report, process)` predicts that process's
`TransferStats`.
- `report_to_dict` returns a JSON-ready summary.
- Messages use the same `path_of` labels as `calibrate_links`, so
per-path totals can be priced with `fit_links`.
It does not choose replicas, rank plans, or model time.
### Tests
- Hand-counted rounds and bytes on an uneven handoff.
- Staging of strided sources.
- A batch with a shared plan.
- Path and pair labels in the JSON summary.
- 4 ranks: `expected_stats` == the executor's `TransferStats`, for a
strided and a replicated parameter under budgets of 3 and 64 elements.
- 2 ranks: on a batch with an in-place local copy, the predicted
`local_copy_bytes` exceeds the executor's by exactly the in-place bytes,
and every other field matches.
Results:
- CPU (gloo): 7 passed; the two 4-rank tests need four devices and are
skipped.
- 4× Intel Arc Pro B70 (xccl): the 2-rank and 4-rank tests pass.
- 4× L20 (nccl): all passed before the in-place test was added; not
re-run since.
Mutation checks (dropping the receiver's round count, or the local bytes
in the path summary) are caught.
### Follow-up
- `expected_stats(...)['local_copy_bytes']` is an upper bound. The
analysis sees no buffers, so it also counts local copies that
`execute_transfers` drops as in place (source and target the same memory
at the same strides); `TransferStats.local_copy_bytes` does not. The
docstrings and `affine-transfer.rst` state this, and the 2-rank test
pins the difference. Making this field exact would need the analysis to
know which copies are in place, for example by passing the buffers or
the in-place copies to `analyze_transfers`. That is left for a
follow-up.
---------
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Signed-off-by: Achyuthan Sivasankar <achyuthan.sivasankar@gmail.com>
Signed-off-by: iLeGend <824040212@qq.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Achyuthan Sivasankar <achyuthan.sivasankar@gmail.com>
Co-authored-by: Ma, Guokai <guokai.ma@gmail.com>