Conversation
setRequiredPrefix(sequence, bytes) makes the next generation begin with the given bytes: while any remain, every token whose text is inconsistent with them is masked before sampling, and each sampled token consumes what it covers. A caller completing a half-typed word prompts up to the word boundary, so the tokenizer sees whole words rather than a word cut at an arbitrary byte, and requires the completion to start with the boundary whitespace plus the typed letters. Token texts are cached at model load so the mask costs one pass over the vocabulary per constrained token; a row with no consistent token drops the constraint instead of sampling from an all-masked distribution.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
CotabbyInferenceEngine::setRequiredPrefix(sequence, utf8, length)makes the next generation on a sequence begin with the given bytes. While any remain, every token whose text is inconsistent with them is masked before sampling (the seed indecodePromptand eachsampleNext), each sampled token consumes the bytes it covers, and the constraint clears once they have all been produced.Why
Completing a word the user has half typed ("…the draft yest") works poorly with the partial word in the prompt: the tokenizer sees a word cut at an arbitrary byte, and the model tends to continue another word or produce a misspelled tail. With this constraint the caller prompts up to the word boundary, so the tokenizer sees whole words, and requires the completion to begin with the boundary whitespace plus the typed letters (" yest"), so the model finishes the user's word (" yesterday"). Cotabby uses it for every mid-word request: FuJacob/cotabby#827.
Details
token_pieces), so the mask costs one pass over the vocabulary per constrained token, and nothing when no prefix is set.Tests
testRequiredPrefixConstrainsTheStartOfTheCompletion(model-backed): with " yest" required after "Thanks for sending over the draft", the completion begins " yesterday".testRequiredPrefixIsClearedByAnEmptyPrefixAndIgnoredWithoutASequence.