mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-11 12:31:23 +08:00
CI: Force docs warnings to be raised as errors (+ fix all) (#1191)
* add argument to force warn * fix automodule error * fix permalink error * fix indentation warning * fix warning * fix import warnings * fix duplicate label warning * fix bullet point indentation warning * fix duplicate label warning * fix "import not top level" warning * line too long * fix indentation * fix bullet points indentation warning * fix hooks warnings * fix reference problem with excluded test_tube * fix indentation in print * change imports for trains logger * remove pandas type annotation * Update pytorch_lightning/core/lightning.py * include bullet points inside note * remove old quick start guide (unused) * fix unused warning * fix formatting * fix duplicate label issue * fix duplicate label warning (replaced by class ref) * fix tick * fix indentation warnings * docstring ticks * remove obsolete docstring typing * Revert "remove old quick start guide (unused)" This reverts commit d51bb40695442c8fa11bc9df74f6db56264f7509. * added old quick start guide to navigation * remove unused tutorials file * ignore some modules that got deprecated and are not used anymore * fix duplicate label warning * move examples doc and exclude pl_examples from autodoc * fix formatting for configure_optimizer * fix no blank line warnings * fix "see also" labels and add paramref extension * fix more reference problems * fix multi-gpu reference * fix weird warning * fix indentation and unrecognized characters in code block * fix warning "... not included in toctree" * fix PIL import error * fix duplicate target "here" warning * fix broken link * revert accidentally moved pl_examples * changelog * stdout * note some things to know Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: J. Borovec <jirka.borovec@seznam.cz> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
This commit is contained in:
co-authored by
Jirka Borovec
J. Borovec
parent
732eaee4d7
commit
792962ecc9
@@ -1,6 +1,8 @@
|
||||
.. role:: hidden
|
||||
:class: hidden-section
|
||||
|
||||
.. _callbacks:
|
||||
|
||||
Callbacks
|
||||
=========
|
||||
|
||||
|
||||
+28
-5
@@ -73,7 +73,7 @@ needs_sphinx = '1.4'
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinxcontrib.mockautodoc',
|
||||
# 'sphinxcontrib.mockautodoc', # raises error: directive 'automodule' is already registered ...
|
||||
# 'sphinxcontrib.fulltoc', # breaks pytorch-theme with unexpected kw argument 'titles_only'
|
||||
'sphinx.ext.doctest',
|
||||
'sphinx.ext.intersphinx',
|
||||
@@ -87,6 +87,7 @@ extensions = [
|
||||
# 'm2r',
|
||||
'nbsphinx',
|
||||
'sphinx_autodoc_typehints',
|
||||
'sphinx_paramlinks',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
@@ -125,7 +126,20 @@ language = None
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = ['*.test_*']
|
||||
exclude_patterns = [
|
||||
'pytorch_lightning.rst',
|
||||
'pl_examples.*',
|
||||
'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
|
||||
]
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = None
|
||||
@@ -297,8 +311,17 @@ with open(os.path.join(PATH_ROOT, 'requirements.txt'), 'r') as fp:
|
||||
MOCK_REQUIRE_PACKAGES.append(pkg.rstrip())
|
||||
|
||||
# TODO: better parse from package since the import name and package name may differ
|
||||
MOCK_MANUAL_PACKAGES = ['torch', 'torchvision', 'test_tube',
|
||||
'mlflow', 'comet_ml', 'wandb', 'neptune', 'trains']
|
||||
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()
|
||||
@@ -369,7 +392,7 @@ autodoc_default_options = {
|
||||
# This value determines the text for the permalink; it defaults to "¶". Set it to None or the empty
|
||||
# string to disable permalinks.
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_add_permalinks
|
||||
html_add_permalinks = True
|
||||
html_add_permalinks = "¶"
|
||||
|
||||
# True to prefix each section label with the name of the document it is in, followed by a colon.
|
||||
# For example, index:Introduction for a section called Introduction that appears in document index.rst.
|
||||
|
||||
+16
-13
@@ -8,6 +8,9 @@ This flag runs a "unit test" by running 1 training batch and 1 validation batch.
|
||||
The point is to detect any bugs in the training/validation loop without having to wait for
|
||||
a full epoch to crash.
|
||||
|
||||
(See: :paramref:`~pytorch_lightning.trainer.trainer.Trainer.fast_dev_run`
|
||||
argument of :class:`~pytorch_lightning.trainer.trainer.Trainer`)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
trainer = pl.Trainer(fast_dev_run=True)
|
||||
@@ -16,6 +19,9 @@ Inspect gradient norms
|
||||
----------------------
|
||||
Logs (to a logger), the norm of each weight matrix.
|
||||
|
||||
(See: :paramref:`~pytorch_lightning.trainer.trainer.Trainer.track_grad_norm`
|
||||
argument of :class:`~pytorch_lightning.trainer.trainer.Trainer`)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# the 2-norm
|
||||
@@ -25,7 +31,8 @@ Log GPU usage
|
||||
-------------
|
||||
Logs (to a logger) the GPU usage for each GPU on the master machine.
|
||||
|
||||
(See: :ref:`trainer`)
|
||||
(See: :paramref:`~pytorch_lightning.trainer.trainer.Trainer.log_gpu_memory`
|
||||
argument of :class:`~pytorch_lightning.trainer.trainer.Trainer`)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -37,7 +44,8 @@ Make model overfit on subset of data
|
||||
A good debugging technique is to take a tiny portion of your data (say 2 samples per class),
|
||||
and try to get your model to overfit. If it can't, it's a sign it won't work with large datasets.
|
||||
|
||||
(See: :ref:`trainer`)
|
||||
(See: :paramref:`~pytorch_lightning.trainer.trainer.Trainer.overfit_pct`
|
||||
argument of :class:`~pytorch_lightning.trainer.trainer.Trainer`)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -48,28 +56,23 @@ Print the parameter count by layer
|
||||
Whenever the .fit() function gets called, the Trainer will print the weights summary for the lightningModule.
|
||||
To disable this behavior, turn off this flag:
|
||||
|
||||
(See: :ref:`trainer.weights_summary`)
|
||||
(See: :paramref:`~pytorch_lightning.trainer.trainer.Trainer.weights_summary`
|
||||
argument of :class:`~pytorch_lightning.trainer.trainer.Trainer`)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
trainer = pl.Trainer(weights_summary=None)
|
||||
|
||||
Print which gradients are nan
|
||||
-----------------------------
|
||||
Prints the tensors with nan gradients.
|
||||
|
||||
(See: :meth:`trainer.print_nan_grads`)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
trainer = pl.Trainer(print_nan_grads=False)
|
||||
|
||||
Set the number of validation sanity steps
|
||||
-----------------------------------------
|
||||
Lightning runs a few steps of validation in the beginning of training.
|
||||
This avoids crashing in the validation loop sometime deep into a lengthy training loop.
|
||||
|
||||
(See: :paramref:`~pytorch_lightning.trainer.trainer.Trainer.num_sanity_val_steps`
|
||||
argument of :class:`~pytorch_lightning.trainer.trainer.Trainer`)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# DEFAULT
|
||||
trainer = Trainer(nb_sanity_val_steps=5)
|
||||
trainer = Trainer(num_sanity_val_steps=5)
|
||||
@@ -11,7 +11,8 @@ Enable Early Stopping
|
||||
---------------------
|
||||
There are two ways to enable early stopping.
|
||||
|
||||
.. seealso:: :ref:`trainer`
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.trainer.trainer.Trainer`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -35,4 +36,5 @@ To disable early stopping pass ``False`` to the `early_stop_callback`.
|
||||
Note that ``None`` will not disable early stopping but will lead to the
|
||||
default behaviour.
|
||||
|
||||
.. seealso:: :ref:`trainer`
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.trainer.trainer.Trainer`
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:name: Community Examples
|
||||
:caption: Community Examples
|
||||
|
||||
Contextual Emotion Detection (DoubleDistilBert) <https://github.com/PyTorchLightning/emotion_transformer>
|
||||
Generative Adversarial Network <https://colab.research.google.com/drive/1F_RNcHzTfFuQf-LeKvSlud6x7jXYkG31#scrollTo=TyYOdg8g77P0>
|
||||
Hyperparameter optimization with Optuna <https://github.com/optuna/optuna/blob/master/examples/pytorch_lightning_simple.py>
|
||||
Image Inpainting using Partial Convolutions <https://github.com/ryanwongsa/Image-Inpainting>
|
||||
MNIST on TPU <https://colab.research.google.com/drive/1-_LKx4HwAxl5M6xPJmqAAu444LTDQoa3#scrollTo=BHBz1_AnamN_>
|
||||
NER (transformers, TPU) <https://colab.research.google.com/drive/1dBN-wwYUngLYVt985wGs_OKPlK_ANB9D>
|
||||
NeuralTexture (CVPR) <https://github.com/PyTorchLightning/neuraltexture>
|
||||
Recurrent Attentive Neural Process <https://github.com/PyTorchLightning/attentive-neural-processes>
|
||||
Siamese Nets for One-shot Image Recognition <https://github.com/PyTorchLightning/Siamese-Neural-Networks>
|
||||
Speech Transformers <https://github.com/PyTorchLightning/speech-transformer-pytorch_lightning>
|
||||
Transformers transfer learning (Huggingface) <https://colab.research.google.com/drive/1F_RNcHzTfFuQf-LeKvSlud6x7jXYkG31#scrollTo=yr7eaxkF-djf>
|
||||
Transformers text classification <https://github.com/ricardorei/lightning-text-classification>
|
||||
VAE Library of over 18+ VAE flavors <https://github.com/AntixK/PyTorch-VAE>
|
||||
@@ -7,7 +7,8 @@ Comet.ml
|
||||
`Comet.ml <https://www.comet.ml/site/>`_ is a third-party logger.
|
||||
To use CometLogger as your logger do the following.
|
||||
|
||||
.. seealso:: :ref:`comet` docs.
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.loggers.CometLogger` docs.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -38,7 +39,8 @@ Neptune.ai
|
||||
`Neptune.ai <https://neptune.ai/>`_ is a third-party logger.
|
||||
To use Neptune.ai as your logger do the following.
|
||||
|
||||
.. seealso:: :ref:`neptune` docs.
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.loggers.NeptuneLogger` docs.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -68,7 +70,8 @@ allegro.ai TRAINS
|
||||
`allegro.ai <https://github.com/allegroai/trains/>`_ is a third-party logger.
|
||||
To use TRAINS as your logger do the following.
|
||||
|
||||
.. seealso:: :ref:`trains` docs.
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.loggers.TrainsLogger` docs.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -95,7 +98,8 @@ Tensorboard
|
||||
|
||||
To use `Tensorboard <https://pytorch.org/docs/stable/tensorboard.html>`_ as your logger do the following.
|
||||
|
||||
.. seealso:: TensorBoardLogger :ref:`tf-logger`
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.loggers.TensorBoardLogger` docs.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -121,7 +125,8 @@ Test Tube
|
||||
`Test Tube <https://github.com/williamFalcon/test-tube>`_ is a tensorboard logger but with nicer file structure.
|
||||
To use TestTube as your logger do the following.
|
||||
|
||||
.. seealso:: TestTube :ref:`testTube`
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.loggers.TestTubeLogger` docs.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -146,7 +151,8 @@ Wandb
|
||||
`Wandb <https://www.wandb.com/>`_ is a third-party logger.
|
||||
To use Wandb as your logger do the following.
|
||||
|
||||
.. seealso:: :ref:`wandb` docs
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.loggers.WandbLogger` docs.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -167,7 +173,7 @@ The Wandb logger is available anywhere except ``__init__`` in your LightningModu
|
||||
|
||||
|
||||
Multiple Loggers
|
||||
^^^^^^^^^^^^^^^^^
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
PyTorch-Lightning supports use of multiple loggers, just pass a list to the `Trainer`.
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ Control log writing frequency
|
||||
Writing to a logger can be expensive. In Lightning you can set the interval at which you
|
||||
want to log using this trainer flag.
|
||||
|
||||
.. seealso:: :ref:`trainer`
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.trainer.trainer.Trainer`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ Force training for min or max epochs
|
||||
-------------------------------------
|
||||
It can be useful to force training for a minimum number of epochs or limit to a max number.
|
||||
|
||||
.. seealso:: :ref:`trainer`
|
||||
.. seealso::
|
||||
:class:`~pytorch_lightning.trainer.trainer.Trainer`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ Hooks
|
||||
=====
|
||||
|
||||
.. automodule:: pytorch_lightning.core.hooks
|
||||
:noindex:
|
||||
|
||||
Hooks lifecycle
|
||||
---------------
|
||||
|
||||
+28
-2
@@ -11,6 +11,7 @@ PyTorch Lightning Documentation
|
||||
:name: start
|
||||
:caption: Start Here
|
||||
|
||||
new-project
|
||||
introduction_guide
|
||||
|
||||
.. toctree::
|
||||
@@ -24,13 +25,24 @@ PyTorch Lightning Documentation
|
||||
loggers
|
||||
trainer
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:name: Community Examples
|
||||
:caption: Community Examples
|
||||
|
||||
examples
|
||||
Contextual Emotion Detection (DoubleDistilBert) <https://github.com/PyTorchLightning/emotion_transformer>
|
||||
Generative Adversarial Network <https://colab.research.google.com/drive/1F_RNcHzTfFuQf-LeKvSlud6x7jXYkG31#scrollTo=TyYOdg8g77P0>
|
||||
Hyperparameter optimization with Optuna <https://github.com/optuna/optuna/blob/master/examples/pytorch_lightning_simple.py>
|
||||
Image Inpainting using Partial Convolutions <https://github.com/ryanwongsa/Image-Inpainting>
|
||||
MNIST on TPU <https://colab.research.google.com/drive/1-_LKx4HwAxl5M6xPJmqAAu444LTDQoa3#scrollTo=BHBz1_AnamN_>
|
||||
NER (transformers, TPU) <https://colab.research.google.com/drive/1dBN-wwYUngLYVt985wGs_OKPlK_ANB9D>
|
||||
NeuralTexture (CVPR) <https://github.com/PyTorchLightning/neuraltexture>
|
||||
Recurrent Attentive Neural Process <https://github.com/PyTorchLightning/attentive-neural-processes>
|
||||
Siamese Nets for One-shot Image Recognition <https://github.com/PyTorchLightning/Siamese-Neural-Networks>
|
||||
Speech Transformers <https://github.com/PyTorchLightning/speech-transformer-pytorch_lightning>
|
||||
Transformers transfer learning (Huggingface) <https://colab.research.google.com/drive/1F_RNcHzTfFuQf-LeKvSlud6x7jXYkG31#scrollTo=yr7eaxkF-djf>
|
||||
Transformers text classification <https://github.com/ricardorei/lightning-text-classification>
|
||||
VAE Library of over 18+ VAE flavors <https://github.com/AntixK/PyTorch-VAE>
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
@@ -83,3 +95,17 @@ Indices and tables
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
|
||||
|
||||
.. This is here to make sphinx aware of the modules but not throw an error/warning
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
pytorch_lightning.core
|
||||
pytorch_lightning.callbacks
|
||||
pytorch_lightning.loggers
|
||||
pytorch_lightning.overrides
|
||||
pytorch_lightning.profiler
|
||||
pytorch_lightning.trainer
|
||||
pytorch_lightning.utilities
|
||||
@@ -472,7 +472,7 @@ First, change the runtime to TPU (and reinstall lightning).
|
||||
|
||||
Next, install the required xla library (adds support for PyTorch on TPUs)
|
||||
|
||||
.. code-block::
|
||||
.. code-block:: python
|
||||
|
||||
import collections
|
||||
from datetime import datetime, timedelta
|
||||
@@ -504,6 +504,8 @@ Next, install the required xla library (adds support for PyTorch on TPUs)
|
||||
update = threading.Thread(target=update_server_xrt)
|
||||
update.start()
|
||||
|
||||
.. code-block::
|
||||
|
||||
# Install Colab TPU compat PyTorch/TPU wheels and dependencies
|
||||
!pip uninstall -y torch torchvision
|
||||
!gsutil cp "$DIST_BUCKET/$TORCH_WHEEL" .
|
||||
@@ -981,7 +983,8 @@ And pass the callbacks into the trainer
|
||||
|
||||
Trainer(callbacks=[MyPrintingCallback()])
|
||||
|
||||
.. note:: See full list of 12+ hooks in the `Callback docs <callbacks.rst#callback-class>`_
|
||||
.. note::
|
||||
See full list of 12+ hooks in the :ref:`callbacks`.
|
||||
|
||||
---------
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
.. _multi-gpu-training:
|
||||
|
||||
Multi-GPU training
|
||||
===================
|
||||
==================
|
||||
Lightning supports multiple ways of doing distributed training.
|
||||
|
||||
Preparing your code
|
||||
@@ -235,7 +237,7 @@ Validation and test step also have the same option when using dp
|
||||
...
|
||||
|
||||
Implement Your Own Distributed (DDP) training
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
If you need your own way to init PyTorch DDP you can override :meth:`pytorch_lightning.core.LightningModule.`.
|
||||
|
||||
If you also need to use your own DDP implementation, override: :meth:`pytorch_lightning.core.LightningModule.configure_ddp`.
|
||||
|
||||
+50
-49
@@ -41,65 +41,66 @@ hosted on GCP.
|
||||
|
||||
To get a TPU on colab, follow these steps:
|
||||
|
||||
1. Go to https://colab.research.google.com/.
|
||||
1. Go to `https://colab.research.google.com/ <https://colab.research.google.com/>`_.
|
||||
|
||||
2. Click "new notebook" (bottom right of pop-up).
|
||||
2. Click "new notebook" (bottom right of pop-up).
|
||||
|
||||
3. Click runtime > change runtime settings. Select Python 3,
|
||||
and hardware accelerator "TPU". This will give you a TPU with 8 cores.
|
||||
3. Click runtime > change runtime settings. Select Python 3, and hardware accelerator "TPU".
|
||||
This will give you a TPU with 8 cores.
|
||||
|
||||
4. Next, insert this code into the first cell and execute. This
|
||||
will install the xla library that interfaces between PyTorch and
|
||||
the TPU.
|
||||
4. Next, insert this code into the first cell and execute.
|
||||
This will install the xla library that interfaces between PyTorch and the TPU.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: python
|
||||
|
||||
import collections
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import requests
|
||||
import threading
|
||||
import collections
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import requests
|
||||
import threading
|
||||
|
||||
_VersionConfig = collections.namedtuple('_VersionConfig', 'wheels,server')
|
||||
VERSION = "xrt==1.15.0" #@param ["xrt==1.15.0", "torch_xla==nightly"]
|
||||
CONFIG = {
|
||||
'xrt==1.15.0': _VersionConfig('1.15', '1.15.0'),
|
||||
'torch_xla==nightly': _VersionConfig('nightly', 'XRT-dev{}'.format(
|
||||
(datetime.today() - timedelta(1)).strftime('%Y%m%d'))),
|
||||
}[VERSION]
|
||||
DIST_BUCKET = 'gs://tpu-pytorch/wheels'
|
||||
TORCH_WHEEL = 'torch-{}-cp36-cp36m-linux_x86_64.whl'.format(CONFIG.wheels)
|
||||
TORCH_XLA_WHEEL = 'torch_xla-{}-cp36-cp36m-linux_x86_64.whl'.format(CONFIG.wheels)
|
||||
TORCHVISION_WHEEL = 'torchvision-{}-cp36-cp36m-linux_x86_64.whl'.format(CONFIG.wheels)
|
||||
_VersionConfig = collections.namedtuple('_VersionConfig', 'wheels,server')
|
||||
VERSION = "xrt==1.15.0" #@param ["xrt==1.15.0", "torch_xla==nightly"]
|
||||
CONFIG = {
|
||||
'xrt==1.15.0': _VersionConfig('1.15', '1.15.0'),
|
||||
'torch_xla==nightly': _VersionConfig('nightly', 'XRT-dev{}'.format(
|
||||
(datetime.today() - timedelta(1)).strftime('%Y%m%d'))),
|
||||
}[VERSION]
|
||||
DIST_BUCKET = 'gs://tpu-pytorch/wheels'
|
||||
TORCH_WHEEL = 'torch-{}-cp36-cp36m-linux_x86_64.whl'.format(CONFIG.wheels)
|
||||
TORCH_XLA_WHEEL = 'torch_xla-{}-cp36-cp36m-linux_x86_64.whl'.format(CONFIG.wheels)
|
||||
TORCHVISION_WHEEL = 'torchvision-{}-cp36-cp36m-linux_x86_64.whl'.format(CONFIG.wheels)
|
||||
|
||||
# Update TPU XRT version
|
||||
def update_server_xrt():
|
||||
print('Updating server-side XRT to {} ...'.format(CONFIG.server))
|
||||
url = 'http://{TPU_ADDRESS}:8475/requestversion/{XRT_VERSION}'.format(
|
||||
TPU_ADDRESS=os.environ['COLAB_TPU_ADDR'].split(':')[0],
|
||||
XRT_VERSION=CONFIG.server,
|
||||
)
|
||||
print('Done updating server-side XRT: {}'.format(requests.post(url)))
|
||||
# Update TPU XRT version
|
||||
def update_server_xrt():
|
||||
print('Updating server-side XRT to {} ...'.format(CONFIG.server))
|
||||
url = 'http://{TPU_ADDRESS}:8475/requestversion/{XRT_VERSION}'.format(
|
||||
TPU_ADDRESS=os.environ['COLAB_TPU_ADDR'].split(':')[0],
|
||||
XRT_VERSION=CONFIG.server,
|
||||
)
|
||||
print('Done updating server-side XRT: {}'.format(requests.post(url)))
|
||||
|
||||
update = threading.Thread(target=update_server_xrt)
|
||||
update.start()
|
||||
update = threading.Thread(target=update_server_xrt)
|
||||
update.start()
|
||||
|
||||
# Install Colab TPU compat PyTorch/TPU wheels and dependencies
|
||||
!pip uninstall -y torch torchvision
|
||||
!gsutil cp "$DIST_BUCKET/$TORCH_WHEEL" .
|
||||
!gsutil cp "$DIST_BUCKET/$TORCH_XLA_WHEEL" .
|
||||
!gsutil cp "$DIST_BUCKET/$TORCHVISION_WHEEL" .
|
||||
!pip install "$TORCH_WHEEL"
|
||||
!pip install "$TORCH_XLA_WHEEL"
|
||||
!pip install "$TORCHVISION_WHEEL"
|
||||
!sudo apt-get install libomp5
|
||||
update.join()
|
||||
.. code-block::
|
||||
|
||||
5. Once the above is done, install PyTorch Lightning (v 0.7.0+).
|
||||
# Install Colab TPU compat PyTorch/TPU wheels and dependencies
|
||||
!pip uninstall -y torch torchvision
|
||||
!gsutil cp "$DIST_BUCKET/$TORCH_WHEEL" .
|
||||
!gsutil cp "$DIST_BUCKET/$TORCH_XLA_WHEEL" .
|
||||
!gsutil cp "$DIST_BUCKET/$TORCHVISION_WHEEL" .
|
||||
!pip install "$TORCH_WHEEL"
|
||||
!pip install "$TORCH_XLA_WHEEL"
|
||||
!pip install "$TORCHVISION_WHEEL"
|
||||
!sudo apt-get install libomp5
|
||||
update.join()
|
||||
|
||||
.. code-block::
|
||||
5. Once the above is done, install PyTorch Lightning (v 0.7.0+).
|
||||
|
||||
! pip install pytorch-lightning
|
||||
.. code-block::
|
||||
|
||||
!pip install pytorch-lightning
|
||||
|
||||
6. Then set up your LightningModule as normal.
|
||||
|
||||
@@ -147,8 +148,8 @@ for TPU use
|
||||
|
||||
return loader
|
||||
|
||||
8. Configure the number of TPU cores in the trainer. You can only choose
|
||||
1 or 8. To use a full TPU pod skip to the TPU pod section.
|
||||
Configure the number of TPU cores in the trainer. You can only choose 1 or 8.
|
||||
To use a full TPU pod skip to the TPU pod section.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Accumulate gradients
|
||||
Accumulated gradients runs K small batches of size N before doing a backwards pass.
|
||||
The effect is a large effective batch size of size KxN.
|
||||
|
||||
.. seealso:: :ref:`trainer`
|
||||
.. seealso:: :class:`~pytorch_lightning.trainer.trainer.Trainer`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -20,7 +20,7 @@ Gradient Clipping
|
||||
Gradient clipping may be enabled to avoid exploding gradients. Specifically, this will `clip the gradient
|
||||
norm <https://pytorch.org/docs/stable/nn.html#torch.nn.utils.clip_grad_norm_>`_ computed over all model parameters together.
|
||||
|
||||
.. seealso:: :ref:`trainer`
|
||||
.. seealso:: :class:`~pytorch_lightning.trainer.trainer.Trainer`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
From PyTorch to Lightning
|
||||
=========================
|
||||
|
||||
Talk about how to convert
|
||||
Reference in New Issue
Block a user