Skip to content

Commit

Permalink
Do not use wandb if not specified in the config file (#1253)
Browse files Browse the repository at this point in the history
#1252, even if the config file does NOT include any wandb field, training with ivadomed can use wandb in case wandb logging was previously done, indicating that deliberate omission of the value to `wandb_api_key` while logging in and the anonymous logging feature introduced in #1193 could sometimes be misleading and undesired. Hence, this PR undoes and simplifies it by bypassing the `wandb.login` call if the key is not defined or is empty.

Co-authored-by: Kanishk Kalra <36276423+kanishk16@users.noreply.github.com>
  • Loading branch information
jcohenadad and kanishk16 committed Jan 17, 2023
1 parent e9739b7 commit 8b70c30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions docs/source/configuration_file.rst
Expand Up @@ -173,8 +173,7 @@ without an account, since the metrics are logged on Tensorboard by default.
"A private key used to sync the local wandb folder with the wandb dashboard accessible through the browser.\n",
"The API key can be found from the browser in your WandB Account's Settings, under the section ``API Keys``.\n",
"Note that once it is successfully authenticated, a message would be printed in the terminal notifying\n",
"that the API key is stored in the ``.netrc`` file in the ``/home`` folder. From then on, the value in this key-value\n",
"pair in the config file could be omitted, like ``'wandb_api_key': ''``"
"that the API key is stored in the ``.netrc`` file in the ``/home`` folder.
],
"type": "string"
}
Expand Down
12 changes: 12 additions & 0 deletions ivadomed/utils.py
Expand Up @@ -35,7 +35,19 @@ def __str__(self):


def initialize_wandb(wandb_params):
"""Initializes WandB and based upon the parameters sets it up or disables it for experimental tracking
Args:
wandb_params (dict): wandb parameters
Returns:
bool, wandb_tracking: True if wandb tracking is enabled
"""
try:
# raise an error if the key is empty
if not bool(wandb_params[WandbKW.WANDB_API_KEY].strip()):
raise ValueError()

# Log on to WandB (assuming that the API Key is correct)
# if not, login would raise an exception for the cases invalid API key and not found
wandb.login(key=wandb_params[WandbKW.WANDB_API_KEY], anonymous='allow', timeout=60)
Expand Down

0 comments on commit 8b70c30

Please sign in to comment.