File size: 1,025 Bytes
7f30bda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
"""Exact-name read-back gate: the built file is the receipt, not the ftype name.
usage: readback.py <expect_output> <expect_embd> <file.gguf>   (use '-' to skip a check)"""
import sys
sys.path.insert(0, "/opt/llama-rocm/rocmfpx-724/gguf-py")
import gguf
exp_out, exp_emb, path = sys.argv[1:4]
r = gguf.GGUFReader(path)
def tname(t):
    try: return t.tensor_type.name
    except Exception: return f"TYPE_{int(t.tensor_type)}"
ty = {t.name: tname(t) for t in r.tensors}
f = r.fields.get("general.file_type")
ftype = int(f.parts[f.data[0]][0]) if f else None
arch = bytes(r.fields["general.architecture"].parts[-1]).decode()
nextn = sum(".nextn." in k for k in ty)
out, emb = ty.get("output.weight"), ty.get("token_embd.weight")
ok = (exp_out == "-" or out == exp_out) and (exp_emb == "-" or emb == exp_emb)
print(f"{'PASS' if ok else 'FAIL'} {path.split('/')[-1]} arch={arch} ftype={ftype} tensors={len(ty)} nextn={nextn} "
      f"output.weight={out} token_embd.weight={emb}")
sys.exit(0 if ok else 1)