Repository navigation
GGUF: honest KV and context in residency, device-fit context rule, clear context-full failure - #9
Merged
Merged
Conversation
…it context rule; prompts longer than the context fail clearly before eval
…stored as calibration; streamed context refusal converted; skip reason names holders by label
lpalbou
added a commit
that referenced
this pull request
Oct 29, 2026
…ys-so 0862: a GGUF context that fills up mid-request is freed and fails in words (stacked on #9)
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.
Found on the Linux test server (Quadro RTX 5000 16 GB, gateway 0.17.x): the Models page showed
Qwen3.5-9B-Kimi-k3-Distilled-GGUFas "~5.4 GiB + 8.3 GiB cache" while the GPU held 9.1 GiB in total, and the log repeateddecode: failed to find a memory slot for batch of size 512.Causes
hf_residency.llama_kv_alloc_bytescomputedn_ctx * block_count * 2 * kv_heads * head_dim * 2: all 33 blocks counted as attention. qwen35 has a KV cache on one block in four (full_attention_interval = 4): 2.0 GiB at 65,536 tokens, not 8.25 GiB._gguf_prefill_prompt_cacheevaluated a prompt longer thann_ctx; llama.cpp ran out of KV cells, the lane retried cold, rebuilt the engine, failed again and answered "Error: failed to prefill GGUF prompt cache (RuntimeError: llama_decode returned 1)" as content (reproduced with real weights on the server: 3 failures, ~10 s, an engine reload per request).Fixes
utils/kv_geometry.py: one layer walk (hybrid interval, per-layer kv heads, SWA layers/widths, shared/MTP layers, V padding, recurrent state) used by residency rows,context_estimateand the load.read_gguf_geometryreads the layout keys and per-layer arrays.context_length,kv_cache_bytes,kv_cache_estimated; the pool claim'scache_bytes= KV + prompt caches (same as process rows).max_tokensuntouched; smallest rung always kept. Documented in docs/memory-management.md.ContextWindowExceededError(InvalidRequestError): raised before eval when the prompt does not fit, and for llama-cpp-python's own "exceed context window" refusal; passes through the GGUF catch-alls. Decoding that reaches n_ctx ends withfinish_reason="length"+metadata.context_exhausted.Tests:
tests/providers/test_gguf_kv_context_honesty_unit.py(11; mutation-checked: interval ignored, metadata-only geometry, no pre-check, no device rule each turn it red). 252 related existing tests green.Server check (real weights, CPU, n_ctx 1024, 1,102-token prompt, with and without a cache key): fails in 0.0 s with "This conversation is 1,102 tokens, but ... is loaded with a 1,024-token context on this machine ..."; no memory-slot lines; the next requests answer.