Release/1.2 (#198)
* update template to pytorch 1.10+ and lightning 1.5+ * add experiment mode to all experiment configs and implement special logging paths for experiment mode * add `MaxMetric` to model, for computation of best so far validation accuracy * add RichProgressBar to default callbacks * get rid of trick for preventing auto hparam logging, since lightning now supports it with `self.save_hyperparameters(logger=False)` * add `self.save_hyperparameters()` to datamodule since lightinng now supports it * deprecate Apex support * deprecate bash script for conda setup * change `terminate_on_nan` debug option to `detect_anomaly` for compatibility with lightning v1.5 * specify model and datamodule during `trainer.test()`, for compatibility with lightning v1.5 * remove `configs/trainer/all_params.yaml` * make hyperparameter optimization compatible with lightning v1.5 * general documentation improvements
This commit is contained in:
1 parent
6159c413f2
commit
9468ef91c5
29 files changed
+278
-330
No files matched your search
+16
-16
@@ -10,13 +10,21 @@ from pytorch_lightning.utilities import rank_zero_only
|
||||
|
||||
|
||||
def get_logger(name=__name__) -> logging.Logger:
|
||||
"""Initializes multi-GPU-friendly python logger."""
|
||||
"""Initializes multi-GPU-friendly python command line logger."""
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
|
||||
# this ensures all logging levels get marked with the rank zero decorator
|
||||
# otherwise logs would get multiplied for each GPU process in multi-GPU setup
|
||||
for level in ("debug", "info", "warning", "error", "exception", "fatal", "critical"):
|
||||
for level in (
|
||||
"debug",
|
||||
"info",
|
||||
"warning",
|
||||
"error",
|
||||
"exception",
|
||||
"fatal",
|
||||
"critical",
|
||||
):
|
||||
setattr(logger, level, rank_zero_only(getattr(logger, level)))
|
||||
|
||||
return logger
|
||||
@@ -101,14 +109,10 @@ def print_config(
|
||||
|
||||
rich.print(tree)
|
||||
|
||||
with open("config_tree.txt", "w") as fp:
|
||||
with open("config_tree.log", "w") as fp:
|
||||
rich.print(tree, file=fp)
|
||||
|
||||
|
||||
def empty(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
@rank_zero_only
|
||||
def log_hyperparameters(
|
||||
config: DictConfig,
|
||||
@@ -121,7 +125,7 @@ def log_hyperparameters(
|
||||
"""This method controls which parameters from Hydra config are saved by Lightning loggers.
|
||||
|
||||
Additionaly saves:
|
||||
- number of trainable model parameters
|
||||
- number of model parameters
|
||||
"""
|
||||
|
||||
hparams = {}
|
||||
@@ -130,28 +134,24 @@ def log_hyperparameters(
|
||||
hparams["trainer"] = config["trainer"]
|
||||
hparams["model"] = config["model"]
|
||||
hparams["datamodule"] = config["datamodule"]
|
||||
|
||||
if "seed" in config:
|
||||
hparams["seed"] = config["seed"]
|
||||
if "callbacks" in config:
|
||||
hparams["callbacks"] = config["callbacks"]
|
||||
|
||||
# save number of model parameters
|
||||
hparams["model/params_total"] = sum(p.numel() for p in model.parameters())
|
||||
hparams["model/params_trainable"] = sum(
|
||||
hparams["model/params/total"] = sum(p.numel() for p in model.parameters())
|
||||
hparams["model/params/trainable"] = sum(
|
||||
p.numel() for p in model.parameters() if p.requires_grad
|
||||
)
|
||||
hparams["model/params_not_trainable"] = sum(
|
||||
hparams["model/params/non_trainable"] = sum(
|
||||
p.numel() for p in model.parameters() if not p.requires_grad
|
||||
)
|
||||
|
||||
# send hparams to all loggers
|
||||
trainer.logger.log_hyperparams(hparams)
|
||||
|
||||
# disable logging any more hyperparameters for all loggers
|
||||
# this is just a trick to prevent trainer from logging hparams of model,
|
||||
# since we already did that above
|
||||
trainer.logger.log_hyperparams = empty
|
||||
|
||||
|
||||
def finish(
|
||||
config: DictConfig,
|
||||
|
||||
Reference in new issue
Block a user