* 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:
Łukasz Zalewski authored and GitHub committed 2021-04-07 17:15:09 +02:00
1 parent 6a15f8ef3b
commit e2c8ed4bf8
3 files changed
+23 -14

No files matched your search

+12 -5
View File
@@ -9,12 +9,19 @@ from torchvision.transforms import transforms
class MNISTDataModule(LightningDataModule):
"""
Example of LightningDataModule for MNIST dataset.
A DataModule standardizes the train, val, test splits, data preparation and transforms.
The main advantage is consistent data splits, data preparation and transforms across models.
A DataModule implements 5 key methods:
- 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:
https://pytorch-lightning.readthedocs.io/en/latest/datamodules.html
https://pytorch-lightning.readthedocs.io/en/latest/extensions/datamodules.html
"""
def __init__(
@@ -24,7 +31,7 @@ class MNISTDataModule(LightningDataModule):
batch_size: int = 64,
num_workers: int = 0,
pin_memory: bool = False,
**kwargs,
**kwargs
):
super().__init__()
+3 -4
View File
@@ -19,7 +19,7 @@ class MNISTLitModel(LightningModule):
- Optimizers (configure_optimizers)
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__(
@@ -57,10 +57,10 @@ class MNISTLitModel(LightningModule):
"val/loss": [],
}
def forward(self, x):
def forward(self, x: torch.Tensor):
return self.model(x)
def step(self, batch):
def step(self, batch: Any):
x, y = batch
logits = self.forward(x)
loss = self.criterion(logits, y)
@@ -123,7 +123,6 @@ class MNISTLitModel(LightningModule):
See examples here:
https://pytorch-lightning.readthedocs.io/en/latest/common/lightning_module.html#configure-optimizers
"""
return torch.optim.Adam(
params=self.parameters(), lr=self.hparams.lr, weight_decay=self.hparams.weight_decay