Skip to content

Commit

Permalink
propagate to unigram
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurZucker committed Oct 21, 2024
1 parent 6e0175a commit ab3236f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions bindings/python/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ impl PyBPE {

fn clear_cache(self_: PyRef<Self>){
let super_ = self_.as_ref();
let model = super_.model.read().unwrap();
if let ModelWrapper::BPE(ref mo) = *model {
let mut model = super_.model.write().unwrap();
if let ModelWrapper::Unigram(ref mut mo) = *model {
mo.clear_cache()
} else {
unreachable!()
Expand Down Expand Up @@ -868,6 +868,16 @@ impl PyUnigram {
)),
}
}

fn clear_cache(self_: PyRef<Self>){
let super_ = self_.as_ref();
let mut model = super_.model.write().unwrap();
if let ModelWrapper::Unigram(ref mut mo) = *model {
mo.clear_cache()
} else {
unreachable!()
};
}
}

/// Models Module
Expand Down
4 changes: 4 additions & 0 deletions tokenizers/src/models/unigram/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ impl Unigram {
let string = read_to_string(path)?;
Ok(serde_json::from_str(&string)?)
}

pub fn clear_cache(&mut self){
self.cache.clear();
}
}

/// Iterator to iterate of vocabulary of the model, and their relative score.
Expand Down

0 comments on commit ab3236f

Please sign in to comment.