Skip to content

[AffineIR] Analyze affine transfer batches before execution (Plan analysis & calibration Part-1) - #8967

Merged
delock merged 20 commits into
deepspeedai:masterfrom
jinyouzhi:affine-transfer-analysis
Nov 23, 2026
Merged

delock merged 20 commits into
deepspeedai:masterfrom
jinyouzhi:affine-transfer-analysis

Conversation

@jinyouzhi

@jinyouzhi jinyouzhi commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

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.

@jinyouzhi jinyouzhi changed the title Analyze affine transfer batches before execution [AffineIR] Analyze affine transfer batches before execution (Plan analysis & calibration Part-1) Oct 31, 2026

@0z5a 0z5a 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.

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, and build_operations isn'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_bytes in particular isn't covered by the expected_stats comparison, since TransferStats has 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 LOCAL and default_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.

@0z5a

0z5a commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@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 e38477d7 copy this module mirrors, so the report still matches today.

What I have in mind is a public, tensor-free helper in affine_transfer_executor, say schedule_transfers(plans, endpoints, budget, element_size, process=None). For one process, or for all of them, it returns, per peer and direction, the packed rounds with their element counts, whether each round goes direct, and the arena size, plus the local copies. The direct decision needs only geometry: _region is an as_strided view of a contiguous flat shard, so region.is_contiguous() depends only on (chunk_shape, strides), the same rule as your _is_packed. execute_transfers would build its rounds and arenas from that result, and this module could drop _packed_rounds, build_operations and its own direct-send and arena logic, so staging_bytes can't drift from what the executor allocates. That's now #9027, and this one can switch to it once it lands.

Separately, this head is stacked on 17aa897e, before #8966's d00ba303. Once it's rebased, it needs the external-group test fix from my #8966 comment.

@jinyouzhi
jinyouzhi force-pushed the affine-transfer-analysis branch from 8870b61 to 1ac1de1 Compare November 11, 2026 07:11
@jinyouzhi

Copy link
Copy Markdown
Contributor Author

Rebased onto #8966's 57a47ff, which carries the test fix. I'll switch to schedule_transfers and drop the mirrored scheduling once #9027 lands.

@jinyouzhi
jinyouzhi force-pushed the affine-transfer-analysis branch from 1ac1de1 to b97d6af Compare November 11, 2026 10:11
jinyouzhi and others added 10 commits November 11, 2026 18:10
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>
jinyouzhi pushed a commit to jinyouzhi/DeepSpeed that referenced this pull request Nov 13, 2026
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>
@jinyouzhi
jinyouzhi force-pushed the affine-transfer-analysis branch from b97d6af to 1da4d66 Compare November 13, 2026 15:31
@jinyouzhi

Copy link
Copy Markdown
Contributor Author

@0z5a Switched to schedule_transfers (#9027 is merged into this branch until it lands): the module no longer imports _packed_rounds / build_operations or re-derives direct sends and arenas, so staging_bytes is the executor's arena. Reports are identical to the previous version on 300 random batches, except the per-chunk size distribution, which the schedule doesn't carry (the chunk count stays). The summary now records process_numbering, and the docs say to calibrate on the transfer's group. Since #8966 is close, I kept LOCAL / default_path_of there rather than moving them. Tests: 72 pass on 4×H20.

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>
@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 14, 2026
banxingmjj pushed a commit to openanolis/DeepSpeed that referenced this pull request Nov 15, 2026
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>
@jinyouzhi
jinyouzhi force-pushed the affine-transfer-analysis branch from 1da4d66 to 1dfbbc4 Compare November 16, 2026 09:16
@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 16, 2026
@jinyouzhi
jinyouzhi marked this pull request as ready for review November 18, 2026 04:11
@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 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 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-18T04:16:05.589417Z 9ede0b1 Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@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 18, 2026
@jinyouzhi

Copy link
Copy Markdown
Contributor Author

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>
@delock
delock self-requested a review November 18, 2026 15:05
jinyouzhi and others added 2 commits November 18, 2026 15:13
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>
@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 22, 2026
@delock

delock commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Nice work on the dry-run analysis — reading the schedule from schedule_transfers instead of re-deriving it makes the executor/analysis contract easy to trust, and the expected_stats-vs-TransferStats test is exactly the right anchor.

One request before approval, about the local_copy_bytes contract:

analyze_transfers's docstring says the counts "match what each process will return in TransferStats", and expected_stats is positioned as the checkable prediction. That holds for segments, chunks, rounds, sent_bytes and received_bytes, but local_copy_bytes has a known divergence: schedule_transfers counts every local copy, including the ones execute_transfers drops as in place (source and target the same memory at the same strides), while TransferStats.local_copy_bytes does not count those (noted in schedule_transfers's own docstring). On a batch containing an in-place copy, expected_stats(report, p)['local_copy_bytes'] will therefore exceed the actual TransferStats value, and nothing in this module or the docs tells the caller that.

The 4-rank comparison test avoids such batches, so the blind spot is currently untested as well. Could you add a sentence to the analyze_transfers (and/or expected_stats) docstring — and ideally a line in affine-transfer.rst — stating that local-copy figures count copies the executor may drop as in place, so a mismatch on that field after a run points at this known difference rather than a prediction bug? A follow-up test asserting the known delta on an in-place batch would be welcome but is optional for me.

I'll approve once the docstring lands.

@jinyouzhi

jinyouzhi commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @delock for reviewing, great suggestion, added in 46d7543:

  • analyze_transfers and expected_stats docstrings, and affine-transfer.rst: local_copy_bytes is an upper bound, since the analysis also counts local copies that execute_transfers drops as in place. A smaller value after a run is this known difference, not a prediction error. The other fields are exact.
  • A 2-rank test with one in-place and one copied local copy: the predicted local_copy_bytes exceeds TransferStats by exactly the in-place bytes, and every other field matches.

Making the field exact (passing buffers or the in-place copies to the analysis) is listed as a follow-up in the PR description.

@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 22, 2026
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
@delock
delock enabled auto-merge November 23, 2026 03:00
@delock
delock added this pull request to the merge queue Nov 23, 2026
Merged via the queue into deepspeedai:master with commit 9d53dfb Nov 23, 2026
19 checks passed
banxingmjj pushed a commit to openanolis/DeepSpeed that referenced this pull request Nov 23, 2026
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>
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.

4 participants