Skip to content

[Bug] save_pretrained_gguf Broken - (Tokenizer?), doesn't support gemma-3 anymore #3348

Closed

Description

@orenong

The Gemma-3 notebooks use this for saving:


if True: # Change to True to save to GGUF
    model.save_pretrained_gguf(
        "gemma-3-finetune",
        quantization_type = "Q8_0"
)

I added a tokenizer, because it seems to be required now

if True: # Change to True to save to GGUF
    model.save_pretrained_gguf(
        "gemma-3-finetune",
        tokenizer,
        quantization_type = "Q8_0"
)

and the result is a model that when used, returns text that looks like this:

sed24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused24><unused

Looked to me like an issue with the tokenizer. Using a fresh tokenizer results in the same issue.

Example in a notebook

gemma_en_notebook (1).ipynb

Update:

Same issue with different quantizations as well.

Activity

  1. changed the title [-][Bug] save_pretrained_gguf Broken Tokenizer, doesn't support gemma-3 anymore[/-] [+][Bug] save_pretrained_gguf Broken - (Tokenizer?), doesn't support gemma-3 anymore[/+] on Sep 21, 2025
  2. Erland366 commented on Sep 22, 2025

    @Erland366
    Collaborator

    Did you finetune it? I tried immediately convert to GGUF after adding LoRA and it works fine. How is the inference result after finetuning (using HF)? Is it working normally there?

  3. rolandtannous commented on Sep 22, 2025

    @rolandtannous
    Contributor

    Hello a fix for llama.cpp compatibility and GGUF conversion+ quantization is getting pushed in the next two days :)
    I'll ping you once it's out

  4. orenong commented on Sep 24, 2025

    @orenong
    Author

    Did you finetune it? I tried immediately convert to GGUF after adding LoRA and it works fine. How is the inference result after finetuning (using HF)? Is it working normally there?

    The inference inside the notebook works normally, Did not try in other ways. I uploaded a new notebook and a dataset, in case anyone wants to test.

    dataset.csv

    gemma_en_notebook (1).ipynb

  5. orenong commented on Sep 24, 2025

    @orenong
    Author

    Hello a fix for llama.cpp compatibility and GGUF conversion+ quantization is getting pushed in the next two days :) I'll ping you once it's out

    Thank you. I hope it's gonna fix it 💯

  6. orenong commented on Sep 25, 2025

    @orenong
    Author

    Did you finetune it? I tried immediately convert to GGUF after adding LoRA and it works fine. How is the inference result after finetuning (using HF)? Is it working normally there?

    Tried with unsloth's notebook, just to make sure. Same issue. I'm not even sure it's the GGUF conversion that breaks it, a fix suggested in discord for the GGUF conversion doesn't help.
    What can be said for sure, is that unsloth can't fine tune Gemma 3-1b and save it as GGUF

    https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_(4B).ipynb

  7. orenong commented on Sep 25, 2025

    @orenong
    Author

    Tried running using llama-cpp. Same issue, this rules out an LM-Studio compatibility issue

  8. rolandtannous commented on Sep 25, 2025

    @rolandtannous
    Contributor

    We still haven't pushed a fix to saving in gguf. It's under review. You'll get pinged here on the thread once its out.
    Also note that in the notebook you shared you might want to explicitely remove the bos token just like we do on the official notebook , or else you might end up with garbled output.

  9. pranaysawant17 commented on Sep 26, 2025

    @pranaysawant17

    when will you do I really need to convert my model to gguf

  10. rolandtannous commented on Sep 26, 2025

    @rolandtannous
    Contributor

    @pranaysawant17 not before last week.
    meanwhile, merge and push your model to HF, then run this space https://huggingface.co/spaces/ggml-org/gguf-my-repo against your repo. it will convert your repo to GGUF
    or do it manually for the time being using llama.cpp directly. should also work

  11. pranaysawant17 commented on Sep 27, 2025

    @pranaysawant17

    I tried this my HF model works but as soon as I convert it gguf (I used the above space only) on inference it gives no output. This is from verbose
    llama_model_loader: - type f32: 157 tensors
    llama_model_loader: - type q8_0: 183 tensors
    print_info: file format = GGUF V3 (latest)
    print_info: file type = Q8_0
    print_info: file size = 1013.54 MiB (8.50 BPW)
    init_tokenizer: initializing tokenizer for type 1
    load: control token: 1 '' is not marked as EOG
    load: control token: 0 '' is not marked as EOG
    load: control token: 46 '' is not marked as EOG
    load: control token: 3 '' is not marked as EOG
    load: control token: 54 '' is not marked as EOG
    load: control token: 23 '' is not marked as EOG
    load: control token: 261532 '' is not marked as EOG
    load: control token: 2 '' is not marked as EOG
    load: control token: 30 '' is not marked as EOG
    load: control token: 260607 '' is not marked as EOG
    load: control token: 74 '' is not marked as EOG
    load: control token: 259984 '' is not marked as EOG
    load: control token: 259158 '' is not marked as EOG
    load: control token: 57 '' is not marked as EOG
    load: control token: 4 '' is not marked as EOG
    load: control token: 43 '' is not marked as EOG
    load: control token: 34 '' is not marked as EOG
    load: control token: 6 '' is not marked as EOG
    load: control token: 258560 '' is not marked as EOG
    load: control token: 42 '' is not marked as EOG
    load: control token: 35 '' is not marked as EOG
    load: control token: 7 '' is not marked as EOG
    load: control token: 256766 '' is not marked as EOG
    load: control token: 41 '' is not marked as EOG
    load: control token: 258676 '' is not marked as EOG
    load: control token: 8 '' is not marked as EOG
    load: control token: 40 '' is not marked as EOG
    load: control token: 260391 '' is not marked as EOG
    load: control token: 9 '' is not marked as EOG
    load: control token: 39 '' is not marked as EOG
    load: control token: 10 '' is not marked as EOG
    load: control token: 38 '' is not marked as EOG
    load: control token: 11 '' is not marked as EOG
    load: control token: 37 '' is not marked as EOG
    load: control token: 12 '' is not marked as EOG
    load: control token: 36 '' is not marked as EOG

  12. orenong commented on Oct 3, 2025

    @orenong
    Author

    Ran the same notebook again, and it worked.
    Closing for now

  13. rolandtannous commented on Oct 14, 2025

    @rolandtannous
    Contributor

    @orenong @pranaysawant17

    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)

    Have fun

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions