You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Impossible to convert Gemma3 4b into gguf #2399
I tried to save my fine-tuned gemma3 on HuggingFace in gguf format, I followed the unsloth's notebook but I have the following error when I run model.save_pretrained_merged("gemma-3-finetune", tokenizer)
NotImplementedError: Unsloth: llama.cpp GGUF conversion does not yet support converting model types of Gemma3ForConditionalGeneration.
I also have the same issues.
"NotImplementedError: Unsloth: llama.cpp GGUF conversion does not yet support converting model types of Gemma3ForCausalLM."
It was working until last week, but a few days ago it didn't work.
I used the unsloth/gemma-3-12-it model.
I hope it will be solved.
Is there any workaround for this issue?, It was working well at the beginning of April.
The model:
unsloth/gemma-3-4b-it
The error message:
/usr/local/lib/python3.11/dist-packages/unsloth_zoo/llama_cpp.py in convert_to_gguf(input_folder, output_filename, quantization_type, max_shard_size, print_output, print_outputs) 657 arch = config_file["architectures"][0] 658 if arch not in supported_types:--> 659 raise NotImplementedError( 660 f"Unsloth: llama.cpp GGUF conversion does not yet support "\ 661 f"converting model types of {arch}."NotImplementedError: Unsloth: llama.cpp GGUF conversion does not yet support converting model types of Gemma3ForCausalLM.
The error occurs when I try to run the following code:
model.save_pretrained_gguf(
"gemma-3-finetune",
quantization_type = "Q8_0",
)
If that's the case, here's how I made it work again:
I assume you have the following versions installed:
unsloth 2025.3.19
unsloth_zoo 2025.3.17
Delete llama.cpp from your local folder where your code is, download llama.cpp version b5137 and install it in your local folder:
wget https://github.com/ggml-org/llama.cpp/archive/refs/tags/b5137.zip
unzip b5137.zip
rm -rf llama.cpp b5137.zip
mv llama.cpp-b5137 llama.cpp
cd llama.cpp
# change this to ON if you have CUDA installed, but it's not mandatory just for fine-tuning
cmake -B build -DGGML_CUDA=OFF
cmake --build build --config Release
ln -s ./build/bin/llama-quantize llama-quantize
ln -s ./build/bin/llama-gguf-split llama-gguf-split
cd ..
Create unsloth_zoo.patch with this content:
diff -u unsloth_zoo.orig/llama_cpp.py unsloth_zoo/llama_cpp.py
--- unsloth_zoo.orig/llama_cpp.py 2025-03-14 08:02:07.000000000 -0700
+++ unsloth_zoo/llama_cpp.py 2025-04-24 15:31:20.129628636 -0700
@@ -32,8 +32,7 @@
import contextlib
import os
-LLAMA_CPP_CONVERT_FILE = \
- "https://github.com/ggerganov/llama.cpp/raw/refs/heads/master/convert_hf_to_gguf.py"
+LLAMA_CPP_CONVERT_FILE = "llama.cpp/convert_hf_to_gguf.py"
COMMANDS_NOT_FOUND = (
"command not found",
@@ -348,11 +347,12 @@
# All Unsloth Zoo code licensed under LGPLv3
# Downloads from llama.cpp's Github repo
try:
- converter_latest = requests.get(LLAMA_CPP_CONVERT_FILE).content
+ with open(LLAMA_CPP_CONVERT_FILE, 'rb') as f:
+ converter_latest = f.read()
except:
raise RuntimeError(
f"Unsloth: Could not obtain `{LLAMA_CPP_CONVERT_FILE}`.\n"\
- f"Maybe you don't have internet ocnnection?"
+ f"Is llama.cpp installed?"
)
# Get all supported models
Apply the patch:
patch -p0 -u < unsloth_zoo.patch
Now you have:
a patched unsloth_zoo-2025.3.17 that does not do sneaky downloads of external code anymore
a version of llama.cpp known to work with unsloth_zoo-2025.3.17
Restart your Jupyter kernels and try again.
Do not change or delete the folders llama.cpp and unsloth_zoo. Or, if you do, repeat the process above.
TLDR: Unsloth relies on external libraries, but it does not check properly when those dependencies change. Freezing the version of the dependency to a value known to work, and preventing the automatic downloads, might fix it.
If that's the case, here's how I made it work again:
I assume you have the following versions installed:我假設您安裝了以下版本:
unsloth 2025.3.19
unsloth_zoo 2025.3.17
Delete llama.cpp from your local folder where your code is, download llama.cpp version b5137 and install it in your local folder:
wget https://github.com/ggml-org/llama.cpp/archive/refs/tags/b5137.zip
unzip b5137.zip
rm -rf llama.cpp b5137.zip
mv llama.cpp-b5137 llama.cpp
cd llama.cpp
# change this to ON if you have CUDA installed, but it's not mandatory just for fine-tuning
cmake -B build -DGGML_CUDA=OFF
cmake --build build --config Release
ln -s ./build/bin/llama-quantize llama-quantize
ln -s ./build/bin/llama-gguf-split llama-gguf-split
cd ..
Download unsloth_zoo version 2025.3.17 and install it in your local folder. Your Python code will automatically import that instead of the installed unsloth_zoo Python module:
diff -u unsloth_zoo.orig/llama_cpp.py unsloth_zoo/llama_cpp.py
--- unsloth_zoo.orig/llama_cpp.py 2025-03-14 08:02:07.000000000 -0700
+++ unsloth_zoo/llama_cpp.py 2025-04-24 15:31:20.129628636 -0700
@@ -32,8 +32,7 @@
import contextlib
import os
-LLAMA_CPP_CONVERT_FILE = \
- "https://github.com/ggerganov/llama.cpp/raw/refs/heads/master/convert_hf_to_gguf.py"
+LLAMA_CPP_CONVERT_FILE = "llama.cpp/convert_hf_to_gguf.py"
COMMANDS_NOT_FOUND = (
"command not found",
@@ -348,11 +347,12 @@
# All Unsloth Zoo code licensed under LGPLv3
# Downloads from llama.cpp's Github repo
try:
- converter_latest = requests.get(LLAMA_CPP_CONVERT_FILE).content
+ with open(LLAMA_CPP_CONVERT_FILE, 'rb') as f:
+ converter_latest = f.read()
except:
raise RuntimeError(
f"Unsloth: Could not obtain `{LLAMA_CPP_CONVERT_FILE}`.\n"\
- f"Maybe you don't have internet ocnnection?"
+ f"Is llama.cpp installed?"
)
# Get all supported models
Apply the patch:
patch -p0 -u < unsloth_zoo.patch
Now you have:
a patched unsloth_zoo-2025.3.17 that does not do sneaky downloads of external code anymore
a version of llama.cpp known to work with unsloth_zoo-2025.3.17
Restart your Jupyter kernels and try again.
Do not change or delete the folders llama.cpp and unsloth_zoo. Or, if you do, repeat the process above.
TLDR: Unsloth relies on external libraries, but it does not check properly when those dependencies change. Freezing the version of the dependency to a value known to work, and preventing the automatic downloads, might fix it.TLDR:
@tw-evan [@hdiaztuesta Do not apply patches or follow instructions not coming from maintainers or contributors especially ones that encourage you to download an unverified version of Unsloth and Unsloth-zoo from sources not approved by the maintainers. You do this at your own peril. You risk and you will break your installation.
Root of the problem
This is unrelated to #issue 119. Issue #119 is about unsloth not working with the latest version of the llama.cpp (a fix will be released soon), while in here, and in contradiction to issue #119, you're being told to use a much older version of llama.cpp . Please don't do that.
The issue is not with unsloth being broken. Unsloth used llama.cpp for conversion to the GGUF format. Ollama being a wrapper around llama.cpp, was compatible with models converted using llama.cpp up and until Ollama version 0.6.2. After that version, the folks at Ollama seem to have made breaking changes. For VLMs such as gemma3, ollama now expects the visual projector file (mmproj) and the text model file (model) to be fused in a single file while llama.cpp still separates the two files. Look here for reference: https://github.com/ggml-org/llama.cpp/blob/master/docs/multimodal/gemma3.md
Small experiment (if you're curious)
You can manually test this by:
downloading the latest version of convert_hf_to_gguf.py
run the following sequence of instructions in the folder containing the model you wish to convert:
llama-mtmd-cli should be in the build/bin subfolder of your llama.cpp installation folder
model.gguf and mm-proj.gguf are the result of the conversion steps above.
You will notice that this will make gemma3 vision capabilities work with llama.cpp
Now try to run the same model with ollama. It won't work for the reasons I explained in the previous section.
Moving Forward
1- We are releasing a fix to make unsloth play nice with the breaking changes introduced in the latest llama.cpp conversion script. This should make any model you convert using _save_to_gguf() work with llama.cpp
2- Ollama issue is being worked on separately and a fix will be released afterwards.
Also a general reminder to adhere to the github code of conduct.
Hi @FlorinAndrei, we really appreciate you helping out! That said, it's generally not good practice to recommend users install patches from sources outside of the official Unsloth releases.
It would have been better to suggest the previous Unsloth version or suggest code changes instead. Recommending an external package or link can be risky, even if the source seems trustworthy.
Of course, I'm not saying the link you shared was dangerous - it's just a matter of maintaining standard safety practices. Thanks again for your support!
İnce ayarlı gemma3'ümü HuggingFace'te gguf formatında kaydetmeye çalıştım, unsloth'un not defterini takip ettim ancak model.save_pretrained_merged("gemma-3-finetune", tokenizer) çalıştırdığımda aşağıdaki hatayı alıyorum.
NotImplementedError: Unsloth: llama.cpp GGUF dönüştürmesi henüz 'nin model türlerinin dönüştürülmesini desteklemiyor.Gemma3ForConditionalGeneration
Öneri?
Not: model.push_to_hub_gguf kullanırken aynı hata
Hello, I also encountered this kind of problem and tried a different method for GGUF conversion as a solution, I hope it works for you too.
INFO:hf-to-gguf:Loading model: gemma-3_merged
INFO:hf-to-gguf:Model architecture: Gemma3ForCausalLM
INFO:gguf.gguf_writer:gguf: This GGUF file is for Little Endian only
INFO:hf-to-gguf:Exporting model...
INFO:hf-to-gguf:gguf: loading model weight map from 'model.safetensors.index.json'
INFO:hf-to-gguf:gguf: loading model part 'model-00001-of-00002.safetensors'
INFO:hf-to-gguf:token_embd.weight, torch.bfloat16 --> Q8_0, shape = {2560, 262208}
INFO:hf-to-gguf:blk.0.attn_norm.weight, torch.bfloat16 --> F32, shape = {2560}
...
INFO:hf-to-gguf:output_norm.weight, torch.bfloat16 --> F32, shape = {2560}
INFO:hf-to-gguf:Set meta model
INFO:hf-to-gguf:Set model parameters
Traceback (most recent call last):
File "/content/./llama.cpp/convert_hf_to_gguf.py", line 5957, in <module>
main()
File "/content/./llama.cpp/convert_hf_to_gguf.py", line 5951, in main
model_instance.write()
File "/content/./llama.cpp/convert_hf_to_gguf.py", line 402, in write
self.prepare_metadata(vocab_only=False)
File "/content/./llama.cpp/convert_hf_to_gguf.py", line 477, in prepare_metadata
super().prepare_metadata(vocab_only=vocab_only)
File "/content/./llama.cpp/convert_hf_to_gguf.py", line 392, in prepare_metadata
self.set_gguf_parameters()
File "/content/./llama.cpp/convert_hf_to_gguf.py", line 3733, in set_gguf_parameters
assert hparams.get("attn_logit_softcapping") is None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
I have finetuned gemma-4b and 12b. I can convert 4b to gguf with no issue. However, for 12b, I got the following error even though the environment, code is same.
NotImplementedError: Unsloth: llama.cpp GGUF conversion does not yet support converting model types of Gemma3ForCausalLM.
Note: I already tried all the possible quantization_methods.
I forgot to write it here, I have found my own way to handle this issue.
First problem was, when the storage is not enough, the save_pretrained_merged function throws an error where the log says completely different thing. I found out that issue by debugging the source code of unsloth.
Secondly, it is possible to convert that save finetuned model to gguf file by calling convert_to_gguf.py file in lama.cpp directly from cli.
@Elreniel you should be able to convert manually by cli . they recently updated the conversion script so the syntax might have changed and the docs are sort of hidden but conversion actually works.
Yes, yes all of my pipeline for all gemma models is working for now. I can finetune, convert to gguf and deploy it with ollama succesfully. Since its working with older version, i prefer not to touch it :D
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)
Just tested phi-4 and it worked nicely with llama.cpp and ollama.
Let me know how it goes for you.
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.
Activity
tw-evan commentedon Apr 23, 2025
I have the same issue!
marinewhlae commentedon Apr 24, 2025
I also have the same issues.
"NotImplementedError: Unsloth: llama.cpp GGUF conversion does not yet support converting model types of
Gemma3ForCausalLM."It was working until last week, but a few days ago it didn't work.
I used the unsloth/gemma-3-12-it model.
I hope it will be solved.
askie commentedon Apr 24, 2025
+1
hdiaztuesta commentedon Apr 24, 2025
Is there any workaround for this issue?, It was working well at the beginning of April.
The model:
unsloth/gemma-3-4b-it
The error message:
/usr/local/lib/python3.11/dist-packages/unsloth_zoo/llama_cpp.py in convert_to_gguf(input_folder, output_filename, quantization_type, max_shard_size, print_output, print_outputs) 657 arch = config_file["architectures"][0] 658 if arch not in supported_types:--> 659 raise NotImplementedError( 660 f"Unsloth: llama.cpp GGUF conversion does not yet support "\ 661 f"converting model types of
{arch}."NotImplementedError: Unsloth: llama.cpp GGUF conversion does not yet support converting model types ofGemma3ForCausalLM.The error occurs when I try to run the following code:
model.save_pretrained_gguf(
"gemma-3-finetune",
quantization_type = "Q8_0",
)
FlorinAndrei commentedon Apr 24, 2025
@hdiaztuesta It could be fallout from this bug:
unslothai/unsloth-zoo#119
If that's the case, here's how I made it work again:
I assume you have the following versions installed:
Delete
llama.cppfrom your local folder where your code is, download llama.cpp version b5137 and install it in your local folder:Create
unsloth_zoo.patchwith this content:Apply the patch:
Now you have:
Restart your Jupyter kernels and try again.
Do not change or delete the folders
llama.cppandunsloth_zoo. Or, if you do, repeat the process above.TLDR: Unsloth relies on external libraries, but it does not check properly when those dependencies change. Freezing the version of the dependency to a value known to work, and preventing the automatic downloads, might fix it.
hdiaztuesta commentedon Apr 25, 2025
Dear @FlorinAndrei ,
Thank you very much for your help. I will follow your instructions and try again.
Greetings.
tw-evan commentedon Apr 25, 2025
Hi, thank you for your help!
However, after following your suggestions, I encountered a runtime error when executing model.save_pretrained_gguf().
FlorinAndrei commentedon Apr 25, 2025
@tw-evan I think
model.save_pretrained_gguf()is a bit picky with the values. You putf16in there, but it only recognizes all-caps values, likeF16.BTW, you probably want
BF16in there instead of plainF16, unless you have a specific requirement for the format that I'm not aware of.rolandtannous commentedon Apr 26, 2025
@tw-evan [@hdiaztuesta Do not apply patches or follow instructions not coming from maintainers or contributors especially ones that encourage you to download an unverified version of Unsloth and Unsloth-zoo from sources not approved by the maintainers. You do this at your own peril. You risk and you will break your installation.
Root of the problem
This is unrelated to #issue 119. Issue #119 is about unsloth not working with the latest version of the llama.cpp (a fix will be released soon), while in here, and in contradiction to issue #119, you're being told to use a much older version of llama.cpp . Please don't do that.
The issue is not with unsloth being broken. Unsloth used llama.cpp for conversion to the GGUF format. Ollama being a wrapper around llama.cpp, was compatible with models converted using llama.cpp up and until Ollama version 0.6.2. After that version, the folks at Ollama seem to have made breaking changes. For VLMs such as gemma3, ollama now expects the visual projector file (mmproj) and the text model file (model) to be fused in a single file while llama.cpp still separates the two files. Look here for reference: https://github.com/ggml-org/llama.cpp/blob/master/docs/multimodal/gemma3.md
Small experiment (if you're curious)
You can manually test this by:
This will create a model.gguf file
Also run:
This will create a mmproj-model.gguf file.
To run gemma3 with vision capabilities in llama.cpp:
1- Make sure you build the latest version of llama.cpp
2- run:
llama-mtmd-cli should be in the build/bin subfolder of your llama.cpp installation folder
model.gguf and mm-proj.gguf are the result of the conversion steps above.
You will notice that this will make gemma3 vision capabilities work with llama.cpp
Now try to run the same model with ollama. It won't work for the reasons I explained in the previous section.
Moving Forward
1- We are releasing a fix to make unsloth play nice with the breaking changes introduced in the latest llama.cpp conversion script. This should make any model you convert using _save_to_gguf() work with llama.cpp
2- Ollama issue is being worked on separately and a fix will be released afterwards.
Also a general reminder to adhere to the github code of conduct.
shimmyshimmer commentedon Apr 27, 2025
Hi @FlorinAndrei, we really appreciate you helping out! That said, it's generally not good practice to recommend users install patches from sources outside of the official Unsloth releases.
It would have been better to suggest the previous Unsloth version or suggest code changes instead. Recommending an external package or link can be risky, even if the source seems trustworthy.
Of course, I'm not saying the link you shared was dangerous - it's just a matter of maintaining standard safety practices. Thanks again for your support!
anti-oksidan commentedon Apr 30, 2025
Hello, I also encountered this kind of problem and tried a different method for GGUF conversion as a solution, I hope it works for you too.
!git clone https://github.com/ggml-org/llama.cpp.git!python ./llama.cpp/convert_hf_to_gguf.py ./gemma_merged_folder --outfile ./gemma3-4b-it.gguf --outtype q8_0You can try it from the Colab address below.
https://colab.research.google.com/drive/1GWC0Tym3b-Fcr3IMtlcwNdKkp79mzMW1?usp=sharing
tw-evan commentedon May 1, 2025
Thank you all for your help, but I'm still running into an error.
Elreniel commentedon May 1, 2025
I have finetuned gemma-4b and 12b. I can convert 4b to gguf with no issue. However, for 12b, I got the following error even though the environment, code is same.
NotImplementedError: Unsloth: llama.cpp GGUF conversion does not yet support converting model types of
Gemma3ForCausalLM.Note: I already tried all the possible quantization_methods.
rolandtannous commentedon May 16, 2025
@Elreniel llama.cpp GGUF should now support Gemma3ForCausalLM. try again please
greenirvavril commentedon Jun 4, 2025
hello, I still get Unsloth: llama.cpp GGUF conversion does not yet support converting model types of
Gemma3ForCausalLMI tried with Gemma3 4b and 12b
rolandtannous commentedon Jun 4, 2025
@greenirvavril i just started working on all gguf conversion issues. this should be resolved soon. I will notify you guys when the PR is merged.
Elreniel commentedon Jun 4, 2025
Hey everyone,
I forgot to write it here, I have found my own way to handle this issue.
First problem was, when the storage is not enough, the save_pretrained_merged function throws an error where the log says completely different thing. I found out that issue by debugging the source code of unsloth.
Secondly, it is possible to convert that save finetuned model to gguf file by calling convert_to_gguf.py file in lama.cpp directly from cli.
rolandtannous commentedon Jun 4, 2025
@Elreniel you should be able to convert manually by cli . they recently updated the conversion script so the syntax might have changed and the docs are sort of hidden but conversion actually works.
Elreniel commentedon Jun 4, 2025
Yes, yes all of my pipeline for all gemma models is working for now. I can finetune, convert to gguf and deploy it with ollama succesfully. Since its working with older version, i prefer not to touch it :D
github-actions commentedon Jul 1, 2025
Is this issue still important to you? Apologies in advance we might have missed this issue as well. For faster response times, please post on our Reddit server - https://www.reddit.com/r/unsloth or our Discord - https://discord.com/invite/unsloth
rolandtannous commentedon Oct 23, 2025
@greenirvavril @Elreniel @tw-evan @aydndglr @hdiaztuesta @askie @marinewhlae
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)
Just tested phi-4 and it worked nicely with llama.cpp and ollama.
Let me know how it goes for you.
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