Repository navigation
Avoid redundant copies in MPS P2P staging - #8314
Merged
delock merged 1 commit intoAug 25, 2026
Merged
Conversation
Treat staged isend as input-only and staged irecv as output-only so the MPS path avoids transfers that cannot affect the P2P result. Publish receive buffers only after a successful wait, and preserve the backend None return for non-member group ranks. Signed-off-by: Fu Xiaonan <[email protected]>
FU-max-boop
requested review from
loadams,
tjruwase and
tohtana
as code owners
August 25, 2026 04:14
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5caf2b6f9a
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
delock
approved these changes
Aug 25, 2026
delock
enabled auto-merge
August 25, 2026 07:39
Merged
via the queue into
deepspeedai:master
with commit Aug 25, 2026
eba5d27
13 of 15 checks passed
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.
Summary
isendinput-only: take one CPU snapshot and retain it through completion without copying it backirecvoutput-only: allocate an empty CPU target without reading the destination, then publish it only after the underlying barewait()succeedsNonereturn for non-member ranks and never publish an unconfirmed or failed receive bufferStagedWork.wait()deliberately narrow instead of broadening the Work contractFollow-up to #8303. The directional-staging scope was approved by @delock in this review comment.
Why
#8303 made
isendandirecvgenuinely asynchronous and deferred MPS publication until completion. The generic staging path still treats every tensor as both input and output, which adds two transfers that cannot affect a point-to-point result:isendcopies the staged CPU payload back to an unchanged MPS source afterwait();irecvcopies the old MPS destination to CPU before the receive overwrites it.P2P direction is known at the call site, so those copies can be removed without changing the default in-out staging contract used by other collectives.
Correctness contract
isendkeeps its CPU payload reachable through the returned work handle.irecvcopies CPU to MPS only after the backendwait()returns successfully.Nonereturn remainsNone, including non-member group ranks, and never publishes the empty receive target.is_completed(), timeout-awarewait(),get_future(), andresult()remain outside this change, matching the maintainer-approved scope.Verification
Exact local head:
5caf2b6f9aef9ee52a2c3ba58a1a24059cf35add.None-return tests:4 passed2 passed2 passedtests/unit/comm/test_dist.pyon MPS:16 passed, 19 skippedgit diff --checkThe new four-test direction/failure matrix was first run against the unchanged #8303 source:
3 failed, 1 passed. It is4 passedwith this patch.Local staging evidence
An instrumented no-network microbenchmark on one Apple M5 Pro host (Python 3.12.13, PyTorch 2.13.0) confirmed the expected Python/ATen-visible cross-device copy matrix at 1, 16, and 64 MiB:
isendirecvFor the eliminated local phases, median p50 reductions were 99.84-99.96% for
isendwait and 96.41-98.11% forirecvcreation. These measurements isolate wrapper staging overhead with a completed fake Work; they are not end-to-end Gloo, pipeline, training, or multi-node speedup claims.