Skip to content

Error saving GGUF of vision model #1504

Closed

Description

@SergioRubio01

Hey,
Congrat for the work!
I have a vision FT but when attempting to download the GGUF for Ollama usage, it gives me this exception:

Loading checkpoint shards: 100%|██████████| 2/2 [00:03<00:00,  1.57s/it]%|          | 0/2 [00:00<?, ?it/s]
2025-01-05 04:09:07,810 - ERROR - STDERR: max_steps is given, it will override any value given in num_train_epochs
2025-01-05 04:09:07,810 - ERROR - STDERR: ==((====))==  Unsloth - 2x faster free finetuning | Num GPUs = 1
2025-01-05 04:09:07,810 - ERROR - STDERR: \\   /|    Num examples = 54 | Num Epochs = 1
2025-01-05 04:09:07,820 - ERROR - STDERR: O^O/ \_/ \    Batch size per device = 2 | Gradient Accumulation steps = 4
2025-01-05 04:09:07,820 - ERROR - STDERR: \        /    Total batch size = 8 | Total steps = 5
2025-01-05 04:09:07,824 - ERROR - STDERR: "-____-"     Number of trainable parameters = 16,793,600
2025-01-05 04:09:07,826 - ERROR - STDERR: 🦥 Unsloth needs about 1-3 minutes to load everything - please wait!
100%|██████████| 5/5 [01:20<00:00, 16.08s/it]          | 0/5 [00:00<?, ?it/s]
2025-01-05 04:09:07,829 - ERROR - STDERR: Traceback (most recent call last):
2025-01-05 04:09:07,832 - ERROR - STDERR: File "/home/Ubuntu/finetune.py", line 145, in <module>
2025-01-05 04:09:07,833 - ERROR - STDERR: model.save_pretrained_gguf(MODEL_NAME, tokenizer)
2025-01-05 04:09:07,835 - ERROR - STDERR: File "/home/Ubuntu/miniconda3/lib/python3.12/site-packages/unsloth/save.py", line 2238, in not_implemented_save 
2025-01-05 04:09:07,836 - ERROR - STDERR: raise NotImplementedError("Unsloth: Sorry GGUF is currently not supported for vision models!")
2025-01-05 04:09:07,837 - ERROR - STDERR: NotImplementedError: Unsloth: Sorry GGUF is currently not supported for vision models!
2025-01-05 04:09:07,840 - ERROR - Command failed with non-zero exit status: bash -l -c 'eval "$(~/miniconda3/bin/conda shell.bash hook)" &&         conda activate &&         python3 finetune.py'

Is this being currently developed? Or is there another possible way of using my FT LLM models in Ollama?

I followed the steps from the Docs:

...
trainer_stats = trainer.train()

model.save_pretrained(MODEL_NAME) # Local saving
tokenizer.save_pretrained(MODEL_NAME)
# model.push_to_hub("your_name/lora_model", token = "...") # Online saving
# tokenizer.push_to_hub("your_name/lora_model", token = "...") # Online saving

used_memory = round(torch.cuda.max_memory_reserved()/1024/1024/1024, 3)
used_memory_for_lora = round(used_memory - start_gpu_memory, 3)
used_percentage = round(used_memory/max_memory*100, 3)
lora_percentage = round(used_memory_for_lora/max_memory*100,3)
print(f"{trainer_stats.metrics['train_runtime']} seconds used for training.")
print(f"Peak reserved memory = {used_memory} GB.")
print(f"Peak reserved memory for training = {used_memory_for_lora} GB.")
print(f"Peak reserved memory % of max memory = {used_percentage} %.")
print(f"Peak reserved memory for training % of max memory = {lora_percentage} %.")

# Save model in GGUF format
model.save_pretrained_gguf(MODEL_NAME, tokenizer)

