[Feature Extractors] Fix kwargs to pre-trained #30260
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
It was reported by @osanseviero that when instantiating a feature extractor from pre-trained, setting kwargs occasionally leads to incorrect behaviour. This is particularly the case for Whisper, where setting the argument
feature_size
can have no effect on the number of Mel-bins:Print Output:
This is because of the order in which we set the args in the feature extractor. We first pass all the arguments that we have saved in the
preprocessor_config.json
file:transformers/src/transformers/feature_extraction_utils.py
Line 569 in 8127f39
And subsequently override any kwargs that we got from the user:
transformers/src/transformers/feature_extraction_utils.py
Lines 573 to 575 in 8127f39
The problem with this method is that for Whisper, we set some attributes based on the values of others in the init. E.g. we set
mel_filters
based on the value offeature_size
:transformers/src/transformers/models/whisper/feature_extraction_whisper.py
Lines 87 to 89 in 8127f39
These won't be updated properly with our current method, since we're only updating the attribute
feature_size
, and not subsequently recomputing the correctmel_filters
.The simple fix is to give priority to the user kwargs and ensure these are passed to the init.