@@ -1246,6 +1246,37 @@ def pick_output_type(model: LazyModel, output_type_str: str | None) -> GGMLFileT
1246
1246
raise Exception (f"Unexpected combination of types: { name_to_type } " )
1247
1247
1248
1248
1249
+ def model_parameter_count (model : LazyModel ) -> int :
1250
+ total_model_parameters = 0
1251
+ for i , (name , lazy_tensor ) in enumerate (model .items ()):
1252
+ sum_weights_in_tensor = 1
1253
+ for dim in lazy_tensor .shape :
1254
+ sum_weights_in_tensor *= dim
1255
+ total_model_parameters += sum_weights_in_tensor
1256
+ return total_model_parameters
1257
+
1258
+
1259
+ def model_parameter_count_rounded_notation (model_params_count : int ) -> str :
1260
+ if model_params_count > 1e12 :
1261
+ # Trillions Of Parameters
1262
+ scaled_model_params = model_params_count * 1e-12
1263
+ scale_suffix = "T"
1264
+ elif model_params_count > 1e9 :
1265
+ # Billions Of Parameters
1266
+ scaled_model_params = model_params_count * 1e-9
1267
+ scale_suffix = "B"
1268
+ elif model_params_count > 1e6 :
1269
+ # Millions Of Parameters
1270
+ scaled_model_params = model_params_count * 1e-6
1271
+ scale_suffix = "M"
1272
+ else :
1273
+ # Thousands Of Parameters
1274
+ scaled_model_params = model_params_count * 1e-3
1275
+ scale_suffix = "K"
1276
+
1277
+ return f"{ round (scaled_model_params )} { scale_suffix } "
1278
+
1279
+
1249
1280
def convert_to_output_type (model : LazyModel , output_type : GGMLFileType ) -> LazyModel :
1250
1281
return {name : tensor .astype (output_type .type_for_tensor (name , tensor ))
1251
1282
for (name , tensor ) in model .items ()}
@@ -1432,13 +1463,20 @@ def load_vocab(
1432
1463
return vocab , special_vocab
1433
1464
1434
1465
1435
- def default_output_file (model_paths : list [Path ], file_type : GGMLFileType ) -> Path :
1436
- namestr = {
1437
- GGMLFileType .AllF32 : "f32" ,
1466
+ def default_outfile (model_paths : list [Path ], file_type : GGMLFileType , params : Params , model_params_count : int ) -> Path :
1467
+ quantization = {
1468
+ GGMLFileType .AllF32 : "f32" ,
1438
1469
GGMLFileType .MostlyF16 : "f16" ,
1439
1470
GGMLFileType .MostlyQ8_0 : "q8_0" ,
1440
1471
}[file_type ]
1441
- ret = model_paths [0 ].parent / f"ggml-model-{ namestr } .gguf"
1472
+
1473
+ parameters = model_parameter_count_rounded_notation (model_params_count )
1474
+
1475
+ name = "ggml-model"
1476
+ if params .path_model is not None :
1477
+ name = params .path_model .name
1478
+
1479
+ ret = model_paths [0 ].parent / f"{ name } -{ parameters } -{ quantization } .gguf"
1442
1480
if ret in model_paths :
1443
1481
sys .stderr .write (
1444
1482
f"Error: Default output path ({ ret } ) would overwrite the input. "
@@ -1580,6 +1618,9 @@ def main(argv: Optional[list[str]] = None) -> None:
1580
1618
model = {}, paths = [args .model / "dummy" ], format = "none" , vocab = None
1581
1619
)
1582
1620
1621
+ model_params_count = model_parameter_count (model_plus .model )
1622
+ print (f"model parameters count : { model_params_count } ({ model_parameter_count_rounded_notation (model_params_count )} )" )
1623
+
1583
1624
if args .dump :
1584
1625
do_dump_model (model_plus )
1585
1626
return
@@ -1631,11 +1672,18 @@ def main(argv: Optional[list[str]] = None) -> None:
1631
1672
if model_plus .vocab is not None and args .vocab_dir is None :
1632
1673
vocab = model_plus .vocab
1633
1674
1634
- model = model_plus .model
1635
- model = convert_model_names (model , params )
1636
- ftype = pick_output_type (model , args .outtype )
1637
- model = convert_to_output_type (model , ftype )
1638
- outfile = args .outfile or default_output_file (model_plus .paths , ftype )
1675
+ # FIXME: Try to respect vocab_dir somehow?
1676
+ print (f"Vocab info: { vocab } " )
1677
+ special_vocab = gguf .SpecialVocab (model_plus .paths [0 ].parent ,
1678
+ load_merges = True ,
1679
+ n_vocab = vocab .vocab_size )
1680
+
1681
+ print (f"Special vocab info: { special_vocab } " )
1682
+ model = model_plus .model
1683
+ model = convert_model_names (model , params )
1684
+ ftype = pick_output_type (model , args .outtype )
1685
+ model = convert_to_output_type (model , ftype )
1686
+ outfile = args .outfile or default_outfile (model_plus .paths , ftype , params , model_params_count )
1639
1687
1640
1688
params .ftype = ftype
1641
1689
print (f"Writing { outfile } , format { ftype } " )
0 commit comments