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! #71DescriptionPreviously 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")
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! Activityx4080 commented on Jan 9, 2024 It seems to be a better workflow from a glance at it, great job danielhanchen commented on Jan 10, 2024 x4080 commented on Jan 12, 2024 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 danielhanchen commented on Jan 12, 2024 @x4080 OH YYEPPP!! I remember someone else reported this - I'm working on a fix!!! dsbyprateekg commented on Jan 12, 2024 @danielhanchen I faced following error-

While I ran the following code-

It is unable to save locally. danielhanchen commented on 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) or model.push_to_hub_merged. The Mistral / Llama notebooks got updated! x4080 commented on Jan 18, 2024
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|