Skip to main content
Start a sweep on one or more agents on one or more machines. Sweep agents use the sweep configuration defined when you initialize a sweep to explore different hyperparameter combinations. W&B creates a new run for each hyperparameter combination the sweep agent tries. See Manage sweeps to learn how to pause, resume, stop, or cancel a sweep.
Before you continue, make sure you:
The following code snippets demonstrate how to start an agent with the CLI and within a Jupyter Notebook or Python script. For both methods, provide the sweep ID that W&B returns when you initialized the sweep. The sweep ID has the form:
entity/project/sweep_ID
Where:
  • entity: Your W&B username or team name.
  • project: The name of the project where you want W&B to store the output of the run. If the project is not specified, W&B puts the run in a project called “Uncategorized”.
  • sweep_ID: The pseudo random, unique ID generated by W&B.
  • CLI
  • Python script or notebook
Use the wandb agent command to start a sweep. Provide the sweep ID that W&B returns when you initialized the sweep.Copy and paste the code snippet below and replace sweep_id with your sweep ID:
wandb agent sweep_id

Limit the number of runs a sweep agent tries

Random and Bayesian searches will run forever. You must stop the process from the command line, within your python script, or the Sweeps UI.
Specify the number of runs a sweep agent should try. The following code snippets demonstrate how to set a maximum number of W&B Runs with the CLI and within a Jupyter Notebook, Python script.
  • CLI
  • Python script or notebook
First, initialize your sweep with the wandb sweep command. For more information, see Initialize sweeps.
wandb sweep config.yaml
Next, pass an integer value to the count flag to set the maximum number of runs to try.
NUM=10
SWEEPID="dtzl1o7u"
wandb agent --count $NUM $SWEEPID