Visitar URL original
[Native] Serve many sequences from one ggml engine KV cache by metascroy · Pull Request #25007 · pytorch/executorch · GitHub
Skip to content

[Native] Serve many sequences from one ggml engine KV cache - #25007

Draft
metascroy wants to merge 1 commit into
offgraph-kv-ggml-kv-poolfrom
offgraph-kv-ggml-cell-cache
Draft

metascroy wants to merge 1 commit into
offgraph-kv-ggml-kv-poolfrom
offgraph-kv-ggml-cell-cache

Conversation

@metascroy

@metascroy metascroy commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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

The ggml engine's off-graph cache held one sequence, so a batching runtime couldn't put several sessions in one forward, clone a prefix, or share a pool between sessions.

  • Cache: GgmlCellCache is the neutral CellCache over a GgmlKvPool whose rows are its cells, registered for kind::kBatched and kind::kBatchedCell. It offers BatchControl to the control plane.
  • Engine: a context accepts either cache through llm_cache_registry_key. With a cell cache, the executor:
    • places the forward's tokens at their positions before building the graph (the control plane declared their sequences);
    • grows storage to the step's read extent;
    • fills each window's cache rows and mask straight from the cache's step: rows are the step's cells, and the mask keeps each query to its own sequence's earlier cells within its window.
  • Windows: a windowed layer keeps every cell, so a rewind or clone never needs history the cache dropped.
  • Failure: a forward that fails after placement leaves its cells claimed, as a failed MLX forward does.

Test plan

New engine tests against a multi-sequence reference (naive attention per sequence):

  • two sequences prefilling separately, then decoding in one forward, with and without graph caching, on fp32 and fp16 storage, starting from one row so storage regrows;
  • a clone sharing its source's prefix as both continue, plus rewinds and closing the clone;
  • sliding windows, including inside a prefill wider than the window;
  • undeclared steps and positions that don't continue a sequence are refused.

All pass on CPU, and on Metal through a temporary local change. Making the executor ignore the cache's mask fails three of the four.


Authored with Claude Code.

The ggml engine's off-graph cache held one sequence, so a batching runtime
could not put several sessions in one forward, clone a prefix, or share a
pool between sessions. GgmlCellCache is the neutral CellCache over a
GgmlKvPool whose rows are its cells, registered for kind::kBatched and
kind::kBatchedCell; it offers BatchControl to the control plane.

A context accepts either cache. With a cell cache, the executor places the
forward's tokens at their positions before building the graph (the control
plane declared their sequences), grows storage to the step's read extent,
and fills each window's cache rows and mask from the cache's step: rows are
the step's cells, and the mask keeps each query to its own sequence's
earlier cells within its window. A windowed layer keeps every cell, so a
rewind or clone never needs history the cache dropped. A forward that fails
after placement leaves its cells claimed, as a failed MLX forward does.
@pytorch-bot

pytorch-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25007

Note: Links to docs will display an error until the docs builds have been completed.

❌ 136 New Failures, 7 Unrelated Failures, 10 Unclassified Failures

As of commit 3fbeb45 with merge base c7f7931 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 13, 2026
This was referenced Nov 13, 2026

This branch had an error being deployed

1 failed deployment
cadence — 3fbeb45b Deployed Nov 13, 2026 by metascroy via hifi-build / hifi4 #38147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant