-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgen_model_files.py
More file actions
36 lines (29 loc) · 1.25 KB
/
Copy pathgen_model_files.py
File metadata and controls
36 lines (29 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import mmap
import struct
import os
import argparse
from scripts.config import Config
from scripts.tokenizer import Tokenizer
from scripts.weights import Weights
MODEL_FILE_PATH = 'scripts/input/stories260K.bin'
TOKENIZER_FILE_PATH = 'scripts/input/tok512.bin'
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate model files from checkpoints and tokenizer data.")
parser.add_argument("--checkpoint",
default=MODEL_FILE_PATH,
help="Path to the model checkpoint file. Default is 'stories260K.bin'.")
parser.add_argument("--tokenizer",
default=TOKENIZER_FILE_PATH,
help="Path to the tokenizer file. Default is 'tok512.bin'.")
args = parser.parse_args()
config = Config()
config.read_checkpoint(args.checkpoint, "config.bin")
tokenizer = Tokenizer()
tokenizer.build_tokenizer(args.tokenizer, config.vocab_size)
tokenizer.save_tokenizer("tokenizer.bin")
tokenizer.free_tokenizer()
weights = Weights()
weights.read_weights(args.checkpoint, "weights.psp")
print(f"Tokenizer saved to tokenizer.bin")
print(f"Config saved to config.bin")
print(f"Weights saved as PSP image to weights.psp")