Activity

  1. danielhanchen commented on Jan 10, 2025

    @danielhanchen
    Member

    Sorry on the delay - I'm planning to add GGUF support in the coming days!

  2. SecchiAlessandro commented on Feb 3, 2025

    @SecchiAlessandro

    Is it resolved?

  3. fitlemon commented on Feb 22, 2025

    @fitlemon

    I want to use finetuned vision models on CPU. Converting to GGUF doesn't work. What alternatives are there to use models on CPU?

  4. just4give commented on Mar 16, 2025

    @just4give

    Sorry on the delay - I'm planning to add GGUF support in the coming days!

    wondering if there is any update on this? I am trying to convert FT Vision model to GGUF for ollama and experiencing the same issue above.
    Is there any alternative anyone got working? Looks like gguf is not supported by llama.cpp for llama vision models either.

  5. weoieoeo commented on Mar 28, 2025

    @weoieoeo

    May I ask once again if this is currently being addressed?
    Mistral Small 3.1 and Qwen2.5_32B seem very promising. I can fine-tune them on a dedicated PC, but for inference, I need GGUF versions to partially offload workloads onto the CPU, as not all inference PCs have 24GB of VRAM.
    Thank you in advance!

  6. phiwi commented on Mar 31, 2025

    @phiwi

    Any news on this?

  7. AbhayaHanuma commented on Apr 19, 2025

    @AbhayaHanuma

    Facing the same issue. Any luck for anyone?

  8. JackCro02 commented on Apr 27, 2025

    @JackCro02

    Same issue.
    unsloth (versions unsloth-2025.3.19 and unsloth-2025.4.1) will not save gguf using the commands listed here:
    https://docs.unsloth.ai/basics/running-and-saving-models/saving-to-gguf
    Any luck anyone?

  9. karltrout commented on May 4, 2025

    @karltrout

    Having the same issue. Following.

  10. kaiu85 commented on May 6, 2025

    @kaiu85

    I'm experiencing the same issue when trying to save a fine-tuned version of Mistral-3.1-Small-Instruct-2503.

  11. weoieoeo commented on May 7, 2025

    @weoieoeo

    Hi kaiu85,

    this may be offtopic, but could you share a code snippet on how you finetuned Mistral 3.1 small? What is the structure of your vision dataset and how did you structure the instruction that includes prompt (1), image (2) and the desired answer (3)?

    Is it comparable to finetuning lama3.2_11B_Vision? Like here:

    Many thanks!

  12. sambhavnoobcoder commented on May 8, 2025

    @sambhavnoobcoder

    saw this as a recurrent issue , for all the folks out there facing this , could you lay down a simple reproducer for me? you can try out this branch : https://github.com/sambhavnoobcoder/unsloth/tree/GGUF-Save . wrote some basic tests myself , it seems to pass my version and understanding of the tests , i can look into this more clearly if any of you could lay down a clearer reproducer for the same . thanks .

  13. kaiu85 commented on May 8, 2025

    @kaiu85

    Thank you very much. This is a very basic training notebook, which reproduces my issue (completely based on your great tutorial notebooks): https://colab.research.google.com/drive/1a4lW9H-9PN_nhjjh9NNy0I_QhZk6XNMn?usp=sharing

  14. sambhavnoobcoder commented on May 8, 2025

    @sambhavnoobcoder

    thank you very much for the reproducer @kaiu85 . i'll aim to use your colab as a test for my branch , check out if it solves the issue for you and this reproducer , use this as a parameter and report back once successful on the same .

  15. sambhavnoobcoder commented on May 9, 2025

    @sambhavnoobcoder

    okay cool , so i think the fix is here @kaiu85 , i tried out your reproducer , modified it slightly with a different model (slightly smaller ) and tested with this script here , a slight modification of your original reproducer . this seems to be able to run and save everything successfully . Here is a reference of the screenshot of the colab where i tested this out :

    Image

    Do tell me if there is anything else you'd like to point out , i would look at that as well .

    also @danielhanchen , do you need this fixed in the project ? just confirming , because if you do , i'll raise a PR for the same . Awaiting your confirmation .

  16. just4give commented on Jul 8, 2025

    @just4give

    @sambhavnoobcoder can you please help understand what you did to successfully convert to gguf? I am using llama 3.2 11b vision instruct.

  17. chrisjohnson00 commented on Jul 28, 2025

    @chrisjohnson00

    okay cool , so i think the fix is here @kaiu85 , i tried out your reproducer , modified it slightly with a different model (slightly smaller ) and tested with this script here , a slight modification of your original reproducer . this seems to be able to run and save everything successfully . Here is a reference of the screenshot of the colab where i tested this out :
    Image

    Do tell me if there is anything else you'd like to point out , i would look at that as well .

    also @danielhanchen , do you need this fixed in the project ? just confirming , because if you do , i'll raise a PR for the same . Awaiting your confirmation .

    I used a slightly modified version of your script with the following mods, but was unable to get anything to save successfully:

    1. Removed vision_model_save_pretrained_gguf references as that seems to not be part of unsloth.save anymore
    2. Commented out use_flash_attention_2=False, as that seemed to cause all models to fail loading
    3. I added ("unsloth/gemma-3n-E2B-it", True, False) to models_to_try as this is the model I'm playing with

    This resulted in:

    Attempting to save model to GGUF in /tmp/tmpsq7tdnfq/model...
    Saving model and tokenizer to output directory...
    Error during GGUF conversion: save_to_gguf_generic() got multiple values for argument 'quantization_method'
    An unexpected error occurred during GGUF conversion.
    Error type: TypeError
    Error message: save_to_gguf_generic() got multiple values for argument 'quantization_method'
    Reproducer failed to demonstrate the issue.
    

    Switching quantization_method for quantization_type in the arguments of mode.save_pretrained_gguf (as suggested in other issues), resulted in

    Error type: TypeError
    Error message: Unsloth: quantization_method can only be a string or a list of strings
    

    Adding any value, string or list of strings to quantization_method, for example quantization_method=['fast_quantized'], provides me with:

    Error message: save_to_gguf_generic() got multiple values for argument 'quantization_method'
    

    Using unsloth==2025.7.8 in this test

  18. chrisjohnson00 commented on Jul 29, 2025

    @chrisjohnson00

    I'm fine tuning unsloth/gemma-3n-E2B-it and when I get to:

    model.push_to_hub_gguf("chrisjohnson00/xxx", tokenizer, token=os.environ['HF_TOKEN'])
    

    I debug traced it to the save_to_gguf_generic method call, and quantization_method is passing in as Gemma3nProcessor type, which causes it to fall into the TypeError clause.
    I'll continue looking into this, but am going on vacation after tomorrow, so can only give it another day of troubleshooting before I will likely move on to other projects for bit.

  19. chrisjohnson00 commented on Aug 18, 2025

    @chrisjohnson00

    Hi everyone, i think this link will help you to solve the problem, just folow the instructions https://docs.unsloth.ai/basics/tutorials-how-to-fine-tune-and-run-llms/tutorial-how-to-finetune-llama-3-and-use-in-ollama, and use thier colab notebook https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3_(8B)-Ollama.ipynb#scrollTo=95_Nn-89DhsL

    I followed the guides to get where I am. I'm not running with google colab, using my own environments. The colab notebooks are great, hard to convert to native Python, but are either missing some details that the colab env brings, or are incomplete.

  20. Guedd commented on Aug 25, 2025

    @Guedd

    Hi everyone, i think this link will help you to solve the problem, just folow the instructions https://docs.unsloth.ai/basics/tutorials-how-to-fine-tune-and-run-llms/tutorial-how-to-finetune-llama-3-and-use-in-ollama, and use thier colab notebook https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3_(8B)-Ollama.ipynb#scrollTo=95_Nn-89DhsL

    I followed the guides to get where I am. I'm not running with google colab, using my own environments. The colab notebooks are great, hard to convert to native Python, but are either missing some details that the colab env brings, or are incomplete.

    Hi, I have switched from using Unsloth's Built-in functions to manually converting the model. First, use the save_pretrained_merged function after finishing training, or loading a model with LORA weights and merging it using the same function. After merging, follow the manual steps to export the GGUF file using llama.ccp: https://github.com/unslothai/unsloth/wiki#manually-saving-to-gguf

    After the exporting, you have to create and edit the "modelfile", it's different from a model to another, depends on the starts, eos, end tokens, and special tokens, model Imstruction, and other, you can check some youtube video to learn, or give it to ChatGPT, or Gemini they will take care of the file

  21. Guedd commented on Aug 25, 2025

    @Guedd

    I want to use finetuned vision models on CPU. Converting to GGUF doesn't work. What alternatives are there to use models on CPU?

    Vsiom Model uses a GPU in the first place. If you are willing to use it for text-to-text conversation, then it wouldn't require a GPU, but for images, you have to use a GPU. After converting, push the model to your ollama Hub, or you can save it locally and use it with ollama as well.

  22. chrisjohnson00 commented on Aug 25, 2025

    @chrisjohnson00

    Hi everyone, i think this link will help you to solve the problem, just folow the instructions https://docs.unsloth.ai/basics/tutorials-how-to-fine-tune-and-run-llms/tutorial-how-to-finetune-llama-3-and-use-in-ollama, and use thier colab notebook https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3_(8B)-Ollama.ipynb#scrollTo=95_Nn-89DhsL

    I followed the guides to get where I am. I'm not running with google colab, using my own environments. The colab notebooks are great, hard to convert to native Python, but are either missing some details that the colab env brings, or are incomplete.

    Hi, I have switched from using Unsloth's Built-in functions to manually converting the model. First, use the save_pretrained_merged function after finishing training, or loading a model with LORA weights and merging it using the same function. After merging, follow the manual steps to export the GGUF file using llama.ccp: https://github.com/unslothai/unsloth/wiki#manually-saving-to-gguf

    After the exporting, you have to create and edit the "modelfile", it's different from a model to another, depends on the starts, eos, end tokens, and special tokens, model Imstruction, and other, you can check some youtube video to learn, or give it to ChatGPT, or Gemini they will take care of the file

    Thanks! Will try. I, understandably, only had one save_pretrained_merged call, so check this out. It may be days/weeks before I get back to this though, so no one hold your breath on my response!

  23. rolandtannous commented on Oct 15, 2025

    @rolandtannous
    Contributor

    @Any-Winter-4079 @FierceHero @Guedd @JackCro02 @JustinYuann @SecchiAlessandro @SergioRubio01 @chrisjohnson00 @ejektaflex @fitlemon @juanqui @just4give @kaiu85 @karltrout @mikeknapp @phiwi @sambhavnoobcoder @valentinfrlch @vishwa30 @weoieoeo

    We just pushed a major fix for llamacpp integration.

    1- Please make sure to update your local install of unsloth

    pip install --force-reinstall --no-deps unsloth-zoo unsloth
    

    If you're using a notebook on kaggle or colab, it should pull the latest version automatically.

    2- You can now use save_pretrained_gguf to quantize and save to GGUF format:

    model.save_pretrained_gguf(
                save_directory,
                tokenizer=tokenizer,
                quantization_method=quantization_method,
            )
    

    For vision/multimodal models, use tokenizer=processor

    3- You can pass it one or several quant methods (as a list):

    quantization_method = "q8_0"
    

    or

    quantization_method = ["q8_0", "q4_k_m"]
    

    We support all the quants mentioned in this page except the iq variants.

    4- If the model is supported by Ollama, it will now also automatically create a Modelfile for you that you can use to create your model in ollama using:

    ollama create model_name -f ./Modelfile
    

    5- Use push_to_hub_gguf if you want to convert to gguf and push to Huggingface Hub instead.

    6- Should work for all models supported by unsloth and ollama.

    7- It now fully supports linux debian and RPM variants. We are still testing windows (if someone has a windows machine and is on our discord channel ping me to help debug)

    Let me know.

    Thanks!

  24. rolandtannous commented on Oct 23, 2025

    @rolandtannous
    Contributor

    Will be closing this for now as the issue has been resolved. Please make sure to follow the instructions given in my last response.

    Meanwhile , please feel free to respond if you're still having any issues.

    Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions