Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/gpu-head-to-head/blob/main/q35-9b/tools/cmp_ssm_a.py # gpu-head-to-head aien-dev/gpu-head-to-head Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `gpu-head-to-head / q35-9b / tools / cmp_ssm_a.py` 25 lines ยท 1158 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Throwaway: max ULP distance between GGUF ssm_a and -exp(A_log) from the HF safetensors, per layer.""" 3 import glob, sys, re 4 from safetensors import safe_open 5 import numpy as np, torch, gguf 6 HF, GG = sys.argv[1], sys.argv[2] 7 alog = {} 8 for f in sorted(glob.glob(HF + "/model.safetensors-*.safetensors")): 9 with safe_open(f, "pt") as s: 10 for k in s.keys(): 11 m = re.search(r"layers\.(\d+)\.linear_attn\.A_log$", k) 12 if m and "mtp" not in k: 13 alog[int(m.group(1))] = s.get_tensor(k) 14 worst = 0 15 for t in gguf.GGUFReader(GG).tensors: 16 m = re.match(r"blk\.(\d+)\.ssm_a$", t.name) 17 if not m: 18 continue 19 g = np.sort(np.array(t.data, dtype=np.float32).ravel()) # converter may reorder value heads 20 ref = np.sort((-torch.exp(alog[int(m.group(1))].float())).numpy().ravel()) 21 ulp = np.abs(g.view(np.int32).astype(np.int64) - ref.view(np.int32).astype(np.int64)).max() 22 rel = np.abs(g - ref).max() / np.abs(ref).max() 23 worst = max(worst, ulp) 24 print(t.name, "max_ulp", ulp, "max_rel", "%.3g" % rel, "A_log dtype", alog[int(m.group(1))].dtype) 25 print("WORST_ULP", worst)