Skip to content

Commit

Permalink
Clear cache for mistral
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler committed Dec 1, 2023
1 parent a6c3ec3 commit 753b887
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/openai/models/mistral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ impl Attention {
.reshape((b_sz, q_len, self.hidden_size))?
.apply(&self.o_proj)
}

fn clear_cache(&mut self) {
self.kv_cache = None;
}
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -404,4 +408,10 @@ impl Model {
.apply(&self.norm)?
.apply(&self.lm_head)
}

pub fn clear_cache(&mut self) {
for block in &mut self.layers {
block.self_attn.clear_cache();
}
}
}
2 changes: 2 additions & 0 deletions src/openai/pipelines/mistral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ impl<'s> ModulePipeline<'s> for Mistral7BPipeline {
}
}

self.mistral.clear_cache();

Ok((
Some(choices),
ChatCompletionUsageResponse {
Expand Down

0 comments on commit 753b887

Please sign in to comment.