Skip to content

Commit

Permalink
Fix GGUF (unslothai#731)
Browse files Browse the repository at this point in the history
* Update mapper.py

* Update Model Conversion Command in `save.py` to `convert_hf_to_gguf.py` (unslothai#730)

* Updated convert_hf_to_gguf.py call to align with changes in llama.cpp repository

* Update save.py

---------

Co-authored-by: Daniel Han <[email protected]>

* Typo Fix (unslothai#690)

---------

Co-authored-by: M. Ali Bayram <[email protected]>
Co-authored-by: johnpaulbin <[email protected]>
  • Loading branch information
3 people authored Jul 4, 2024
1 parent 5ab565f commit 9b4cc93
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion unsloth/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def from_pretrained(
# Cannot be both!
if is_model and is_peft:
raise RuntimeError(
"Unsloth: You repo has a LoRA adapter and a base model.\n"\
"Unsloth: Your repo has a LoRA adapter and a base model.\n"\
"You have 2 files `config.json` and `adapter_config.json`.\n"\
"We must only allow one config file.\n"\
"Please separate the LoRA and base models to 2 repos."
Expand Down
11 changes: 11 additions & 0 deletions unsloth/models/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@
"unsloth/gemma-2-27b",
"google/gemma-2-27b",
),
"unsloth/gemma-2-9b-it-bnb-4bit" : (
"unsloth/gemma-2-9b-it",
"google/gemma-2-9b-it",
),
"unsloth/gemma-2-27b-it-bnb-4bit" : (
"unsloth/gemma-2-27b-it",
"google/gemma-2-27b-it",
),
"unsloth/Phi-3-mini-4k-instruct-v0-bnb-4bit" : ( # Old Phi pre July
"unsloth/Phi-3-mini-4k-instruct-v0",
),
}

INT_TO_FLOAT_MAPPER = {}
Expand Down
27 changes: 23 additions & 4 deletions unsloth/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ def install_llama_cpp_old(version = -10):
# Check if successful
if not os.path.exists("llama.cpp/quantize") and not os.path.exists("llama.cpp/llama-quantize"):
raise RuntimeError(
"Unsloth: llama.cpp GGUF seems to be too buggy to install.\n"\
"File a report to llama.cpp's main repo since this is not an Unsloth issue."
"Unsloth: The file 'llama.cpp/llama-quantize' or `llama.cpp/quantize` does not exist.\n"\
"But we expect this file to exist! Maybe the llama.cpp developers changed the name?"
)
pass
pass
Expand Down Expand Up @@ -945,9 +945,28 @@ def save_to_gguf(
quantize_location = "llama.cpp/quantize"
elif os.path.exists("llama.cpp/llama-quantize"):
quantize_location = "llama.cpp/llama-quantize"
else:
raise RuntimeError(
"Unsloth: The file 'llama.cpp/llama-quantize' or 'llama.cpp/quantize' does not exist.\n"\
"But we expect this file to exist! Maybe the llama.cpp developers changed the name?"
)
pass

# See https://github.com/unslothai/unsloth/pull/730
# Filenames changed again!
convert_location = None
if os.path.exists("llama.cpp/convert-hf-to-gguf.py"):
convert_location = "llama.cpp/convert-hf-to-gguf.py"
elif os.path.exists("llama.cpp/convert_hf_to_gguf.py"):
convert_location = "llama.cpp/convert_hf_to_gguf.py"
else:
raise RuntimeError(
"Unsloth: The file 'llama.cpp/convert-hf-to-gguf.py' or 'llama.cpp/convert_hf_to_gguf.py' does not exist.\n"\
"But we expect this file to exist! Maybe the llama.cpp developers changed the name?"
)
pass

if error != 0 or quantize_location is None:
if error != 0 or quantize_location is None or convert_location is None:
print(f"Unsloth: llama.cpp error code = {error}.")
install_llama_cpp_old(-10)
pass
Expand Down Expand Up @@ -1035,7 +1054,7 @@ def save_to_gguf(
f"--outfile {final_location} --vocab-type {vocab_type} "\
f"--outtype {first_conversion} --concurrency {n_cpus} --pad-vocab"
else:
command = f"python llama.cpp/convert-hf-to-gguf.py {model_directory} "\
command = f"python {convert_location} {model_directory} "\
f"--outfile {final_location} "\
f"--outtype {first_conversion}"
pass
Expand Down
2 changes: 1 addition & 1 deletion unsloth/tokenizer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def fix_sentencepiece_gguf(saved_location):
"""
Fixes sentencepiece tokenizers which did not extend the vocabulary with
user defined tokens.
Inspiration from https://github.com/ggerganov/llama.cpp/blob/master/convert-hf-to-gguf.py
Inspiration from https://github.com/ggerganov/llama.cpp/blob/master/convert_hf_to_gguf.py
"""
from copy import deepcopy
from transformers.utils import sentencepiece_model_pb2
Expand Down

0 comments on commit 9b4cc93

Please sign in to comment.