improve experiment configs
This commit is contained in:
1 parent
fe81cbb304
commit
9cffc61c20
25 files changed
+204
-124
No files matched your search
Whitespace-only changes.
@@ -1,12 +0,0 @@
|
||||
# @package _group_
|
||||
|
||||
class: "pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule"
|
||||
|
||||
hparams:
|
||||
lr: 0.001
|
||||
weight_decay: 0.00001
|
||||
input_size: 784
|
||||
output_size: 10
|
||||
lin1_size: 256
|
||||
lin2_size: 256
|
||||
lin3_size: 128
|
||||
@@ -0,0 +1,7 @@
|
||||
# @package _group_
|
||||
|
||||
class: "pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule"
|
||||
|
||||
hparams:
|
||||
batch_size: 64
|
||||
train_val_test_split: (55_000, 5_000, 10_000)
|
||||
@@ -0,0 +1,33 @@
|
||||
# @package _global_
|
||||
|
||||
# to execute this experiment run:
|
||||
# python train.py +experiment=xxx
|
||||
|
||||
defaults:
|
||||
- override /trainer: default_trainer.yaml
|
||||
- override /model: null
|
||||
- override /datamodule: null
|
||||
- override /callbacks: default_callbacks.yaml
|
||||
|
||||
pytorch_seed: 12345
|
||||
|
||||
trainer:
|
||||
args:
|
||||
max_epochs: 10
|
||||
|
||||
model:
|
||||
class: pytorch_modules.lightning_models.simple_mnist_classifier.LitModel
|
||||
args:
|
||||
lr: 0.001
|
||||
weight_decay: 0.00001
|
||||
input_size: 784
|
||||
output_size: 10
|
||||
lin1_size: 256
|
||||
lin2_size: 256
|
||||
lin3_size: 128
|
||||
|
||||
datamodule:
|
||||
class: pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule
|
||||
args:
|
||||
batch_size: 32
|
||||
train_val_test_split: (55_000, 5_000, 10_000)
|
||||
@@ -1,12 +1,11 @@
|
||||
# @package _global_
|
||||
|
||||
# to execute this experiment run:
|
||||
# python train.py +experiment=xxx
|
||||
|
||||
defaults:
|
||||
- override /trainer: default_trainer.yaml
|
||||
- override /model: default_classifier.yaml
|
||||
- override /datamodule: default_datamodule.yaml
|
||||
- override /logger: comet.yaml
|
||||
- override /logger: wandb.yaml
|
||||
|
||||
pytorch_seed: 12345
|
||||
|
||||
@@ -15,7 +14,7 @@ trainer:
|
||||
max_epochs: 10
|
||||
|
||||
model:
|
||||
class: "pytorch_modules.lightning_models.simple_mnist_classifier.LitModel"
|
||||
class: pytorch_modules.lightning_models.simple_mnist_classifier.LitModel
|
||||
hparams:
|
||||
lr: 0.001
|
||||
weight_decay: 0.00001
|
||||
@@ -26,7 +25,7 @@ model:
|
||||
lin3_size: 128
|
||||
|
||||
datamodule:
|
||||
class: "pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule"
|
||||
class: pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule
|
||||
hparams:
|
||||
batch_size: 32
|
||||
train_val_test_split: [55_000, 5_000, 10_000]
|
||||
train_val_test_split: (55_000, 5_000, 10_000)
|
||||
@@ -0,0 +1,31 @@
|
||||
# @package _global_
|
||||
|
||||
# to execute this experiment run:
|
||||
# python train.py +experiment=xxx
|
||||
|
||||
defaults:
|
||||
- override /trainer: default_trainer.yaml
|
||||
- override /logger: wandb.yaml
|
||||
|
||||
pytorch_seed: 12345
|
||||
|
||||
trainer:
|
||||
args:
|
||||
max_epochs: 10
|
||||
|
||||
model:
|
||||
class: pytorch_modules.lightning_models.simple_mnist_classifier.LitModel
|
||||
hparams:
|
||||
lr: 0.001
|
||||
weight_decay: 0.00001
|
||||
input_size: 784
|
||||
output_size: 10
|
||||
lin1_size: 256
|
||||
lin2_size: 256
|
||||
lin3_size: 128
|
||||
|
||||
datamodule:
|
||||
class: pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule
|
||||
hparams:
|
||||
batch_size: 32
|
||||
train_val_test_split: (55_000, 5_000, 10_000)
|
||||
@@ -1,13 +1,13 @@
|
||||
# @package _global_
|
||||
|
||||
# to execute this experiment run:
|
||||
# python train.py +experiment=xxx2
|
||||
|
||||
defaults:
|
||||
- override /trainer: default_trainer.yaml # choose trainer from 'configs/trainer/' folder
|
||||
- override /model: default_model.yaml # choose model from 'configs/model/' folder
|
||||
- override /datamodule: default_datamodule.yaml # choose datamodule from 'configs/datamodule/' folder
|
||||
- override /model: null # choose model from 'configs/model/' folder
|
||||
- override /datamodule: null # choose datamodule from 'configs/datamodule/' folder
|
||||
- override /callbacks: default_callbacks.yaml # choose callback set from 'configs/callbacks/' folder
|
||||
- override /logger: comet.yaml # choose logger from 'configs/logger/' folder
|
||||
|
||||
pytorch_seed: 12345 # pytorch seed for this experiment (also affects lightning random_split() method)
|
||||
|
||||
@@ -24,8 +24,8 @@ trainer:
|
||||
val_check_interval: 0.5 # perform validation twice per epoch
|
||||
|
||||
model:
|
||||
class: "pytorch_modules.lightning_models.simple_mnist_classifier.LitModel"
|
||||
hparams: # you can add here any params you want and then access them in lightning model
|
||||
class: pytorch_modules.lightning_models.simple_mnist_classifier.LitModel
|
||||
args: # you can add here any params you want and then access them in lightning model
|
||||
lr: 0.001
|
||||
weight_decay: 0.00001
|
||||
input_size: 784 # img size is 1*28*28
|
||||
@@ -35,18 +35,21 @@ model:
|
||||
lin3_size: 128
|
||||
|
||||
datamodule:
|
||||
class: "pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule"
|
||||
hparams: # you can add here any params you want and then access them in lightning datamodule
|
||||
class: pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule
|
||||
args: # you can add here any params you want and then access them in lightning datamodule
|
||||
batch_size: 64
|
||||
train_val_test_split: [55_000, 5_000, 10_000]
|
||||
train_val_test_split: (55_000, 5_000, 10_000)
|
||||
num_workers: 1 # num of processes used for loading data in parallel
|
||||
pin_memory: False # dataloaders will copy tensors into CUDA pinned memory before returning them
|
||||
|
||||
logger:
|
||||
args: # you can add here additional logger arguments specific for this experiment
|
||||
tags: ["uwu", "best_model"]
|
||||
loggers:
|
||||
wandb:
|
||||
args: # you can add here additional loggers arguments specific for this experiment
|
||||
tags: ["uwu", "best_model"]
|
||||
comet:
|
||||
args:
|
||||
tags: ["uwu", "best_model"]
|
||||
|
||||
resume_training: # use this if you want to resume training from checkpoint
|
||||
checkpoint_path: False # path to your checkpoint
|
||||
wandb_run_id: False # you can add id of wandb run you want to resume but it's optional
|
||||
comet_run_id: False # you can add id of comet run you want to resume but it's optional
|
||||
logger_run_id: False # loggers experiment id that you want to resume (optional)
|
||||
@@ -1,10 +0,0 @@
|
||||
# @package _group_
|
||||
# Comet logger config
|
||||
|
||||
args:
|
||||
api_key: "sadfhgadfhsdfhadgkajdgsdg"
|
||||
project_name: "project_template_test"
|
||||
|
||||
extra_options:
|
||||
log_optimizer_name: True
|
||||
log_train_val_test_sizes: True
|
||||
@@ -1,6 +0,0 @@
|
||||
# @package _group_
|
||||
# Tensorboard logger config
|
||||
|
||||
args: {}
|
||||
|
||||
extra_options: {}
|
||||
@@ -1,13 +0,0 @@
|
||||
# @package _group_
|
||||
# Weights&Biases logger config
|
||||
|
||||
args:
|
||||
project: "project_template_test"
|
||||
entity: "" # change to your username or name of your team on wandb
|
||||
log_model: True # set True to automatically upload model checkpoint to wandb cloud after training
|
||||
offline: False # set True to store all logs only locally
|
||||
|
||||
extra_options:
|
||||
log_gradients: False # set True to log gradient histograms (avoid this for very big lightning_models)
|
||||
log_optimizer_name: True
|
||||
log_train_val_test_sizes: True
|
||||
@@ -0,0 +1,9 @@
|
||||
# @package _group_
|
||||
|
||||
# train with all loggers at once
|
||||
defaults:
|
||||
- comet
|
||||
- csv_logger
|
||||
- neptune
|
||||
- tensorboard
|
||||
- wandb
|
||||
@@ -0,0 +1,13 @@
|
||||
# @package _group_
|
||||
|
||||
# Comet loggers config
|
||||
comet:
|
||||
class: pytorch_lightning.loggers.CometLogger
|
||||
|
||||
args:
|
||||
api_key: ???
|
||||
project_name: "project_template_test"
|
||||
|
||||
extra_options:
|
||||
log_optimizer_name: True
|
||||
log_train_val_test_sizes: True
|
||||
@@ -0,0 +1,9 @@
|
||||
# @package _group_
|
||||
|
||||
# default loggers is just lightning CSVLogger which doesn't require any additional dependencies
|
||||
csv_logger:
|
||||
class: pytorch_lightning.loggers.CSVLogger
|
||||
|
||||
args: {}
|
||||
|
||||
extra_options: {}
|
||||
@@ -0,0 +1,11 @@
|
||||
# @package _group_
|
||||
|
||||
# Neptune loggers config
|
||||
neptune:
|
||||
class: pytorch_lightning.loggers.NeptuneLogger
|
||||
|
||||
args: {}
|
||||
|
||||
extra_options:
|
||||
log_optimizer_name: True
|
||||
log_train_val_test_sizes: True
|
||||
@@ -0,0 +1,9 @@
|
||||
# @package _group_
|
||||
|
||||
# Tensorboard loggers config
|
||||
tensorboard:
|
||||
class: pytorch_lightning.loggers.TensorboardLogger
|
||||
|
||||
args: {}
|
||||
|
||||
extra_options: {}
|
||||
@@ -0,0 +1,16 @@
|
||||
# @package _group_
|
||||
|
||||
# Weights&Biases loggers config
|
||||
wandb:
|
||||
class: pytorch_lightning.loggers.WandbLogger
|
||||
|
||||
args:
|
||||
project: "project_template_test"
|
||||
entity: "" # change to your username or name of your team on wandb
|
||||
log_model: True # set True to automatically upload model checkpoint to wandb cloud after training
|
||||
offline: False # set True to store all logs only locally
|
||||
|
||||
extra_options:
|
||||
log_gradients: False # set True to log gradient histograms (avoid this for very big models)
|
||||
log_optimizer_name: True
|
||||
log_train_val_test_sizes: True
|
||||
@@ -0,0 +1,6 @@
|
||||
# @package _group_
|
||||
|
||||
class: "pytorch_modules.lightning_models.simple_mnist_classifier.LitModel"
|
||||
|
||||
hparams:
|
||||
YYYYYYY: XXXXXXXXXXXXXXXXXXX
|
||||
+1
@@ -10,3 +10,4 @@ hparams:
|
||||
lin1_size: 256
|
||||
lin2_size: 256
|
||||
lin3_size: 128
|
||||
|
||||
Whitespace-only changes.
@@ -2,10 +2,10 @@
|
||||
|
||||
defaults:
|
||||
- trainer: default_trainer.yaml
|
||||
- model: default_model.yaml
|
||||
- datamodule: default_datamodule.yaml
|
||||
- model: simple_mnist_classifier.yaml
|
||||
- datamodule: mnist_datamodule.yaml
|
||||
- callbacks: default_callbacks.yaml
|
||||
- logger: comet.yaml
|
||||
- loggers: null
|
||||
|
||||
|
||||
paths:
|
||||
|
||||
@@ -21,11 +21,9 @@ class LitModel(pl.LightningModule):
|
||||
https://pytorch-lightning.readthedocs.io/en/latest/lightning_module.html
|
||||
"""
|
||||
|
||||
def __init__(self, hparams: dict = None):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
if hparams:
|
||||
self.save_hyperparameters(hparams)
|
||||
self.save_hyperparameters(kwargs)
|
||||
|
||||
self.model = SimpleMNISTClassifier(hparams=self.hparams)
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
# pytorch lightning imports
|
||||
from pytorch_lightning.loggers import WandbLogger, CometLogger
|
||||
from pytorch_lightning.profiler import SimpleProfiler
|
||||
import pytorch_lightning as pl
|
||||
|
||||
# normal imports
|
||||
@@ -11,82 +9,59 @@ import os
|
||||
# template utils imports
|
||||
from pytorch_lightning import callbacks as lightning_callbacks
|
||||
from pytorch_modules.lightning_callbacks import wandb_callbacks, custom_callbacks as custom_callbacks
|
||||
from pytorch_lightning.loggers import CSVLogger
|
||||
|
||||
|
||||
def normalize_config_paths(project_config: dict, run_config: dict, base_dir: str) -> Tuple[dict, dict]:
|
||||
"""
|
||||
Convert all config paths to absolute paths relatively to base_dir and normalize them.
|
||||
"""
|
||||
def format_path(path: str, base_dir: str):
|
||||
"""Convert path to absolute relatively to base_dir and normalize it."""
|
||||
if not os.path.isabs(path):
|
||||
path = os.path.join(base_dir, path)
|
||||
return os.path.normpath(path)
|
||||
|
||||
if not os.path.isabs(project_config["data_dir"]):
|
||||
project_config["data_dir"] = \
|
||||
os.path.normpath(os.path.join(base_dir, project_config["data_dir"]))
|
||||
|
||||
if not os.path.isabs(project_config["logs_dir"]):
|
||||
project_config["logs_dir"] = \
|
||||
os.path.normpath(os.path.join(base_dir, project_config["logs_dir"]))
|
||||
def format_config_paths(config: dict, base_dir: str) -> dict:
|
||||
config["paths"]["data_dir"] = format_path(config["paths"]["data_dir"], base_dir)
|
||||
config["paths"]["logs_dir"] = format_path(config["paths"]["logs_dir"], base_dir)
|
||||
return config
|
||||
|
||||
if not os.path.isabs(run_config["model"]["load_from"]["model_path"]):
|
||||
run_config["model"]["load_from"]["model_path"] = \
|
||||
os.path.normpath(os.path.join(base_dir, run_config["model"]["load_from"]["model_path"]))
|
||||
|
||||
if not os.path.isabs(run_config["datamodule"]["load_from"]["datamodule_path"]):
|
||||
run_config["datamodule"]["load_from"]["datamodule_path"] = \
|
||||
os.path.normpath(os.path.join(base_dir, run_config["datamodule"]["load_from"]["datamodule_path"]))
|
||||
def load_object(obj_path):
|
||||
obj_path, obj_name = obj_path.rsplit('.', 1)
|
||||
module = importlib.import_module(obj_path)
|
||||
|
||||
return project_config, run_config
|
||||
assert hasattr(module, obj_name), \
|
||||
f'Object `{obj_name}` cannot be loaded from `{obj_path}`.'
|
||||
|
||||
return getattr(module, obj_name)
|
||||
|
||||
|
||||
def init_model(model_config: dict) -> pl.LightningModule:
|
||||
"""
|
||||
Load LightningModule from path specified in run config.
|
||||
"""
|
||||
model_class = model_config["class"]
|
||||
model_hparams = model_config["hparams"]
|
||||
|
||||
model_path = model_config["load_from"]["model_path"]
|
||||
model_class = model_config["load_from"]["model_class"]
|
||||
|
||||
assert os.path.isfile(model_path), f"incorrect model path '{model_path}'"
|
||||
|
||||
spec = importlib.util.spec_from_file_location("lightning_model", model_path)
|
||||
lightning_module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(lightning_module)
|
||||
|
||||
assert hasattr(lightning_module, model_class), \
|
||||
f"model class '{model_class}' doesn't exist in file '{model_path}'"
|
||||
|
||||
LitModel = getattr(lightning_module, model_class)
|
||||
|
||||
LitModel = load_object(model_class)
|
||||
assert issubclass(LitModel, pl.LightningModule), \
|
||||
f"specified model class '{model_class}' is not a 'LightningModule' type"
|
||||
f"Specified model class `{model_class}` is not a subclass of `LightningModule`."
|
||||
|
||||
model = LitModel(hparams=model_config["hparams"])
|
||||
|
||||
return model
|
||||
return LitModel(hparams=model_hparams)
|
||||
|
||||
|
||||
def init_datamodule(datamodule_config: dict, data_dir: str) -> pl.LightningDataModule:
|
||||
"""
|
||||
Load LightningDataModule from path specified in run config.
|
||||
"""
|
||||
datamodule_class = datamodule_config["class"]
|
||||
datamodule_hparams = datamodule_config["hparams"]
|
||||
|
||||
datamodule_path = datamodule_config["load_from"]["datamodule_path"]
|
||||
datamodule_class = datamodule_config["load_from"]["datamodule_class"]
|
||||
|
||||
assert os.path.isfile(datamodule_path), f"incorrect datamodule path '{datamodule_path}'"
|
||||
|
||||
spec = importlib.util.spec_from_file_location("lightning_datamodule", datamodule_path)
|
||||
lightning_module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(lightning_module)
|
||||
|
||||
assert hasattr(lightning_module, datamodule_class), \
|
||||
f"datamodule class '{datamodule_class}' doesn't exist in file '{datamodule_path}'"
|
||||
|
||||
DataModule = getattr(lightning_module, datamodule_class)
|
||||
DataModule = load_object(datamodule_class)
|
||||
|
||||
assert issubclass(DataModule, pl.LightningDataModule), \
|
||||
f"specified datamodule class '{datamodule_class}' is not a 'LightningDataModule' type"
|
||||
f"Specified datamodule class `{datamodule_class}` is not a subclass of `LightningDataModule`"
|
||||
|
||||
datamodule = DataModule(data_dir=data_dir, hparams=datamodule_config["hparams"])
|
||||
datamodule = DataModule(data_dir=data_dir, hparams=datamodule_hparams)
|
||||
datamodule.prepare_data()
|
||||
datamodule.setup()
|
||||
|
||||
@@ -129,7 +104,7 @@ def init_trainer(project_config: dict,
|
||||
# number of validation sanity checks
|
||||
num_sanity_val_steps=3,
|
||||
|
||||
# default log dir if no logger is found
|
||||
# default log dir if no loggers is found
|
||||
default_root_dir=os.path.join(project_config["logs_dir"], "lightning_logs"),
|
||||
|
||||
# insert all other trainer args specified in run config
|
||||
@@ -215,7 +190,7 @@ def init_wandb_logger(project_config: dict,
|
||||
model: pl.LightningModule,
|
||||
datamodule: pl.LightningDataModule) -> pl.loggers.WandbLogger:
|
||||
"""
|
||||
Initialize Weights&Biases logger.
|
||||
Initialize Weights&Biases loggers.
|
||||
"""
|
||||
|
||||
if "loggers" not in project_config or "wandb" not in project_config["loggers"]:
|
||||
@@ -284,7 +259,7 @@ def init_wandb_logger(project_config: dict,
|
||||
|
||||
|
||||
def init_tensorboard_logger() -> pl.loggers.TensorBoardLogger:
|
||||
"""Initialize tensorboard logger"""
|
||||
"""Initialize tensorboard loggers"""
|
||||
# TODO
|
||||
return None
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from omegaconf import DictConfig, OmegaConf
|
||||
import hydra.conf.hydra.output
|
||||
from hydra.experimental import initialize, compose
|
||||
import comet_ml
|
||||
|
||||
|
||||
@hydra.main(config_path="configs/", config_name="project_config.yaml")
|
||||
|
||||
@@ -6,7 +6,6 @@ import torch
|
||||
# normal imports
|
||||
from argparse import ArgumentParser
|
||||
from typing import List
|
||||
import pprint
|
||||
import yaml
|
||||
import os
|
||||
|
||||
|
||||
Reference in new issue
Block a user