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 bug in _get_named_modules #3052

Merged
merged 3 commits into from
Sep 6, 2024
Merged

fix bug in _get_named_modules #3052

merged 3 commits into from
Sep 6, 2024

Conversation

faaany
Copy link
Contributor

@faaany faaany commented Aug 27, 2024

What does this PR do?

I got the following error when running the UT in transformers: tests/models/glpn/test_modeling_glpn.py::GLPNModelTest::test_model_parallelism

src/transformers/modeling_utils.py:3780: in from_pretrained
    device_map = infer_auto_device_map(model, dtype=target_dtype, **device_map_kwargs)
../accelerate/src/accelerate/utils/modeling.py:1238: in infer_auto_device_map
    tied_parameters = find_tied_parameters(model)
../accelerate/src/accelerate/utils/modeling.py:708: in find_tied_parameters
    all_named_parameters = {name: param for name, param in _get_named_parameters(model, remove_duplicate=False)}
../accelerate/src/accelerate/utils/modeling.py:708: in <dictcomp>
    all_named_parameters = {name: param for name, param in _get_named_parameters(model, remove_duplicate=False)}
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

module = None, prefix = '', recurse = True, remove_duplicate = False

    def _get_named_parameters(module: torch.nn.Module, prefix="", recurse=True, remove_duplicate: bool = True):
        """
        Help yield various names + members of modules. Copied from PyTorch `torch.nn.Module.named_modules` for
        compatability with torch < 2.0 versions with `remove_duplicate` option added.
        """
        memo = set()
        modules = (
            _get_named_modules(module, prefix=prefix, remove_duplicate=remove_duplicate) if recurse else [(prefix, module)]
        )
        for module_prefix, module in modules:
>           members = module._parameters.items()
E           AttributeError: 'NoneType' object has no attribute '_parameters'

../accelerate/src/accelerate/utils/modeling.py:667: AttributeError

Pls have a review. Thx!
@muellerzr

@muellerzr muellerzr requested a review from SunMarc August 27, 2024 09:32
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 the PR @faaany ! I left a comment

src/accelerate/utils/modeling.py Show resolved Hide resolved
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.

Nice job @faaany ! Thanks for your help !

src/accelerate/utils/modeling.py Show resolved Hide resolved
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 for the fix!

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

@SunMarc
Copy link
Member

SunMarc commented Sep 6, 2024

CI failing test is unrelated, merging !

@SunMarc SunMarc merged commit e7e0181 into huggingface:main Sep 6, 2024
23 of 25 checks passed
@faaany faaany deleted the fix-module branch November 4, 2024 06:08
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.

4 participants