Environment variables
When you're running a script in an automated environment, you can control wandb with environment variables set before the script runs or within the script.
# This is secret and shouldn't be checked into version control
WANDB_API_KEY=$YOUR_API_KEY
# Name and notes optional
WANDB_NAME="My first run"
WANDB_NOTES="Smaller learning rate, more regularization."
# Only needed if you don't check in the wandb/settings file
WANDB_ENTITY=$username
WANDB_PROJECT=$project
# If you don't want your script to sync to the cloud
os.environ["WANDB_MODE"] = "offline"
Optional environment variables
Use these optional environment variables to do things like set up authentication on remote machines.
Variable name | Usage |
---|---|
WANDB_ANONYMOUS | Set this to "allow", "never", or "must" to let users create anonymous runs with secret urls. |
WANDB_API_KEY | Sets the authentication key associated with your account. You can find your key on your settings page. This must be set if wandb login hasn't been run on the remote machine. |
WANDB_BASE_URL | If you're using wandb/local you should set this environment variable to http://YOUR_IP:YOUR_PORT |
WANDB_CACHE_DIR | This defaults to ~/.cache/wandb, you can override this location with this environment variable |
WANDB_CONFIG_DIR | This defaults to ~/.config/wandb, you can override this location with this environment variable |
WANDB_CONFIG_PATHS | Comma separated list of yaml files to load into wandb.config. See config. |
WANDB_CONSOLE | Set this to "off" to disable stdout / stderr logging. This defaults to "on" in environments that support it. |
WANDB_DIR | Set this to an absolute path to store all generated files here instead of the wandb directory relative to your training script. be sure this directory exists and the user your process runs as can write to it |
WANDB_DISABLE_GIT | Prevent wandb from probing for a git repository and capturing the latest commit / diff. |
WANDB_DISABLE_CODE | Set this to true to prevent wandb from saving notebooks or git diffs. We'll still save the current commit if we're in a git repo. |
WANDB_DOCKER | Set this to a docker image digest to enable restoring of runs. This is set automatically with the wandb docker command. You can obtain an image digest by running wandb docker my/image/name:tag --digest |
WANDB_ENTITY | The entity associated with your run. If you have run wandb init in the directory of your training script, it will create a directory named wandb and will save a default entity which can be checked into source control. If you don't want to create that file or want to override the file you can use the environmental variable. |
WANDB_ERROR_REPORTING | Set this to false to prevent wandb from logging fatal errors to its error tracking system. |
WANDB_HOST | Set this to the hostname you want to see in the wandb interface if you don't want to use the system provided hostname |
WANDB_IGNORE_GLOBS | Set this to a comma separated list of file globs to ignore. These files will not be synced to the cloud. |
WANDB_JOB_NAME | Specify a name for any jobs created by wandb . For more information, see create a job |
WANDB_JOB_TYPE | Specify the job type, like "training" or "evaluation" to indicate different types of runs. See grouping for more info. |
WANDB_MODE | If you set this to "offline" wandb will save your run metadata locally and not sync to the server. If you set this to "disabled" wandb will turn off completely. |
WANDB_NAME | The human-readable name of your run. If not set it will be randomly generated for you |
WANDB_NOTEBOOK_NAME | If you're running in jupyter you can set the name of the notebook with this variable. We attempt to auto detect this. |
WANDB_NOTES | Longer notes about your run. Markdown is allowed and you can edit this later in the UI. |
WANDB_PROJECT | The project associated with your run. This can also be set with wandb init , but the environmental variable will override the value. |
WANDB_RESUME | By default this is set to never. If set to auto wandb will automatically resume failed runs. If set to must forces the run to exist on startup. If you want to always generate your own unique ids, set this to allow and always set WANDB_RUN_ID. |
WANDB_RUN_GROUP | Specify the experiment name to automatically group runs together. See grouping for more info. |
WANDB_RUN_ID | Set this to a globally unique string (per project) corresponding to a single run of your script. It must be no longer than 64 characters. All non-word characters will be converted to dashes. This can be used to resume an existing run in cases of failure. |
WANDB_SILENT | Set this to true to silence wandb log statements. If this is set all logs will be written to WANDB_DIR/debug.log |
WANDB_SHOW_RUN | Set this to true to automatically open a browser with the run url if your operating system supports it. |
WANDB_TAGS | A comma separated list of tags to be applied to the run. |
WANDB_USERNAME | The username of a member of your team associated with the run. This can be used along with a service account API key to enable attribution of automated runs to members of your team. |
WANDB_USER_EMAIL | The email of a member of your team associated with the run. This can be used along with a service account API key to enable attribution of automated runs to members of your team. |
Singularity environments
If you're running containers in Singularity you can pass environment variables by pre-pending the above variables with SINGULARITYENV_. More details about Singularity environment variables can be found here.
Running on AWS
If you're running batch jobs in AWS, it's easy to authenticate your machines with your W&B credentials. Get your API key from your settings page, and set the WANDB_API_KEY environment variable in the AWS batch job spec.
Common Questions
Automated runs and service accounts
If you have automated tests or internal tools that launch runs logging to W&B, create a Service Account on your team settings page. This will allow you to use a service API key for your automated jobs. If you want to attribute service account jobs to a specific user, you can use the WANDB_USERNAME or WANDB_USER_EMAIL environment variables.
This is useful for continuous integration and tools like TravisCI or CircleCI if you're setting up automated unit tests.
Do environment variables overwrite the parameters passed to wandb.init()?
Arguments passed to wandb.init
take precedence over the environment. You could call wandb.init(dir=os.getenv("WANDB_DIR", my_default_override))
if you want to have a default other than the system default when the environment variable isn't set.
Turn off logging
The command wandb offline
sets an environment variable, WANDB_MODE=offline
. This stops any data from syncing from your machine to the remote wandb server. If you have multiple projects, they will all stop syncing logged data to W&B servers.
To quiet the warning messages:
import logging
logger = logging.getLogger("wandb")
logger.setLevel(logging.WARNING)
Multiple wandb users on shared machines
If you're using a shared machine and another person is a wandb user, it's easy to make sure your runs are always logged to the proper account. Set the WANDB_API_KEY environment variable to authenticate. If you source it in your env, when you log in you'll have the right credentials, or you can set the environment variable from your script.
Run this command export WANDB_API_KEY=X
where X is your API key. When you're logged in, you can find your API key at wandb.ai/authorize.