# Saving a model and loading it

**URL:** <https://discuss.huggingface.co/t/saving-a-model-and-loading-it/21492>\
**Category:** Models\
**Created:** [August 10, 2022, 5:50pm UTC](https://discuss.huggingface.co/t/saving-a-model-and-loading-it/21492 "2022-08-10T17:50:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel-Fipps](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@Samuel-Fipps](https://discuss.huggingface.co/u/Samuel-Fipps)\
**Post date:** [August 10, 2022, 5:50pm UTC](https://discuss.huggingface.co/t/saving-a-model-and-loading-it/21492/1 "2022-08-10T17:50:06Z")

</div>

So I am using this to get the model  
model = T5ForConditionalGeneration.from\_pretrained(“t5-small”)

then I try to save the model using  
model.save\_pretrained(“/home/myname/Desktop/”, from\_pt=True)

And I get the these files: config.json, pytorch\_model.bin

next i try to load the model using  
model = T5ForConditionalGeneration.from\_pretrained(“config.json”)

and i get the error:  
OSError: Unable to load weights from pytorch checkpoint file for ‘config.json’ at ‘config.json’. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from\_tf=True.

What am I doing wrong? Am i supposed to do something with the pytorch\_model.bin file ?

---

<div class="post-metadata">

**Author:** ![rwheel](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rwheel/32/5603_2.png) [@rwheel](https://discuss.huggingface.co/u/rwheel)\
**Post date:** [August 10, 2022, 7:33pm UTC](https://discuss.huggingface.co/t/saving-a-model-and-loading-it/21492/2 "2022-08-10T19:33:40Z")

</div>

Hi Samuel, you need to pass the folder with all the exported files to load the model. For example:

```auto
from transformers import T5ForConditionalGeneration

model = T5ForConditionalGeneration.from_pretrained("t5-small")

model.save_pretrained("/home/my_name/Desktop/t5small", from_pt=True) 

```

And then, you can load the model:

```auto
model = T5ForConditionalGeneration.from_pretrained("/home/my_name/Desktop/t5small")

```

---

<div class="post-metadata">

**Author:** ![Samuel-Fipps](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@Samuel-Fipps](https://discuss.huggingface.co/u/Samuel-Fipps)\
**Post date:** [August 10, 2022, 10:09pm UTC](https://discuss.huggingface.co/t/saving-a-model-and-loading-it/21492/3 "2022-08-10T22:09:30Z")

</div>

Thank you so much!! This caused me so much frustration! haha

---

<div class="post-metadata">

**Author:** ![DonManiek](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@DonManiek](https://discuss.huggingface.co/u/DonManiek)\
**Post date:** [July 5, 2024, 4:16pm UTC](https://discuss.huggingface.co/t/saving-a-model-and-loading-it/21492/5 "2024-07-05T16:16:10Z")

</div>

Hello guys. I’m new to NLP and I just have trained llama3 on Sentiment Classification and I want to save it. I already used the:  
trainer.save\_model(“saved\_model”)  
method. But it only saves the configuration files and I need to re-upload it every time I want to use it:

tokenizer = AutoTokenizer.from\_pretrained(checkpoint\_path)  
model = LlamaForSequenceClassification.from\_pretrained(checkpoint\_path, num\_labels=4)  
model.eval()

Which honestly makes me mad. Can I save the model with full weights (similarly, when I download the model using ollama)? Dose Hugging Face support this type of download?
