Documentation
Search…
Ray Tune
W&B integrates with Ray by offering two lightweight integrations.
One is the WandbLogger, which automatically logs metrics reported to Tune to the Wandb API. The other one is the @wandb_mixin decorator, which can be used with the function API. It automatically initializes the Wandb API with Tune’s training information. You can just use the Wandb API like you would normally do, e.g. using wandb.log() to log your training process.

WandbLogger

1
from ray.tune.integration.wandb import WandbLogger
Copied!
Wandb configuration is done by passing a wandb key to the config parameter of tune.run() (see example below).
The content of the wandb config entry is passed to wandb.init() as keyword arguments. The exception are the following settings, which are used to configure the WandbLogger itself:

Parameters

api_key_file (str) – Path to file containing the Wandb API KEY.
api_key (str) – Wandb API Key. Alternative to setting api_key_file.
excludes (list) – List of metrics that should be excluded from the log.
log_config (bool) – Boolean indicating if the config parameter of the results dict should be logged. This makes sense if parameters will change during training, e.g. with PopulationBasedTraining. Defaults to False.

Example

1
from ray.tune.logger import DEFAULT_LOGGERS
2
from ray.tune.integration.wandb import WandbLogger
3
tune.run(
4
train_fn,
5
config={
6
# define search space here
7
"parameter_1": tune.choice([1, 2, 3]),
8
"parameter_2": tune.choice([4, 5, 6]),
9
# wandb configuration
10
"wandb": {
11
"project": "Optimization_Project",
12
"api_key_file": "/path/to/file",
13
"log_config": True
14
}
15
},
16
loggers=DEFAULT_LOGGERS + (WandbLogger, ))
Copied!

wandb_mixin

1
ray.tune.integration.wandb.wandb_mixin(func)
Copied!
This Ray Tune Trainable mixin helps initializing the Wandb API for use with the Trainable class or with @wandb_mixin for the function API.
For basic usage, just prepend your training function with the @wandb_mixin decorator:
1
from ray.tune.integration.wandb import wandb_mixin
2
3
@wandb_mixin
4
def train_fn(config):
5
wandb.log()
Copied!
Wandb configuration is done by passing a wandb key to the config parameter of tune.run() (see example below).
The content of the wandb config entry is passed to wandb.init() as keyword arguments. The exception are the following settings, which are used to configure the WandbTrainableMixin itself:

Parameters

api_key_file (str) – Path to file containing the Wandb API KEY.
api_key (str) – Wandb API Key. Alternative to setting api_key_file.
Wandb’s group, run_id and run_name are automatically selected by Tune, but can be overwritten by filling out the respective configuration values.
Please see here for all other valid configuration settings: https://docs.wandb.com/library/init

Example:

1
from ray import tune
2
from ray.tune.integration.wandb import wandb_mixin
3
4
@wandb_mixin
5
def train_fn(config):
6
for i in range(10):
7
loss = self.config["a"] + self.config["b"]
8
wandb.log({"loss": loss})
9
tune.report(loss=loss)
10
11
tune.run(
12
train_fn,
13
config={
14
# define search space here
15
"a": tune.choice([1, 2, 3]),
16
"b": tune.choice([4, 5, 6]),
17
# wandb configuration
18
"wandb": {
19
"project": "Optimization_Project",
20
"api_key_file": "/path/to/file"
21
}
22
})
Copied!

Example Code

We've created a few examples for you to see how the integration works:
    Colab: A simple demo to try the integration
    Dashboard: View dashboard generated from the example
Last modified 1yr ago