Skip to content

cuda: bound the weight-cache arena to free VRAM by default - #995

Open
GHTKFI wants to merge 1 commit into
antirez:mainfrom
GHTKFI:fix/cuda-unbounded-weight-cache
Open

cuda: bound the weight-cache arena to free VRAM by default#995
GHTKFI wants to merge 1 commit into
antirez:mainfrom
GHTKFI:fix/cuda-unbounded-weight-cache

Conversation

@GHTKFI

@GHTKFI GHTKFI commented Sep 6, 2026

Copy link
Copy Markdown

cuda_model_cache_limit_bytes() returned UINT64_MAX whenever DS4_CUDA_WEIGHT_CACHE_LIMIT_GB was unset, letting the weight-cache arena grow unbounded during prefill until a later cudaMalloc call fails mid-generation (issue #170 shows the identical "arena alloc failed: out of memory" symptom on an RTX 4090, with the same unbounded default as the unidentified root cause).

Query cudaMemGetInfo() and default the limit to free VRAM minus a 4 GiB safety margin instead, leaving room for the KV cache, prefill buffers, and the dynamic q8/fp16 cache. DS4_CUDA_WEIGHT_CACHE_LIMIT_GB still overrides this when set explicitly.

Tested: reproduced the OOM crash on an RTX 3090 (24 GB) with a 22-token prompt + --ssd-streaming-cache-experts 14GB; with this fix, the same command completes generation with no arena alloc failures.

cuda_model_cache_limit_bytes() returned UINT64_MAX whenever
DS4_CUDA_WEIGHT_CACHE_LIMIT_GB was unset, letting the weight-cache
arena grow unbounded during prefill until a later cudaMalloc call
fails mid-generation (issue antirez#170 shows the identical "arena alloc
failed: out of memory" symptom on an RTX 4090, with the same
unbounded default as the unidentified root cause).

Query cudaMemGetInfo() and default the limit to free VRAM minus a
4 GiB safety margin instead, leaving room for the KV cache, prefill
buffers, and the dynamic q8/fp16 cache. DS4_CUDA_WEIGHT_CACHE_LIMIT_GB
still overrides this when set explicitly.

Tested: reproduced the OOM crash on an RTX 3090 (24 GB) with a 22-token
prompt + --ssd-streaming-cache-experts 14GB; with this fix, the same
command completes generation with no arena alloc failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant