Conversation
Every distinct (batch,seq) ShapePlan allocates a persistent arena plus up to 64 MiB of cuBLASLt workspace, a cudaGraph and a cudaGraphExec, retained for the worker's lifetime. A long-lived worker embedding diverse batch shapes therefore accumulated one arena per shape and could OOM the 6 GiB RTX 4050 (observed out-of-memory crashes in the live gateway log at cuda_family_common.cuh:73). Retain at most two warm plans per context. Eviction happens before allocation of a new plan and after cudaStreamSynchronize, so a victim's buffers are freed while no kernel references them; the just-executed plan is always promoted to most-recently-used and never the victim. Deleting a plan destroys its DeviceAllocation members (cudaFree) via destructors, so eviction is what bounds VRAM. Also restores the plans member declaration that the eviction edit had dropped (build previously failed with 7 undefined-identifier errors). Verified live: four distinct shapes captured, replay of the evicted first shape bit-identical (max_abs_delta=0), steady serving VRAM ~1.9 GiB on the RTX 4050 lane.
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.
Problem
QwenContextretains every distinct(batch, seq)ShapePlanfor the worker's lifetime. Each plan owns a persistent arena (scales withbatch*seq*hidden + batch*heads*seq^2, see #2314-style arithmetic), up to 64 MiB of cuBLASLt workspace, acudaGraphand acudaGraphExec. A long-lived worker that embeds diverse batch shapes therefore accumulates one arena per distinct shape.Observed live: the production gateway serving AFT/MC traffic logged repeated
cudaMalloc ... out of memoryengine crashes (cuda_family_common.cuh:73) after accumulating shapes like64x172(arena 646 MB),16x1117(1.59 GB), and dozens of 1xN shapes — on a 6 GiB RTX 4050, where persistent f16 weights alone are ~1.1 GiB.Fix
Bound the cache: retain at most two warm plans per context (
max_plans = 2, LRU order).cudaStreamSynchronizeon the context's single stream, so victim buffers are freed while no kernel references them; the just-executed plan is promoted to MRU and never the victim.unique_ptr<ShapePlan>, whose destructor chain frees graph exec, graph, and everyDeviceAllocation(cudaFree). Eviction is what bounds VRAM.plansmember declaration that the eviction edit had dropped (the tree previously failed to compile with 7 undefined-identifier errors).Verification (live RTX 4050, production gateway lane)
synapse-worker-cuda(--features cuda) green.1x34,1x66,1x98,1x130) each captured a plan (captured_exact=truein worker logs).0.0), norms all 1.0 — correctness preserved across eviction.Notes
max_plansif a workload shows pathological eviction thrash.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Bounds the Qwen3 shape-plan cache to two entries with LRU eviction, preventing VRAM exhaustion on workers that see many distinct batch shapes.
plansmember declaration that was accidentally dropped, fixing a compile error.Written for commit d409db1. Summary will update on new commits.