Documentation
Search…
Configure Experiments with wandb.config
Use a dictionary-like object to save your experiment configuration

Overview

Set the wandb.config object in your script to save your training configuration: hyperparameters, input settings like dataset name or model type, and any other independent variables for your experiments. This is useful for analyzing your experiments and reproducing your work in the future. You'll be able to group by config values in the web interface, comparing the settings of different runs and seeing how these affect the output. Note that output metrics or dependent variables (like loss and accuracy) should be saved with wandb.loginstead.
You can send us a nested dictionary in config, and we'll flatten the names using dots in our backend. We recommend that you avoid using dots in your config variable names, and use a dash or underscore instead. Once you've created your wandb config dictionary, if your script accesses wandb.config keys below the root, use [ ] syntax instead of . syntax.

Simple Example

1
wandb.config.epochs = 4
2
wandb.config.batch_size = 32
3
# you can also initialize your run with a config
4
wandb.init(config={"epochs": 4})
Copied!

Efficient Initialization

You can treat wandb.config as a dictionary, updating multiple values at a time.
1
wandb.init(config={"epochs": 4, "batch_size": 32})
2
# later
3
wandb.config.update({"lr": 0.1, "channels": 16})
Copied!

argparse.Namespace

You can pass in the arguments returned by argparse. This is convenient for quickly testing different hyperparameter values from the command line.
1
wandb.init(config={"lr": 0.1})
2
wandb.config.epochs = 4
3
4
parser = argparse.ArgumentParser()
5
parser.add_argument('-b', '--batch-size', type=int, default=8, metavar='N',
6
help='input batch size for training (default: 8)')
7
args = parser.parse_args()
8
wandb.config.update(args) # adds all of the arguments as config variables
Copied!

absl.FLAGS

You can also pass in absl flags.
1
flags.DEFINE_string("model", None, "model to run") # name, default, help
2
wandb.config.update(flags.FLAGS) # adds all absl flags to config
Copied!

File-Based Configs

If you create a file called config-defaults.yaml, and it will automatically be loaded into wandb.config.
configs-default.yaml
1
# sample config defaults file
2
epochs:
3
desc: Number of epochs to train over
4
value: 100
5
batch_size:
6
desc: Size of each mini-batch
7
value: 32
Copied!
These values can then be over-written inside your script by passing values to the config argument of wandb.init.
You can also load different config files with the command line argument --configs.
One example use case: you have a YAML file with some metadata for the run, and then a dictionary of hyperparameters in your Python script. You can save both in the nested config object:
1
hyperparameter_defaults = dict(
2
dropout=0.5,
3
batch_size=100,
4
learning_rate=0.001,
5
)
6
7
config_dictionary = dict(
8
yaml=my_yaml_file,
9
params=hyperparameter_defaults,
10
)
11
12
wandb.init(config=config_dictionary)
Copied!

Dataset Identifier

You can add a unique identifier (like a hash or other identifier) in your run's configuration for your dataset by tracking it as input to your experiment using wandb.config
1
wandb.config.update({"dataset": "ab131"})
Copied!

Update Config Files

You can use the public API to add values your config file, even after the run has finished.
1
import wandb
2
api = wandb.Api()
3
run = api.run("username/project/run_id")
4
run.config["foo"] = 32
5
run.update()
Copied!

Key Value Pairs

You can log any key-value pairs into wandb.config. They can be different for every type of model you are training, e.g.wandb.config.update({"my_param": 10, "learning_rate": 0.3, "model_architecture": "B"}).

TensorFlow v1 Flags

You can pass TensorFlow flags into the wandb.config object directly.
1
wandb.init()
2
wandb.config.epochs = 4
3
4
flags = tf.app.flags
5
flags.DEFINE_string("data_dir", "/tmp/data")
6
flags.DEFINE_integer("batch_size", 128, "Batch size.")
7
wandb.config.update(flags.FLAGS) # adds all of the tensorflow flags as config
Copied!
Last modified 8mo ago