- Configure your training script to create and track hyperparameter combinations with Weights & Biases. See Add Weights & Biases to your code for examples.
- Define a configuration file for your sweep.
- Initialize the sweep and note its sweep ID.
Start a scheduler
If you specify a custom scheduler in your sweep configuration, you need to start the scheduler before launching any agents. In the scheduler environment, install the dependencies for your engine. If you configuredscheduler.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:
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, runwandb 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:
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.
- CLI
- Python script or notebook
Use the For graceful shutdown when you interrupt the agent (for example, with
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: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.- CLI
- Python script or notebook
First, initialize your sweep with the Next, pass an integer value to the count flag to set the maximum number of runs to try.
wandb sweep command. For more information, see Initialize sweeps.