Skip to content

Commit

Permalink
let's add a version line. i learned this from llama2c, where not doin…
Browse files Browse the repository at this point in the history
…g this caused a ton of chaos and suffering
  • Loading branch information
karpathy committed Feb 18, 2024
1 parent a0a05f8 commit bbf845d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions minbpe/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def save(self, file_prefix):
# write the model: to be used in load() later
model_file = file_prefix + ".model"
with open(model_file, 'w') as f:
# write the pattern on the first line
# write the version, pattern and merges, that's all that's needed
f.write(f"minbpe v1\n")
f.write(f"{self.pattern}\n")
# the merges dict is the only critical information we need
for idx1, idx2 in self.merges:
f.write(f"{idx1} {idx2}\n")
# write the vocab: for the human to look at
Expand Down Expand Up @@ -135,7 +135,10 @@ def load(self, model_file):
merges = {}
idx = 256
with open(model_file, 'r') as f:
# read the pattern from the first line
# read the version
version = f.readline().strip()
assert version == "minbpe v1"
# read the pattern
self.pattern = f.readline().strip()
# read the merges
for line in f:
Expand Down

0 comments on commit bbf845d

Please sign in to comment.