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

Offload fixes #17810

Merged
merged 2 commits into from
Jun 22, 2022
Merged

Offload fixes #17810

merged 2 commits into from
Jun 22, 2022

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Jun 21, 2022

What does this PR do?

This PR fixes a few bugs in the current offload to disk implementation via Accelerate.

  1. The offload_folder is not created if it doesn't exists, loading to cryptic errors about missing files.
  2. When the model is a task model and the checkpoint one of the base model (like for OPT), there are two issues arising:
    • if offload_state_dict=True, the weights should be reloaded in model_to_load from the temporary offload
    • all the weights offloaded to disk are missing the base_model_cls prefix since they were offloaded as weights of model_to_load and not of model.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 21, 2022

The documentation is not available anymore as the PR was closed or merged.

@@ -2449,6 +2451,15 @@ def _find_mismatched_keys(
gc.collect()

if offload_index is not None and len(offload_index) > 0:
if model != model_to_load:
# We need to add the prefix of the base model
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) Maybe make the comment a bit more explicit? Took me a bit to figure out what is going on here

Suggested change
# We need to add the prefix of the base model
# We need to add the prefix of the base model `model_to_load` to be able to correctly the weights into the task model `model`

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Looks good to me! Maybe we could add a test as well or too edge casy?

@sgugger sgugger merged commit df8e680 into main Jun 22, 2022
@sgugger sgugger deleted the offload_fixes branch June 22, 2022 16:23
younesbelkada pushed a commit to younesbelkada/transformers that referenced this pull request Jun 25, 2022
* Offload fixes

* Add a test
younesbelkada pushed a commit to younesbelkada/transformers that referenced this pull request Jun 29, 2022
* Offload fixes

* Add a test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants