llama : fix NaN default tensor split when devices report zero free memory - #27647
Draft
jebbadee wants to merge 1 commit into
Draft
llama : fix NaN default tensor split when devices report zero free memory#27647jebbadee wants to merge 1 commit into
jebbadee wants to merge 1 commit into
Conversation
…mory When no tensor_split is provided, load_tensors sizes the split points by free device memory. If every device reports free == 0 with total != 0 (e.g. Windows/WDDM after another model filled VRAM - the common case when loading a speculative draft model second), split_sum is 0 and the normalization computes 0/0 = NaN for every split point. upper_bound over NaNs then returns past-the-end and devices.at(layer_gpu) throws out_of_range, surfacing as 'error loading model: invalid vector subscript'. Guard the zero sum and fall back to an even split instead. Fixes ggml-org#24795 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PwFYMMdiGG5jC3mdZcafxK
|
Hi @jebbadee, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
This was referenced Sep 2, 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.
Fixes #24795 ("invalid vector subscript" loading MTP draft models — regression b9553→b9702).
Root cause
When no
tensor_splitis provided,llama_model_base::load_tensorssizes the default split points by free device memory. If every device reportsfree == 0withtotal != 0— which Windows/WDDM CUDA commonly does once VRAM is filled, i.e. exactly when a speculative draft model loads second after the target —split_sumis 0 and the normalization computes0/0 = NaNfor every split point.std::upper_boundover NaNs returns past-the-end, anddevices.at(layer_gpu)throwsout_of_range("invalid vector subscript" on the MSVC STL), surfacing aserror loading model: invalid vector subscript.This is why the crash looked MTP/arch-specific in #24795: the draft is just the model that loads second. Reproduced with both gemma4-assistant (OP) and qwen35 (Qwen3.8-27B-MTP-ONLY) drafters.
Fix
Guard the zero sum and fall back to an even split (with a warning) instead of dividing by zero.
Verification
Experiments on Windows 11, RTX 4090 Laptop 16 GB, official b10581/b10603 CUDA 12.4 builds, Qwen3.8-27B UD-Q3_K_XL target + a4lg/Qwen3.8-27B-MTP-ONLY-GGUF Q4_K_M draft via
--spec-type draft-mtp --spec-draft-model:--ctx-size 512(VRAM headroom left when the draft loads)--ctx-size 8192/65536--ctx-size 8192/65536+--fit off--ctx-size 8192/65536+ explicit--tensor-split 1(skips the free-memory branch)The explicit-
--tensor-splitresult isolates the free-memory branch as the crash site; thefree==0+ NaN mechanism is the only failure path in it that ends atdevices.at(). Patch build compiles and passes a load test (CPU build; no local CUDA toolchain to rebuild the CUDA backend, but the change is backend-agnostic host code).Full write-up with logs in #24795 (comment).
🤖 Generated with Claude Code
https://claude.ai/code/session_01PwFYMMdiGG5jC3mdZcafxK