Repository navigation
Optimize pipeline receive buffer allocation - #193872
Closed
SherlockNoMad wants to merge 2 commits into
Closed
SherlockNoMad wants to merge 2 commits into
SherlockNoMad wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193872
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit e0a6a27 with merge base 1b5baff ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
SherlockNoMad
requested review from
fegin,
sanketpurandare,
tianyu-l and
wconstab
August 18, 2026 00:36
SherlockNoMad
added a commit
that referenced
this pull request
Aug 18, 2026
Pipeline receive descriptors allocated activation and gradient buffers for every microbatch during stage initialization and retained them for the whole pipeline step. This reserved memory before communication needed it and required explicit gradient cleanup because the same activation leaves were reused across steps. Keep only tensor metadata in the receive descriptors, allocate storage immediately before posting an irecv, and transfer the buffer out of the descriptor when microbatch compute consumes it. Same-rank stage handoffs follow the same ownership contract. Fresh receive buffers also make the old input-gradient cleanup and unused non-consuming buffer helper unnecessary. Test Plan: ``` python test/distributed/pipelining/test_schedule.py -k test_stage_recv_buffers_allocated_just_in_time ``` ``` python test/distributed/pipelining/test_schedule_multiproc.py -k test_multi_iter ``` Both test commands reported OK; the test harness exited with status 134 during teardown, matching the existing environment behavior. ``` lintrunner -a ``` Lint initialization failed because the environment could not download its pinned CPython runtime through the network tunnel. No patches were applied. Authored with assistance from an AI coding assistant. ghstack-source-id: cd67792 Pull-Request: #193872
Contributor
|
Superseded by a refreshed current-main ghstack that preserves this implementation and authorship, then adds schedule-derived deterministic receive-buffer pooling. I am taking over maintenance of the replacement stack. |
This was referenced Sep 9, 2026
Contributor
sanketpurandare
added a commit
that referenced
this pull request
Sep 15, 2026
… in time" Summary: Pipeline stages currently retain one forward and backward receive buffer per microbatch from setup. Allocate a receive buffer immediately before posting its receive, transfer ownership to computation and autograd when consumed, and clear the descriptor reference afterward. This supersedes #193872 on current main while preserving its implementation and authorship. It establishes explicit ownership for later static reuse, but does not add pooling, polling, schedule rewrites, or send-wait policy. A descriptor that still owns storage fails loudly: an interrupted distributed step may have in-flight P2P work, so callers must recreate the schedule and process group rather than silently reusing that storage. The peak number of live lazy buffers is determined by the schedule's receive-prefetch depth, not necessarily one. Local V-schedule transfers follow the same ownership contract. Test Plan: - `python test/distributed/pipelining/test_schedule.py -k recv_buffer` - `python test/distributed/pipelining/test_schedule_multiproc.py` [ghstack-poisoned]
sanketpurandare
added a commit
that referenced
this pull request
Sep 15, 2026
Summary: Pipeline stages currently retain one forward and backward receive buffer per microbatch from setup. Allocate a receive buffer immediately before posting its receive, transfer ownership to computation and autograd when consumed, and clear the descriptor reference afterward. This supersedes #193872 on current main while preserving its implementation and authorship. It establishes explicit ownership for later static reuse, but does not add pooling, polling, schedule rewrites, or send-wait policy. A descriptor that still owns storage fails loudly: an interrupted distributed step may have in-flight P2P work, so callers must recreate the schedule and process group rather than silently reusing that storage. The peak number of live lazy buffers is determined by the schedule's receive-prefetch depth, not necessarily one. Local V-schedule transfers follow the same ownership contract. Test Plan: - `python test/distributed/pipelining/test_schedule.py -k recv_buffer` - `python test/distributed/pipelining/test_schedule_multiproc.py` [ghstack-poisoned]
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.
Stack from ghstack (oldest at bottom):
Pipeline receive descriptors allocated activation and gradient buffers for every microbatch during stage initialization and retained them for the whole pipeline step. This reserved memory before communication needed it and required explicit gradient cleanup because the same activation leaves were reused across steps.
Keep only tensor metadata in the receive descriptors, allocate storage immediately before posting an irecv, and transfer the buffer out of the descriptor when microbatch compute consumes it. Same-rank stage handoffs follow the same ownership contract. Fresh receive buffers also make the old input-gradient cleanup and unused non-consuming buffer helper unnecessary.
Test Plan:
Both test commands reported OK; the test harness exited with status 134 during teardown, matching the existing environment behavior.
Memory Savings
Configuration: DeepSeek-V3 16B eager, PP4/VPP4, EP2, DP-shard2, microbatch size 1, local batch size 16, sequence length 4096, no activation checkpointing, and 10 training steps on 8 H100 GPUs.
viable/strictpp-lazy-recv-buffersLazy receive-buffer allocation reduced peak reserved memory on every PP stage by 1.54-1.66 GiB.
Authored with assistance from an AI coding assistant.