Skip to content

Error when saving unsloth Llama 3.1 model to GGUF format #965

Closed

Description

@okoliechykwuka

I'm encountering an error while trying to save the default unsloth Llama 3.1 model to GGUF format. The issue occurs when running the code on Google Colab with a T4 GPU.

Environment:

  • Google Colab
  • T4 GPU
  • Default unsloth Llama 3.1 code

Changes made:

  • Updated API key
  • Updated Hugging Face username

Code snippet:

# Save to q4_k_m GGUF
if True: model.save_pretrained_gguf("model", tokenizer, quantization_method = "q4_k_m")
if True: model.push_to_hub_gguf("chukypedro/testing", tokenizer, quantization_method = "q4_k_m", token = "api_key")

# Save to multiple GGUF options - much faster if you want multiple!
if True:
    model.push_to_hub_gguf(
        "myname/testing", # Change hf to your username!
        tokenizer,
        quantization_method = ["q4_k_m"],
        token = "", # Get a token at https://huggingface.co/settings/tokens

Error traceback:

RuntimeError                              Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/torch/serialization.py](https://localhost:8080/#) in __exit__(self, *args)
    497 
    498     def __exit__(self, *args) -> None:
--> 499         self.file_like.write_end_of_file()
    500         if self.file_stream is not None:
    501             self.file_stream.close()
RuntimeError: [enforce fail at inline_container.cc:603] . unexpected pos 576 vs 470

Expected behavior:
The model should save successfully to GGUF format without any errors.

Actual behavior:
The saving process fails with a RuntimeError, indicating an unexpected position in the file.

Activity

  1. 3m1rc1kk commented on Aug 30, 2024

    @3m1rc1kk

    I have the same error, I think the disk is filling up, so either use a smaller model or become a colab pro subscriber, so the disk space increases

  2. Ammar-Alnagar commented on Sep 5, 2024

    @Ammar-Alnagar

    The pos error is a storage error , since whe. Saving as qkm , it gets saved as two files one qkm and the other as F16 and that usually fills up the space if you had a big dataset for finetuning or ran it for too many epochs.
    My advice is save it as merged 16 bit then on huggingface_hub use this space to get a qkm version of your model for free.
    https://huggingface.co/spaces/ggml-org/gguf-my-repo

  3. shimmyshimmer commented on Oct 9, 2024

    @shimmyshimmer
    Member

    Thanks for helping out @circle-games and @Ammar-Alnagar

    @okoliechykwuka hopefully your issue was solved?

  4. rolandtannous commented on Oct 15, 2025

    @rolandtannous
    Contributor

    @Ammar-Alnagar @circle-games @okoliechykwuka

    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)

    Let me know if it works out for you.

    Thanks!

  5. Ammar-Alnagar commented on Oct 20, 2025

    @Ammar-Alnagar

    @rolandtannous I can confirm it's fixed and working

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

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

    fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions