Repository navigation
[Native] Separate the ggml engine's K/V storage from its sequence cache - #25006
Merged
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25006
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit bf8a09d with merge base 520c55b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Nov 13, 2026
JakeStevens
pushed a commit
that referenced
this pull request
Nov 18, 2026
### Stack Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own. - #24957 - #24956 - #25055 - #25009 - #25008 - #25007 - #25006 - #24955 - #24954 - #24951 - #24950 - #24949 - **#24947** (this PR) - #24946 - #24945 - #24944 - #24943 - #24639 - #24638 - #24637 - #24636 - #24635 - #24634 ### Summary `--gguf` excluded `--layers`, because every GGUF tensor must name a parameter and a truncated model has none for the later blocks. `gguf_to_hf` and `load_gguf` now take `truncated=True` to skip blocks past the model's last layer, and the export passes it when `--layers` is set. That exports a few layers of a large GGUF checkpoint to test the lowering quickly. Without the flag, a tensor that names no parameter still raises. ### Test plan - `test_gguf_hf.py`: a truncated model skips later blocks and still rejects unknown names. - `test_export_hf_llm.py`: a 1-layer model loaded from a 2-layer GGUF matches the reference cut to one layer exactly. --- Authored with Claude Code.
JakeStevens
force-pushed
the
offgraph-kv-ggml-kv-pool
branch
from
November 19, 2026 01:58
0c25e4c to
3551b67
Compare
This PR needs a
|
GgmlSequenceCache owned its K/V tensors, their growth, and the row copies a regrow makes. A cache of another layout needs the same storage, so it moves to GgmlKvPool, which the sequence cache now holds; the executor binds the pool's storage. Each pool layer records its window, which groups masks, and whether it is a ring, which decides whether attention reads all its rows or a prefix; the lowering keys off that rather than off the window. No change in behavior. Restacked with Codex.
JakeStevens
pushed a commit
that referenced
this pull request
Nov 19, 2026
### Stack Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own. - #24957 - #24956 - #25055 - #25009 - #25008 - #25007 - #25006 - #24955 - #24954 - #24951 - #24950 - **#24949** (this PR) - #24947 - #24946 - #24945 - #24944 - #24943 - #24639 - #24638 - #24637 - #24636 - #24635 - #24634 ### Summary Maps Muse Glimmer GGUF tensors onto the Hugging Face `MuseGlimmerForConditionalGeneration` parameters under `model.language_model`. - **Names:** gguf-py has no tensor map for the `muse-glimmer` architecture, so `gguf_hf` gets an explicit table, for architectures without one. The `attn_q_norm` / `attn_k_norm` tensors are skipped: the HF QK norm has no weight. llama.cpp's converter stores the query scale HF reads from the config (`qk_scale_factor`) as `attn_q_norm` and ones as `attn_k_norm`, so `load_gguf` checks them against the config (`check_config_tensors`) instead of dropping them silently. - **Conversion:** undoes llama.cpp's Q/K row permutation, as for Llama, and the 1 it adds to the four centered decoder norms. The final norm is a plain gain and stays as stored. ### Test plan - `test_gguf_hf.py`: names, conversions, and the QK norm check on a tiny Muse Glimmer. Needs a transformers with Muse Glimmer; skips otherwise. - The real GGUF's QK norms pass the check in all 52 layers (`attn_q_norm` = 3.87); a config with another scale is rejected. - On the first four layers of `Muse-Glimmer-30B-KQuant-17GB-Q4_K_M.gguf`, HF with this mapping matches Muse Glimmer's own model and GGUF loader to 4.9e-5 at FP32, with the same top token at every position. Dropping the Q/K un-permute or the norm offset breaks it (max errors 7.5 and 13.8). --- Authored with Claude Code.
JakeStevens
force-pushed
the
offgraph-kv-ggml-kv-pool
branch
from
November 19, 2026 14:13
3551b67 to
bf8a09d
Compare
JakeStevens
pushed a commit
that referenced
this pull request
Nov 19, 2026
### Stack Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own. - #24957 - #24956 - #25055 - #25009 - #25008 - #25007 - #25006 - #24955 - #24954 - #24951 - **#24950** (this PR) - #24949 - #24947 - #24946 - #24945 - #24944 - #24943 - #24639 - #24638 - #24637 - #24636 - #24635 - #24634 ### Summary `--verify_samples` streamed each generated token through `--tokenizer`, which only decodes Llama 3 vocabularies and threw on any other model's token IDs, though replay compares logits and never needs text. `generate()` now takes the tokenizer as optional and streams text only when given one; sample replay passes none. ### Test plan - Muse Glimmer packages, whose token IDs exceed Llama 3's vocabulary, replay their golden samples. - Existing packages still verify, and normal generation still streams text. --- Authored with Claude Code.
JakeStevens
pushed a commit
that referenced
this pull request
Nov 19, 2026
### Stack Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own. - #24957 - #24956 - #25055 - #25009 - #25008 - #25007 - #25006 - #24955 - #24954 - **#24951** (this PR) - #24950 - #24949 - #24947 - #24946 - #24945 - #24944 - #24943 - #24639 - #24638 - #24637 - #24636 - #24635 - #24634 ### Summary Exports Muse Glimmer through the native backend. - **Model class:** Transformers builds Muse Glimmer only as `MuseGlimmerForConditionalGeneration`, not through `AutoModelForCausalLM`. That class carries a vision tower and scans `input_ids` for image and video tokens, which the ggml engine can't run. The export builds it with `AutoModelForImageTextToText` and exports `MuseGlimmerTextLM` (new `muse_glimmer.py`) instead: its language model and LM head under their HF parameter names, with the output multiplier and logit soft cap. - **`--layers`:** also truncates its per-layer `layer_rope_theta`. - **Cache:** it exports only with `--offgraph_cache`, which carries its sliding windows. ``` python -m executorch.backends.native.examples.hf_llm.export_hf_llm \ --model <meta-models/Muse-Glimmer-30B dir> \ --gguf Muse-Glimmer-30B-KQuant-17GB-Q4_K_M.gguf \ --offgraph_cache --output mg.ptn ``` ### Test plan - `test_export_hf_llm.py`: off-graph golden samples of a tiny Muse Glimmer match HF's full multimodal model; one `update_and_attend` per layer and no `aten.eq`. Skips without a transformers that has Muse Glimmer. - Full 52-layer model (Q4_K_M, transformers 5.22.2): exports in ~3 min to a 15.6 GB `.ptn` with every weight packed. Its golden samples pass on Metal (max logit error 0.04–0.20) and CPU (0.43–0.62). `run_hf_llm_ggml` needs `--allow_activation_quant_for_weight_only` for its GGUF weights. Greedy continuation of "The capital of France is": " Paris. It is the". About 24 decode steps/s on an M4 Max. --- Authored with Claude Code.
JakeStevens
pushed a commit
that referenced
this pull request
Nov 19, 2026
### Stack Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own. - #24957 - #24956 - #25055 - #25009 - #25008 - #25007 - #25006 - #24955 - **#24954** (this PR) - #24951 - #24950 - #24949 - #24947 - #24946 - #24945 - #24944 - #24943 - #24639 - #24638 - #24637 - #24636 - #24635 - #24634 ### Summary The native LLM runner derived the off-graph KV cache a method needs in code private to the runner: layers from the `update_and_attend` calls, windows from the package metadata. This moves it to the header-only `backends/native/runtime/OffGraphCache.h`, along with the token bound that sizes a ring layer, so a serving executor builds the same cache. The runner's behavior is unchanged. ### Test plan The runner still verifies golden samples of a sliding-window package and a Muse Glimmer slice. --- Authored with Claude Code.
JakeStevens
pushed a commit
that referenced
this pull request
Nov 19, 2026
### Stack Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own. - #24957 - #24956 - #25055 - #25009 - #25008 - #25007 - #25006 - **#24955** (this PR) - #24954 - #24951 - #24950 - #24949 - #24947 - #24946 - #24945 - #24944 - #24943 - #24639 - #24638 - #24637 - #24636 - #24635 - #24634 ### Summary A serving runtime sizes its sessions from the context a package publishes, as MLX packages do with `get_max_context_len`, but native packages carried only the cache geometry. The off-graph export now also writes the model's `max_position_embeddings` under that name, or the export's `--max_seq_length` for a config without one. For an off-graph package this is the longest context the model supports; the runtime still sizes its own cache. The wrapper's `cache_metadata()` becomes `metadata()`, since it now carries more than the cache's geometry. ### Test plan - `test_export_hf_llm.py` on transformers 5.11.0 and 5.22.2. A full Muse Glimmer export publishes 131072. - CI: `.ci/scripts/test_native_llm_runner.py` adds an off-graph package with a 7-token method. The runner installs its cache from the package's metadata and prefills a 20-token prompt in chunks; its tokens match eager HF. --- Authored with Claude Code.
digantdesai
approved these changes
Nov 19, 2026
This branch was previously deployed
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.
Stack
Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own.
Summary
GgmlSequenceCacheowned its K/V tensors, their growth, and the row copies a regrow makes. The cell cache in the next PR needs the same storage, so it moves toGgmlKvPool, which the sequence cache now holds; the executor binds the pool's storage.Each pool layer records:
The lowering keys the read extent off
ringrather than off the window. That's the same for the sequence cache, but lets a cell cache's windowed layers read a prefix. No change in behavior.Test plan
Authored with Claude Code.