-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the sequence generation #366
Merged
Merged
Conversation
This file contains 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
1e08ea5
to
18cecff
Compare
18cecff
to
c8eaf8b
Compare
rlouf
commented
Nov 21, 2023
rlouf
commented
Nov 21, 2023
615e550
to
0a11393
Compare
rlouf
commented
Nov 24, 2023
46299fe
to
8190126
Compare
This was referenced Dec 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
JSON
structured generation
Linked to structured generation
text
Linked to text generation
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.
In the current design the FSM that drives the generation process and the next token sampling are coupled, which makes adding new FSMs cumbersome. We also lack the possiblity to stream the tokens. In this PR I introduce a few changes to the core of the library:
Sequence
class now happens in agenerate_next_token
Python generator, which returns sampled tokens one at a time. This generator is responsible for calling the model, applying logit biases and sampling the next token.Regex
is factored out in a newprocess
generator. This generator is responsible for creating the logit biases, calling the models and concatenating the new token to the running sequence.After these changes are made there is a clear path to #335, #163, #155, #53.
Closes #317. Closes #340. Closes #266. Closes #247. Closes #216. Closes #185.
TODO
prompts.py
to the parent modulesample.py
tosampler(s).py
text
one level down so everything can be called viaoutlines.generate
token_ids
exceeds the context length;dataclass
orNamedTuple
Update and return the current sequence, last generated token ids, last logits and total sequence logprob in a single objectgenerator
can work with batches on inputs;processor
works with batches of sequencesoutlines.generate.sequence
andoutlines.stream.sequence
functions that build the generators.pad
tokens once an EOS token has been foundoutlines.generate.text
outlines.generate.regex
outlines.generate.format
outlines.generate.json
Return logits + sequence logprobAddstop_at
kwarg togenerate.text
for feature parityIndex
should beint
s andList[int]
index.py
->fsm.py
,/index
->/fsm
andfsm.py
->regex.py
Notes