From fa8cdccd91bcb6803ea50855166ed8254ea70708 Mon Sep 17 00:00:00 2001 From: Joao Gante Date: Wed, 19 Feb 2025 15:13:10 +0000 Subject: [PATCH] [tests] deflake dither test (#36284) --- .../feature_extraction_audio_spectrogram_transformer.py | 2 +- src/transformers/models/clap/feature_extraction_clap.py | 2 +- src/transformers/models/clvp/feature_extraction_clvp.py | 2 +- src/transformers/models/dac/feature_extraction_dac.py | 2 +- .../models/encodec/feature_extraction_encodec.py | 2 +- .../musicgen_melody/feature_extraction_musicgen_melody.py | 2 +- .../models/seamless_m4t/feature_extraction_seamless_m4t.py | 2 +- .../speech_to_text/feature_extraction_speech_to_text.py | 2 +- .../models/speecht5/feature_extraction_speecht5.py | 2 +- .../models/univnet/feature_extraction_univnet.py | 2 +- .../models/wav2vec2/feature_extraction_wav2vec2.py | 2 +- .../models/whisper/feature_extraction_whisper.py | 3 +-- .../test_feature_extraction_speech_to_text.py | 6 +++--- tests/models/whisper/test_feature_extraction_whisper.py | 6 +++--- 14 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py b/src/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py index b181afe19e..7da6d94bf8 100644 --- a/src/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py +++ b/src/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py @@ -193,7 +193,7 @@ class ASTFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/clap/feature_extraction_clap.py b/src/transformers/models/clap/feature_extraction_clap.py index 42d3646065..6a407cdb87 100644 --- a/src/transformers/models/clap/feature_extraction_clap.py +++ b/src/transformers/models/clap/feature_extraction_clap.py @@ -308,7 +308,7 @@ class ClapFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/clvp/feature_extraction_clvp.py b/src/transformers/models/clvp/feature_extraction_clvp.py index 2dbda430bb..ce6f5c782e 100644 --- a/src/transformers/models/clvp/feature_extraction_clvp.py +++ b/src/transformers/models/clvp/feature_extraction_clvp.py @@ -188,7 +188,7 @@ class ClvpFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/dac/feature_extraction_dac.py b/src/transformers/models/dac/feature_extraction_dac.py index c22a7603f0..8e5bfadb61 100644 --- a/src/transformers/models/dac/feature_extraction_dac.py +++ b/src/transformers/models/dac/feature_extraction_dac.py @@ -108,7 +108,7 @@ class DacFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/encodec/feature_extraction_encodec.py b/src/transformers/models/encodec/feature_extraction_encodec.py index 9bed59de45..3f83c660b2 100644 --- a/src/transformers/models/encodec/feature_extraction_encodec.py +++ b/src/transformers/models/encodec/feature_extraction_encodec.py @@ -132,7 +132,7 @@ class EncodecFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/musicgen_melody/feature_extraction_musicgen_melody.py b/src/transformers/models/musicgen_melody/feature_extraction_musicgen_melody.py index ac83f3ac8d..ec490b7d90 100644 --- a/src/transformers/models/musicgen_melody/feature_extraction_musicgen_melody.py +++ b/src/transformers/models/musicgen_melody/feature_extraction_musicgen_melody.py @@ -242,7 +242,7 @@ class MusicgenMelodyFeatureExtractor(SequenceFeatureExtractor): if sampling_rate is None: logger.warning_once( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/seamless_m4t/feature_extraction_seamless_m4t.py b/src/transformers/models/seamless_m4t/feature_extraction_seamless_m4t.py index 08ea4ea082..84b47cc998 100644 --- a/src/transformers/models/seamless_m4t/feature_extraction_seamless_m4t.py +++ b/src/transformers/models/seamless_m4t/feature_extraction_seamless_m4t.py @@ -225,7 +225,7 @@ class SeamlessM4TFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/speech_to_text/feature_extraction_speech_to_text.py b/src/transformers/models/speech_to_text/feature_extraction_speech_to_text.py index 9e460bb2c4..5473c16681 100644 --- a/src/transformers/models/speech_to_text/feature_extraction_speech_to_text.py +++ b/src/transformers/models/speech_to_text/feature_extraction_speech_to_text.py @@ -248,7 +248,7 @@ class Speech2TextFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/speecht5/feature_extraction_speecht5.py b/src/transformers/models/speecht5/feature_extraction_speecht5.py index aea75ca50b..e6b277644c 100644 --- a/src/transformers/models/speecht5/feature_extraction_speecht5.py +++ b/src/transformers/models/speecht5/feature_extraction_speecht5.py @@ -252,7 +252,7 @@ class SpeechT5FeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the ``sampling_rate`` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/univnet/feature_extraction_univnet.py b/src/transformers/models/univnet/feature_extraction_univnet.py index ab9d3ed5dd..f9881a90c2 100644 --- a/src/transformers/models/univnet/feature_extraction_univnet.py +++ b/src/transformers/models/univnet/feature_extraction_univnet.py @@ -370,7 +370,7 @@ class UnivNetFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/wav2vec2/feature_extraction_wav2vec2.py b/src/transformers/models/wav2vec2/feature_extraction_wav2vec2.py index f76d983094..3dde386b32 100644 --- a/src/transformers/models/wav2vec2/feature_extraction_wav2vec2.py +++ b/src/transformers/models/wav2vec2/feature_extraction_wav2vec2.py @@ -178,7 +178,7 @@ class Wav2Vec2FeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the ``sampling_rate`` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/src/transformers/models/whisper/feature_extraction_whisper.py b/src/transformers/models/whisper/feature_extraction_whisper.py index 766071e9bf..af21fb7d3e 100644 --- a/src/transformers/models/whisper/feature_extraction_whisper.py +++ b/src/transformers/models/whisper/feature_extraction_whisper.py @@ -255,7 +255,6 @@ class WhisperFeatureExtractor(SequenceFeatureExtractor): Whether or not to return the number of frames of the input raw_speech. These num_frames can be used by the model to compute word level timestamps. """ - if sampling_rate is not None: if sampling_rate != self.sampling_rate: raise ValueError( @@ -265,7 +264,7 @@ class WhisperFeatureExtractor(SequenceFeatureExtractor): ) else: logger.warning( - "It is strongly recommended to pass the `sampling_rate` argument to this function. " + f"It is strongly recommended to pass the `sampling_rate` argument to `{self.__class__.__name__}()`. " "Failing to do so can result in silent errors that might be hard to debug." ) diff --git a/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py b/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py index f6ddbb140b..8b10b88650 100644 --- a/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py +++ b/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py @@ -163,10 +163,10 @@ class Speech2TextFeatureExtractionTest(SequenceFeatureExtractionTestMixin, unitt # compute features input_features_no_dither = feature_extractor_no_dither( - np_speech_inputs, padding=True, return_tensors="np" + np_speech_inputs, padding=True, return_tensors="np", sampling_rate=dict_no_dither["sampling_rate"] ).input_features input_features_dither = feature_extractor_dither( - np_speech_inputs, padding=True, return_tensors="np" + np_speech_inputs, padding=True, return_tensors="np", sampling_rate=dict_dither["sampling_rate"] ).input_features # test there is a difference between features (there's added noise to input signal) @@ -176,7 +176,7 @@ class Speech2TextFeatureExtractionTest(SequenceFeatureExtractionTestMixin, unitt self.assertTrue(np.abs(diff).mean() > 1e-5) # features are not too different self.assertTrue(np.abs(diff).mean() <= 1e-3) - self.assertTrue(np.abs(diff).max() <= 1e-2) + self.assertTrue(np.abs(diff).max() <= 5e-2) def test_cepstral_mean_and_variance_normalization(self): feature_extractor = self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()) diff --git a/tests/models/whisper/test_feature_extraction_whisper.py b/tests/models/whisper/test_feature_extraction_whisper.py index d07ef2221c..80cb421d13 100644 --- a/tests/models/whisper/test_feature_extraction_whisper.py +++ b/tests/models/whisper/test_feature_extraction_whisper.py @@ -219,10 +219,10 @@ class WhisperFeatureExtractionTest(SequenceFeatureExtractionTestMixin, unittest. # compute features input_features_no_dither = feature_extractor_no_dither( - np_speech_inputs, padding=True, return_tensors="np" + np_speech_inputs, padding=True, return_tensors="np", sampling_rate=dict_no_dither["sampling_rate"] ).input_features input_features_dither = feature_extractor_dither( - np_speech_inputs, padding=True, return_tensors="np" + np_speech_inputs, padding=True, return_tensors="np", sampling_rate=dict_dither["sampling_rate"] ).input_features # test there is a difference between features (there's added noise to input signal) @@ -232,7 +232,7 @@ class WhisperFeatureExtractionTest(SequenceFeatureExtractionTestMixin, unittest. self.assertTrue(np.abs(diff).mean() > 1e-6) # features are not too different self.assertTrue(np.abs(diff).mean() <= 1e-4) - self.assertTrue(np.abs(diff).max() <= 1e-3) + self.assertTrue(np.abs(diff).max() <= 5e-3) @require_torch def test_double_precision_pad(self):