ISKA / scripts /get_rank.py
YaroslavLinder's picture
Add files with Git LFS support
0a1410b
Raw History Blame Contribute Delete
977 Bytes
from safetensors import safe_open
import re
path = "iska.safetensors"
with safe_open(path, framework="pt") as f:
meta = f.metadata()
rank = meta.get("ss_network_dim") or meta.get("lora_rank") or meta.get("r")
if rank:
print("rank:", rank)
else:
# Look for a typical LoRA up/down weight
up = next((k for k in f.keys() if re.search(r"lora(_\w+)?\.up\.weight$", k)), None)
down = next((k for k in f.keys() if re.search(r"lora(_\w+)?\.down\.weight$", k)), None)
if up:
s = f.get_tensor(up).shape
r = s[1] if len(s) in (2,4) else min(s)
elif down:
s = f.get_tensor(down).shape
r = s[0] if len(s) in (2,4) else min(s)
else:
# Fallback: smallest dimension of any lora weight tensor
k = next(k for k in f.keys() if "lora" in k and k.endswith(".weight"))
s = f.get_tensor(k).shape
r = min(s)
print("rank:", r)