Skip to content

Commit

Permalink
Small performance fixup (negligible but obviously better).
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil committed Aug 1, 2024
1 parent 835f9a1 commit 41f258c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tokenizers/src/models/bpe/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ impl BPE {
}

fn tokenize_with_cache(&self, sequence: &str) -> Result<Vec<Token>> {
if let Some(ref hit) = self.cache.as_ref().and_then(|c| c.get(sequence)) {
return Ok(self.word_to_tokens(hit).collect());
}
if self.ignore_merges {
if let Some(id) = self.vocab.get(sequence) {
return Ok(vec![Token::new(*id, sequence.to_string().clone(), (0, 0))]);
}
}
if let Some(ref hit) = self.cache.as_ref().and_then(|c| c.get(sequence)) {
return Ok(self.word_to_tokens(hit).collect());
}
let word = self.merge_word(sequence)?;
let ret = self.word_to_tokens(&word).collect();
if let Some(ref cache) = self.cache {
Expand Down

0 comments on commit 41f258c

Please sign in to comment.