# Using Trainer to save a Bartforsequenceclassification model

**URL:** <https://discuss.huggingface.co/t/using-trainer-to-save-a-bartforsequenceclassification-model/81606>\
**Category:** Beginners\
**Created:** [April 13, 2024, 10:10pm UTC](https://discuss.huggingface.co/t/using-trainer-to-save-a-bartforsequenceclassification-model/81606 "2024-04-13T22:10:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![animeshk](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animeshk](https://discuss.huggingface.co/u/animeshk)\
**Post date:** [April 13, 2024, 10:10pm UTC](https://discuss.huggingface.co/t/using-trainer-to-save-a-bartforsequenceclassification-model/81606/1 "2024-04-13T22:10:16Z")

</div>

```auto
trainer.train()
trainer.save_model()

```

It gives me the error:

> modeling\_utils.py", line 2546, in save\_pretrained  
> raise RuntimeError(  
> RuntimeError: The weights trying to be saved contained shared tensors [{‘model.shared.weight’, ‘model.encoder.embed\_tokens.weight’, ‘model.decoder.embed\_tokens.weight’}] that are mismatching the transformers base configuration. Try saving using `safe_serialization=False` or remove this tensor sharing.

Could anyone please tell me why is it happening? and how to solve it without using that safe\_serialization=False?

---

<div class="post-metadata">

**Author:** ![saheedniyi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/saheedniyi/32/30429_2.png) [@saheedniyi](https://discuss.huggingface.co/u/saheedniyi)\
**Post date:** [August 12, 2024, 7:26pm UTC](https://discuss.huggingface.co/t/using-trainer-to-save-a-bartforsequenceclassification-model/81606/2 "2024-08-12T19:26:02Z")

</div>

How were you abe to resolve it? I’m facing a similar error!

---

<div class="post-metadata">

**Author:** ![Chahnwoo](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Chahnwoo](https://discuss.huggingface.co/u/Chahnwoo)\
**Post date:** [August 13, 2024, 2:22am UTC](https://discuss.huggingface.co/t/using-trainer-to-save-a-bartforsequenceclassification-model/81606/3 "2024-08-13T02:22:38Z")

</div>

It seems to be an issue with compatibility? There is a brief explanation on the HuggingFace [SafeTensors page](https://huggingface.co/docs/safetensors/torch_shared_tensors#why-are-shared-tensors-not-saved-in-safetensors-) which seems to suggest that shared tensors is a torch-specific feature that isn’t compatible with HuggingFace.

A [similar problem](https://github.com/huggingface/transformers/issues/27293#issuecomment-1815352570) was resolved by setting `safe_serialization=False` but I couldn’t find any other work around and the SafeTensors page seems to suggest that unless HuggingFace addresses this, there really isn’t any other approach.

---

<div class="post-metadata">

**Author:** ![HarsimarSingh](https://avatars.discourse-cdn.com/v4/letter/h/4bbf92/32.png) [@HarsimarSingh](https://discuss.huggingface.co/u/HarsimarSingh)\
**Post date:** [August 13, 2024, 8:14am UTC](https://discuss.huggingface.co/t/using-trainer-to-save-a-bartforsequenceclassification-model/81606/4 "2024-08-13T08:14:35Z")

</div>

It looks like you have introduced a new layer in your model. Is it so?
