Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Fix GGUF (#731)
Daniel Hanc1009008e3e3
diff --git a/unsloth/models/loader.py b/unsloth/models/loader.pyindex 9134d4a2263..82d177e466a 100644--- a/unsloth/models/loader.py+++ b/unsloth/models/loader.py@@ -108,7 +108,7 @@ class FastLanguageModel(FastLlamaModel):# 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."diff --git a/unsloth/models/mapper.py b/unsloth/models/mapper.pyindex cec7332ec93..31b3ab6df65 100644--- a/unsloth/models/mapper.py+++ b/unsloth/models/mapper.py@@ -199,6 +199,17 @@ __INT_TO_FLOAT_MAPPER = \"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 = {}diff --git a/unsloth/save.py b/unsloth/save.pyindex 9163c6d38da..1ceea3c19b4 100644--- a/unsloth/save.py+++ b/unsloth/save.py@@ -800,8 +800,8 @@ def install_llama_cpp_old(version = -10):# Check if successfulif 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?")passpass@@ -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@@ -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}"passdiff --git a/unsloth/tokenizer_utils.py b/unsloth/tokenizer_utils.pyindex 8727ca03f52..b0bc514f67b 100644--- a/unsloth/tokenizer_utils.py+++ b/unsloth/tokenizer_utils.py@@ -376,7 +376,7 @@ def fix_sentencepiece_gguf(saved_location):"""Fixes sentencepiece tokenizers which did not extend the vocabulary withuser 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 deepcopyfrom transformers.utils import sentencepiece_model_pb2