Repository navigation
Speculative decoding under a JSON schema: grammar-masked acceptance and grammar proposals - #391
Open
carinapeng wants to merge 1 commit into
Open
carinapeng wants to merge 1 commit into
carinapeng wants to merge 1 commit into
Conversation
Greedy speculative decoding accepts a grammar. The target's choice at each verified position is its argmax over the tokens the grammar allows, and the grammar advances by every emitted token, so the output is schema-valid and token-for-token identical to grammar-constrained greedy decoding of the target alone. A span the grammar fully determines (for example the key names of an object) is verified as the proposal in place of drafted tokens, trimmed to leave the last token to the target. The span is checked against the matcher and rolled back, so the grammar advances only when the decoder commits tokens. When a run stops before the end of an accepted block, the grammar is rolled back to the emitted stream. llm-runner accepts --json-schema with --draft-model and --prompt-lookup under greedy decoding, and gains --grammar-proposal-max (0 disables grammar proposals; default 7, at most 63, the grammar session's rollback budget less the anchor). Sampling with a schema is refused. Verification scores the full logits of each slot; a top-k shortcut is not part of this change.
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
llm-runnerrefused--json-schemawith speculative decoding because the verifier had no notion of the grammar. Greedy speculative decoding now runs under a grammar:llm-runner.--json-schemais accepted with--draft-modeland--prompt-lookupunder greedy decoding. New--grammar-proposal-max(default 7, 0 disables, at most 63). Sampling with a schema is refused.Verification scores full logits per slot; a top-k shortcut would need a new engine primitive and is not part of this change.
Testing
swift test --filter "Speculative|Grammar|Constrained|StaticShape|PromptLookup": 102 tests pass.swift format lintclean.The gain is bounded by how much of the output the schema forces.