Repository navigation
[pipelining] Reuse deterministic receive buffers - #196465
sanketpurandare wants to merge 14 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196465
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 1a9c52c with merge base 38e2a2e ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Summary: Optionally preallocate and reuse a deterministic pool of pipeline receive buffers. The finalized schedule is colored before warmup, each slot is assigned before its receive, and the slot is released only after the consuming backward; inference retains it until outstanding sends complete. This provides stable CUDA-graph addresses without restoring one buffer per microbatch. Lazy just-in-time allocation remains supported. The change adds no polling, dynamic recoloring, or schedule mutation. Dependencies and risks: - Requires the receive ownership model from #196463 and slot coloring from #196464. - Tests cover forward/backward shape classes, full and split backward, inference send lifetime, repeated steps, and storage aliasing. Test Plan: - `python test/distributed/pipelining/test_schedule.py -k recv_buffer` - `python test/distributed/pipelining/test_schedule_multiproc.py` ghstack-source-id: c410342 Pull-Request: #196465
[ghstack-poisoned]
|
@claude provide a critical pr review, check for bugs, soundness of design, test coverage, redundant tests, slop code, cpmpactness of code, api design and provide feedback or suggest changes on how to make it better. |
|
Claude finished @sanketpurandare's task in 46m 33s —— View job Reviewed the pool lifecycle against the runtime loop and the P2P stream semantics: the reuse itself is safe (thanks to Full review — #196465 [pipelining] Reuse deterministic receive buffersPR Review: #196465SummaryAdds an opt-in ( Code Quality1. Any exception during Fix: reset pool ownership in 2. Backward slot is released before its 3. Dead metadata validation with a misleading error. 4. 5. Slot count is derived twice. 6. 7. Shared mutable sentinel across stages. API Design8. 9. Name collision. 10. Performance11. Inference gets zero slot reuse and more retained memory than the lazy path. With 12. Alternating 13. Note on the CUDA-graph motivation. The reuse is stream-safe, but for a subtler reason than the allocator: P2P always runs on the internal NCCL stream ( Testing14. Two multiproc tests trade default-path coverage for new-path coverage. 15. The claimed "storage aliasing" coverage does not exist. There is no 16. 17. Error paths are almost entirely untested. Only 18. Untested combinations: 19. The new unit test is fragile. RecommendationRequest Changes Finding #1 is a real robustness bug that turns any recoverable mid-step failure into an unrecoverable one, and it needs a regression test. Findings #11/#12 mean the flag is a pessimization for inference and does not deliver stable addresses across train/eval alternation — the stated goal. #2 needs confirmation before landing. The rest (#3-#10, #13-#19) are cleanups and coverage that should ride along. |
[ghstack-poisoned]
|
@claude Preserved fail-fast recovery after an incomplete distributed step because outstanding communication makes silent owner reset unsafe. The pool now uses explicit forward/backward assignment maps and counts, validates uniform metadata once, reuses stable addresses across successful steps, and materializes a send only when it aliases either receive pool. Inference intentionally retains one slot per live microbatch until all pending sends complete; the PR no longer claims an inference memory reduction over lazy allocation. Existing multiprocess coverage exercises lazy/static modes, repeated pointers, aliasing, split backward, V/local transfer, DTensor metadata, deferred receives, and train/eval reuse. |
Summary: Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Forward and backward pools are independent, use explicit assignment maps and allocation counts, and validate uniform receive metadata once before allocation. Training slots are released after their full or weight backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send completion actions. A single pool per direction avoids retaining separate train and eval allocations; changing execution mode may resize it. A backward send that aliases either receive pool is materialized before the slot can be reused. Ordinary non-aliasing sends avoid the copy. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; recreating the schedule and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -k recv_buffer` - `python test/distributed/pipelining/test_schedule_multiproc.py` [ghstack-poisoned]
[ghstack-poisoned]
|
Claude finished @sanketpurandare's task in 39m 41s —— View job Most of the previous round landed cleanly — the slot-count duplication, the test-only Full re-review — #196465 [pipelining] Reuse deterministic receive buffersRe-review: #196465Verified against Accepting your rationaleFail-fast on incomplete steps. You're right and I was wrong to call this a bug. Outstanding One follow-on, since the guard's meaning changed: because the documented recovery discards the stage objects (and therefore the pool), the guard in Metadata validated once. Inference retention. Accepted, and the docstring change is the right call. One wording sharpen: Slot counts, sentinel, naming, DTensor-guard comment, test-only hook. All resolved. Zero cost when disabled. Worth stating explicitly since it's load-bearing for the default path: with Still open1. The window is: I'll grant this is a much looser race than the backward one you closed — 2. Mode switching frees and reallocates the backward pool, and nothing tests it. The docstring now warns that switching "may resize the single pool", which is honest. But train-then-validate is the common loop, and this is the case where address stability — the feature's headline benefit — is guaranteed not to hold, plus you get allocator churn proportional to the backward pool at every transition. A pool per mode (or per Either way this path has no test: 3. Release condition reads 4. The clone in 5. Interaction with custom action overrides is unstated. Coverage claimsTwo of the claims in your comment don't match what's in the tree: DTensor metadata is not covered with this flag. Train/eval reuse is not covered. As above — The rest of the claims check out: lazy vs static via the Remaining test notes:
RecommendationApprove with comments — this is close. I'd resolve #1 (guard |
| """ | ||
|
|
||
| def __init__(self, direction: str) -> None: | ||
| self._direction = direction |
There was a problem hiding this comment.
do we need 2 pools?
A slot indexed by payload size would address the issue of different buffer size.
In the naive pipeline case, forward activation and backward gradient of the activation usually share the same size.
I wonder having the same pool would enable more buffer reuse?
There was a problem hiding this comment.
A stage can send one or more tensors to the next stage, I think for this option of using a single static recv buffer pool we need to enforce some conditions like your forward and backward payload tensors should be same. There is no guarantee that they would be same, for instance, i can send some tensors to a stage that doesn't require grads, then the backward would be None. Or in case of DTensors they might have different sizes due to some padding stuff. During init we know the exact metadata for send/recv of all the stages, so we can error out or fallback to lazy recv with a warning.
| def __init__(self, *args, **kwargs): | ||
| self._defer_pp_recv: bool = kwargs.pop("defer_pp_recv", False) | ||
| self._max_active_stages: int = kwargs.pop("max_active_stages", 3) | ||
| self._reuse_recv_buffers: bool = kwargs.pop("reuse_recv_buffers", False) |
There was a problem hiding this comment.
do you see problems with always reuse the recv buffer? maybe don't need a new flag
There was a problem hiding this comment.
| self._fwd_recv_pool = _RecvBufferPool("forward") | ||
| self._bwd_recv_pool = _RecvBufferPool("backward") |
There was a problem hiding this comment.
These 2 pools seems to be owned by per stage.
I thought they should be global?
There was a problem hiding this comment.
There is no guarantee that fwd/bwd send/recv metadata across stages is identical. Maybe for static recv buffer pool this also needs to be enforced as a constraint and we fallback to lazy recv buffers in case of non-satisfaction
| for info, buffer in zip(recv_infos, buffers, strict=True): | ||
| if buffer is not None: | ||
| info.set_buffer(buffer) | ||
| self._owners[slot] = microbatch_index |
There was a problem hiding this comment.
I am confused by the semantics of _owners?
I expect a slot to be jointly owned by a (stage, microbatch_index) pair.
There was a problem hiding this comment.
yes if we are sharing the slots across stages
| None if info.is_root_arg else info.tensor_meta for info in recv_infos | ||
| ) | ||
| allocation_signature = tuple( | ||
| None if meta is None else (meta.shape, meta.stride, meta.dtype) |
There was a problem hiding this comment.
stride can be skipped?
recv tensor must be contiguous.
There was a problem hiding this comment.
more generally, I would expect buffer to be just blob of bytes, signatured by byte_size.
There was a problem hiding this comment.
This should be handled by stage metadata runtime checks when the env variable is set for debug/runtime checks is set.
| def _ensure_owned_send(self, tensor: torch.Tensor) -> torch.Tensor: | ||
| """Materialize sends that alias storage managed by either recv pool.""" | ||
| if self._fwd_recv_pool.aliases(tensor) or self._bwd_recv_pool.aliases(tensor): | ||
| logger.debug( | ||
| "%s Materializing a send that aliases a recv pool", self.log_prefix | ||
| ) | ||
| return tensor.clone() | ||
| return tensor |
There was a problem hiding this comment.
interesting that you are handling such case.
did you run into a concrete case where it's sending the received tensor?
I suppose this could be common case for model with AttnRes, where stages are just forwarding the recv buffer.
Such clone could need further optimization.
There was a problem hiding this comment.
yes this is when recv buffer is directly forwarded, no I don't have a concrete usecase other than skip connections be served by passing tensors across stages. It is a valid case but needs to be handled with more care since if a recv buffer is used by the current stage plus the next stage then it requires accumulating the grads.
| num_fwd_slots: int, | ||
| bwd_slots: Mapping[int, int], | ||
| num_bwd_slots: int, | ||
| ) -> None: |
There was a problem hiding this comment.
can you infer number of slots from the slots?
Pool granularity: per-(stage, direction) leaves ~40% on the tableI measured three pooling granularities against the schedule this PR actually
Invariant across B captures essentially all of itC beats B by 2 slots out of 112, and only on one rank. Merging forward with The win is cross-stage, and it is mostly backwardAggregated over ranks: forward 84 -> 60 (1.4x), backward 28 -> 9 (3.1x). Backward collapses hardest because a Forward gains less but from a bigger base. Rank 3's per-stage forward peaks form SuggestionWorth considering one pool per direction shared across a rank's local stages. |
Pool granularity, part 2: V-shape schedules invert the resultFollow-up to my comment on pool granularity, which measured loop topology only. Same methodology: build
ScheduleZBVZeroBubble
ScheduleDualPipeV
Worst-rank figures, which are what actually decide whether a job fits: ZBV 16 -> Why B does nothing hereTwo separate reasons, and neither has an analogue in the loop topology. At the V endpoints, a rank has exactly one stage per direction, so there is On the middle ranks both stages do use both directions, but their peaks coincide The two local stages in a V sit on opposite legs and are co-active by Cross-topology summary
This supersedes the suggestion in my earlier comment. B is the better grouping Incidentally, C lands on 33 total slots for all three pp=4 / 2-stages-per-rank The cost of C is that variable-size slots in a single arena is bin-packing |
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. The new public option follows the existing `max_active_stages` argument so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Forward and backward sends that alias either receive pool are materialized before a slot can be reused. Ordinary non-aliasing sends avoid the copy. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; recreating the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. [ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: 0c2144f Pull Request resolved: #196465
[ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: d2bcf3c Pull Request resolved: #196465
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. [ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: bdea003 Pull Request resolved: #196465
[ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: bf77499 Pull Request resolved: #196465
[ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: 9f8e99d Pull Request resolved: #196465
[ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: 3bd2447 Pull Request resolved: #196465
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. [ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: 04608a3 Pull Request resolved: #196465
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. [ghstack-poisoned]
Add an opt-in static receive-buffer pool whose slots are colored from the finalized pipeline schedule. The pool retains stable tensor addresses across successful steps while preserving the just-in-time descriptor ownership contract. Every public multi-stage schedule exposes and documents the `reuse_recv_buffers` option after the existing `max_active_stages` argument, so positional callers retain their prior meaning. Keep receive descriptors and storage ownership in `_recv_buffers.py`. Stage execution imports those primitives, while schedule-IR lifetime analysis remains in `schedules.py`; this preserves a one-way dependency without coupling buffer allocation to schedule action types. The pool retains ordinary, autograd-neutral base tensors allocated independently of ambient inference mode. Each acquisition gives the receive descriptor a fresh detached alias. Hooks, gradients, and `requires_grad` state therefore cannot cross lease boundaries, while the underlying address remains stable for CUDA graph capture and inference-to-training transitions. Forward and backward pools are independent, use explicit assignment maps and allocation counts, validate uniform receive metadata before allocation, and resolve every peer before acquiring storage. Invalid routing metadata therefore cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools grow without replacing existing storage, so train/eval transitions retain at most the larger mode footprint while preserving captured addresses. Training slots are released after their full or weight-backward lifetime. Inference retains received inputs until all outstanding sends complete because the runtime does not yet expose per-send wait actions. Tensors that escape through network sends, same-rank stage handoffs, or final outputs are materialized only when they alias a receive pool. Ordinary non-aliasing values remain zero-copy. Native alias detection handles dense views and non-strided tensors such as sparse wrappers without dereferencing unsupported storage. Buffer acquisition and `P2POp` construction are transactional, so a failure before launch restores both descriptor and pool ownership. Custom receive handlers must preserve the stage receive acquire/populate contract. Incomplete distributed steps remain fail-fast because outstanding P2P work may still own the buffers; reconstructing the stages, schedule, and process group is the safe retry boundary. Test Plan: - `python test/distributed/pipelining/test_schedule.py -v` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.py` - `CUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuse` - `lintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.py` AI assistance disclosure: > This change was authored with assistance from an AI coding tool and reviewed by the author. ghstack-source-id: 73e4976 Pull Request resolved: #196465
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Stack from ghstack (oldest at bottom):
Add an opt-in static receive-buffer pool whose slots are colored from the
finalized pipeline schedule. The pool retains stable tensor addresses across
successful steps while preserving the just-in-time descriptor ownership
contract. Every public multi-stage schedule exposes and documents the
reuse_recv_buffersoption after the existingmax_active_stagesargument, sopositional callers retain their prior meaning.
Keep receive descriptors and storage ownership in
_recv_buffers.py. Stageexecution imports those primitives, while schedule-IR lifetime analysis remains
in
schedules.py; this preserves a one-way dependency without coupling bufferallocation to schedule action types.
The pool retains ordinary, autograd-neutral base tensors allocated independently
of ambient inference mode. Each acquisition gives the receive descriptor a fresh
detached alias. Hooks, gradients, and
requires_gradstate therefore cannotcross lease boundaries, while the underlying address remains stable for CUDA
graph capture and inference-to-training transitions.
Forward and backward pools are independent, use explicit assignment maps and
allocation counts, validate uniform receive metadata before allocation, and
resolve every peer before acquiring storage. Invalid routing metadata therefore
cannot leave lazy descriptors or pooled slots falsely owned. Compatible pools
grow without replacing existing storage, so train/eval transitions retain at
most the larger mode footprint while preserving captured addresses. Training
slots are released after their full or weight-backward lifetime. Inference
retains received inputs until all outstanding sends complete because the runtime
does not yet expose per-send wait actions.
Tensors that escape through network sends, same-rank stage handoffs, or final
outputs are materialized only when they alias a receive pool. Ordinary
non-aliasing values remain zero-copy. Native alias detection handles dense views
and non-strided tensors such as sparse wrappers without dereferencing unsupported
storage. Buffer acquisition and
P2POpconstruction are transactional, so afailure before launch restores both descriptor and pool ownership. Custom
receive handlers must preserve the stage receive acquire/populate contract.
Incomplete distributed steps remain fail-fast because outstanding P2P work may
still own the buffers; reconstructing the stages, schedule, and process group is
the safe retry boundary.
Test Plan:
python test/distributed/pipelining/test_schedule.py -vCUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_schedule_multiproc.pyCUDA_VISIBLE_DEVICES=0,1,2,3 python test/distributed/pipelining/test_dtensor_pp_integration.py TestDTensorPPModes.test_static_mode_interleaved1f1b_replicate_with_recv_buffer_reuselintrunner --config=.lintrunner.toml torch/distributed/pipelining/_recv_buffers.py torch/distributed/pipelining/stage.py torch/distributed/pipelining/schedules.py test/distributed/pipelining/test_schedule.py test/distributed/pipelining/test_schedule_multiproc.py test/distributed/pipelining/test_dtensor_pp_integration.pyAI assistance disclosure: