Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load the finetuned model? #210

Open
code-iter opened this issue Jan 14, 2025 · 1 comment
Open

How to load the finetuned model? #210

code-iter opened this issue Jan 14, 2025 · 1 comment

Comments

@code-iter
Copy link

Hey mate. I've been having problems trying to load the finetuned model.safetensors. I've finetuned the model using the provided notebook script, and in the end after saving the model i got the following files:

  • config.json;
  • generation_config.json;
  • model.safetensors.

Now, i've tried to load the model using transformers but i keep getting errors. the last one was:

AttributeError: module 'transformers_modules.vikhyatk.moondream2.fb2293ab7450beb1dae536b069f5966becf58e5c.moondream' has no attribute 'Moondream'

i've tried many scripts to try and load the finetuned model.safetensors, like:

model = AutoModelForCausalLM.from_pretrained(
    pretrained_model_name_or_path=model_root_dir,
    use_safetensors=True,
    state_dict=load_file(model_path),
    config=model_config,  # Provide a configuration file for the model
    trust_remote_code=True,
)

But nothing seems to work. Could you help me on this?

@forensicmike
Copy link

forensicmike commented Jan 25, 2025

Hi, I had problems with this too, specifically it starting giving me pyvips errors again (I installed the pip package but there's a missing DLL, I presume this is why they are telling you to use revision = "2024-08-26" with transformers.)

I got around it by saving the text encoder only (an instance of PhiForCasualLM)

So after fine tuning, you can do:
model.text_model.save_pretrained('./models/phifortext-ft')
or even
torch.save(model.text_model.state_dict(), './models/textmodel-finetune.pt')

I was then able to load the model normally and call
model.text_model.load_state_dict(torch.load('g:/ai/_vdataset/models/phitext.pt', weights_only=False))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants