bad_words_ids no longer slow on mps
Author: dwarez
Pull request: yes

# What does this PR do?
Using the `bad_words_ids` on mps is slowing down a lot the text generation, this PR tries to address that.

Fixes https://github.com/huggingface/transformers/issues/39512


## 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#create-a-pull-request),
      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.

 @ArthurZucker


Comments:
Thanks for identifying the issue and opening a PR! This does speed up things quite a lot, but it's still around 6 times slower than without setting bad_words_ids 🤔 

Pretty much the same as just doing:
```py
            eos_token_id_list = eos_token_id.tolist() # convert to python list before
            bad_words_ids = list(
                filter(lambda bad_token_seq: all(bad_token_seq != [i] for i in eos_token_id_list), bad_words_ids)
            )
```

Though... I guess, since this is just done once (in the init function), 2 seconds vs 36 seconds is still much better!

Hi @ArthurZucker, the problem was in the `_prepare_bias_variables` method, in particular here https://github.com/huggingface/transformers/blob/3bc726b381592601cd9dd0fdcff5edcb02f3a85b/src/transformers/generation/logits_process.py#L1187-L1190

In the last commit I made, I modified it with a vectorized access and it's much faster, almost reaching the perfs when not using the `bad_words_ids` parameter.

Could you check the failing test:
```python
=========================== short test summary info ============================
FAILED tests/generation/test_logits_process.py::LogitsProcessorTest::test_no_bad_words_dist_processor - AssertionError: Lists differ: [[True, True, False, True, True], [True, True, True, False, True]] != [[True, True, False, True, False], [True, True, True, False, False]]

First differing element 0:
[True, True, False, True, True]
[True, True, False, True, False]

- [[True, True, False, True, True], [True, True, True, False, True]]
?                            ^^^                              ^^^

+ [[True, True, False, True, False], [True, True, True, False, False]]
?                            ^^^^                              ^^^^
============= 1 failed, 43 passed, 4 warnings in 107.08s (0:01:47) =============
```

Oops, my bad, the previous fix had a small bug, which I fixed using @xenova's  suggested code 🤗
We lose 0.1s on average with respect to the previous version, but at least it's correct. 


@bot /style

Style bot fixed some files and pushed the changes.

Thanks!