-
Notifications
You must be signed in to change notification settings - Fork 2
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
Cfg beta #85
base: main
Are you sure you want to change the base?
Conversation
@@ -614,6 +617,8 @@ def __init__(self, conf: "LexerConf", states, always_accept=()): | |||
lexer_conf.terminals = [ | |||
terminals_by_name[n] for n in accepts if n in terminals_by_name | |||
] | |||
if not lexer_conf.terminals: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Enables returning EOS
token_history=lexer_state.last_token and [lexer_state.last_token], | ||
state=parser_state, | ||
terminals_by_name=self.root_lexer.terminals, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Fixes the following tests
- Multiple Valid Continuations
- Token is Substring of Another Token
- Recursive Patterns
db36739
to
5922b3b
Compare
Any updates on when this will be merged? Grammars via vLLM are completely broken atm. |
@w013nad Please track dottxt-ai#1067 I'll follow up this week and see if we can get this merged. |
Has this pr been available? I'd like to see the behavior of CFG via PartialLark. |
e763f29
to
b8d5b42
Compare
Fixes:
Rendered Docs: https://github.com/lapp0/outlines/blob/cfg-beta/docs/reference/creating_grammars.md
Changes
CFGGuide
CFGGuide
based on Brandon Willard's implementation inexamples/parsing.py
outlines.fsm.parsing
to handle some edge cases$END
is a legal next terminalCFGFSM
Grammars
ESCAPED_STRING
injson.lark
andcommon.lark
Integrations
outlines.generate.cfg(...)
viaSequenceGeneratorAdapter
outlines.processors.CFGLogitsProcessor
Testing
tests/fsm/test_cfg_guide.py
test_cfg_next_token
: assert that given a sequence of prior tokens generated, the expected next tokens in a vocabulary are allowed.test_cfg_grammar_sample
: Resurrected tests from an old PR which encode a sample which is valid with the grammar, and assert that the sequence of encoded tokens can be produced byCFGGuide
. Allows for a new test to be created by simply adding an example totests/cfg_samples/
test
outlines.generate.cfg
viatests/generate/test_generate.py
Benchmarks
benchmarks/bench_cfg_guide.py
: measureCFGGuide
construction time, token run time, and token run peak-memoryAnalysis
Regardless of length, 10 tokens, 40 tokens, or 100 tokens, it takes ~1.2 seconds to generate a token.
Unsurprisingly
get_next_instruction
takes most of the time, totaling over 99.99% of the runtime. It's intuitive considering the same operation is applied forget_next_state
, but for a single token instead of once for each of gpt2's 50,257 tokens.cProfile:
Future Work
(TODO: Move these to issues)
Improvements
Context-sensitive features such as pythons tree parser
Currently tree parser isn't supported dottxt-ai#592
Allow CFG in
outlines.serve
Remove
Guide.is_final_state
is_final_state
is ambiguous (dottxt-ai#885), in a separate PR we should removeis_final_state
Clean Up Dead Code
Remove
StopAtEosFSM
RegexFSM
StopAtEOSGuide
is useful anywhereBug Fixes
Ensure parser allows ambiguous terminals
(e.g.
?start: /ab*/ /bc?/
)Improve performance
Incorrectly Over-Constrained
arithmetic_lots_of_ops.arithmetic.test
- guide doesn't allow generation of eos token at endTODO
outlines.generate.cfg
CFGLogitsProcessor
test_generate.py
Notify these threads:
CFGFSM
LALR(1) dottxt-ai/outlines#588Separate PR
outlines.grammars.sql_select
and testssql_select_select_minimal_lalr1.sql.test
dottxt-ai#636
dottxt-ai#633