#!/usr/bin/env python3 """Merge MTP head (safetensors) into BF16 GGUF — raw binary header rewrite.""" import argparse import os, struct, shutil, gguf import ml_dtypes import numpy as np from safetensors import safe_open LLAMA_GGUF = os.environ.get( "LLAMA_GGUF", "/home/wepiqx/llama.cpp/build/bin/llama-gguf" ) NAME_MAP = { "mtp.pre_fc_norm_embedding.weight": "blk.32.pre_fc_norm_embedding.weight", "mtp.pre_fc_norm_hidden.weight": "blk.32.pre_fc_norm_hidden.weight", "mtp.fc.weight": "blk.32.fc.weight", "mtp.layers.0.input_layernorm.weight": "blk.32.input_layernorm.weight", "mtp.layers.0.self_attn.q_proj.weight": "blk.32.attn_q.weight", "mtp.layers.0.self_attn.k_proj.weight": "blk.32.attn_k.weight", "mtp.layers.0.self_attn.v_proj.weight": "blk.32.attn_v.weight", "mtp.layers.0.self_attn.o_proj.weight": "blk.32.attn_output.weight", "mtp.layers.0.self_attn.q_norm.weight": "blk.32.self_attn_q_norm.weight", "mtp.layers.0.self_attn.k_norm.weight": "blk.32.self_attn_k_norm.weight", "mtp.layers.0.post_attention_layernorm.weight": "blk.32.post_attention_layernorm.weight", "mtp.layers.0.mlp.gate_proj.weight": "blk.32.ffn_gate.weight", "mtp.layers.0.mlp.up_proj.weight": "blk.32.ffn_up.weight", "mtp.layers.0.mlp.down_proj.weight": "blk.32.ffn_down.weight", "mtp.norm.weight": "blk.32.norm.weight", } def pack_str(s): b = s.encode() return struct.pack('