You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GGUF llama.cpp direct conversion - BETA testers wanted! #71
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:
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.
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.
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.
[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")
@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!
Activity
x4080 commentedon Jan 9, 2024
It seems to be a better workflow from a glance at it, great job
danielhanchen commentedon Jan 10, 2024
@x4080 Thanks! Hope it works!
x4080 commentedon Jan 12, 2024
Hi, just tried to upload to hf and got this error
is there a new colab version ?
Thanks
danielhanchen commentedon Jan 12, 2024
@x4080 OH YYEPPP!! I remember someone else reported this - I'm working on a fix!!!
dsbyprateekg commentedon Jan 12, 2024
@danielhanchen I faced following error-

While I ran the following code-

It is unable to save locally.
danielhanchen commentedon Jan 18, 2024
@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)ormodel.push_to_hub_merged. The Mistral / Llama notebooks got updated!x4080 commentedon Jan 18, 2024
@danielhanchen thanks
Gemma 3 bug fixes (unslothai#71)
Gemma 3 bug fixes (unslothai#71)
Gemma 3 bug fixes (unslothai#71)
Merge pull request unslothai#71 from unslothai/fix/frontend-default-path
Studio sd.cpp: pin the prebuilt resynced with upstream master-1056 (u…