Skip to content

Commit

Permalink
convert-hf-to-gguf.py: fix flake8 warnings. Removed unused variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mofosyne committed May 10, 2024
1 parent 1088626 commit 95dabb1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions convert-hf-to-gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2293,8 +2293,6 @@ def set_vocab(self):
vocab_size = hparams.get("padded_vocab_size", len(tokenizer.get_vocab()))
assert max(tokenizer.get_vocab().values()) < vocab_size

reverse_vocab = {id_: encoded_tok for encoded_tok, id_ in tokenizer.get_vocab().items()}

for token_id in range(vocab_size):
piece = tokenizer._convert_id_to_token(token_id)
if token_id == 0:
Expand Down Expand Up @@ -2395,7 +2393,7 @@ def write_tensors(self):
),
axis=0,
)
print("re-format attention.linear_qkv.weight")
logger.debug("re-format attention.linear_qkv.weight")
elif re.match(r"h\.\d+\.self_attention\.query_key_value\.bias", name):
qkv_bias = data.reshape((n_head, 3, n_embed // n_head))
data = np.concatenate(
Expand All @@ -2406,12 +2404,12 @@ def write_tensors(self):
),
axis=0,
)
print("re-format attention.linear_qkv.bias")
logger.debug("re-format attention.linear_qkv.bias")

# map tensor names
new_name = tensor_map.get_name(name, try_suffixes=(".weight", ".bias"))
if new_name is None:
print(f"Can not map tensor {name!r}")
logger.error(f"Can not map tensor {name!r}")
sys.exit()

n_dims = len(data.shape)
Expand All @@ -2429,13 +2427,13 @@ def write_tensors(self):
if self.ftype == 1 and data_dtype == np.float32 and name.endswith(".weight") and n_dims == 2:
data = data.astype(np.float16)

print(f"=> {new_name}, shape = {data.shape}, {old_dtype} --> {data.dtype}")
logger.debug(f"=> {new_name}, shape = {data.shape}, {old_dtype} --> {data.dtype}")

self.gguf_writer.add_tensor(new_name, data)

if not has_lm_head and name == "word_embeddings.weight":
self.gguf_writer.add_tensor("output.weight", data)
print(name, f"=> output.weight, shape = {data.shape}, {old_dtype} --> {data.dtype}")
logger.debug(name, f"=> output.weight, shape = {data.shape}, {old_dtype} --> {data.dtype}")


###### CONVERSION LOGIC ######
Expand Down

0 comments on commit 95dabb1

Please sign in to comment.