Conversation
shuangwu
marked this pull request as ready for review
September 18, 2026 19:05
Collaborator
Author
|
Closing after design review. The broad suppression policy changes legitimate memory-release behavior; the narrowed opt-in helper adds API and lifecycle state without improving on removing unnecessary per-wave flushes in the application. We will use that simpler mitigation instead. Transport fault containment (#747) and owned teardown (#751) remain independent and necessary. A future coordinated-cleanup proposal should be driven by a demonstrated need for memory handoff while transport remains active. |
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
Provide an opt-in policy for opportunistic CUDA cache cleanup, such as optional per-wave housekeeping. Do not suppress intentional memory release.
This revision removes the earlier broad rewrite of existing cleanup sites. Model loading, checkpoint resume, simulator shutdown, and other in-tree direct
torch.cuda.empty_cache()calls are unchanged from upstream main.Contract
maybe_empty_cuda_cache()only when the flush is safe to omit. It returns whether PyTorch's flush was invoked, not the number of bytes released.suppress_opportunistic_cuda_cache_cleanup()before launching native/background work.The practical prevention applies only once downstream optional per-wave callers adopt the helper or remove their flushes. No existing in-tree cleanup is guessed to be optional. This is intentionally not a blanket fix for every concurrent allocator-cleanup interaction.
Validation
Portable reproduction:
PYTHONPATH=. torchrun --standalone --nproc-per-node=2 tests/cuda_cache_cleanup_canary.py --backend nccl(or--backend gloo). Use a finite outer timeout. The canary tests real background communication and an explicit post-teardown boundary, not the original deadlock or a full training workload.Scope and tradeoffs
Optional cleanup can leave allocator-reserved memory higher, but intentional memory handoff is no longer silently disabled. Applications must not mark a required release as optional when another allocator depends on it.
Independent of #747 (fault containment), #751 (owned teardown), and #754 (receive-memory budgets). Does not control allocator-internal reclamation, third-party engine cleanup, or native fault recovery. The same optional policy covers NCCL and UCXX; no live RDMA claim is made.
See
docs/payload_transport/cuda_cache_cleanup.mdfor adoption requirements and safe-boundary obligations.