Dev (#123)
* fix quickstart command in readme * fix documentation links in model and datamodule * add `terminate_on_nan` trainer arg to readme * improve docstrings and type hinting
This commit is contained in:
1 parent
6a15f8ef3b
commit
e2c8ed4bf8
3 files changed
+21
-12
No files matched your search
@@ -113,7 +113,7 @@ The directory structure of new project looks like this:
|
|||||||
## 🚀 Quickstart
|
## 🚀 Quickstart
|
||||||
```yaml
|
```yaml
|
||||||
# clone project
|
# clone project
|
||||||
git clone https://github.com/hobogalaxy/lightning-hydra-template
|
git clone https://github.com/ashleve/lightning-hydra-template
|
||||||
cd lightning-hydra-template
|
cd lightning-hydra-template
|
||||||
|
|
||||||
# [OPTIONAL] create conda environment
|
# [OPTIONAL] create conda environment
|
||||||
@@ -232,7 +232,7 @@ python run.py callbacks=default_callbacks
|
|||||||
python run.py +trainer.gradient_clip_val=0.5
|
python run.py +trainer.gradient_clip_val=0.5
|
||||||
|
|
||||||
# stochastic weight averaging can make your models generalize better
|
# stochastic weight averaging can make your models generalize better
|
||||||
python run.py +trainer.stochastic_weight_avg=True
|
python run.py +trainer.stochastic_weight_avg=true
|
||||||
|
|
||||||
# run validation loop 4 times during a training epoch
|
# run validation loop 4 times during a training epoch
|
||||||
python run.py +trainer.val_check_interval=0.25
|
python run.py +trainer.val_check_interval=0.25
|
||||||
@@ -257,6 +257,9 @@ python run.py trainer.weights_summary="full"
|
|||||||
# print execution time profiling after training ends
|
# print execution time profiling after training ends
|
||||||
python run.py +trainer.profiler="simple"
|
python run.py +trainer.profiler="simple"
|
||||||
|
|
||||||
|
# raise exception, if any of the parameters or the loss are NaN or +/-inf
|
||||||
|
python run.py trainer.terminate_on_nan=true
|
||||||
|
|
||||||
# try overfitting to 1 batch
|
# try overfitting to 1 batch
|
||||||
python run.py +trainer.overfit_batches=1 trainer.max_epochs=20
|
python run.py +trainer.overfit_batches=1 trainer.max_epochs=20
|
||||||
|
|
||||||
@@ -360,7 +363,7 @@ If you want to use some popular official image instead, I recommend the [nvidia
|
|||||||
|
|
||||||
## :heart: Contributions
|
## :heart: Contributions
|
||||||
Have a question? Found a bug? Missing a specific feature? Ran into a problem? Feel free to file a new issue with respective title and description. If you already found a solution to your problem, don't hesitate to share it. Suggestions for new best practices and tricks are always welcome!
|
Have a question? Found a bug? Missing a specific feature? Ran into a problem? Feel free to file a new issue with respective title and description. If you already found a solution to your problem, don't hesitate to share it. Suggestions for new best practices and tricks are always welcome!
|
||||||
<br><br><br>
|
<br><br><br><br>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -424,7 +427,7 @@ data_dir: ${work_dir}/data/
|
|||||||
|
|
||||||
|
|
||||||
# use `python run.py debug=true` for easy debugging!
|
# use `python run.py debug=true` for easy debugging!
|
||||||
# (equivalent to running `python run.py trainer.fast_dev_run=True`)
|
# (equivalent to running `python run.py trainer.fast_dev_run=true`)
|
||||||
debug: False
|
debug: False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,18 @@ class MNISTDataModule(LightningDataModule):
|
|||||||
"""
|
"""
|
||||||
Example of LightningDataModule for MNIST dataset.
|
Example of LightningDataModule for MNIST dataset.
|
||||||
|
|
||||||
A DataModule standardizes the train, val, test splits, data preparation and transforms.
|
A DataModule implements 5 key methods:
|
||||||
The main advantage is consistent data splits, data preparation and transforms across models.
|
- prepare_data (things to do on 1 GPU/TPU, not on every GPU/TPU in distributed mode)
|
||||||
|
- setup (things to do on every accelerator in distributed mode)
|
||||||
|
- train_dataloader (the training dataloader)
|
||||||
|
- val_dataloader (the validation dataloader(s))
|
||||||
|
- test_dataloader (the test dataloader(s))
|
||||||
|
|
||||||
|
This allows you to share a full dataset without explaining how to download,
|
||||||
|
split, transform and process the data
|
||||||
|
|
||||||
Read the docs:
|
Read the docs:
|
||||||
https://pytorch-lightning.readthedocs.io/en/latest/datamodules.html
|
https://pytorch-lightning.readthedocs.io/en/latest/extensions/datamodules.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -24,7 +31,7 @@ class MNISTDataModule(LightningDataModule):
|
|||||||
batch_size: int = 64,
|
batch_size: int = 64,
|
||||||
num_workers: int = 0,
|
num_workers: int = 0,
|
||||||
pin_memory: bool = False,
|
pin_memory: bool = False,
|
||||||
**kwargs,
|
**kwargs
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class MNISTLitModel(LightningModule):
|
|||||||
- Optimizers (configure_optimizers)
|
- Optimizers (configure_optimizers)
|
||||||
|
|
||||||
Read the docs:
|
Read the docs:
|
||||||
https://pytorch-lightning.readthedocs.io/en/latest/lightning_module.html
|
https://pytorch-lightning.readthedocs.io/en/latest/common/lightning_module.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -57,10 +57,10 @@ class MNISTLitModel(LightningModule):
|
|||||||
"val/loss": [],
|
"val/loss": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x: torch.Tensor):
|
||||||
return self.model(x)
|
return self.model(x)
|
||||||
|
|
||||||
def step(self, batch):
|
def step(self, batch: Any):
|
||||||
x, y = batch
|
x, y = batch
|
||||||
logits = self.forward(x)
|
logits = self.forward(x)
|
||||||
loss = self.criterion(logits, y)
|
loss = self.criterion(logits, y)
|
||||||
@@ -123,7 +123,6 @@ class MNISTLitModel(LightningModule):
|
|||||||
|
|
||||||
See examples here:
|
See examples here:
|
||||||
https://pytorch-lightning.readthedocs.io/en/latest/common/lightning_module.html#configure-optimizers
|
https://pytorch-lightning.readthedocs.io/en/latest/common/lightning_module.html#configure-optimizers
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return torch.optim.Adam(
|
return torch.optim.Adam(
|
||||||
params=self.parameters(), lr=self.hparams.lr, weight_decay=self.hparams.weight_decay
|
params=self.parameters(), lr=self.hparams.lr, weight_decay=self.hparams.weight_decay
|
||||||
|
|||||||
Reference in new issue
Block a user