Repository navigation
[Engine] Retry instead of failing when a CUDA graph is out of VRAM - #301
Open
okada-shogo wants to merge 1 commit into
Open
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
cudaGraphInstantiate ran out of VRAM in the middle of an answer on 8 GB cards (RTX 2070 Super, Inkling 2 Mini): --serve at 32K with --kv q8_0 on the second request, --window 6, and the DSpark drafter after a 2K prompt. The request ended with "ERR cudaGraphInstantiate: out of memory". On out of memory, record() (and the drafter's block recording) now 1. drops the step recordings, as before; 2. drops record()'s recordings made before this call (made again where they are next needed); 3. if the card still has no VRAM: runs the recording's launches unrecorded (the same launches, positions from at_), and at the next call's start the expert cache gives up one 64 MiB piece, which mind_vram() keeps free from then on. Where the cache cannot change (frozen, pool, no VMM) the next 256 calls run unrecorded. Class: same bits, except step 3's cache cut (placement), which only happens where main failed the request. Test knobs: STRATA_POLY_RECORD_FAIL=N, STRATA_POLY_RECORD_DROP=N. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 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.
Problem and result
When a CUDA graph cannot get VRAM, the engine now frees its older graphs and retries instead of failing the request.
Three cases that failed on main on 8 GB cards now finish, with the same output bits and unchanged decode speed.
Background: on 8 GB cards,
cudaGraphInstantiatecan run out of VRAM in the middle of a session, and the request thenends with
ERR cudaGraphInstantiate: out of memory. The engine records decode launches into CUDA graphs as it goes(one per token count, context room, window and drafter block length) and keeps every recording. Their VRAM comes out
of the reserve that the expert cache leaves free, so a long session uses it up.
Each case was run on main and on this PR:
--serve --max-context 32768 --kv q8_0 --window 4: 302 tokens, then 2,048 tokens (+64 each)--draft-model,--prompt-int8,STRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1 STRATA_INK_PRESTAGE=1), default reserve: 302 tokens (+1), then 2,048 tokens (+512)--serve --window 6: 302 tokens, then 2,048, then 4,096Output bits are unchanged (frozen identity, below). Decode speed is unchanged (RTX 2070 8 GB, mean of 3 runs):
The PR does not change the path that runs when there is no out-of-memory error. The IQ4_NL -1.5% comes from one slow
run (40.8 tok/s); the other two runs match main.
Each run (decode tok/s)
Related discussion
none
Approach
When
cudaGraphInstantiatereturns out of memory (inrecord()and in the drafter's block recording):bits do not change. In every run above, this step was enough.
kernels, reading positions from
at_. Requests for experts in RAM (the doorbell,STRATA_POLY_BELL: the GPU asksthe CPU workers through a flag in pinned memory) are answered layer by layer. At the start of the next call,
the expert cache gives up one 64 MiB piece, and
mind_vram()keeps that piece free from then on. This is theonly step that changes which experts are in VRAM, and it only happens where main would have failed the request. If the
cache cannot shrink (frozen experts,
--vram-pool, no VMM), the engine records nothing for the next 256 calls.Two test knobs force the fallbacks:
STRATA_POLY_RECORD_FAIL=N: every Nth recording fails.STRATA_POLY_RECORD_DROP=N: drops the recordings at every Nth recording and every Nth call.Metal keeps its old path. Other model families only see a change when instantiation fails, which used to fail the
request.
Merge notes:
--vram-elastic): whichever lands second adds this PR'srec_room_mib_to the reserve thatelastic_card()keeps:keep = reserve_mib_ + rec_room_mib_. Otherwise the elastic grow takes back the piece this PRgave the recordings.
drop_recordings()says HIP has no doorbell. With [Engine] Inkling 2 on AMD: GPU doorbell for experts in RAM #306 it has one. ThecudaStreamSynchronizethere is still safe, because nothing is recorded between a doorbell request and its answer.Whichever lands second only updates the comment.
Validation
Passed:
go-repro.sh). RTX 2070 Super, main 36e654b vs this PR 4319541, CUDA 12.9 sm_75.ERR cudaGraphInstantiate: out of memory."0 runs unrecorded".
--window 4and--window 6cases.STRATA_GPU_EXPERTS=800 STRATA_FREEZE_EXPERTS=1), main vs this PR:poly_logits_dump, IQ4_NL, md5 of all logits: 302-token and 2,048-token prompts, each followed by 64 tokensfed one by one. SAME for this PR,
RECORD_FAIL=1,RECORD_FAIL=3andRECORD_DROP=2. RTX 2070 Super andRTX 2070.
strata-poly --serve, DSpark drafter with the flags from the table above (--prompt-int8,STRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1 STRATA_INK_PRESTAGE=1), 2,048-token prompt + 128 greedy token ids: SAME for this PR and allthree knob settings. RTX 2070 Super.
--window 4 --kv q8_0, 2,048-token prompt + 128 greedy tokens, withSTRATA_SPEC_FIXED=1(fixed draft-cost table): SAME formain run twice, this PR, and all three knob settings. RTX 2070. Without the fixed table, main differs from main
between runs, because the lookup policy learns from timings.
e2e-nw.sh, 3 rounds, RTX 2070 8 GB).Failed:
Not run:
#if-guarded to main's behavior.measured run.
Limits
that main would have failed on.
about 360 at a time. The request still decoded at 43.7 tok/s.
cudaGraphLaunchitself returning out of memory is not handled; it was not seen in any run.🤖 Generated with Claude Code