[Whisper] Fix errors with MPS backend introduced by new code on word-level timestamps computation
Author: ercaronte
Pull request: yes

Fixed some issue with MPS backend raised from the recent changes from the great 
 updates from https://github.com/huggingface/transformers/pull/28114

First, the torch.std_mean is not implemented and is not scheduled for implementation, while the single torch.std and torch.mean are. 

Second, MPS backend does not support float64, so it can not cast from float32 to float64. Inverting the double() when the matrix tensor is loaded in the the cpu fixes the issue while it does not change the logic.

Finally, the first changed line is adding to the `isinstance` check tuple the `np.ndarray` type. This is a bug that has also been found here: https://github.com/huggingface/transformers/pull/28226

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->

I think @ylacombe can review this as a continuation of https://github.com/huggingface/transformers/pull/28114
In addition, as per suggestions in the PR: @sanchit-gandhi

Looking forward to your feedback.

Comments:
Sorry @ylacombe for a last minute (small) code change.

I was running a load test, where I transcribed a 2 hours audio file and I stumbled into another `torch.std_mean` instruction (at line 2602) that I did not fix in the initial commit.
After this second fix I got no more issues and could complete the full transcription. 
I also reviewed all the other changes in your initial PR https://github.com/huggingface/transformers/pull/28114 and I could not find any other apparent incompatibility with the current status of the MPS backend.

Please have a quick check :-)

No worries, could you actually use the `is_torch_mps_available` method available in `utils` to check if `torch.std_mean` is available instead of the error catching mechanism ?


Sure, I am totally fine with it and I agree it is more readable.

In theory, the `is_torch_mps_available` check verifies if mps is available, but the user can also set the torch device to be the CPU or other external CUDA cards. In any case, the code is exactly equivalent and it is much more readable. So that when in the future the MPS backend will support the std_mean this (hopefully temporary) fix will be immediately spotted and removed.

I have just committed the changes. Tested with the short and long audio files.

Please have a check :-)

LGTM ! thanks for the quick iteration !


Thank you @amyeroberts, the proposed changes make the code much cleaner.
I didn't dare to be so drastic as the initial commit, but I am quite happy this way. 

Thanks again @ercaronte, merging!