Skip to content

[Native] Add a batching executor for native-backend packages - #25055

Draft
metascroy wants to merge 1 commit into
offgraph-kv-selected-logitsfrom
offgraph-kv-native-executor
Draft

metascroy wants to merge 1 commit into
offgraph-kv-selected-logitsfrom
offgraph-kv-native-executor

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

NativeExecutor, in the new backends/native/batching/, serves a .ptn exported with --offgraph_cache --logits_to_keep selected behind extension/llm/batching. It's the native counterpart of ModuleExecutor, as CudaExecutor in backends/cuda/batching/ is for CUDA.

  • Setup: reads the cache geometry and context length from the package, and builds the engine's batched cache with room for every resident session's context. Storage grows with the cells in use.
  • Sessions: they're the cache's sequences, through SessionTable. A batch puts several sessions in one forward; each forward declares its sequences and selects the logits row each input wants. A clone shares its source's cells.
  • Engine-neutral: the config takes a host factory and the CacheFactory backend ID of that engine's caches, as the native LLM runner does. A model's serving code picks ggml (or another engine with a batched cache) and adds only its own preparation.

Build: native_batching is installed and exported, so out-of-tree projects such as the Muse Glimmer example link it. There's also a Buck target.

Test plan

native_batching_test, given a toy package from test/export_toy_llm.py (ET_NATIVE_BATCHING_PTN; skips without one):

  • sessions decoded together in one batch get exactly the greedy tokens they get alone;
  • a clone continues as its source, including after a prompt wider than the method's token bound;
  • one batch carrying a session's decode and another's prompt wider than the method, so the prompt's last token is selected in a later forward, matches both sessions alone;
  • a batch the cache refuses fails without changing the session, which then continues as it would have.

All pass. Making the engine ignore the cache's mask fails the batching test. The Buck target is unverified.


Authored with Claude Code.

@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/25055

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

❌ 132 New Failures, 1 Cancelled Job, 2 Pending, 7 Unrelated Failures, 26 Unclassified Failures

As of commit 39b07a5 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:

CANCELLED JOB - The following job was cancelled. Please retry:

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
@metascroy
metascroy force-pushed the offgraph-kv-native-executor branch from 834004e to a52159c Compare November 14, 2026 00:18
NativeExecutor, in backends/native/batching, serves a .ptn exported with
--offgraph_cache --logits_to_keep selected behind extension/llm/batching:
the native counterpart of ModuleExecutor, as CudaExecutor is for CUDA. It
reads the cache geometry and context length from the package, builds the
engine's batched cache with room for every resident session's context, and
serves sessions as the cache's sequences through SessionTable. A batch puts
several sessions in one forward; each forward declares its sequences and
selects the logits row each input wants; a clone shares its source's cells.

The engine is the caller's: the config takes a host factory and the
CacheFactory backend id of that engine's caches, as the native LLM runner
does, so a model's serving code picks ggml (or another engine with a batched
cache) and adds only its own preparation.

native_batching_test, given a package from test/export_toy_llm.py, checks
that sessions decoded together in one batch get the tokens they get alone
and that a clone continues as its source; it skips without one.

This branch had an error being deployed

1 failed deployment
cadence — 39b07a58 Deployed Nov 14, 2026 by metascroy via vision-build / vision #38344
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