Add StaticInputHandler protocol for zero-allocation input filling - #188
Open
stikves wants to merge 7 commits into
Open
Add StaticInputHandler protocol for zero-allocation input filling#188stikves wants to merge 7 commits into
stikves wants to merge 7 commits into
Conversation
stikves
marked this pull request as ready for review
August 26, 2026 02:26
Introduces InputBuffers (pre-allocated, reused across steps) and the StaticInputHandler protocol (inout fill pattern). TokenStaticInputHandler fills input_ids and position_ids without per-step allocation. Wires the existing SyncInputHandler (TokenInputHandler) into the sequential engine, proving the protocol end-to-end. The engine now delegates input construction to handler.prepare() instead of inline fillNDArray calls. StaticShapeEngine (ANE) is unchanged.
stikves
force-pushed
the
sukru/input-handler-public
branch
from
August 27, 2026 05:33
d25b4fa to
1a4c832
Compare
Add StaticBucketInputFiller conforming to StaticInputHandler. It fills position_ids (UInt16), causal_mask (Float16), and step (Int32) into engine-owned InputBuffers in-place — no per-step allocation. The static engine now delegates input construction to the filler via the register/fill protocol. Embedding table and transformer_input (which require ANE gather invocation) remain engine-managed. Add contextBucket field to InputContext so the filler knows the current graph's context length for mask shape selection.
stikves
force-pushed
the
sukru/input-handler-public
branch
from
August 27, 2026 06:21
0d12561 to
54cff2d
Compare
tjia1818
approved these changes
Aug 27, 2026
carinapeng
reviewed
Aug 27, 2026
carinapeng
reviewed
Aug 27, 2026
carinapeng
reviewed
Aug 27, 2026
carinapeng
reviewed
Aug 27, 2026
carinapeng
reviewed
Aug 27, 2026
carinapeng
requested changes
Aug 27, 2026
carinapeng
left a comment
Contributor
There was a problem hiding this comment.
There are two blockers, suggest testing more and testing end to end before marking as review ready
For perf/CoW, I agree with you that maybe we want to switch to _modify
Rewrite StaticBucketInputFiller to pre-allocate all input NDArrays per (batchSize, contextBucket) pair at init from per-graph descriptors. Zero per-step allocation — bucket switch is an O(1) pool lookup. This matches the original RFC design (StaticBucketInputHandler with per-bucket BucketBuffers) but conforms to the StaticInputHandler protocol's inout fill pattern instead of returning a new dictionary. Add InputBuffers.preAllocate(name:descriptor:) for pooling NDArrays by shape at init, and ensureCapacity(name:descriptor:) for O(1) pool swap at runtime. These bypass resolvingDynamicDimensions entirely — static-shape models have all-fixed descriptors, no dynamic dims. Add InputBuffers.withMutableBuffer for COW-safe mutation through the dictionary's _modify accessor. Engine init now scans all extend/prompt functions to build the complete bucket descriptor table. Remove dead fillCausalMask — superseded by the handler.
stikves
force-pushed
the
sukru/input-handler-public
branch
3 times, most recently
from
August 28, 2026 16:43
f0c2192 to
4c5fee0
Compare
Addresses review: TokenStaticInputHandler was never wired into any engine. The sequential engine uses TokenInputHandler (SyncInputHandler), the static engine uses StaticBucketInputFiller (StaticInputHandler). Drop it until the sequential engine migration is ready.
stikves
force-pushed
the
sukru/input-handler-public
branch
from
August 28, 2026 17:04
d39698d to
372db91
Compare
Contributor
Author
They should be handled now, please take a look |
carinapeng
reviewed
Aug 31, 2026
carinapeng
reviewed
Aug 31, 2026
carinapeng
reviewed
Aug 31, 2026
carinapeng
reviewed
Aug 31, 2026
carinapeng
reviewed
Aug 31, 2026
carinapeng
reviewed
Aug 31, 2026
…ument COW Extract parseFunctionDimensions() to eliminate 5 duplicated context/query length parsing sites across StaticShapeEngine. Add resolveInputName() with known-name lists instead of fragile contains() matching. Rename asDict() to borrowedInputs() with ownership-contract docs. Add causalMaskSentinel constant shared across engines. Document COW risk on InputBuffers subscript get accessor.
carinapeng
approved these changes
Aug 31, 2026
carinapeng
left a comment
Contributor
There was a problem hiding this comment.
Let's do more testing before merging :)
added 2 commits
August 31, 2026 14:01
The model's step input is named in_step but knownStepNames only contained step, so the input was silently skipped. This caused in_step errors during graph evaluation on all static-shape models.
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.
Adds
InputBuffersandStaticInputHandler, a protocol for filling pre-allocated input buffers in-place without per-step allocation.Design
InputBuffers, creates once at init, passesinouteach step_modifyaccessor onInputBufferssubscript avoids COW (26× vs get/set)fill— handler holds no per-step stateSyncInputHandlerunchangedPrimary benefit is architectural (no COW risk, compile-time ownership via inout) rather than raw throughput.