11
11
"""
12
12
13
13
import argparse
14
+ import logging
14
15
import mmap
15
16
import os
16
17
import pathlib
34
35
35
36
import gguf
36
37
37
- logger = logging .getLogger ("convert_grok" )
38
-
39
38
GGML_QK8_0 = 32
40
39
GGML_QK4_0 = 32
41
40
GGML_QK4_1 = 32
@@ -216,7 +215,7 @@ def dump_state_dict(f, ggml_type, input_dir, config):
216
215
tensor_ggml_type ,
217
216
)
218
217
weights [name ] = weight , scales
219
- logger . info ("Loaded" , len (weight_names ), "files" )
218
+ logging . debug ("Loaded %i files " , len (weight_names ))
220
219
221
220
f .write_header_to_file ()
222
221
f .write_kv_data_to_file ()
@@ -232,21 +231,23 @@ def dump_state_dict(f, ggml_type, input_dir, config):
232
231
_ , tensor_ggml_type = get_dtype_and_ggml_type (tensor , ggml_type )
233
232
array = maybe_quantize_tensor (tensor , tensor_ggml_type ).numpy ()
234
233
235
- logger . debug (
236
- f"dumping { name } :" ,
237
- f"{ tensor_ggml_type .name } /{ array .dtype } , { list (tensor .shape )} , { array .nbytes } bytes" ,
234
+ logging . info (
235
+ f"dumping { name } :"
236
+ f"{ tensor_ggml_type .name } /{ array .dtype } , { list (tensor .shape )} , { array .nbytes } bytes"
238
237
)
239
238
f .write_tensor_data (array )
240
239
241
240
tensor_info .append ((name , list (tensor .shape ), tensor_ggml_type .name ))
242
241
243
242
try :
244
- print (tabulate (tensor_info , headers = ["name" , "shape" , "dtype" ], tablefmt = "psql" )) # noqa: NP100
243
+ print (
244
+ tabulate (tensor_info , headers = ["name" , "shape" , "dtype" ], tablefmt = "psql" )
245
+ ) # noqa: NP100
245
246
except NameError :
246
247
pass
247
248
248
249
if len (tensor_info ) != len (weight_names ):
249
- logger .warning ("Not all tensors are converted" )
250
+ logging .warning ("Not all tensors are converted" )
250
251
251
252
252
253
def from_numpy (array ):
@@ -379,7 +380,7 @@ def ffn_size(emb_size, widening_factor):
379
380
config .num_experts = len (config .experts )
380
381
381
382
assert config .num_experts >= 2 , "need at least 2 experts"
382
- logger .info ("experts to export:" , config .experts )
383
+ logging .info ("experts to export: %s " , config .experts )
383
384
384
385
f = gguf .GGUFWriter (args .save_path , "grok" , endianess = gguf .GGUFEndian .LITTLE )
385
386
@@ -411,12 +412,12 @@ def ffn_size(emb_size, widening_factor):
411
412
412
413
delta = time .time () - start
413
414
414
- logger .info (f"grok GGUF model saved to { args .save_path } . Total time { delta :.2f} sec" )
415
+ logging .info (f"grok GGUF model saved to { args .save_path } . Total time { delta :.2f} sec" )
415
416
416
417
417
418
def load_vocab (path ):
418
419
def load_spm (p ):
419
- logger .info (f"Loading vocab file { p } " )
420
+ logging .info (f"Loading vocab file { p } " )
420
421
return SentencePieceVocab (p )
421
422
422
423
# Be extra-friendly and accept either a file or a directory. Also, if it's
@@ -452,7 +453,7 @@ def main():
452
453
args = parser .parse_args ()
453
454
454
455
logging .basicConfig (level = logging .DEBUG if args .verbose else logging .INFO )
455
-
456
+
456
457
vocab = load_vocab (
457
458
pathlib .Path (args .vocab_dir ) if args .vocab_dir else pathlib .Path (args .input_dir )
458
459
)
0 commit comments