Repository navigation
test(prompt-cache): pin model-aware snapshot sizing for attention caches - #2129
Merged
Merged
Conversation
Issue #1761 reported that gemma3, llama4 and afmoe fell back to the fixed 512 MiB snapshot store and that `_text` model_type spellings missed the model-aware path. PR #1978 already added those families and the `_text` normalization; nothing covered them with the geometry the real checkpoints carry, so a regression would go unnoticed. The snapshot_sizing tests move to snapshot_sizing_tests.rs (the module was over 600 lines) and gain cases built from the on-disk configs of gemma-3-4b, llama-4-scout, gemma-4-12b (gemma4_unified_text), muse-glimmer-30b and an AFMoE config: each must take the model-aware path, size an unwindowed 8192-token entry, and skip the dense KV-store raise. Per-token estimates are asserted within 2% of first-turn boundary snapshots measured on GB10, and the Scout figure against the #1752 measurement. docs/environment-variables.md states the sizing formula, that the value is a cap rather than an allocation, and the measured effect on Gemma 3 4B and Gemma 4 12B. Validation on GB10: snapshot_sizing (14), kv_arch (28) and server::prompt_cache (184) tests, clippy --lib --tests --features cuda, fmt, and default-launch multi-turn mlxcel-server runs on three checkpoints against a 512 MiB control. Refs #1761
3 tasks done
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.
Summary
The code defects named in #1761 already landed in #1978 (
d7279c52):gemma3,llama4andafmoeare in the model-aware family list, andmodel_types()strips_text. This PR adds what the issue still required: tests built from the geometry the real checkpoints carry (including thegemma4_unified_textandmuse_glimmer_textspellings), the real-checkpoint measurement of the default memory change, and the policy wording indocs/environment-variables.md. The sizing module's tests move tosnapshot_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 oneentrywhen it fits inleft / 2.entryis the unwindowed snapshot atmin(ctx, 8192)tokens (8192 on a default launch) andleftis 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.gemma4_unified_text), 6 turns to 15.8kmuse_glimmer_text), 6 turns to 17.4kOn 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
prompt_cache::snapshot_sizing(14),execution::kv_arch(28),server::prompt_cache(184) with--features cuda --release,--test-threads=1cargo clippy --lib --tests --features cuda -- -D warnings,cargo fmt --checkNot verified on this host
cargo testandclippy --workspace(narrow selectors run instead).Closes #1761