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

progressive restoring of trainer state #7652

Merged
merged 36 commits into from
Jun 17, 2021
Merged

progressive restoring of trainer state #7652

merged 36 commits into from
Jun 17, 2021

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented May 22, 2021

What does this PR do?

Fixes #7535

Includes the changes from #7955, target branch will be changed to master.

The restore flow before:

call to trainer.fit()

model.setup("fit")  # trainer calls setup
call_configure_sharded_model(model)
accelerator.setup(model) 
...

dispatch() #  _run_train, etc.
restore() # restore everything at once (model, callbacks, optimizers, loop state etc.)

The restore flow now:

call to Trainer.fit()

# check if/what we needs to resume, load the checkpoint file
resume_start() 

model.setup("fit")  # trainer calls setup

# model weights get restored as soon as model is setup
restore_datamodule() # calls datamodule.on_load_checkpoint()
restore_model() # calls model.on_load_checkpoint()
restore_callbacks() # calls callback.on_load_checkpoint()

call_configure_sharded_model(model)
accelerator.setup(model) 

pre_dispatch()

# restore training state as soon as everything
restore_training_state()  # restore optimizer, precision, loop progress

dispatch() #  _run_train, etc.

resume_end() # delete checkpoint file in memory

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 🙃

Follow up to this PR

Make plugin decide if we want to restore model weights before or after call to configure_sharded_model hook as per #7535 (comment)

if TrainingTypePlugin.restore_before_configure_sharded_model:
    restore_model() # also calls model.on_load_checkpoint()

call_configure_sharded_model(model)

if not TrainingTypePlugin.restore_before_configure_sharded_model:
    restore_model() # also calls model.on_load_checkpoint()

@pep8speaks
Copy link

pep8speaks commented May 22, 2021

Hello @awaelchli! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-06-17 07:49:49 UTC

@codecov
Copy link

codecov bot commented May 22, 2021

Codecov Report

Merging #7652 (02c3d54) into master (bc2c2db) will decrease coverage by 0%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #7652    +/-   ##
=======================================
- Coverage      92%     91%    -0%     
=======================================
  Files         207     207            
  Lines       13374   13485   +111     
=======================================
+ Hits        12246   12317    +71     
- Misses       1128    1168    +40     

@awaelchli awaelchli changed the base branch from master to feature/resume-8 June 12, 2021 12:55
@mergify mergify bot removed the has conflicts label Jun 16, 2021
tests/models/test_hooks.py Outdated Show resolved Hide resolved
@awaelchli awaelchli requested a review from carmocca June 16, 2021 12:37
@mergify mergify bot removed the has conflicts label Jun 16, 2021
@carmocca carmocca added this to the v1.4 milestone Jun 16, 2021
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 !

@tchaton tchaton added the ready PRs ready to be merged label Jun 16, 2021
@awaelchli awaelchli enabled auto-merge (squash) June 16, 2021 21:18
Co-authored-by: Carlos Mocholí <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checkpointing Related to checkpointing distributed Generic distributed-related topic 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.

[bug]Resuming From Checkpoint for FP16 failure (Single GPU)
7 participants