Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Lightning-AI/pytorch-lightning
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f5c48c8e2b71e1a11601e5bd6b235080949acf41
Choose a base ref
..
head repository: Lightning-AI/pytorch-lightning
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c9b05ca79399d8d969c25248d55bc4c534537976
Choose a head ref
Showing with 2,041 additions and 1,878 deletions.
  1. +1 −1 .drone.yml
  2. +74 −0 .github/workflows/ci_dockers.yml
  3. +1 −3 .github/workflows/{install-pkg.yml → ci_pkg-install.yml}
  4. +5 −5 .github/workflows/{pt-conda.yml → ci_pt-conda.yml}
  5. +1 −3 .github/workflows/{ci-test-base.yml → ci_test-base.yml}
  6. +3 −5 .github/workflows/{ci-testing.yml → ci_test-full.yml}
  7. +1 −1 .github/workflows/{tpu-testing.yml → ci_test-tpu.yml}
  8. +2 −3 .github/workflows/code-formatting.yml
  9. +0 −11 .github/workflows/docker-builds.yml
  10. +1 −3 .github/workflows/pypi-release.yml
  11. +1 −1 .mergify.yml
  12. +2 −0 CHANGELOG.md
  13. +3 −0 MANIFEST.in
  14. +7 −4 README.md
  15. +1 −1 benchmarks/test_parity.py
  16. +8 −10 dockers/base-xla/Dockerfile
  17. +30 −17 dockers/conda/Dockerfile
  18. +8 −8 docs/source/converting.rst
  19. +3 −3 docs/source/introduction_guide.rst
  20. +2 −4 docs/source/lr_finder.rst
  21. +3 −20 environment.yml
  22. +94 −0 pytorch_lightning/accelerators/accelerator_connector.py
  23. +7 −7 pytorch_lightning/core/lightning.py
  24. +1 −0 pytorch_lightning/loggers/comet.py
  25. +5 −1 pytorch_lightning/metrics/classification.py
  26. +3 −1 pytorch_lightning/metrics/functional/classification.py
  27. 0 pytorch_lightning/py.typed
  28. +0 −99 pytorch_lightning/trainer/callback_config.py
  29. +104 −0 pytorch_lightning/trainer/callback_connector.py
  30. +8 −0 pytorch_lightning/trainer/data_connector.py
  31. +0 −7 pytorch_lightning/trainer/data_loading.py
  32. +110 −0 pytorch_lightning/trainer/debugging_connector.py
  33. +1 −0 pytorch_lightning/trainer/docstrings/__init__.py
  34. +239 −0 pytorch_lightning/trainer/docstrings/trainer_ds.py
  35. +0 −264 pytorch_lightning/trainer/evaluate_loop.py
  36. +287 −258 pytorch_lightning/trainer/evaluation_loop.py
  37. +24 −0 pytorch_lightning/trainer/logger_connector.py
  38. +0 −16 pytorch_lightning/trainer/logging.py
  39. +5 −0 pytorch_lightning/trainer/model_connector.py
  40. +10 −9 pytorch_lightning/trainer/{lr_scheduler_connector.py → optimizer_connector.py}
  41. +24 −15 pytorch_lightning/trainer/{auto_mix_precision.py → precision_connector.py}
  42. +26 −0 pytorch_lightning/trainer/profiler_connector.py
  43. +152 −0 pytorch_lightning/trainer/properties.py
  44. +170 −884 pytorch_lightning/trainer/trainer.py
  45. +28 −3 pytorch_lightning/trainer/training_loop.py
  46. +55 −0 pytorch_lightning/trainer/training_trick_connector.py
  47. +0 −9 pytorch_lightning/trainer/training_tricks.py
  48. +224 −185 pytorch_lightning/{trainer → tuner}/lr_finder.py
  49. +34 −0 pytorch_lightning/tuner/tuning.py
  50. +223 −0 pytorch_lightning/utilities/argparse_utils.py
  51. +3 −3 requirements/test.txt
  52. +3 −3 setup.py
  53. +8 −0 tests/base/model_optimizers.py
  54. +5 −0 tests/metrics/functional/test_classification.py
  55. +7 −3 tests/metrics/test_classification.py
  56. +7 −7 tests/trainer/test_lr_finder.py
  57. +15 −0 tests/trainer/test_optimizers.py
  58. +2 −1 tests/trainer/test_trainer_cli.py
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ steps:
- pip list
- python -c "import torch ; print(' & '.join([torch.cuda.get_device_name(i) for i in range(torch.cuda.device_count())]) if torch.cuda.is_available() else 'only CPU')"
- coverage run --source pytorch_lightning -m py.test pytorch_lightning tests -v --durations=25 # --flake8
- python -m py.test benchmarks pl_examples -v --maxfail=2 --durations=0 # --flake8
- python -m py.test benchmarks pl_examples -v --maxfail=2 --durations=0 # --flake8
#- cd docs; make doctest; make coverage
- coverage report
# see: https://docs.codecov.io/docs/merging-reports
74 changes: 74 additions & 0 deletions .github/workflows/ci_dockers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI build Docker
# https://www.docker.com/blog/first-docker-github-action-is-here
# https://github.com/docker/build-push-action
# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build-Conda:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python_version: [3.7]
pytorch_version: [1.6]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build Docker
# publish master
uses: docker/build-push-action@v1.1.0
with:
dockerfile: dockers/conda/Dockerfile
build_args: PYTHON_VERSION=${{ matrix.python_version }},PYTORCH_VERSION=${{ matrix.pytorch_version }}
push: false
timeout-minutes: 40

