Download scripts/get_rank.py from YaroslavLinder/ISKA: direct link, hf CLI and curl.
- Browser
- Download file 977 Bytes
-
https://huggingface.co/YaroslavLinder/ISKA/resolve/main/scripts/get_rank.py
- Command line
-
hf download hf://YaroslavLinder/ISKA/scripts/get_rank.py
-
curl -L -o get_rank.py https://huggingface.co/YaroslavLinder/ISKA/resolve/main/scripts/get_rank.py
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) |