Repository navigation
Description
Im having problems saving GGUFs of Gemma 3 finetunes. I was having this problem on my container environment and assumed I was having issues while training that caused other files to be generated but I am not. I have an almost identical Jypiter notebook as the one on the blog, yet I still cannot get model.save_pretrained_gguf() to run successfully with Gemma 3 models. In fact, it doesn't even work on the current version of the notebooks on the blog!
I have tried multiple methods of generating the config.json files
model.save_pretrained("Careconnect-gemma-3-4b-it")
tokenizer.save_pretrained("Careconnect-gemma-3-4b-it")
model.config.save_pretrained("Careconnect-gemma-3-4b-it") # Try to ensure config is saved config is saved
from transformers import AutoConfig
# Force auto generate because model.config.save_pretrained() isn't working
config = AutoConfig.from_pretrained("Careconnect-gemma-3-4b-it")
config.save_pretrained("Careconnect-gemma-3-4b-it")
Doing this, I was able to generate a config.json. However, an issue which I believe stems from limitations to external internet access on my container, still will be unable to run the model.save_pretrained_gguf(). Supposedly due to internet access, possibly not related to the config issue.
Unsloth: Updating system package directories
Unsloth: Install GGUF and other packages
RuntimeError: Unsloth: Could not obtain https://github.com/ggerganov/llama.cpp/raw/refs/heads/master/convert_hf_to_gguf.py. Maybe you don't have internet ocnnection?
Traceback:
File "Cell [cell17]", line 1, in <module>
model.save_pretrained_gguf(
File "/opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
File "/opt/conda/lib/python3.10/site-packages/unsloth/save.py", line 2246, in save_to_gguf_generic
metadata = _convert_to_gguf(
File "/opt/conda/lib/python3.10/site-packages/unsloth_zoo/llama_cpp.py", line 653, in convert_to_gguf
conversion_filename, supported_types = _download_convert_hf_to_gguf()
File "/opt/conda/lib/python3.10/site-packages/unsloth_zoo/llama_cpp.py", line 353, in _download_convert_hf_to_gguf
raise RuntimeError(
As a work around I simply run the llama.cpp convert_hf_to_gguf.py python script and get this output.
python convert_hf_to_gguf.py Careconnect-gemma-3-4b-it --outtype q8_0 --outfile ./gguf_model
INFO:hf-to-gguf:Loading model: Careconnect-gemma-3-4b-it
INFO:gguf.gguf_writer:gguf: This GGUF file is for Little Endian only
INFO:hf-to-gguf:Has vision encoder, but it will be ignored
INFO:hf-to-gguf:Exporting model...
INFO:hf-to-gguf:Set meta model
INFO:hf-to-gguf:Set model parameters
INFO:hf-to-gguf:Set model tokenizer
INFO:gguf.vocab:Setting special token type bos to 2
INFO:gguf.vocab:Setting special token type eos to 106
INFO:gguf.vocab:Setting special token type unk to 3
INFO:gguf.vocab:Setting special token type pad to 0
INFO:gguf.vocab:Setting add_bos_token to True
INFO:gguf.vocab:Setting add_eos_token to False
INFO:gguf.vocab:Setting chat_template to {{ bos_token }}
{%- if messages[0]['role'] == 'system' -%}
{%- if messages[0]['content'] is string -%}
{%- set first_user_prefix = messages[0]['content'] + '
' -%}
{%- else -%}
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '
' -%}
{%- endif -%}
{%- set loop_messages = messages[1:] -%}
{%- else -%}
{%- set first_user_prefix = "" -%}
{%- set loop_messages = messages -%}
{%- endif -%}
{%- for message in loop_messages -%}
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif -%}
{%- if (message['role'] == 'assistant') -%}
{%- set role = "model" -%}
{%- else -%}
{%- set role = message['role'] -%}
{%- endif -%}
{{ '<start_of_turn>' + role + '
' + (first_user_prefix if loop.first else "") }}
{%- if message['content'] is string -%}
{{ message['content'] | trim }}
{%- elif message['content'] is iterable -%}
{%- for item in message['content'] -%}
{%- if item['type'] == 'image' -%}
{{ '<start_of_image>' }}
{%- elif item['type'] == 'text' -%}
{{ item['text'] | trim }}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{ raise_exception("Invalid content type") }}
{%- endif -%}
{{ '<end_of_turn>
' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{'<start_of_turn>model
'}}
{%- endif -%}
INFO:hf-to-gguf:Set model quantization version
INFO:gguf.gguf_writer:Writing the following files:
INFO:gguf.gguf_writer:gguf_model: n_tensors = 0, total_size = negligible - metadata only
Writing: 0.00byte [00:00, ?byte/s]
INFO:hf-to-gguf:NOTE: this script only convert the language model to GGUF
INFO:hf-to-gguf: for the vision model, please use gemma3_convert_encoder_to_gguf.py
INFO:hf-to-gguf:Model successfully exported to gguf_model
Writing 0.00bytes? 0:00 seconds? This cannot be right! The generated .gguf file is also only 6.3MB!
-rw-r--r--. 1 root root 6.3M Mar 19 01:54 /home/app/Careconnect-gemma-3-4b-it.gguf
This could be a problem with llama.cpp Gemma 3 GGUF and not Unsloth. But considering the issue is even appearing on the Colab Notebooks I believe this issue should be looked into by more people / devs. I see that Unsloth does have Hugging Face repositories with the GGUF files, so there should be a workaround.
Activity
l-lorne-n commentedon Mar 19, 2025
same problem!
eljanmahammadli commentedon Mar 19, 2025
Facing the same issue. Even after I create
config.jsonmanually I am getting the following error:JdoubleU2 commentedon Mar 19, 2025
Yeah, it doesn't seem like the config file gets generated correctly with gemma3. Hope they can fix this soon
l-lorne-n commentedon Mar 21, 2025
hey,guys! I think i might find the answer:
try: merged_model = model.merge_and_unload() #after(trainer_stats = trainer.train())
then: merged_model.save_pretrained("the position you want to preserve")
tokenizer.save_pretrained("the position you want to preserve")
after that ,config.json will exist
finally: model.save_pretrained_gguf(
"the position you want to preserve",
quantization_type = "Q8_0",
)
danielhanchen commentedon Mar 22, 2025
Let me investigate the issue - apologies on the error!
jonmorton commentedon Mar 23, 2025
Has anyone figured this one out? I can't get gguf export of gemma3 or phi-4 models to work.
sanshaoyeyang commentedon Mar 25, 2025
fix it pls
stathamos commentedon Mar 25, 2025
Facing the same issue. Cannot generate gguf from Gemma 3 finetuning.
hcstubbe commentedon Mar 30, 2025
Try different quantizations: I find, that for gemma-3-27b-it-unsloth-bnb-4bit gguf can be created using BF16 and F16, but not Q8_0. For the 1bit and 27 bit models, all three currently supported quantizations ("Q8_0", "BF16", and "F16") work.
I run this in a docker container (here is the docker file for the respective image) with an h100.
shimmyshimmer commentedon Apr 2, 2025
@JuanMao-CuSO4 @rust17 just moving the conversation here thank you :)
pooja-singh-scm commentedon Apr 3, 2025
I used an additional save_pretrained_merged function call as a workaround. It creates the config.json correctly, and the subsequent gguf creation goes through.
model.save_pretrained_merged("gemma-3-finetune", tokenizer)
model.save_pretrained_gguf(
"gemma-3-finetune",
quantization_type = "Q8_0",
)
Jordinia commentedon May 12, 2025
I have the same issue. Not using Gemma but this I found other issues but got referenced to this thread. I have finished training Qwen3 4B and Llama 3.2 3B but I have not found a way to export to GGUF. I don't know if its my skill issue but I tried on almost everything it does not work.
Hardware config I have tried out:
When I run
model.save_pretrained_ggufhere is the error I got (on Windows, different error on WSL Ubuntu and Arch):I did able to export lora adapter using
and I can reload it consistently using this code:
and if I want to inference, I can just call
model = FastLanguageModel.for_inference(model)and try inference as usual.The problem comes when I try to convert to GGUF to test it on Ollama.
model.save_pretrained_gguf("dir", tokenizer, quantization_method = "f16")does not work anywhere I tried, and I'm unable to replicate it in Google Colab since the default Nvidia T4 does not support BF16. I do follow the tutorial to manually save GGUF by using llama.cpp (building llama.cpp is horrible) but I managed to run something like this:I tried loading it to Ollama and running directly on llama.cpp but the result is bad, and I think the model corrupted in the process of either saving to hf or converting to GGUF. I don't know what configuration I'm missing or since I'm training with 4bit should I change the save_method or quantization I'm also not sure. Any help would be much appreciated.🙏
hcstubbe commentedon May 13, 2025
Your error message states that compiling llama.cpp using unsloth fails. You should get the llama.cpp repo, locate it in the folder where you execute your unsloth python code (same working directory) and compile llama.cpp there.
In ubuntu (e.g. WSL) with CUDA support you can do that like this:
P.S.: I use a docker image with these install instructions and converting Qwen3 to gguf works.
jonmorton commentedon Jun 4, 2025
One problem is that there are two different gguf export functions, and if there is no "config" property in the model, only the generic one is used. The generic one doesn't create a ollama Modelfile, etc.
unsloth/unsloth/save.py
Lines 2524 to 2540 in 6ebef50
How does this config property get created? Why doesn't it exist for qwen2.5 coder for example?
jonmorton commentedon Jun 4, 2025
Actually, I found the issue for me at least - if you are loading in 8bit or doing full fine tuning,
FastLanguageModel.from_pretrainedis redirected toFastModel.from_pretrainedwhich usesFastBaseModel.from_pretrained. FastBaseModel is in vision.py and assumes the model is a vision model, so the unsloth specific functions are not used.As it turns out, I never get errors about config.json when using the unsloth export method.
rolandtannous commentedon Jun 30, 2025
Hello ,
The save_pretrained_merged method has been updated and fixed.
Please make sure to upgrade your installation to the latest version using
Will close this for now.
Please feel free to comment back if you are still facing the same issue after trying the above.
Thank you for using Unsloth
crisdesivo commentedon Jul 21, 2025
I am having the same issue with Qwen3 1.7b
thewh1teagle commentedon Sep 30, 2025
I experience the same issue with gemma3-270m
Vivek-RKD commentedon Sep 30, 2025
Can confirm that. I tried the official finetuning notebook (link) for gemma3-270m and faced the same export issue for gguf for all quantizations (Q8_0, BF16, F16).
rolandtannous commentedon Sep 30, 2025
Hello,
please note that I recently pushed a couple of PRs to solve saving to GGUF in unsloth for linux systems as well as colab and kaggle. I've just linked them up.
They're being reviewed and should be merged this week. Will ping you all once it's done.
rolandtannous commentedon Oct 15, 2025
@DaAe-Lee @JacksonDescant @JdoubleU2 @Jordinia @OmarJ9 @Shrijeeth @TheSittingCat @Vivek-RKD @a-chris @andresgr96 @crisdesivo @eljanmahammadli @epie-godfred @fabiochiusano @frikishaan @fungiboletus @hcstubbe @jonmorton @l-lorne-n @plkumar @pooja-singh-scm @robert-bor @sanshaoyeyang @stathamos @stevechk @thash-ai @thewh1teagle @vinhnx @younik
@C-rypto
We just pushed a major fix for llamacpp integration.
1- Please make sure to update your local install of 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_ggufto quantize and save to GGUF format:For vision/multimodal models, use
tokenizer=processor3- You can pass it one or several quant methods (as a list):
or
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
Modelfilefor you that you can use to create your model in ollama using:5- Use
push_to_hub_ggufif 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)
Thanks!
thewh1teagle commentedon Oct 19, 2025
@rolandtannous
Thanks for the update! I just tried now to export the model to GGUF, and it does create the Modelfile now, but it lacks the chat template / system prompt, it just have basic Modelfile without the pre configured prompt.
Details
I had to manually create Modelfile like this one
Details
rolandtannous commentedon Oct 23, 2025
@thewh1teagle the modelfile created by unsloth is correct and is in the ollama standard format for gemma3 .
It originates from here: https://ollama.com/library/gemma3:270m/blobs/4b19ac7dd2fb
Ollama uses its own format that you need to follow when writing the model file or writing a custom model file as you just did here :)
Will be closing this for now as the original 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