# Properly loading a fine tuned model from directory

**URL:** <https://discuss.huggingface.co/t/properly-loading-a-fine-tuned-model-from-directory/857>\
**Category:** Intermediate\
**Created:** [August 25, 2020, 9:15am UTC](https://discuss.huggingface.co/t/properly-loading-a-fine-tuned-model-from-directory/857 "2020-08-25T09:15:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kasar3](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@kasar3](https://discuss.huggingface.co/u/kasar3)\
**Post date:** [August 25, 2020, 9:15am UTC](https://discuss.huggingface.co/t/properly-loading-a-fine-tuned-model-from-directory/857/1 "2020-08-25T09:15:42Z")

</div>

Hi everybody,

After reading the docs I still don’t really understand how should I load my saved model properly.

I fine tuned a CamembertForSequenceClassification.from\_pretrained model with some data, the results was good so I saved it using save\_pretrained(model\_path). Now I would like to use this model to do inference… I use these lines of code:

config = AutoConfig.from\_pretrained(model\_path)  
tokenizer = AutoTokenizer.from\_pretrained(model\_path)  
model = AutoModelForSequenceClassification.from\_config(config)

I now have several interogation:

1. If I tokenize a new sequence with tokenizer.encode\_plus(new\_seq), it doesn’t tokenize the sentence the way it did when I previously saved the model. I must precise all the params (max\_length…) to retrieve what I want. Is that normal?
2. If I load my saved model without using AutoModelForSequenceClassification but with AutoModel the model do not load a classification layer however I saved my model using this last layer. Is that also normal?

So I’m wondering how can I be sure that I load the exact same model with all the weights and params that I saved previously.

Thanks for everything! 🙂

---

<div class="post-metadata">

**Author:** ![valhalla](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/valhalla/32/4179_2.png) [@valhalla](https://discuss.huggingface.co/u/valhalla)\
**Post date:** [August 25, 2020, 9:32am UTC](https://discuss.huggingface.co/t/properly-loading-a-fine-tuned-model-from-directory/857/2 "2020-08-25T09:32:48Z")

</div>

1. Yes, you should pass the same params to tokenizer that you passed during training.
2. `AutoModel` won’t add the heads (classfication layer, LM head etc). Use proper AutoModel classes to get same weights and params i.e `AutoModelForSequenceClassification` for classification model, `AutoModelForCausalLM` for causal LM’s like GPT-2 etc

You can load the saved model using just `AutoModelForSequenceClassification.from_pretrained`, it’ll load the `config` itself. You should pass `config` explicitly when you want to change something in it.

---

<div class="post-metadata">

**Author:** ![kasar3](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@kasar3](https://discuss.huggingface.co/u/kasar3)\
**Post date:** [August 25, 2020, 9:41am UTC](https://discuss.huggingface.co/t/properly-loading-a-fine-tuned-model-from-directory/857/3 "2020-08-25T09:41:16Z")

</div>

Ok that’s clear, thank you very much for your answer.
