mistralrs_core/dummy_paged_attention/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pub trait ModelConfigLike {
    fn num_layers(&self) -> usize;
    fn hidden_size(&self) -> usize;
    fn num_kv_heads(&self) -> usize;
    fn num_attn_heads(&self) -> usize;
    fn k_head_dim(&self) -> usize {
        self.hidden_size() / self.num_attn_heads()
    }
    fn v_head_dim(&self) -> usize {
        self.hidden_size() / self.num_attn_heads()
    }
}

#[derive(Clone)]
pub struct ModelConfigMetadata {
    pub num_layers: usize,
    pub hidden_size: usize,
    pub num_kv_heads: usize,
    pub num_attn_heads: usize,
    pub sliding_window: Option<usize>,
    pub k_head_dim: Option<usize>,
    pub v_head_dim: Option<usize>,
}

impl ModelConfigLike for ModelConfigMetadata {
    fn hidden_size(&self) -> usize {
        self.hidden_size
    }
    fn num_attn_heads(&self) -> usize {
        self.num_attn_heads
    }
    fn num_kv_heads(&self) -> usize {
        self.num_kv_heads
    }
    fn num_layers(&self) -> usize {
        self.num_layers
    }
    fn k_head_dim(&self) -> usize {
        self.k_head_dim
            .unwrap_or(self.hidden_size() / self.num_attn_heads())
    }
    fn v_head_dim(&self) -> usize {
        self.v_head_dim
            .unwrap_or(self.hidden_size() / self.num_attn_heads())
    }
}