Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
a8fa6fbb
Unverified
Commit
a8fa6fbb
authored
Jul 06, 2024
by
Thien Tran
Committed by
GitHub
Jul 05, 2024
Browse files
Fix Wav2Vec2 Fairseq conversion (weight norm state dict keys) (#31714)
* handle new weight norm * fix * fix trailing space
parent
a01b033c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
src/transformers/models/wav2vec2/convert_wav2vec2_original_pytorch_checkpoint_to_pytorch.py
...onvert_wav2vec2_original_pytorch_checkpoint_to_pytorch.py
+18
-3
No files found.
src/transformers/models/wav2vec2/convert_wav2vec2_original_pytorch_checkpoint_to_pytorch.py
View file @
a8fa6fbb
...
...
@@ -94,8 +94,17 @@ def set_recursively(key, value, full_name, weight_type, hf_pointer):
hf_param_name
=
PARAM_MAPPING
[
full_name
.
split
(
"."
)[
-
1
]]
weight_type
=
"param"
# fairseq uses nn.utils.weight_norm() while transformers switches to nn.utils.parametrizations.weight_norm()
# the mapping between two versions:
# https://github.com/pytorch/pytorch/blob/56935684c3dfad7841c83c719eeebecb560fe466/torch/nn/utils/parametrizations.py#L389-L395
if
weight_type
is
not
None
and
weight_type
!=
"param"
:
hf_shape
=
getattr
(
hf_pointer
,
weight_type
).
shape
if
weight_type
==
"weight_g"
and
not
hasattr
(
hf_pointer
,
"weight_g"
):
hf_shape
=
hf_pointer
.
parametrizations
.
weight
.
original0
.
shape
elif
weight_type
==
"weight_v"
and
not
hasattr
(
hf_pointer
,
"weight_v"
):
hf_shape
=
hf_pointer
.
parametrizations
.
weight
.
original1
.
shape
else
:
hf_shape
=
getattr
(
hf_pointer
,
weight_type
).
shape
elif
weight_type
is
not
None
and
weight_type
==
"param"
:
shape_pointer
=
hf_pointer
for
attribute
in
hf_param_name
.
split
(
"."
):
...
...
@@ -116,9 +125,15 @@ def set_recursively(key, value, full_name, weight_type, hf_pointer):
if
weight_type
==
"weight"
:
hf_pointer
.
weight
.
data
=
value
elif
weight_type
==
"weight_g"
:
hf_pointer
.
weight_g
.
data
=
value
if
hasattr
(
hf_pointer
,
"weight_g"
):
hf_pointer
.
weight_g
.
data
=
value
else
:
hf_pointer
.
parametrizations
.
weight
.
original0
.
data
=
value
elif
weight_type
==
"weight_v"
:
hf_pointer
.
weight_v
.
data
=
value
if
hasattr
(
hf_pointer
,
"weight_v"
):
hf_pointer
.
weight_v
.
data
=
value
else
:
hf_pointer
.
parametrizations
.
weight
.
original1
.
data
=
value
elif
weight_type
==
"bias"
:
hf_pointer
.
bias
.
data
=
value
elif
weight_type
==
"param"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment