Repository: huggingface/transformers
Pull request: fix asr ut failures

4 tests failed with AttributeError: 'AudioDecoder' object has no attribute 'copy':

`pytest -rA tests/pipelines/test_pipelines_automatic_speech_recognition.py::AutomaticSpeechRecognitionPipelineTests::test_speculative_decoding_whisper_non_distil
pytest -rA tests/test_pipeline_mixin.py::AutomaticSpeechRecognitionPipelineTests::test_speculative_decoding_whisper_non_distil
pytest -rA tests/pipelines/test_pipelines_automatic_speech_recognition.py::AutomaticSpeechRecognitionPipelineTests::test_whisper_prompted
pytest -rA tests/test_pipeline_mixin.py::AutomaticSpeechRecognitionPipelineTests::test_whisper_prompted`

after fixing, they all passed

@SunMarc  @ydshieh , pls help review, thx very much.

Changed files:
filename: src/transformers/generation/logits_process.py
patch: @@ -1915,7 +1915,7 @@ def __init__(self, suppress_tokens, device: str = "cpu"):
     @add_start_docstrings(LOGITS_PROCESSOR_INPUTS_DOCSTRING)
     def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
         vocab_tensor = torch.arange(scores.shape[-1], device=scores.device)
-        suppress_token_mask = isin_mps_friendly(vocab_tensor, self.suppress_tokens)
+        suppress_token_mask = isin_mps_friendly(vocab_tensor, self.suppress_tokens.to(scores.device))
         scores = torch.where(suppress_token_mask, -float("inf"), scores)
         return scores
 

filename: tests/pipelines/test_pipelines_automatic_speech_recognition.py
patch: @@ -1104,7 +1104,7 @@ def test_whisper_language(self):
     def test_speculative_decoding_whisper_non_distil(self):
         # Load data:
         dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation[:1]")
-        sample = dataset[0]["audio"]
+        sample = dataset[0]["audio"].get_all_samples().data
 
         # Load model:
         model_id = "openai/whisper-large-v2"
@@ -1133,8 +1133,8 @@ def test_speculative_decoding_whisper_non_distil(self):
             num_beams=1,
         )
 
-        transcription_non_ass = pipe(sample.copy(), generate_kwargs={"assistant_model": assistant_model})["text"]
-        transcription_ass = pipe(sample)["text"]
+        transcription_ass = pipe(sample.clone().detach(), generate_kwargs={"assistant_model": assistant_model})["text"]
+        transcription_non_ass = pipe(sample)["text"]
 
         self.assertEqual(transcription_ass, transcription_non_ass)
         self.assertEqual(
@@ -1422,13 +1422,13 @@ def test_whisper_prompted(self):
         )
 
         dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
-        sample = dataset[0]["audio"]
+        sample = dataset[0]["audio"].get_all_samples().data
 
         # prompt the model to misspell "Mr Quilter" as "Mr Quillter"
         whisper_prompt = "Mr. Quillter."
         prompt_ids = pipe.tokenizer.get_prompt_ids(whisper_prompt, return_tensors="pt").to(torch_device)
 
-        unprompted_result = pipe(sample.copy())["text"]
+        unprompted_result = pipe(sample.clone().detach())["text"]
         prompted_result = pipe(sample, generate_kwargs={"prompt_ids": prompt_ids})["text"]
 
         # fmt: off