mirror of
https://github.com/huggingface/candle.git
synced 2025-06-15 10:26:33 +00:00
Fix token generation in bilingual models (non-English outputs) (#1668)
Co-authored-by: Guoqing Bao <guoqing.bao@enflame-tech.com>
This commit is contained in:
@ -104,6 +104,7 @@ impl TextGeneration {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if let Some(t) = self.tokenizer.next_token(next_token)? {
|
if let Some(t) = self.tokenizer.next_token(next_token)? {
|
||||||
|
let t = t.replace("<|im_end|>", "\n");
|
||||||
print!("{t}");
|
print!("{t}");
|
||||||
std::io::stdout().flush()?;
|
std::io::stdout().flush()?;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ impl TokenOutputStream {
|
|||||||
};
|
};
|
||||||
self.tokens.push(token);
|
self.tokens.push(token);
|
||||||
let text = self.decode(&self.tokens[self.prev_index..])?;
|
let text = self.decode(&self.tokens[self.prev_index..])?;
|
||||||
if text.len() > prev_text.len() && text.chars().last().unwrap().is_ascii() {
|
if text.len() > prev_text.len() && text.chars().last().unwrap().is_alphabetic() {
|
||||||
let text = text.split_at(prev_text.len());
|
let text = text.split_at(prev_text.len());
|
||||||
self.prev_index = self.current_index;
|
self.prev_index = self.current_index;
|
||||||
self.current_index = self.tokens.len();
|
self.current_index = self.tokens.len();
|
||||||
|
Reference in New Issue
Block a user