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

convert_wav2vec2_original_pytorch_checkpoint_to_pytorch.py does not work due to weight norm key #31633

Open
1 of 4 tasks
gau-nernst opened this issue Jun 26, 2024 · 3 comments · May be fixed by #31714
Open
1 of 4 tasks
Labels

Comments

@gau-nernst
Copy link
Contributor

gau-nernst commented Jun 26, 2024

System Info

NA

Who can help?

@sanchit-gandhi

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

Fairseq uses nn.utils.weight_norm(), which produces weight_g and weight_v keys

https://github.com/facebookresearch/fairseq/blob/d9a627082fd03ec72a27a31a4e56289bfcb2e4e4/fairseq/models/wav2vec/wav2vec2.py#L939

The weight conversion script assumes this old-style weight norm

elif weight_type == "weight_g":
hf_pointer.weight_g.data = value
elif weight_type == "weight_v":
hf_pointer.weight_v.data = value

Thus, the weight conversion script will fail since transformers has switched to nn.utils.parametrizations.weight_norm for quite some time, which produces parametrizations.weight.original0 and parametrizations.weight.original1 keys instead.

weight_norm = nn.utils.weight_norm
if hasattr(nn.utils.parametrizations, "weight_norm"):
weight_norm = nn.utils.parametrizations.weight_norm

Thus the weight conversion script should be updated accordingly.

Expected behavior

Weight conversion script works.

@amyeroberts
Copy link
Collaborator

cc @sanchit-gandhi

@gau-nernst
Copy link
Contributor Author

I had something working for me. f you don't have time to look into it, I can open a PR. I can provide a snippet to test it with some original fairseq checkpoints too. I

@amyeroberts
Copy link
Collaborator

@gau-nernst Yes please, that would be great cc @kamilakesbi too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants