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
fa4abdb3
Unverified
Commit
fa4abdb3
authored
Oct 22, 2021
by
Jayesh Dewangan
Committed by
GitHub
Oct 22, 2021
Browse files
Replace assertions with valueError Exeptions (#14117)
* Replace assertions with valueError Exeptions * Reformatted
parent
9f53f049
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
src/transformers/models/wav2vec2/convert_wav2vec2_original_pytorch_checkpoint_to_pytorch.py
...onvert_wav2vec2_original_pytorch_checkpoint_to_pytorch.py
+20
-15
No files found.
src/transformers/models/wav2vec2/convert_wav2vec2_original_pytorch_checkpoint_to_pytorch.py
View file @
fa4abdb3
...
...
@@ -75,9 +75,10 @@ def set_recursively(hf_pointer, key, value, full_name, weight_type):
else
:
hf_shape
=
hf_pointer
.
shape
assert
(
hf_shape
==
value
.
shape
),
f
"Shape of hf
{
key
+
'.'
+
weight_type
if
weight_type
is
not
None
else
''
}
is
{
hf_shape
}
, but should be
{
value
.
shape
}
for
{
full_name
}
"
if
hf_shape
!=
value
.
shape
:
raise
ValueError
(
f
"Shape of hf
{
key
+
'.'
+
weight_type
if
weight_type
is
not
None
else
''
}
is
{
hf_shape
}
, but should be
{
value
.
shape
}
for
{
full_name
}
"
)
if
weight_type
==
"weight"
:
hf_pointer
.
weight
.
data
=
value
...
...
@@ -145,28 +146,32 @@ def load_conv_layer(full_name, value, feature_extractor, unused_weights, use_gro
if
type_id
==
0
:
if
"bias"
in
name
:
assert
(
value
.
shape
==
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
bias
.
data
.
shape
),
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
bias
.
data
.
shape
}
was found."
if
value
.
shape
!=
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
bias
.
data
.
shape
:
raise
ValueError
(
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
bias
.
data
.
shape
}
was found."
)
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
bias
.
data
=
value
logger
.
info
(
f
"Feat extract conv layer
{
layer_id
}
was initialized from
{
full_name
}
."
)
elif
"weight"
in
name
:
assert
(
value
.
shape
==
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
weight
.
data
.
shape
),
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
weight
.
data
.
shape
}
was found."
if
value
.
shape
==
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
weight
.
data
.
shape
:
raise
ValueError
(
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
weight
.
data
.
shape
}
was found."
)
feature_extractor
.
conv_layers
[
layer_id
].
conv
.
weight
.
data
=
value
logger
.
info
(
f
"Feat extract conv layer
{
layer_id
}
was initialized from
{
full_name
}
."
)
elif
(
type_id
==
2
and
not
use_group_norm
)
or
(
type_id
==
2
and
layer_id
==
0
and
use_group_norm
):
if
"bias"
in
name
:
assert
(
value
.
shape
==
feature_extractor
.
conv_layers
[
layer_id
].
layer_norm
.
bias
.
data
.
shape
),
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
[
layer_id
].
layer_norm
.
bias
.
data
.
shape
}
was found."
if
value
.
shape
!=
feature_extractor
.
conv_layers
[
layer_id
].
layer_norm
.
bias
.
data
.
shape
:
raise
ValueError
(
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
[
layer_id
].
layer_norm
.
bias
.
data
.
shape
}
was found."
)
feature_extractor
.
conv_layers
[
layer_id
].
layer_norm
.
bias
.
data
=
value
logger
.
info
(
f
"Feat extract layer norm weight of layer
{
layer_id
}
was initialized from
{
full_name
}
."
)
elif
"weight"
in
name
:
assert
(
value
.
shape
==
feature_extractor
.
conv_layers
[
layer_id
].
layer_norm
.
weight
.
data
.
shape
),
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
[
layer_id
].
layer_norm
.
weight
.
data
.
shape
}
was found."
if
value
.
shape
!=
feature_extractor
.
conv_layers
[
layer_id
].
layer_norm
.
weight
.
data
.
shape
:
raise
ValueError
(
f
"
{
full_name
}
has size
{
value
.
shape
}
, but
{
feature_extractor
[
layer_id
].
layer_norm
.
weight
.
data
.
shape
}
was found."
)
feature_extractor
.
conv_layers
[
layer_id
].
layer_norm
.
weight
.
data
=
value
logger
.
info
(
f
"Feat extract layer norm weight of layer
{
layer_id
}
was initialized from
{
full_name
}
."
)
else
:
...
...
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