-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Wav2Vec2FeatureExtractor] Fix extractor.pad()
dtype backwards compatibility
#13693
[Wav2Vec2FeatureExtractor] Fix extractor.pad()
dtype backwards compatibility
#13693
Conversation
@@ -187,23 +187,6 @@ def pad( | |||
padding_strategy = self._get_padding_strategies(padding=padding, max_length=max_length) | |||
|
|||
required_input = processed_features[self.model_input_names[0]] | |||
if required_input and not isinstance(required_input[0], np.ndarray): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover logic from the old implementation, required_input[0]
is always np.ndarray
now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
if value.dtype is np.dtype(np.float64): | ||
value = value.astype(np.float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding dtype customization to .pad()
, just always use np.float32
, until we really need float64
support for some new models.
…atibility (huggingface#13693) * Force dtype, add tests * Local torch imports * Remove unused logic (always ndarray)
…atibility (huggingface#13693) * Force dtype, add tests * Local torch imports * Remove unused logic (always ndarray)
…atibility (huggingface#13693) * Force dtype, add tests * Local torch imports * Remove unused logic (always ndarray)
…atibility (huggingface#13693) * Force dtype, add tests * Local torch imports * Remove unused logic (always ndarray)
Resolves #13689
This fixes an issue introduced by #13650 with speech feature extractors' tensors being returned as torch.float64 when
.pad()
is called directly:This is due to how pytorch converts float numpy arrays (new padding logic) vs python lists (old padding logic):
torch.tensor([1.2, 2.3]).dtype # torch.float32
np.array([1.2, 2.3]).dtype # np.float64
torch.tensor(np.array([1.2, 2.3])).dtype # torch.float64