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
52972e70
Unverified
Commit
52972e70
authored
Jun 07, 2023
by
Patrick von Platen
Committed by
GitHub
Jun 07, 2023
Browse files
[Wav2Vec2] Fix torch srcipt (#24062)
* [Wav2Vec2] Fix torch srcipt * fix more
parent
612b2a1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
6 deletions
+5
-6
src/transformers/models/wav2vec2/modeling_wav2vec2.py
src/transformers/models/wav2vec2/modeling_wav2vec2.py
+2
-3
tests/models/wav2vec2/test_modeling_wav2vec2.py
tests/models/wav2vec2/test_modeling_wav2vec2.py
+3
-3
No files found.
src/transformers/models/wav2vec2/modeling_wav2vec2.py
View file @
52972e70
...
...
@@ -1178,8 +1178,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel):
if
isinstance
(
module
,
(
Wav2Vec2Encoder
,
Wav2Vec2EncoderStableLayerNorm
,
Wav2Vec2FeatureEncoder
)):
module
.
gradient_checkpointing
=
value
@
property
def
_adapters
(
self
):
def
_get_adapters
(
self
):
if
self
.
config
.
adapter_attn_dim
is
None
:
raise
ValueError
(
f
"
{
self
.
__class__
}
has no adapter layers. Make sure to define `config.adapter_attn_dim`."
)
...
...
@@ -1339,7 +1338,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel):
f
" directory containing a file named
{
filepath
}
."
)
adapter_weights
=
self
.
_adapters
adapter_weights
=
self
.
_
get_
adapters
()
unexpected_keys
=
set
(
state_dict
.
keys
())
-
set
(
adapter_weights
.
keys
())
missing_keys
=
set
(
adapter_weights
.
keys
())
-
set
(
state_dict
.
keys
())
...
...
tests/models/wav2vec2/test_modeling_wav2vec2.py
View file @
52972e70
...
...
@@ -297,7 +297,7 @@ class Wav2Vec2ModelTester:
config
.
adapter_attn_dim
=
16
model
=
Wav2Vec2ForCTC
(
config
=
config
)
self
.
parent
.
assertIsNotNone
(
model
.
_adapters
)
self
.
parent
.
assertIsNotNone
(
model
.
_
get_
adapters
()
)
model
.
to
(
torch_device
)
model
.
eval
()
...
...
@@ -1146,7 +1146,7 @@ class Wav2Vec2RobustModelTest(ModelTesterMixin, unittest.TestCase):
model
=
Wav2Vec2ForCTC
.
from_pretrained
(
tempdir
)
logits
=
get_logits
(
model
,
input_features
)
adapter_weights
=
model
.
_adapters
adapter_weights
=
model
.
_
get_
adapters
()
# save safe weights
safe_filepath
=
os
.
path
.
join
(
tempdir
,
WAV2VEC2_ADAPTER_SAFE_FILE
.
format
(
"eng"
))
...
...
@@ -1168,7 +1168,7 @@ class Wav2Vec2RobustModelTest(ModelTesterMixin, unittest.TestCase):
model
=
Wav2Vec2ForCTC
.
from_pretrained
(
tempdir
)
logits
=
get_logits
(
model
,
input_features
)
adapter_weights
=
model
.
_adapters
adapter_weights
=
model
.
_
get_
adapters
()
# save pt weights
pt_filepath
=
os
.
path
.
join
(
tempdir
,
WAV2VEC2_ADAPTER_PT_FILE
.
format
(
"eng"
))
...
...
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