Skip to content

Commit

Permalink
Merge pull request #77 from neuro-ml/develop
Browse files Browse the repository at this point in the history
Batch iter compatibility with lightning
  • Loading branch information
vovaf709 authored Jul 19, 2023
2 parents 0ef97f4 + 74f60de commit 56c3658
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dpipe/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.4'
__version__ = '0.2.5'
19 changes: 19 additions & 0 deletions dpipe/batch_iter/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ def close(self):
"""Stop all background processes."""
self.__exit__(None, None, None)

@property
def closing_callback(self):
"""
A callback to make this interface compatible with `Lightning` which allows for a safe release of resources
Examples
--------
>>> batch_iter = Infinite(...)
>>> trainer = Trainer(callbacks=[batch_iter.closing_callback, ...])
"""
from lightning.pytorch.callbacks import Callback

class ClosingCallback(Callback):
def teardown(self, trainer, pl_module, stage):
this.close()

this = self
return ClosingCallback()

def __iter__(self):
return self()

Expand Down

0 comments on commit 56c3658

Please sign in to comment.