Skip to content

Commit 381e526

Browse files
authored
Merge branch 'master' into feat/enable_auto_tying__for_tpus
2 parents 82bf7d3 + b054d21 commit 381e526

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+246
-303
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
163163
- Added `pl_legacy_patch` load utility for loading old checkpoints that have pickled legacy Lightning attributes ([#9166](https://github.com/PyTorchLightning/pytorch-lightning/pull/9166))
164164

165165

166+
- Added support for `torch.use_deterministic_algorithms` ([#9121](https://github.com/PyTorchLightning/pytorch-lightning/pull/9121))
167+
168+
166169
- Enabled auto parameters tying for TPUs ([#9525](https://github.com/PyTorchLightning/pytorch-lightning/pull/9525))
167170

168171

@@ -228,9 +231,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
228231
- Executing the `optimizer_closure` is now required when overriding the `optimizer_step` hook ([#9360](https://github.com/PyTorchLightning/pytorch-lightning/pull/9360))
229232

230233

231-
- Removed `TrainerProperties` mixin and moved property definitions directly into `Trainer` ([#9495](https://github.com/PyTorchLightning/pytorch-lightning/pull/9495))
232-
233-
234234
- Changed logging of `LightningModule` and `LightningDataModule` hyperparameters to raise an exception only if there are colliding keys with different values ([#9496](https://github.com/PyTorchLightning/pytorch-lightning/pull/9496))
235235

236236

@@ -349,6 +349,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
349349
- Removed `TrainingTypePlugin.on_save` and `Accelerator.on_save` ([#9023](https://github.com/PyTorchLightning/pytorch-lightning/pull/9023))
350350

351351

352+
- Removed `{Accelerator,TrainingTypePlugin,PrecisionPlugin}.post_optimizer_step` ([#9746](https://github.com/PyTorchLightning/pytorch-lightning/pull/9746))
353+
354+
352355
- Removed deprecated `connect_precision_plugin` and `connect_training_type_plugin` from `Accelerator` ([#9019](https://github.com/PyTorchLightning/pytorch-lightning/pull/9019))
353356

354357

@@ -397,6 +400,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
397400
- Removed `call_configure_sharded_model_hook` property from `Accelerator` and `TrainingTypePlugin` ([#9612](https://github.com/PyTorchLightning/pytorch-lightning/pull/9612))
398401

399402

403+
- Removed `TrainerProperties` mixin and moved property definitions directly into `Trainer` ([#9495](https://github.com/PyTorchLightning/pytorch-lightning/pull/9495))
404+
405+
400406
### Fixed
401407

402408

benchmarks/test_basic_parity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def vanilla_loop(cls_model, idx, device_type: str = "cuda", num_epochs=10):
151151

152152
def lightning_loop(cls_model, idx, device_type: str = "cuda", num_epochs=10):
153153
seed_everything(idx)
154+
torch.backends.cudnn.deterministic = True
154155

155156
model = cls_model()
156157
# init model parts
@@ -161,7 +162,6 @@ def lightning_loop(cls_model, idx, device_type: str = "cuda", num_epochs=10):
161162
weights_summary=None,
162163
gpus=1 if device_type == "cuda" else 0,
163164
checkpoint_callback=False,
164-
deterministic=True,
165165
logger=False,
166166
replace_sampler_ddp=False,
167167
)

docs/source/advanced/mixed_precision.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Since computation happens in FP16, there is a chance of numerical instability. T
3030
When using TPUs, setting ``precision=16`` will enable bfloat16 which is the only supported precision type on TPUs.
3131

3232
.. testcode::
33-
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE or not torch.cuda.is_available()
33+
:skipif: not torch.cuda.is_available()
3434

3535
Trainer(gpus=1, precision=16)
3636

@@ -71,13 +71,13 @@ NVIDIA APEX Mixed Precision
7171
`NVIDIA APEX <https://github.com/NVIDIA/apex>`__ offers some additional flexibility in setting mixed precision. This can be useful for when wanting to try out different precision configurations, such as keeping most of your weights in FP16 as well as running computation in FP16.
7272

7373
.. testcode::
74-
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE or not torch.cuda.is_available()
74+
:skipif: not _APEX_AVAILABLE or not torch.cuda.is_available()
7575

7676
Trainer(gpus=1, amp_backend="apex")
7777

7878
Set the `NVIDIA optimization level <https://nvidia.github.io/apex/amp.html#opt-levels>`__ via the trainer.
7979

8080
.. testcode::
81-
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE or not torch.cuda.is_available()
81+
:skipif: not _APEX_AVAILABLE or not torch.cuda.is_available()
8282

8383
Trainer(gpus=1, amp_backend="apex", amp_level="O2")

docs/source/common/trainer.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ Lightning supports either double precision (64), full precision (32), or half pr
11721172
Half precision, or mixed precision, is the combined use of 32 and 16 bit floating points to reduce memory footprint during model training. This can result in improved performance, achieving +3X speedups on modern GPUs.
11731173

11741174
.. testcode::
1175-
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE or not torch.cuda.is_available()
1175+
:skipif: not torch.cuda.is_available()
11761176

11771177
# default used by the Trainer
11781178
trainer = Trainer(precision=32, gpus=1)
@@ -1221,7 +1221,7 @@ Half precision, or mixed precision, is the combined use of 32 and 16 bit floatin
12211221
2. Set the `precision` trainer flag to 16. You can customize the `Apex optimization level <https://nvidia.github.io/apex/amp.html#opt-levels>`_ by setting the `amp_level` flag.
12221222

12231223
.. testcode::
1224-
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE or not torch.cuda.is_available()
1224+
:skipif: not _APEX_AVAILABLE or not torch.cuda.is_available()
12251225

12261226
# turn on 16-bit
12271227
trainer = Trainer(amp_backend="apex", amp_level="O2", precision=16)

docs/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ def package_list_from_file(file):
369369
import pytorch_lightning as pl
370370
from pytorch_lightning import LightningDataModule, LightningModule, Trainer
371371
from pytorch_lightning.utilities import (
372-
_NATIVE_AMP_AVAILABLE,
373372
_APEX_AVAILABLE,
374373
_XLA_AVAILABLE,
375374
_TPU_AVAILABLE,

docs/source/guides/speed.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Lightning offers mixed precision training for GPUs and CPUs, as well as bfloat16
214214

215215

216216
.. testcode::
217-
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE or not torch.cuda.is_available()
217+
:skipif: torch.cuda.device_count() < 4
218218

219219
# 16-bit precision
220220
trainer = Trainer(precision=16, gpus=4)

pytorch_lightning/accelerators/accelerator.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import torch
1818
from torch import Tensor
19+
from torch.cuda.amp import GradScaler
1920
from torch.nn import Module
2021
from torch.optim import Optimizer
2122
from torch.utils.data import DataLoader
@@ -24,14 +25,11 @@
2425
from pytorch_lightning.plugins.precision import ApexMixedPrecisionPlugin, NativeMixedPrecisionPlugin, PrecisionPlugin
2526
from pytorch_lightning.plugins.training_type import DataParallelPlugin, TrainingTypePlugin
2627
from pytorch_lightning.trainer.states import TrainerFn
27-
from pytorch_lightning.utilities import _NATIVE_AMP_AVAILABLE, rank_zero_deprecation
28+
from pytorch_lightning.utilities import rank_zero_deprecation
2829
from pytorch_lightning.utilities.apply_func import apply_to_collection, move_data_to_device
2930
from pytorch_lightning.utilities.enums import AMPType, GradClipAlgorithmType, LightningEnum
3031
from pytorch_lightning.utilities.types import _PATH, STEP_OUTPUT
3132

32-
if _NATIVE_AMP_AVAILABLE:
33-
from torch.cuda.amp import GradScaler
34-
3533

3634
class Accelerator:
3735
"""The Accelerator Base Class. An Accelerator is meant to deal with one type of Hardware.
@@ -258,8 +256,6 @@ def optimizer_step(self, optimizer: Optimizer, opt_idx: int, lambda_closure: Cal
258256
)
259257
if make_optimizer_step:
260258
self.run_optimizer_step(optimizer, opt_idx, lambda_closure, **kwargs)
261-
self.precision_plugin.post_optimizer_step(optimizer, opt_idx)
262-
self.training_type_plugin.post_optimizer_step(optimizer, opt_idx, **kwargs)
263259

264260
def run_optimizer_step(
265261
self, optimizer: Optimizer, optimizer_idx: int, lambda_closure: Callable, **kwargs: Any

pytorch_lightning/callbacks/progress/rich_progress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def __init__(
209209
) -> None:
210210
if not _RICH_AVAILABLE:
211211
raise ImportError(
212-
"`RichProgressBar` requires `rich` to be installed. Install it by running `pip install rich`."
212+
"`RichProgressBar` requires `rich` to be installed. Install it by running `pip install -U rich`."
213213
)
214214
super().__init__()
215215
self._refresh_rate_per_second: int = refresh_rate_per_second

pytorch_lightning/callbacks/rich_model_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class RichModelSummary(ModelSummary):
6161
def __init__(self, max_depth: int = 1) -> None:
6262
if not _RICH_AVAILABLE:
6363
raise ImportError(
64-
"`RichModelSummary` requires `rich` to be installed. Install it by running `pip install rich`."
64+
"`RichProgressBar` requires `rich` to be installed. Install it by running `pip install -U rich`."
6565
)
6666
super().__init__(max_depth)
6767

pytorch_lightning/loops/optimization/optimizer_loop.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ def _run_optimization_end(self, opt_idx: int) -> None:
371371
model.untoggle_optimizer(opt_idx)
372372

373373
def _optimizer_step(
374-
self, optimizer: torch.optim.Optimizer, opt_idx: int, batch_idx: int, train_step_and_backward_closure: Callable
374+
self,
375+
optimizer: Optimizer,
376+
opt_idx: int,
377+
batch_idx: int,
378+
train_step_and_backward_closure: Callable[[], Optional[Tensor]],
375379
) -> None:
376380
"""Performs the optimizer step and some sanity checking.
377381
@@ -385,15 +389,6 @@ def _optimizer_step(
385389
lightning_module = self.trainer.lightning_module
386390

387391
is_lbfgs = isinstance(optimizer, torch.optim.LBFGS)
388-
using_native_amp = self.trainer.amp_backend is not None and self.trainer.amp_backend == AMPType.NATIVE
389-
390-
# native amp + lbfgs is a no go right now
391-
if using_native_amp and is_lbfgs:
392-
raise MisconfigurationException(
393-
"native PyTorch amp and lbfgs are not compatible."
394-
" To request, please file a Github issue in PyTorch and tag @mcarilli"
395-
)
396-
397392
# wraps into LightningOptimizer only for running step
398393
optimizer = LightningOptimizer._to_lightning_optimizer(optimizer, self.trainer, opt_idx)
399394

@@ -407,7 +402,7 @@ def _optimizer_step(
407402
opt_idx,
408403
train_step_and_backward_closure,
409404
on_tpu=(self.trainer._device_type == DeviceType.TPU and _TPU_AVAILABLE),
410-
using_native_amp=using_native_amp,
405+
using_native_amp=(self.trainer.amp_backend is not None and self.trainer.amp_backend == AMPType.NATIVE),
411406
using_lbfgs=is_lbfgs,
412407
)
413408

0 commit comments

Comments
 (0)