@@ -6486,7 +6486,7 @@ def prepare_tensors(self):
6486
6486
self .gguf_writer .add_max_alibi_bias (self .max_alibi_bias )
6487
6487
6488
6488
6489
- @ModelBase .register ("Glm4ForCausalLM" )
6489
+ @ModelBase .register ("Glm4ForCausalLM" , "Glm4vForConditionalGeneration" )
6490
6490
class Glm4Model (TextModel ):
6491
6491
model_arch = gguf .MODEL_ARCH .GLM4
6492
6492
@@ -6508,14 +6508,22 @@ def set_vocab(self):
6508
6508
6509
6509
def set_gguf_parameters (self ):
6510
6510
super ().set_gguf_parameters ()
6511
- rope_dim = self .hparams ["head_dim" ]
6511
+ if (rope_dim := self .hparams .get ("head_dim" )) is None :
6512
+ rope_dim = self .hparams ["hidden_size" ] // self .hparams ["num_attention_heads" ]
6512
6513
self .gguf_writer .add_rope_dimension_count (int (rope_dim * self .hparams .get ("partial_rotary_factor" , 0.5 )))
6513
6514
rope_scaling = self .hparams .get ("rope_scaling" ) or {}
6514
6515
if rope_scaling .get ("rope_type" , rope_scaling .get ("type" )) == "yarn" and "factor" in rope_scaling :
6515
6516
self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
6516
6517
self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
6517
6518
self .gguf_writer .add_rope_scaling_orig_ctx_len (rope_scaling ["original_max_position_embeddings" ])
6518
6519
6520
+ def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
6521
+ if name .startswith ("model.visual." ): # ignore visual part of Glm4v
6522
+ return []
6523
+ elif name .startswith ("model.language_model." ):
6524
+ name = name .replace ("language_model." , "" ) # for Glm4v
6525
+ return super ().modify_tensors (data_torch , name , bid )
6526
+
6519
6527
6520
6528
@ModelBase .register ("GlmForCausalLM" , "ChatGLMModel" , "ChatGLMForConditionalGeneration" )
6521
6529
class ChatGLMModel (TextModel ):
0 commit comments