Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicki Skafte committed May 6, 2020
2 parents 0a639b5 + 810ecc8 commit df02a2c
Show file tree
Hide file tree
Showing 159 changed files with 2,296 additions and 1,316 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ references:
name: Make Documentation
command: |
# sudo apt-get install pandoc
sudo apt-get update && sudo apt-get install -y cmake
pip install -r requirements.txt --user
sudo pip install -r docs/requirements.txt
pip install -r requirements-extra.txt --user # for doctesting loggers etc.
# sphinx-apidoc -o ./docs/source ./pytorch_lightning **/test_* --force --follow-links
cd docs; make clean ; make html --debug --jobs 2 SPHINXOPTS="-W"
cd docs; make clean; make html --debug --jobs 2 SPHINXOPTS="-W"
make doctest; make coverage
jobs:

Expand Down
2 changes: 2 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ steps:
- apt-get update && apt-get install -y cmake
- pip install -r requirements.txt --user -q
- pip install -r ./tests/requirements-devel.txt --user -q
#- pip install -r ./docs/requirements.txt --user -q
- 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 benchmarks -v --doctest-modules # --flake8
#- cd docs; make doctest; make coverage
- coverage report
- codecov --token $CODECOV_TOKEN # --pr $DRONE_PULL_REQUEST --build $DRONE_BUILD_NUMBER --branch $DRONE_BRANCH --commit $DRONE_COMMIT --tag $DRONE_TAG
- python tests/collect_env_details.py
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ jobs:
pip list
shell: bash

- name: Reinstall Horovod if necessary
if: runner.os != 'windows' && matrix.python-version != '3.8'
run: |
HOROVOD_BUILT=$(python -c "import horovod.torch; horovod.torch.nccl_built(); print('SUCCESS')")
if [[ $HOROVOD_BUILT != "SUCCESS" ]]; then
pip uninstall -y horovod
HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install --no-cache-dir $(grep "horovod" requirements-extra.txt)
fi
horovodrun --check-build
shell: bash

- name: Cache datasets
uses: actions/cache@v1
with:
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ test_tube_data/
test_tube_exp/

