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

refactor CheckpointConnector.restore_weights #7862

Merged
merged 15 commits into from
Jun 9, 2021
Merged

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Jun 7, 2021

What does this PR do?

Part of #7652

Splits the function restore_weights in to two:

  • resume_start()
  • Trainer restores state
  • resume_end()

The checkpoint loaded in resume_start() will be temporarily cached and then destroyed in resume_end().
This is in preparation of #7652 where we will call resume_start() and resume_end() individually to split the restoring of trainer state to multiple stages.

Discussion regarding partial restoring of trainer state in stages can be found in #7535

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@awaelchli awaelchli added refactor design Includes a design discussion labels Jun 7, 2021
@awaelchli awaelchli added this to the v1.4 milestone Jun 7, 2021
@codecov
Copy link

codecov bot commented Jun 7, 2021

Codecov Report

Merging #7862 (afb89ce) into master (b214442) will decrease coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #7862   +/-   ##
======================================
- Coverage      91%     91%   -0%     
======================================
  Files         204     204           
  Lines       13630   13643   +13     
======================================
- Hits        12414   12389   -25     
- Misses       1216    1254   +38     

@awaelchli awaelchli marked this pull request as ready for review June 7, 2021 11:36
Comment on lines 55 to 60
dir_path_hpc = str(self.trainer.weights_save_path)
max_suffix = self.max_ckpt_in_folder(dir_path_hpc, "hpc_ckpt_")
if max_suffix is not None:
checkpoint_path = f'{dir_path_hpc}/hpc_ckpt_{max_suffix}.ckpt'
self.hpc_load(checkpoint_path, self.trainer._device_type == DeviceType.GPU)
rank_zero_info(f'restored hpc model from: {checkpoint_path}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewers: this part is now in the property hpc_resume_path

Comment on lines 78 to 85
# Try to read the checkpoint file at `checkpoint_path`. If not exist, do not restore checkpoint.
fs = get_filesystem(checkpoint_path)
if not fs.exists(checkpoint_path):
raise FileNotFoundError(f"Checkpoint at {checkpoint_path} not found. Aborting training.")

checkpoint, load_optimizer_states = self.trainer.training_type_plugin.restore_model_state_from_ckpt_path(
checkpoint_path, map_location=lambda storage, loc: storage
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewers: this part has moved to resume_start()

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@awaelchli awaelchli added the ready PRs ready to be merged label Jun 8, 2021
@mergify mergify bot requested a review from a team June 8, 2021 22:09
Copy link
Contributor

@kaushikb11 kaushikb11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments. Approving to unblock :)

@awaelchli awaelchli requested a review from williamFalcon as a code owner June 9, 2021 07:13
@awaelchli awaelchli enabled auto-merge (squash) June 9, 2021 07:30
@awaelchli awaelchli merged commit 764d2c7 into master Jun 9, 2021
@awaelchli awaelchli deleted the feature/resume-5 branch June 9, 2021 09:55

def resume_end(self) -> None:
""" Signal the connector that all states have resumed and memory for the checkpoint object can be released. """
rank_zero_info(f"Restored all states from the checkpoint file at {self.resume_checkpoint_path}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@awaelchli we shouldn't print this if not self.resume_checkpoint_path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know and it's addressed in #7652
sorry for the inconvenience

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Includes a design discussion ready PRs ready to be merged refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants