Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop Refactor 5/N - Prediction Loop #7700

Merged
merged 616 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 190 commits
Commits
Show all changes
616 commits
Select commit Hold shift + click to select a range
42210fc
Minor changes
carmocca Jun 7, 2021
e76010a
Refactor loop logic into logger connector
carmocca Jun 7, 2021
305e31b
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
carmocca Jun 7, 2021
e761890
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 7, 2021
fa9ff73
Refactor test
carmocca Jun 7, 2021
a1f839f
Tighter fx validator
carmocca Jun 7, 2021
a587879
Add back split idx
carmocca Jun 7, 2021
631da98
Typing
carmocca Jun 7, 2021
e098631
update
tchaton Jun 7, 2021
2f13234
Conflict
carmocca Jun 7, 2021
502dcbd
Fix tests
carmocca Jun 7, 2021
c716736
resolve grad_norm
tchaton Jun 7, 2021
26f5e03
update
tchaton Jun 7, 2021
89aaaa2
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
tchaton Jun 7, 2021
badd645
move to train loop
tchaton Jun 7, 2021
aac11a0
Bye grad_norm_dict parameter
carmocca Jun 7, 2021
919cbfb
Fix sync test
carmocca Jun 7, 2021
1c75341
update
tchaton Jun 7, 2021
b00e4a5
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
tchaton Jun 7, 2021
23a7510
Fix bug when validation is run mid epoch
carmocca Jun 7, 2021
9df0da2
fix grad_norm_dict test
carmocca Jun 7, 2021
0485a98
Fix fx_validator test
carmocca Jun 7, 2021
e0702aa
fix grad_norm_dict test
carmocca Jun 7, 2021
32ca719
Fix order bug
carmocca Jun 7, 2021
c68825c
Detach tensors in test
carmocca Jun 7, 2021
37ed74d
resolve some tests
tchaton Jun 7, 2021
39829b5
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
tchaton Jun 7, 2021
cabd48b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 7, 2021
bc106c3
remove pdb
tchaton Jun 7, 2021
e048417
merge
tchaton Jun 7, 2021
98298e1
resolve flake8
tchaton Jun 7, 2021
d8da3cd
Update test
carmocca Jun 7, 2021
49558bf
more tests
tchaton Jun 7, 2021
bae75e9
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
tchaton Jun 7, 2021
0fe870a
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
carmocca Jun 7, 2021
f27d0a3
Revert last thomas' changes
carmocca Jun 7, 2021
f4444c4
resolve 1 test
tchaton Jun 7, 2021
fa4bcec
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
tchaton Jun 7, 2021
d144771
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 7, 2021
ffff6f4
Refactor context restoration
carmocca Jun 7, 2021
43e8873
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 7, 2021
54b6c88
integrate latest changes from logger connector refactor poc
awaelchli Jun 7, 2021
b7edf27
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 7, 2021
766ad99
integrate latest changes from logger connector refactor poc
awaelchli Jun 7, 2021
515ad9f
Minor changes
carmocca Jun 7, 2021
7df8ddb
update changelog
awaelchli Jun 7, 2021
0aa8428
Remove unused argument
carmocca Jun 7, 2021
24b41e3
Update CHANGELOG
carmocca Jun 7, 2021
6d71e6a
Copy call_hook changes
carmocca Jun 7, 2021
44ad4ac
Docs
carmocca Jun 7, 2021
2c74018
Fix ref
carmocca Jun 7, 2021
b15984b
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 7, 2021
e8021bb
merge
tchaton Jun 8, 2021
9747023
move to cpu
tchaton Jun 8, 2021
d9ae37a
Bad merge
carmocca Jun 8, 2021
bad51c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2021
273bc92
remove pdb
tchaton Jun 8, 2021
f214632
remove pdb
tchaton Jun 8, 2021
5fdf3c5
merge
tchaton Jun 8, 2021
99543a7
Refactor to
carmocca Jun 8, 2021
738c810
Avoid partial
carmocca Jun 8, 2021
6a7637d
trigger ci
carmocca Jun 8, 2021
8077cf9
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 8, 2021
aff9e3d
Bad merge
carmocca Jun 8, 2021
c55267d
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 8, 2021
33a7d5a
integrate latest logger connector changes
awaelchli Jun 8, 2021
0e59b09
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2021
d63f6bb
remove grad norm dicts list
awaelchli Jun 8, 2021
0fd3eee
Merge remote-tracking branch 'origin/refactor/loops_everywhere' into …
awaelchli Jun 8, 2021
e75a958
Diff
carmocca Jun 8, 2021
cb076d0
properties first
awaelchli Jun 8, 2021
007dcac
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 8, 2021
2e4bb24
Bad merge
carmocca Jun 8, 2021
f5154ae
Reuse metrics_to_scalars
carmocca Jun 8, 2021
558cdf4
Use active loop
carmocca Jun 8, 2021
90d71bf
Move to device
carmocca Jun 8, 2021
d7f1761
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 8, 2021
6ce6762
resolve test
tchaton Jun 8, 2021
08e103e
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 8, 2021
e1d30d6
integrate latest changes from logger connector poc
awaelchli Jun 8, 2021
fd967af
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 8, 2021
ec0a7a2
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 8, 2021
05eddd0
define union
awaelchli Jun 8, 2021
79c73b9
define union
awaelchli Jun 8, 2021
37a0b9d
Update logger connector
carmocca Jun 8, 2021
aaea387
Update result
carmocca Jun 8, 2021
e2f69ce
Update imports
carmocca Jun 8, 2021
6037833
Update after rename
carmocca Jun 8, 2021
3804963
Merge branch 'refactor/logger-connector-poc' of https://github.com/Py…
carmocca Jun 8, 2021
499da76
Refactor reduce_fx and op
carmocca Jun 8, 2021
6eb448a
Fix test after rename
carmocca Jun 8, 2021
f871cbd
mypy
carmocca Jun 8, 2021
a32f8ea
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 8, 2021
3b63f44
integrate latest logger connector refactor poc changes
awaelchli Jun 9, 2021
7b6803a
Fix test
carmocca Jun 9, 2021
9bfedc9
Refactor test
carmocca Jun 9, 2021
c9c7829
Deprecate `self.log(sync_dist_op)` in favor of `self.log(reduce_fx)`
carmocca Jun 9, 2021
e3dde0b
Undo field
carmocca Jun 9, 2021
9891f8f
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 9, 2021
21e7637
add redundant return
awaelchli Jun 9, 2021
54183e5
rename
awaelchli Jun 9, 2021
b562550
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 9, 2021
e374fe4
rename
awaelchli Jun 9, 2021
e1d4fd2
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 9, 2021
a7c3555
Replace code
carmocca Jun 9, 2021
501224d
Fix names and imports
carmocca Jun 9, 2021
dee7e5f
Remove metric_attribute
carmocca Jun 9, 2021
7628326
imports
awaelchli Jun 9, 2021
c20de54
loop hygiene
awaelchli Jun 9, 2021
0477437
yapf on loops
awaelchli Jun 9, 2021
b8c8cdd
protected new loop trigger
awaelchli Jun 9, 2021
ec4cb49
rename NEW LOOP guard
awaelchli Jun 9, 2021
4627984
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 9, 2021
d254b38
integrate latest logger connector changes
awaelchli Jun 9, 2021
75848b2
integrate latest logger connector changes (eval loop)
awaelchli Jun 9, 2021
deb4790
resolve todo dataloading reset
awaelchli Jun 10, 2021
2b183e6
re-add notebooks
awaelchli Jun 10, 2021
b071532
Merge branch 'master' into refactor/logger-connector-poc
awaelchli Jun 10, 2021
53deef8
add missing init
awaelchli Jun 10, 2021
dcac700
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 10, 2021
93fd682
bad merge
awaelchli Jun 10, 2021
0baee04
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 10, 2021
4950821
Merge branch 'master' into refactor/logger-connector-poc
carmocca Jun 10, 2021
ecac33b
remove NEW_LOOP guard
awaelchli Jun 10, 2021
32cfcb9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2021
4c55ab5
Merge branch 'refactor/logger-connector-poc' into refactor/loops/loop…
awaelchli Jun 10, 2021
5e99672
flake8
awaelchli Jun 10, 2021
4701e85
exclude coverage
awaelchli Jun 10, 2021
2b6cc28
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 10, 2021
d06a8e8
integrate #7917, remove teardown from training loop
awaelchli Jun 10, 2021
e7b4174
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2021
f3e55c0
update "accumulated_batches_reached" condition
awaelchli Jun 11, 2021
ef63f1f
remove public loop properties
awaelchli Jun 11, 2021
7de848d
make skip backward protected again
awaelchli Jun 11, 2021
7a36e28
typing base loop
justusschock Jun 11, 2021
ece57fd
typing fit loop
justusschock Jun 11, 2021
a28d62d
typing training_batch_loop
justusschock Jun 11, 2021
5bb3e04
typing evaluation loop
justusschock Jun 11, 2021
21fd993
typing prediction loop
justusschock Jun 11, 2021
6824814
typing training epoch loop
justusschock Jun 11, 2021
d84e57a
dataloader_loop
justusschock Jun 11, 2021
812661c
evaluation_dataloader_loop
justusschock Jun 11, 2021
61f8495
prediction_dataloader_loop
justusschock Jun 11, 2021
f1e537a
merge
justusschock Jun 11, 2021
b447a6b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 11, 2021
7851e26
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 11, 2021
65d85a3
integrate train loop changes from master
awaelchli Jun 11, 2021
9194d99
integrate eval loop changes from master
awaelchli Jun 11, 2021
6713126
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 11, 2021
8b905db
fix tpipes moving model to cpu and leaving it there.
awaelchli Jun 12, 2021
e5eac72
don't reset fit loop
awaelchli Jun 12, 2021
7a377be
fix test iteration count <-> batch_idx reset
awaelchli Jun 14, 2021
ccafaa9
replace torch.Tensor -> Tensor
awaelchli Jun 14, 2021
50f8bb8
fix attribute error to block_ddp_sync_behaviour
awaelchli Jun 14, 2021
a864a25
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 14, 2021
3ff21b5
fix flake8 and yapf conflict
awaelchli Jun 14, 2021
36f4fae
remove redundant override
awaelchli Jun 14, 2021
11bbbf6
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 15, 2021
d1ab532
add classes
awaelchli Jun 15, 2021
781f26b
trainer changes
awaelchli Jun 15, 2021
7c0f96e
connect
awaelchli Jun 15, 2021
4533b2c
clean up
awaelchli Jun 15, 2021
ea48342
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2021
9a3a908
update test renaming
awaelchli Jun 15, 2021
a7d2d86
Merge remote-tracking branch 'origin/refactor/loops/loops_everywhere_…
awaelchli Jun 15, 2021
d711a49
rename evaluation loop to evaluation epoch loop
awaelchli Jun 15, 2021
e592423
minor docstring improvements
awaelchli Jun 15, 2021
e3c0512
update chlog
awaelchli Jun 15, 2021
9044c19
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2021
c5c02ec
try ci fix
awaelchli Jun 15, 2021
cc4c57c
Merge remote-tracking branch 'origin/refactor/loops/loops_everywhere_…
awaelchli Jun 15, 2021
6d8af9f
Merge branch 'master' into refactor/loops/loops_everywhere_eval
awaelchli Jun 16, 2021
7e030e5
update code owners for pl/loops
awaelchli Jun 16, 2021
d174d04
update mock path
awaelchli Jun 16, 2021
d135da8
re-order
awaelchli Jun 16, 2021
ed6352c
simplify dataloader reset
awaelchli Jun 16, 2021
0fb4e90
simplify get_dataloaders()
awaelchli Jun 16, 2021
ca73fc4
save predictions on_run_end()
awaelchli Jun 16, 2021
a6b9798
improve skip condition re-routing
awaelchli Jun 17, 2021
4ff7084
re-order
awaelchli Jun 17, 2021
0ecbd55
Merge branch 'master' into refactor/loops/loops_everywhere_eval
awaelchli Jun 17, 2021
cab35a6
remove unused type import
awaelchli Jun 17, 2021
b7483b4
check which assert is failing
awaelchli Jun 17, 2021
33d89e0
pig
awaelchli Jun 17, 2021
e81b0db
hobbit
awaelchli Jun 17, 2021
cfbdc8b
teardown for evaluation
awaelchli Jun 17, 2021
7f70bfa
Revert "hobbit"
awaelchli Jun 17, 2021
f700ab4
Revert "pig"
awaelchli Jun 17, 2021
4f88695
Revert "check which assert is failing"
awaelchli Jun 17, 2021
9769e5a
free memory in fit loop teardown
awaelchli Jun 17, 2021
71c1f6e
update docstring
awaelchli Jun 17, 2021
a6229f5
period
awaelchli Jun 17, 2021
aa27b9f
remove dead code
awaelchli Jun 17, 2021
e082524
else carlos
awaelchli Jun 17, 2021
ea8fcf4
Update pytorch_lightning/loops/dataloader/evaluation_dataloader_loop.py
awaelchli Jun 17, 2021
4650461
Merge remote-tracking branch 'origin/refactor/loops/loops_everywhere_…
awaelchli Jun 17, 2021
424a1a6
update chlog
awaelchli Jun 18, 2021
0e110b6
unused imp
awaelchli Jun 18, 2021
8fd15c6
move default construction in run_evaluation
awaelchli Jun 18, 2021
61b3837
add something for lawyer to read
awaelchli Jun 18, 2021
07d605e
switch typehint for eval loop trainer property
awaelchli Jun 18, 2021
c5a2511
add missing imports
awaelchli Jun 18, 2021
0f4d536
remove a todo that needs more discussion
awaelchli Jun 18, 2021
9db3ddc
combine _get_num_dataloaders with the property
awaelchli Jun 18, 2021
90da366
Update pytorch_lightning/loops/dataloader/dataloader_loop.py
awaelchli Jun 18, 2021
891a429
Merge remote-tracking branch 'origin/refactor/loops/loops_everywhere_…
awaelchli Jun 18, 2021
e583d6e
black + yapf
awaelchli Jun 18, 2021
c7579ab
avoid coverage on old unused eval loop
awaelchli Jun 18, 2021
7f785f4
empty space in docstring
awaelchli Jun 18, 2021
89ba6fc
resolve todo for args forwarding
awaelchli Jun 18, 2021
f34b68f
Merge branch 'refactor/loops/loops_everywhere_eval' into refactor/loo…
awaelchli Jun 18, 2021
d4e6969
weekproxy trainer
awaelchli Jun 18, 2021
e95f36d
fix check for num dataloaders kwargs
awaelchli Jun 18, 2021
deb5bb2
clean up num prediction dataloaders property
awaelchli Jun 18, 2021
e806bfc
free memory
awaelchli Jun 18, 2021
ceb7d3f
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 18, 2021
90e4f9a
rm notebooks folder
awaelchli Jun 18, 2021
238b830
rm old file
awaelchli Jun 18, 2021
c6c580a
revert changes to old eval loop
awaelchli Jun 18, 2021
f4e13f3
bad merge
awaelchli Jun 18, 2021
46dba5a
undo teardown
awaelchli Jun 18, 2021
e7f42d8
setup signature
awaelchli Jun 18, 2021
0b8e0cf
remove file for notes
awaelchli Jun 18, 2021
be8e303
free memory
awaelchli Jun 18, 2021
e061bad
chlog
awaelchli Jun 18, 2021
ce1d1e7
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 21, 2021
4910b61
Revert "weekproxy trainer"
awaelchli Jun 18, 2021
d472357
connect trainer
awaelchli Jun 21, 2021
27914dc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2021
49d2ada
clean up max batches and dataloaders
awaelchli Jun 21, 2021
126b136
max batches handling
awaelchli Jun 21, 2021
1f34677
no grad handling
awaelchli Jun 21, 2021
45b1f4a
Merge remote-tracking branch 'origin/refactor/loops_everywhere' into …
awaelchli Jun 21, 2021
f219fdb
unused argument
awaelchli Jun 21, 2021
e0463eb
protected attrs
awaelchli Jun 21, 2021
06dcd39
unused imports
awaelchli Jun 21, 2021
d7d88e7
undo unintentional rename
awaelchli Jun 21, 2021
9094ae4
consistent naming
awaelchli Jun 21, 2021
0d47b93
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 22, 2021
9f26850
capitalization in docstring
awaelchli Jun 22, 2021
6f06f3b
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 22, 2021
2790175
Merge branch 'master' into refactor/loops/loops_everywhere
awaelchli Jun 22, 2021
2639c78
list all args
awaelchli Jun 22, 2021
3a094de
Update pytorch_lightning/loops/prediction_epoch_loop.py
awaelchli Jun 22, 2021
dddfe80
Update pytorch_lightning/loops/prediction_epoch_loop.py
awaelchli Jun 22, 2021
36faf76
Update pytorch_lightning/loops/dataloader/prediction_dataloader_loop.py
awaelchli Jun 22, 2021
286982b
Update pytorch_lightning/loops/dataloader/prediction_dataloader_loop.py
awaelchli Jun 22, 2021
935dea2
Update pytorch_lightning/loops/prediction_epoch_loop.py
awaelchli Jun 23, 2021
e707aff
Merge branch 'master' into refactor/loops_everywhere
justusschock Jun 23, 2021
5ca00bd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
* Moved attributes `hiddens` and `split_idx` to TrainLoop ([#7507](https://github.com/PyTorchLightning/pytorch-lightning/pull/7507))
* Refactored the logic around manual and automatic optimization inside the optimizer loop ([#7526](https://github.com/PyTorchLightning/pytorch-lightning/pull/7526))
* Simplified "should run validation" logic ([#7682](https://github.com/PyTorchLightning/pytorch-lightning/pull/7682))
* Refactored "should run validation" logic when the trainer is signaled to stop ([#7701](https://github.com/PyTorchLightning/pytorch-lightning/pull/7701))
* Simplified logic for updating the learning rate for schedulers ([#7682](https://github.com/PyTorchLightning/pytorch-lightning/pull/7682))
* Removed the `on_epoch` guard from the "should stop" validation check ([#7701](https://github.com/PyTorchLightning/pytorch-lightning/pull/7701))
...
* Refactored internal loop interface; added new classes `EpochLoop`, `TrainingLoop`, `BatchLoop` ([#7700](https://github.com/PyTorchLightning/pytorch-lightning/pull/7700))


- Refactored logging
Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/callbacks/prediction_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def on_predict_batch_end(
if not self.interval.on_batch:
return
is_distributed = trainer.accelerator_connector.is_distributed
batch_indices = trainer.predict_loop.batch_indices if is_distributed else None
batch_indices = trainer.predict_loop.prediction_loop.current_batch_indices if is_distributed else None
awaelchli marked this conversation as resolved.
Show resolved Hide resolved
self.write_on_batch_end(trainer, pl_module, outputs, batch_indices, batch, batch_idx, dataloader_idx)

def on_predict_epoch_end(
Expand Down
4 changes: 2 additions & 2 deletions pytorch_lightning/callbacks/stochastic_weight_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ def on_train_epoch_start(self, trainer: 'pl.Trainer', pl_module: 'pl.LightningMo
# performing only one pass over the train data-loader to compute activation statistics
# Therefore, we will virtually increase `num_training_batches` by 1 and skip backward.
trainer.num_training_batches += 1
trainer.train_loop._skip_backward = True
trainer.train_loop.skip_backward = True
self._accumulate_grad_batches = trainer.accumulate_grad_batches
trainer.accumulate_grad_batches = len(trainer.train_dataloader)

def on_train_epoch_end(self, trainer: 'pl.Trainer', *args):
trainer.train_loop._skip_backward = False
trainer.train_loop.skip_backward = False

def on_train_end(self, trainer: 'pl.Trainer', pl_module: 'pl.LightningModule'):
if self._model_contains_batch_norm and trainer.current_epoch == self.swa_end + 1:
Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/core/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ def training_step(...):

# backward
self._running_manual_backward = True
self.trainer.train_loop.backward(loss, optimizer=None, opt_idx=None, *args, **kwargs)
self.trainer.batch_loop.backward(loss, optimizer=None, opt_idx=None, *args, **kwargs)
self._running_manual_backward = False

def backward(self, loss: Tensor, optimizer: Optimizer, optimizer_idx: int, *args, **kwargs) -> None:
Expand Down
Empty file.
59 changes: 59 additions & 0 deletions pytorch_lightning/loops/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from abc import ABC, abstractmethod
from typing import Any, Optional
from weakref import proxy

import pytorch_lightning as pl


class Loop(ABC):

def __init__(self):
self.iteration_count: int = 0
self.trainer: Optional['pl.Trainer'] = None

def connect(self, trainer, *args, **kwargs) -> None:
"""Connects Loop with all the necessary things like connectors and accelerators"""
self.trainer = proxy(trainer)

@property
@abstractmethod
def done(self) -> bool:
"""Property indicating when loop is finished"""

@abstractmethod
def reset(self) -> None:
pass

def run(self, *args: Any, **kwargs: Any) -> Any:
self.reset()
self.on_run_start(*args, **kwargs)

while not self.done:
try:
self.on_advance_start(*args, **kwargs)
self.advance(*args, **kwargs)
self.on_advance_end()
self.iteration_count = self.increment_iteration(self.iteration_count)
except StopIteration:
break

return self.on_run_end()

def on_run_start(self, *args: Any, **kwargs: Any) -> None:
pass

def on_advance_start(self, *args: Any, **kwargs: Any) -> None:
pass

@abstractmethod
def advance(self, *args: Any, **kwargs: Any) -> None:
"""What to do within a single step"""

def on_advance_end(self) -> None:
pass

def on_run_end(self) -> Any:
pass

def increment_iteration(self, iteration: int) -> int:
return iteration + 1
Loading