Skip to content

Commit a12363b

Browse files
convert : text-only support for GLM-4.1V-9B-Thinking (#14823)
* use language_model part only, ignore visual layers * fix rope_dim calculation
1 parent a86f52b commit a12363b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

convert_hf_to_gguf.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6486,7 +6486,7 @@ def prepare_tensors(self):
64866486
self.gguf_writer.add_max_alibi_bias(self.max_alibi_bias)
64876487

64886488

6489-
@ModelBase.register("Glm4ForCausalLM")
6489+
@ModelBase.register("Glm4ForCausalLM", "Glm4vForConditionalGeneration")
64906490
class Glm4Model(TextModel):
64916491
model_arch = gguf.MODEL_ARCH.GLM4
64926492

@@ -6508,14 +6508,22 @@ def set_vocab(self):
65086508

65096509
def set_gguf_parameters(self):
65106510
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"]
65126513
self.gguf_writer.add_rope_dimension_count(int(rope_dim * self.hparams.get("partial_rotary_factor", 0.5)))
65136514
rope_scaling = self.hparams.get("rope_scaling") or {}
65146515
if rope_scaling.get("rope_type", rope_scaling.get("type")) == "yarn" and "factor" in rope_scaling:
65156516
self.gguf_writer.add_rope_scaling_type(gguf.RopeScalingType.YARN)
65166517
self.gguf_writer.add_rope_scaling_factor(rope_scaling["factor"])
65176518
self.gguf_writer.add_rope_scaling_orig_ctx_len(rope_scaling["original_max_position_embeddings"])
65186519

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+
65196527

65206528
@ModelBase.register("GlmForCausalLM", "ChatGLMModel", "ChatGLMForConditionalGeneration")
65216529
class ChatGLMModel(TextModel):

0 commit comments

Comments
 (0)