-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Check the full vocab for grammar only if necessary #4306
Merged
ggerganov
merged 8 commits into
ggerganov:master
from
kalomaze:conditional-grammar-check
Dec 23, 2023
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2e3b4f6
Check the full vocab for grammar only if necessary
kalomaze 281e2ba
Fix missing logit restoration step (?)
kalomaze de454b9
Fix whitespace / formatting
kalomaze 245de1f
Adjust comment
kalomaze f5f9d96
Didn't mean to push test gbnf
kalomaze 115a921
Split sampling into the helper function (?)
kalomaze b4377ee
Merge branch 'master' into conditional-grammar-check
ggerganov 88fd22c
common : fix final newline
ggerganov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Adjust comment
- Loading branch information
commit 245de1fc67905a9fceb6d7f050d1d066cf1d077e
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
root ::= [ \t\n]* exp | ||
|
||
ws ::= [ \t\n]+ | ||
w ::= [ \t]* | ||
|
||
comment ::= "#" [^#]* "#" [ \t]+ [\n]? [ \t]* | ||
|
||
### Expressions | ||
|
||
exp ::= comment* sequence-exp | ||
|
||
sequence-exp ::= tuple-exp (w ";" ws tuple-exp)* | ||
|
||
tuple-exp ::= cons-exp (w "," ws cons-exp)* | ||
|
||
cons-exp ::= binary-exp (w "::" w binary-exp)* | ||
|
||
binary-exp ::= unary-exp (ws binary-op ws unary-exp)* | ||
|
||
unary-exp ::= unary-op* function-app-exp | ||
|
||
function-app-exp ::= primary-exp (w "(" w exp w ")" w)* | ||
|
||
primary-exp ::= bool | | ||
integer | | ||
float | | ||
string | | ||
variable | | ||
"()" | | ||
"[]" | | ||
constructor | | ||
constructor-app | | ||
parenthesized-exp | | ||
list-exp | | ||
let-exp | | ||
if-exp | | ||
case-exp | | ||
test-exp | | ||
type-alias | | ||
fun | ||
|
||
constructor-app ::= constructor "(" w exp w ")" | ||
parenthesized-exp ::= "(" w exp w ")" | ||
list-exp ::= "[" exp ("," ws exp)* "]" | ||
let-exp ::= "let" ws pat ws "=" ws exp ws "in" ws exp | ||
if-exp ::= "if" ws exp ws "then" ws exp ws "else" ws exp | ||
case-exp ::= "case" ws exp (ws "|" ws pat ws "=>" ws exp)+ ws "end" | ||
test-exp ::= "test" ws exp ws "end" | ||
type-alias ::= "type" ws constructor ws "=" ws typ ws "in" ws exp | ||
fun ::= "fun" ws pat ws "->" ws exp | ||
|
||
type-variable ::= [a-z][A-Za-z0-9_]* | ||
constructor ::= [A-Z][A-Za-z0-9_]* | ||
variable ::= ([_a-bdg-hj-kn-qu-z][A-Za-z0-9_.]*)|(("s" ([.0-9A-Z_a-su-z][A-Za-z0-9_.]*)?)|("st" ([.0-9A-Z_a-qs-z][A-Za-z0-9_.]*)?)|("str" ([.0-9A-Z_a-tv-z][A-Za-z0-9_.]*)?)|("stru" ([.0-9A-Z_a-bd-z][A-Za-z0-9_.]*)?)|("struc" ([.0-9A-Z_a-su-z][A-Za-z0-9_.]*)?)|("struct" [A-Za-z0-9_.]+)|("c" ([.0-9A-Z_b-z][A-Za-z0-9_.]*)?)|("ca" ([.0-9A-Z_a-rt-z][A-Za-z0-9_.]*)?)|("cas" ([.0-9A-Z_a-df-z][A-Za-z0-9_.]*)?)|("case" [A-Za-z0-9_.]+)|("i" ([.0-9A-Z_a-mo-z][A-Za-z0-9_.]*)?)|("in" [A-Za-z0-9_.]+)|("r" ([.0-9A-Z_a-df-z][A-Za-z0-9_.]*)?)|("re" ([.0-9A-Z_a-bd-z][A-Za-z0-9_.]*)?)|("rec" [A-Za-z0-9_.]+)|("t" ([.0-9A-Z_a-df-z][A-Za-z0-9_.]*)?)|("te" ([.0-9A-Z_a-rt-z][A-Za-z0-9_.]*)?)|("tes" ([.0-9A-Z_a-su-z][A-Za-z0-9_.]*)?)|("test" [A-Za-z0-9_.]+)|("l" ([.0-9A-Z_a-df-z][A-Za-z0-9_.]*)?)|("le" ([.0-9A-Z_a-su-z][A-Za-z0-9_.]*)?)|("let" [A-Za-z0-9_.]+)|("m" ([.0-9A-Z_b-z][A-Za-z0-9_.]*)?)|("ma" ([.0-9A-Z_a-su-z][A-Za-z0-9_.]*)?)|("mat" ([.0-9A-Z_a-bd-z][A-Za-z0-9_.]*)?)|("matc" ([.0-9A-Z_a-gi-z][A-Za-z0-9_.]*)?)|("match" [A-Za-z0-9_.]+)|("f" ([.0-9A-Z_a-tv-z][A-Za-z0-9_.]*)?)|("fu" ([.0-9A-Z_a-mo-z][A-Za-z0-9_.]*)?)|("fun" [A-Za-z0-9_.]+)|("e" ([.0-9A-Z_a-mo-z][A-Za-z0-9_.]*)?)|("en" ([.0-9A-Z_a-ce-z][A-Za-z0-9_.]*)?)|("end" [A-Za-z0-9_.]+)) | ||
bool ::= "true" | "false" | ||
integer ::= [0-9]+ | ||
float ::= [0-9]* "." [0-9]+ | ||
string ::= "\"" [^"]* "\"" | ||
|
||
unary-op ::= "-" | "!" | ||
binary-op-int ::= "+" | "-" | "*" | "/" | "<" | ">" | "<=" | ">=" | "==" | "!=" | ||
binary-op-float ::= "+." | "-." | "*." | "/." | "<." | ">." | "<=." | ">=." | "==." | "!=." | ||
binary-op-string ::= "$==" | "@" | ||
binary-op-logic ::= "&&" | ||
binary-op ::= binary-op-int | binary-op-float | binary-op-string | binary-op-logic | ||
|
||
### Patterns | ||
|
||
pat ::= type-ascription-pat | ||
|
||
type-ascription-pat ::= tuple-pat (w ":" ws typ)* | ||
|
||
tuple-pat ::= cons-pat (w "," ws cons-pat)* | ||
|
||
cons-pat ::= primary-pat (w "::" w primary-pat)* | ||
|
||
primary-pat ::= | ||
bool | | ||
integer | | ||
float | | ||
string | | ||
variable | | ||
"()" | | ||
"[]" | | ||
"_" | | ||
constructor | | ||
constructor-app-pat | | ||
parenthesized-pat | | ||
list-pat | ||
|
||
constructor-app-pat ::= constructor "(" w pat w ")" | ||
parenthesized-pat ::= "(" w pat w ")" | ||
list-pat ::= "[" pat (w "," ws pat)* "]" | ||
|
||
### Types | ||
|
||
typ ::= arrow-typ | ||
|
||
arrow-typ ::= tuple-typ (ws "->" ws tuple-typ)* | ||
|
||
tuple-typ ::= primary-typ (w "," ws primary-typ)* | ||
|
||
primary-typ ::= | ||
"Unit" | | ||
"Int" | | ||
"Float" | | ||
"Bool" | | ||
"String" | | ||
type-variable | | ||
constructor | | ||
constructor-def (ws "+" ws constructor-def)+ | | ||
parenthesized-typ | | ||
list-typ | ||
|
||
parenthesized-typ ::= "(" w typ w ")" | ||
list-typ ::= "[" w typ w "]" | ||
constructor-def ::= constructor | constructor "(" w typ w ")" |
Oops, something went wrong.
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.
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.
We should merge this after we fix this:
is_resampling
is an implementation detail and should not be exposed in the API, because somebody can start using it or get confused what it is for.Change
llama_sampling_sample
to not acceptis_resampling
and to callllama_sampling_sample_impl
which in turn acceptsis_resampling
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.
Will look into this soon