Add constrained generation protocol and pipelined strategy (3/4) - #146
Open
stikves wants to merge 3 commits into
Open
Add constrained generation protocol and pipelined strategy (3/4)#146stikves wants to merge 3 commits into
stikves wants to merge 3 commits into
Conversation
…rategy Introduce the abstraction layer for GPU-accelerated grammar-constrained decoding, independent of the engine implementation: - ConstrainedGenerationCapable: protocol for engines that support GPU-side bitmask application during sampling - ConstrainedSessionHandle: thread-safe wrapper around ConstrainedGenerationSession with checkout/checkin cache pattern - PipelinedConstrainedDecodingStrategy: AsyncSequence-based strategy that drives constrained token generation through a capable engine - Integration tests with MockConstrainedEngine covering session lifecycle, cache reuse, stop sequences, and error paths
stikves
requested review from
alejandro-isaza,
carinapeng,
kevchengcodes and
tjia1818
August 7, 2026 20:30
stikves
marked this pull request as ready for review
August 7, 2026 20:30
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.
Summary
Introduces the abstraction layer for GPU-accelerated grammar-constrained decoding, split out from #114 for independent review:
ConstrainedGenerationCapableprotocol: capability signal for engines that support GPU-side bitmask application during samplingConstrainedSessionHandle: thread-safe wrapper aroundConstrainedGenerationSessionwith checkout/checkin cache pattern for reuse across callsPipelinedConstrainedDecodingStrategy:AsyncSequence-based strategy that drives constrained token generation through a capable engine, with single-use iteration guardMockConstrainedEnginecovering session lifecycle, cache reuse, schema invalidation, stop sequences, and error pathsThis PR contains no engine implementation — a follow-up PR (4/4) will add the
CoreAIPipelinedEngineconformance and CLI wiring.Dependencies
Builds on top of:
Test plan
xcodebuild build-for-testing -scheme CoreAILMpassesPipelinedConstrainedIntegrationTestssuite passes (mock-only, no GPU required)