vectorize PrefixConstrainedLogitsProcessor
Author: erip
Pull request: yes

# 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 #25217 (in part).


## 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?
- [x] 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.

@gante 

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25276). All of your documentation changes will be reflected on that endpoint.

There's a silly shape thing happening here which I'll try to debug ASAP (unless others are interested). Unfortunately testing locally is not working since I'm on Silicon and some dependencies for dev aren't available ☹️  but this looks close. I'll want to think hard about the vectorization of the function (which is slightly different and hopefully not breaking).

@erip thank you for jumping into the issue 💪  LMK when it is ready for review (assuming it yields speedups)

I believe it'll yield some improvements since there will be much less CPU<->GPU with masking ops. Whether they're significant will be hard to measure. My big concern is that the semantics of the prefix fn will change slightly (reflected in the test); whether this is acceptable is unclear.

Worst case scenario, a flag could be set at init time (of the logits processor), if the function supports vectorization

cc @gante I think this is ready for review. Nothing too controversial here, but I can add a fallback to original behavior in case the fn doesn't support vectorization. I'd like to test the speedup eventually, but I think this won't incur regressions at the very least.

Hmm, I just tested this hoping to benchmark against the original unvectorized impl and it seems like it's not quite ready.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.