Describe a parameter held in several layouts as one affine map #9052
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #9052"
general
weight: 0.35
jinyouzhi
Refs #9026 (open question 8), #9045.
Why
A rollout replica that changes placement can often keep a tensor-parallel shard that is still current, while the trainer's ZeRO-3 partitions hold the whole parameter.
plan_transfercan read a block from any of its holders only if the source map's blocks are equal or disjoint and each block lists every holder. A map that simply lists both layouts' pieces breaks both rules, since a partition can start or end inside a row of the shard. So today the planner refuses it, and #9045 falls back to its own planner for these weights.What
union_affine_maps(maps)indeepspeed/checkpoint/affine.pyreturns one map of a parameter that several layouts hold at once.- Each piece is cut at the edges of every block held over it, in any layout (replicas within one layout may store a region whole or in parts), and each cut piece lists the holders from every layout.
- A cut keeps the piece's strides and moves its offsets, so every location still stores exactly what it did.
- Layouts use disjoint locations, one per buffer.
TransferEndpointsalready lets several locations map to one process.- More than two layouts are merged pairwise.
- Blocks are taken in order of their first row, and each is compared only with the parts that still reach into its rows; a piece is cut against only the parts that start in its rows. That keeps the work close to linear in the number of partitions (see Cost).
- Layouts that contradict each other raise
InvalidMapError, and a piece that is not an axis-aligned block raisesUnsupportedLayoutError: the planner's types for the same problems, so a caller that falls back onAffineTransferErrorcatches these too.subtractmoves unchanged fromaffine_transfer._subtractintoaffine_geometry, the module #9010 added for shared box arithmetic. The planner imports it under its old name.affine-transfer.rst, after the replica-policy section from #8936.Scope
Cuts along rows and along columns are both planned. A ZeRO-3 block of several rows cut at a column edge keeps its row-major strides and its partition's offset, so it is not dense in its flat shard; the planner reads such shards since @0z5a's #9070.
Cost
@jinyouzhi measured the first version growing with the square of the number of ZeRO-3 partitions.
union_affine_mapson a (4096, 4096) parameter's ZeRO-3 partitions plus another layout, macOS arm64 CPU (before = the previous version):| Other layout | 200 partitions | 1000 partitions |
| --- | --- | --- |
| 8-way row split | 1.93 s → 0.03 s | 48.0 s → 0.18 s |
| 8-way column split | 11.0 s → 0.26 s | 1.3 s (34k pieces) |
| whole replica | 1.91 s → 0.03 s | 0.18 s |
A column split is the slowest case left, because each of its blocks spans every row.
A union is cut at every layout's edges, so it can exceed the default
PlanBudget(4,096 pieces per map).plan_transferon the same unions, into a row-split and a column-split TP8 target (the same for both unless noted):| Partitions + other layout | Pieces | Default
PlanBudget()|max_pieces_per_map=1 << 16|| --- | --- | --- | --- |
| 200 + 8-way row | 1,196 | planned | planned |
| 200 + 8-way column | 6,782 | refused (pieces) | planned |
| 1000 + 8-way row | 5,996 | refused (pieces) | planned |
| 1000 + 8-way column | 33,976 | refused (pieces) | into rows: planned (2.3 s); into columns: refused at
max_merge_checks(262,144), planned (3.5 s) withmax_merge_checksandmax_pair_checksraised as well |The docs now show the budget next to the call (thanks @delock).
Tests
test_affine_transfer_plan.py:- each element's holders are exactly the union of both layouts' holders;
- every location extracts what its own layout says;
- every plan reproduces
extractexactly;- the surviving shard is read.
test_affine_transfer_executor.py: on 2 ranks, one process holds a ZeRO-3 partition and a surviving row shard under two locations. The plan runs throughexecute_transfer, and every target shard equalsextract.Not merging the holders, dropping the part of a block that a later block doesn't overlap, or leaving the destination offset unmoved makes 9 of these 11 tests fail. Setting a part aside one row too early, or ending the search for the parts under a piece one row short, makes 6 and 7 of them fail.
Validation
The fifth commit changes only the spec and
affine-transfer.rst: the column cut is planned since #9070, and the example passes aPlanBudgetsized for a union.Rebased on master c00a7f68c, after #9070 and #9093 merged. The only conflict was in
test_affine_transfer_executor.py, where this PR and #9093 added test classes at the same place; both are kept. The three earlier commits are otherwise unchanged (git range-diff), and a fourth extends the column-cut test to plan. macOS arm64 CPU, Python 3.9.6, torch 2.8.0, gloo (DS_ACCELERATOR=cpu LOCAL_SIZE=4):On GPU: 4× A100-SXM4-40GB (NVLink), driver 595.71.05, torch 2.12.1+cu130, NCCL 2.29.7, Python 3.12.11, with
pytest --forkedover the sixtest_affine_*.pyfiles andtest_zero_affine.py: this branch 905 passed and 1 skipped (master c00a7f68c: 894 passed and 1 skipped), so the 11 new tests also pass over NCCL.Earlier, rebased on master 97aa3c10d, after #9039 renamed the geometry imports. The only conflicts were those imports and
affine_geometry.__all__;subtractnow sits with master's unaliased imports. macOS arm64 CPU, Python 3.9.6, torch 2.8.0, gloo (DS_ACCELERATOR=cpu LOCAL_SIZE=4):The runs below are from before that rebase and the cost change.
Earlier, rebased on master 892ed83e4, which includes #9011. The code and test changes are the same as before the rebase; the only conflicts were additions next to #9011's (
subtractnext toboxes_disjointinaffine_geometry.py, and the imports). macOS arm64 CPU, Python 3.9.6, torch 2.8.0, gloo (DS_ACCELERATOR=cpu LOCAL_SIZE=4):On master 988b2e319, before that rebase (with #9010 and #8936):
test_affine_replica_policy.py: 412 passed.plan_transferswithlocal_first_least_loadedand withfirst_holderinto both targets: all 16 plans reproduceextractexactly.Before the rebase, on f9fe4df34 with #9010 applied:
- holders and map-level exactness hold in every case;
- cuts along rows: 137 of 137 planned and exact;
- cuts along columns: 79 planned and exact, and 84 refused by the current planner.
On GPU, also before the rebase: 4× A100-SXM4-40GB (NVLink), driver 595.71.05, torch 2.12.1+cu130, NCCL 2.29.7, Python 3.12.11, with
pytest --forkedover six of the affine test files (all buttest_autoep_affine_universal.py):cc @0z5a @LiRunGuo @jinyouzhi