Skip to content

Commit 5cc98b8

Browse files
authored
init kwargs (#3)
1 parent a97cf2a commit 5cc98b8

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

mmf/configs/defaults.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ training:
5050
# it will log the run to your user account.
5151
entity: null
5252
# Project name to be used while logging the experiment with wandb
53-
wandb_projectname: mmf_${oc.env:USER,}
53+
project: mmf
5454
# Experiment/ run name to be used while logging the experiment
5555
# under the project with wandb
56-
wandb_runname: ${training.experiment_name}
56+
name: ${training.experiment_name}
5757
# Specify other argument values that you want to pass to wandb.init(). Check out the documentation
5858
# at https://docs.wandb.ai/ref/python/init to see what arguments are available.
5959
# job_type: 'train'

mmf/trainers/callbacks/logistics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ def __init__(self, config, trainer):
6060

6161
self.wandb_logger = WandbLogger(
6262
entity=config.training.wandb.entity,
63-
project=config.training.wandb.wandb_projectname,
6463
config=config,
65-
name=config.training.wandb.wandb_runname,
66-
save_dir=log_dir,
64+
project=config.training.wandb.project,
6765
)
6866

6967
def on_train_start(self):

mmf/utils/logger.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections
44
import functools
5-
import itertools
65
import json
76
import logging
87
import os
@@ -11,12 +10,14 @@
1110
from functools import wraps
1211
from typing import Any, Callable, Dict, Optional, Union
1312

13+
import omegaconf
1414
import torch
1515
from mmf.common.registry import registry
1616
from mmf.utils.configuration import get_mmf_env
1717
from mmf.utils.distributed import get_rank, is_main, is_xla
1818
from mmf.utils.file_io import PathManager
1919
from mmf.utils.timer import Timer
20+
from omegaconf import OmegaConf
2021
from termcolor import colored
2122

2223

@@ -226,17 +227,19 @@ def summarize_report(
226227
if not is_main() and not is_xla():
227228
return
228229

230+
# Log the learning rate if available
231+
if wandb_logger and "lr" in extra.keys():
232+
wandb_logger.log_metrics(
233+
{"train/learning_rate": float(extra["lr"])}, commit=False
234+
)
235+
229236
if tb_writer:
230237
scalar_dict = meter.get_scalar_dict()
231238
tb_writer.add_scalars(scalar_dict, current_iteration)
232239

233240
if wandb_logger:
234241
metrics = meter.get_scalar_dict()
235-
wandb_logger.log_metrics({**metrics, "trainer/global_step": current_iteration}, commit=False)
236-
237-
# Log the learning rate if available
238-
if wandb_logger and 'lr' in extra.keys():
239-
wandb_logger.log_metrics({"train/learning_rate": float(extra["lr"])})
242+
wandb_logger.log_metrics({**metrics, "trainer/global_step": current_iteration})
240243

241244
if not should_print:
242245
return
@@ -401,10 +404,8 @@ class WandbLogger:
401404
402405
Args:
403406
entity: An entity is a username or team name where you're sending runs.
404-
name: Display name for the run.
405-
save_dir: Path where data is saved (./save/logs/wandb/ by default).
406-
project: Display name for the project.
407407
config: Configuration for the run.
408+
project: Name of the W&B project.
408409
409410
Raises:
410411
ImportError: If wandb package is not installed.
@@ -413,10 +414,8 @@ class WandbLogger:
413414
def __init__(
414415
self,
415416
entity: Optional[str] = None,
416-
name: Optional[str] = None,
417-
save_dir: Optional[str] = None,
418-
project: Optional[str] = None,
419417
config: Optional[Dict] = None,
418+
project: Optional[str] = None,
420419
):
421420
try:
422421
import wandb
@@ -428,15 +427,15 @@ def __init__(
428427

429428
self._wandb = wandb
430429

431-
self._wandb_init = dict(
432-
entity=entity, name=name, project=project, dir=save_dir, config=config
433-
)
430+
self._wandb_init = dict(entity=entity, config=config, project=project)
434431

435-
init_kwargs = dict(
436-
itertools.islice(
437-
config.training.wandb.items(), 4, len(config.training.wandb)
438-
)
439-
)
432+
wandb_params = config.training.wandb
433+
with omegaconf.open_dict(wandb_params):
434+
wandb_params.pop("enabled")
435+
wandb_params.pop("entity")
436+
wandb_params.pop("project")
437+
438+
init_kwargs = OmegaConf.to_container(wandb_params, resolve=True)
440439
self._wandb_init.update(**init_kwargs)
441440

442441
self.setup()
@@ -473,7 +472,8 @@ def log_metrics(self, metrics: Dict[str, float], commit=True):
473472
474473
Args:
475474
metrics (Dict[str, float]): A dictionary of metrics to log.
476-
commit (bool): Save the metrics dict to the wandb server and increment the step. (default: True)
475+
commit (bool): Save the metrics dict to the wandb server and
476+
increment the step. (default: True)
477477
"""
478478
if not self._should_log_wandb():
479479
return

website/docs/notes/logging.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ sidebar_label: Weights and Biases Logging
88

99
MMF now has a `WandbLogger` class which lets the user to log their model's progress using [Weights and Biases](https://wandb.ai/site). Enable this logger to automatically log the training/validation metrics, system (GPU and CPU) metrics and configuration parameters.
1010

11-
## First time setup
11+
## First time setup
1212

1313
To set up wandb, run the following:
1414
```
1515
pip install wandb
1616
```
17-
In order to log anything to the W&B server you need to authenticate the machine with W&B **API key**. You can create a new account by going to https://wandb.ai/signup which will generate an API key. If you are an existing user you can retrieve your key from https://wandb.ai/authorize. You only need to supply your key once, and then it is remembered on the same device.
17+
In order to log anything to the W&B server you need to authenticate the machine with W&B **API key**. You can create a new account by going to https://wandb.ai/signup which will generate an API key. If you are an existing user you can retrieve your key from https://wandb.ai/authorize. You only need to supply your key once, and then it is remembered on the same device.
1818

1919
```
2020
wandb login
@@ -28,42 +28,42 @@ training:
2828
# Weights and Biases control, by default Weights and Biases (wandb) is disabled
2929
wandb:
3030
# Whether to use Weights and Biases Logger, (Default: false)
31-
enabled: false
31+
enabled: true
3232
# An entity is a username or team name where you're sending runs.
3333
# This is necessary if you want to log your metrics to a team account. By default
3434
# it will log the run to your user account.
3535
entity: null
3636
# Project name to be used while logging the experiment with wandb
37-
wandb_projectname: mmf_${oc.env:USER,}
37+
project: mmf
3838
# Experiment/ run name to be used while logging the experiment
3939
# under the project with wandb
40-
wandb_runname: ${training.experiment_name}
40+
name: ${training.experiment_name}
4141
# Specify other argument values that you want to pass to wandb.init(). Check out the documentation
4242
# at https://docs.wandb.ai/ref/python/init to see what arguments are available.
4343
# job_type: 'train'
4444
# tags: ['tag1', 'tag2']
4545
env:
4646
wandb_logdir: ${env:MMF_WANDB_LOGDIR,}
47-
```
47+
```
4848
4949
* To enable wandb logger the user needs to change the following option in the config.
5050
5151
`training.wandb.enabled=True`
5252

53-
* To give the `entity` which is the name of the team or the username, the user needs to change the following option in the config. In case no `entity` is provided, the data will be logged to the `entity` set as default in the user's settings.
53+
* To give the `entity` which is the name of the team or the username, the user needs to change the following option in the config. In case no `entity` is provided, the data will be logged to the `entity` set as default in the user's settings.
5454

5555
`training.wandb.entity=<teamname/username>`
5656

57-
* To give the current experiment a project and run name, user should add these config options.
57+
* To give the current experiment a project and run name, user should add these config options. The default project name is `mmf` and the default run name is `${training.experiment_name}`.
5858

59-
`training.wandb.wandb_projectname=<ProjectName>` <br>
60-
`training.wandb.wandb_runname=<RunName>`
59+
`training.wandb.project=<ProjectName>` <br>
60+
`training.wandb.name=<RunName>`
6161

6262
* To change the path to the directory where wandb metadata would be stored (Default: `env.log_dir`):
6363

6464
`env.wandb_logdir=<dir_name>`
6565

66-
* To provide extra arguments to `wandb.init()`, the user just needs to define them in the config file. Check out the documentation at https://docs.wandb.ai/ref/python/init to see what arguments are available. An example is shown in the config parameter shown above.
66+
* To provide extra arguments to `wandb.init()`, the user just needs to define them in the config file. Check out the documentation at https://docs.wandb.ai/ref/python/init to see what arguments are available. An example is shown in the config parameter shown above. Make sure to use the same key name in the config file as defined in the documentation.
6767

6868
## Current features
6969

0 commit comments

Comments
 (0)