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

Support serialized checkpoint loading [redo #9605] #10141

Conversation

jjenniferdai
Copy link
Contributor

What does this PR do?

Fixes #9406: redo #9605 now that #10061 resolves #10057.

Does your PR introduce any breaking changes? If yes, please list them.

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 list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
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 🙃

del checkpoint["state_dict"]
self._has_loaded_state_dict = True
log.info(f"Rank {self.global_rank}: done loading model states from {checkpoint_path}.")
self.barrier()
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this hang if the user runs any collective op in their on_load_checkpoint hook?

Copy link
Contributor Author

@jjenniferdai jjenniferdai Oct 27, 2021

Choose a reason for hiding this comment

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

good point I think yes ... is this resolvable though, how could we support collective op in model.on_load_checkpoint(checkpoint) if it's impossible to concurrently load then pass checkpoint for large models that OOM?

If it's not possible (please correct me if i'm wrong) - should we control serialized loading option with a boolean, and note that if serialized loading is set, model.on_load_checkpoint would not support collective ops?

Copy link
Contributor

Choose a reason for hiding this comment

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

@carmocca good catch. Yes this will hang if the user on_load_checkpoint runs any collective.

Copy link
Contributor

@carmocca carmocca Oct 27, 2021

Choose a reason for hiding this comment

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

for large models that OOM?

I guess it's more of a problem for models that don't need this serialized loading. Because this PR makes serialization the default mechanism with no opt-out.

should we control serialized loading option with a boolean

This would probably be too ugly to implement.

This weak point seems very niche, as you would generally not run a collective op inside these hooks. Some possibilities that come to mind:

  • IIRC, FB has mentioned in the past that they call model.setup from model.on_load_checkpoint in some cases (sharded only?). I'd say setup is more likely to run such ops.
  • Naive property accesses (like self.trainer.log_dir) can run broadcast.

For this PR, I'd suggest adding a comment here about this weak point. But it's something to remember if we see such hangs.

Perhaps this boolean would be easier to implement and manage after the collective refactor.

cc @awaelchli

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, FB has mentioned in the past that they call model.setup from model.on_load_checkpoint in some cases (sharded only?). I'd say setup is more likely to run such ops.

It's not allowed to call setup() in this hook. With the change we made to the loading logic in #????, we removed the need to call setup() in that hook.

But generally I agree, it is going to be hard to debug hangs as this mechanism may not be obvious. Adding a comment would help minimally.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds great @yifuwang !!

Copy link
Contributor

Choose a reason for hiding this comment

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

This could also resolve the current bug where the checkpoint doesn't exist on some nodes when the filesystem isn't shared.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yifuwan, Would you mind opening an issue for this proposal?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we close this PR and use the proposed logic ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@yifuwang @jjenniferdai Who would make a PR with the above proposition?

@awaelchli awaelchli added the checkpointing Related to checkpointing label Oct 27, 2021
@awaelchli awaelchli added this to the v1.5 milestone Oct 27, 2021
@awaelchli awaelchli added the feature Is an improvement or enhancement label Oct 27, 2021
return
self.lightning_module.load_state_dict(checkpoint["state_dict"])

def load_checkpoint(self, checkpoint_path: _PATH) -> Dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we test this by mocking the hooks called and asserting the order? also the warning/info message

@mergify mergify bot added ready PRs ready to be merged has conflicts labels Oct 30, 2021
@tchaton tchaton modified the milestones: v1.5, v1.6 Nov 1, 2021
@tchaton
Copy link
Contributor

tchaton commented Nov 18, 2021

@jjenniferdai What is the status with this PR ?

@jjenniferdai
Copy link
Contributor Author

if everyone's onboard I think we can close this PR, I'll work with Yifu on the proposed alternative

@carmocca carmocca closed this Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checkpointing Related to checkpointing feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support serialized checkpoint loading
6 participants