CUDA OOM regression on DGX Spark (GB10)
Hi,
I've found what appears to be a regression in the CUDA backend on a NVIDIA DGX Spark (GB10).
I spent some time trying to bisect the problem, but unfortunately many of the intermediate commits no longer compile for me, so I couldn't identify the exact commit that introduced the regression.
Working commit
Commit:
519c4d8fe71a67bc80bba6e7b034d0dadc2114b5
Command:
./ds4-server
--cuda
-m ./ds4flash.gguf
--host 0.0.0.0
--port 5000
--ctx 500000
--kv-disk-dir ../cache/ds4-kv
--kv-disk-space-mb 32768
The server starts correctly and is fully usable.
Startup log:
ds4: Linux cuda backend set oom_score_adj=1000 ds4: CUDA backend initialized on NVIDIA GB10 (sm_121) ds4: CUDA host registration skipped: operation not supported ds4: CUDA preparing model tensor mappings ds4: CUDA loading model tensors into device cache ds4: CUDA loading model tensors 16.02 GiB cached ds4: CUDA prepared model tensor mappings 16.37 GiB ds4: CUDA loading model tensors 32.06 GiB cached ds4: CUDA prepared model tensor mappings 32.07 GiB ds4: CUDA loading model tensors 48.02 GiB cached ds4: CUDA prepared model tensor mappings 48.43 GiB ds4: CUDA loading model tensors 64.01 GiB cached ds4: CUDA prepared model tensor mappings 64.70 GiB ds4: CUDA loading model tensors 80.01 GiB cached ds4: CUDA prepared model tensor mappings 80.45 GiB ds4: CUDA startup model preparation covered 90.88 GiB of tensor spans in 21.776s ds4: cuda backend initialized for graph diagnostics ds4-server: context buffers 10835.27 MiB (ctx=500000, backend=cuda, prefill_chunk=4096, raw_kv_rows=4352, compressed_kv_rows=125002) ds4: CUDA using managed KV cache for ctx=500000 (kv cache 6.76 GiB, context buffers 10.58 GiB); this may degrade performance but is needed for very large contexts ds4-server: KV disk cache ../cache/ds4-kv (...) ds4-server: listening on http://0.0.0.0:5000 Current HEAD
Running the same model with the current HEAD consistently results in an out-of-memory condition during startup.
I also tried reducing the context size to 300000, but the result is the same: the server fails with an OOM before becoming usable.
The relevant part of the log is:
ds4: CUDA backend initialized on NVIDIA GB10 (sm_121) dev=0 ds4: CUDA (no-copy) host registration skipped: operation not supported ds4: CUDA preparing model tensor mappings ds4: CUDA loading model tensors into device cache ... ds4: CUDA startup model preparation covered 90.88 GiB of tensor spans ds4: cuda backend initialized for graph diagnostics ds4: memory: KV 4.20 GiB (raw 0.36 + compressed 3.84) + buffers 2.29 GiB + resident model 90.88 GiB = 97.38 GiB planned ds4: memory detail: ctx=300000 prefill_cap=4096 raw_kv_rows=4352 compressed_kv_rows=75002 backend=cuda ds4-server: context buffers 6648.24 MiB (...)
After that, the process runs out of memory.
Additional observations
I found one interesting behavior while testing:
Reducing --prefill-chunk to a much smaller value allows the server to start. However, as soon as the first prompt is processed, it immediately runs out of memory.
I don't know whether this is related or just another symptom, but I thought it was worth mentioning.
Notes --ssd-streaming avoids the startup OOM, but performance drops to roughly 1 token/sec, so it isn't a practical workaround. I intentionally avoided speculating about the root cause because I don't have enough information to draw conclusions from the code changes alone.
If it helps, I'm happy to test experimental patches, add temporary logging, or run any additional experiments on the DGX Spark hardware.
Getting this also.
Working on a pr for this https://github.com/wiltaylor/ds4/tree/fix/glm-gb10-cuda-streaming
A working commit is ba00a8a88c4c5810a3d1fed6b7b8fa2b44b82fdc
I hit this on a DGX Spark (GB10, sm_121, 121.63 GiB unified memory) with the 0731 q2/q4 hybrid GGUF (97.6 GB / 90.89 GiB of spans), and I think the root cause is narrower than "aligned artifacts are too big" — it's arena chunk sizing, and it's fixable with an existing env var.
What's actually happening
With the aligned artifacts enabled, replaces_complete works correctly: the expert residency is replaced and the model mmap is left unpinned, exactly as designed.
built 456 aligned CUDA artifacts (68.58 GiB) in 18.7s; expert raw residency replaced
CUDA aligned artifacts replace expert residency; leaving the 90.89 GiB model mmap unpinned
The remaining non-replaced tensor spans then get cached, and that's where it goes wrong:
CUDA model arena allocated 1792.00 MiB (arenas 12.25 GiB)
CUDA fd-cached tensor-span:7 1152.00 MiB (total 7.88 GiB)
12.25 GiB of arenas for 7.88 GiB of spans — 1.555×. The spans on this model are 1152 MiB and DS4_CUDA_WEIGHT_ARENA_CHUNK_MB defaults to 1792 MiB, so each chunk holds exactly one span and wastes 640 MiB (35.7%).
This model needs 28.45 GiB of non-replaced spans, so at the default chunk size that's 44.2 GiB of arenas. Add the artifacts and context and it's ~125 GiB on a 121.63 GiB box — OOM, at any context size. I confirmed context is not the variable: the failure is byte-identical at --ctx 393216 and --ctx 131072, same span, same offset.
The workaround
DS4_CUDA_WEIGHT_ARENA_CHUNK_MB=2304 # 2 x 1152 MiB spans per arena
With that, covered 28.45 GiB of tensor spans and the server loads and serves at the full --ctx 393216 in ~30 s.
A second finding, possibly worth separating
Q8_0_ALIGNED_DENSE is the one additive artifact (+6.15 GiB — the MoE kinds are byte-neutral replacements). On this box it costs more than it returns. Disabling it with DS4_CUDA_Q8_NO_ALIGNED=1 keeps replaces_complete intact (artifacts 456 → 111, 68.58 → 62.44 GiB, mmap still unpinned) and improved things:
| decode tok/s | free memory | |
|---|---|---|
| artifacts incl. Q8 dense | 17.08 | ~0–1.5 GiB |
DS4_CUDA_Q8_NO_ALIGNED=1 |
18.24 | ~7 GiB |
For reference, against the older build this machine was pinned to (80ebbc3), the working ae504c9 configuration gives prefill 373.7 → 686.2 tok/s (+83.6%) and decode 14.51 → 18.24 tok/s (+25.7%) at --ctx 393216, same GGUF, same prompt, both cold. (Steady state over 3 reps; the first rep is a consistent warm-up outlier in every arm.)
Suggested fix
Size the arena chunk from the span size rather than a fixed 1792 MiB default — either round the chunk up to a multiple of the largest span, or allow spans to pack across arenas. As it stands the default silently wastes 35.7% on any model whose spans don't divide 1792 MiB, and on a unified-memory box that's the difference between loading and not loading.
Happy to run further tests on this hardware if useful.