keys-GLM-5.3-EXL3 / serving /donor_diff.py
drowzeys's picture
Add files using upload-large-folder tool
c226d57 verified
Raw History Blame Contribute Delete
834 Bytes
import json, torch, os, sys
from safetensors import safe_open
M="/models/GLM-5.3-EXL3-3bpw"; D="/models/glm53-ablit-donor-derisked"
idx=json.load(open(f"{M}/model.safetensors.index.json"))["weight_map"]
man=json.load(open(f"{D}/MANIFEST.json"))["layers"]
print("layer rel_l2 cos donor_bits")
for L in range(79):
key=f"model.layers.{L}.self_attn.o_proj.weight"
if key not in idx: print(L,"no-stock"); continue
with safe_open(f"{M}/{idx[key]}","pt") as f: w=f.get_tensor(key).float()
info=man[str(L)]; raw=open(f"{D}/L{L}.bin","rb").read()
d=torch.frombuffer(bytearray(raw),dtype=torch.bfloat16).view(info["shape"]).float()
rel=((d-w).norm()/w.norm()).item(); cos=torch.nn.functional.cosine_similarity(d.flatten(),w.flatten(),dim=0).item()
print(f"{L:2d} {rel:.4f} {cos:.5f} {info.get('bits')}", flush=True)