Skip to content

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

Merged
stikves merged 5 commits into
apple:mainfrom
stikves:feature/constrained-protocol-strategy
Aug 14, 2026
Merged

Add constrained generation protocol and pipelined strategy (3/4)#146
stikves merged 5 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

@carinapeng carinapeng 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.

Nice work, please consider comments before merging

- ConstrainedSessionHandle: clarify it is single-owner, not thread-safe
- Remove misleading warning about multi-token stops (handled by iterator)
- Add consecutive decode-failure guard (maxConsecutiveDecodeFailures=10)
- Document conformer obligations on ConstrainedGenerationCapable protocol
- Note that AsyncThrowingStream.AsyncIterator copy is safe (class-backed)
@stikves
stikves force-pushed the feature/constrained-protocol-strategy branch from 234d125 to dcc214a Compare August 14, 2026 00:26
@stikves
stikves merged commit 0bc7bc3 into apple:main Aug 14, 2026
3 checks passed
@stikves
stikves deleted the feature/constrained-protocol-strategy branch August 14, 2026 01:21
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.

3 participants