"""Separate normalized embedded MTP by byte-preserving safetensors repack. Avoids mlx-lm's presence-keyed RMSNorm shift on a converted trunk. No inference, quantization, normalization, provider selection or source mutation is performed. """ from pathlib import Path import argparse,hashlib,json,os,shutil,struct def header(path): with path.open('rb') as f: length=struct.unpack('16*1024**2:raise ValueError('Header size limit') data=json.loads(f.read(length)) return data,8+length def repack(output,entries,heads): metadata={'__metadata__':{'format':'mlx'}};cursor=0 for newname,src,old,base,key in entries: start,end=old['data_offsets'];metadata[newname]={**old,'data_offsets':[cursor,cursor+end-start]};cursor+=end-start raw=json.dumps(metadata,separators=(',',':')).encode();raw+=b' '*(-len(raw)%8);digests={} with output.open('xb') as out: out.write(struct.pack('