Skip to content

Instantly share code, notes, and snippets.

@AdamGleave
Created September 11, 2019 13:11
Show Gist options
  • Save AdamGleave/ce76233da6f4449e53c788f3da02ed7d to your computer and use it in GitHub Desktop.
Save AdamGleave/ce76233da6f4449e53c788f3da02ed7d to your computer and use it in GitHub Desktop.
Sacred for hyperparameter sweep
import sacred
standalone_ex = sacred.Experiment('standalone')
@standalone_ex.config
def default_config():
a = 1
b = 2
@standalone_ex.main
def compute(a, b):
return a + b
if __name__ == '__main__':
standalone_ex.run_commandline()
import sacred
from standalone import standalone_ex
sweep_ex = sacred.Experiment('sweep')
@sweep_ex.config
def default_config():
a_vals = [1, 21, 42]
b_vals = [1, 21, 42]
@sweep_ex.automain
def sweep(a_vals, b_vals):
res = {}
for a in a_vals:
for b in b_vals:
run = standalone_ex.run(config_updates=dict(a=a, b=b))
res[(a, b)] = run.result
for k, v in res.items():
if v == 42:
print("Successful hyperparam! ", k)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment