Repository navigation
Conversation
Expose the affine maps of an AutoEPMoELayer's live expert weights and plan their movement to a target placement through the affine transfer planner (deepspeedai#8623), without reading checkpoint metadata or materializing the logical parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Codex Review SummaryThis 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: 9637a10dbf
ℹ️ 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".
| affine_maps[name] = autoep_placement_to_affine_map(placement, self._expert_logical_shape(param)) | ||
| return affine_maps | ||
|
|
||
| def plan_expert_transfer(self, |
There was a problem hiding this comment.
Add user documentation for the transfer-planning API
For downstream code that consumes these new public planning methods, the dedicated AutoEP documentation and affine IR specification remain unchanged, so users are not given a discoverable contract for constructing target_placement, translating the separate source/target EP-local rank namespaces, or normalizing ZeRO/EDP storage before applying segment offsets. Add this API and its placement/normalization requirements to docs/code-docs/source/autoep.rst or the affine specification rather than relying only on implementation docstrings.
AGENTS.md reference: AGENTS.md:L26-L26
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Added in c02604d: a "Planning expert placement transfers" section in docs/code-docs/source/autoep.rst covering how to build target_placement with make_autoep_placement_descriptor, the source/target EP-local rank namespaces (and dist.get_global_rank(layer.ep_group, rank)), element offsets into the unpartitioned packed [local_experts, ...] tensor (gather under ZeRO-3; EDP replicas hold the same tensor), replica selection, PlanBudget limits, and the uniform live-placement requirement. affine_ir_spec.md §8.4 now points to the runtime API.
Describe expert_affine_maps() and plan_expert_transfer(): how to build a target placement, the EP-local rank namespaces of a plan, the element offsets into the unpartitioned packed tensor under ZeRO-3/EDP, replica selection, plan budgets, and the uniform live placement requirement. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
# Conflicts: # docs/code-docs/source/autoep.rst
…partitions Add autoep_storage_affine_map and AutoEPMoELayer.expert_storage_affine_maps so the transfer planner can read directly from runtime storage: maps are keyed by global rank over the flattened parameter, every EDP replica is offered as a holder for replica selection, ZeRO-3 partitions exclude padding, and ranks without experts or with padding-only partitions get empty shards. Compare placements by explicit rank IDs instead of list order, and verify that the published per-parameter affine map matches the live placement. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
…oep-live-affine-map
Summary
#8623 plans shard-to-shard copies between two
ParamAffineMaps. Today, though, the only AutoEP maps come from checkpoint metadata, so nothing at runtime can feed the planner. This PR closes that gap: it builds the source map from the placement the liveAutoEPMoELayeractually holds, and builds the target map from a target placement descriptor. Both maps then go straight toplan_transfer.It also describes what each process actually stores under expert data parallelism (EDP) and ZeRO, so a plan can read directly from runtime storage instead of first normalizing it to one packed tensor per EP rank.
Related: #8252 (§8.4 AutoEP expert placement), #8230, #8544.
Changes
AutoEPMoELayer.expert_affine_maps()returns the affine maps of the livew1/w2/w3.dist.get_global_rank(self.ep_group, rank).[local_experts, ...]tensor. ZeRO-3/EDP fragments stay outside the map, and the shape comes fromds_shape.AutoEPMoELayer.plan_expert_transfer(target_placement, limits=None, *, replica_selector=None)returns oneTransferPlanper expert parameter.autoep_affine.plan_autoep_placement_transfer(source_placement, target_placement, logical_shape, ...)is the layer-independent form. Both placements go through the existingautoep_placement_to_affine_map, so no second placement→map conversion is introduced.AutoEPMoELayer.expert_storage_affine_maps()returns maps of the storage each global rank holds, built byautoep_affine.autoep_storage_affine_map(descriptor, logical_shape, holders_by_ep_rank, partition_numel_by_ep_rank=None).(numel,), so each shard is a rank's flat storage, and a ZeRO-3 fragment that splits an expert row stays one interval.locations. The map makes no choice among them; the planner's default orreplica_selectordoes (replica policy stays with Define affine IR for checkpointing #8252).dstores[d*n, (d+1)*n)of the packed tensor with trailing padding excluded, so a padding-only partition, or any holder of an EP rank without experts, has an empty shard and is never a source or target.all_gather_objectgives each rank the holders of every EP rank, without assuming a rank layout. Expert tensor parallelism (etp_size > 1) raisesNotImplementedError; optimizer state is not described.autoep_placements_equal), and each parameter's publishedDS_AUTOEP_UC_METAplacement and affine map must equal the live lowering.repack_expert_weightsactually packed the weights; today that is contiguous and uniform. A descriptor that disagrees raisesNotImplementedError, rather than producing a map that addresses shards the weights do not have.Not in scope
Tests
tests/unit/v1/moe/test_autoep_unit.py:test_live_expert_maps_address_the_packed_runtime_weights: for each rank, the map's shard shape and contents match the real packedw1/w2/w3. The reference is the full tensor fromrepack_expert_weights(ep_size=1), which does not depend on any affine map.test_plan_expert_transfer_moves_live_shards_into_target_packed_order: from EP=2 into 3 ranks with reordered, uneven, empty and replicated placements; executing the plan reproduces the target shards, every element is written once, and planning never callsrebuild/extract.test_live_expert_maps_reject_a_placement_the_weights_do_not_have,test_live_expert_maps_identify_placement_ranks_by_id,test_live_expert_maps_reject_a_published_map_the_placement_does_not_produce.tests/unit/checkpoint/test_autoep_affine.py(storage maps): each global rank's shard equals storage built by indexing the full tensor; every EDP replica is offered as a candidate and a selector can pick another; a ZeRO-3 source with padding-only and empty ranks plans directly into a new placement; explicit rank IDs; invalid holders/partitions are rejected.tests/unit/v1/moe/test_autoep_checkpoint.py::TestAutoEPExpertStorageMaps(4 processes, EP=2/EDP=2, ZeRO-2, ZeRO-3, ZeRO-3 + folded AutoTP=2): on real engines,extractof the gathered packed tensors equals each rank'sparam.dataords_tensor, and a plan from the live storage into a 4-rank one-expert-per-rank placement reproduces the target exactly.Results (Intel Arc Pro B70):
test_autoep_unit.py,test_autoep_affine.py,test_autoep_affine_universal.py,test_affine_transfer_plan.py,test_affine_shard_map.py,test_autoep_zero3_metadata.py: 443 passed, 6 skipped.TestAutoEPExpertStorageMaps: 3 passed on 4× B70.locations, cutting at only the first replica's boundaries, keeping padding in shards, dropping ZeRO-3 partition sizes in the layer) each make at least one new test fail.Contribution checklist
Related work.
plan_transfer).A search for AutoEP placement and transfer and for affine maps found no overlapping PR.
Commands and results. Hardware and software: Intel Arc Pro B70 (XPU, XCCL), Level Zero driver 1.15.39122 (compute runtime 26.27.39122.11), torch 2.14.0.dev20260804+xpu.
Results are listed under Tests above.
Numerics, performance, memory. Training is not affected. The new methods only run when called.
expert_storage_affine_maps()issues oneall_gather_object; the other methods use no collectives.Compatibility matrix.
etp_size > 1(raisesNotImplementedError)AI assistance. This PR was developed with AI assistance (GitHub Copilot CLI). I reviewed every changed line and ran the tests above.