Skip to content

State handling for static-shape inference engine - #160

Open
carinapeng wants to merge 4 commits into
apple:mainfrom
carinapeng:carina/static-engine-runner-design
Open

State handling for static-shape inference engine#160
carinapeng wants to merge 4 commits into
apple:mainfrom
carinapeng:carina/static-engine-runner-design

Conversation

@carinapeng

Copy link
Copy Markdown
Contributor

Purpose

Static-shape LLM inference engine (StaticShapeEngine) built on the bind(into:) state binding from #156. States are discovered by name and the KV cache is right-sized per context bucket; ctx is parsed from the function name. Input preparation is pluggable per model family via StaticInputProvider + StaticModelProfile; StaticInputContext composes the shared InputContext and the provider mirrors SyncInputHandler.

Testing: LanguageModelsTests (317) pass; correct output on static assets.

@carinapeng
carinapeng force-pushed the carina/static-engine-runner-design branch 2 times, most recently from 6265330 to 50693ed Compare August 10, 2026 22:47
- Right-size KV cache per context bucket
- Extend shared SyncInputHandler / InputContext (drop Static* fork)
- Unit tests + gemma4/qwen static verified
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/StaticModelProfile.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/StaticModelProfile.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/StaticModelProfile.swift Outdated
@carinapeng
carinapeng force-pushed the carina/static-engine-runner-design branch 4 times, most recently from 4bbfe62 to 6af4562 Compare August 12, 2026 16:55
@carinapeng
carinapeng force-pushed the carina/static-engine-runner-design branch from 6af4562 to f8ed131 Compare August 12, 2026 16:58

@blevine1 blevine1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes looks good to me in general given the pre-existing design, but I'd consider zooming out and potentially changing some details of the "input handler" structure/interface at a later point. It is a pretty thick abstraction that'll limit what performance can be achieved.

Left some comments mostly about structure and readability.

Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/StaticModelProfile.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/StaticModelProfile.swift Outdated
Comment thread swift/Sources/CoreAILanguageModels/InferenceEngines/StaticModelProfile.swift Outdated
@carinapeng
carinapeng force-pushed the carina/static-engine-runner-design branch from 9f2706b to 09f695d Compare August 12, 2026 23:43
@carinapeng

Copy link
Copy Markdown
Contributor Author

@blevine1 Thanks Ben! Agree with your comments, the SyncInputHandler abstraction (existentials + prepare -> [String: NDArray]) is inherited, so I'd like to keep the interface change out of this PR. I'll file a follow up to revisit the handler structure / interface. Appreciate the review!

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.

3 participants