Skip to content

Commit be5e53f

Browse files
committed
convert.py: named instance logging
1 parent bd00610 commit be5e53f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

convert.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import numpy as np
3030
from sentencepiece import SentencePieceProcessor
3131

32+
logger = logging.getLogger(__name__)
33+
3234
if 'NO_LOCAL_GGUF' not in os.environ:
3335
sys.path.insert(1, str(Path(__file__).parent / 'gguf-py'))
3436
import gguf
@@ -638,7 +640,7 @@ def __repr__(self) -> str:
638640

639641

640642
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) )
642644
if n_head_kv is not None and n_head != n_head_kv:
643645
n_head = n_head_kv
644646
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)
10271029

10281030
# Check for a vocab size mismatch
10291031
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.")
10311033
return
10321034

10331035
if pad_vocab and params.n_vocab > vocab.vocab_size:
10341036
pad_count = params.n_vocab - vocab.vocab_size
1035-
logging.debug(
1037+
logger.debug(
10361038
f"Padding vocab with {pad_count} token(s) - <dummy00001> through <dummy{pad_count:05}>"
10371039
)
10381040
for i in range(1, pad_count + 1):
@@ -1160,7 +1162,7 @@ def write_tensor_data(self, ftype: GGMLFileType, model: LazyModel, concurrency:
11601162
elapsed = time.time() - start
11611163
size = ' x '.join(f"{dim:6d}" for dim in lazy_tensor.shape)
11621164
padi = len(str(len(model)))
1163-
logging.info(
1165+
logger.info(
11641166
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}"
11651167
)
11661168
self.gguf.write_tensor_data(ndarray)
@@ -1275,12 +1277,12 @@ def convert_model_names(model: LazyModel, params: Params, skip_unknown: bool) ->
12751277
# HF models permut or pack some of the tensors, so we need to undo that
12761278
for i in itertools.count():
12771279
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}")
12791281
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)
12801282
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)
12811283
# tmp[f"model.layers.{i}.self_attn.v_proj.weight"] = model[f"model.layers.{i}.self_attn.v_proj.weight"]
12821284
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}")
12841286
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)
12851287
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)
12861288
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) ->
12931295
tensor_type, name_new = tmap.get_type_and_name(name, try_suffixes = (".weight", ".bias")) or (None, None)
12941296
if name_new is None:
12951297
if skip_unknown:
1296-
logging.warning(f"Unexpected tensor name: {name} - skipping")
1298+
logger.warning(f"Unexpected tensor name: {name} - skipping")
12971299
continue
12981300
raise ValueError(f"Unexpected tensor name: {name}. Use --skip-unknown to ignore it (e.g. LLaVA)")
12991301

13001302
if tensor_type in should_skip:
1301-
logging.debug(f"skipping tensor {name_new}")
1303+
logger.debug(f"skipping tensor {name_new}")
13021304
continue
13031305

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}")
13051307
out[name_new] = lazy_tensor
13061308

13071309
return out
@@ -1366,7 +1368,7 @@ def load_some_model(path: Path) -> ModelPlus:
13661368
paths = find_multifile_paths(path)
13671369
models_plus: list[ModelPlus] = []
13681370
for path in paths:
1369-
logging.info(f"Loading model file {path}")
1371+
logger.info(f"Loading model file {path}")
13701372
models_plus.append(lazy_load_file(path))
13711373

13721374
model_plus = merge_multifile_models(models_plus)
@@ -1407,7 +1409,7 @@ def _create_vocab_by_path(self, vocab_types: list[str]) -> Vocab:
14071409
else:
14081410
raise FileNotFoundError(f"Could not find a tokenizer matching any of {vocab_types}")
14091411

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}")
14111413
return vocab
14121414

14131415
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:
15171519
"f16": GGMLFileType.MostlyF16,
15181520
"q8_0": GGMLFileType.MostlyQ8_0,
15191521
}[args.outtype]
1520-
15211522
logging.info(f"params = {params}")
15221523

15231524
model_parent_path = model_plus.paths[0].parent

0 commit comments

Comments
 (0)