Skip to content

Serialize checkpoint loading on each node #7509

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

Closed

Conversation

maximsch2
Copy link
Contributor

@maximsch2 maximsch2 commented May 12, 2021

What does this PR do?

Loading large checkpoints across multiple workers on the same host can lead to OOMs (easy to imagine case: model_size*num_gpus < total ram < 2*model_size*num_gpus - we get 2x penalty for loading checkpoint on each worker before setting it into state_dict of the model), serializing the process would help as now we'll only do things one local worker at a time.

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 🙃

@codecov
Copy link

codecov bot commented May 12, 2021

Codecov Report

Merging #7509 (81508f6) into master (20f6337) will decrease coverage by 5%.
The diff coverage is 43%.

@@           Coverage Diff           @@
##           master   #7509    +/-   ##
=======================================
- Coverage      92%     88%    -5%     
=======================================
  Files         197     197            
  Lines       12878   12884     +6     
=======================================
- Hits        11899   11314   -585     
- Misses        979    1570   +591     

@maximsch2 maximsch2 changed the title WIP: Serialize checkpoint loading on each node Serialize checkpoint loading on each node May 12, 2021
@maximsch2 maximsch2 marked this pull request as ready for review May 12, 2021 23:55
@maximsch2 maximsch2 requested a review from ananthsub May 13, 2021 00:07
@pep8speaks
Copy link

pep8speaks commented May 13, 2021

Hello @maximsch2! Thanks for updating this PR.

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

Comment last updated at 2021-05-17 17:58:59 UTC

@@ -143,7 +143,8 @@ def __init__(
distributed_backend: Optional[str] = None,
move_metrics_to_cpu: bool = False,
multiple_trainloader_mode: str = 'max_size_cycle',
stochastic_weight_avg: bool = False
stochastic_weight_avg: bool = False,
serialize_checkpoint_loading: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think a trainer flag is necessary here? Is it too slow to always serialize?

What about us making the choice by comparing the ram available and model size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can potentially be unsafe to always serialize, specifically if you are doing any NCCL communications in on_load_checkpoint and assume they are happening at the same time on all hosts - with serialization those will deadlock, hence having this off by default.

@carmocca carmocca added the feature Is an improvement or enhancement label May 17, 2021
@@ -143,7 +143,8 @@ def __init__(
distributed_backend: Optional[str] = None,
move_metrics_to_cpu: bool = False,
multiple_trainloader_mode: str = 'max_size_cycle',
stochastic_weight_avg: bool = False
stochastic_weight_avg: bool = False,
serialize_checkpoint_loading: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, sequential_checkpoint_loading would be easier to understand.

ckpt_path, map_location=lambda storage, loc: storage
)
# Serialize checkpoint loading to avoid OOMs
if self.serialize_checkpoint_loading and self.num_gpus > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not let this responsibility to the training_type_plugin, I guess this is useful only for DDP and derivate right now.

@stale
Copy link

stale bot commented Jun 4, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://pytorch-lightning.readthedocs.io/en/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Slack. Thank you for your contributions.

@stale stale bot added the won't fix This will not be worked on label Jun 4, 2021
@stale
Copy link

stale bot commented Jun 9, 2021

This pull request is going to be closed. Please feel free to reopen it create a new from the actual master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement won't fix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants