Skip to content

Commit

Permalink
Merge 709d4bf into 4f391bc
Browse files Browse the repository at this point in the history
  • Loading branch information
camruta authored Mar 5, 2021
2 parents 4f391bc + 709d4bf commit 9169c17
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Added arg to `self.log` that enables users to give custom names when dealing with multiple dataloaders ([#6274](https://github.com/PyTorchLightning/pytorch-lightning/pull/6274))

- Added teardown method to BaseProfiler to enable subclasses define post-profiling steps outside of __del__ method.

### Changed

Expand Down
Binary file added a.out
Binary file not shown.
17 changes: 15 additions & 2 deletions pytorch_lightning/profiler/profilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def start(self, action_name: str) -> None:
def stop(self, action_name: str) -> None:
"""Defines how to record the duration once an action is complete."""

@abstractmethod
def teardown(self) -> None:
"""Execute arbitrary post-profiling tear-down steps as defined by subclass."""

@contextmanager
def profile(self, action_name: str) -> None:
"""
Expand Down Expand Up @@ -114,6 +118,9 @@ def start(self, action_name: str) -> None:
def stop(self, action_name: str) -> None:
pass

def teardown(self) -> None:
pass

def summary(self) -> str:
return ""

Expand Down Expand Up @@ -214,11 +221,14 @@ def describe(self):
if self.output_file:
self.output_file.flush()

def __del__(self):
def teardown(self) -> None:
"""Close profiler's stream."""
if self.output_file:
self.output_file.close()

def __del__(self):
self.teardown()


class AdvancedProfiler(BaseProfiler):
"""
Expand Down Expand Up @@ -286,7 +296,10 @@ def describe(self):
if self.output_file:
self.output_file.flush()

def __del__(self):
def teardown(self) -> None:
"""Close profiler's stream."""
if self.output_file:
self.output_file.close()

def __del__(self):
self.teardown()
5 changes: 4 additions & 1 deletion pytorch_lightning/profiler/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ def describe(self):
if self.output_file:
self.output_file.flush()

def __del__(self):
def teardown(self) -> None:
"""Close profiler's stream."""
if self.output_file:
self.output_file.close()

def __del__(self):
self.teardown()

0 comments on commit 9169c17

Please sign in to comment.