GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GGUF llama.cpp direct conversion - BETA testers wanted! · Issue #71 · unslothai/unsloth

GGUF llama.cpp direct conversion - BETA testers wanted! #71

New issue
Copy link
New issue
Copy link
Closed
Closed
GGUF llama.cpp direct conversion - BETA testers wanted!#71
Copy link

Description

@danielhanchen
danielhanchen
opened on Jan 8, 2024
Issue body actions

Previously when one trains with either HF's TRL library or Unsloth, converting the model to GGUF / llama.cpp was a nightmare.

Either the following strategies were used:

  1. Save PEFT adapters and upload them to HF. Use llama.cpp to combine a GGUF version of Mistral / Llama and combine LoRA via convert-lora-to-ggml.py then quantize. Accuracy is medium, since bitsandbytes's quantization method is different to GGUF. VRAM usage is great.
  2. Train with load_in_4bit = False to use 16bit, then use model.save_pretrained and using llama.cpp then quantize. Accuracy is superb, since 16bit retains full accuracy, but VRAM usage for llama-7b goes to 14.5GB, and Mistral OOMs.
  3. Merge PEFT adapters back using model.merge_and_unload() then converting each layer to 16bit then step 2. Accuracy is low, since conversion to 4bit then upcasting to 16bit loses lots of bits.
  4. [NEW] Unsloth: Combines best of both worlds - train with QLoRA (low memory), then we upcast to 16bit, but on the fly, using mmap. Accuracy is high as well.

A table comparing all strategies:

Strategy VRAM Usage Disk Usage Accuracy
1. PEFT Low Low Medium
2. 16bit Horrible High High
3. Merge Horrible High Low
4. Unsloth Low High High

To use Unsloth:

from unsloth import unsloth_save_model
# unsloth_save_model has the same args as model.save_pretrained
unsloth_save_model(model, tokenizer, "output_model", push_to_hub = False, token = None)
colab_quantize_to_gguf("output_model", quantization_method = "q4_k_m")

I'm looking for beta testers to test out this Colab notebook! It finetunes Mistral and saves to GGUF: https://colab.research.google.com/drive/14DW0VwuqL2O3tqGlX7aUF6TOBA8S59M4?usp=sharing

It would be great it anyone tested it to check the perplexity / whether my conversions are correct! Thanks!

Activity

  1. danielhanchen
    pinned this issue on Jan 8, 2024
  2. x4080 commented on Jan 9, 2024

    @x4080
    x4080
    on Jan 9, 2024
    More actions

    It seems to be a better workflow from a glance at it, great job

    Reacted by Daniel Han
  3. danielhanchen commented on Jan 10, 2024

    @danielhanchen
    danielhanchen
    on Jan 10, 2024
    MemberAuthor
    More actions

    @x4080 Thanks! Hope it works!

  4. x4080 commented on Jan 12, 2024

    @x4080
    x4080
    on Jan 12, 2024
    More actions

    Hi, just tried to upload to hf and got this error

    Unsloth: `unsloth_save_model` is still in development mode.
    If anything errors or breaks, please file a ticket on Github.
    Also, if you used this successfully, please tell us on Discord!
    Unsloth: Merging 4bit and LoRA weights to 16bit...
    100%|██████████| 32/32 [01:12<00:00,  2.26s/it]
    Unsloth: Saving tokenizer...
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    [<ipython-input-11-164e96edda3b>](https://localhost:8080/#) in <cell line: 4>()
          2 
          3 # unsloth_save_model has the same args as model.save_pretrained
    ----> 4 unsloth_save_model(model, tokenizer, "model_combinedunsloth", push_to_hub = True, token = None)
          5 # colab_quantize_to_gguf("output_model", quantization_method = "q4_k_m")
    
    2 frames
    [/usr/local/lib/python3.10/dist-packages/transformers/tokenization_utils_base.py](https://localhost:8080/#) in save_pretrained(self, save_directory, legacy_format, filename_prefix, push_to_hub, **kwargs)
       2364             commit_message = kwargs.pop("commit_message", None)
       2365             repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1])
    -> 2366             repo_id = self._create_repo(repo_id, **kwargs)
       2367             files_timestamps = self._get_files_timestamps(save_directory)
       2368 
    
    TypeError: PushToHubMixin._create_repo() got an unexpected keyword argument 'is_main_process'
    

    is there a new colab version ?

    Thanks

  5. danielhanchen commented on Jan 12, 2024

    @danielhanchen
    danielhanchen
    on Jan 12, 2024
    MemberAuthor
    More actions

    @x4080 OH YYEPPP!! I remember someone else reported this - I'm working on a fix!!!

  6. dsbyprateekg commented on Jan 12, 2024

    @dsbyprateekg
    dsbyprateekg
    on Jan 12, 2024
    More actions

    @danielhanchen I faced following error-
    image

    While I ran the following code-
    image

    It is unable to save locally.

  7. danielhanchen commented on Jan 18, 2024

    @danielhanchen
    danielhanchen
    on Jan 18, 2024
    MemberAuthor
    More actions

    @dsbyprateekg @x4080 Sorry for the delay! Just pushed a new version - you can now save to GGUF directly with model.save_pretrained_merged(..., tokenizer = tokenizer) or model.push_to_hub_merged. The Mistral / Llama notebooks got updated!

    Reacted by Prateek Gupta
  8. x4080 commented on Jan 18, 2024

    @x4080
    x4080
    on Jan 18, 2024
    More actions

    @danielhanchen thanks

  9. danielhanchen
    unpinned this issue on Jan 20, 2024
  10. danielhanchen
    closed this as completedon Jan 20, 2024
  11. mmathew23
    added a commit that references this issue on Jun 8, 2025

    Gemma 3 bug fixes (unslothai#71)

    abfc60f
  12. mmathew23
    added a commit that references this issue on Jun 25, 2025

    Gemma 3 bug fixes (unslothai#71)

    85d3d38
  13. mmathew23
    added a commit that references this issue on Jul 7, 2025

    Gemma 3 bug fixes (unslothai#71)

    2742228
  14. Stanley00
    added a commit that references this issue on Mar 12, 2026

    Merge pull request unslothai#71 from unslothai/fix/frontend-default-path

    957e39c
  15. debojyoti-dev
    added a commit that references this issue on Nov 11, 2026

    Studio sd.cpp: pin the prebuilt resynced with upstream master-1056 (u…

    57a486b
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.