Skip to content

Commit

Permalink
gpt : add support for gpt-jt + fix unicode support
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Dec 4, 2022
1 parent f56828e commit ed09c71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion examples/gpt-2/convert-ckpt-to-ggml.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def bytes_to_unicode():
byte_decoder = {v:k for k, v in byte_encoder.items()}

fout.write(struct.pack("i", len(encoder)))

for key in encoder:
text = bytearray([byte_decoder[c] for c in key]).decode('utf-8', errors='replace').encode('utf-8')
text = bytearray([byte_decoder[c] for c in key])
fout.write(struct.pack("i", len(text)))
fout.write(text)

Expand All @@ -105,6 +106,10 @@ def bytes_to_unicode():
print(" Converting to float16")
data = data.astype(np.float16)
ftype = 1
else:
print(" Converting to float32")
data = data.astype(np.float32)
ftype = 0

# for efficiency - transpose the projection matrices
if name[-13:] == "/mlp/c_proj/w":
Expand Down
9 changes: 7 additions & 2 deletions examples/gpt-j/convert-h5-to-ggml.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ def bytes_to_unicode():
byte_decoder = {v:k for k, v in byte_encoder.items()}

fout.write(struct.pack("i", len(encoder) + len(encoder_added)))

for key in encoder:
text = bytearray([byte_decoder[c] for c in key]).decode('utf-8', errors='replace').encode('utf-8')
text = bytearray([byte_decoder[c] for c in key])
fout.write(struct.pack("i", len(text)))
fout.write(text)

for key in encoder_added:
text = bytearray([byte_decoder[c] for c in key]).decode('utf-8', errors='replace').encode('utf-8')
text = bytearray([byte_decoder[c] for c in key])
fout.write(struct.pack("i", len(text)))
fout.write(text)

Expand All @@ -119,6 +120,10 @@ def bytes_to_unicode():
print(" Converting to float16")
data = data.astype(np.float16)
ftype = 1
else:
print(" Converting to float32")
data = data.astype(np.float32)
ftype = 0

# for efficiency - transpose these matrices:
# "transformer.h.*.mlp.fc_in.weight
Expand Down

0 comments on commit ed09c71

Please sign in to comment.