PreTrained (custom) model not correctly initializing when using AutoModel methods
Author: mar-wel
Pull request: no

## Environment info

- `transformers` version: 3.1.0
- Platform: Windows-10-10.0.18362-SP0
- Python version: 3.8.5
- PyTorch version (GPU?): 1.6.0 (True)
- Tensorflow version (GPU?): 2.3.0 (True)
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: ???

### Who can help
@LysandreJik 

## Information

Model I am using (Bert, XLNet ...): bert-base-uncased, roberta-base, albert-large-v2

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [X] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [X] my own task or dataset: (give details below)

## To reproduce

(Conceptual) steps to reproduce the behavior:

1) Derive a custom model from a "PreTrainedModel" like:

class TransformerLSTMDocClassifier(PreTrainedModel):

    def __init__(self, model_config: AutoConfig):
        
        super(TransformerLSTMDocClassifier, self).__init__(model_config)
        self.transformer = AutoModel.from_config(model_config)
        self.dropout = nn.Dropout(p=model_config.hidden_dropout_prob)
        self.lstm = LSTM(model_config.hidden_size, model_config.hidden_size)
        self.classifier = nn.Sequential(
                        nn.Dropout(p=model_config.hidden_dropout_prob),
                        nn.Linear(model_config.hidden_size, model_config.num_labels),
                        nn.Tanh()
                    )

2) Train (fine-tune) the custom model starting from a pre-trained (standard) model such as bert-base-uncased, roberta-base, albert-large-v2 (using AutoModel features). My objective is to easily exchange the 'transformer' part in the above model

3) Initializing the model class 'TransformerLSTMDocClassifier' via the 'from_pretrained' method with the fine-tuned model (output of step 2) results in the message:

Some weights of TransformerLSTMDocClassifier were not initialized from the model checkpoint at <MODEL_CHECKPOINT> and are newly initialized: [...]

The list of weights apparently includes ALL weights of the TransformerLSTMDocClassifier  (200+in case of using bert-base_uncased)

## Expected behavior

Properly initialized weights

## Addendum

Disclaimer: I am a novice in the "transformers" framework. The above described (unexpected) behavior might result from an incorrect use of 'transformers' features/methods at my end.

However, I was digging a bit in the code and made the following observations:

(1) in case of deriving the custom model from a specific class (e.g. BertPreTrainedModel in case of using bert-base-uncased) instead from the generic class 'PreTrainedModel', the custom model is correctly initialized.

(2) the 'cls.base_model_prefix' (module: modeling_utils; method: from_pretrained) is "" (empty string) in case the custom model is derived from "PreTrainedModel", resulting in 'has_prefix_module' being set to 'True' in line 925, finally resulting in an inappropriate 'start_prefix' (apparently preventing that weights are matched/loaded).


Comments:
Could you set your logging level to `INFO` and show us the results?

You can put the following lines above your script:
```py
from transformers import logging

logging.set_verbosity_info()
```

It would really help us debug if you could also put a small script that reproduces the issue, so that we can easily reproduce and help you.

While trying putting together a minimal sample as you requested, I finally realized that the issue is on my side: as a novice in pytorch, I didn't expect that model (object) names in the code have to match (sub)models (e.g. base_model_prefix).

With a BERT configuration in the above AutoModel example, I replaced

self.transformer = AutoModel.from_config(model_config)

by

self.bert = AutoModel.from_config(model_config)

and it basically worked as expected. 

However, this constraint somehow limits my flexibility in "just" replacing the transformer part in my custom model.

Glad you got it to work!