-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Make asyncio checkpointing work if validate/fit is called more than once #20952
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
Open
jjh42
wants to merge
5
commits into
Lightning-AI:master
Choose a base branch
from
jjh42:jhunt/fix-async-reset
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
21f9f28
Make asyncio checkpointing work if validate/fit is called more than o…
jjh42 42ee02f
Merge branch 'master' into jhunt/fix-async-reset
Borda d5e2b36
Merge branch 'master' into jhunt/fix-async-reset
Borda 355a0b9
Apply suggestions from code review
Borda 24bdcf3
Merge branch 'master' into jhunt/fix-async-reset
SkafteNicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,23 @@ class AsyncCheckpointIO(_WrappingCheckpointIO): | |
|
||
def __init__(self, checkpoint_io: Optional["CheckpointIO"] = None) -> None: | ||
super().__init__(checkpoint_io) | ||
|
||
self._executor = ThreadPoolExecutor(max_workers=1) | ||
self._executor: Optional[ThreadPoolExecutor] = None | ||
self._error: Optional[BaseException] = None | ||
|
||
# CheckpointIO doesn't have a setup method so we have to do something like. | ||
# We can't do setup in __init__ because if train or validate is called more than once the | ||
# teardown method deletes the executor. | ||
Comment on lines
+39
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can put this in a function's docstring? |
||
def _ensure_setup(self) -> None: | ||
if self._executor is None: | ||
self._executor = ThreadPoolExecutor(max_workers=1) | ||
self._error: Optional[BaseException] = None | ||
|
||
@override | ||
def save_checkpoint(self, *args: Any, **kwargs: Any) -> None: | ||
"""Uses the ``ThreadPoolExecutor`` to save the checkpoints using the base ``checkpoint_io``.""" | ||
|
||
self._ensure_setup() | ||
|
||
def _save_checkpoint(*args: Any, **kwargs: Any) -> None: | ||
try: | ||
assert self.checkpoint_io is not None | ||
|
@@ -58,8 +67,10 @@ def _save_checkpoint(*args: Any, **kwargs: Any) -> None: | |
@override | ||
def teardown(self) -> None: | ||
"""This method is called to close the threads.""" | ||
self._executor.shutdown(wait=True) | ||
if self._executor is not None: | ||
self._executor.shutdown(wait=True) | ||
self._executor = None | ||
|
||
# if an error was raised anytime in any of the `executor.submit` calls | ||
if self._error: | ||
raise self._error | ||
# if an error was raised anytime in any of the `executor.submit` calls | ||
if self._error: | ||
raise self._error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.