Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions unsloth/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,15 +804,15 @@ def install_llama_cpp_make_non_blocking():


def install_python_non_blocking(packages = []):
full_command = ["pip", "install"] + packages
full_command = [sys.executable, "-m", "pip", "install"] + packages
run_installer = subprocess.Popen(full_command, stdout = subprocess.DEVNULL, stderr = subprocess.STDOUT)
return run_installer
pass


def try_execute(commands, force_complete = False):
def try_execute(commands, force_complete = False, shell = True):
for command in commands:
with subprocess.Popen(command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, bufsize = 1) as sp:
with subprocess.Popen(command, shell = shell, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, bufsize = 1) as sp:
for line in sp.stdout:
line = line.decode("utf-8", errors = "replace")
if "undefined reference" in line:
Expand Down Expand Up @@ -1191,16 +1191,20 @@ def save_to_gguf(
# convert.py is deprecated!
use_fast_convert = False
if use_fast_convert:
command = f"python llama.cpp/convert.py {model_directory} "\
f"--outfile {final_location} --vocab-type {vocab_type} "\
f"--outtype {first_conversion} --concurrency {n_cpus} --pad-vocab"
command = [
sys.executable, "llama.cpp/convert.py", model_directory,
"--outfile", final_location, "--vocab-type", vocab_type,
"--outtype", first_conversion, "--concurrency", str(n_cpus), "--pad-vocab"
]
else:
command = f"python {convert_location} {model_directory} "\
f"--outfile {final_location} "\
f"--outtype {first_conversion}"
command = [
sys.executable, convert_location, model_directory,
"--outfile", final_location,
"--outtype", first_conversion
]
pass

try_execute([command,], force_complete = True)
try_execute([command,], force_complete = True, shell = False)

# Check if quantization succeeded!
if not os.path.isfile(final_location):
Expand Down Expand Up @@ -1239,10 +1243,12 @@ 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} "\
f"{final_location} {quant_method} {n_cpus}"
command = [
quantize_location, full_precision_location,
final_location, quant_method, str(n_cpus)
]

try_execute([command,], force_complete = True)
try_execute([command,], force_complete = True, shell = False)

# Check if quantization succeeded!
if not os.path.isfile(final_location):
Expand Down Expand Up @@ -2145,10 +2151,10 @@ def unsloth_convert_lora_to_ggml_and_push_to_hub(
print(f"Unsloth: Converting auto-saved LoRA adapters at {lora_directory_push} to GGML format.")
print(f"The output file will be {output_file}")

command = f"python3 llama.cpp/convert-lora-to-ggml.py {lora_directory_push} {output_file} llama"
command = [sys.executable, "llama.cpp/convert-lora-to-ggml.py", lora_directory_push, output_file, "llama"]

try:
with subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, universal_newlines=True) as sp:
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, universal_newlines=True) as sp:
for line in sp.stdout:
print(line, end="", flush=True)
for line in sp.stderr:
Expand Down Expand Up @@ -2206,10 +2212,10 @@ def unsloth_convert_lora_to_ggml_and_save_locally(
print(f"Unsloth: Converting auto-saved LoRA adapters at {save_directory} to GGML format.")
print(f"The output file will be {output_file}")

command = f"python3 llama.cpp/convert-lora-to-ggml.py {save_directory} {output_file} llama"
command = [sys.executable, "llama.cpp/convert-lora-to-ggml.py", save_directory, output_file, "llama"]

try:
with subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, universal_newlines=True) as sp:
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, universal_newlines=True) as sp:
for line in sp.stdout:
print(line, end="", flush=True)
for line in sp.stderr:
Expand Down