[tests] ensure device-required software is available in the testing environment before testing    
Author: faaany
Pull request: yes

## What does this PR do?
When running unit tests on XPU, I notice that some tests fail because the required software `intel_extension_for_pytorch` is not imported beforehand. The fact is that third-party devices (e.g. xpu) should be used together with third-party software libraries (e.g. IPEX). Therefore, same as in [this](https://github.com/huggingface/transformers/blob/main/src/transformers/testing_utils.py#L814) line, we should make sure that the software is available in the environment, otherwise, we should interrupt the program, because user wants to use `xpu`, but he doesn't take care of its testing environment, e.g. install the required library.

BTW, this is an example how I run test on XPU:
```bash
TRANSFORMERS_TEST_DEVICE="xpu" TRANSFORMERS_TEST_DEVICE_SPEC="spec.py" python -m pytest -rA tests/test_modeling_utils.py
```

## Who can review?
@ArthurZucker and @muellerzr 


Comments:
I'd expect the `try/except` following that to fail if it's not available, do you know why that's not the case? (When testing `torch.device()`)

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_29477). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

> I'd expect the `try/except` following that to fail if it's not available, do you know why that's not the case? (When testing `torch.device()`)

all devices in [this](https://github.com/pytorch/pytorch/blob/main/c10/core/Device.cpp#L17) list are valid values for `torch.device()`, but this doesn't guarantee the required hardware and software are available in the environment. If whenever I define `torch.device('cuda')` and it checks whether `CUDA` is available in the environment, it will slow down the software performance a lot. 

@muellerzr but thanks for the question. It reminds me that I should also add a check for the CUDA device as well. However, I am thinking whether it would be better that we just auto-detect the hardware and set the corresponding `torch_device` for users automatically, just like in `accelerate`?  Do you know why we have the variable `TRANSFORMERS_TEST_DEVICE` at all?

cc @ydshieh if you can have a look as well

Hi @ydshieh, could you take a look at this PR as well? Thank you so much! 

Thank you @faaany This indeed improves the error message in an earlier stage.

@amyeroberts Do you feel strong to make them using `requires_backends`? I don't feel strong, as these places are not really about a library/package's availability. Also, the current approach is more precise regarding the error message.

> Nice.
> 
> BTW, the file `docs/source/en/testing.md` has no mention of XPU, you might want to add it to that file for XPU visibility :-)

thanks for reminding me of the testing doc! Yes, I will submit a PR for XPU visibility and fix some typos and formatting stuff I noticed last time when reading through the doc. ;)  

@amyeroberts I am talking about the following block.

But let's keep as it is for now and revise in the future when necessary

```python
        if torch_device == "cuda" and not torch.cuda.is_available():
            raise ValueError(
                f"TRANSFORMERS_TEST_DEVICE={torch_device}, but CUDA is unavailable. Please double-check your testing environment."
            )
        if torch_device == "xpu" and not is_torch_xpu_available():
            raise ValueError(
                f"TRANSFORMERS_TEST_DEVICE={torch_device}, but XPU is unavailable. Please double-check your testing environment."
            )
        if torch_device == "npu" and not is_torch_npu_available():
            raise ValueError(
                f"TRANSFORMERS_TEST_DEVICE={torch_device}, but NPU is unavailable. Please double-check your testing environment."
            )
```