Skip to main content
This page explains how to start a sweep agent on one or more machines so that W&B can run your hyperparameter search. Sweep agents use the sweep configuration that you define when you initialize a sweep to explore different hyperparameter combinations. W&B creates a new run for each hyperparameter combination that the sweep agent runs. See Manage sweeps to learn how to pause, resume, stop, or cancel a running sweep agent. Before you continue: These examples show how to start a sweep agent with the W&B CLI or from Python. You need the sweep ID that W&B returns when you initialize the sweep. You can use the short sweep ID on its own (for example, dtzl1o7u), or include the entity and project as a path:
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 you don’t specify the project, W&B puts the run in a project called “Uncategorized”.
  • sweep_ID: The pseudo-random, unique ID that W&B generates.
Use the wandb agent command to start a sweep. Provide the sweep ID that W&B returns when you initialize the sweep.Replace [SWEEP-ID] with your sweep ID in the following command:
wandb agent [SWEEP-ID]
For graceful shutdown when you interrupt the agent (for example, with Ctrl+C), use wandb agent --forward-signals [SWEEP-ID] so the current run receives the signal and can shut down cleanly. See Signal handling and sweep runs for details.

Limit the number of runs a sweep agent tries

By default, random and Bayesian searches run indefinitely, so cap how many runs an agent attempts. Specify the number of runs a sweep agent should try to bound its work. The following code snippets demonstrate how to set a maximum number of runs with the CLI and within a Jupyter notebook or Python script.
Random and Bayesian searches run indefinitely. If you don’t set a run count, you must stop the process from the command line, from within your Python script, or from the Sweeps UI.
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