Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
allow W&B anon mode (#5110)
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Apr 22, 2021
1 parent 4e862a5 commit 6ec6459
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added a T5 implementation to `modules.transformers`.

### Changed

- Weights & Biases callback can now work in anonymous mode (i.e. without the `WANDB_API_KEY` environment variable).

### Fixed

- Fixed `cached_path()` for "hf://" files.
Expand Down
13 changes: 11 additions & 2 deletions allennlp/training/callbacks/wandb.py
@@ -1,3 +1,4 @@
import logging
import os
from typing import Optional, Dict, Any, List, Union, Tuple, TYPE_CHECKING

Expand All @@ -13,13 +14,18 @@
from allennlp.training.trainer import GradientDescentTrainer


logger = logging.getLogger(__name__)


@TrainerCallback.register("wandb")
class WandBCallback(LogWriterCallback):
"""
Logs training runs to Weights & Biases.
!!! Note
This requires the environment variable 'WANDB_API_KEY' to be set.
This requires the environment variable 'WANDB_API_KEY' to be set in order
to authenticate with Weights & Biases. If not set, you may be prompted to
log in or upload the experiment to an anonymous account.
In addition to the parameters that `LogWriterCallback` takes, there are several other
parameters specific to `WandBWriter` listed below.
Expand Down Expand Up @@ -67,7 +73,9 @@ def __init__(
wandb_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
if "WANDB_API_KEY" not in os.environ:
raise ValueError("Missing environment variable 'WANDB_API_KEY'")
logger.warning(
"Missing environment variable 'WANDB_API_KEY' required to authenticate to Weights & Biases."
)

super().__init__(
serialization_dir,
Expand All @@ -93,6 +101,7 @@ def __init__(
notes=notes,
config=Params.from_file(os.path.join(serialization_dir, "config.json")).as_dict(),
tags=tags,
anonymous="allow",
**(wandb_kwargs or {}),
)

Expand Down

0 comments on commit 6ec6459

Please sign in to comment.