Download code/run_all.py from SoulFireMage/weight-reading-probe: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/datasets/SoulFireMage/weight-reading-probe/resolve/main/code/run_all.py
- Command line
-
hf download hf://datasets/SoulFireMage/weight-reading-probe/code/run_all.py
-
curl -L -o run_all.py https://huggingface.co/datasets/SoulFireMage/weight-reading-probe/resolve/main/code/run_all.py
1.87 kB
| """HF Jobs entry point: train 12 policies (4 games x 3 seeds) in parallel, make 2 random-init | |
| nulls, and upload raw labelled weights + stats to the PRIVATE raw repo.""" | |
| import json, os, sys, multiprocessing as mp | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| import numpy as np, torch | |
| from huggingface_hub import HfApi | |
| REPO = "SoulFireMage/weight-reading-probe-raw" | |
| OUT = "/tmp/out" | |
| STEPS = int(os.environ.get("STEPS", "0")) or None | |
| PREFIX = os.environ.get("PREFIX", "raw") | |
| def job(args): | |
| game, seed = args | |
| from train import train, weights_dict | |
| pi, stats = train(game, seed, STEPS) | |
| np.savez(f"{OUT}/{game}_s{seed}.npz", **weights_dict(pi)) | |
| HfApi().upload_file(path_or_fileobj=f"{OUT}/{game}_s{seed}.npz", repo_id=REPO, repo_type="dataset", | |
| path_in_repo=f"{PREFIX}/{game}_s{seed}.npz", commit_message=f"raw {game} s{seed}") | |
| return stats | |
| if __name__ == "__main__": | |
| os.makedirs(OUT, exist_ok=True) | |
| from train import policy_net, weights_dict | |
| for i, s in enumerate([900, 901]): | |
| torch.manual_seed(s) | |
| np.savez(f"{OUT}/random_init_{i}.npz", **weights_dict(policy_net())) | |
| runs = [(g, s) for g in ["breakout", "pong", "pacman", "freeway"] for s in (0, 1, 2)] | |
| with mp.get_context("spawn").Pool(min(len(runs), os.cpu_count())) as p: | |
| stats = p.map(job, runs) | |
| json.dump(stats, open(f"{OUT}/train_stats.json", "w"), indent=1) | |
| api = HfApi() | |
| for f in ["random_init_0.npz", "random_init_1.npz", "train_stats.json"]: | |
| api.upload_file(path_or_fileobj=f"{OUT}/{f}", repo_id=REPO, repo_type="dataset", | |
| path_in_repo=f"{PREFIX}/{f}", commit_message=f"raw {f}") | |
| for s in stats: | |
| print(s["game"], s["seed"], round(s["trained_mean"], 2), "vs random", round(s["random_mean"], 2), | |
| "gate", s["passes_gate"], flush=True) | |