@@ -32,7 +32,7 @@ def parse_args():
32
32
return parser .parse_args ()
33
33
34
34
def get_n_parts (dim ):
35
-
35
+
36
36
mappings = {4096 : 1 , 5120 : 2 , 6656 : 4 , 8192 : 8 }
37
37
n_parts = mappings .get (dim )
38
38
if n_parts is None :
@@ -43,7 +43,7 @@ def get_n_parts(dim):
43
43
return n_parts
44
44
45
45
def load_hparams_and_tokenizer (dir_model ):
46
-
46
+
47
47
fname_hparams = f"{ dir_model } /params.json"
48
48
fname_tokenizer = f"{ dir_model } /../tokenizer.model"
49
49
@@ -57,7 +57,7 @@ def load_hparams_and_tokenizer(dir_model):
57
57
return hparams , tokenizer
58
58
59
59
def write_header (fout , hparams , ftype ):
60
-
60
+
61
61
keys = ["vocab_size" , "dim" , "multiple_of" , "n_heads" , "n_layers" ]
62
62
values = [
63
63
0x67676d6c , # magic: ggml in hex
@@ -88,26 +88,17 @@ def write_tokens(fout, tokenizer):
88
88
89
89
def process_and_write_variables (fout , model , ftype ):
90
90
91
- for name , data in model .items ():
92
-
91
+ for name , datao in model .items ():
92
+
93
93
if name .endswith ("freqs" ):
94
94
continue
95
-
96
- shape = data .shape
97
-
98
- print (f"Processing variable: { name } with shape: { shape } and type: { data .dtype } \n " )
99
-
100
- data = np .squeeze (data )
101
- n_dims = len (shape )
102
95
103
- # for efficiency - transpose some matrices
104
- # "model/h.*/attn/c_attn/w"
105
- # "model/h.*/attn/c_proj/w"
106
- # "model/h.*/mlp/c_fc/w"
107
- # "model/h.*/mlp/c_proj/w"
108
- #if name.endswith(("/attn/c_attn/w", "/attn/c_proj/w", "/mlp/c_fc/w", "/mlp/c_proj/w")):
109
- # print("Transposing")
110
- # data = data.transpose()
96
+ shape = datao .shape
97
+
98
+ print (f"Processing variable: { name } with shape: { shape } and type: { datao .dtype } " )
99
+
100
+ data = datao .numpy ().squeeze ()
101
+ n_dims = len (shape )
111
102
112
103
# default type is fp16
113
104
ftype_cur = 1
@@ -122,8 +113,8 @@ def process_and_write_variables(fout, model, ftype):
122
113
for dim in reversed (data .shape ):
123
114
fout .write (struct .pack ("i" , dim ))
124
115
fout .write (sname )
125
-
126
- # data
116
+
117
+ # data output to file
127
118
data .tofile (fout )
128
119
129
120
def main ():
@@ -139,7 +130,7 @@ def main():
139
130
for p in range (n_parts ):
140
131
141
132
print (f"Processing part { p } \n " )
142
-
133
+
143
134
fname_model = f"{ dir_model } /consolidated.0{ p } .pth"
144
135
fname_out = f"{ dir_model } /ggml-model-{ ftype_str [ftype ]} .bin{ '' if p == 0 else '.' + str (p )} "
145
136
0 commit comments