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
1e847b40
Unverified
Commit
1e847b40
authored
Dec 28, 2021
by
Patrick von Platen
Committed by
GitHub
Dec 28, 2021
Browse files
[WavLM] give model for precision (#14958)
parent
1c121916
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
tests/test_modeling_wavlm.py
tests/test_modeling_wavlm.py
+28
-2
No files found.
tests/test_modeling_wavlm.py
View file @
1e847b40
...
...
@@ -14,6 +14,7 @@
# limitations under the License.
""" Testing suite for the PyTorch WavLM model. """
import
copy
import
math
import
unittest
...
...
@@ -451,6 +452,31 @@ class WavLMModelTest(ModelTesterMixin, unittest.TestCase):
if
hasattr
(
module
,
"masked_spec_embed"
)
and
module
.
masked_spec_embed
is
not
None
:
module
.
masked_spec_embed
.
data
.
fill_
(
3
)
# overwrite from test_modeling_common
# as WavLM is not very precise
def
test_feed_forward_chunking
(
self
):
(
original_config
,
inputs_dict
,
)
=
self
.
model_tester
.
prepare_config_and_inputs_for_common
()
for
model_class
in
self
.
all_model_classes
:
torch
.
manual_seed
(
0
)
config
=
copy
.
deepcopy
(
original_config
)
model
=
model_class
(
config
)
model
.
to
(
torch_device
)
model
.
eval
()
hidden_states_no_chunk
=
model
(
**
self
.
_prepare_for_class
(
inputs_dict
,
model_class
))[
0
]
torch
.
manual_seed
(
0
)
config
.
chunk_size_feed_forward
=
1
model
=
model_class
(
config
)
model
.
to
(
torch_device
)
model
.
eval
()
hidden_states_with_chunk
=
model
(
**
self
.
_prepare_for_class
(
inputs_dict
,
model_class
))[
0
]
self
.
assertTrue
(
torch
.
allclose
(
hidden_states_no_chunk
,
hidden_states_with_chunk
,
atol
=
1e-2
))
@
slow
def
test_model_from_pretrained
(
self
):
model
=
WavLMModel
.
from_pretrained
(
"microsoft/wavlm-base-plus"
)
...
...
@@ -497,7 +523,7 @@ class WavLMModelIntegrationTest(unittest.TestCase):
[[[
0.0577
,
0.1161
],
[
0.0579
,
0.1165
]],
[[
0.0199
,
0.1237
],
[
0.0059
,
0.0605
]]]
)
# TODO: update the tolerance after the CI moves to torch 1.10
self
.
assertTrue
(
torch
.
allclose
(
hidden_states_slice
,
EXPECTED_HIDDEN_STATES_SLICE
,
atol
=
1
e-2
))
self
.
assertTrue
(
torch
.
allclose
(
hidden_states_slice
,
EXPECTED_HIDDEN_STATES_SLICE
,
atol
=
5
e-2
))
def
test_inference_large
(
self
):
model
=
WavLMModel
.
from_pretrained
(
"microsoft/wavlm-large"
).
to
(
torch_device
)
...
...
@@ -520,7 +546,7 @@ class WavLMModelIntegrationTest(unittest.TestCase):
EXPECTED_HIDDEN_STATES_SLICE
=
torch
.
tensor
(
[[[
0.1612
,
0.4314
],
[
0.1690
,
0.4344
]],
[[
0.2086
,
0.1396
],
[
0.3014
,
0.0903
]]]
)
self
.
assertTrue
(
torch
.
allclose
(
hidden_states_slice
,
EXPECTED_HIDDEN_STATES_SLICE
,
rtol
=
1
e-2
))
self
.
assertTrue
(
torch
.
allclose
(
hidden_states_slice
,
EXPECTED_HIDDEN_STATES_SLICE
,
rtol
=
5
e-2
))
def
test_inference_diarization
(
self
):
model
=
WavLMForAudioFrameClassification
.
from_pretrained
(
"microsoft/wavlm-base-plus-sd"
).
to
(
torch_device
)
...
...
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