build-XLA:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python_version: [3.7]
xla_version: ["nightly"]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build Docker
# publish master
uses: docker/build-push-action@v1.1.0
with:
dockerfile: dockers/base-xla/Dockerfile
build_args: PYTHON_VERSION=${{ matrix.python_version }},XLA_VERSION=${{ matrix.xla_version }}
push: false
timeout-minutes: 40

# TODO: uncomment this with fixing CUDA docker, no need to increase mergify count
# build-cuda:
# runs-on: ubuntu-20.04
# strategy:
# fail-fast: false
# matrix:
# python_version: [3.7]
# pytorch_version: [1.5]
# steps:
# - name: Checkout
# uses: actions/checkout@v2
#
# - name: Publish Master to Docker
# # publish master
# uses: docker/build-push-action@v1.1.0
# with:
# dockerfile: dockers/base-cuda/Dockerfile
# build_args: PYTHON_VERSION=${{ matrix.python_version }},PYTORCH_VERSION=${{ matrix.pytorch_version }}
# push: false
# timeout-minutes: 40
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Install pkg

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
on: # Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- master
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: PyTorch & Conda

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
on: # Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- master
@@ -65,7 +63,7 @@ jobs:
conda-version: 4.7.12
python-version: ${{ matrix.python-version }}
environment-file: environment.yml
activate-environment: pl-env
activate-environment: lightning
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!

