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