Repository navigation
fix: qwen3_5_moe CUDA graphs capture into a new pool after the buffers grow - #78
Closed
philip-pentatonic wants to merge 1 commit into
Closed
philip-pentatonic wants to merge 1 commit into
philip-pentatonic wants to merge 1 commit into
Conversation
…s grow With expandable segments (PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True), the first request whose prompt plus max_tokens passed 8192 rows, and every request after it, failed at capture: "it->second->use_count > 0 INTERNAL ASSERT FAILED at CUDACachingAllocator.cpp:3332". Growing the buffers drops every graph but kept the pool handle. Torch counts a private pool's expandable mappings per allocation and its unmaps per free range, so once freed blocks coalesce the count stays above zero, the pool is never unregistered, and a capture into it finds a pool no graph uses. A growth now takes a new handle. RTX PRO 6000, torch 2.13 (NGC 26.07), Vontra/Qwen3.6-35B-A3B-MLX-4bit-MTP: 40 label-style requests from 8 clients, three past 8192 rows, fail from the first growth on before and pass after, with unchanged token SHA-256s equal to "draft": false. The new test_graphs_recapture_after_the_buffers_grow fails 2 of 4 cases before; tests/cuda/test_qwen36_moe.py and tests/test_qwen36_family.py: 16 passed.
This was referenced Sep 29, 2026
Closed
Owner
|
Thank you, @philip-pentatonic. This is in 0.3.6.3 under your name (9b8bc3ad). We ran |
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.
With
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True, Qwen3.6-35B-A3B on CUDA fails the first request whose prompt plusmax_tokenspasses 8192 rows, and every request after it:Cause:
Graphs.loaddrops every graph when it grows the buffers, but kept the pool handle. Torch removes an unused private pool only once itscudaMalloc_countis back to zero. With expandable segments that count goes up once per allocation that extends a segment and down once per free range it unmaps; freed blocks merge first, so it stays above zero. The pool stays registered withuse_count0, and the next capture into that handle trips the assert (torch 2.13.0a0+9186a08, CUDACachingAllocator.cpp lines 3906, 4238, 4093, 3332). With the default allocator,empty_cacheremoves the pool and growth works.Fix: a growth takes a new
torch.cuda.graph_pool_handle().empty_cachestill unmaps the old pool's memory; one bookkeeping entry is left per growth, at most one per doubling up to the context window.Repro with public text: serve Vontra/Qwen3.6-35B-A3B-MLX-4bit-MTP (81169a9) with expandable segments and
--context 32768. Send 40 JSON chat requests from 8 clients, each the opening of A Tale of Two Cities repeated to 2.7k–5.9k tokens withmax_tokens1410, and three of them repeated to 9k tokens.After the fix:
"draft": false(12/12 distinct prompts on each GPU).Tests: the new
test_graphs_recapture_after_the_buffers_growruns a tiny model with a 1M vocabulary, so two chain widths extend the pool's segment twice; greedy and sampled, expandable segments off and on. It fails 2 of 4 before and passes after, on both GPUs.tests/cuda/test_qwen36_moe.pyandtests/test_qwen36_family.py: 16 passed on both.