File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,10 @@ uint32_t llama_hparams::n_embd_v_gqa(uint32_t il) const {
49
49
return n_embd_head_v * n_head_kv;
50
50
}
51
51
52
- uint32_t llama_hparams::n_embd_k_s () const {
52
+ uint32_t llama_hparams::n_embd_k_s (uint32_t il) const {
53
+ if (!recurrent_layer (il)) {
54
+ return 0 ;
55
+ }
53
56
if (wkv_head_size != 0 ) {
54
57
// for RWKV models
55
58
return token_shift_count * n_embd;
@@ -60,7 +63,10 @@ uint32_t llama_hparams::n_embd_k_s() const {
60
63
return (ssm_d_conv > 0 ? ssm_d_conv - 1 : 0 ) * ssm_d_inner;
61
64
}
62
65
63
- uint32_t llama_hparams::n_embd_v_s () const {
66
+ uint32_t llama_hparams::n_embd_v_s (uint32_t il) const {
67
+ if (!recurrent_layer (il)) {
68
+ return 0 ;
69
+ }
64
70
if (wkv_head_size != 0 ) {
65
71
// corresponds to RWKV's wkv_states size
66
72
return n_embd * wkv_head_size;
@@ -70,6 +76,10 @@ uint32_t llama_hparams::n_embd_v_s() const {
70
76
return ssm_d_state * ssm_d_inner;
71
77
}
72
78
79
+ bool llama_hparams::recurrent_layer (uint32_t il) const {
80
+ return recurrent_layer_arr[il];
81
+ }
82
+
73
83
bool llama_hparams::is_swa (uint32_t il) const {
74
84
if (il < n_layer) {
75
85
return n_swa > 0 && n_swa_pattern > 0 && il % n_swa_pattern < (n_swa_pattern - 1 );
Original file line number Diff line number Diff line change @@ -112,6 +112,9 @@ struct llama_hparams {
112
112
uint32_t ssm_d_state = 0 ;
113
113
uint32_t ssm_dt_rank = 0 ;
114
114
115
+ // for hybrid state space models
116
+ std::array<bool , LLAMA_MAX_LAYERS> recurrent_layer_arr;
117
+
115
118
bool ssm_dt_b_c_rms = false ;
116
119
117
120
float f_clamp_kqv = 0 .0f ;
@@ -158,10 +161,13 @@ struct llama_hparams {
158
161
159
162
// dimension of the rolling state embeddings
160
163
// corresponds to Mamba's conv_states size or RWKV's token_shift states size
161
- uint32_t n_embd_k_s () const ;
164
+ uint32_t n_embd_k_s (uint32_t il = 0 ) const ;
162
165
163
166
// dimension of the recurrent state embeddings
164
- uint32_t n_embd_v_s () const ;
167
+ uint32_t n_embd_v_s (uint32_t il = 0 ) const ;
168
+
169
+ // whether or not the given layer is recurrent (for hybrid models)
170
+ bool recurrent_layer (uint32_t il) const ;
165
171
166
172
bool is_swa (uint32_t il) const ;
167
173
};
You can’t perform that action at this time.
0 commit comments