Skip to content

Price affine transfer plans from their schedule, and keep the cheapest - #9145

Merged
delock merged 2 commits into
deepspeedai:masterfrom
Achyuthan-S:affine-transfer-cost
Nov 23, 2026
Merged

delock merged 2 commits into
deepspeedai:masterfrom
Achyuthan-S:affine-transfer-cost

Conversation

@Achyuthan-S

Copy link
Copy Markdown
Contributor

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 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 (#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:

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 ([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.

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>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 05:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T05:56:58.463121Z dd88aff PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 22, 2026
@delock
delock self-requested a review November 23, 2026 03:02
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. and removed skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. labels Nov 23, 2026
@delock
delock enabled auto-merge November 23, 2026 08:17
@delock
delock added this pull request to the merge queue Nov 23, 2026
Merged via the queue into deepspeedai:master with commit 9913758 Nov 23, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants