Skip to main content
This page explains how to start a sweep agent on one or more machines so that Weights & Biases can run your hyperparameter search. Sweep agents use the sweep configuration that you define when you initialize a sweep to explore different hyperparameter combinations. Weights & Biases 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:

Start a scheduler

If you specify a custom scheduler in your sweep configuration, you need to start the scheduler before launching any agents.
Sweeps that use the default hosted controller don’t require starting a local scheduler. Only start wandb sweep-scheduler if your sweep configuration includes a custom scheduler.
In the scheduler environment, install the dependencies for your engine. If you configured scheduler.source, make the source file and its dependencies available there, and run the scheduler from a directory where the relative source path resolves. Replace ENTITY, PROJECT, and SWEEP_ID with the entity, project, and ID of your initialized sweep:
Use one scheduler per sweep. Multiple schedulers for the same sweep don’t share optimizer state and can generate duplicate runs. Keep the scheduler running as a separate process while agents execute your training code. For all command options and default values, see wandb sweep-scheduler. The scheduler respects sweep lifecycle commands, including pausing, resuming, and stopping the sweep. If you kill or delete the sweep, the scheduler exits.

Restart a scheduler

To restart a scheduler, run wandb sweep-scheduler with the same sweep path. The scheduler reads the existing run data to initialize the engine, then continues optimization. This restores observations from Weights & Biases rather than a saved optimizer checkpoint. If you use a custom optimizer factory, see Handle scheduler restarts for requirements on optimizer state and source files.

Start an agent

Each agent environment requires the Weights & Biases Python SDK (wandb), your training program, and its dependencies. If you started a scheduler, start agents in separate terminals or environments. Start additional agents with the same sweep path to evaluate configurations concurrently. See Parallelize agents. These examples show how to start a sweep agent with the W&B CLI or from Python. You need the sweep ID that Weights & Biases 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:
Where:
  • entity: Your Weights & Biases team name.
  • project: The name of the project where you want Weights & Biases to store the output of the run. If you don’t specify the project, Weights & Biases puts the run in a project called “Uncategorized”.
  • sweep_ID: The pseudo-random, unique ID that Weights & Biases generates.
Use the wandb agent command to start a sweep agent. Provide the sweep ID that Weights & Biases returns when you initialize the sweep.Replace [SWEEP-ID] with your sweep ID in the following command:
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.
Next, pass an integer value to the count flag to set the maximum number of runs to try.
Last modified on November 6, 2026