Fix GC pause during CUDAGraph capture to prevent abort#1339
Merged
Conversation
…bort (#1322) During CUDAGraph capture, MiniMax-M3's autotuned _topk_index_partial_kernel discards candidate CompiledKernels. A gen-0 GC firing inside the stream-capture region runs CompiledKernel.__del__ -> hipModuleUnload, which HIP forbids while a stream is capturing (HIP 900), corrupting the capture and aborting the custom_all_reduce IPC handshake (SIGABRT). gc.freeze() did not help because the discarded kernels are created mid-loop. Disable GC for the whole capture window and restore via try/finally.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents HIP stream-capture aborts during CUDA/HIP graph capture by pausing Python’s cyclic GC across the entire capture window, avoiding finalizers (e.g., Triton/HIP module unload) running inside capture.
Changes:
- Add a local
pause_gc()context manager that runsgc.collect(), disables GC for the capture window, then restores GC infinally. - Wrap
graph_capture()withpause_gc()to cover the full capture loop. - Rename the
graph_capture()context variable fromgctocapture_ctxand updatestreamusages accordingly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2288
to
+2296
| def pause_gc(): | ||
| # No GC during capture: a finalizer's hipModuleUnload aborts it (HIP 900). | ||
| gc.collect() | ||
| gc.disable() | ||
| try: | ||
| yield | ||
| finally: | ||
| gc.enable() | ||
| gc.collect() |
valarLip
approved these changes
Jun 25, 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.
…bort (#1322)
During CUDAGraph capture, MiniMax-M3's autotuned _topk_index_partial_kernel discards candidate CompiledKernels. A gen-0 GC firing inside the stream-capture region runs CompiledKernel.del -> hipModuleUnload, which HIP forbids while a stream is capturing (HIP 900), corrupting the capture and aborting the custom_all_reduce IPC handshake (SIGABRT). gc.freeze() did not help because the discarded kernels are created mid-loop. Disable GC for the whole capture window and restore via try/finally.
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist