Spaces:
Runtime error
Runtime error
File size: 1,089 Bytes
1fc2558 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from pathlib import Path
from subprocess import run
def convert(model_id:str, precision:str, quantization:bool)->Path:
# Conversion
cmd = [
"python",
"./bloomz.cpp/convert-hf-to-ggml.py",
model_id, # bigscience/bloomz-560m
"./bloomz.cpp/models",
]
if precision == "FP32":
cmd.append("--use-fp32")
run(cmd, check=True)
# Model file should exist
f_suffix = "f32" if precision == "FP32" else "f16"
_, model_name = model_id.split("/")
model_path = Path(f"./bloomz.cpp/models/ggml-model-{model_name}-{f_suffix}.bin")
assert model_path.is_file()
# Quantization
if quantization:
cmd = [
"./bloomz.cpp/quantize",
f"./bloomz.cpp/models/ggml-model-{model_name}-{f_suffix}.bin",
f"./bloomz.cpp/models/ggml-model-{model_name}-{f_suffix}-q4_0.bin",
"2",
]
run(cmd, check=True)
model_path = Path(f"./bloomz.cpp/models/ggml-model-{model_name}-{f_suffix}.bin")
assert model_path.is_file()
# Return
return model_path
|