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

handle weight sharing with init_on_device #2737

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aws-rhsoln
Copy link

What does this PR do?

This PR handles the case when we are using meta_device and have tied weights. During model init, when we have a case, where weight2 = weight1 , this would result in register_param getting called again. This call will re-init the param instead of using weight1. This will result in relationship between the weights getting lost.

Fixes # (issue)

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.

@muellerzr muellerzr requested a review from SunMarc May 3, 2024 01:20
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link

github-actions bot commented Jun 2, 2024

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

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.

Hi @aws-rhsoln, thanks for the PR ! Could you add a few tests ? Also, could you explain in which context you needed that ?

@github-actions github-actions bot closed this Jun 16, 2024
@SunMarc SunMarc reopened this Jun 17, 2024
@SunMarc
Copy link
Member

SunMarc commented Jun 17, 2024

Hi @aws-rhsoln, are you still planning to finish the PR ? Thanks !

@aws-rhsoln
Copy link
Author

I'll add some tests soon. Context for the change: For our pipeline parallel implementation here, we first create the model and then trace it, use the traced model to partition for PP. Now we create the model using meta-device and then copy the weights into device after PP init. When copying weights, if we have shared weights such that self.output_layer.weight = self.embedding.weight , the init_on_device api would first initialize embedding weight and then when its about to initialize output.layer weight, since its the embedding weight, its already on device and hence would end up throwing an error. Hence to fix it, this PR was introduced.

@SunMarc
Copy link
Member

SunMarc commented Jun 17, 2024

Awesome ! Thanks for the update !

@muellerzr muellerzr added the wip Work in progress label Jul 15, 2024
@huggingface huggingface deleted a comment from github-actions bot Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wip Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants