Skip to content

Add constrained generation protocol and pipelined strategy (3/4) - #146

Open
stikves wants to merge 3 commits into
apple:mainfrom
stikves:feature/constrained-protocol-strategy
Open

Add constrained generation protocol and pipelined strategy (3/4)#146
stikves wants to merge 3 commits into
apple:mainfrom
stikves:feature/constrained-protocol-strategy

Conversation

@stikves

@stikves stikves commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces the abstraction layer for GPU-accelerated grammar-constrained decoding, split out from #114 for independent review:

  • ConstrainedGenerationCapable protocol: capability signal for engines that support GPU-side bitmask application during sampling
  • ConstrainedSessionHandle: thread-safe wrapper around ConstrainedGenerationSession with checkout/checkin cache pattern for reuse across calls
  • PipelinedConstrainedDecodingStrategy: AsyncSequence-based strategy that drives constrained token generation through a capable engine, with single-use iteration guard
  • Integration tests with MockConstrainedEngine covering session lifecycle, cache reuse, schema invalidation, stop sequences, and error paths

This PR contains no engine implementation — a follow-up PR (4/4) will add the CoreAIPipelinedEngine conformance and CLI wiring.

Dependencies

Builds on top of:

Test plan

  • xcodebuild build-for-testing -scheme CoreAILM passes
  • PipelinedConstrainedIntegrationTests suite passes (mock-only, no GPU required)

…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 stikves self-assigned this Aug 5, 2026
@stikves stikves added the enhancement New feature or request label Aug 5, 2026
@stikves
stikves marked this pull request as ready for review August 7, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant