Configure experiments
6 minute read
Use the config
property of a run to save your training configuration:
- hyperparameter
- input settings such as the dataset name or model type
- any other independent variables for your experiments.
The run.config
property makes it easy to analyze your experiments and reproduce your work in the future. You can group by configuration values in the W&B App, compare the configurations of different W&B runs, and evaluate how each training configuration affects the output. The config
property is a dictionary-like object that can be composed from multiple dictionary-like objects.
run.log
instead of run.config
.Set up an experiment configuration
Configurations are typically defined in the beginning of a training script. Machine learning workflows may vary, however, so you are not required to define a configuration at the beginning of your training script.
Use dashes (-
) or underscores (_
) instead of periods (.
) in your config variable names.
Use the dictionary access syntax ["key"]["value"]
instead of the attribute access syntax config.key.value
if your script accesses run.config
keys below the root.
The following sections outline different common scenarios of how to define your experiments configuration.
Set the configuration at initialization
Pass a dictionary at the beginning of your script when you call the wandb.init()
API to generate a background process to sync and log data as a W&B Run.
The proceeding code snippet demonstrates how to define a Python dictionary with configuration values and how to pass that dictionary as an argument when you initialize a W&B Run.
If you pass a nested dictionary as the config
, W&B flattens the names using dots.
Access the values from the dictionary similarly to how you access other dictionaries in Python:
Set the configuration with argparse
You can set your configuration with an argparse object. argparse, short for argument parser, is a standard library module in Python 3.2 and above that makes it easy to write scripts that take advantage of all the flexibility and power of command line arguments.
This is useful for tracking results from scripts that are launched from the command line.
The proceeding Python script demonstrates how to define a parser object to define and set your experiment config. The functions train_one_epoch
and evaluate_one_epoch
are provided to simulate a training loop for the purpose of this demonstration:
Set the configuration throughout your script
You can add more parameters to your config object throughout your script. The proceeding code snippet demonstrates how to add new key-value pairs to your config object:
You can update multiple values at a time:
Set the configuration after your Run has finished
Use the W&B Public API to update a completed run’s config.
You must provide the API with your entity, project name and the run’s ID. You can find these details in the Run object or in the W&B App UI:
absl.FLAGS
You can also pass in absl
flags.
File-Based Configs
If you place a file named config-defaults.yaml
in the same directory as your run script, the run automatically picks up the key-value pairs defined in the file and passes them to run.config
.
The following code snippet shows a sample config-defaults.yaml
YAML file:
You can override the default values automatically loaded from config-defaults.yaml
by setting updated values in the config
argument of wandb.init
. For example:
To load a configuration file other than config-defaults.yaml
, use the --configs command-line
argument and specify the path to the file:
Example use case for file-based configs
Suppose 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:
TensorFlow v1 flags
You can pass TensorFlow flags into the wandb.config
object directly.
Feedback
Was this page helpful?
Glad to hear it! If you have more to say, please let us know.
Sorry to hear that. Please tell us how we can improve.