Release/0.9 (#141)
* add flake8 and prettier to pre-commit-config * add setup.cfg * add workers=True to seed_everything() * update lightning badge logo * bump package versions * update README.md * add __init__.py files * add more logger configs parameters * add default Dockerfile * change .env.template to .env.example * move inference example to readme * remove img_dataset.py * simplify names of wandb callbacks * remove wandb test marker * format files with prettier
This commit is contained in:
1 parent
023d4bdecc
commit
70ab061f75
49 files changed
+473
-415
No files matched your search
+26
-26
@@ -3,17 +3,16 @@ import warnings
|
||||
from typing import List, Sequence
|
||||
|
||||
import pytorch_lightning as pl
|
||||
import rich
|
||||
import rich.syntax
|
||||
import rich.tree
|
||||
import wandb
|
||||
from omegaconf import DictConfig, OmegaConf
|
||||
from pytorch_lightning.loggers.wandb import WandbLogger
|
||||
from pytorch_lightning.utilities import rank_zero_only
|
||||
from rich.syntax import Syntax
|
||||
from rich.tree import Tree
|
||||
|
||||
|
||||
def get_logger(name=__name__, level=logging.INFO):
|
||||
"""Initializes python logger."""
|
||||
def get_logger(name=__name__, level=logging.INFO) -> logging.Logger:
|
||||
"""Initializes multi-GPU-friendly python logger."""
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(level)
|
||||
@@ -26,25 +25,27 @@ def get_logger(name=__name__, level=logging.INFO):
|
||||
return logger
|
||||
|
||||
|
||||
log = get_logger()
|
||||
|
||||
|
||||
def extras(config: DictConfig) -> None:
|
||||
"""A couple of optional utilities, controlled by main config file.
|
||||
- disabling warnings
|
||||
- easier access to debug mode
|
||||
- forcing debug friendly configuration
|
||||
- forcing multi-gpu friendly configuration
|
||||
"""A couple of optional utilities, controlled by main config file:
|
||||
- disabling warnings
|
||||
- easier access to debug mode
|
||||
- forcing debug friendly configuration
|
||||
- forcing multi-gpu friendly configuration
|
||||
|
||||
Modifies DictConfig in place.
|
||||
|
||||
Args:
|
||||
config (DictConfig): [description]
|
||||
config (DictConfig): Configuration composed by Hydra.
|
||||
"""
|
||||
|
||||
log = get_logger()
|
||||
|
||||
# enable adding new keys to config
|
||||
OmegaConf.set_struct(config, False)
|
||||
|
||||
# disable python warnings if <config.ignore_warnings=True>
|
||||
if config.get("ignore_warnings"):
|
||||
log.info(f"Disabling python warnings! <config.ignore_warnings=True>")
|
||||
log.info("Disabling python warnings! <config.ignore_warnings=True>")
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
# set <config.trainer.fast_dev_run=True> if <config.debug=True>
|
||||
@@ -64,9 +65,9 @@ def extras(config: DictConfig) -> None:
|
||||
config.datamodule.num_workers = 0
|
||||
|
||||
# force multi-gpu friendly configuration if <config.trainer.accelerator=ddp>
|
||||
if config.trainer.get("accelerator") in ["ddp", "ddp_spawn", "dp", "ddp2"]:
|
||||
log.info("Forcing ddp friendly configuration! <config.trainer.accelerator=ddp>")
|
||||
# ddp doesn't like num_workers>0 or pin_memory=True
|
||||
accelerator = config.trainer.get("accelerator")
|
||||
if accelerator in ["ddp", "ddp_spawn", "dp", "ddp2"]:
|
||||
log.info(f"Forcing ddp friendly configuration! <config.trainer.accelerator={accelerator}>")
|
||||
if config.datamodule.get("num_workers"):
|
||||
config.datamodule.num_workers = 0
|
||||
if config.datamodule.get("pin_memory"):
|
||||
@@ -92,14 +93,14 @@ def print_config(
|
||||
"""Prints content of DictConfig using Rich library and its tree structure.
|
||||
|
||||
Args:
|
||||
config (DictConfig): Config.
|
||||
fields (Sequence[str], optional): Determines which main fields from config will be printed
|
||||
and in what order.
|
||||
config (DictConfig): Configuration composed by Hydra.
|
||||
fields (Sequence[str], optional): Determines which main fields from config will
|
||||
be printed and in what order.
|
||||
resolve (bool, optional): Whether to resolve reference fields of DictConfig.
|
||||
"""
|
||||
|
||||
style = "dim"
|
||||
tree = Tree(f":gear: CONFIG", style=style, guide_style=style)
|
||||
tree = rich.tree.Tree(":gear: CONFIG", style=style, guide_style=style)
|
||||
|
||||
for field in fields:
|
||||
branch = tree.add(field, style=style, guide_style=style)
|
||||
@@ -109,7 +110,7 @@ def print_config(
|
||||
if isinstance(config_section, DictConfig):
|
||||
branch_content = OmegaConf.to_yaml(config_section, resolve=resolve)
|
||||
|
||||
branch.add(Syntax(branch_content, "yaml"))
|
||||
branch.add(rich.syntax.Syntax(branch_content, "yaml"))
|
||||
|
||||
rich.print(tree)
|
||||
|
||||
@@ -139,8 +140,6 @@ def log_hyperparameters(
|
||||
hparams["trainer"] = config["trainer"]
|
||||
hparams["model"] = config["model"]
|
||||
hparams["datamodule"] = config["datamodule"]
|
||||
if "optimizer" in config:
|
||||
hparams["optimizer"] = config["optimizer"]
|
||||
if "callbacks" in config:
|
||||
hparams["callbacks"] = config["callbacks"]
|
||||
|
||||
@@ -157,7 +156,8 @@ def log_hyperparameters(
|
||||
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)
|
||||
# this is just a trick to prevent trainer from logging hparams of model,
|
||||
# since we already did that above
|
||||
trainer.logger.log_hyperparams = empty
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user