# Documentations
docs/source/pl_examples*.rst
docs/source/pytorch_lightning*.rst
docs/source/tests*.rst
docs/source/api
docs/source/*.md

# Byte-compiled / optimized / DLL files
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Reduction when `batch_size < num_gpus` ([#1609](https://github.com/PyTorchLightning/pytorch-lightning/pull/1609))

- Updated LightningTemplateModel to look more like Colab example ([#1577](https://github.com/PyTorchLightning/pytorch-lightning/pull/1577))

### Deprecated

### Removed
Expand All @@ -34,6 +36,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Fixed wandb logger `global_step` affects other loggers ([#1492](https://github.com/PyTorchLightning/pytorch-lightning/issues/1485))

- Fixed disabling progress bar on non-zero ranks using Horovod backend ([#1709](https://github.com/PyTorchLightning/pytorch-lightning/pull/1709))

- Fixed bugs that prevent lr finder to be used together with early stopping and validation dataloaders ([#1676](https://github.com/PyTorchLightning/pytorch-lightning/pull/1676))

## [0.7.5] - 2020-04-27

### Changed
Expand Down Expand Up @@ -78,7 +84,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Defines shared proc. rank, remove rank from instances (e.g. loggers) ([#1408](https://github.com/PyTorchLightning/pytorch-lightning/pull/1408))
- Updated semantic segmentation example with custom U-Net and logging ([#1371](https://github.com/PyTorchLightning/pytorch-lightning/pull/1371))
- Disabled val and test shuffling ([#1600](https://github.com/PyTorchLightning/pytorch-lightning/pull/1600))
- Updated LightningTemplateModel to look more like Colab example ([#1546](https://github.com/PyTorchLightning/pytorch-lightning/pull/1577))

### Deprecated

Expand Down
Binary file added Datasets/MNIST/digits-0-1-2_nb-100/test.pt
Binary file not shown.
Binary file added Datasets/MNIST/digits-0-1-2_nb-100/training.pt
Binary file not shown.
9 changes: 7 additions & 2 deletions docs/source/apex.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.. testsetup:: *

from pytorch_lightning.trainer.trainer import Trainer


16-bit training
=================
Lightning offers 16-bit training for CPUs, GPUs and TPUs.
Expand Down Expand Up @@ -38,7 +43,7 @@ Install apex
Enable 16-bit
^^^^^^^^^^^^^

.. code-block:: python
.. testcode::

# turn on 16-bit
trainer = Trainer(amp_level='O1', precision=16)
Expand All @@ -50,7 +55,7 @@ TPU 16-bit
----------
16-bit on TPus is much simpler. To use 16-bit with TPUs set precision to 16 when using the tpu flag

.. code-block:: python
.. testcode::

# DEFAULT
trainer = Trainer(num_tpu_cores=8, precision=32)
Expand Down
37 changes: 22 additions & 15 deletions docs/source/callbacks.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.. testsetup:: *

from pytorch_lightning.trainer.trainer import Trainer
from pytorch_lightning.callbacks.base import Callback

.. role:: hidden
:class: hidden-section

Expand All @@ -18,21 +23,23 @@ An overall Lightning system should have:

Example:

.. doctest::

>>> import pytorch_lightning as pl
>>> class MyPrintingCallback(pl.Callback):
...
... def on_init_start(self, trainer):
... print('Starting to init trainer!')
...
... def on_init_end(self, trainer):
... print('trainer is init now')
...
... def on_train_end(self, trainer, pl_module):
... print('do something when training ends')
...
>>> trainer = pl.Trainer(callbacks=[MyPrintingCallback()])
.. testcode::

class MyPrintingCallback(Callback):

def on_init_start(self, trainer):
print('Starting to init trainer!')

def on_init_end(self, trainer):
print('trainer is init now')

def on_train_end(self, trainer, pl_module):
print('do something when training ends')

trainer = Trainer(callbacks=[MyPrintingCallback()])

.. testoutput::

Starting to init trainer!
trainer is init now

Expand Down
35 changes: 29 additions & 6 deletions docs/source/child_modules.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
.. testsetup:: *

import torch
from pytorch_lightning.trainer.trainer import Trainer
from pytorch_lightning.callbacks.base import Callback
from pytorch_lightning.core.lightning import LightningModule

class LitMNIST(LightningModule):

def __init__(self):
super().__init__()

def train_dataloader():
pass

def val_dataloader():
pass


Child Modules
-------------
Research projects tend to test different approaches to the same dataset.
Expand All @@ -7,13 +26,18 @@ For example, imagine we now want to train an Autoencoder to use as a feature ext
Recall that `LitMNIST` already defines all the dataloading etc... The only things
that change in the `Autoencoder` model are the init, forward, training, validation and test step.

.. code-block:: python
.. testcode::

class Encoder(torch.nn.Module):
...
pass

class Decoder(torch.nn.Module):
pass

class AutoEncoder(LitMNIST):

def __init__(self):
super().__init__()
self.encoder = Encoder()
self.decoder = Decoder()

Expand All @@ -30,10 +54,10 @@ that change in the `Autoencoder` model are the init, forward, training, validati
return loss

def validation_step(self, batch, batch_idx):
return self._shared_eval(batch, batch_idx, 'val'):
return self._shared_eval(batch, batch_idx, 'val')

def test_step(self, batch, batch_idx):
return self._shared_eval(batch, batch_idx, 'test'):
return self._shared_eval(batch, batch_idx, 'test')

def _shared_eval(self, batch, batch_idx, prefix):
x, y = batch
Expand All @@ -43,6 +67,7 @@ that change in the `Autoencoder` model are the init, forward, training, validati
loss = F.nll_loss(logits, y)
return {f'{prefix}_loss': loss}


and we can train this using the same trainer

.. code-block:: python
Expand All @@ -58,5 +83,3 @@ In this case, we want to use the `AutoEncoder` to extract image representations
some_images = torch.Tensor(32, 1, 28, 28)
representations = autoencoder(some_images)
..
80 changes: 43 additions & 37 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# import m2r
import builtins
import pt_lightning_sphinx_theme
from sphinx.ext import apidoc

PATH_HERE = os.path.abspath(os.path.dirname(__file__))
PATH_ROOT = os.path.join(PATH_HERE, '..', '..')
Expand Down Expand Up @@ -127,18 +128,18 @@
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
'pytorch_lightning.rst',
'pl_examples.*',
'modules.rst',
'api/pytorch_lightning.rst',
'api/pl_examples.*',
'api/modules.rst',

# deprecated/renamed:
'pytorch_lightning.loggers.comet_logger.rst', # TODO: remove in v0.8.0
'pytorch_lightning.loggers.mlflow_logger.rst', # TODO: remove in v0.8.0
'pytorch_lightning.loggers.test_tube_logger.rst', # TODO: remove in v0.8.0
'pytorch_lightning.callbacks.pt_callbacks.*', # TODO: remove in v0.8.0
'pytorch_lightning.pt_overrides.*', # TODO: remove in v0.8.0
'pytorch_lightning.root_module.*', # TODO: remove in v0.8.0
'pytorch_lightning.logging.*', # TODO: remove in v0.8.0
'api/pytorch_lightning.loggers.comet_logger.rst', # TODO: remove in v0.8.0
'api/pytorch_lightning.loggers.mlflow_logger.rst', # TODO: remove in v0.8.0
'api/pytorch_lightning.loggers.test_tube_logger.rst', # TODO: remove in v0.8.0
'api/pytorch_lightning.callbacks.pt_callbacks.*', # TODO: remove in v0.8.0
'api/pytorch_lightning.pt_overrides.*', # TODO: remove in v0.8.0
'api/pytorch_lightning.root_module.*', # TODO: remove in v0.8.0
'api/pytorch_lightning.logging.*', # TODO: remove in v0.8.0
]

# The name of the Pygments (syntax highlighting) style to use.
Expand Down Expand Up @@ -263,32 +264,33 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

# https://github.com/rtfd/readthedocs.org/issues/1139
# I use sphinx-apidoc to auto-generate API documentation for my project.
# Right now I have to commit these auto-generated files to my repository
# so that RTD can build them into HTML docs. It'd be cool if RTD could run
# sphinx-apidoc for me, since it's easy to forget to regen API docs
# and commit them to my repo after making changes to my code.

# packages for which sphinx-apidoc should generate the docs (.rst files)
PACKAGES = [
pytorch_lightning.__name__,
'pl_examples',
]

apidoc_output_folder = os.path.join(PATH_HERE, 'api')


def run_apidoc(_):
sys.path.insert(0, apidoc_output_folder)

# delete api-doc files before generating them
if os.path.exists(apidoc_output_folder):
shutil.rmtree(apidoc_output_folder)

for pkg in PACKAGES:
argv = ['-e', '-o', PATH_HERE, os.path.join(PATH_HERE, PATH_ROOT, pkg),
'**/test_*', '--force', '--private', '--module-first']
try:
# Sphinx 1.7+
from sphinx.ext import apidoc
apidoc.main(argv)
except ImportError:
# Sphinx 1.6 (and earlier)
from sphinx import apidoc
argv.insert(0, apidoc.__file__)
apidoc.main(argv)
argv = ['-e',
'-o', apidoc_output_folder,
os.path.join(PATH_ROOT, pkg),
'**/test_*',
'--force',
'--private',
'--module-first']

