# ImportError: cannot import name 'PreTrainedModel' from 'transformers'

**URL:** <https://discuss.huggingface.co/t/importerror-cannot-import-name-pretrainedmodel-from-transformers/167797>\
**Category:** Beginners\
**Created:** [August 27, 2025, 2:21am UTC](https://discuss.huggingface.co/t/importerror-cannot-import-name-pretrainedmodel-from-transformers/167797 "2025-08-27T02:21:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaydeepb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jaydeepb/32/14906_2.png) [@jaydeepb](https://discuss.huggingface.co/u/jaydeepb)\
**Post date:** [August 27, 2025, 2:21am UTC](https://discuss.huggingface.co/t/importerror-cannot-import-name-pretrainedmodel-from-transformers/167797/1 "2025-08-27T02:21:03Z")

</div>

Hi. This looks like an issue from peft side. I’m working with `mistralai/Mistral-Small-24B-Base-2501` model and trying to fine-tune it. But it throws `ImportError: cannot import name ‘PreTrainedModel’ from ‘transformers’`. My versions are transformers 4.55.4, tokenizers 0.21.4, peft 0.17.1. Is this a version incompatibility issue?

I downgraded transformers to 4.42.4, tokenizers to 0.19.1 and peft to 0.5.0 and it throws `Exception: data did not match any variant of untagged enum ModelWrapper at line 1217944 column 3`

---

<div class="post-metadata">

**Author:** ![jaydeepb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jaydeepb/32/14906_2.png) [@jaydeepb](https://discuss.huggingface.co/u/jaydeepb)\
**Post date:** [August 27, 2025, 3:01am UTC](https://discuss.huggingface.co/t/importerror-cannot-import-name-pretrainedmodel-from-transformers/167797/2 "2025-08-27T03:01:32Z")

</div>

Managed to solve this by using tokenizers-0.20.1 transformers-4.45.2 ([json - Tokenizer.from\_file() HUGGINFACE : Exception: data did not match any variant of untagged enum ModelWrapper - Stack Overflow](https://stackoverflow.com/a/79076471))

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [August 27, 2025, 3:02pm UTC](https://discuss.huggingface.co/t/importerror-cannot-import-name-pretrainedmodel-from-transformers/167797/3 "2025-08-27T15:02:11Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
