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

Fix find_tied_params for models with shared layers #2986

Merged
merged 6 commits into from
Aug 13, 2024

Conversation

qubvel
Copy link
Member

@qubvel qubvel commented Aug 2, 2024

What does this PR do?

Fixes #2984

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?

@SunMarc

@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.

@qubvel
Copy link
Member Author

qubvel commented Aug 2, 2024

Added a test case that fails

FAILED tests/test_modeling_utils.py::ModelingUtilsTester::test_find_tied_parameters - AssertionError: assert [] == [['0.weight',...s', '1.bias']]
  
  Right contains 2 more items, first extra item: ['0.weight', '1.weight']
  
  Full diff:
  + []
  - [
  -     [
  -         '0.weight',
  -         '1.weight',
  -     ],
  -     [
  -         '0.bias',
  -         '1.bias',
  -     ],
  - ]

@qubvel
Copy link
Member Author

qubvel commented Aug 2, 2024

CI error looks unrelated:

Cannot access gated repo for url https://huggingface.co/meta-llama/Llama-2-7b-hf/resolve/main/config.json.
Access to model meta-llama/Llama-2-7b-hf is restricted. You must be authenticated to access it.
======== 1 failed, 29 passed, 1 skipped, 1 warning in 65.21s (0:01:05) =========
make: *** [Makefile:34: test_cli] Error 1

@SunMarc, its ready for review

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.

Thanks for fixing the issue @qubvel ! LGTM ! Just a nit !

tests/test_modeling_utils.py Show resolved Hide resolved
src/accelerate/utils/modeling.py Outdated Show resolved Hide resolved
@SunMarc SunMarc requested a review from muellerzr August 5, 2024 15:41
@SunMarc
Copy link
Member

SunMarc commented Aug 5, 2024

Can you have a second look @muellerzr ?

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Thanks! I like this simplicity and thanks for adding the test. A few suggestions for clarity

src/accelerate/utils/modeling.py Outdated Show resolved Hide resolved
@@ -616,7 +616,73 @@ def check_tied_parameters_on_same_device(tied_params, device_map):
)


def find_tied_parameters(model: nn.Module, **kwargs):
def _get_named_modules(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're documenting it in this way, we should make this public :)

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure you need it public :) its just copied form PyTorch code

Copy link
Member Author

@qubvel qubvel Aug 13, 2024

Choose a reason for hiding this comment

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

I removed Example for this docstring, not sure it is needed for a private method, and also doc-builder was raising an error (commit #952324c)

src/accelerate/utils/modeling.py Outdated Show resolved Hide resolved
@qubvel
Copy link
Member Author

qubvel commented Aug 13, 2024

@SunMarc I suppose it can be merged!

@muellerzr
Copy link
Collaborator

Yes indeed, thanks @qubvel !

@muellerzr muellerzr merged commit 851cf34 into huggingface:main Aug 13, 2024
25 checks passed
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.

find_tied_parameters miss tied parameters
4 participants