Repository navigation
Price affine transfer plans from their schedule, and keep the cheapest - #9145
Queued
Achyuthan-S wants to merge 2 commits into
Queued
Achyuthan-S wants to merge 2 commits into
Achyuthan-S wants to merge 2 commits into
Conversation
Plans that move the same data can differ several-fold in time, depending on which holder each target reads and on the staging budget. affine_transfer_cost estimates a sequence of execute_transfers calls from schedule_transfers and a per-machine model (resource capacities, and costs per call, per round and per staged region), and cheapest() picks among candidate plans so that every rank given the same inputs picks the same one. Nothing calls it by default. Signed-off-by: Achyuthan Sivasankar <achyuthan.sivasankar@gmail.com>
Achyuthan-S
requested review from
loadams,
tjruwase and
tohtana
as code owners
November 22, 2026 05:52
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. |
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
7 tasks
delock
self-requested a review
November 23, 2026 03:02
delock
approved these changes
Nov 23, 2026
delock
enabled auto-merge
November 23, 2026 08:17
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #9026 (the cost model), #8252, #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 (#8935, #8936), a two-stage relay (#9074) or a weight sync (#9045) needs a way to compare candidates before running one. #8967 reports what a batch moves and states that it does not model time; #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 byimport 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;capacitygives 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'snetwork_sendand the receiver'snetwork_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 oneexecute_transferscall, and stages run one after another. A call's rounds come fromschedule_transfers, so the estimate prices the rounds thatexecute_transferswill run. A round takes its most loaded resource's bytes over that resource's capacity, plusseconds_per_round. Copy launches,seconds_per_regionfor each staged or local region of the busiest process, overlap the bytes, so a call takesseconds_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.affine-transfer.rst.Not priced: a plan's one-time preparation (#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:local_first_least_loadedis chosen.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:
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:
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:
network_sendandnetwork_receiveterms are checked only against the published GH200 numbers in the unit test; no multi-node run here.schedule_transfersand calls no device or collective, but it was calibrated only on these two NVIDIA machines.calibrate_links([AffineIR] Calibrate affine transfer links per path (Plan analysis & calibration Part-2) #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.