- name: Reinstall Horovod if necessary
@@ -90,8 +88,10 @@ jobs:
run: |
conda info
conda list
pip install --requirement requirements/test.txt
pip list
# NOTE: run coverage on tests does not propagare faler status for Win, https://github.com/nedbat/coveragepy/issues/1003
python -m pytest pytorch_lightning tests -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
python -m pytest pytorch_lightning tests -v --durations=0 --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
# coverage report
shell: bash -l {0}

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: CI base testing

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
on: # Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- master
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: CI complete testing

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
on: # Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- master
@@ -68,7 +66,7 @@ jobs:
run: |
python -c "fname = 'requirements/base.txt' ; req = open(fname).read().replace('>=', '==') ; open(fname, 'w').write(req)"
python -c "fname = 'requirements/extra.txt' ; req = open(fname).read().replace('>=', '==') ; open(fname, 'w').write(req)"
python -c "fname = 'requirements/devel.txt' ; req = open(fname).read().replace('>=', '==') ; open(fname, 'w').write(req)"
python -c "fname = 'requirements/test.txt' ; req = open(fname).read().replace('>=', '==') ; open(fname, 'w').write(req)"
# Note: This uses an internal pip API and may not always work
# https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow
@@ -116,7 +114,7 @@ jobs:
- name: Tests
run: |
# NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003
coverage run --source pytorch_lightning -m pytest pytorch_lightning tests -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
coverage run --source pytorch_lightning -m pytest pytorch_lightning tests -v --durations=0 --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
- name: Upload pytest test results
uses: actions/upload-artifact@master
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ on:
push:
branches:
- master
# TODO: temporal disable TPU testing until we find way how to pass credentials to forked PRs
# TODO: temporal disable TPU testing until we find way how to pass credentials to forked PRs
# pull_request:
# branches:
# - master
5 changes: 2 additions & 3 deletions .github/workflows/code-formatting.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: "Check Code Format"
on:
# Trigger the workflow on push or pull request,
# but only for the master branch

on: # Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- master
11 changes: 0 additions & 11 deletions .github/workflows/docker-builds.yml
Original file line number Diff line number Diff line change
@@ -24,9 +24,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Publish Master to Docker
# publish master
@@ -69,14 +66,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Publish Master to Docker
# publish master
uses: docker/build-push-action@v1.1.0
if: github.event_name == 'push'
with:
repository: pytorchlightning/pytorch_lightning
username: ${{ secrets.DOCKER_USERNAME }}
@@ -96,14 +89,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Publish Master to Docker
# publish master
uses: docker/build-push-action@v1.1.0
if: github.event_name == 'push'
with:
repository: pytorchlightning/pytorch_lightning
username: ${{ secrets.DOCKER_USERNAME }}
4 changes: 1 addition & 3 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: PyPI Release

