2020-08-20 02:03:22 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2020-04-16 16:04:12 +00:00
|
|
|
"""
|
2020-11-13 15:05:54 +00:00
|
|
|
Weights and Biases Logger
|
|
|
|
-------------------------
|
2020-02-11 04:55:22 +00:00
|
|
|
"""
|
2020-01-14 03:25:27 +00:00
|
|
|
import os
|
2020-03-04 14:33:39 +00:00
|
|
|
from argparse import Namespace
|
2020-12-21 09:15:04 +00:00
|
|
|
from typing import Any, Dict, Optional, Union
|
2020-01-14 03:25:27 +00:00
|
|
|
|
2020-03-03 01:49:14 +00:00
|
|
|
import torch.nn as nn
|
|
|
|
|
2021-01-05 19:34:47 +00:00
|
|
|
from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
|
2021-01-15 17:23:56 +00:00
|
|
|
from pytorch_lightning.utilities import _module_available, rank_zero_only
|
2021-02-02 17:06:11 +00:00
|
|
|
from pytorch_lightning.utilities.exceptions import MisconfigurationException
|
PoC: Accelerator refactor (#5743)
* restoring the result from subprocess
* fix queue.get() order for results
* add missing "block_backward_sync" context manager
* add missing "block_backward_sync" context manager
* fix sync_batchnorm
* fix supported gpu-ids for tuple
* fix clip gradients and inf recursion
* accelerator selection: added cluster_environment plugin
* fix torchelastic test
* fix reduce early stopping decision for DDP
* fix tests: callbacks, conversion to lightning optimizer
* fix lightning optimizer does not pickle
* fix setting benchmark and deterministic option
* fix slurm amp test
* fix prepare_data test and determine node_rank
* fix retrieving last path when testing
* remove obsolete plugin argument
* fix test: test_trainer_config
* fix torchscript tests
* fix trainer.model access
* move properties
* fix test_transfer_batch_hook
* fix auto_select_gpus
* fix omegaconf test
* fix test that needs to simulate slurm ddp
* add horovod plugin
* fix test with named arguments
* clean up whitespace
* fix datamodules test
* remove old accelerators
* fix naming
* move old plugins
* move to plugins
* create precision subpackage
* create training_type subpackage
* fix all new import errors
* fix wrong arguments order passed to test
* fix LR finder
* Added sharded training type and amp plugin
* Move clip grad to precision plugin
* Added sharded spawn, select accelerators based on distributed_backend + enable custom fp16 plugin automatically
* Fix import issue, attempting to fix tests
* Fix initial test
* Reflect hook logic from master, should wrap model after move to device
* Optional state consolidation, since master has optimizers not wrapped
* change attribute for instance test
* reset optimizers
optimizers are not used in main process, so state would be wrong.
* legacy
* imports in accel
* legacy2
* trainer imports
* fix import errors after rebase
* move hook to new setup location
* provide unwrapping logic
* fix trainer callback system
* added ddp2 implementation
* fix imports .legacy
* move plugins
* restore legacy
* drop test.py from root
* add tpu accelerator and plugins
* fixes
* fix lightning optimizer merge
* reset bugreportmodel
* unwrapping
* step routing forward
* model access
* unwrap
* opt
* integrate distrib_type
* sync changes
* sync
* fixes
* add forgotten generators
* add missing logic
* update
* import
* missed imports
* import fixes
* isort
* mv f
* changelog
* format
* move helper to parallel plugin
* d
* add world size
* clean up
* duplicate
* activate ddp_sharded and tpu
* set nvidia flags
* remove unused colab var
* use_tpu <-> on_tpu attrs
* make some ddp_cpu and clusterplugin tests pass
* Ref/accelerator connector (#5742)
* final cleanup
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* connector cleanup
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* trainer cleanup
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* accelerator cleanup + missing logic in accelerator connector
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* add missing changes to callbacks
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* reflect accelerator changes to lightning module
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* clean cluster envs
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* cleanup plugins
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* add broadcasting
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* yapf
* remove plugin connector
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* plugins
* manual optimization
* update optimizer routing
* add rank to torchelastic
* fix memory mixed precision
* setstate on trainer for pickling in ddp spawn
* add predict method
* add back commented accelerator code
* adapt test for sync_batch_norm to new plugin
* fix deprecated tests
* fix ddp cpu choice when no num_processes are given
* yapf format
* skip a memory test that cannot pass anymore
* fix pickle error in spawn plugin
* x
* avoid
* x
* fix cyclic import in docs build
* add support for sharded
* update typing
* add sharded and sharded_spawn to distributed types
* make unwrap model default
* refactor LightningShardedDataParallel similar to LightningDistributedDataParallel
* update sharded spawn to reflect changes
* update sharded to reflect changes
* Merge 1.1.5 changes
* fix merge
* fix merge
* yapf isort
* fix merge
* yapf isort
* fix indentation in test
* copy over reinit scheduler implementation from dev1.2
* fix apex tracking calls with dev_debugger
* reduce diff to dev1.2, clean up
* fix trainer config test when gpus>0 and num_processes >0 and ddp_cpu
* sort plugin tests legacy/new
* fix error handling for amp on cpu
* fix merge
fix merge
fix merge
* [Feat] Resolve manual_backward (#5837)
* resolve manual_backward
* resolve flake8
* update
* resolve for ddp_spawn
* resolve flake8
* resolve flake8
* resolve flake8
Co-authored-by: Ubuntu <ubuntu@ip-172-31-88-60.ec2.internal>
* fix tests/accelerator tests on cpu
* [BugFix] Resolve manual optimization (#5852)
* resolve manual_optimization
* update
* update
Co-authored-by: Ubuntu <ubuntu@ip-172-31-88-60.ec2.internal>
* Remove copy trainer parameters to happen earlier within the loop and add safe guard to get ref model (#5856)
* resovle a bug
* Accelerator refactor sharded rpc (#5854)
* rpc branch
* merge
* update handling of rpc
* make devices etc. Optional in RPC
* set devices etc. later if necessary
* remove devices from sequential
* make devices optional in rpc
* fix import
* uncomment everything
* fix cluster selection
Co-authored-by: Ubuntu <ubuntu@ip-172-31-88-60.ec2.internal>
* resolve bug
* fix assert in rpc test
* resolve a test
* fix docs compilation
* accelerator refactor - fix for sharded parity test (#5866)
* fix memory issue with ddp_spawn
* x
x
x
x
x
x
x
x
x
* x
* Remove DDP2 as this does not apply
* Add missing pre optimizer hook to ensure lambda closure is called
* fix apex docstring
* [accelerator][BugFix] Resolve some test for 1 gpu (#5863)
* update
* revert init
* resolve a bug
* update
* resolve flake8
* update
* update
* update
* revert init
* resolve a bug
* update
* resolve flake8
* update
* update
* update
* update
* update
* revert init
* resolve a bug
* update
* resolve flake8
* update
* update
* update
* revert init
* update
* resolve flake8
* update
* update
* update
* update
* update
* all_gather
* update
* make plugins work, add misconfig for RPC
* update
* update
* remove breaking test
* resolve some tests
* resolve flake8
* revert to ddp_spawn
Co-authored-by: root <root@ip-172-31-88-60.ec2.internal>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-88-60.ec2.internal>
Co-authored-by: Justus Schock <justus.schock@rwth-aachen.de>
* yapf isort
* resolve flake8
* fix apex doctests
* fix apex doctests 2
* resolve docs
* update drone
* clean env
* update
* update
* update
* update
* merge
* Fix RPC related tests, clean out old API, update for new accelerator API [skip ci] (#5881)
* Fix RPC related tests, clean out old API, update for new accelerator API
* Move tests out of legacy folder, update paths and names
* Update test_remove_1-4.py
* Expose properties for tpu cores/gpus/num_gpus
* Add root GPU property
* Move properties to properties.py
* move tests that were previously in drone
* Fix root GPU property (#5908)
* Move root GPU to property, remove horovod set as this is handled in horovod plugin, ensure we mock correctly to set GPU accelerator
* Add missing tests back
* fix best model path transfer when no checkpoint callback available
* Fix setup hook order [wip] (#5858)
* Call trainer setup hook before accelerator setup
* Add test case
* add new test
* typo
* fix callback order in test
Co-authored-by: tchaton <thomas@grid.ai>
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* rename ddp sequential -> rpc sequential for special test
* revert
* fix stupid merge problem
* Use property in connector for sampler (#5913)
* merge the import conflicts
* fix spawning of processes in slurm
* [wip] Fix some bugs for TPU [skip ci] (#5878)
* fixed for single tpu
* fixed spawn
* fixed spawn
* update
* update
* wip
* resolve bugs
* resolve bug
* update on comment
* removed decorator
* resolve comments
* set to 4
* update
* update
* need cleaning
* update
* update
* update
* resolve flake8
* resolve bugs
* exclude broadcast
* resolve bugs
* change test
* update
* update
* skip if meet fails
* properly raise trace
* update
* add catch
* wrap test
* resolve typo
* update
* typo
Co-authored-by: Lezwon Castelino <lezwon@gmail.com>
Co-authored-by: Your Name <you@example.com>
* resolve some tests
* update
* fix imports
* update
* resolve flake8
* update azure pipeline
* skip a sharded test on cpu that requires a gpu
* resolve tpus
* resolve bug
* resolve flake8
* update
* updat utils
* revert permission change on files
* suggestions from carlos
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
* remove unrelated formatting changes
* remove incomplete comment
* Update pytorch_lightning/accelerators/__init__.py
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
* remove unrelated formatting change
* add types
* warn 1.7 ddp manual backward only if ddp kwarg unset
* yapf + isort
* pep8 unused imports
* fix cyclic import in docs
* Apply suggestions from code review
* typer in accelerator.py
* typo
* Apply suggestions from code review
* formatting
* update on comments
* update typo
* Update pytorch_lightning/trainer/properties.py
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
* update
* suggestion from code review
* suggestion from code review
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: SeanNaren <sean@grid.ai>
Co-authored-by: Jirka Borovec <jirka.borovec@seznam.cz>
Co-authored-by: chaton <thomas@grid.ai>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-88-60.ec2.internal>
Co-authored-by: Sean Naren <sean.narenthiran@gmail.com>
Co-authored-by: root <root@ip-172-31-88-60.ec2.internal>
Co-authored-by: Lezwon Castelino <lezwon@gmail.com>
Co-authored-by: Your Name <you@example.com>
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-02-12 20:48:56 +00:00
|
|
|
from pytorch_lightning.utilities.warnings import WarningCache
|
2021-01-05 19:34:47 +00:00
|
|
|
|
2021-02-27 01:52:23 +00:00
|
|
|
warning_cache = WarningCache()
|
|
|
|
|
2021-01-05 19:34:47 +00:00
|
|
|
_WANDB_AVAILABLE = _module_available("wandb")
|
|
|
|
|
2020-01-14 03:25:27 +00:00
|
|
|
try:
|
2021-01-24 12:32:02 +00:00
|
|
|
import wandb
|
2021-01-25 19:31:38 +00:00
|
|
|
from wandb.wandb_run import Run
|
2021-01-05 19:34:47 +00:00
|
|
|
except ImportError:
|
|
|
|
# needed for test mocks, these tests shall be updated
|
|
|
|
wandb, Run = None, None
|
2020-01-14 03:25:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WandbLogger(LightningLoggerBase):
|
2020-09-19 16:51:43 +00:00
|
|
|
r"""
|
2020-11-13 15:05:54 +00:00
|
|
|
Log using `Weights and Biases <https://www.wandb.com/>`_.
|
|
|
|
|
|
|
|
Install it with pip:
|
2020-04-16 16:04:12 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
pip install wandb
|
2020-01-14 03:25:27 +00:00
|
|
|
|
|
|
|
Args:
|
2020-04-16 16:04:12 +00:00
|
|
|
name: Display name for the run.
|
2021-01-24 22:44:09 +00:00
|
|
|
save_dir: Path where data is saved (wandb dir by default).
|
2020-04-16 16:04:12 +00:00
|
|
|
offline: Run offline (data can be streamed later to wandb servers).
|
|
|
|
id: Sets the version, mainly used to resume a previous run.
|
2021-01-24 22:44:09 +00:00
|
|
|
version: Same as id.
|
2020-04-16 16:04:12 +00:00
|
|
|
anonymous: Enables or explicitly disables anonymous logging.
|
|
|
|
project: The name of the project to which this run will belong.
|
|
|
|
log_model: Save checkpoints in wandb dir to upload on W&B servers.
|
2020-11-22 05:38:58 +00:00
|
|
|
prefix: A string to put at the beginning of metric keys.
|
2021-01-24 22:44:09 +00:00
|
|
|
experiment: WandB experiment object. Automatically set when creating a run.
|
2020-09-19 16:51:43 +00:00
|
|
|
\**kwargs: Additional arguments like `entity`, `group`, `tags`, etc. used by
|
|
|
|
:func:`wandb.init` can be passed as keyword arguments in this logger.
|
2020-04-16 16:04:12 +00:00
|
|
|
|
2021-02-25 20:08:32 +00:00
|
|
|
Raises:
|
|
|
|
ImportError:
|
|
|
|
If required WandB package is not installed on the device.
|
|
|
|
MisconfigurationException:
|
|
|
|
If both ``log_model`` and ``offline``is set to ``True``.
|
|
|
|
|
2021-02-16 19:14:01 +00:00
|
|
|
Example::
|
2020-11-23 20:01:28 +00:00
|
|
|
|
2020-09-25 14:00:02 +00:00
|
|
|
from pytorch_lightning.loggers import WandbLogger
|
|
|
|
from pytorch_lightning import Trainer
|
|
|
|
wandb_logger = WandbLogger()
|
|
|
|
trainer = Trainer(logger=wandb_logger)
|
2020-04-16 16:04:12 +00:00
|
|
|
|
2020-12-19 12:52:11 +00:00
|
|
|
Note: When logging manually through `wandb.log` or `trainer.logger.experiment.log`,
|
|
|
|
make sure to use `commit=False` so the logging step does not increase.
|
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
See Also:
|
2021-01-24 22:44:09 +00:00
|
|
|
- `Tutorial <https://colab.research.google.com/drive/16d1uctGaw2y9KhGBlINNTsWpmlXdJwRW?usp=sharing>`__
|
|
|
|
on how to use W&B with PyTorch Lightning
|
|
|
|
- `W&B Documentation <https://docs.wandb.ai/integrations/lightning>`__
|
2020-04-16 16:04:12 +00:00
|
|
|
|
2020-01-14 03:25:27 +00:00
|
|
|
"""
|
|
|
|
|
2020-11-22 05:38:58 +00:00
|
|
|
LOGGER_JOIN_CHAR = '-'
|
|
|
|
|
2020-09-19 16:51:43 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
name: Optional[str] = None,
|
|
|
|
save_dir: Optional[str] = None,
|
2021-01-24 22:44:09 +00:00
|
|
|
offline: Optional[bool] = False,
|
2020-09-19 16:51:43 +00:00
|
|
|
id: Optional[str] = None,
|
2021-01-24 22:44:09 +00:00
|
|
|
anonymous: Optional[bool] = False,
|
2020-09-19 16:51:43 +00:00
|
|
|
version: Optional[str] = None,
|
|
|
|
project: Optional[str] = None,
|
2021-01-24 22:44:09 +00:00
|
|
|
log_model: Optional[bool] = False,
|
2020-09-19 16:51:43 +00:00
|
|
|
experiment=None,
|
2021-01-24 22:44:09 +00:00
|
|
|
prefix: Optional[str] = '',
|
2021-02-27 01:52:23 +00:00
|
|
|
sync_step: Optional[bool] = None,
|
2020-09-19 16:51:43 +00:00
|
|
|
**kwargs
|
|
|
|
):
|
2020-09-25 14:00:02 +00:00
|
|
|
if wandb is None:
|
2021-02-08 19:28:38 +00:00
|
|
|
raise ImportError(
|
|
|
|
'You want to use `wandb` logger which is not installed yet,' # pragma: no-cover
|
|
|
|
' install it with `pip install wandb`.'
|
|
|
|
)
|
2021-02-02 17:06:11 +00:00
|
|
|
|
|
|
|
if offline and log_model:
|
|
|
|
raise MisconfigurationException(
|
|
|
|
f'Providing log_model={log_model} and offline={offline} is an invalid configuration'
|
|
|
|
' since model checkpoints cannot be uploaded in offline mode.\n'
|
|
|
|
'Hint: Set `offline=False` to log your model.'
|
|
|
|
)
|
|
|
|
|
2021-02-27 01:52:23 +00:00
|
|
|
if sync_step is not None:
|
|
|
|
warning_cache.warn(
|
|
|
|
"`WandbLogger(sync_step=(True|False))` is deprecated in v1.2.1 and will be removed in v1.5."
|
|
|
|
" Metrics are now logged separately and automatically synchronized.", DeprecationWarning
|
|
|
|
)
|
|
|
|
|
2020-01-14 03:25:27 +00:00
|
|
|
super().__init__()
|
|
|
|
self._name = name
|
|
|
|
self._save_dir = save_dir
|
2021-01-24 22:44:09 +00:00
|
|
|
self._offline = offline
|
2020-01-14 03:25:27 +00:00
|
|
|
self._id = version or id
|
2021-01-24 22:44:09 +00:00
|
|
|
self._anonymous = 'allow' if anonymous else None
|
2020-01-14 03:25:27 +00:00
|
|
|
self._project = project
|
2020-04-02 12:55:34 +00:00
|
|
|
self._log_model = log_model
|
2020-11-22 05:38:58 +00:00
|
|
|
self._prefix = prefix
|
2021-01-24 22:44:09 +00:00
|
|
|
self._experiment = experiment
|
2020-09-19 16:51:43 +00:00
|
|
|
self._kwargs = kwargs
|
2020-01-14 03:25:27 +00:00
|
|
|
|
|
|
|
def __getstate__(self):
|
|
|
|
state = self.__dict__.copy()
|
2020-04-03 19:03:00 +00:00
|
|
|
# args needed to reload correct experiment
|
|
|
|
state['_id'] = self._experiment.id if self._experiment is not None else None
|
|
|
|
|
2020-01-14 03:25:27 +00:00
|
|
|
# cannot be pickled
|
|
|
|
state['_experiment'] = None
|
|
|
|
return state
|
|
|
|
|
|
|
|
@property
|
2020-06-30 22:09:16 +00:00
|
|
|
@rank_zero_experiment
|
2020-02-25 19:52:39 +00:00
|
|
|
def experiment(self) -> Run:
|
2020-01-17 11:03:31 +00:00
|
|
|
r"""
|
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Actual wandb object. To use wandb features in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule` do the following.
|
2020-01-17 11:03:31 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Example::
|
2020-01-17 11:03:31 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
self.logger.experiment.some_wandb_function()
|
2020-01-17 11:03:31 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
"""
|
2020-01-14 03:25:27 +00:00
|
|
|
if self._experiment is None:
|
|
|
|
if self._offline:
|
2020-03-03 01:49:14 +00:00
|
|
|
os.environ['WANDB_MODE'] = 'dryrun'
|
2020-01-14 03:25:27 +00:00
|
|
|
self._experiment = wandb.init(
|
2021-02-08 19:28:38 +00:00
|
|
|
name=self._name,
|
|
|
|
dir=self._save_dir,
|
|
|
|
project=self._project,
|
|
|
|
anonymous=self._anonymous,
|
|
|
|
id=self._id,
|
|
|
|
resume='allow',
|
|
|
|
**self._kwargs
|
|
|
|
) if wandb.run is None else wandb.run
|
2021-02-02 17:06:11 +00:00
|
|
|
|
2020-04-02 12:55:34 +00:00
|
|
|
# save checkpoints in wandb dir to upload on W&B servers
|
2021-02-02 17:06:11 +00:00
|
|
|
if self._save_dir is None:
|
2020-07-09 11:15:41 +00:00
|
|
|
self._save_dir = self._experiment.dir
|
2021-02-27 01:52:23 +00:00
|
|
|
|
|
|
|
# define default x-axis (for latest wandb versions)
|
|
|
|
if getattr(self._experiment, "define_metric", None):
|
|
|
|
self._experiment.define_metric("trainer/global_step")
|
|
|
|
self._experiment.define_metric("*", step_metric='trainer/global_step', step_sync=True)
|
|
|
|
|
2020-01-14 03:25:27 +00:00
|
|
|
return self._experiment
|
|
|
|
|
2020-03-03 01:49:14 +00:00
|
|
|
def watch(self, model: nn.Module, log: str = 'gradients', log_freq: int = 100):
|
2020-04-03 19:02:38 +00:00
|
|
|
self.experiment.watch(model, log=log, log_freq=log_freq)
|
2020-01-14 03:25:27 +00:00
|
|
|
|
|
|
|
@rank_zero_only
|
2020-03-04 14:33:39 +00:00
|
|
|
def log_hyperparams(self, params: Union[Dict[str, Any], Namespace]) -> None:
|
|
|
|
params = self._convert_params(params)
|
2020-07-08 05:45:25 +00:00
|
|
|
params = self._flatten_dict(params)
|
2020-10-26 11:57:03 +00:00
|
|
|
params = self._sanitize_callable_params(params)
|
2020-04-24 14:29:24 +00:00
|
|
|
self.experiment.config.update(params, allow_val_change=True)
|
2020-01-14 03:25:27 +00:00
|
|
|
|
|
|
|
@rank_zero_only
|
2020-03-04 14:33:39 +00:00
|
|
|
def log_metrics(self, metrics: Dict[str, float], step: Optional[int] = None) -> None:
|
2020-06-30 22:09:16 +00:00
|
|
|
assert rank_zero_only.rank == 0, 'experiment tried to log from global_rank != 0'
|
2020-11-22 05:38:58 +00:00
|
|
|
|
|
|
|
metrics = self._add_prefix(metrics)
|
2021-02-27 01:52:23 +00:00
|
|
|
if step is not None:
|
|
|
|
self.experiment.log({**metrics, 'trainer/global_step': step})
|
2021-01-24 22:44:09 +00:00
|
|
|
else:
|
|
|
|
self.experiment.log(metrics)
|
2020-01-14 03:25:27 +00:00
|
|
|
|
2020-07-09 11:15:41 +00:00
|
|
|
@property
|
|
|
|
def save_dir(self) -> Optional[str]:
|
|
|
|
return self._save_dir
|
|
|
|
|
2020-01-14 03:25:27 +00:00
|
|
|
@property
|
2020-06-29 01:36:46 +00:00
|
|
|
def name(self) -> Optional[str]:
|
2020-04-03 19:03:00 +00:00
|
|
|
# don't create an experiment if we don't have one
|
2020-07-09 11:15:41 +00:00
|
|
|
return self._experiment.project_name() if self._experiment else self._name
|
2020-01-14 03:25:27 +00:00
|
|
|
|
|
|
|
@property
|
2020-06-29 01:36:46 +00:00
|
|
|
def version(self) -> Optional[str]:
|
2020-04-03 19:03:00 +00:00
|
|
|
# don't create an experiment if we don't have one
|
2020-07-09 11:15:41 +00:00
|
|
|
return self._experiment.id if self._experiment else self._id
|
2020-10-26 11:22:09 +00:00
|
|
|
|
2020-12-01 06:05:00 +00:00
|
|
|
@rank_zero_only
|
2020-10-26 11:22:09 +00:00
|
|
|
def finalize(self, status: str) -> None:
|
|
|
|
# upload all checkpoints from saving dir
|
|
|
|
if self._log_model:
|
|
|
|
wandb.save(os.path.join(self.save_dir, "*.ckpt"))
|