cuda: fall back to pinned host memory when the model arena runs out of VRAM#487
Open
riccardo-galbani wants to merge 1 commit into
Open
cuda: fall back to pinned host memory when the model arena runs out of VRAM#487riccardo-galbani wants to merge 1 commit into
riccardo-galbani wants to merge 1 commit into
Conversation
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.
cuda_model_arena_alloc()would fail hard (return NULL,g_model_cache_full = 1) the momentcudaMallocfailed for a modelweight chunk. On GPUs where the non-routed (always-resident) weights
of a model exceed available VRAM, this made
--ssd-streamingunusable even though the model's routed experts would otherwise fit
comfortably via the existing streaming expert cache.
This adds a fallback: when the device allocation fails, allocate
pinned host memory (
cudaHostAllocwithcudaHostAllocMapped) andexpose it to the GPU via
cudaHostGetDevicePointer(zero-copy). Thiskeeps such models loadable and correct, at the cost of PCIe latency
on every access to the affected chunk. Set
DS4_CUDA_NO_PINNED_ARENA_FALLBACKto restore the previousfail-fast behavior.
Tested on a consumer laptop low memory CUDA GPU with a model whose
non-routed weights (8.20 GiB) exceed available VRAM. Previously
this crashed with an illegal memory access / OOM during prefill.
With this patch it loads and generates correctly, though slowly due
to PCIe round-trips on the pinned chunks:
ds4: CUDA model arena using pinned host RAM fallback for q8_0 (1792.00 MiB chunk, zero-copy device access)
ds4: CUDA model arena using pinned host RAM fallback for q8_0_pair0 (1792.00 MiB chunk, zero-copy device access)
ds4: CUDA model arena using pinned host RAM fallback for q8_hc_expand (1792.00 MiB chunk, zero-copy device access)
...
ds4: prefill: 0.52 t/s, generation: 0.58 t/s
On GPUs with enough VRAM for a model's non-routed weights, this
fallback never triggers and behavior is unchanged.