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

Add PyTorch 1.8 Profiler 5/5 #6618

Merged
merged 153 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 142 commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
aa89fa1
Refactor profilers
carmocca Mar 4, 2021
b66f1f6
Update PassThrough
carmocca Mar 5, 2021
d388d80
WIP - This is broken and will change
carmocca Mar 6, 2021
93aa073
Update pytorch_lightning/profiler/pytorch.py
carmocca Mar 9, 2021
0f8b6ef
resolve tests
tchaton Mar 18, 2021
d219ae1
Merge branch 'master' into update-pytorch-profiler
tchaton Mar 18, 2021
8a3d3cf
resolve tests
tchaton Mar 18, 2021
af865ff
find output
tchaton Mar 18, 2021
6147e6e
try something
tchaton Mar 19, 2021
5053b4f
update
tchaton Mar 19, 2021
3ae2fbf
add support for test and predict
tchaton Mar 19, 2021
1d7ac88
update
tchaton Mar 19, 2021
64f8a58
update
tchaton Mar 19, 2021
655ff46
use getattr
tchaton Mar 19, 2021
3f5c4d6
test
tchaton Mar 19, 2021
ced0d66
test
tchaton Mar 19, 2021
662f8de
update
tchaton Mar 19, 2021
753f63b
tests
tchaton Mar 19, 2021
e6a6917
update
tchaton Mar 19, 2021
a7f7f4c
update
tchaton Mar 19, 2021
c221d7d
update
tchaton Mar 19, 2021
e39f6d7
update
tchaton Mar 19, 2021
e485850
update
tchaton Mar 19, 2021
00d355a
remove file
tchaton Mar 19, 2021
61da390
update
tchaton Mar 19, 2021
002f137
Merge branch 'update-pytorch-profiler' of https://github.com/PyTorchL…
tchaton Mar 19, 2021
e565e8a
update
tchaton Mar 19, 2021
6f2258f
update
tchaton Mar 19, 2021
883b242
update
tchaton Mar 21, 2021
9b957bd
update
tchaton Mar 21, 2021
70cc20d
test
tchaton Mar 21, 2021
226e0be
update#
tchaton Mar 21, 2021
27348c7
update
tchaton Mar 21, 2021
853d36c
update tests
tchaton Mar 21, 2021
9004e92
update
tchaton Mar 21, 2021
c35e927
add suport for 1.8
tchaton Mar 21, 2021
1f9d2d9
rename records
tchaton Mar 21, 2021
13caa86
add support for 1.8
tchaton Mar 21, 2021
18c48ce
update
tchaton Mar 21, 2021
a1c37ad
resolve flake8
tchaton Mar 21, 2021
3750b22
resolve test
tchaton Mar 21, 2021
9a87c52
Merge branch 'master' into update-pytorch-profiler
carmocca Mar 22, 2021
fbbb9a2
Refactor basic profilers
carmocca Mar 22, 2021
2a82e05
Fixes
carmocca Mar 22, 2021
ff125e2
Unused import
carmocca Mar 22, 2021
01a760e
Introduce setup
carmocca Mar 22, 2021
b31831e
Profile on all ranks. Print to stdout on 0
carmocca Mar 22, 2021
f8a8772
Introduce dirpath + filename
carmocca Mar 22, 2021
aa4b7dd
CHANGELOG
carmocca Mar 22, 2021
8e3034e
Add tests. Address comments
carmocca Mar 22, 2021
96259a4
Merge branch 'update-pytorch-profiler' into update-pytorch-profiler-1.8
tchaton Mar 22, 2021
e4e0dd6
add `on_run_stage_setup`
tchaton Mar 22, 2021
d0fdbb9
add on_run_stage_setup function
tchaton Mar 22, 2021
1a16bb3
update
tchaton Mar 22, 2021
52fa69b
add test for RegisterRecordFunction
tchaton Mar 22, 2021
63b6988
update lightnng flow direction
tchaton Mar 22, 2021
1cf5a64
move variable to private
tchaton Mar 22, 2021
a05acdd
remove trace
tchaton Mar 22, 2021
af72dff
Merge branch 'master' into refactor-base-profilers
tchaton Mar 22, 2021
59c941b
Undo code that should be in 3/4
carmocca Mar 22, 2021
da0f310
Multi-stage multi-rank
carmocca Mar 22, 2021
59c1b4c
2/5 changes
carmocca Mar 22, 2021
dd1dce0
Pass stage in __del__
carmocca Mar 22, 2021
12d014b
Merge branch 'master' into refactor-base-profilers
carmocca Mar 22, 2021
097a426
Remove TODOs
carmocca Mar 22, 2021
4d529fa
Describe on_evaluation_end. Add tests
carmocca Mar 22, 2021
58dcd4e
Typo
carmocca Mar 22, 2021
c37162f
Address comments
carmocca Mar 22, 2021
4c5f1f3
deepcopy tests
carmocca Mar 22, 2021
5ed73fb
Advanced teardown
carmocca Mar 22, 2021
897f8e5
Fix teardown test
carmocca Mar 22, 2021
e42be2a
Fix tests
carmocca Mar 22, 2021
32c301c
Minor change
carmocca Mar 22, 2021
af0c8ad
Update CHANGELOG.md
carmocca Mar 22, 2021
29a73c5
Fix test
carmocca Mar 22, 2021
d6ede58
Merge branch 'refactor-base-profilers' into update-pytorch-profiler
carmocca Mar 22, 2021
0dc1e06
Quick fixes
carmocca Mar 22, 2021
cb756b8
Fix 6522
carmocca Mar 22, 2021
758b942
resolve ddp tests
tchaton Mar 23, 2021
fca4eb2
resolve tests
tchaton Mar 23, 2021
2919a39
resolve some tests
tchaton Mar 23, 2021
d7ca5fa
update tests
tchaton Mar 23, 2021
34b7991
Merge branch 'refactor-base-profilers' into update-pytorch-profiler
tchaton Mar 23, 2021
b3ffe64
resolve tests
tchaton Mar 23, 2021
e0d8308
Merge branch 'master' into update-pytorch-profiler
tchaton Mar 23, 2021
ecd1fd2
update
tchaton Mar 23, 2021
3a0d821
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
tchaton Mar 23, 2021
c3e52f8
Merge branch 'update-pytorch-profiler' into update-pytorch-profiler-1.8
tchaton Mar 23, 2021
97c87d3
resolve tests
tchaton Mar 23, 2021
172b388
resolve some tests
tchaton Mar 23, 2021
ae31f00
Missed fixes from 3/5
carmocca Mar 23, 2021
78970d5
Fixes
carmocca Mar 23, 2021
7e27a8d
resolve some tests
tchaton Mar 23, 2021
dbd1c7e
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
tchaton Mar 23, 2021
c0107e2
Merge branch 'update-pytorch-profiler' of https://github.com/PyTorchL…
tchaton Mar 23, 2021
87aa09f
resolve test for 1.7.1
tchaton Mar 23, 2021
ba067fd
Broken refactor
carmocca Mar 23, 2021
f916013
Missed stage
carmocca Mar 23, 2021
9a1b1b6
Minor changes
carmocca Mar 23, 2021
04abd0a
resolve tests
tchaton Mar 23, 2021
ab1218e
Merge branch 'update-pytorch-profiler' of https://github.com/PyTorchL…
tchaton Mar 23, 2021
0230330
Update CHANGELOG
carmocca Mar 23, 2021
cba643b
resolve bug
tchaton Mar 23, 2021
85bfc7d
Merge branch 'update-pytorch-profiler' of https://github.com/PyTorchL…
tchaton Mar 23, 2021
af209f5
remove print
tchaton Mar 23, 2021
bb813bb
Typo
carmocca Mar 23, 2021
624a85f
Cleanup
carmocca Mar 23, 2021
1732ece
resolve ddp test
tchaton Mar 23, 2021
f0c1675
remove barrier
tchaton Mar 23, 2021
fbe50b1
update profiler
tchaton Mar 23, 2021
a13664d
Merge branch 'master' into update-pytorch-profiler
tchaton Mar 23, 2021
374f0da
update
tchaton Mar 23, 2021
e3c162e
Merge branch 'master' into update-pytorch-profiler-1.8
tchaton Mar 23, 2021
6e948ca
Smaller model
carmocca Mar 23, 2021
ad55628
update
tchaton Mar 23, 2021
05f68b4
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
tchaton Mar 23, 2021
88c44d6
Merge branch 'update-pytorch-profiler' into update-pytorch-profiler-1.8
tchaton Mar 23, 2021
2b0f92d
resolve tests
tchaton Mar 23, 2021
e46cf1c
update
tchaton Mar 23, 2021
5071947
Merge branch 'master' into update-pytorch-profiler-1.8
tchaton Mar 23, 2021
5b51259
Minor changes. CHANGELOG
carmocca Mar 23, 2021
5aa19ec
Minimize diff
carmocca Mar 23, 2021
efdb20b
update to 1.8.1
tchaton Mar 23, 2021
ea00c36
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
tchaton Mar 23, 2021
79efcb2
RunIf. Extra code. Check segfault
carmocca Mar 23, 2021
5453bbe
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
carmocca Mar 23, 2021
11e3150
resolve tests
tchaton Mar 23, 2021
2cd2be1
Typo. Bad merge
carmocca Mar 23, 2021
6aab082
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
tchaton Mar 23, 2021
7cff95a
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
tchaton Mar 23, 2021
496efab
Fixing a bad merge
carmocca Mar 23, 2021
9ced644
replace for kineto
tchaton Mar 23, 2021
ee85864
Update pytorch_lightning/profiler/pytorch.py
tchaton Mar 23, 2021
efaa459
Update pytorch_lightning/profiler/pytorch.py
tchaton Mar 23, 2021
e73becc
Minor changes
carmocca Mar 23, 2021
2865c96
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
carmocca Mar 23, 2021
92fa085
Bad merge
carmocca Mar 23, 2021
a5093cb
Use lists for flexibility
carmocca Mar 23, 2021
5ccbfd0
Use sets
carmocca Mar 23, 2021
d1c0915
predict_step
carmocca Mar 23, 2021
8098aaf
Ananth's suggestion
carmocca Mar 23, 2021
8b9bbf0
update
tchaton Mar 23, 2021
a74e835
Docs
carmocca Mar 23, 2021
5af66be
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
carmocca Mar 23, 2021
3605b1a
Update pl_examples/basic_examples/profiler_example.py
tchaton Mar 23, 2021
8e93145
update example
tchaton Mar 23, 2021
af5d2ef
update example
tchaton Mar 23, 2021
f30fa58
definition
Borda Mar 23, 2021
9b5f90c
yapf
Borda Mar 23, 2021
92eaf7d
move pm
Borda Mar 23, 2021
8a631e0
typo
Borda Mar 23, 2021
8f95814
update
tchaton Mar 23, 2021
175f285
Merge branch 'update-pytorch-profiler-1.8' of https://github.com/PyTo…
tchaton Mar 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added support for including module names for forward in the autograd trace of `PyTorchProfiler` ([#6349](https://github.com/PyTorchLightning/pytorch-lightning/pull/6349))


- Added support for the PyTorch 1.8.1 autograd profiler ([#6618](https://github.com/PyTorchLightning/pytorch-lightning/pull/6618))


- Added `outputs` parameter to callback's `on_validation_epoch_end` & `on_test_epoch_end` hooks ([#6120](https://github.com/PyTorchLightning/pytorch-lightning/pull/6120))


Expand Down
96 changes: 96 additions & 0 deletions pl_examples/basic_examples/profiler_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This script will generate 2 traces: one for `training_step` and one for `validation_step`.
kaushikb11 marked this conversation as resolved.
Show resolved Hide resolved
The traces can be visualized in 2 ways:
* With Chrome:
1. Open Chrome and copy/paste this url: `chrome://tracing/`.
2. Once tracing opens, click on `Load` at the top-right and load one of the generated traces.
* With PyTorch Tensorboard Profiler (Instructions are here: https://github.com/pytorch/kineto/tree/master/tb_plugin)
1. pip install tensorboard torch-tb-profiler
2. tensorboard --logdir={FOLDER}
"""

import sys
from argparse import ArgumentParser

import torch
import torchvision
import torchvision.models as models
import torchvision.transforms as T

from pl_examples import cli_lightning_logo
from pytorch_lightning import LightningDataModule, LightningModule, Trainer

DEFAULT_CMD_LINE = "--max_epochs 1"
DEFAULT_CMD_LINE += "--limit_train_batches 15"
DEFAULT_CMD_LINE += "--limit_val_batches 15"
DEFAULT_CMD_LINE += "--profiler pytorch"
DEFAULT_CMD_LINE += f"--gpus {torch.cuda.is_available()}"
DEFAULT_CMD_LINE = DEFAULT_CMD_LINE.split(" ")
tchaton marked this conversation as resolved.
Show resolved Hide resolved


class ModelToProfile(LightningModule):

def __init__(self, model):
super().__init__()
self.model = model
self.criterion = torch.nn.CrossEntropyLoss()

def training_step(self, batch, batch_idx):
inputs, labels = batch
outputs = self.model(inputs)
loss = self.criterion(outputs, labels)
self.log("train_loss", loss)
return loss

def validation_step(self, batch, batch_idx):
inputs, labels = batch
outputs = self.model(inputs)
loss = self.criterion(outputs, labels)
self.log("val_loss", loss)

def configure_optimizers(self):
return torch.optim.SGD(self.parameters(), lr=0.001, momentum=0.9)


class CIFAR10DataModule(LightningDataModule):

transform = T.Compose([T.Resize(256), T.CenterCrop(224), T.ToTensor()])

def train_dataloader(self, *args, **kwargs):
trainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=self.transform)
return torch.utils.data.DataLoader(trainset, batch_size=32, shuffle=True, num_workers=0)

def val_dataloader(self, *args, **kwargs):
valset = torchvision.datasets.CIFAR10(root='./data', train=False, download=True, transform=self.transform)
return torch.utils.data.DataLoader(valset, batch_size=32, shuffle=True, num_workers=0)


def cli_main():

parser = ArgumentParser()
parser = Trainer.add_argparse_args(parser)
cmd_line = None if len(sys.argv) != 1 else DEFAULT_CMD_LINE
tchaton marked this conversation as resolved.
Show resolved Hide resolved
args = parser.parse_args(args=cmd_line)

model = ModelToProfile(models.resnet50(pretrained=True))
datamodule = CIFAR10DataModule()
trainer = Trainer(**vars(args))
trainer.fit(model, datamodule=datamodule)


if __name__ == '__main__':
cli_lightning_logo()
cli_main()
4 changes: 2 additions & 2 deletions pytorch_lightning/profiler/profilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ def _rank_zero_info(self, *args, **kwargs) -> None:
if self._local_rank in (None, 0):
log.info(*args, **kwargs)

def _prepare_filename(self) -> str:
def _prepare_filename(self, extension: str = ".txt") -> str:
filename = ""
if self._stage is not None:
filename += f"{self._stage}-"
filename += str(self.filename)
if self._local_rank is not None:
filename += f"-{self._local_rank}"
filename += ".txt"
filename += extension
return filename

def _prepare_streams(self) -> None:
Expand Down
Loading