#!/usr/bin/env python3 """Fix the DSpark draft GGUF: 1. Rename dflash-draft.* keys to dflash.* 2. Rename nested dflash.dflash.* keys to dflash.* equivalents 3. Add tokenizer keys from K3 model """ import struct, sys, os def read_gguf_kv(data, pos, n_kv): """Read all KV pairs, return list of (key_bytes, vtype, value_bytes_or_data)""" kvs = [] for i in range(n_kv): klen = struct.unpack_from(" {new_key.decode()}") elif key.startswith(GENERAL_PREFIX_OLD): new_key = GENERAL_PREFIX_NEW + key[len(GENERAL_PREFIX_OLD):] renamed += 1 else: new_key = key new_kvs.append((new_key, vtype, val)) existing_keys.add(new_key) # Add missing tokenizer keys added = 0 for key in tok_keys_needed: if key not in existing_keys and key in tok_kvs: vtype, val = tok_kvs[key] new_kvs.append((key, vtype, val)) added += 1 print(f" added: {key.decode()}") print(f"\nRenamed {renamed} keys, added {added} tokenizer keys") print(f"Total KV: {len(new_kvs)} (was {n_kv})") # Write output out = bytearray() out += magic out += struct.pack(" {new_tname.decode()}") else: new_tname = tname tensor_infos_out += struct.pack("