Repository navigation
[AffineIR] Analyze affine transfer batches before execution (Plan analysis & calibration Part-1) - #8967
Conversation
0z5a
left a comment
There was a problem hiding this comment.
Read the last commit (72081c1b). The report is what a policy or cost model needs: per-process sent and received bytes, rounds and messages give the bandwidth and per-message terms, and expected_stats matching the executor's TransferStats on 4 ranks is a good anchor. It passes on CPU (gloo, 4 ranks) here.
I checked the schedule reconstruction against the executor at e38477d7. The direct-send test (_is_packed versus region.is_contiguous()), the per-peer, per-direction arena sized by the largest staged round, and rounds as the maximum over a process's peer queues all match today. Two structural suggestions:
- Share the schedule instead of re-deriving it. The module imports the executor's private
_packed_rounds, andbuild_operationsisn't in its__all__either. It then re-implements the direct-versus-staged decision and the arena sizing. Those will drift when the executor's staging changes.staging_bytesin particular isn't covered by theexpected_statscomparison, sinceTransferStatshas no staging field. Would a public schedule helper in the executor work for you, returning each peer's rounds and whether each round is sent directly? Both sides could then call it. - Ordering. This stacks on #8966 only for
LOCALanddefault_path_of. Defining those here, or in a small shared module that calibration imports, would let this land first.
Minor: the report numbers processes by transport-group rank, while calibration uses default-group ranks, so the path labels join only when the two groups coincide. The docstring says so, but recording that assumption in the report itself would stop a consumer from mixing the two.
72081c1 to
8870b61
Compare
|
@jinyouzhi on the schedule question: yes, I'd rather the executor own it, and I can add it. #8809 is in master now, and the executor is unchanged from the What I have in mind is a public, tensor-free helper in Separately, this head is stacked on |
8870b61 to
1ac1de1
Compare
1ac1de1 to
b97d6af
Compare
Add calibrate_links/fit_links: raw local, pairwise, concurrent, 1-to-N and N-to-1 timings labelled by a path_of(from, to) hook, with a per-path alpha + bytes/bandwidth summary, as measured inputs for transfer cost models. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com> (cherry picked from commit 3cfa415)
…ive capacity Signed-off-by: Achyuthan Sivasankar <achyuthan.sivasankar@gmail.com> (cherry picked from commit dc1722e)
…ode-capped default - fit_links keys fan_out, fan_in, send and receive by (root, sorted peers), so fans of one width with different senders stay apart; the width is len(peers). Adds peer_pairs, a fit per ordered (from, to) pair. - calibrate_links takes fan_peers(root, width) to choose the peers, and an optional group whose ranks number the processes. - The default fan width is one less than the fewest processes on any node, and default peers are on the root's node first. - Docs state that width-keyed fits assume a uniform fabric, with B70 data. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com> (cherry picked from commit ba8b39f)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com> (cherry picked from commit f00ce17)
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com> (cherry picked from commit 2c43824)
… a path A concurrent sample times a process's send to process + shift and its receive from process - shift together, but was labelled by the send path alone. Across nodes, an intra-node send paired with an inter-node receive takes the inter-node time, so the intra_node concurrent fit came out at 7.5 GB/s over TCP against 65 GB/s for clean intra-node processes on 2x8 H20. Record receive_paths and fit each path only from processes whose send and receive both took it. Document calibrating on the group and settings the transfer uses. Signed-off-by: iLeGend <824040212@qq.com> (cherry picked from commit 575bef3)
Weight transfers are one-way: a training process sends and a rollout process receives, so no process sends and receives at once. The concurrent shift pattern timed every process doing both, which matches no transfer, and needed per-direction path filtering to fit at all. Remove it with its fit, docs and tests, and drop the hardware-specific measurements from the docs. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com> (cherry picked from commit 17aa897)
Some transfers have a process send and receive at the same time: colocated resharding, the all-gather stage of a relay, a pipelined relay, and moves between trainers of different DP sizes. peer samples gain both_ways. A two-way sample has a pair send to each other at once, with every other process idle, and gives one sample per direction labeled with that direction's path. fit_links keeps peer and peer_pairs one-way and adds peer_both_ways and peer_both_ways_pairs, so a policy can see what a link loses per direction when both directions are busy. The shift pattern returns as relay: every process receives from process - shift while sending to process + shift. Each sample is one process's own time, labeled with who it received from and sent to and with both the receive_path and the send_path, since that time covers both. fit_links fits relay per (receive_path, send_path), so no sample is filed under a path it only half used. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com> (cherry picked from commit d00ba30)
Both directions of a both_ways sample carry the pair's completion time, so peer_both_ways_pairs[(a, b)] equals peer_both_ways_pairs[(b, a)]. Say so in fit_links and the docs, and compare against the slower of the two one-way fits. Keep the external-group executor test's assertion to one-way peer samples, since calibrate_links now also returns both_ways samples. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com> (cherry picked from commit 57a47ff)
A path_of that tells local devices apart, as on a host with unlike accelerators, had every local copy labeled 'local' and pooled into one fit. Local samples now carry path_of(process, process) like every other sample. communication_backend recorded the accelerator's preferred backend, which need not be the one the measured group runs on. It now comes from the group itself, through a new deepspeed.comm.get_backend that wraps the backend's existing get_backend. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Add schedule_transfers, which returns what execute_transfers would run for a batch without buffers or communication: for each process, the rounds per peer and direction with their element and chunk counts and whether each is sent or received in place, the staging arena each peer direction allocates, the local copies, and the round count TransferStats reports. A replica policy or cost model can then price a plan before running it, without importing the executor's private helpers (deepspeedai#8967 asked for this). execute_transfers now builds its rounds and arenas from the same private computation, so the two cannot drift apart. The in-place decision is made from geometry, not from the buffer: _region is an as_strided view of a packed shard, so the view is contiguous exactly when (chunk_shape, strides) is row-major packed, extent-1 axes excepted. plan_digest, the batch fingerprint and TransferStats are unchanged, and build_operations and _packed_rounds keep their names and signatures. Tests: test_schedule_is_what_the_executor_runs (2 and 4 ranks, mixed packed and strided regions, 16-element messages) checks rounds, sent, received and local copy bytes against the executor's TransferStats, that both sides of every message agree, the arena sizes, and that the batch exercises both the in-place and the staged path. test_packed_regions_are_exactly_the_contiguous_views compares the geometric rule with Tensor.is_contiguous over 2000 random shapes and strides. A single-process case covers local-only batches and the argument checks. Forcing every round to staged, or dropping the extent-1 exception, fails these tests. On macOS arm64 CPU (Python 3.12, torch 2.15.0), the executor, external-group, planner and shard-map suites pass (263). All affine checkpoint tests pass except the four TestAffineUniversalCheckpointResume cases, which fail the same way on master here (uninstalled package version). pre-commit (yapf, flake8, codespell, license) is clean. Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
b97d6af to
1da4d66
Compare
|
@0z5a Switched to |
fit_links reads peer samples' both_ways and the raw relay list. A raw calibration saved before those existed still claimed schema 1, so it passed the schema check and then raised KeyError. Schema 2 makes fit_links refuse it with a clear error instead. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
deepspeedai#9027) ## Why A replica policy (deepspeedai#8936) or cost model (deepspeedai#8252) needs to know what a batch will cost before running it: messages per peer, rounds, and staging memory. deepspeedai#8967 builds that report today by importing the executor's private `_packed_rounds` and `build_operations`. It then re-derives the in-place decision and the arena sizing, so its numbers would drift silently whenever the executor's staging changes. It asked for a public API instead. ## What `schedule_transfers(plans, endpoints, budget, element_size, process=None)` in `affine_transfer_executor` returns, for one process or for every process the endpoints name, the `ProcessSchedule` that `execute_transfers` would run. It uses no buffers and no communication: - the rounds per peer and direction (`ScheduledRound`: elements, chunks, and whether the round is sent or received in place); - the staging arena each peer direction allocates; - the local copies; - the round count that `TransferStats.rounds` reports. `execute_transfers` now builds its rounds and arenas from the same private computation, so the report and the run cannot disagree. The in-place decision is made from geometry rather than from the buffer. `_region` is an `as_strided` view of a packed shard, so it is contiguous exactly when `(chunk_shape, strides)` is row-major packed, ignoring extent-1 axes. Unchanged: - `plan_digest`, the batch fingerprint and `TransferStats`, so mixed versions still agree on the schedule; - `build_operations` and `_packed_rounds`, which keep their names and signatures until deepspeedai#8967 switches. ## Tests - `test_schedule_is_what_the_executor_runs` (2 and 4 ranks; mixed packed and strided regions with 16-element messages) checks: - rounds, sent, received and local-copy bytes against the executor's `TransferStats`; - that both sides of every message agree; - the arena sizes; - that the batch exercises both the in-place and the staged path. - `test_packed_regions_are_exactly_the_contiguous_views` compares the geometric rule with `Tensor.is_contiguous` over 2000 random shapes and strides, including extent-1 axes. - A single-process case covers local-only batches and the argument checks. - Forcing every round to be staged, or dropping the extent-1 exception, makes these tests fail. On macOS arm64 CPU (Python 3.12, torch 2.15.0): - The executor, external-group, planner and shard-map suites pass (263). - All other affine checkpoint tests pass, except the four `TestAffineUniversalCheckpointResume` cases, which fail the same way on master in this environment (uninstalled package version). - With deepspeedai#8967 merged on top, its analysis tests pass unchanged (59 together with the executor suite). - pre-commit is clean. This merges cleanly with deepspeedai#8936, deepspeedai#9010 and deepspeedai#9011. With deepspeedai#8966 and deepspeedai#8967 the only conflict is that both append a section to `affine-transfer.rst`. --------- Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de> Co-authored-by: Ma, Guokai <guokai.ma@gmail.com>
1da4d66 to
1dfbbc4
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ede0b1a16
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
|
Ready to review @delock Thanks! |
The path summary filed every local copy under 'local'. Record path_of(process, process) per process, as calibrate_links does, so the totals join with fit_links results for a custom classifier. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Assert that both sides of a pair schedule the same rounds, note which expected_stats fields are batch-wide, require element_size to match the executed dtype, and give an empty distribution the same keys. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
|
Nice work on the dry-run analysis — reading the schedule from One request before approval, about the
The 4-rank comparison test avoids such batches, so the blind spot is currently untested as well. Could you add a sentence to the I'll approve once the docstring lands. |
|
Thanks @delock for reviewing, great suggestion, added in 46d7543:
Making the field exact (passing buffers or the in-place copies to the analysis) is listed as a follow-up in the PR description. |
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
deepspeedai#9145) Refs deepspeedai#9026 (the cost model), deepspeedai#8252, deepspeedai#8935. ### Why Plans that move the same data can differ in time by several times. Which holder each target reads and the staging budget are free choices, and the planner guarantees an exact result whichever is picked. In the runs below, the default (the planner's first holder, the larger budget) is up to 76% slower than the fastest candidate. A replica policy (deepspeedai#8935, deepspeedai#8936), a two-stage relay (deepspeedai#9074) or a weight sync (deepspeedai#9045) needs a way to compare candidates before running one. deepspeedai#8967 reports what a batch moves and states that it does not model time; deepspeedai#8966 measures link rates. This adds the step between them: a time estimate per candidate, and the choice. ### What `deepspeed/checkpoint/affine_transfer_cost.py`, which is not imported by `import deepspeed`: - `TransferCostModel(route, capacity, seconds_per_call, seconds_per_round, seconds_per_region)`: one machine's calibrated costs. `route(sender, receiver)` names the resources a message occupies; `capacity` gives bytes per second per resource kind. Capacities must be positive and finite, and the costs non-negative and finite. - `node_route(nodes, intra_node)`: across nodes, the sender's `network_send` and the receiver's `network_receive`; within a node, each GPU's own link (`device_send`, `device_receive`, as on NVSwitch) or the link between the two GPUs (`device_pair`, NVLink). - `estimate_seconds(stages, model)`: each stage is one `execute_transfers` call, and stages run one after another. A call's rounds come from `schedule_transfers`, so the estimate prices the rounds that `execute_transfers` will run. A round takes its most loaded resource's bytes over that resource's capacity, plus `seconds_per_round`. Copy launches, `seconds_per_region` for each staged or local region of the busiest process, overlap the bytes, so a call takes `seconds_per_call + max(rounds, launches)`. Rounds sent or received in place launch no copy. - `cheapest(candidates, model)`: estimates every candidate and returns the cheapest name with every estimate. A tie goes to the name that sorts first, so ranks given the same model and candidates choose the same plan. The model must be built from data every rank shares. - A section in `affine-transfer.rst`. Not priced: a plan's one-time preparation (deepspeedai#9094), and overlap between stages. ### Tests `tests/unit/checkpoint/test_affine_transfer_cost.py`, single process. Each expected time is computed in the test from the bytes and the given capacities: - A round takes its busiest resource, whether the sender's or the receivers' side binds. - Two resources in one round bind on their own (the mixed incast of RFC deepspeedai#9026). - Copy launches overlap the bytes; local copies count as regions; rounds sent and received in place do not. - The GH200 capacities of RFC deepspeedai#9026 give its model rows for direct (4 × 8 GiB / 68.4 GB/s) and sharded (8 GiB / 23.4 GB/s), and the relay through deepspeedai#8936's `local_first_least_loaded` is chosen. - A tie goes to the first name. - Refusals: a routed resource with no capacity, a process with no node, a zero capacity, an unknown intra-node kind, no candidates. Each of these changes to the module makes at least one test fail: adding the resources instead of taking the busiest (3 fail), adding launches to the bytes (1), counting in-place rounds as regions (1), counting each message on both sides (2), dropping `seconds_per_round` (1), and breaking ties toward the last name (1). ### Validation macOS arm64 CPU, Python 3.9.6, torch 2.8.0, on master c00a7f6: the 6 tests pass; yapf 0.43.0 and flake8 5.0.4 pass on the new files. On GPU, with this exact module file on master e35282b: 4 GPUs of an 8-GPU node, on two machines, driver 595.71.05, torch 2.12.1+cu130, NCCL 2.29.7: - 4× A100-SXM4-40GB (NV12), AMD EPYC 7763; - 4× H200 (NV18), Intel Xeon Platinum 8558. On each, the 6 tests pass. Then a ranking test: 5 moves, each run as 2 to 4 candidate plans that deliver the same bf16 data and differ only in the holders read or the staging budget (16 plans). Each plan's time is the median of 7 runs after 3 warmups, from a barrier to the end of the call, slowest process. The first run of every plan was checked exact against the maps. The model was fitted on each machine from 8 calibration transfers only: one pair at 64 MiB, 256 MiB and 1 GiB in one round and 1 GiB at 64 and 8 MiB budgets, a 1 GiB fan-out to three, a fan-in of three times 1 GiB, and a gather of 2048 pieces of 4 KiB. The candidates were fixed, and their times kept out of view, until the fit was done. Regret is the chosen plan's time over the fastest measured: | Move | Candidates | A100: model | A100: default | H200: model | H200: default | | --- | --- | --- | --- | --- | --- | | 1 GiB held on 2 GPUs, into row halves on the other 2 | first holder or one each, 16/64 MiB budget | 0% | 56.7% | 0% | 38.6% | | DP2 × TP2 into TP4 (1 GiB) | first holder, local, local then the other | 0.3% | 4.1% | 1.4% | 5.1% | | Ring of 512 MiB blocks | budget 8/16/32/64 MiB | 0% | 0% | 0% | 0% | | Rows to columns over 4 GPUs | budget 4/16/32 MiB | 0% | 0% | 0% | 0% | | 16 weights of 64 MiB held on 2 GPUs, into row quarters on 4 | first holder or split | 0% | 76.4% | 0% | 76.3% | The estimates rank plans; they are not times. Against the measured times of these 16 plans they range from 62% under to 15% over on the A100 node (5 of 16 within 15%), and from 57% under to 5% under on the H200 node (3 of 16). Rerunning the scoring with the module on master c00a7f6 gives byte-identical output on both machines. Not validated: - Across nodes: the `network_send` and `network_receive` terms are checked only against the published GH200 numbers in the unit test; no multi-node run here. - Other accelerators: the module is pure Python over `schedule_transfers` and calls no device or collective, but it was calibrated only on these two NVIDIA machines. - Turning `calibrate_links` (deepspeedai#8966) fits into these capacities is left to the caller. The module does not change any training, checkpoint or ZeRO code path, so no ZeRO stage, offload, precision or parallelism setting is affected. Signed-off-by: Achyuthan Sivasankar <achyuthan.sivasankar@gmail.com> Co-authored-by: Ma, Guokai <guokai.ma@gmail.com>
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
StagingBudgetdominates 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 publicschedule_transfers, so it reports whatexecute_transferswill run:expected_stats(report, process)predicts that process'sTransferStats.report_to_dictreturns a JSON-ready summary.path_oflabels ascalibrate_links, so per-path totals can be priced withfit_links.It does not choose replicas, rank plans, or model time.
Tests
expected_stats== the executor'sTransferStats, for a strided and a replicated parameter under budgets of 3 and 64 elements.local_copy_bytesexceeds the executor's by exactly the in-place bytes, and every other field matches.Results:
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 thatexecute_transfersdrops as in place (source and target the same memory at the same strides);TransferStats.local_copy_bytesdoes not. The docstrings andaffine-transfer.rststate 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 toanalyze_transfers. That is left for a follow-up.