Skip to content

Commit

Permalink
feat(wandb): save models on wandb (#1339)
Browse files Browse the repository at this point in the history
* feat(wandb): save models on wandb

* docs(changelog): allow to upload models on W&B
  • Loading branch information
borisdayma authored Apr 2, 2020
1 parent 04935ea commit 6b41b5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added support for `IterableDataset` when `val_check_interval=1.0` (default), this will trigger validation at the end of each epoch. ([#1283](https://github.com/PyTorchLightning/pytorch-lightning/pull/1283))
- Added `summary` method to Profilers. ([#1259](https://github.com/PyTorchLightning/pytorch-lightning/pull/1259))
- Added informative errors if user defined dataloader has zero length ([#1280](https://github.com/PyTorchLightning/pytorch-lightning/pull/1280))
- Allow to upload models on W&B ([#1339](https://github.com/PyTorchLightning/pytorch-lightning/pull/1339))

### Changed

Expand Down
8 changes: 7 additions & 1 deletion pytorch_lightning/loggers/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WandbLogger(LightningLoggerBase):
anonymous (bool): enables or explicitly disables anonymous logging.
project (str): the name of the project to which this run will belong.
tags (list of str): tags associated with this run.
log_model (bool): save checkpoints in wandb dir to upload on W&B servers.
Example
--------
Expand All @@ -48,7 +49,8 @@ class WandbLogger(LightningLoggerBase):
def __init__(self, name: Optional[str] = None, save_dir: Optional[str] = None,
offline: bool = False, id: Optional[str] = None, anonymous: bool = False,
version: Optional[str] = None, project: Optional[str] = None,
tags: Optional[List[str]] = None, experiment=None, entity=None):
tags: Optional[List[str]] = None, log_model: bool = False,
experiment=None, entity=None):
super().__init__()
self._name = name
self._save_dir = save_dir
Expand All @@ -59,6 +61,7 @@ def __init__(self, name: Optional[str] = None, save_dir: Optional[str] = None,
self._experiment = experiment
self._offline = offline
self._entity = entity
self._log_model = log_model

def __getstate__(self):
state = self.__dict__.copy()
Expand All @@ -85,6 +88,9 @@ def experiment(self) -> Run:
self._experiment = wandb.init(
name=self._name, dir=self._save_dir, project=self._project, anonymous=self._anonymous,
id=self._id, resume='allow', tags=self._tags, entity=self._entity)
# save checkpoints in wandb dir to upload on W&B servers
if self._log_model:
self.save_dir = self._experiment.dir
return self._experiment

def watch(self, model: nn.Module, log: str = 'gradients', log_freq: int = 100):
Expand Down

0 comments on commit 6b41b5c

Please sign in to comment.