apidoc.main(argv)


def setup(app):
Expand All @@ -307,7 +309,7 @@ def setup(app):
# https://stackoverflow.com/questions/15889621/sphinx-how-to-exclude-imports-in-automodule

MOCK_REQUIRE_PACKAGES = []
with open(os.path.join(PATH_ROOT, 'requirements.txt'), 'r') as fp:
with open(os.path.join(PATH_ROOT, 'requirements-extra.txt'), 'r') as fp:
for ln in fp.readlines():
found = [ln.index(ch) for ch in list(',=<>#') if ch in ln]
pkg = ln[:min(found)] if found else ln
Expand All @@ -316,19 +318,10 @@ def setup(app):

# TODO: better parse from package since the import name and package name may differ
MOCK_MANUAL_PACKAGES = [
'torch',
'torchvision',
'PIL',
'test_tube',
'mlflow',
'comet_ml',
'wandb',
'neptune',
'trains',
]
autodoc_mock_imports = MOCK_REQUIRE_PACKAGES + MOCK_MANUAL_PACKAGES
# for mod_name in MOCK_REQUIRE_PACKAGES:
# sys.modules[mod_name] = mock.Mock()


# Options for the linkcode extension
Expand Down Expand Up @@ -403,3 +396,16 @@ def find_source():
# Useful for avoiding ambiguity when the same section heading appears in different documents.
# http://www.sphinx-doc.org/en/master/usage/extensions/autosectionlabel.html
autosectionlabel_prefix_document = True

# only run doctests marked with a ".. doctest::" directive
doctest_test_doctest_blocks = ''
doctest_global_setup = """
import importlib
import os
import torch
TORCHVISION_AVAILABLE = importlib.util.find_spec('torchvision')
"""
coverage_skip_undoc_in_source = True
Loading

0 comments on commit df02a2c

Please sign in to comment.