eac123 commited on
Commit
3ceb445
·
verified ·
1 Parent(s): 2564c5d

run_all: chosen_lr.json shared via Hub between job stages

Browse files
Files changed (1) hide show
  1. run_all.py +15 -3
run_all.py CHANGED
@@ -52,15 +52,27 @@ def stage_lrsweep(args):
52
  scores[str(lr)] = tot / 2
53
  best = max(scores, key=scores.get)
54
  json.dump({"scores": scores, "chosen": best}, open(LR_FILE, "w"))
 
 
 
 
 
55
  print("[lrsweep] scores", scores, "-> chosen", best)
56
 
57
 
58
- def chosen_lr():
 
 
 
 
 
 
 
59
  return json.load(open(LR_FILE))["chosen"]
60
 
61
 
62
  def stage1(args):
63
- lr = chosen_lr()
64
  seeds = (0, 1, 2)
65
  archs = [("fixed", 4, "1"), ("rec", 1, "4"), ("rec", 2, "2"),
66
  ("rec", 1, "dynamic")]
@@ -77,7 +89,7 @@ def stage1(args):
77
 
78
 
79
  def stage2(args):
80
- lr = chosen_lr()
81
  for s in (0, 1, 2):
82
  name = f"rec4x4-seed{s}"
83
  if not os.path.exists(f"out/{name}.pt"):
 
52
  scores[str(lr)] = tot / 2
53
  best = max(scores, key=scores.get)
54
  json.dump({"scores": scores, "chosen": best}, open(LR_FILE, "w"))
55
+ if args.hub_repo:
56
+ run([sys.executable, "-c", "import sys; from huggingface_hub import "
57
+ "HfApi; HfApi().upload_file(path_or_fileobj='out/chosen_lr.json', "
58
+ "path_in_repo='results/chosen_lr.json', "
59
+ f"repo_id='{args.hub_repo}', repo_type='model')"])
60
  print("[lrsweep] scores", scores, "-> chosen", best)
61
 
62
 
63
+ def chosen_lr(hub_repo=None):
64
+ if not os.path.exists(LR_FILE):
65
+ # stage1/stage2 run in fresh containers: fetch the lr choice made by
66
+ # the lrsweep job from the Hub repo
67
+ from huggingface_hub import hf_hub_download
68
+ p = hf_hub_download(repo_id=hub_repo, repo_type="model",
69
+ filename="results/chosen_lr.json", local_dir="out")
70
+ os.replace(os.path.join("out", "results", "chosen_lr.json"), LR_FILE)
71
  return json.load(open(LR_FILE))["chosen"]
72
 
73
 
74
  def stage1(args):
75
+ lr = chosen_lr(args.hub_repo)
76
  seeds = (0, 1, 2)
77
  archs = [("fixed", 4, "1"), ("rec", 1, "4"), ("rec", 2, "2"),
78
  ("rec", 1, "dynamic")]
 
89
 
90
 
91
  def stage2(args):
92
+ lr = chosen_lr(args.hub_repo)
93
  for s in (0, 1, 2):
94
  name = f"rec4x4-seed{s}"
95
  if not os.path.exists(f"out/{name}.pt"):