Spaces:
Running
Running
Download calibration/prefetch.py from coralexbadea/BackdoorChecker: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/coralexbadea/BackdoorChecker/resolve/main/calibration/prefetch.py
- Command line
-
hf download hf://spaces/coralexbadea/BackdoorChecker/calibration/prefetch.py
-
curl -L -o prefetch.py https://huggingface.co/spaces/coralexbadea/BackdoorChecker/resolve/main/calibration/prefetch.py
1.05 kB
| """Download safetensors + configs for every suite model and parent in parallel (no GPU).""" | |
| import csv, sys | |
| from concurrent.futures import ThreadPoolExecutor | |
| from huggingface_hub import snapshot_download | |
| sys.path.insert(0, "/workspace/BackdoorChecker") | |
| from backdoorcheck.loading import is_adapter, adapter_base | |
| ids = set() | |
| for r in csv.DictReader(open("/workspace/BackdoorChecker/calibration/suite.tsv"), delimiter="\t"): | |
| if r["group"] == "test": | |
| ids.add(r["model"]) | |
| if r["parent"]: ids.add(r["parent"]) | |
| for m in list(ids): | |
| try: | |
| if is_adapter(m): ids.add(adapter_base(m)) | |
| except Exception as e: print("adapter check failed", m, e) | |
| def get(m): | |
| try: | |
| snapshot_download(m, allow_patterns=["*.safetensors", "*.json", "*.txt", "*.model", "tokenizer*"], | |
| ignore_patterns=["checkpoint-*/*"]) | |
| return f"ok {m}" | |
| except Exception as e: | |
| return f"FAIL {m}: {str(e)[:120]}" | |
| with ThreadPoolExecutor(6) as ex: | |
| for line in ex.map(get, sorted(ids)): print(line, flush=True) | |