Skip to content

Commit

Permalink
fix crash in gctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed May 13, 2024
1 parent e4e10f3 commit 76f8abe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions controllers/guidance_ctrl/src/tokenparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ impl TokenParser {
infoln!("\n");
let trie = self.token_env.tok_trie();

infoln!("post tokens: {}", trie.tokens_dbg(&arg.tokens));
infoln!("post tokens: bt={} {}", arg.backtrack, trie.tokens_dbg(&arg.tokens));
arg.save_tokens(&mut self.llm_tokens);

let new_bytes = trie.decode(&arg.tokens);
self.llm_bytes.extend_from_slice(&new_bytes);

// TODO maybe remove in future
assert!(self.llm_bytes == trie.decode(&self.llm_tokens));
if self.llm_bytes != trie.decode(&self.llm_tokens) {
panic!(
"llm_bytes mismatch: {:?} {:?}",
String::from_utf8_lossy(&self.llm_bytes),
String::from_utf8_lossy(&trie.decode(&self.llm_tokens))
);
}

let res = self
.parser
Expand Down Expand Up @@ -169,8 +175,8 @@ impl TokenParser {
// here we remove a suffix from grm_tokens that could be possibly tokenized differently
grm_tokens.truncate(grm_tokens.len() - chop_tokens);

if grm_tokens.len() > 0 {
infoln!("fixed_tokens: {}", trie.tokens_dbg(&grm_tokens));
if grm_tokens.len() > 0 || backtrack > 0 {
infoln!("fixed_tokens: {} bt={}", trie.tokens_dbg(&grm_tokens), backtrack);
return MidProcessResult::splice(backtrack as u32, grm_tokens);
} else {
infoln!("no fixed tokens");
Expand Down
1 change: 1 addition & 0 deletions scripts/test-guidance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export AZURE_GUIDANCE_URL

cd $(dirname $0)/../py/guidance
pytest --selected_model azure_guidance tests/models/test_azure_guidance.py"$@"
pytest --selected_model azure_guidance_chat tests/models/test_azure_guidance_chat.py"$@"

0 comments on commit 76f8abe

Please sign in to comment.