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

Bug of init bert-based-uncased #743

Closed
jacazjx opened this issue Oct 17, 2024 · 1 comment
Closed

Bug of init bert-based-uncased #743

jacazjx opened this issue Oct 17, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@jacazjx
Copy link

jacazjx commented Oct 17, 2024

model = AutoAdapterModel.from_pretrained('bert-base-uncased')

adapters-1.0.0 tokenizers-0.19.1 transformers-4.43.4

BUG:
RUN this code:

modules = {}
for n, m in model.named_modules():
    for np, p in m.named_parameters(recurse=False):
        if p is None:
            continue
        key = n + '.' + np
        if key in modules:
            assert id(p) == id(modules[key][0]), (n, np, p.shape, modules[key][0].shape)
            continue
        modules[key] = (p, m)

n_params = len(list(self.model.named_parameters()))   # There is a bug that named_parameters cannot print all parameters
assert len(modules) == n_params, (len(modules), n_params)

PRINT:
134 != 133

So there is a layer of parameters is not register
IT IS heads.default.3.weight
And I found its bias can print normally.

@jacazjx jacazjx added the bug Something isn't working label Oct 17, 2024
@calpt
Copy link
Member

calpt commented Dec 22, 2024

Hey @jacazjx,

I believe this behavior happens due to weight sharing between the input embeddings layer and the output projection of the default head (heads.default.3). By default, shared weights are not yielded twice in named_parameters(), meaning when iterating over the full model's parameters, you only get the input embedding projection and not the (identical) output projection in the head. You can set named_parameters(remove_duplicate=False) to also output shared weights, which should then also return heads.default.3 See here.

Hope this clears things up!

@calpt calpt added question Further information is requested and removed bug Something isn't working labels Dec 22, 2024
@calpt calpt self-assigned this Dec 22, 2024
@calpt calpt closed this as completed Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants