Skip to content

Commit

Permalink
add note on grammar check in chop_tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Feb 26, 2025
1 parent ad8ca92 commit 5bc87e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/fast_forward.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ examples where `max_token==4` is not enough, we have not bee able to do so.
Note, that we can conservatively skip `grammar_allows()` check in the algorithm
above, and thus just compute once and for all the set of tokens that are not allowed
as the last token in forced bytes.
This drops the proportion of forced tokens in maskbench from `12.7%` to `12.1%`.

3 changes: 2 additions & 1 deletion toktrie/src/recognizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl<S: Copy + Debug, R: FunctionalRecognizer<S>> Recognizer for StackRecognizer

fn trie_finished(&mut self) {
// println!("{:?}", &self.stack[0..=self.stack_ptr]);
assert!(self.stack_ptr == 0);
// assert!(self.stack_ptr == 0);
self.stack_ptr = 0;
}

fn collapse(&mut self) {
Expand Down
4 changes: 4 additions & 0 deletions toktrie/src/toktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,10 @@ impl TokTrie {
let suff_bytes =
self.decode_raw(&tokens[tokens.len().saturating_sub(max_token_lookback)..]);
let suff_bytes = &suff_bytes[suff_bytes.len().saturating_sub(self.max_token_len())..];
// let suff_bytes = self.decode_raw(tokens);
// let suff_bytes = &suff_bytes[suff_bytes.len().saturating_sub(6)..];

// let mut anything_goes = StackRecognizer::from(AnythingGoes {});

for idx in 0..suff_bytes.len() {
let suff = &suff_bytes[idx..];
Expand Down

0 comments on commit 5bc87e2

Please sign in to comment.