Return type annotation for PretrainedConfig.from_pretrained wrong?
Author: mauvilsa
Pull request: no

### System Info

- `transformers` version: 4.42.3
- Platform: macOS-14.5-x86_64-i386-64bit
- Python version: 3.9.16
- Huggingface_hub version: 0.23.4
- Safetensors version: 0.4.3
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): 2.0.0 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>


### Who can help?

@ydshieh @stevhliu

### Information

- [ ] 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

The problem is that the return type annotation for `PretrainedConfig.from_pretrained wrong` seems to be wrong. Currently it is `"PretrainedConfig"`, see [configuration_utils.py#L520](https://github.com/huggingface/transformers/blob/0abf5e8eaec361350888517f0d98501b2c5b2559/src/transformers/configuration_utils.py#L520). However, run the following

```
>>> from transformers import BertModel, PretrainedConfig
>>> pretrained=BertModel.from_pretrained("bert-base-uncased")
>>> type(pretrained)
<class 'transformers.models.bert.modeling_bert.BertModel'>
>>> isinstance(pretrained, PretrainedConfig)
False
```

On the other hand, the docstring says "Instantiate a [`PretrainedConfig`] (or a derived class) from a pretrained model configuration." Which seems to imply that the return type is correct, but then `BertModel` would be wrong because it doesn't return a configuration object, but the model already instantiated. If this is the case, I am not sure that `BertModel` is the only problem.

### Expected behavior

If the return type annotation were correct, then the `isinstance` statement should return `True`. Or it could return `False` but then response should always be a config object and not a model. Or maybe all the models should inherit from `PretrainedConfig`. I am not really sure what was the intention.

This probably requires some context to make clear why correct type annotations are important. In `pytorch-lightning` there is `LightningCLI`, which makes automatically configurable module classes (from yaml, command line, etc.). But for this to work correctly the types must be correct. See for more details https://github.com/Lightning-AI/pytorch-lightning/discussions/19863#discussioncomment-9978122

Comments:
Hi @mauvilsa, 

`BertModel` doesn't inherit from `PretrainedConfig`, it inherits from `BertPreTrainedModel` which itself inherits from `PreTrainedModel`. [PreTrainedModel.from_pretrained](https://github.com/huggingface/transformers/blob/0abf5e8eaec361350888517f0d98501b2c5b2559/src/transformers/modeling_utils.py#L2819) returns a pretrained model object (although this isn't type annotated). 

The equivalent for a pretrained config would be to use the model's config class:
```py
>>> from transformers import BertConfig, PretrainedConfig
>>> config = BertConfig.from_pretrained("bert-base-uncased")
>>> isinstance(config, PretrainedConfig)
True
```

Thanks for the fast response. Then what we need is to add the return annotation to [PreTrainedModel.from_pretrained](https://github.com/huggingface/transformers/blob/0abf5e8eaec361350888517f0d98501b2c5b2559/src/transformers/modeling_utils.py#L2819). This should be easily accepted, right?

Yep - would you like to open a PR to add this? You can ping me for review 

Sure, I can create a pull request.