This page shows you how to run a sweep’s search and stopping algorithms locally instead of using the W&B cloud-hosted controller. Use the local controller to inspect and instrument the code to debug issues or develop new algorithms that you can later incorporate into the cloud-hosted controller.
By default, W&B hosts the hyperparameter controller as a cloud service. W&B agents communicate with the controller to determine the next set of parameters to use for training. The controller also runs early stopping algorithms to determine which runs to stop.
The local controller feature lets you run search and stop algorithms locally.
This feature supports faster development and debugging of new algorithms for the Sweeps tool. It isn’t appropriate for hyperparameter optimization workloads.
Prerequisites
Install the W&B SDK (wandb) so that the local controller commands are available:
The following examples assume you already have a configuration file and a training loop defined in a Python script or Jupyter notebook. For more information, see Define sweep configuration.
Run a local controller from the command line
Initialize a sweep the same way as when you use hyperparameter controllers hosted by W&B as a cloud service, but pass the --controller flag to use the local controller:
-
Initialize the sweep with the
--controller flag:
-
Note the sweep ID that
wandb sweep generates, then start the controller. Replace [SWEEP-ID] with the sweep ID. You can pass the short sweep ID alone or include the entity and project as a path ([ENTITY]/[PROJECT]/[SWEEP-ID]):
-
Start one or more sweep agents to run the sweep. Replace
[SWEEP-ID] with the sweep ID:
For more information, see Start sweep agents.
Alternatively, add the controller to your configuration file so you don’t need to pass --controller each time you initialize the sweep:
Then initialize the sweep without the flag, and continue with steps 2 and 3:
Run a local controller with W&B Python SDK
The following code snippets demonstrate how to specify and use a local controller with the W&B Python SDK. Each example offers progressively more control, so you can choose the approach that matches how much you need to customize search and scheduling.
To use a controller with the Python SDK, pass the sweep ID to the wandb.controller() method, then call the returned object’s run method to start the sweep job:
For more control over the controller loop, step through it yourself:
For even more control over the parameters served, call search and schedule directly:
To specify your sweep entirely in code rather than a YAML configuration file, configure the search, program, controller, and parameters in Python: