Skip to content

model.save_pretrained_gguf() fails to generate modelfile #2115

Closed

Description

@asdfwqfu

When calling model.save_pretrained_gguf(), the function appears to run to completion but does not generate the expected modelfile in the output directory.

if True: # Change to True to save to GGUF
save_path = "/content/drive/MyDrive/model/gemma3/gemma-3-finetune"
model.save_pretrained_gguf(
save_path,
quantization_type = "f16", # For now only Q8_0, BF16, F16 supported
)

Unsloth: Updating system package directories
Unsloth: Install GGUF and other packages
Unsloth GGUF:hf-to-gguf:Loading model: gemma-3-finetune
Unsloth GGUF:gguf.gguf_writer:gguf: This GGUF file is for Little Endian only
Unsloth GGUF:hf-to-gguf:Exporting model...
Unsloth GGUF:hf-to-gguf:gguf: loading model weight map from 'model.safetensors.index.json'
Unsloth GGUF:hf-to-gguf:gguf: loading model part 'model-00001-of-00002.safetensors'
Unsloth GGUF:hf-to-gguf:token_embd.weight, torch.bfloat16 --> F16, shape = {2560, 262208}
Unsloth GGUF:hf-to-gguf:gguf: loading model part 'model-00002-of-00002.safetensors'
Unsloth GGUF:hf-to-gguf:output_norm.weight, torch.bfloat16 --> F32, shape = {2560}
Unsloth GGUF:hf-to-gguf:Set meta model
Unsloth GGUF:hf-to-gguf:Set model parameters
Unsloth GGUF:hf-to-gguf:Set model tokenizer
Unsloth GGUF:gguf.vocab:Setting special token type bos to 2
Unsloth GGUF:gguf.vocab:Setting special token type eos to 106
Unsloth GGUF:gguf.vocab:Setting special token type unk to 3
Unsloth GGUF:gguf.vocab:Setting special token type pad to 0
Unsloth GGUF:gguf.vocab:Setting add_bos_token to True
Unsloth GGUF:gguf.vocab:Setting add_eos_token to False
Unsloth GGUF: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'] + '
..... Chat template truncated .....

Unsloth GGUF:hf-to-gguf:Set model quantization version
Unsloth GGUF:gguf.gguf_writer:Writing the following files:
Unsloth GGUF:gguf.gguf_writer:/content/drive/MyDrive/model/gemma3/gemma-3-finetune.F16.gguf: n_tensors = 444, total_size = 7.8G

Unsloth: GGUF conversion: 100%
 100/100 [00:42<00:00,  2.83it/s, 7.76G/7.76G]
Unsloth GGUF:hf-to-gguf:Model successfully exported to /content/drive/MyDrive/model/gemma3/
Unsloth: Converted to /content/drive/MyDrive/model/gemma3/gemma-3-finetune.F16.gguf with size = 7.8G
Unsloth: Successfully saved GGUF to:
/content/drive/MyDrive/model/gemma3/gemma-3-finetune.F16.gguf

Activity

  1. hcstubbe commented on Mar 30, 2025

    @hcstubbe

    you can get the Modelfile like this within the python script (note: you need to add the location of the .gguf file):

    tokenizer._ollama_modelfile

    if this does not work, you should be able to use the template from ollama like so (with ollama installed and using bash):

    ollama show --modelfile gemma3 >> Modelfile

  2. rolandtannous commented on Oct 15, 2025

    @rolandtannous
    Contributor

    @asdfwqfu @hcstubbe

    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)

    This should now work.
    Let me know how it goes for you.

    Thanks!

  3. 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

  4. thewh1teagle commented on Dec 26, 2025

    @thewh1teagle

    The issue still persist

  5. rolandtannous commented on Dec 26, 2025

    @rolandtannous
    Contributor

    @thewh1teagle would appreciate if you can open a new github issue and provide your unsloth/unsloth-zoo versions, which environment are you running this in? which model ? and what is the exact stack trace you are getting?

    thanks

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

    bugfixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions