29
29
import numpy as np
30
30
from sentencepiece import SentencePieceProcessor
31
31
32
+ logger = logging .getLogger (__name__ )
33
+
32
34
if 'NO_LOCAL_GGUF' not in os .environ :
33
35
sys .path .insert (1 , str (Path (__file__ ).parent / 'gguf-py' ))
34
36
import gguf
@@ -638,7 +640,7 @@ def __repr__(self) -> str:
638
640
639
641
640
642
def permute (weights : NDArray , n_head : int , n_head_kv : int ) -> NDArray :
641
- # logging .info( "permute debug " + str(weights.shape[0]) + " x " + str(weights.shape[1]) + " nhead " + str(n_head) + " nheadkv " + str(n_kv_head) )
643
+ # logger .info( "permute debug " + str(weights.shape[0]) + " x " + str(weights.shape[1]) + " nhead " + str(n_head) + " nheadkv " + str(n_kv_head) )
642
644
if n_head_kv is not None and n_head != n_head_kv :
643
645
n_head = n_head_kv
644
646
return (weights .reshape (n_head , 2 , weights .shape [0 ] // n_head // 2 , * weights .shape [1 :])
@@ -1027,12 +1029,12 @@ def check_vocab_size(params: Params, vocab: BaseVocab, pad_vocab: bool = False)
1027
1029
1028
1030
# Check for a vocab size mismatch
1029
1031
if params .n_vocab == vocab .vocab_size :
1030
- logging .warning ("Ignoring added_tokens.json since model matches vocab size without it." )
1032
+ logger .warning ("Ignoring added_tokens.json since model matches vocab size without it." )
1031
1033
return
1032
1034
1033
1035
if pad_vocab and params .n_vocab > vocab .vocab_size :
1034
1036
pad_count = params .n_vocab - vocab .vocab_size
1035
- logging .debug (
1037
+ logger .debug (
1036
1038
f"Padding vocab with { pad_count } token(s) - <dummy00001> through <dummy{ pad_count :05} >"
1037
1039
)
1038
1040
for i in range (1 , pad_count + 1 ):
@@ -1160,7 +1162,7 @@ def write_tensor_data(self, ftype: GGMLFileType, model: LazyModel, concurrency:
1160
1162
elapsed = time .time () - start
1161
1163
size = ' x ' .join (f"{ dim :6d} " for dim in lazy_tensor .shape )
1162
1164
padi = len (str (len (model )))
1163
- logging .info (
1165
+ logger .info (
1164
1166
f"[{ i + 1 :{padi }d} /{ len (model )} ] Writing tensor { name :38s} | size { size :16} | type { lazy_tensor .data_type .name :4} | T+{ int (elapsed ):4} "
1165
1167
)
1166
1168
self .gguf .write_tensor_data (ndarray )
@@ -1275,12 +1277,12 @@ def convert_model_names(model: LazyModel, params: Params, skip_unknown: bool) ->
1275
1277
# HF models permut or pack some of the tensors, so we need to undo that
1276
1278
for i in itertools .count ():
1277
1279
if f"model.layers.{ i } .self_attn.q_proj.weight" in model :
1278
- logging .debug (f"Permuting layer { i } " )
1280
+ logger .debug (f"Permuting layer { i } " )
1279
1281
tmp [f"model.layers.{ i } .self_attn.q_proj.weight" ] = permute_lazy (model [f"model.layers.{ i } .self_attn.q_proj.weight" ], params .n_head , params .n_head )
1280
1282
tmp [f"model.layers.{ i } .self_attn.k_proj.weight" ] = permute_lazy (model [f"model.layers.{ i } .self_attn.k_proj.weight" ], params .n_head , params .n_head_kv )
1281
1283
# tmp[f"model.layers.{i}.self_attn.v_proj.weight"] = model[f"model.layers.{i}.self_attn.v_proj.weight"]
1282
1284
elif f"model.layers.{ i } .self_attn.W_pack.weight" in model :
1283
- logging .debug (f"Unpacking and permuting layer { i } " )
1285
+ logger .debug (f"Unpacking and permuting layer { i } " )
1284
1286
tmp [f"model.layers.{ i } .self_attn.q_proj.weight" ] = permute_part_lazy (model [f"model.layers.{ i } .self_attn.W_pack.weight" ], 0 , params .n_head , params .n_head )
1285
1287
tmp [f"model.layers.{ i } .self_attn.k_proj.weight" ] = permute_part_lazy (model [f"model.layers.{ i } .self_attn.W_pack.weight" ], 1 , params .n_head , params .n_head_kv )
1286
1288
tmp [f"model.layers.{ i } .self_attn.v_proj.weight" ] = part_lazy (model [f"model.layers.{ i } .self_attn.W_pack.weight" ], 2 )
@@ -1293,15 +1295,15 @@ def convert_model_names(model: LazyModel, params: Params, skip_unknown: bool) ->
1293
1295
tensor_type , name_new = tmap .get_type_and_name (name , try_suffixes = (".weight" , ".bias" )) or (None , None )
1294
1296
if name_new is None :
1295
1297
if skip_unknown :
1296
- logging .warning (f"Unexpected tensor name: { name } - skipping" )
1298
+ logger .warning (f"Unexpected tensor name: { name } - skipping" )
1297
1299
continue
1298
1300
raise ValueError (f"Unexpected tensor name: { name } . Use --skip-unknown to ignore it (e.g. LLaVA)" )
1299
1301
1300
1302
if tensor_type in should_skip :
1301
- logging .debug (f"skipping tensor { name_new } " )
1303
+ logger .debug (f"skipping tensor { name_new } " )
1302
1304
continue
1303
1305
1304
- logging .debug (f"{ name :48s} -> { name_new :40s} | { lazy_tensor .data_type .name :6s} | { lazy_tensor .shape } " )
1306
+ logger .debug (f"{ name :48s} -> { name_new :40s} | { lazy_tensor .data_type .name :6s} | { lazy_tensor .shape } " )
1305
1307
out [name_new ] = lazy_tensor
1306
1308
1307
1309
return out
@@ -1366,7 +1368,7 @@ def load_some_model(path: Path) -> ModelPlus:
1366
1368
paths = find_multifile_paths (path )
1367
1369
models_plus : list [ModelPlus ] = []
1368
1370
for path in paths :
1369
- logging .info (f"Loading model file { path } " )
1371
+ logger .info (f"Loading model file { path } " )
1370
1372
models_plus .append (lazy_load_file (path ))
1371
1373
1372
1374
model_plus = merge_multifile_models (models_plus )
@@ -1407,7 +1409,7 @@ def _create_vocab_by_path(self, vocab_types: list[str]) -> Vocab:
1407
1409
else :
1408
1410
raise FileNotFoundError (f"Could not find a tokenizer matching any of { vocab_types } " )
1409
1411
1410
- logging .info (f"Loaded vocab file { vocab .fname_tokenizer !r} , type { vocab .name !r} " )
1412
+ logger .info (f"Loaded vocab file { vocab .fname_tokenizer !r} , type { vocab .name !r} " )
1411
1413
return vocab
1412
1414
1413
1415
def load_vocab (self , vocab_types : list [str ] | None , model_parent_path : Path ) -> tuple [BaseVocab , gguf .SpecialVocab ]:
@@ -1517,7 +1519,6 @@ def main(args_in: list[str] | None = None) -> None:
1517
1519
"f16" : GGMLFileType .MostlyF16 ,
1518
1520
"q8_0" : GGMLFileType .MostlyQ8_0 ,
1519
1521
}[args .outtype ]
1520
-
1521
1522
logging .info (f"params = { params } " )
1522
1523
1523
1524
model_parent_path = model_plus .paths [0 ].parent
0 commit comments