@@ -34,6 +34,9 @@ struct llama_hparams_convnext {
3434};
3535
3636struct llama_hparams {
37+ // note: use the `_impl` suffix to avoid name conflict between members and getters
38+ // for example: n_embd_out() vs n_embd_out_impl
39+
3740 bool vocab_only;
3841 bool no_alloc;
3942 bool rope_finetuned;
@@ -43,7 +46,7 @@ struct llama_hparams {
4346 uint32_t n_ctx_train; // context size the model was trained on
4447 uint32_t n_embd;
4548 uint32_t n_layer;
46- int32_t n_layer_kv_from_start = -1 ; // if non-negative, the first n_layer_kv_from_start layers have KV cache
49+ int32_t n_layer_kv_from_start = -1 ; // if non-negative, the first n_layer_kv_from_start layers have KV cache
4750 uint32_t n_expert = 0 ;
4851 uint32_t n_expert_used = 0 ;
4952 uint32_t n_rel_attn_bkts = 0 ;
@@ -134,12 +137,16 @@ struct llama_hparams {
134137 llama_swa_type swa_type = LLAMA_SWA_TYPE_NONE ;
135138 // the size of the sliding window (0 - no SWA)
136139 uint32_t n_swa = 0 ;
140+
137141 // if is_swa_impl[il] == 1, then layer il is SWA
138142 // if is_swa_impl[il] == 0, then layer il is dense (i.e. non-SWA)
139143 // by default, all layers are dense
140144 // note: using uint32_t type for compatibility reason
141145 std::array<uint32_t , LLAMA_MAX_LAYERS > is_swa_impl;
142146
147+ // for hybrid state space models
148+ std::array<uint32_t , LLAMA_MAX_LAYERS > is_recr_impl;
149+
143150 // for State Space Models
144151 uint32_t ssm_d_conv = 0 ;
145152 uint32_t ssm_d_inner = 0 ;
@@ -150,9 +157,6 @@ struct llama_hparams {
150157 // for Kimi Linear KDA
151158 uint32_t n_embd_head_kda = 0 ;
152159
153- // for hybrid state space models
154- std::array<uint32_t , LLAMA_MAX_LAYERS > is_recr_impl;
155-
156160 bool ssm_dt_b_c_rms = false ;
157161
158162 float f_clamp_kqv = 0 .0f ;
@@ -255,6 +259,14 @@ struct llama_hparams {
255259 // return true if one of the layers is SWA
256260 bool is_swa_any () const ;
257261
262+ bool is_swa (uint32_t il) const ;
263+
264+ // TODO: implement
265+ // void set_recr_pattern(uint32_t n_pattern, bool dense_first = false);
266+
267+ // whether or not the given layer is recurrent (for hybrid models)
268+ bool is_recr (uint32_t il) const ;
269+
258270 uint32_t n_head (uint32_t il = 0 ) const ;
259271
260272 uint32_t n_head_kv (uint32_t il = 0 ) const ;
@@ -296,13 +308,8 @@ struct llama_hparams {
296308 // dimension of the recurrent state embeddings
297309 uint32_t n_embd_s () const ;
298310
299- // whether or not the given layer is recurrent (for hybrid models)
300- bool is_recurrent (uint32_t il) const ;
301-
302311 uint32_t n_pos_per_embd () const ;
303312
304- bool is_swa (uint32_t il) const ;
305-
306313 // note: currently only support if either all or none of the layers are MLA
307314 bool is_mla () const ;
308315
0 commit comments