Skip to content

Commit

Permalink
Update Lightning Lite examples (#15599)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
  • Loading branch information
awaelchli and carmocca committed Nov 10, 2022
1 parent 4f4b43f commit 2076746
Show file tree
Hide file tree
Showing 18 changed files with 297 additions and 826 deletions.
13 changes: 12 additions & 1 deletion .azure/gpu-tests-lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pr:
- "release/*"
paths:
include:
- "examples/lite/**"
- "examples/run_lite_examples.sh"
- ".azure/gpu-tests-lite.yml"
- "requirements/lite/**"
- "src/lightning_lite/**"
Expand Down Expand Up @@ -64,7 +66,7 @@ jobs:
- bash: |
set -e
CUDA_VERSION_MM=$(python -c "import torch ; print(''.join(map(str, torch.version.cuda.split('.')[:2])))")
pip install -e .[dev,strategies] --find-links https://download.pytorch.org/whl/cu${CUDA_VERSION_MM}/torch_stable.html
pip install -e .[dev,strategies,examples] --find-links https://download.pytorch.org/whl/cu${CUDA_VERSION_MM}/torch_stable.html
pip list
env:
PACKAGE_NAME: "lite"
Expand Down Expand Up @@ -108,3 +110,12 @@ jobs:
testResultsFiles: '$(Build.StagingDirectory)/test-results.xml'
testRunTitle: '$(Agent.OS) - $(Build.DefinitionName) - Python $(python.version)'
condition: succeededOrFailed()

- script: |
# In order to run the examples, we need to substitute the meta package imports with the standalone package
python ../.actions/assistant.py copy_replace_imports --source_dir="./lite" --source_import="lightning.lite" --target_import="lightning_lite.lite"
set -e
bash run_lite_examples.sh --accelerator=cuda --devices=1
bash run_lite_examples.sh --accelerator=cuda --devices=2 --strategy ddp
workingDirectory: examples
displayName: 'Testing: Lite examples'
4 changes: 0 additions & 4 deletions .azure/gpu-tests-pytorch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ pr:
paths:
include:
- ".azure/gpu-tests-pytorch.yml"
- "examples/run_ddp_examples.sh"
- "examples/convert_from_pt_to_pl/**"
- "examples/run_pl_examples.sh"
- "examples/pl_basics/backbone_image_classifier.py"
- "examples/pl_basics/autoencoder.py"
- "examples/pl_loops/mnist_lite.py"
- "examples/pl_fault_tolerant/automatic.py"
- "examples/test_pl_examples.py"
- "examples/pl_integrations/dali_image_classifier.py"
Expand Down Expand Up @@ -169,7 +166,6 @@ jobs:

- script: |
set -e
bash run_ddp_examples.sh
bash run_pl_examples.sh --trainer.accelerator=gpu --trainer.devices=1
bash run_pl_examples.sh --trainer.accelerator=gpu --trainer.devices=2 --trainer.strategy=ddp
bash run_pl_examples.sh --trainer.accelerator=gpu --trainer.devices=2 --trainer.strategy=ddp --trainer.precision=16
Expand Down
5 changes: 2 additions & 3 deletions .github/checkgroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ subprojects:
- id: "pytorch_lightning"
paths:
# all examples don't need to be added because they aren't used in CI, but these are
- "examples/run_ddp_examples.sh"
- "examples/convert_from_pt_to_pl/**"
- "examples/run_pl_examples.sh"
- "examples/pl_basics/backbone_image_classifier.py"
- "examples/pl_basics/autoencoder.py"
- "examples/pl_loops/mnist_lite.py"
- "examples/pl_fault_tolerant/automatic.py"
- "examples/test_pl_examples.py"
- "examples/pl_integrations/dali_image_classifier.py"
Expand Down Expand Up @@ -237,6 +234,8 @@ subprojects:
- id: "lightning_lite: Azure GPU"
paths:
- ".azure/gpu-tests-lite.yml"
- "examples/lite/**"
- "examples/run_lite_examples.sh"
- "tests/tests_lite/run_standalone_*.sh"
- "tests/tests_pytorch/run_standalone_tests.sh" # used by Lite through a symlink
checks:
Expand Down
18 changes: 7 additions & 11 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ ______________________________________________________________________

______________________________________________________________________

## MNIST Examples
## Lightning Lite Examples

5 MNIST examples showing how to gradually convert from pure PyTorch to PyTorch Lightning.
We show how to accelerate your PyTorch code with [Lightning Lite](https://pytorch-lightning.readthedocs.io/en/latest/starter/lightning_lite.html) with minimal code changes.
You stay in full control of the training loop.

The transition through [LightningLite](https://pytorch-lightning.readthedocs.io/en/latest/starter/lightning_lite.html) from pure PyTorch is optional, but it might be helpful to learn about it.

- [MNIST with vanilla PyTorch](convert_from_pt_to_pl/image_classifier_1_pytorch.py)
- [MNIST with LightningLite](convert_from_pt_to_pl/image_classifier_2_lite.py)
- [MNIST LightningLite to LightningModule](convert_from_pt_to_pl/image_classifier_3_lite_to_lightning_module.py)
- [MNIST with LightningModule](convert_from_pt_to_pl/image_classifier_4_lightning_module.py)
- [MNIST with LightningModule + LightningDataModule](convert_from_pt_to_pl/image_classifier_5_lightning_datamodule.py)
- [MNIST with vanilla PyTorch](lite/image_classifier_1_pytorch.py)
- [MNIST with Lightning Lite](lite/image_classifier_2_lite.py)

______________________________________________________________________

## Basic Examples
## Lightning Trainer Examples

In this folder, we have 2 simple examples:
In this folder, we have 2 simple examples that showcase the power of the Lightning Trainer.

- [Image Classifier](pl_basics/backbone_image_classifier.py) (trains arbitrary datasets with arbitrary backbones).
- [Image Classifier + DALI](convert_from_pt_to_pl/image_classifier_4_dali.py) (defines the model inside the `LightningModule`).
Expand Down
67 changes: 0 additions & 67 deletions examples/convert_from_pt_to_pl/README.md

This file was deleted.

164 changes: 0 additions & 164 deletions examples/convert_from_pt_to_pl/image_classifier_2_lite.py

This file was deleted.

0 comments on commit 2076746

Please sign in to comment.