1use burn::tensor::backend::Backend;
2use burn::tensor::Tensor;
3
4#[derive(Clone, Debug)]
5pub struct MsaCache<B: Backend> {
6 pub k_cache: Tensor<B, 4>,
7 pub v_cache: Tensor<B, 4>,
8 pub k_idx_cache: Tensor<B, 4>,
9}
10
11impl<B: Backend> MsaCache<B> {
12 pub fn new(k: Tensor<B, 4>, v: Tensor<B, 4>, k_idx: Tensor<B, 4>) -> Self {
13 Self {
14 k_cache: k,
15 v_cache: v,
16 k_idx_cache: k_idx,
17 }
18 }
19
20 pub fn update(self, new_k: Tensor<B, 4>, new_v: Tensor<B, 4>, new_k_idx: Tensor<B, 4>) -> Self {
21 Self {
22 k_cache: Tensor::cat(vec![self.k_cache, new_k], 2),
23 v_cache: Tensor::cat(vec![self.v_cache, new_v], 2),
24 k_idx_cache: Tensor::cat(vec![self.k_idx_cache, new_k_idx], 2),
25 }
26 }
27}