Views
No views yet
model.py and tokenizer.json to load the model:1import torch
2from tokenizers import Tokenizer
3from model import GPT
4
5# Load model checkpoint
6checkpoint = torch.load("dpo_model.pt", map_location="cpu")
7config = checkpoint["config"]
8model = GPT(config)
9model.load_state_dict(checkpoint["model"])
10model.eval()
11
12# Load tokenizer
13tokenizer = Tokenizer.from_file("tokenizer.json")
14
15# Generate text
16prompt = "<|im_start|>user\nWrite a python function to check if a number is prime.<|im_end|>\n<|im_start|>assistant\n"
17x = torch.tensor(tokenizer.encode(prompt).ids, dtype=torch.long).unsqueeze(0)
18y = model.generate(x, max_new_tokens=150, temperature=0.8, top_k=50)
19print(tokenizer.decode(y[0].tolist()))