Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,10 +11,8 @@ from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
|
11 |
from apscheduler.schedulers.background import BackgroundScheduler
|
12 |
from datetime import datetime
|
13 |
import numpy as np
|
14 |
-
import shutil
|
15 |
-
|
16 |
-
|
17 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
|
18 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
19 |
CONVERSION_SCRIPT = "./llama.cpp/convert_hf_to_gguf.py"
|
20 |
|
@@ -227,19 +225,21 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
227 |
fp16 = str(Path(outdir)/f"{model_name}.fp16.gguf")
|
228 |
|
229 |
with tempfile.TemporaryDirectory(dir=downloads_dir) as tmpdir:
|
|
|
230 |
local_dir = Path(tmpdir)/model_name
|
231 |
-
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " Start download")
|
232 |
api.snapshot_download(repo_id=model_id, local_dir=local_dir, local_dir_use_symlinks=False, allow_patterns=dl_pattern)
|
233 |
-
|
234 |
config_dir = local_dir/"config.json"
|
235 |
adapter_config_dir = local_dir/"adapter_config.json"
|
236 |
if os.path.exists(adapter_config_dir) and not os.path.exists(config_dir):
|
237 |
raise Exception("adapter_config.json is present. If converting LoRA, use GGUF-my-lora.")
|
238 |
-
|
|
|
239 |
result = subprocess.run(["python", CONVERSION_SCRIPT, local_dir, "--outtype", "f16", "--outfile", fp16], shell=False, capture_output=True)
|
|
|
240 |
if result.returncode != 0:
|
241 |
raise Exception(f"Error converting to fp16: {result.stderr.decode()}")
|
242 |
-
|
243 |
imatrix_path = Path(outdir)/"imatrix.dat"
|
244 |
if use_imatrix:
|
245 |
train_data_path = train_data_file.name if train_data_file else "llama.cpp/groups_merged.txt"
|
@@ -249,9 +249,10 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
249 |
|
250 |
quant_methods = [imatrix_q_method] if use_imatrix else (q_method if isinstance(q_method, list) else [q_method])
|
251 |
suffix = "imat" if use_imatrix else None
|
252 |
-
|
253 |
gguf_files = []
|
254 |
for method in quant_methods:
|
|
|
255 |
name = f"{model_name.lower()}-{method.lower()}-{suffix}.gguf" if suffix else f"{model_name.lower()}-{method.lower()}.gguf"
|
256 |
path = str(Path(outdir)/name)
|
257 |
quant_cmd = ["./llama.cpp/llama-quantize", "--imatrix", imatrix_path, fp16, path, method] if use_imatrix else ["./llama.cpp/llama-quantize", fp16, path, method]
|
@@ -261,6 +262,7 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
261 |
size = os.path.getsize(path)/1024/1024/1024
|
262 |
gguf_files.append((name, path, size, method))
|
263 |
|
|
|
264 |
suffix_for_repo = f"{imatrix_q_method}-imat" if use_imatrix else "-".join(quant_methods)
|
265 |
repo_id = f"{repo_namespace}/{model_name}-{suffix_for_repo}-GGUF"
|
266 |
new_repo_url = api.create_repo(repo_id=repo_id, exist_ok=True, private=private_repo)
|
|
|
11 |
from apscheduler.schedulers.background import BackgroundScheduler
|
12 |
from datetime import datetime
|
13 |
import numpy as np
|
|
|
|
|
|
|
14 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
15 |
+
|
16 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
17 |
CONVERSION_SCRIPT = "./llama.cpp/convert_hf_to_gguf.py"
|
18 |
|
|
|
225 |
fp16 = str(Path(outdir)/f"{model_name}.fp16.gguf")
|
226 |
|
227 |
with tempfile.TemporaryDirectory(dir=downloads_dir) as tmpdir:
|
228 |
+
print("Downloading")
|
229 |
local_dir = Path(tmpdir)/model_name
|
|
|
230 |
api.snapshot_download(repo_id=model_id, local_dir=local_dir, local_dir_use_symlinks=False, allow_patterns=dl_pattern)
|
231 |
+
|
232 |
config_dir = local_dir/"config.json"
|
233 |
adapter_config_dir = local_dir/"adapter_config.json"
|
234 |
if os.path.exists(adapter_config_dir) and not os.path.exists(config_dir):
|
235 |
raise Exception("adapter_config.json is present. If converting LoRA, use GGUF-my-lora.")
|
236 |
+
|
237 |
+
print("Download successfully")
|
238 |
result = subprocess.run(["python", CONVERSION_SCRIPT, local_dir, "--outtype", "f16", "--outfile", fp16], shell=False, capture_output=True)
|
239 |
+
print("Converted to f16")
|
240 |
if result.returncode != 0:
|
241 |
raise Exception(f"Error converting to fp16: {result.stderr.decode()}")
|
242 |
+
|
243 |
imatrix_path = Path(outdir)/"imatrix.dat"
|
244 |
if use_imatrix:
|
245 |
train_data_path = train_data_file.name if train_data_file else "llama.cpp/groups_merged.txt"
|
|
|
249 |
|
250 |
quant_methods = [imatrix_q_method] if use_imatrix else (q_method if isinstance(q_method, list) else [q_method])
|
251 |
suffix = "imat" if use_imatrix else None
|
252 |
+
|
253 |
gguf_files = []
|
254 |
for method in quant_methods:
|
255 |
+
print("Begin quantize")
|
256 |
name = f"{model_name.lower()}-{method.lower()}-{suffix}.gguf" if suffix else f"{model_name.lower()}-{method.lower()}.gguf"
|
257 |
path = str(Path(outdir)/name)
|
258 |
quant_cmd = ["./llama.cpp/llama-quantize", "--imatrix", imatrix_path, fp16, path, method] if use_imatrix else ["./llama.cpp/llama-quantize", fp16, path, method]
|
|
|
262 |
size = os.path.getsize(path)/1024/1024/1024
|
263 |
gguf_files.append((name, path, size, method))
|
264 |
|
265 |
+
print("Quantize successfully!")
|
266 |
suffix_for_repo = f"{imatrix_q_method}-imat" if use_imatrix else "-".join(quant_methods)
|
267 |
repo_id = f"{repo_namespace}/{model_name}-{suffix_for_repo}-GGUF"
|
268 |
new_repo_url = api.create_repo(repo_id=repo_id, exist_ok=True, private=private_repo)
|