Skip to content

Commit 1af1071

Browse files
authored
Fix misleading WandB error when WANDB_DISABLED is set (#39891)
When users set `report_to="wandb"` but also have `WANDB_DISABLED=true` in their environment, the previous error message was misleading: "WandbCallback requires wandb to be installed. Run pip install wandb." This was confusing because wandb was actually installed, just disabled via the environment variable. The fix detects this specific case and provides a clear, actionable error message explaining the conflict and how to resolve it.
1 parent 78ef849 commit 1af1071

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/transformers/integrations/integration_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,19 @@ class WandbCallback(TrainerCallback):
806806
def __init__(self):
807807
has_wandb = is_wandb_available()
808808
if not has_wandb:
809+
# Check if wandb is actually installed but disabled via WANDB_DISABLED
810+
if importlib.util.find_spec("wandb") is not None:
811+
# wandb is installed but disabled
812+
wandb_disabled = os.getenv("WANDB_DISABLED", "").upper() in ENV_VARS_TRUE_VALUES
813+
if wandb_disabled:
814+
raise RuntimeError(
815+
"You specified `report_to='wandb'` but also set the `WANDB_DISABLED` environment variable.\n"
816+
"This disables wandb logging, even though it was explicitly requested.\n\n"
817+
"- To enable wandb logging: unset `WANDB_DISABLED`.\n"
818+
"- To disable logging: use `report_to='none'`.\n\n"
819+
"Note: WANDB_DISABLED is deprecated and will be removed in v5."
820+
)
821+
# If wandb is not installed at all, use the original error message
809822
raise RuntimeError("WandbCallback requires wandb to be installed. Run `pip install wandb`.")
810823
if has_wandb:
811824
import wandb

0 commit comments

Comments
 (0)