Skip to content

Enable batched attention for LLM exports - #334

Merged
stikves merged 3 commits into
apple:mainfrom
stikves:sukru/public-batched-stage1-export
Oct 18, 2026
Merged

stikves merged 3 commits into
apple:mainfrom
stikves:sukru/public-batched-stage1-export

Conversation

@stikves

@stikves stikves commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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 N export flags, an
    AttentionMaskMode export mode, and the use_attention_mask model plumbing.
    Default is off, so existing exports are byte-identical and the standard is_causal contract is
    untouched (masked-vs-causal parity is covered by tests).
  • Conditional metadata version: a batched LLM bundle (max_batch_size > 1) stamps
    metadata_version 0.3 and carries a max_batch_size field; every other model still keeps 0.2 version.

Scope / behavior

  • macOS only; iOS and the paged mode are rejected with explicit errors.
  • A model exported as 0.3 is intentionally not runnable until the runtime stage lands

…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 stikves changed the title Opt-in batched / attention-mask LLM export (conditional 0.3 metadata) Enable batched attention for LLM exports Oct 9, 2026
@stikves
stikves marked this pull request as ready for review October 9, 2026 00:51
Comment thread python/src/coreai_models/export/pipeline.py Outdated
Comment thread python/src/coreai_models/export/pipeline.py Outdated
Comment thread python/src/coreai_models/_constants.py
@tjia1818 tjia1818 closed this Oct 12, 2026
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.
@stikves stikves reopened this Oct 17, 2026
@stikves
stikves merged commit f98640a into apple:main Oct 18, 2026
3 checks passed
@stikves
stikves deleted the sukru/public-batched-stage1-export branch October 18, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants