From 24881008a6743e958cc619133b8ee6994ed1cb8c Mon Sep 17 00:00:00 2001 From: Stas Bekman Date: Mon, 1 Feb 2021 00:14:06 -0800 Subject: [PATCH] [wandb] restore WANDB_DISABLED=true to disable wandb (#9896) * [t5 doc] typos a few run away backticks @sgugger * style * [trainer] put fp16 args together this PR proposes a purely cosmetic change that puts all the fp16 args together - so they are easier to manager/read @sgugger * style * [wandb] make WANDB_DISABLED disable wandb with any value This PR solves part of https://github.com/huggingface/transformers/issues/9623 It tries to actually do what https://github.com/huggingface/transformers/issues/9699 requested/discussed and that is any value of `WANDB_DISABLED` should disable wandb. The current behavior is that it has to be one of `ENV_VARS_TRUE_VALUES = {"1", "ON", "YES"}` I have been using `WANDB_DISABLED=true` everywhere in scripts as it was originally advertised. I have no idea why this was changed to a sub-set of possible values. And it's not documented anywhere. @sgugger * WANDB_DISABLED=true to disable; make tf trainer consistent * style --- src/transformers/file_utils.py | 2 +- src/transformers/integrations.py | 3 ++- src/transformers/trainer_tf.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/transformers/file_utils.py b/src/transformers/file_utils.py index fc4f73b686..eb6ccdd233 100644 --- a/src/transformers/file_utils.py +++ b/src/transformers/file_utils.py @@ -59,7 +59,7 @@ else: logger = logging.get_logger(__name__) # pylint: disable=invalid-name -ENV_VARS_TRUE_VALUES = {"1", "ON", "YES"} +ENV_VARS_TRUE_VALUES = {"1", "ON", "YES", "TRUE"} ENV_VARS_TRUE_AND_AUTO_VALUES = ENV_VARS_TRUE_VALUES.union({"AUTO"}) USE_TF = os.environ.get("USE_TF", "AUTO").upper() diff --git a/src/transformers/integrations.py b/src/transformers/integrations.py index f66989381d..bc4e2a3b7a 100644 --- a/src/transformers/integrations.py +++ b/src/transformers/integrations.py @@ -54,6 +54,7 @@ from .trainer_utils import PREFIX_CHECKPOINT_DIR, BestRun, EvaluationStrategy # # Integration functions: def is_wandb_available(): + # any value of WANDB_DISABLED disables wandb if os.getenv("WANDB_DISABLED", "").upper() in ENV_VARS_TRUE_VALUES: return False return importlib.util.find_spec("wandb") is not None @@ -535,7 +536,7 @@ class WandbCallback(TrainerCallback): WANDB_PROJECT (:obj:`str`, `optional`, defaults to :obj:`"huggingface"`): Set this to a custom string to store results in a different project. WANDB_DISABLED (:obj:`bool`, `optional`, defaults to :obj:`False`): - Whether or not to disable wandb entirely. + Whether or not to disable wandb entirely. Set `WANDB_DISABLED=true` to disable. """ if self._wandb is None: return diff --git a/src/transformers/trainer_tf.py b/src/transformers/trainer_tf.py index ed5d34a8bf..adc08e6c7c 100644 --- a/src/transformers/trainer_tf.py +++ b/src/transformers/trainer_tf.py @@ -18,6 +18,8 @@ import math import os from typing import Callable, Dict, Optional, Tuple +from .file_utils import ENV_VARS_TRUE_VALUES + # Integrations must be imported before ML frameworks: from .integrations import ( # isort: split @@ -110,7 +112,7 @@ class TFTrainer: if is_wandb_available(): self.setup_wandb() - elif os.environ.get("WANDB_DISABLED") != "true": + elif os.getenv("WANDB_DISABLED", "").upper() not in ENV_VARS_TRUE_VALUES: logger.info( "You are instantiating a Trainer but W&B is not installed. To use wandb logging, " "run `pip install wandb; wandb login` see https://docs.wandb.com/huggingface."