Repository navigation
Enable batched attention for LLM exports - #334
Merged
Merged
Conversation
…etadata Introduce opt-in macOS attention-mask / dynamic-batch export for LLMs: - Add the --attention-mask and --dynamic-batch-size CLI flags, the AttentionMaskMode export mode, and the use_attention_mask model plumbing (default off, so existing exports are byte-identical; masked-vs-causal parity is covered by test_qwen3_attention_mask). - Make the LLM metadata schema conditional: a batched bundle (max_batch_size > 1, exported with --attention-mask batched) stamps metadata_version 0.3 and carries the max_batch_size field, while every single-sequence bundle stays on 0.2 and omits the field. Other bundle kinds (diffusion/segmentation/VLM) are untouched and remain on 0.2, so current runtimes keep running existing models. First stage of the batched model export and serving work; the runtime that consumes 0.3 bundles lands in a later stage.
stikves
requested review from
carinapeng,
guru-desh,
kevchengcodes,
pkmandke,
srjoglekar246 and
tjia1818
October 9, 2026 00:50
stikves
marked this pull request as ready for review
October 9, 2026 00:51
Move use_attention_mask forwarding into build_model after the export pipeline split. Hoist the default dynamic batch max into DEFAULT_DYNAMIC_MAX_BATCH_SIZE and drop the iOS check that the attn_mask check already covers.
srjoglekar246
approved these changes
Oct 18, 2026
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.
First stage of batched model export & serving
Export only
This adds the opt-in path that produces batched / attention-mask LLM bundles. The runtime will follow up.
What this adds
--attention-mask [default|batched|paged]and--dynamic-batch-size Nexport flags, anAttentionMaskModeexport mode, and theuse_attention_maskmodel plumbing.Default is off, so existing exports are byte-identical and the standard
is_causalcontract isuntouched (masked-vs-causal parity is covered by tests).
max_batch_size > 1) stampsmetadata_version0.3 and carries amax_batch_sizefield; every other model still keeps 0.2 version.Scope / behavior
pagedmode are rejected with explicit errors.