Repository navigation
Fix heap corruption when sizing thrown-away CUDA graph captures - #976
Merged
Merged
Conversation
…e pool's id
_capture_thrown_away read its graph's size with torch.cuda.memory_snapshot(pool.handle).
torch's THCPModule_memorySnapshot wraps the borrowed items of that tuple in owning
THPObjectPtrs, so every call drops a reference to each item of the pool id (torch 2.9.1, 2.12.1
and 2.13.0 alike). A graph_pool_handle() id counts the pools the process has made, so once a
process has made 256 the id is no cached small int: the call freed it while the pool's handle
still held it, and the handle's release then decremented a refcount in freed memory. That is
the glibc heap corruption ("malloc_consolidate(): unaligned fastbin chunk detected", and others)
that the draft-verify GPU modules and the Qwen3.5 integration module hit when one process ran
them all, at the first throwaway capture after the 256th pool.
The pool's bytes are now summed from the whole snapshot by segment_pool_id, which hands torch no
object of ours.
No behaviour change.
Collaborator
Live test: Fix heap corruption when sizing thrown-away CUDA graph capturesWorks. The crash reproduces on main past ~256 graph pools and is gone on the PR. The new size matches the old one on the same pool every time. Every served config builds the same capture plan as main. H200 · torch 2.9.1 · PR head The crash
The number
Tests
CommandsHarness: |
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.
_capture_thrown_awaysizes a capture withtorch.cuda.memory_snapshot(pool.handle), and torch drops a reference to the pool id on every such call (torch 2.9.1, 2.12.1, 2.13.0). Once a process has made more than 256 graph pools, the id is no longer a cached int, so the call frees it while the pool still holds it and the next release writes into freed memory:malloc_consolidate(): unaligned fastbin chunk, or a segfault in the caching allocator. In main since #341.This sums the pool's bytes from the full snapshot by
segment_pool_id, which passes torch nothing of ours. The number is the same.Tests:
test_capture_budget.py::test_sizing_a_throwaway_capture_keeps_the_references_to_its_pool_idfails 2/2 on main and passes 2/2 here;test_capture_budget.py46 passed. CPU Core fails the same 4 tests as main, by name. ruff clean.The torch bug itself is worth an upstream report, separately.
AI assistance (Claude) was used for this PR.