colors/search.py

58 lines
1.7 KiB
Python
Raw Normal View History

2023-12-31 07:04:54 +00:00
import subprocess
import sys
2023-12-30 05:13:50 +00:00
from random import sample
2024-01-15 21:39:44 +00:00
import numpy as np # noqa: F401
2024-01-14 03:02:27 +00:00
from lightning_sdk import Machine, Studio # noqa: F401
2023-12-30 05:30:52 +00:00
2024-01-14 07:04:11 +00:00
NUM_JOBS = 100
2023-12-30 05:13:50 +00:00
# reference to the current studio
# if you run outside of Lightning, you can pass the Studio name
2024-01-15 07:00:50 +00:00
# studio = Studio()
2023-12-30 05:13:50 +00:00
# use the jobs plugin
2024-01-15 07:00:50 +00:00
# studio.install_plugin("jobs")
# job_plugin = studio.installed_plugins["jobs"]
2023-12-30 05:13:50 +00:00
# do a sweep over learning rates
# Define the ranges or sets of values for each hyperparameter
2024-01-15 05:32:17 +00:00
# alpha_values = list(np.round(np.linspace(2, 4, 21), 4))
2024-01-15 19:45:40 +00:00
# learning_rate_values = list(np.round(np.logspace(-5, -3, 21), 5))
2024-01-16 04:37:22 +00:00
learning_rate_values = [1e-2]
2024-01-15 06:31:17 +00:00
alpha_values = [0, 1, 2]
2024-01-16 04:37:22 +00:00
widths = [2**k for k in range(4, 15)]
2024-01-15 06:31:17 +00:00
# learning_rate_values = [5e-4]
2024-01-16 04:37:22 +00:00
batch_size_values = [256]
max_epochs_values = [100]
2024-01-15 04:25:29 +00:00
seeds = list(range(21, 1992))
2023-12-30 05:13:50 +00:00
# Generate all possible combinations of hyperparameters
2023-12-30 05:30:52 +00:00
all_params = [
2024-01-15 06:35:48 +00:00
(alpha, lr, bs, me, s, w)
2023-12-30 05:30:52 +00:00
for alpha in alpha_values
for lr in learning_rate_values
for bs in batch_size_values
for me in max_epochs_values
2024-01-15 04:25:29 +00:00
for s in seeds
2024-01-15 06:35:48 +00:00
for w in widths
2023-12-30 05:30:52 +00:00
]
2023-12-30 05:13:50 +00:00
# perform random search with a limit
2023-12-31 07:04:54 +00:00
search_params = sample(all_params, min(NUM_JOBS, len(all_params)))
2023-12-30 05:13:50 +00:00
2023-12-30 06:35:19 +00:00
for idx, params in enumerate(search_params):
2024-01-15 06:35:48 +00:00
a, lr, bs, me, s, w = params
cmd = f"cd ~/colors && python main.py --alpha {a} --lr {lr} --bs {bs} --max_epochs {me} --seed {s} --width {w}"
2024-01-14 03:51:34 +00:00
# job_name = f"color2_{bs}_{a}_{lr:2.2e}"
2023-12-31 07:02:13 +00:00
# job_plugin.run(cmd, machine=Machine.T4, name=job_name)
print(f"Running {params}: {cmd}")
2023-12-31 07:04:54 +00:00
try:
# Run the command and wait for it to complete
subprocess.run(cmd, shell=True, check=True)
except KeyboardInterrupt:
print("Interrupted by user")
sys.exit(1)