Download runtime/weights/identity.py from hscr/luxfer: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/hscr/luxfer/resolve/main/runtime/weights/identity.py
- Command line
-
hf download hf://hscr/luxfer/runtime/weights/identity.py
-
curl -L -o identity.py https://huggingface.co/hscr/luxfer/resolve/main/runtime/weights/identity.py
1.09 kB
| """Weight identity for original single-file and derivative sharded checkpoints.""" | |
| import hashlib,json | |
| from pathlib import Path | |
| def file_sha256(path): | |
| result=hashlib.sha256() | |
| with Path(path).open('rb') as stream: | |
| while chunk:=stream.read(8*1024*1024):result.update(chunk) | |
| return result.hexdigest() | |
| def shard_files(path): | |
| path=Path(path);index=json.loads((path/'model.safetensors.index.json').read_text());mapping=index['weight_map'] | |
| if not mapping or not all(isinstance(k,str) and isinstance(v,str) and Path(v).name==v and v.endswith('.safetensors') for k,v in mapping.items()):raise ValueError('Invalid shard index') | |
| return index,sorted(set(mapping.values())) | |
| def checkpoint_fingerprint(path): | |
| path=Path(path) | |
| if (path/'model.safetensors').exists():return file_sha256(path/'model.safetensors') | |
| index,files=shard_files(path) | |
| record=dict(index_sha256=file_sha256(path/'model.safetensors.index.json'),shards={name:file_sha256(path/name) for name in files}) | |
| return hashlib.sha256(json.dumps(record,sort_keys=True).encode()).hexdigest() | |