diff --git a/backend/loader.py b/backend/loader.py index 811bce04..9b2e606f 100644 --- a/backend/loader.py +++ b/backend/loader.py @@ -277,6 +277,32 @@ def replace_state_dict(sd: dict[str, torch.Tensor], asd: dict[str, torch.Tensor] asd.clear() asd = asd_new + if "blk.0.attn_norm.weight" in asd: + gguf_llm_format = { # city96 + "blk.": "model.layers.", + "attn_norm": "input_layernorm", + "attn_q": "self_attn.q_proj", + "attn_k": "self_attn.k_proj", + "attn_v": "self_attn.v_proj", + "attn_output": "self_attn.o_proj", + "ffn_up": "mlp.up_proj", + "ffn_down": "mlp.down_proj", + "ffn_gate": "mlp.gate_proj", + "ffn_norm": "post_attention_layernorm", + "token_embd": "model.embed_tokens", + "output_norm": "model.norm", + "output.weight": "lm_head.weight", + } + asd_new = {} + for k, v in asd.items(): + for s, d in gguf_llm_format.items(): + k = k.replace(s, d) + asd_new[k] = v + for k in ("model.embed_tokens.weight",): + asd_new[k] = asd_new[k].dequantize_as_pytorch_parameter() + asd.clear() + asd = asd_new + # sd / sdxl / wan # wan if "decoder.conv_in.weight" in asd or "decoder.middle.0.residual.0.gamma" in asd: keys_to_delete = [k for k in sd if k.startswith(vae_key_prefix)]