Skip to content

Commit 46f9ee2

Browse files
author
liyang
committed
fix: Gemma2/Gemma3 inference issue caused by ln_1/ln_2 keys (switch to ln1/ln2)
1 parent 7f7f683 commit 46f9ee2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

convert_hf_to_gguf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,7 +4873,7 @@ def _xlmroberta_set_vocab(self) -> None:
48734873
with open(tokenizer_config_path, "r", encoding="utf-8") as fp:
48744874
tokenizer_config_json = json.load(fp)
48754875

4876-
add_prefix = tokenizer.add_prefix_space
4876+
add_prefix = getattr(tokenizer, "add_prefix_space", False)
48774877
remove_whitespaces = tokenizer.clean_up_tokenization_spaces
48784878
precompiled_charsmap = b64decode(tokenizer_json["normalizer"]["precompiled_charsmap"])
48794879

@@ -6484,10 +6484,10 @@ def _map_block_tensor(self, layer: int, rest: str, data_torch: Tensor, name: str
64846484
# layer norms
64856485
if rest.startswith('norm1.'):
64866486
suffix = parts[-1]
6487-
return [(f'v.blk.{layer}.ln_1.{suffix}', data_torch)]
6487+
return [(f'v.blk.{layer}.ln1.{suffix}', data_torch)]
64886488
if rest.startswith('norm2.'):
64896489
suffix = parts[-1]
6490-
return [(f'v.blk.{layer}.ln_2.{suffix}', data_torch)]
6490+
return [(f'v.blk.{layer}.ln2.{suffix}', data_torch)]
64916491
if rest.startswith('attn.inner_attn_ln.'):
64926492
suffix = parts[-1]
64936493
return [(f'v.blk.{layer}.attn_ln.{suffix}', data_torch)]
@@ -6623,8 +6623,8 @@ def _should_be_f32(self, gguf_name: str) -> bool:
66236623
binary-op dtype issues; patch embedding bias is also safer as F32.
66246624
"""
66256625
patterns = (
6626-
".ln_1.weight", ".ln_1.bias",
6627-
".ln_2.weight", ".ln_2.bias",
6626+
".ln1.weight", ".ln1.bias",
6627+
".ln2.weight", ".ln2.bias",
66286628
".attn_ln.weight", ".attn_ln.bias",
66296629
".ffn_norm.weight", ".ffn_norm.bias",
66306630
"v.patch_embd.proj.bias",

tools/mtmd/clip-impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
#define TN_FFN_GATE "%s.blk.%d.ffn_gate.%s"
7777
#define TN_FFN_UP "%s.blk.%d.ffn_up.%s"
7878
#define TN_FFN_NORM "%s.blk.%d.ffn_norm.%s"
79-
#define TN_LN_1 "%s.blk.%d.ln_1.%s" // layer norm
80-
#define TN_LN_2 "%s.blk.%d.ln_2.%s" // layer norm
79+
#define TN_LN_1 "%s.blk.%d.ln1.%s" // layer norm
80+
#define TN_LN_2 "%s.blk.%d.ln2.%s" // layer norm
8181
#define TN_LS_1 "%s.blk.%d.ls1.%s" // layer scale
8282
#define TN_LS_2 "%s.blk.%d.ls2.%s" // layer scale
8383
#define TN_LN_PRE "%s.pre_ln.%s"

0 commit comments

Comments
 (0)