Improvement to error handling in subclasses
Author: BramVanroy
Pull request: no

### Feature request

I encountered a fascinating (though very frustrating :-)) scenario about error handling in `transformers`. When subclassing a tokenizer that relies on `sentencepiece`, and not having it installed, you will get an unhelpful error message that sends you down a lot of rabbit holes.

Consider this minimal example:

```python
from transformers import MBartTokenizer


class CustomMBartTokenizer(MBartTokenizer):
    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        inst = super().from_pretrained(*args, **kwargs)
        # Do other stuff with it...


a = CustomMBartTokenizer.from_pretrained("facebook/mbart-large-cc25")
```

If you run this in a new environment where sentencepiece is not installed, you get the following error:

> AttributeError: 'super' object has no attribute 'from_existing'

This error message had me comparing Windows vs. Linux and python 3.8 vs 3.9 vs 3.10 because I could not figure out why it was working on my home machine and not on our cluster. In the end, the reason was that `sentencepiece` was not yet installed on the cluster **but the error message does not show that**. It seems that the sentencepiece error does not show or does not stop execution, which then leads the class to not be successfully initialized. Although admittedly I have not dug much farther.

### Motivation

The error message does not seem to correctly propagate when subclassing a tokenizer. The error message that indicates that sentencepiece is not installed and needs to be installed is not correctly shown. Instead the user gets a vague error message about the `from_pretrained` call.

While this may be an exceptional case, I have found that subclassing tokenizers for a specific task is common in research.

### Your contribution

I do not have the time to work on figuring out what the exact cause is unfortunately. Posting this here for posterity. For anyone getting this issue: **you probably just need to make sure all necessary third party libraries (such as sentencepiece) are installed.**

Comments:
Interesting. It seems like Python gobbles the error raised by the super class (which does tell you to install sentencepiece) and decides it has no `from_pretrained` attribute instead.

If anyone has any idea to fix our metaclass `DummyObject` so it works on subclasses, I'm all ears!

Pinging here as we are seeing the same issue.

```
E           ImportError: 
E           XLMRobertaTokenizer requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the
E           installation page of its repo: https://github.com/google/sentencepiece#installation and follow the ones
E           that match your environment. Please note that you may need to restart your runtime after installation.
```

No this is not the same issue. The error message is clearly indicating that your need to install `sentencepiece`.

Yet it doesn't come up as a requirement from transformers - as described in the original post.

The sentencepiece library has to be added manually. Did I miss something about having to do that otherwise in the release notes?  This was discovered after updating to the latest version of transformers 2.24.0.

site-packages\transformers\models\xlm_roberta\tokenization_xlm_roberta.py

https://github.com/huggingface/transformers/blob/f3d99e49d459f9d1cc7544352041b3a64d68c734/src/transformers/models/xlm_roberta/tokenization_xlm_roberta.py#L22

Also, just a side note here, this occurred in multiple environments - Linux and Windows based.  I hope this helps.

And when running "pip show sentencepiece" locally, it shows as having no requires/requires-by - very odd.

I think `DummyObject` should override `__getattribute__` instead of `__getattr__` to get the expected error.

EDIT:

Tested locally, and it works. I've linked a PR with the fix.

Thanks @mariosasko!

@jacwalte That is the expected behavior. sentencepiece is not installed by default because not all tokenizers need it. You'll get the error message if you need it for your use-case and then you just have to install it manually. Or you can install transformers with the extra `sentencepiece`, `transformers[sentencepiece]`. The problem in my case was that the error message did not show up. This has now been quickly fixed by @mariosasko!

> Thanks @mariosasko!
> 
> @jacwalte That is the expected behavior. sentencepiece is not installed by default because not all tokenizers need it. You'll get the error message if you need it for your use-case and then you just have to install it manually. Or you can install transformers with the extra `sentencepiece`, `transformers[sentencepiece]`. The problem in my case was that the error message did not show up. This has now been quickly fixed by @mariosasko!

Thanks! - will update the requirements with that