import wandbsweep_config = {"name": "My Sweep","method": "grid","parameters": {"param1": {"values": [1, 2, 3]}}}sweep_id = wandb.sweep(sweep_config)
Use the following methods in order to specify the entity or project for the sweep:
Arguments to wandb.sweep() For example: wandb.sweep(sweep_config, entity="user", project="my_project")
Environment Variables WANDB_ENTITY
and WANDB_PROJECT
Command Line Interface using the wandb init
command
Sweep configuration using the keys "entity" and "project"
When running an agent from python, the agent runs a specified function instead of using the program
key from the sweep configuration file.
import wandbimport timedef train():run = wandb.init()print("config:", dict(run.config))for epoch in range(35):print("running", epoch)wandb.log({"metric": run.config.param1, "epoch": epoch})time.sleep(1)wandb.agent(sweep_id, function=train)
Quick overview: Run in colab
Complete walkthrough of using sweeps in a project: Run in colab
Arguments
sweep_id (dict): Sweep ID generated by the UI, CLI, or sweep API
entity (str, optional): username or team where you want to send runs
project (str, optional): project where you want to send runs
function (dir, optional): Configure sweep function
If you want to develop your own parameter search algorithms you can run your controller from python.
The simplest way to run a controller:
sweep = wandb.controller(sweep_id)sweep.run()
If you want more control of the controller loop:
import wandbsweep = wandb.controller(sweep_id)while not sweep.done():sweep.print_status()sweep.step()time.sleep(5)
Or even more control over the parameters being served:
import wandbsweep = wandb.controller(sweep_id)while not sweep.done():params = sweep.search()sweep.schedule(params)sweep.print_status()
If you want to specify your sweep entirely with code you can do something like this:
import wandbfrom wandb.sweeps import GridSearch,RandomSearch,BayesianSearchsweep = wandb.controller()sweep.configure_search(GridSearch)sweep.configure_program('train-dummy.py')sweep.configure_controller(type="local")sweep.configure_parameter('param1', value=3)sweep.create()sweep.run()