From 3e9e50dcc7f71347bdb5d592ac584b8692173ae9 Mon Sep 17 00:00:00 2001 From: simpolism Date: Mon, 7 Jul 2025 00:08:37 -0400 Subject: [PATCH 1/2] Fix windows quantize execution and locating. --- unsloth/save.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/unsloth/save.py b/unsloth/save.py index e61026318..b18f285fa 100644 --- a/unsloth/save.py +++ b/unsloth/save.py @@ -889,7 +889,9 @@ def install_llama_cpp_old(version = -10): os.path.exists("llama.cpp/llama-quantize") or os.path.exists("llama.cpp/quantize.exe") or os.path.exists("llama.cpp/quantize") or + os.path.exists("llama.cpp/build/bin/Release/llama-quantize.exe") or os.path.exists("llama.cpp/build/bin/llama-quantize") or + os.path.exists("llama.cpp/build/bin/Release/quantize.exe") or os.path.exists("llama.cpp/build/bin/quantize") ): raise RuntimeError( @@ -1077,18 +1079,21 @@ def save_to_gguf( # and llama.cpp/main changed to llama.cpp/llama-cli # See https://github.com/ggerganov/llama.cpp/pull/7809 quantize_location = None - if os.path.exists("llama.cpp/quantize.exe"): - quantize_location = "llama.cpp/quantize.exe" - elif os.path.exists("llama.cpp/quantize"): - quantize_location = "llama.cpp/quantize" - elif os.path.exists("llama.cpp/llama-quantize.exe"): - quantize_location = "llama.cpp/llama-quantize.exe" - elif os.path.exists("llama.cpp/llama-quantize"): - quantize_location = "llama.cpp/llama-quantize" - elif os.path.exists("llama.cpp/build/bin/llama-quantize"): - quantize_location = "llama.cpp/build/bin/llama-quantize" - elif os.path.exists("llama.cpp/build/bin/quantize"): - quantize_location = "llama.cpp/build/bin/quantize" + possible_paths = [ + os.path.join(".", "llama.cpp", "quantize.exe"), + os.path.join(".", "llama.cpp", "quantize"), + os.path.join(".", "llama.cpp", "llama-quantize.exe"), + os.path.join(".", "llama.cpp", "llama-quantize"), + os.path.join(".", "llama.cpp", "build", "bin", "llama-quantize"), + os.path.join(".", "llama.cpp", "build", "bin", "quantize"), + os.path.join(".", "llama.cpp", "build", "bin", "Release", "llama-quantize.exe"), + os.path.join(".", "llama.cpp", "build", "bin", "Release", "quantize.exe") + ] + + for path in possible_paths: + if os.path.exists(path): + quantize_location = path + break else: raise RuntimeError( "Unsloth: The file 'llama.cpp/llama-quantize' or `llama.cpp/quantize` does not exist.\n"\ @@ -1239,7 +1244,7 @@ def save_to_gguf( print(f"Unsloth: [2] Converting GGUF 16bit into {quant_method}. This might take 20 minutes...") final_location = str((Path(model_directory) / f"unsloth.{quant_method.upper()}.gguf").absolute()) - command = f"./{quantize_location} {full_precision_location} "\ + command = f"{quantize_location} {full_precision_location} "\ f"{final_location} {quant_method} {n_cpus}" try_execute([command,], force_complete = True) From d2f1dc28e5349a0a4a2bca02415b73a22e7fc560 Mon Sep 17 00:00:00 2001 From: simpolism Date: Mon, 7 Jul 2025 01:56:00 -0400 Subject: [PATCH 2/2] Extract quantize path detection into separate function call --- unsloth/save.py | 54 ++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/unsloth/save.py b/unsloth/save.py index b18f285fa..e66be7cb5 100644 --- a/unsloth/save.py +++ b/unsloth/save.py @@ -884,16 +884,7 @@ def install_llama_cpp_old(version = -10): pass # Check if successful - if not ( - os.path.exists("llama.cpp/llama-quantize.exe") or - os.path.exists("llama.cpp/llama-quantize") or - os.path.exists("llama.cpp/quantize.exe") or - os.path.exists("llama.cpp/quantize") or - os.path.exists("llama.cpp/build/bin/Release/llama-quantize.exe") or - os.path.exists("llama.cpp/build/bin/llama-quantize") or - os.path.exists("llama.cpp/build/bin/Release/quantize.exe") or - os.path.exists("llama.cpp/build/bin/quantize") - ): + if not (get_local_llamacpp_quantize_location()): raise RuntimeError( "Unsloth: The file 'llama.cpp/llama-quantize' or `llama.cpp/quantize` does not exist.\n"\ "We've also double checked the building directory under 'llama.cpp/build/bin/'.\n"\ @@ -949,6 +940,27 @@ def get_executable(executables): return None pass +def get_local_llamacpp_quantize_location(): + # Look for llama.cpp quantize binary in a local installation + # Careful llama.cpp/quantize changed to llama.cpp/llama-quantize + # and llama.cpp/main changed to llama.cpp/llama-cli + # See https://github.com/ggerganov/llama.cpp/pull/7809 + possible_paths = [ + os.path.join(".", "llama.cpp", "quantize.exe"), + os.path.join(".", "llama.cpp", "quantize"), + os.path.join(".", "llama.cpp", "llama-quantize.exe"), + os.path.join(".", "llama.cpp", "llama-quantize"), + os.path.join(".", "llama.cpp", "build", "bin", "llama-quantize"), + os.path.join(".", "llama.cpp", "build", "bin", "quantize"), + os.path.join(".", "llama.cpp", "build", "bin", "Release", "llama-quantize.exe"), + os.path.join(".", "llama.cpp", "build", "bin", "Release", "quantize.exe") + ] + + for path in possible_paths: + if os.path.exists(path): + return path + return None + def save_to_gguf( model_type : str, @@ -1075,26 +1087,8 @@ def save_to_gguf( install_llama_cpp_blocking() pass - # Careful llama.cpp/quantize changed to llama.cpp/llama-quantize - # and llama.cpp/main changed to llama.cpp/llama-cli - # See https://github.com/ggerganov/llama.cpp/pull/7809 - quantize_location = None - possible_paths = [ - os.path.join(".", "llama.cpp", "quantize.exe"), - os.path.join(".", "llama.cpp", "quantize"), - os.path.join(".", "llama.cpp", "llama-quantize.exe"), - os.path.join(".", "llama.cpp", "llama-quantize"), - os.path.join(".", "llama.cpp", "build", "bin", "llama-quantize"), - os.path.join(".", "llama.cpp", "build", "bin", "quantize"), - os.path.join(".", "llama.cpp", "build", "bin", "Release", "llama-quantize.exe"), - os.path.join(".", "llama.cpp", "build", "bin", "Release", "quantize.exe") - ] - - for path in possible_paths: - if os.path.exists(path): - quantize_location = path - break - else: + quantize_location = get_local_llamacpp_quantize_location() + if quantize_location is None: raise RuntimeError( "Unsloth: The file 'llama.cpp/llama-quantize' or `llama.cpp/quantize` does not exist.\n"\ "We've also double checked the building directory under 'llama.cpp/build/bin/'.\n"\