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
cd09a8df
Unverified
Commit
cd09a8df
authored
Apr 19, 2024
by
Sanchit Gandhi
Committed by
GitHub
Apr 19, 2024
Browse files
[Feature Extractors] Fix kwargs to pre-trained (#30260)
fixes
parent
4ab7a282
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
src/transformers/feature_extraction_utils.py
src/transformers/feature_extraction_utils.py
+4
-4
tests/models/whisper/test_feature_extraction_whisper.py
tests/models/whisper/test_feature_extraction_whisper.py
+14
-0
No files found.
src/transformers/feature_extraction_utils.py
View file @
cd09a8df
...
...
@@ -566,17 +566,17 @@ class FeatureExtractionMixin(PushToHubMixin):
"""
return_unused_kwargs
=
kwargs
.
pop
(
"return_unused_kwargs"
,
False
)
feature_extractor
=
cls
(
**
feature_extractor_dict
)
# Update feature_extractor with kwargs if needed
to_remove
=
[]
for
key
,
value
in
kwargs
.
items
():
if
hasattr
(
feature_extractor
,
key
)
:
setattr
(
feature_extractor
,
key
,
value
)
if
key
in
feature_extractor
_dict
:
feature_extractor
_dict
[
key
]
=
value
to_remove
.
append
(
key
)
for
key
in
to_remove
:
kwargs
.
pop
(
key
,
None
)
feature_extractor
=
cls
(
**
feature_extractor_dict
)
logger
.
info
(
f
"Feature extractor
{
feature_extractor
}
"
)
if
return_unused_kwargs
:
return
feature_extractor
,
kwargs
...
...
tests/models/whisper/test_feature_extraction_whisper.py
View file @
cd09a8df
...
...
@@ -142,6 +142,20 @@ class WhisperFeatureExtractionTest(SequenceFeatureExtractionTestMixin, unittest.
self
.
assertTrue
(
np
.
allclose
(
mel_1
,
mel_2
))
self
.
assertEqual
(
dict_first
,
dict_second
)
def
test_feat_extract_from_pretrained_kwargs
(
self
):
feat_extract_first
=
self
.
feature_extraction_class
(
**
self
.
feat_extract_dict
)
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
saved_file
=
feat_extract_first
.
save_pretrained
(
tmpdirname
)[
0
]
check_json_file_has_correct_format
(
saved_file
)
feat_extract_second
=
self
.
feature_extraction_class
.
from_pretrained
(
tmpdirname
,
feature_size
=
2
*
self
.
feat_extract_dict
[
"feature_size"
]
)
mel_1
=
feat_extract_first
.
mel_filters
mel_2
=
feat_extract_second
.
mel_filters
self
.
assertTrue
(
2
*
mel_1
.
shape
[
1
]
==
mel_2
.
shape
[
1
])
def
test_call
(
self
):
# Tests that all call wrap to encode_plus and batch_encode_plus
feature_extractor
=
self
.
feature_extraction_class
(
**
self
.
feat_extract_tester
.
prepare_feat_extract_dict
())
...
...
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