okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
1#!/usr/bin/env python3 2"""Print the size and SHA-256 Hugging Face's API metadata gives for the files of a repository at a pinned commit. 3Nothing is downloaded: https://huggingface.co/api/models/<repo>/tree/<revision>?recursive=1 lists each LFS file with 4`lfs.oid` (the SHA-256) and `size`. 5 6python tools/hf_pin_fetch.py ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF ed59f92082b1e93c0e96d60a8b11aab089b52f09 7python tools/hf_pin_fetch.py --json <repo> <revision> # {path: [size, sha256]} as JSON 8python tools/hf_pin_fetch.py --setup # every repository in setup.py's HF_REVISIONS, as JSON 9""" 10from __future__import annotations 11 12import json 13import sys 14import urllib .request 15from pathlib import Path 16 17sys .path .insert (0 ,str (Path (__file__ ).resolve ().parents [1 ])) 18from strata_control import tls # noqa: E402 19 20tls .install ()# #3722: the operating system's certificates 21 22 23def tree (repo :str ,revision :str )-> dict : 24"""{path: (size, sha256)} of the repository's LFS files at `revision` (the API pages its answer with Link headers).""" 25out = {} 26url = f"https://huggingface.co/api/models/ { repo } /tree/ { revision } ?recursive=1&expand=0" 27while url : 28with urllib .request .urlopen (urllib .request .Request (url ,headers = {"User-Agent" :"strata-pin" }),timeout = 60 )as r : 29for e in json .load (r ): 30if e .get ("type" )== "file" and e .get ("lfs" ): 31out [e ["path" ]]= (int (e ["lfs" ]["size" ]),e ["lfs" ]["oid" ]) 32link = r .headers .get ("Link" ,"" ) 33url = next ((p .split (";" )[0 ].strip (" <>" )for p in link .split ("," )if 'rel="next"' in p ),None ) 34return out 35 36 37def main (argv :list )-> int : 38if argv and argv [0 ]== "--setup" : 39sys .path .insert (0 ,str (Path (__file__ ).resolve ().parents [1 ])) 40import setup 41json .dumps ({r : {p :list (v )for p ,v in tree (r ,rev ).items ()}for r ,rev in setup .HF_REVISIONS .items ()},indent = 1 )) 42return 0 43as_json = bool (argv )and argv [0 ]== "--json" 44repo ,revision = argv [1 :3 ]if as_json else argv [:2 ] 45t = tree (repo ,revision ) 46if as_json : 47json .dumps ({p :list (v )for p ,v in t .items ()},indent = 1 )) 48else : 49for p , (size ,sha )in sorted (t .items ()): 50f" { size :>14, } { sha } { p } " ) 51return 0 52 53 54if __name__ == "__main__" : 55sys .exit (main (sys .argv [1 :]))