transformers[tf-cpu] fails because torch isn't installed
Author: BrainSlugs83
Pull request: no
Labels: name: bug

### System Info

transformers-cli-env crashes, so I'm typing things manually, lmk if you need something specific.
```
Windows 10=19043.1826
Miniconda3=4.12.0
pip=22.1.2
python=3.9.13
cudatoolkit=11.3.1
cudnn=8.1.0.77
tensorboard=2.9.1
tensorboard-data-server=0.6.1
tensorboard-plugin-wit=1.8.1
tensorflow-cpu=2.9.1
tensorflow-estimator=2.9.0
tensorflow-io-gcs-filesystem=0.26.0
```
### Who can help?

@Rocketknight1 - looks like you are listed for tensorflow.  Apologies if this is wrong, or if I misinterpreted something.

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Follow the installation instructions for tf-cpu from the [documentation](https://www.tensorflow.org/install/pip#windows).
1. `conda create -n hf python=3.9 pip`
2. `conda activate hf`
3. `pip install transformers[tf-cpu]`
6. Verify tensorflow install: `python -c "import tensorflow as tf; print(tf.config.list_physical_devices('CPU'))"`
7. Verify the hugging face install `python -c "from transformers import AutoModelForSequenceClassification; model=AutoModelForSequenceClassification.from_pretrained('distilbert-base-uncased-finetuned-sst-2-english')"`

It fails complaining that torch is not installed. -- Yes I can create an env with torch, but ... the tf-cpu branch should be working with tensorflow not torch.
```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Mikey\miniconda3\envs\hf\lib\site-packages\transformers\utils\import_utils.py", line 821, in __getattr__
    requires_backends(cls, cls._backends)
  File "C:\Users\Mikey\miniconda3\envs\hf\lib\site-packages\transformers\utils\import_utils.py", line 809, in requires_backends
    raise ImportError("".join(failed))
ImportError:
AutoModelForSequenceClassification requires the PyTorch library but it was not found in your environment. Checkout the instructions on the
installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment.
```

I have also tried installing CUDA and CuDNN, but it did not have any effect.
`conda install -c conda-forge cudatoolkit=11.3 cudnn=8.1.0`

### Expected behavior

The tensorflow version of hugging face should work with tensorflow and not raise exceptions about torch being missing.

Comments:
Hi @BrainSlugs83, the issue there is that the `AutoModelForSequenceClassification` is actually a Torch class - if you want the TF version you should use `TFAutoModelForSequenceClassification`. Can you try that change and let me know if it fixes things?

I see, that's helpful to know -- I think it would fix it (though not for that specific model). -- And we can close this issue as PEBCAK on my part.  

(Definitely PEBCAK as this is documented, I just didn't notice it when I was trying to figure this out yesterday. 🤦🏻‍♂️ -- I really appreciate the guidance, so thank you @Rocketknight1. 🙂)

Though I would like to give the feedback (if you're open to it): 
 1. It seems like a missed opportunity for the Auto classes (i.e. it seems like the Auto classes are designed to look up the class that you actually need and hand that back to you, so as to promote code reuse.)
 
     Therefore, I feel like the auto classes *should* be able to know the difference and just hand you back a TF specific class if you're using TF or a Torch specific class if you're using Torch...

    Because, as-is, this prevents code-reuse (i.e. I can't share the same code between the two frameworks as they have different class names.)

 2. At the very least, it seems like the error message should be telling me to use a different class name, and not to be reinstalling my dev environment and switching ML stacks. 😅

Thank you again though -- I really appreciate the hand holding here!

@BrainSlugs83 Honestly, we like the idea! I'm going to draft a PR - I'll link you when it's ready.

@BrainSlugs83 PR is open at #18280!