Merge pull request #49 from hobogalaxy/version-3.0

Version 3.0
This commit is contained in:
hobogalaxy authored and GitHub committed 2020-12-13 23:10:33 +01:00
commit 56e73a2c6e
3 files changed
+15 -14

No files matched your search

+7 -6
View File
@@ -8,10 +8,10 @@ Click on <b>"Use this template"</b> button above to initialize new repository.<b
- Storing many run configurations in a convenient way ([run_configs.yaml](project/run_configs.yaml)) - Storing many run configurations in a convenient way ([run_configs.yaml](project/run_configs.yaml))
- All advantages of PyTorch Lightning - All advantages of PyTorch Lightning
- Weights&Biases integration: - Weights&Biases integration:
- Automatically stores all relevant code, configs and model checkpoints in Weights&Biases cloud - ~~Automatically stores all relevant code, configs and model checkpoints in Weights&Biases cloud~~ (TODO)
- Hyperparameter search with Weights&Biases sweeps ([execute_sweep.py](project/template_utils/execute_sweep.py)) - Hyperparameter search with Weights&Biases sweeps ([execute_sweep.py](project/template_utils/execute_sweep.py))
- Automates the whole training process and initialization, you only need to create `model` and `datamodule` and specify them in [run_configs.yaml](project/run_configs.yaml) - Automates the whole training process, you only need to create model and datamodule and specify them in [run_configs.yaml](project/run_configs.yaml)
- Scheduling execution of many experiments ([execute_all_runs.py](project/template_utils/execute_all_runs.py)) - Scheduling execution of many runs/experiments ([execute_all_runs.py](project/template_utils/execute_all_runs.py))
- Built in requirements ([requirements.txt](requirements.txt)) - Built in requirements ([requirements.txt](requirements.txt))
- Built in conda environment initialization ([conda_env.yaml](conda_env.yaml)) - Built in conda environment initialization ([conda_env.yaml](conda_env.yaml))
- Built in package setup ([setup.py](setup.py)) - Built in package setup ([setup.py](setup.py))
@@ -31,10 +31,11 @@ The directory structure of new project looks like this:
│ ├── notebooks <- Jupyter notebooks │ ├── notebooks <- Jupyter notebooks
│ │ │ │
│ ├── template_utils <- Different utilities │ ├── template_utils <- Different utilities
│ │ ├── callbacks.py <- Useful training callbacks │ │ ├── callbacks.py <- Custom callbacks
│ │ ├── wandb_callbacks.py <- Custom Weights&Biases related callbacks
│ │ ├── execute_sweep.py <- Special file for executing Weights&Biases sweeps │ │ ├── execute_sweep.py <- Special file for executing Weights&Biases sweeps
│ │ ├── execute_all_runs.py <- Special file for executing all specified runs one after the other │ │ ├── execute_all_runs.py <- Special file for executing all specified runs one after the other
│ │ ├── initializers.py <- Useful initializers │ │ ├── initializers.py <- Initializers for different modules
│ │ └── predict_example.py <- Example of inference with trained model │ │ └── predict_example.py <- Example of inference with trained model
│ │ │ │
│ ├── datamodules <- All your datamodules should be located here! │ ├── datamodules <- All your datamodules should be located here!
@@ -134,7 +135,7 @@ To start training with this configuration run:<br>
`python train.py --run_config_name SIMPLE_CONFIG_EXAMPLE_MNIST` `python train.py --run_config_name SIMPLE_CONFIG_EXAMPLE_MNIST`
Each run configuration needs to contain sections `trainer`, `model` and `datamodule`.<br> Each run configuration needs to contain sections `trainer`, `model` and `datamodule`.<br>
EVERY OTHER SECTION IS OPTIONAL! (see [run_configs.yaml](project/run_configs.yaml) for more advanced config example with optional sections)<br> Every other section is optional! (see [run_configs.yaml](project/run_configs.yaml) for more advanced config example with optional sections)<br>
Every parameter specified in model hparams section will be passed to your model class and can be retrieved through `hparams` dictionary (see example with [simple_mnist_classifier](project/models/simple_mnist_classifier/lightning_module.py)).<br> Every parameter specified in model hparams section will be passed to your model class and can be retrieved through `hparams` dictionary (see example with [simple_mnist_classifier](project/models/simple_mnist_classifier/lightning_module.py)).<br>
@@ -12,7 +12,7 @@ class LitModel(pl.LightningModule):
This is example of lightning model for MNIST digits classification. This is example of lightning model for MNIST digits classification.
The path to model should be specified in your run config. (run_configs.yaml) The path to model should be specified in your run config. (run_configs.yaml)
The 'hparams' dict contains your hparams specified in your run config. (run_configs.yaml) The 'hparams' dict contains your hparams specified in run config. (run_configs.yaml)
This class enables you to specify what happens during training, validation and test step. This class enables you to specify what happens during training, validation and test step.
You can just remove 'validation_step()' or 'test_step()' methods if you don't want to have them during training. You can just remove 'validation_step()' or 'test_step()' methods if you don't want to have them during training.
+7 -7
View File
@@ -46,19 +46,19 @@ def init_model(model_config: dict) -> pl.LightningModule:
model_path = model_config["load_from"]["model_path"] model_path = model_config["load_from"]["model_path"]
model_class = model_config["load_from"]["model_class"] model_class = model_config["load_from"]["model_class"]
assert os.path.isfile(model_path), f"incorrect model path: {model_path}" assert os.path.isfile(model_path), f"incorrect model path '{model_path}'"
spec = importlib.util.spec_from_file_location("lightning_model", model_path) spec = importlib.util.spec_from_file_location("lightning_model", model_path)
lightning_module = importlib.util.module_from_spec(spec) lightning_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(lightning_module) spec.loader.exec_module(lightning_module)
assert hasattr(lightning_module, model_class), \ assert hasattr(lightning_module, model_class), \
f"model class {model_class} doesn't exists in file {model_path}" f"model class '{model_class}' doesn't exist in file '{model_path}'"
LitModel = getattr(lightning_module, model_class) LitModel = getattr(lightning_module, model_class)
assert issubclass(LitModel, pl.LightningModule), \ assert issubclass(LitModel, pl.LightningModule), \
f"specified model class {model_class} is not a LightningModule" f"specified model class '{model_class}' is not a 'LightningModule' type"
model = LitModel(hparams=model_config["hparams"]) model = LitModel(hparams=model_config["hparams"])
@@ -73,19 +73,19 @@ def init_datamodule(datamodule_config: dict, data_dir: str) -> pl.LightningDataM
datamodule_path = datamodule_config["load_from"]["datamodule_path"] datamodule_path = datamodule_config["load_from"]["datamodule_path"]
datamodule_class = datamodule_config["load_from"]["datamodule_class"] datamodule_class = datamodule_config["load_from"]["datamodule_class"]
assert os.path.isfile(datamodule_path), f"incorrect model path: {datamodule_path}" assert os.path.isfile(datamodule_path), f"incorrect datamodule path '{datamodule_path}'"
spec = importlib.util.spec_from_file_location("lightning_model", datamodule_path) spec = importlib.util.spec_from_file_location("lightning_datamodule", datamodule_path)
lightning_module = importlib.util.module_from_spec(spec) lightning_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(lightning_module) spec.loader.exec_module(lightning_module)
assert hasattr(lightning_module, datamodule_class), \ assert hasattr(lightning_module, datamodule_class), \
f"datamodule class {datamodule_class} doesn't exists in file {datamodule_path}" f"datamodule class '{datamodule_class}' doesn't exist in file '{datamodule_path}'"
DataModule = getattr(lightning_module, datamodule_class) DataModule = getattr(lightning_module, datamodule_class)
assert issubclass(DataModule, pl.LightningDataModule), \ assert issubclass(DataModule, pl.LightningDataModule), \
f"specified datamodule class {datamodule_class} is not a LightningDataModule" f"specified datamodule class '{datamodule_class}' is not a 'LightningDataModule' type"
datamodule = DataModule(data_dir=data_dir, hparams=datamodule_config["hparams"]) datamodule = DataModule(data_dir=data_dir, hparams=datamodule_config["hparams"])
datamodule.prepare_data() datamodule.prepare_data()