# Differences between Config.from\_pretrained and Model.from\_pretrained

**URL:** <https://discuss.huggingface.co/t/differences-between-config-from-pretrained-and-model-from-pretrained/8520>\
**Category:** 🤗Transformers\
**Created:** [July 20, 2021, 3:08pm UTC](https://discuss.huggingface.co/t/differences-between-config-from-pretrained-and-model-from-pretrained/8520 "2021-07-20T15:08:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alejandrocr](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@alejandrocr](https://discuss.huggingface.co/u/alejandrocr)\
**Post date:** [July 20, 2021, 3:08pm UTC](https://discuss.huggingface.co/t/differences-between-config-from-pretrained-and-model-from-pretrained/8520/1 "2021-07-20T15:08:40Z")

</div>

Hey there! I have a question regarding the differences between loading a multilingual BERT model from pretrained weights and from a pretrained Config:

Shouldn’t the two models defined below have the same weights?

```auto
from transformers import BertConfig, BertModel

mbert_model_1 = BertModel.from_pretrained("bert-base-multilingual-uncased")

mbert_config = BertConfig.from_pretrained("bert-base-multilingual-uncased")
mbert_model_2 = BertModel(mbert_config)

```

I have checked and they have the same architecture, but the layer weights (and the results obtained when using them) are different.

Sorry if it’s a well-known question but I had never loaded models from Configs and I’ve found this discrepancy. (I’ve looked for a previous question related to this topic but I haven’t found any).

Thanks for your help! 🤗

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [July 20, 2021, 8:25pm UTC](https://discuss.huggingface.co/t/differences-between-config-from-pretrained-and-model-from-pretrained/8520/2 "2021-07-20T20:25:23Z")

</div>

You should have a look at the relevant [section in the course](https://huggingface.co/course/chapter2/3?fw=pt) and the correspond [video](https://youtu.be/AhChOFRegn4) where all of this is explained.

The first model is initialized with the pretrained weights, the second is the same architecture but is initialized randomly.
