forked from stellaraccident/llama.turbine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepack_gguf_params.py
66 lines (60 loc) · 1.53 KB
/
repack_gguf_params.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from turbine_llamacpp.params import HParams
import iree.runtime as rt
import torch
import numpy as np
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--gguf_path",
type=str,
default="ggml-model-q4_1.gguf",
help="path to gguf.",
)
parser.add_argument(
"--irpa_path",
type=str,
default="reformatted_parameters.irpa",
help="path to irpa file to save reformatted parameters.",
)
parser.add_argument(
"--dequantize_params",
type=str,
default="token_embd.weight",
help="Comma separated list of parameter names to dequantize instead of repacking.",
)
parser.add_argument(
"--dequantize_all",
type=bool,
default=False,
help="dequantize all parameters instead of repacking them",
)
def main():
args = parser.parse_args()
dequantize_params = args.dequantize_params.split(",")
# Only Q4_1 has repacking support right now. Dequantize all other types.
dequantize_types = [
"F32",
"F16",
"Q4_0",
"Q5_0",
"Q5_1",
"Q8_0",
"Q8_1",
"Q2_K",
"Q3_K",
"Q4_K",
"Q5_K",
"Q6_K",
"Q8_K",
]
hp = HParams(args.gguf_path)
formatted_params = hp.repack_tensor_params(
dequantize_types=dequantize_types,
dequantize_params=dequantize_params,
dtype=torch.float32,
dequantize_all=args.dequantize_all,
)
rt.save_archive_file(formatted_params, args.irpa_path)
print(f"saved to {args.irpa_path}")
if __name__ == "__main__":
main()