Skip to content

Commit

Permalink
[refactor] Extend WandbLogger to log config variables, entity and kwa…
Browse files Browse the repository at this point in the history
…rgs (#1)

ability to log config file, initialize wandb with kwargs and pass entity argument for teams account.
  • Loading branch information
ayulockin committed Oct 20, 2021
1 parent c172069 commit 78b1428
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions mmf/configs/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ training:
wandb:
# Whether to use Weights and Biases Logger, (Default: false)
enabled: false
# An entity is a username or team name where you're sending runs.
# This is necessary if you want to log your metrics to a team account. By default
# it will log the run to your user account.
entity: null
# Project name to be used while logging the experiment with wandb
wandb_projectname: mmf_${oc.env:USER,}
# Experiment/ run name to be used while logging the experiment
# under the project with wandb
wandb_runname: ${training.experiment_name}
# Specify other argument values to be used while logging the experiment
init_kwargs:
job_type: train


# Size of the batch globally. If distributed or data_parallel
# is used, this will be divided equally among GPUs
Expand Down
10 changes: 7 additions & 3 deletions mmf/trainers/callbacks/logistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ def __init__(self, config, trainer):
if env_wandb_logdir:
log_dir = env_wandb_logdir

wandb_projectname = config.training.wandb.wandb_projectname
wandb_runname = config.training.wandb.wandb_runname
wandb_init_kwargs = config.training.wandb.init_kwargs

self.wandb_logger = WandbLogger(
name=wandb_runname, save_dir=log_dir, project=wandb_projectname
entity=config.training.wandb.entity,
project=config.training.wandb.wandb_projectname,
config=config,
name=config.training.wandb.wandb_runname,
save_dir=log_dir,
**wandb_init_kwargs,
)

def on_train_start(self):
Expand Down
8 changes: 7 additions & 1 deletion mmf/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,11 @@ class WandbLogger:
Log using `Weights and Biases`.
Args:
entity: An entity is a username or team name where you're sending runs.
name: Display name for the run.
save_dir: Path where data is saved (./save/logs/wandb/ by default).
project: Display name for the project.
config: Configuration for the run.
**init_kwargs: Arguments passed to :func:`wandb.init`.
Raises:
Expand All @@ -406,9 +408,11 @@ class WandbLogger:

def __init__(
self,
entity: Optional[str] = None,
name: Optional[str] = None,
save_dir: Optional[str] = None,
project: Optional[str] = None,
config: Optional[Dict] = None,
**init_kwargs,
):
try:
Expand All @@ -421,7 +425,9 @@ def __init__(

self._wandb = wandb

self._wandb_init = dict(name=name, project=project, dir=save_dir)
self._wandb_init = dict(
entity=entity, name=name, project=project, dir=save_dir, config=config
)

self._wandb_init.update(**init_kwargs)

Expand Down

0 comments on commit 78b1428

Please sign in to comment.