# Initialize sweep by passing in config. # (Optional) Provide a name of the project. sweep_id = wandb.sweep( sweep=sweep_configuration, project='my-first-sweep' )
# Define training function that takes in hyperparameter # values from `wandb.config` and uses them to train a # model and return metric deftrain_one_epoch(epoch, lr, bs): acc = 0.25 + ((epoch/30) + (random.random()/10)) loss = 0.2 + (1 - ((epoch-1)/10 + random.random()/5)) return acc, loss
defevaluate_one_epoch(epoch): acc = 0.1 + ((epoch/20) + (random.random()/10)) loss = 0.25 + (1 - ((epoch-1)/10 + random.random()/6)) return acc, loss
defmain(): run = wandb.init()
# note that we define values from `wandb.config` # instead of defining hard values lr = wandb.config.lr bs = wandb.config.batch_size epochs = wandb.config.epochs
for epoch in np.arange(1, epochs): train_acc, train_loss = train_one_epoch(epoch, lr, bs) val_acc, val_loss = evaluate_one_epoch(epoch)