Skip to content

Commit 9f8a776

Browse files
Using with tensor map
1 parent 0aef94b commit 9f8a776

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

convert_hf_to_gguf.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4900,27 +4900,6 @@ def set_gguf_parameters(self):
49004900
self.gguf_writer.add_rope_scaling_factor(self.hparams["rope_scaling"]["factor"])
49014901
self.gguf_writer.add_rope_scaling_orig_ctx_len(self.hparams["rope_scaling"]["original_max_position_embeddings"])
49024902

4903-
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[Tuple[str, Tensor]]:
4904-
if "gate_up_proj" in name:
4905-
match = re.match(r"model\.layers\.(\d+)\.gate_up_proj\.weight", name)
4906-
if match:
4907-
bid = int(match.group(1))
4908-
return [(f"blk.{bid}.ffn_up.weight", data_torch)]
4909-
4910-
if "post_self_attn_layernorm" in name:
4911-
match = re.match(r"model\.layers\.(\d+)\.post_self_attn_layernorm\.weight", name)
4912-
if match:
4913-
bid = int(match.group(1))
4914-
return [(f"blk.{bid}.post_attn_norm.weight", data_torch)]
4915-
4916-
if "post_mlp_layernorm" in name:
4917-
match = re.match(r"model\.layers\.(\d+)\.post_mlp_layernorm\.weight", name)
4918-
if match:
4919-
bid = int(match.group(1))
4920-
return [(f"blk.{bid}.post_mlp_norm.weight", data_torch)]
4921-
4922-
return super().modify_tensors(data_torch, name, bid)
4923-
49244903
@Model.register("GlmForCausalLM", "ChatGLMModel", "ChatGLMForConditionalGeneration")
49254904
class ChatGLMModel(Model):
49264905
model_arch = gguf.MODEL_ARCH.CHATGLM

gguf-py/gguf/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,8 @@ class MODEL_TENSOR(IntEnum):
15771577
MODEL_TENSOR.FFN_NORM,
15781578
MODEL_TENSOR.FFN_DOWN,
15791579
MODEL_TENSOR.FFN_UP,
1580+
MODEL_TENSOR.ATTN_POST_NORM,
1581+
MODEL_TENSOR.FFN_POST_NORM,
15801582
],
15811583
MODEL_ARCH.BITNET: [
15821584
MODEL_TENSOR.ATTN_Q,

gguf-py/gguf/tensor_mapping.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ class TensorNameMap:
233233
),
234234

235235
MODEL_TENSOR.ATTN_POST_NORM: (
236-
"model.layers.{bid}.post_attention_layernorm", # gemma2 olmo2
236+
"model.layers.{bid}.post_attention_layernorm", # gemma2 olmo2 # ge
237+
"model.layers.{bid}.post_self_attn_layernorm", # glm-4-0414
237238
),
238239

239240
# Rotary embeddings
@@ -269,6 +270,7 @@ class TensorNameMap:
269270
# Post feed-forward norm
270271
MODEL_TENSOR.FFN_POST_NORM: (
271272
"model.layers.{bid}.post_feedforward_layernorm", # gemma2 olmo2
273+
"model.layers.{bid}.post_mlp_layernorm", # glm-4-0414
272274
),
273275

274276
MODEL_TENSOR.FFN_GATE_INP: (

0 commit comments

Comments
 (0)