Repository navigation
Closed
Description
Description
When I run the following code:
if True:
model.push_to_hub_gguf(
"my/Repo",
tokenizer,
quantization_method = ["q4_k_m", "q8_0", "q5_k_m",],
token = "hf_myTokenIputHere",
)- Environment Setup:
- Google Colab
- Environment setup:
%%capture
import os
if "COLAB_" not in "".join(os.environ.keys()):
!pip install unsloth
else:
# Do this only in Colab notebooks! Otherwise use pip install unsloth
!pip install --no-deps bitsandbytes accelerate xformers==0.0.29.post3 peft trl==0.15.2 triton cut_cross_entropy unsloth_zoo
!pip install sentencepiece protobuf datasets huggingface_hub hf_transfer
!pip install --no-deps unsloth- Dataset Details:
- Dataset Name: Sweaterdog/Andy-4-FT
- Data Preprocessing Steps: ChatML setup, with ShareGPT style dataset
# Load the first dataset and map it to the ShareGPT format
from unsloth.chat_templates import get_chat_template
tokenizer = get_chat_template(
tokenizer,
chat_template = "chatml", # Supports zephyr, chatml, mistral, llama, alpaca, vicuna, vicuna_old, unsloth
mapping = {"role" : "from", "content" : "value", "user" : "human", "assistant" : "gpt"}, # ShareGPT style
map_eos_token = True, # Maps <|im_end|> to </s> instead
)
def formatting_prompts_func(examples):
convos = examples["conversations"]
texts = [tokenizer.apply_chat_template(convo, tokenize = False, add_generation_prompt = False) for convo in convos]
return { "text" : texts, }
pass
from datasets import load_dataset
dataset = load_dataset("Sweaterdog/Andy-4-FT", split = "train")
dataset = dataset.map(formatting_prompts_func, batched = True,)-
Model Details:
- Model ID:
unsloth/llava-v1.6-mistral-7b-hf-bnb-4bit - Model Configuration: Only fine tuning text layer. LoRA rank of 32, LoRA alpha of 128
- Model ID:
-
Training Configuration:
- Trainer Args:
SFTConfig
- Trainer Args:
from transformers import TrainingArguments
from trl import SFTTrainer
from unsloth import is_bfloat16_supported
trainer = SFTTrainer(
model=model,
tokenizer=tokenizer,
train_dataset=dataset,
dataset_text_field="text",
max_seq_length=max_seq_length,
dataset_num_proc=6, # Increase CPU processing for faster data loading/preprocessing
packing=False,
args=TrainingArguments(
per_device_train_batch_size=2,
gradient_accumulation_steps=2,
warmup_ratio = 0.1,
num_train_epochs=0.05,
learning_rate=4e-5,
fp16= not is_bfloat16_supported(),
bf16= is_bfloat16_supported(),
logging_steps= 100,
optim="adamw_8bit",
weight_decay=0.01,
lr_scheduler_type="cosine",
seed=3407,
output_dir = "outputs",
save_steps = 5000,
),
)-
Reproduction Steps:
-
Expected Behavior:
- Save the model to huggingface, instead of producing an error.
-
Actual Behavior:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-bfda09c104fc> in <cell line: 0>()
1 if True:
----> 2 model.push_to_hub_gguf(
3 "Sweaterdog/llava-GGUF",
4 tokenizer,
5 quantization_method = ["q4_k_m", "q8_0", "q5_k_m",],
/usr/local/lib/python3.11/dist-packages/torch/utils/_contextlib.py in decorate_context(*args, **kwargs)
114 def decorate_context(*args, **kwargs):
115 with ctx_factory():
--> 116 return func(*args, **kwargs)
117
118 return decorate_context
TypeError: save_to_gguf_generic() got an unexpected keyword argument 'quantization_method'
- Additional notes:
- This same code worked in the past, then it didn't, then it did work for a bit, and now it doesn't.
Activity
Sweaterdog commentedon May 5, 2025
I should note I was able to get the code to get further on my PC, running Linux Mint, but it got this error, of which said to report immediately.
edoproch commentedon May 7, 2025
Hi @Sweaterdog! On colab I think that you can try with
model.save_pretrained_gguf(
save_directory = "folder_name",
quantization_type='Q8_0')
(add repo id and token to push on HF)
Sweaterdog commentedon May 7, 2025
I've tried that too, but to no avail. For me, exporting GGUF files to Huggingface just does not work.
edoproch commentedon May 7, 2025
@Sweaterdog Yesterday I wrote on discord to one of the developers. He said that they are working to implement into unsloth the new classes of llama.cpp
I guess we have to be a little patient
Jordinia commentedon May 12, 2025
I have the same issue. 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):Windows
Arch
I remember getting the similar
TypeError: save_to_gguf_generic() got an unexpected keyword argument 'quantization_method'previously.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 on WIndows) 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.🙏
rolandtannous commentedon Jun 8, 2025
@Sweaterdog we're currently fixing this. meanwhile , push_to_hub() or if you need to merge push_to_hub_merged()
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
Padmanaba231 commentedon Jul 17, 2025
i still have the same problem.
when i tried run:
model.save_pretrained_gguf("ocr_model", tokenizer, quantization_method="f16")i always get error:
TypeError: save_to_gguf_generic() got an unexpected keyword argument 'quantization_method'. i am confused, i just follow the tutorial in documentation and its cleary instruct to use argument quantization_method. Is theres a way to fix this?
rolandtannous commentedon Jul 17, 2025
@Padmanaba231
we still have not yet fixed save_pretrained_gguf,
sorry for the bot. It was an experiment. We stopped it and I removed the inactive tag.
Sweaterdog commentedon Jul 17, 2025
Totally fine, thanks for fixing the exports! It has been a huge bummer to not be able to export any of my models.
wooihaw commentedon Jul 24, 2025
I am facing an error when running the following in Google Colab:
model.save_pretrained_gguf("custom_gemma3_1b_q_8", tokenizer, quantization_method = "q8_0")Error:
TypeError: save_to_gguf_generic() got multiple values for argument 'quantization_method'Previously, it would complain that
'quantization_method'was an unexpected keyword argument.By the way, I am using unsloth 2025.7.9
Sweaterdog commentedon Jul 24, 2025
Yeah, I am also getting the same issue when exporting models still, even on the latest version.
manu-one commentedon Jul 30, 2025
rolandtannous commentedon Oct 15, 2025
@Jordinia @Padmanaba231 @Sweaterdog @edoproch @github-actions @manu-one @wooihaw
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)
let me know
Thanks!
rolandtannous commentedon Oct 23, 2025
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