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

Deal with shared memory scenarios #2136

Merged
merged 6 commits into from
Nov 10, 2023
Merged

Deal with shared memory scenarios #2136

merged 6 commits into from
Nov 10, 2023

Conversation

muellerzr
Copy link
Collaborator

What does this PR do?

We need to deal with shared memory scenarios when saving with safetensors and a model. Since the safetensor version relies on passing the entire model instead of the state dict directly, see here, to deal with this, for now a raw copy/paste of the code is done instead to remove duplicate names.

(All state_dict in torch are OrderedDict, hence the check)

Fixes # (issue)
Two failures on the transformers CI

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@SunMarc

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 9, 2023

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

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM ! I know that in the save_model in accelerate and in save_pretrained in transformers, we remove the shared tensors in a different way. I don't know how comparable it is to this method in safetensors but my guess it that it is pretty similar.

@muellerzr
Copy link
Collaborator Author

Good call, I’ll refactor this into a function so that it only warns, doesn’t actually raise an err :)

I think logically it should work the same, bar the bnb explicit part

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thx for iterating ! LGTM !

@muellerzr muellerzr merged commit fc0a43c into main Nov 10, 2023
26 checks passed
@muellerzr muellerzr deleted the shared-mem branch November 10, 2023 15:49
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.

None yet

3 participants