Compare commits

..
22 Commits
Author SHA1 Message Date
William Falcon f338d39b92 release v0.12 2019-06-30 18:42:28 -04:00
William Falcon c13c6a9ec6 release vusing pytorch summarywriter now 2019-06-30 18:41:59 -04:00
William Falcon 1cb31cd210 Merge branch 'master' of https://github.com/williamFalcon/pytorch-lightning 2019-06-29 18:42:44 -04:00
William Falcon 1460987b40 added demo tfx images 2019-06-29 18:42:39 -04:00
William Falcon 56b6fedf18 Update requirements.txt 2019-06-29 18:41:05 -04:00
William Falcon e7d7004d92 Update requirements.txt 2019-06-29 18:40:25 -04:00
William Falcon 01e0027c5e Update README.md 2019-06-29 18:35:41 -04:00
William Falcon 773d677b3b Update README.md 2019-06-29 18:35:13 -04:00
William Falcon 0c5beb5ab1 Update README.md 2019-06-29 18:33:27 -04:00
William Falcon 0d3303a4ab Update README.md 2019-06-29 18:32:55 -04:00
William Falcon 2b55fa89b4 Update README.md 2019-06-29 18:29:37 -04:00
William Falcon ba763be4f9 Update README.md 2019-06-29 18:29:03 -04:00
William Falcon f39f8ed1a9 added demo tfx images 2019-06-29 18:28:11 -04:00
William Falcon 7997c4609b added demo tfx images 2019-06-29 18:26:13 -04:00
William Falcon 7fd2b0fa19 added module properties 2019-06-29 18:14:45 -04:00
William Falcon 04445504e5 Update README.md 2019-06-29 18:09:11 -04:00
William Falcon 5735a366cf Update README.md 2019-06-29 18:08:57 -04:00
William Falcon a36061ad2b Update README.md 2019-06-29 18:06:30 -04:00
William Falcon 614d84e560 Update README.md 2019-06-29 18:05:17 -04:00
William Falcon 3ab8120f27 Update README.md 2019-06-29 17:58:10 -04:00
William Falcon 306ca02813 Update README.md 2019-06-29 17:57:40 -04:00
William Falcon 8a6680937f 0.113 2019-06-29 17:51:15 -04:00
9 changed files with 116 additions and 44 deletions
+1
View File
@@ -8,6 +8,7 @@ datasets/
model_weights/ model_weights/
app/models/ app/models/
pip-wheel-metadata/ pip-wheel-metadata/
test_tube_exp/
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
+71 -8
View File
@@ -36,9 +36,26 @@ To use lightning do 2 things:
2. [Define a LightningModel](https://github.com/williamFalcon/pytorch-lightning/blob/master/examples/new_project_templates/lightning_module_template.py). 2. [Define a LightningModel](https://github.com/williamFalcon/pytorch-lightning/blob/master/examples/new_project_templates/lightning_module_template.py).
## What does lightning control for me? ## What does lightning control for me?
Everything! Except the following three things: Everything!
Except for these 6 core functions which you define:
**What happens in the training loop** ```{.python}
# what to do in the training loop
def training_step(self, data_batch, batch_nb):
# what to do in the validation loop
def validation_step(self, data_batch, batch_nb):
# how to aggregate validation_step outputs
def validation_end(self, outputs):
# and your dataloaders
def tng_dataloader():
def val_dataloader():
def test_dataloader():
```
**Could be as complex as seq-2-seq + attention**
```python ```python
# define what happens for training here # define what happens for training here
@@ -46,25 +63,39 @@ def training_step(self, data_batch, batch_nb):
x, y = data_batch x, y = data_batch
# define your own forward and loss calculation # define your own forward and loss calculation
out = self.forward(x) hidden_states = self.encoder(x)
loss = my_loss(out, y)
# even as complex as a seq-2seq + attn model
# (this is just a toy, non-working example to illustrate)
start_token = '<SOS>'
last_hidden = torch.zeros(...)
loss = 0
for step in range(max_seq_len):
attn_context = self.attention_nn(hidden_states, start_token)
pred = self.decoder(start_token, attn_context, last_hidden)
last_hidden = pred
pred = self.predict_nn(pred)
loss += self.loss(last_hidden, y[step])
#toy example as well
loss = loss / max_seq_len
return {'loss': loss} return {'loss': loss}
``` ```
**What happens in the validation loop** **Or as basic as CNN image classification**
```python ```python
# define what happens for validation here # define what happens for validation here
def validation_step(self, data_batch, batch_nb): def validation_step(self, data_batch, batch_nb):
x, y = data_batch x, y = data_batch
# define your own forward and loss calculation # or as basic as a CNN classification
out = self.forward(x) out = self.forward(x)
loss = my_loss(out, y) loss = my_loss(out, y)
return {'loss': loss} return {'loss': loss}
``` ```
**And what to do with the output of all validation batches** **And you also decide how to collate the output of all validation steps**
```python ```python
def validation_end(self, outputs): def validation_end(self, outputs):
@@ -84,8 +115,40 @@ def validation_end(self, outputs):
tqdm_dic = {'val_loss': val_loss_mean.item(), 'val_acc': val_acc_mean.item()} tqdm_dic = {'val_loss': val_loss_mean.item(), 'val_acc': val_acc_mean.item()}
return tqdm_dic return tqdm_dic
``` ```
## TensorboardX
Lightning is fully integrated with tensorboardX.
## Lightning gives you options to control the following: <p align="center">
<a href="https://williamfalcon.github.io/pytorch-lightning/">
<img alt="" src="https://github.com/williamFalcon/pytorch-lightning/blob/master/docs/source/_static/tf_loss.png" width="900px">
</a>
</p>
Lightning also adds a text column with all the hyperparameters for this experiment.
<p align="center">
<a href="https://williamfalcon.github.io/pytorch-lightning/">
<img alt="" src="https://github.com/williamFalcon/pytorch-lightning/blob/master/docs/source/_static/tf_tags.png" width="900px">
</a>
</p>
Simply note the path you set for the Experiment
``` {.python}
from test_tube import Experiment
from pytorch-lightning import Trainer
exp = Experiment(save_dir='/some/path')
trainer = Trainer(experiment=exp)
...
```
And run tensorboard from that dir
```bash
tensorboard --logdir /some/path
```
## Lightning automatically automates all of the following ([each is also configurable](https://williamfalcon.github.io/pytorch-lightning/Trainer/)):
###### Checkpointing ###### Checkpointing
+18 -3
View File
@@ -8,12 +8,21 @@ The current epoch
#### dtype #### dtype
Current dtype Current dtype
---
#### experiment
An instance of test-tube Experiment which you can use to log anything for tensorboarX.
```{.python}
self.experiment.add_embedding(...)
self.experiment.log({'val_loss': 0.9})
self.experiment.add_scalars(...)
```
--- ---
#### global_step #### global_step
Total training batches seen across all epochs Total training batches seen across all epochs
--- ---
#### gradient_clip #### gradient_clip
The current gradient clip value The current gradient clip value
--- ---
@@ -21,5 +30,11 @@ The current gradient clip value
True if your model is currently running on GPUs. Useful to set flags around the LightningModule for different CPU vs GPU behavior. True if your model is currently running on GPUs. Useful to set flags around the LightningModule for different CPU vs GPU behavior.
--- ---
#### Trainer #### trainer
Last resort access to any state the trainer has. Changing certain properties here could affect your training run. Last resort access to any state the trainer has. Changing certain properties here could affect your training run.
```{.python}
self.trainer.optimizers
self.trainer.current_epoch
...
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 219 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

@@ -0,0 +1 @@
from .lightning_module_template import LightningTemplateModel
@@ -56,6 +56,7 @@ def main(hparams, cluster, results_dict):
# init experiment # init experiment
log_dir = os.path.dirname(os.path.realpath(__file__)) log_dir = os.path.dirname(os.path.realpath(__file__))
log_dir = os.path.join(log_dir, 'test_tube_demo_logs')
exp = Experiment( exp = Experiment(
name='test_tube_exp', name='test_tube_exp',
save_dir=log_dir, save_dir=log_dir,
+21 -30
View File
@@ -1,41 +1,32 @@
absl-py==0.7.1
astor==0.8.0 atomicwrites==1.2.1
bleach==3.1.0 attrs==18.2.0
certifi==2019.6.16 certifi==2018.11.29
cffi==1.12.3 cffi==1.11.5
chardet==3.0.4 imageio==2.4.1
docutils==0.14 mkl-fft==1.0.6
gast==0.2.2
google-pasta==0.1.7
grpcio==1.21.1
h5py==2.9.0
idna==2.8
imageio==2.5.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
Markdown==3.1.1
mkl-fft==1.0.12
mkl-random==1.0.2 mkl-random==1.0.2
numpy==1.16.4 more-itertools==5.0.0
numpy==1.15.4
olefile==0.46 olefile==0.46
pandas==0.24.2 pandas==0.23.4
Pillow==6.0.0 Pillow==5.3.0
pkginfo==1.5.0.1 pluggy==0.8.0
protobuf==3.8.0 py==1.7.0
pycparser==2.19 pycparser==2.19
Pygments==2.4.1 pytest==4.0.2
python-dateutil==2.8.0 python-dateutil==2.7.5
pytz==2019.1 pytz==2018.7
readme-renderer==24.0 scikit-learn==0.20.2
requests==2.22.0 scipy==1.2.0
requests-toolbelt==0.9.1
six==1.12.0 six==1.12.0
sklearn==0.0
tensorboard==1.14.0 tensorboard==1.14.0
tensorboardX==1.7 tensorboardX==1.7
tensorflow==1.14.0 tensorflow==1.14.0
tensorflow-estimator==1.14.0
termcolor==1.1.0
test-tube==0.643 test-tube==0.643
torch==1.0.0
torchvision==0.2.1
tqdm==4.32.1 tqdm==4.32.1
twine==1.13.0 twine==1.13.0
urllib3==1.25.3 urllib3==1.25.3
+3 -3
View File
@@ -7,7 +7,7 @@ from setuptools import setup, find_packages
# http://blog.ionelmc.ro/2014/05/25/python-packaging/ # http://blog.ionelmc.ro/2014/05/25/python-packaging/
setup( setup(
name="pytorch-lightning", name="pytorch-lightning",
version='0.113', version='0.12',
description="The Keras for ML researchers using PyTorch", description="The Keras for ML researchers using PyTorch",
author="William Falcon", author="William Falcon",
author_email="waf2107@columbia.edu", author_email="waf2107@columbia.edu",
@@ -17,9 +17,9 @@ setup(
keywords=["deep learning", "pytorch", "AI"], keywords=["deep learning", "pytorch", "AI"],
python_requires=">=3.5", python_requires=">=3.5",
install_requires=[ install_requires=[
"torch>=1.0.0", "torch>=1.1.0",
"tqdm", "tqdm",
"test-tube>=0.643", "test-tube>=0.65",
"tensorflow>=1.14.0" "tensorflow>=1.14.0"
], ],
packages=find_packages(), packages=find_packages(),