-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_sweep.py
More file actions
34 lines (24 loc) · 956 Bytes
/
run_sweep.py
File metadata and controls
34 lines (24 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""Launch wandb sweeps."""
import re
import subprocess
import sys
SWEEPS = {"model": "wandb_sweeps/model_comparison_sweep.yaml",
"transfer": "wandb_sweeps/transfer_learning_sweep.yaml"}
def main():
if len(sys.argv) < 2 or sys.argv[1] not in SWEEPS:
print(f"Usage: python run_sweep.py [{'/'.join(SWEEPS.keys())}]")
sys.exit(1)
config = SWEEPS[sys.argv[1]]
print(f"Initializing: {config}")
result = subprocess.run(["wandb", "sweep", config], capture_output=True, text=True)
output = result.stdout + result.stderr
match = re.search(r'wandb agent ([^\s]+)', output) or re.search(r'sweep/([a-zA-Z0-9]+)', output)
if not match:
print(f"Failed. Run manually: wandb sweep {config}")
sys.exit(1)
sweep_id = match.group(1)
print(f"Starting agent: {sweep_id}")
subprocess.run(["wandb", "agent", sweep_id])
if __name__ == "__main__":
main()