Repository navigation
fix: size prompt-cache stores for large models, clarify MTP declines - #1978
Merged
Merged
Conversation
Gemma 4 31B QAT on GB10 reported cached=0 on every turn and an MTP decline that read as "target is not Gemma 4". Both reproduced. Prompt cache: one snapshot (2.97 GB boundary, 1.11 GB completion) exceeded the 512 MiB store, so every insert was rejected at DEBUG. The model-aware raise never applied because it read only `text_config.model_type` (`gemma4_text`, and `qwen3_5_text` zeroed Qwen 3.5's recurrent term), treated `context_size == 0` as 32 tokens, sized sliding layers window-capped although boundary snapshots are unwrapped, and ignored Gemma 4's global-layer geometry. All four are fixed; the ceiling now comes from memory left after the model, with a one-entry floor. The dense-KV store gets the same model-aware default (Llama 3.1 8B at 17k tokens needed 2.24 GB against 2 GiB). Oversized rejects on either store now log one WARN naming the flag. MiniCPM-V 4.6 never forwarded the snapshot methods to its Qwen 3.5 backbone; it does now, guarded by a source-scan test. MTP: the decline names the probe verdict and logs once per process; the Metal-only qmv_wide retry is skipped on other backends. The fail-closed default is unchanged. Validation: default-launch multi-turn sweep over 28 local checkpoints on GB10 (31B QAT: 8.8 s to 0.68 s per turn), 1017 related unit tests, clippy, fmt.
This was referenced Sep 26, 2026
7 tasks
inureyes
added a commit
that referenced
this pull request
Sep 26, 2026
Gemma 3 text_config often omits num_attention_heads, num_key_value_heads, head_dim, and sliding_window_pattern (gemma-3-4b-it-4bit carries only hidden_size, intermediate_size, num_hidden_layers, sliding_window). Without them, attn_dims fell back to num_heads=1 and head_dim=hidden_size/1, which misclassified the model as plain standard attention and overstated its per-token KV footprint by about 2.6x, inflating the #1978 prompt-cache snapshot capacity default, estimate_total_memory, and mlxcel inspect for this family. classify now fills in the HF Gemma3TextConfig defaults (num_attention_heads 8, num_key_value_heads 4, head_dim 256, sliding_window_pattern 6) for model_type gemma3 / gemma3_text whenever the corresponding field is absent, leaving any explicit config value untouched, and other families unchanged. Verified on gemma-3-4b-it-4bit: the startup line now reports architecture=sliding-window (5 global / 29 windowed layers) and 139,264 bytes/token, matching the real snapshot measurement, down from the previous 348,160 bytes/token standard-attention misclassification. Closes #1980
3 tasks
3 tasks done
inureyes
added a commit
that referenced
this pull request
Oct 6, 2026
…hes (#2129) ## Summary The code defects named in #1761 already landed in #1978 (`d7279c52`): `gemma3`, `llama4` and `afmoe` are in the model-aware family list, and `model_types()` strips `_text`. This PR adds what the issue still required: tests built from the geometry the real checkpoints carry (including the `gemma4_unified_text` and `muse_glimmer_text` spellings), the real-checkpoint measurement of the default memory change, and the policy wording in `docs/environment-variables.md`. The sizing module's tests move to `snapshot_sizing_tests.rs` (the file was 643 lines). No runtime code changes, so this does not touch admission or restore. ## Default policy `capacity = max(512 MiB, min(6 * entry, left / 4))`, raised to one `entry` when it fits in `left / 2`. `entry` is the unwindowed snapshot at `min(ctx, 8192)` tokens (8192 on a default launch) and `left` is memory after the model's estimated footprint. It is a cap, not an allocation: resident bytes grow only as snapshots are inserted. An explicit flag or env value is never replaced. ## Measurement (GB10, default launch, multi-turn `mlxcel-server`) "Before" is the same binary with `MLXCEL_PROMPT_CACHE_SNAPSHOT_CAPACITY_BYTES=536870912`, which marks the capacity explicit and skips the raise (`startup.rs`), reproducing the fixed bucket the issue describes. | Checkpoint | Capacity | Peak stored | Oversized rejects | Snapshot hits | Last turn | |---|---|---|---|---|---| | gemma-3-4b-it-4bit, 8 turns to 31.8k tokens | 512 MiB -> 6.375 GiB | 532 MB -> 2.02 GB | 13 -> 0 | 15/16 both; before stalls at cached=19918 from turn 6 | 15.5 s -> 2.07 s | | gemma-4-12b-it-4bit (`gemma4_unified_text`), 6 turns to 15.8k | 512 MiB -> 15.75 GiB | 512 MB -> 4.39 GB | 8 -> 0 | 0/12 -> 11/12 | 37.7 s -> 4.3 s | | muse-glimmer-30b-4bit (`muse_glimmer_text`), 6 turns to 17.4k | 512 MiB -> 2.44 GiB | 315 MB -> 739 MB | 0 -> 0 | 5/6 both; self-evictions 6 -> 0 | 7.4 s both | On Gemma 4 12B the "before" completion entries fit, but the next-turn warm-ups were all skipped (0 run, 6 skipped against 5 run, 0 skipped after) once the boundary entries (0.9 to 5.4 GB) were rejected, so no turn hit. Per-token estimates against first-turn boundary snapshots: 139,264 vs 140,847 measured (Gemma 3), 344,064 vs 345,330 (Gemma 4 unified), 53,248 vs 53,465 (Muse Glimmer), all within 1.2% and now asserted at 2%. ## Test plan - [x] `prompt_cache::snapshot_sizing` (14), `execution::kv_arch` (28), `server::prompt_cache` (184) with `--features cuda --release`, `--test-threads=1` - [x] `cargo clippy --lib --tests --features cuda -- -D warnings`, `cargo fmt --check` - [x] Real multi-turn runs above ## Not verified on this host - Llama 4 Scout real run: the checkpoint is 57 GB, over this host's 40 GB rule. Covered by a unit test against the #1752 measurement (192 KiB per token, within 1%). - AFMoE real run: no local checkpoint; unit test only. - Metal, and the issue's workspace-wide `cargo test` and `clippy --workspace` (narrow selectors run instead). Closes #1761
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.
Gemma 4 31B QAT on GB10 showed
cached=0on every turn of one conversation, and its assistant drafter was declined with a message that read as "target is not Gemma 4". Both reproduced on this host.Prompt cache
Every snapshot (2.97 GB boundary, 1.11 GB completion) was larger than the 512 MiB snapshot store and rejected at DEBUG. The existing model-aware raise never applied:
text_config.model_type(gemma4_text); Qwen 3.5 VLM checkpoints (qwen3_5_text) got a zero recurrent-state term for the same reason. Both spellings are now matched, and Gemma 3, Llama 4, AFMoE, and Inkling are included.context_size == 0(no--ctx-size) was sized as 32 tokens, which also disabled the Qwen3.8 raise at default launch.The ceiling is now a quarter of the memory left after the model's estimated footprint, with a one-entry floor. The dense-KV store gets the same model-aware default (Llama 3.1 8B at 17k tokens needed 2.24 GB against the fixed 2 GiB). An oversized reject on either store logs one WARN naming the flag. MiniCPM-V 4.6 did not forward the snapshot methods to its Qwen 3.5 backbone and never cached; a source-scan test guards the wrappers.
MTP
On CUDA the verify block differs from the single-token chain (226171 of 524288 logit bytes at position 0), so the fail-closed policy declines; that default is unchanged. The decline now states the probe verdict and
MLXCEL_MTP_ALLOW_INEXACT, once per process, and the Metal-only qmv_wide retry is skipped elsewhere. With the override, 31B QAT decodes 1.3 to 1.8x faster with near-tie divergence from classic.Validation
Follow-ups for the unfixed findings are filed separately.