Skip to content

[Bug] Saving to GGUF doesn't work for gpt-oss #3297

Closed

Description

@tunaozates

When saving a LoRA model trained for gpt-oss to GGUF with standard command:
if True: model.save_pretrained_gguf("folder",tokenizer, quantization_method ="q8_0")

I get the following error:
RuntimeError: Unsloth: config.json does not exist inside {folder}

I am using BF16 version, but other quants have the same problem. I am using a proprietary dataset, which works fine with any other model. Finetuning part still works but problem occurs only in the gguf conversion part.

Activity

  1. rolandtannous commented on Sep 10, 2025

    @rolandtannous
    Contributor

    Thank you for reporting this issue. We are currently working on resolving several problems with the save_pretrained_gguf functionality.

    Temporary Workarounds

    While we work on a permanent fix, here are two alternative approaches you can use:

    Option 1: Use llama.cpp integration

    We have prepared a Colab notebook that demonstrates how to use llama.cpp for GGUF conversion:
    https://colab.research.google.com/drive/1EevDuEa_CYZt59eMGl7acB6DhlApj61O?usp=sharing

    Option 2: Follow our documentation guide

    You can also follow the llama.cpp instructions in the Long Context GPT OSS Training documentation, which will generate a proper GGUF file.

    Important Installation Update

    If you're working in a local environment, please update your Unsloth installation immediately. We pushed critical fixes for the latest Transformers compatibility last night, but these updates are not yet available on PyPI:

    pip install --force-reinstall --no-deps git+https://github.com/unslothai/unsloth-zoo.git
    pip install --force-reinstall --no-deps git+https://github.com/unslothai/unsloth.git

    We expect to resolve the GGUF saving issues soon and appreciate your patience.

    Note: This issue is related to #3133 and #3090.

  2. homanp commented on Sep 16, 2025

    @homanp

    @rolandtannous save_pretrained_merged is throwing errors as well,

    model-00000-of-00002.safetensors: 100%
     4.79G/4.79G [00:14<00:00, 290MB/s]
    Unsloth: Merging weights into 16bit:   0%|          | 0/3 [00:15<?, ?it/s]
    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    [/tmp/ipython-input-3762107182.py](https://localhost:8080/#) in <cell line: 0>()
          1 model.save_pretrained("finetuned_model")
          2 model.push_to_hub("superagent-ai/superagent-lm-20b") # Save to HF
    ----> 3 model.save_pretrained_merged("superagent_lm_finetue", tokenizer)
          4 model.push_to_hub_merged("superagent-ai/superagent-lm-20b", tokenizer=tokenizer)
    
    6 frames
    [/usr/local/lib/python3.12/dist-packages/unsloth_zoo/saving_utils.py](https://localhost:8080/#) in _merge_and_overwrite_lora(save_directory, filename, lora_weights, output_dtype, model_class_name, base_model_is_quantized, quant_type, overwrite)
        565             success = False
        566             if overwrite and mm is not None and header_metadata is not None:
    --> 567                 key_metadata = header_metadata[output_key]
        568                 index_L, index_R = key_metadata["data_offsets"]
        569                 # dtype = SAFETENSORS_DTYPES[key_metadata["dtype"]]
    
    KeyError: 'model.layers.0.mlp.experts.down_proj'
    
  3. rolandtannous commented on Sep 16, 2025

    @rolandtannous
    Contributor

    @homanp hello

    we're introducing some logic changes, so it's temporarily down. It will be back up and running later today. Will ping you

  4. homanp commented on Sep 16, 2025

    @homanp

    @homanp hello

    we're introducing some logic changes, so it's temporarily down. It will be back up and running later today. Will ping you

    Sounds good! Will the gguf saving method also work or do you still recommend using llama cpp for generating gguf?

  5. KineticCookie commented on Sep 16, 2025

    @KineticCookie

    Hi @rolandtannous

    Which previous version of unsloth should I use for working save_pretrained_merged while fix is in the progress?

  6. rolandtannous commented on Sep 16, 2025

    @rolandtannous
    Contributor

    @KineticCookie @homanp we just pushed a fixx it should be in pypi pip install

    if you're upgrading your env, make sure to use pip install --force-reinstall --no-deps

  7. homanp commented on Sep 16, 2025

    @homanp

    @KineticCookie @homanp we just pushed a fixx it should be in pypi pip install

    if you're upgrading your env, make sure to use pip install --force-reinstall --no-deps

    Thank you very much, seems to work fine now.

  8. rolandtannous commented on Sep 18, 2025

    @rolandtannous
    Contributor

    Hello,

    if you update your existing installation from main repo using:

    pip install --force-reinstall --no-deps git+https://github.com/unslothai/unsloth-zoo
    pip install --force-reinstall --no-deps git+https://github.com/unslothai/unsloth
    

    you should now be able to save and merge in native MXFP4 format, via:

    model.save_pretrained_merged(save_directory, tokenizer, save_method="mxfp4")
    

    It uses up to 75% less disk space, reduces VRAM consumption by 50%, accelerates merging by 5-10x, and enables much faster conversion to GGUF format. We'll be making a pypi release and updating the docs soon.

    Enjoy

  9. rolandtannous commented on Oct 14, 2025

    @rolandtannous
    Contributor

    @KineticCookie @homanp @tunaozates

    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)

  10. homanp commented on Oct 14, 2025

    @homanp

    @rolandtannous this is great, thanks!

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

    bugfixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions