ValueError: Unrecognized model in ./trained_model. Should have a `model_type` key in its config.json

Hello everyone,

I recently encountered an issue while working with a locally saved finetuned model, and I was hoping to get some guidance. Here’s the situation:

  1. I used trainer.save_model() to save my finetuned model and was able to use it locally in my Anaconda environment without any problems.
  2. Later, I decided to create a requirements.txt file for my project. However, I noticed that my current environment had too many unnecessary packages.
  3. To address this, I deleted the old environment (which, in hindsight, was not the best decision) and created a new, cleaner environment to only install the packages I need.

After creating the new environment, I tried to load the saved model, but I keep running into the following error:

ValueError: Unrecognized model in ./trained_model. Should have a `model_type` key in its config.json, or contain one of the following strings in its name: albert, align, altclip...

Here are the details of my current Anaconda environment:

python = 3.11  
cuda version = 12.7  
pytorch-cuda = 12.1  

I would greatly appreciate any advice or insights on what might be causing this issue and how to resolve it. Thank you in advance for your help!

1 Like

Hmm, transformers seems the most suspicious…

pip install -U transformers accelerate peft huggingface_hub
1 Like

Thank you so much for your solution—it worked perfectly! :tada: I’ve been stuck on this for a while, I truly can’t thank you enough.

1 Like

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