[Fix]: Send model output to cpu before numpy cast in token_clf_pipeline
Author: ierezell
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 #13816


## 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/master/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/)? https://github.com/huggingface/transformers/issues/13816
- [X] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation). No docs changes
- [X] Did you write any new necessary tests? No additional test needed


## Who can review?
 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.

Library:

- pipelines: @LysandreJik

Comments:

@Narsil  Do you want me to also add a test (all currents tests are passing) ?

in `tests/test_pipelines_token_classification.py` like : 
```python
@require_torch_gpu
@slow
def test_correct_devices(self):
    sentence = "This dummy sentence checks if all the variables can be loaded on gpu and bring back to cpu"
    ner = TokenClassificationPipeline(model="distilbert-base-cased", device=0)    
```

Have a great day

Hi @Ierezell .

Unfortunately this fix is not desirable, as we're trying to have all "CPU/GPU" logic be contained inside the `Pipeline` class (in `src/transformers/pipelines/base.py`).

I added another proposed fix (the test is still not ran as part of the unit tests (it's still slow) pinging @LysandreJik for advice on if/how we can make GPU tests part of the unit tests.

(I also added you as co-author as you figured out the issue and a solid fix)

HI @Narsil, indeed it seems better to handle all the logic in the same place. I should've checked before. 

I looked at your fix and it's perfect for me. 

For the test, unfortunately, even if it's only a really small computation, the test needs GPU... Is it this bad to have it only as CI/CD test and not as a unit test? 

Thanks for keeping me as coauthor. 

Have a great day! 

Making ALL pipeline tests GPU as unit regular tests is something that was already raised internally.

Currently pipeline tests are relatively fast, so it really is doable. Slow tests are run on every release + once a day if I am not mistaken so it's already something.


Closing as resolved by #13856. Let me know if you'd like to reopen this.