@@ -1388,10 +1388,10 @@ def set_gguf_parameters(self):
1388
1388
self .gguf_writer .add_layer_norm_rms_eps (self .hparams ["rms_norm_eps" ])
1389
1389
self .gguf_writer .add_file_type (self .ftype )
1390
1390
1391
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
1392
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "linear" :
1393
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
1394
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
1391
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
1392
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "linear" and "factor" in rope_scaling :
1393
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
1394
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
1395
1395
1396
1396
def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
1397
1397
head_count = self .hparams ["num_attention_heads" ]
@@ -1512,10 +1512,10 @@ def set_gguf_parameters(self):
1512
1512
self .gguf_writer .add_layer_norm_rms_eps (self .hparams ["rms_norm_eps" ])
1513
1513
self .gguf_writer .add_file_type (self .ftype )
1514
1514
1515
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
1516
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "linear" :
1517
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
1518
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
1515
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
1516
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "linear" and "factor" in rope_scaling :
1517
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
1518
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
1519
1519
1520
1520
def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
1521
1521
del bid # unused
@@ -1828,10 +1828,10 @@ def set_gguf_parameters(self):
1828
1828
rope_dim = hparams ["hidden_size" ] // hparams ["num_attention_heads" ]
1829
1829
self .gguf_writer .add_rope_dimension_count (rope_dim )
1830
1830
1831
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
1832
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "linear" :
1833
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
1834
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
1831
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
1832
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "linear" and "factor" in rope_scaling :
1833
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
1834
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
1835
1835
1836
1836
@staticmethod
1837
1837
def permute (weights : Tensor , n_head : int , n_head_kv : int | None ):
@@ -2206,10 +2206,10 @@ def set_gguf_parameters(self):
2206
2206
rope_dim = hparams ["hidden_size" ] // hparams ["num_attention_heads" ]
2207
2207
self .gguf_writer .add_rope_dimension_count (rope_dim )
2208
2208
2209
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
2210
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "linear" :
2211
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
2212
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
2209
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
2210
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "linear" and "factor" in rope_scaling :
2211
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
2212
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
2213
2213
2214
2214
@staticmethod
2215
2215
def permute (weights : Tensor , n_head : int , n_head_kv : int | None ):
@@ -2449,10 +2449,10 @@ def set_gguf_parameters(self):
2449
2449
logit_scale = self .hparams ["hidden_size" ] / self .hparams ["dim_model_base" ]
2450
2450
self .gguf_writer .add_logit_scale (logit_scale )
2451
2451
logger .info (f"gguf: (minicpm) logit_scale = { logit_scale } " )
2452
- if self .hparams .get ("rope_scaling" ) is not None :
2453
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "longrope" :
2454
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LONGROPE )
2455
- logger .info (f"gguf: (minicpm) rope_scaling_type = { gguf .RopeScalingType .LONGROPE } " )
2452
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
2453
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" ) ) == "longrope" :
2454
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LONGROPE )
2455
+ logger .info (f"gguf: (minicpm) rope_scaling_type = { gguf .RopeScalingType .LONGROPE } " )
2456
2456
2457
2457
def generate_extra_tensors (self ) -> Iterable [tuple [str , Tensor ]]:
2458
2458
rope_dims = self .hparams ["hidden_size" ] // self .hparams ["num_attention_heads" ]
@@ -2597,11 +2597,11 @@ def set_vocab(self):
2597
2597
def set_gguf_parameters (self ):
2598
2598
super ().set_gguf_parameters ()
2599
2599
self ._try_set_pooling_type ()
2600
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
2601
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "yarn" :
2602
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
2603
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
2604
- self .gguf_writer .add_rope_scaling_orig_ctx_len (self . hparams [ " rope_scaling" ] ["original_max_position_embeddings" ])
2600
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
2601
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "yarn" and "factor" in rope_scaling :
2602
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
2603
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
2604
+ self .gguf_writer .add_rope_scaling_orig_ctx_len (rope_scaling ["original_max_position_embeddings" ])
2605
2605
2606
2606
def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
2607
2607
if self .hf_arch == "Qwen2Model" :
@@ -2763,11 +2763,11 @@ def set_gguf_parameters(self):
2763
2763
logger .info (f"gguf: expert shared feed forward length = { shared_expert_intermediate_size } " )
2764
2764
# YaRN is not enabled by default
2765
2765
# To enable it, please refer to this guide: https://huggingface.co/Qwen/Qwen3-30B-A3B#processing-long-texts
2766
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
2767
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "yarn" :
2768
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
2769
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
2770
- self .gguf_writer .add_rope_scaling_orig_ctx_len (self . hparams [ " rope_scaling" ] ["original_max_position_embeddings" ])
2766
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
2767
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "yarn" and "factor" in rope_scaling :
2768
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
2769
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
2770
+ self .gguf_writer .add_rope_scaling_orig_ctx_len (rope_scaling ["original_max_position_embeddings" ])
2771
2771
2772
2772
_experts : list [dict [str , Tensor ]] | None = None
2773
2773
@@ -3035,7 +3035,7 @@ def generate_extra_tensors(self) -> Iterable[tuple[str, Tensor]]:
3035
3035
3036
3036
scale = max_pos_embds / orig_max_pos_embds
3037
3037
3038
- rope_scaling_type = rope_scaling .get ('type' , '' ).lower ()
3038
+ rope_scaling_type = rope_scaling .get ('rope_type' , rope_scaling . get ( ' type' , '' ) ).lower ()
3039
3039
if len (rope_scaling_type ) == 0 :
3040
3040
raise KeyError ('Missing the required key rope_scaling.type' )
3041
3041
@@ -3347,10 +3347,10 @@ def set_gguf_parameters(self):
3347
3347
self .gguf_writer .add_layer_norm_rms_eps (self .hparams ["rms_norm_eps" ])
3348
3348
self .gguf_writer .add_head_count_kv (self .hparams ["num_key_value_heads" ])
3349
3349
self .gguf_writer .add_file_type (self .ftype )
3350
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
3351
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "linear" :
3352
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
3353
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
3350
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
3351
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "linear" and "factor" in rope_scaling :
3352
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
3353
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
3354
3354
3355
3355
def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
3356
3356
num_heads = self .hparams ["num_attention_heads" ]
@@ -3425,10 +3425,10 @@ def set_gguf_parameters(self):
3425
3425
rope_dim = hparams ["hidden_size" ] // hparams ["num_attention_heads" ]
3426
3426
self .gguf_writer .add_rope_dimension_count (rope_dim )
3427
3427
3428
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
3429
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "linear" or self . hparams [ "rope_scaling" ]. get ( "rope_type" ) == "linear" :
3430
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
3431
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
3428
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
3429
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "linear" and "factor" in rope_scaling :
3430
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
3431
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
3432
3432
3433
3433
def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
3434
3434
n_head = self .hparams ["num_attention_heads" ]
@@ -4866,12 +4866,12 @@ def set_gguf_parameters(self):
4866
4866
4867
4867
self .gguf_writer .add_rope_dimension_count (hparams ["qk_rope_head_dim" ])
4868
4868
4869
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
4870
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "yarn" :
4871
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
4872
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
4873
- self .gguf_writer .add_rope_scaling_orig_ctx_len (self . hparams [ " rope_scaling" ] ["original_max_position_embeddings" ])
4874
- self .gguf_writer .add_rope_scaling_yarn_log_mul (0.1 * hparams [ " rope_scaling" ] ["mscale_all_dim" ])
4869
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
4870
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "yarn" and "factor" in rope_scaling :
4871
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
4872
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
4873
+ self .gguf_writer .add_rope_scaling_orig_ctx_len (rope_scaling ["original_max_position_embeddings" ])
4874
+ self .gguf_writer .add_rope_scaling_yarn_log_mul (0.1 * rope_scaling ["mscale_all_dim" ])
4875
4875
4876
4876
_experts : list [dict [str , Tensor ]] | None = None
4877
4877
@@ -5363,11 +5363,11 @@ def set_gguf_parameters(self):
5363
5363
super ().set_gguf_parameters ()
5364
5364
rope_dim = self .hparams ["head_dim" ]
5365
5365
self .gguf_writer .add_rope_dimension_count (int (rope_dim * self .hparams .get ("partial_rotary_factor" , 0.5 )))
5366
- if self .hparams .get ("rope_scaling" ) is not None and "factor" in self . hparams [ "rope_scaling" ]:
5367
- if self . hparams [ "rope_scaling" ] .get ("type" ) == "yarn" :
5368
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
5369
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
5370
- self .gguf_writer .add_rope_scaling_orig_ctx_len (self . hparams [ " rope_scaling" ] ["original_max_position_embeddings" ])
5366
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
5367
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "yarn" and "factor" in rope_scaling :
5368
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
5369
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
5370
+ self .gguf_writer .add_rope_scaling_orig_ctx_len (rope_scaling ["original_max_position_embeddings" ])
5371
5371
5372
5372
5373
5373
@ModelBase .register ("GlmForCausalLM" , "ChatGLMModel" , "ChatGLMForConditionalGeneration" )
@@ -5600,10 +5600,10 @@ def set_gguf_parameters(self):
5600
5600
rotary_factor = self .find_hparam (["partial_rotary_factor" , "rope_pct" ], optional = True )
5601
5601
rotary_factor = rotary_factor if rotary_factor is not None else 1.0
5602
5602
self .gguf_writer .add_rope_dimension_count (int (rotary_factor * (hparams ["hidden_size" ] // hparams ["num_attention_heads" ])))
5603
- if hparams .get ("rope_scaling" ) is not None and "factor" in hparams [ "rope_scaling" ]:
5604
- if hparams [ " rope_scaling" ] .get ("type" ) == "linear" :
5605
- self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
5606
- self .gguf_writer .add_rope_scaling_factor (hparams [ " rope_scaling" ] ["factor" ])
5603
+ rope_scaling = self . hparams .get ("rope_scaling" ) or {}
5604
+ if rope_scaling . get ( "rope_type" , rope_scaling .get ("type" )) == "linear" and "factor" in rope_scaling :
5605
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
5606
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
5607
5607
5608
5608
def generate_extra_tensors (self ) -> Iterable [tuple [str , Tensor ]]:
5609
5609
if rope_scaling := self .find_hparam (["rope_scaling" ], optional = True ):
@@ -5706,10 +5706,11 @@ def set_gguf_parameters(self):
5706
5706
rope_dim = hparams .get ("head_dim" ) or hparams ["hidden_size" ] // hparams ["num_attention_heads" ]
5707
5707
5708
5708
self .gguf_writer .add_rope_dimension_count (rope_dim )
5709
- if (self .hparams .get ("rope_scaling" ) or {}).get ("type" ) == "yarn" and "factor" in self .hparams ["rope_scaling" ]:
5709
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
5710
+ if rope_scaling .get ("rope_type" , rope_scaling .get ("type" )) == "yarn" and "factor" in rope_scaling :
5710
5711
self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
5711
- self .gguf_writer .add_rope_scaling_factor (self . hparams [ " rope_scaling" ] ["factor" ])
5712
- self .gguf_writer .add_rope_scaling_orig_ctx_len (self . hparams [ " rope_scaling" ] ["original_max_position_embeddings" ])
5712
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
5713
+ self .gguf_writer .add_rope_scaling_orig_ctx_len (rope_scaling ["original_max_position_embeddings" ])
5713
5714
else :
5714
5715
self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .NONE )
5715
5716
self .gguf_writer .add_leading_dense_block_count (hparams ["first_k_dense_replace" ])
0 commit comments