Add devlog: Cross-stream memory management: wait_event instead of record_stream - #43
Merged
Merged
Conversation
…ord_stream Explains why producer/consumer pipelining across CUDA streams needs explicit memory lifetime management (the caching allocator only tracks the allocation stream), why Tensor.record_stream makes peak memory depend on CPU run-ahead, and the recommended pattern: keep a Python reference, record an event on the consumer, and wait_event on the allocation stream before dropping the reference. Includes a single-GPU demo script and walks through how FSDP2 applies the pattern in forward (all-gather) and backward (reduce-scatter).
anshul-si
approved these changes
Sep 30, 2026
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.
New post under
content/eager/: Cross-stream memory management: wait_event instead of record_stream.What it covers
Tensor.record_streamis correct but hands block reuse to the allocator's event polling. Peak memory then depends on how far the CPU runs ahead, with links intoCUDACachingAllocator.cpp.wait_event, and the recommended one, keep a Python reference andwait_eventon the allocation stream beforedel.AllGatherState) and backward (ReduceScatterState,set_reduce_scatter_max_input_buffers).Files
content/eager/2026-09-29-cross-stream-memory-without-record-stream.mdstatic/images/eager/cross-stream-*.svg: 9 swimlane diagrams with light and dark variants viaprefers-color-schemeVerification
1a0b56b8onmain, and each claim was checked against the code there.record_stream, stall and keepalive all pass;hugo --minifybuilds cleanly, and the page was checked in headless Chromium in light and dark mode.