# https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
on: # Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- master
2 changes: 1 addition & 1 deletion .mergify.yml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ pull_request_rules:
# no requested chnages from any reviewer
- "#changes-requested-reviews-by=0"
# this serves as ALL check has to pass as we have actually around 40 tests in total
- "#status-success>=41"
- "#status-success>=44"
# this is just in case since we rely on GPU tests (note: redundand to the above)
- status-success=continuous-integration/drone/pr
- "status-success=ci/circleci: TPU-tests"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Fixed `GpuUsageLogger` to work on different platforms ([#3008](https://github.com/PyTorchLightning/pytorch-lightning/pull/3008))

- Fixed batch_outputs with optimizer frequencies ([#3229](https://github.com/PyTorchLightning/pytorch-lightning/pull/3229))

- Fixed setting batch size in `LightningModule.datamodule` when using `auto_scale_batch_size` ([#3266](https://github.com/PyTorchLightning/pytorch-lightning/pull/3266))

- Fixed Horovod distributed backend compatibility with native AMP ([#3404](https://github.com/PyTorchLightning/pytorch-lightning/pull/3404))
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -28,6 +28,9 @@ exclude *.toml
exclude *.svg
recursive-include pytorch_lightning *.py

# Include marker file for PEP 561
include pytorch_lightning/py.typed

# include examples
recursive-include pl_examples *.py *.md *.sh *.txt

11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -74,9 +74,9 @@ Get started with our [3 steps guide](https://pytorch-lightning.readthedocs.io/en
| Conda py3.7 [linux] | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) |
| Linux py3.7 [GPUs**] | - | - | - | [![Build Status](http://35.192.60.23/api/badges/PyTorchLightning/pytorch-lightning/status.svg)](http://35.192.60.23/PyTorchLightning/pytorch-lightning) |
| Linux py3.7 [TPUs***] | - | - | - | [![TPU tests](https://github.com/PyTorchLightning/pytorch-lightning/workflows/TPU%20tests/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22TPU+tests%22+branch%3Amaster) |
| Linux py3.6 / py3.7 / py3.8 | [![CI testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20testing/badge.svg?event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - | - | [![CI testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20testing/badge.svg?event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) |
| OSX py3.6 / py3.7 | - | [![CI testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20testing/badge.svg?event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - | [![CI testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20testing/badge.svg?event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) |
| Windows py3.6 / py3.7 / py3.8 | [![CI testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20testing/badge.svg?event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - | - | [![CI testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20testing/badge.svg?event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22)
| Linux py3.6 / py3.7 / py3.8 | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - | - | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) |
| OSX py3.6 / py3.7 | - | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) |
| Windows py3.6 / py3.7 / py3.8 | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - | - | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22)

- _\* `torch>=1.4` is the minimal pytorch version for Python 3.8_
- _\** tests run on two NVIDIA K80_
@@ -157,6 +157,7 @@ from torchvision.datasets import MNIST
from torch.utils.data import DataLoader, random_split
from torchvision import transforms
import pytorch_lightning as pl
from pytorch_lightning import Trainer
```

```python
@@ -194,13 +195,15 @@ dataset = MNIST(os.getcwd(), download=True, transform=transforms.ToTensor())
train, val = random_split(dataset, [55000, 5000])

model = LitClassifier()
trainer = pl.Trainer()
trainer = Trainer()
trainer.fit(model, DataLoader(train), DataLoader(val))
```

#### And without changing a single line of code, you could run on GPUs
```python
# 8 GPUs


trainer = Trainer(max_epochs=1, gpus=8)

# 256 GPUs
2 changes: 1 addition & 1 deletion benchmarks/test_parity.py
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ def lightning_loop(cls_model, num_runs=10, num_epochs=10):
)
trainer.fit(model)

final_loss = trainer.running_loss.last().item()
final_loss = trainer.train_loop.running_loss.last().item()
errors.append(final_loss)

time_end = time.perf_counter()
18 changes: 8 additions & 10 deletions dockers/base-xla/Dockerfile
Original file line number Diff line number Diff line change
@@ -61,26 +61,24 @@ ENV LD_LIBRARY_PATH="/root/miniconda3/envs/$CONDA_ENV/lib:$LD_LIBRARY_PATH"
# if you want this environment to be the default one, uncomment the following line:
ENV CONDA_DEFAULT_ENV=${CONDA_ENV}

# Install pytorch-lightning dependencies.
RUN \
# Get package
wget https://github.com/PyTorchLightning/pytorch-lightning/archive/master.zip --progress=bar:force:noscroll && \
unzip -q master.zip && \
rm master.zip && \
COPY ./ ./pytorch-lightning/

# Install pytorch-lightning dependencies.
RUN \
# Install PL dependencies
cd pytorch-lightning-master && \
cd pytorch-lightning && \
# drop Torch
python -c "fname = \"./requirements/base.txt\" ; lines = [line for line in open(fname).readlines() if not line.startswith(\"torch\")] ; open(fname, \"w\").writelines(lines)" && \
pip install --requirement ./requirements/base.txt && \
pip install --requirement ./requirements/base.txt --upgrade-strategy only-if-needed && \
# drop Horovod
python -c "fname = \"./requirements/extra.txt\" ; lines = [line for line in open(fname).readlines() if not line.startswith(\"horovod\")] ; open(fname, \"w\").writelines(lines)" && \
pip install --requirement ./requirements/extra.txt && \
pip install --requirement ./requirements/extra.txt --upgrade-strategy only-if-needed && \
# drop TorchVision
python -c "fname = \"./requirements/examples.txt\" ; lines = [line for line in open(fname).readlines() if not line.startswith(\"torchvision\")] ; open(fname, \"w\").writelines(lines)" && \
pip install --requirement ./requirements/examples.txt && \
pip install --requirement ./requirements/examples.txt --upgrade-strategy only-if-needed && \
cd .. && \
rm -rf pytorch-lightning-master && \
rm -rf pytorch-lightning && \
rm -rf /root/.cache

RUN pip --version && \
Loading