Downloads · 30 days
0
adesh01/gpt2-124m-sft-dolly
gpt2-124m-sft-dolly is a text generation model from adesh01. Use it when you need the model to write or continue text. The card lists the license as mit.
A GPT-2 124M model trained entirely from scratch, then instruction-tuned.
Downloads · 30 days
0
Access
Public
Updated Feb 26, 2026
Repo size
1.5 GB
Likes
0
Public
Click a slice to open those files.
.pt1.5 GB · 100%
From the Hugging Face model README
A GPT-2 124M model trained entirely from scratch, then instruction-tuned.
import torch
import tiktoken
from torch.nn import functional as F
# Load model (paste GPT class definition first)
checkpoint = torch.load('model_sft_best.pt', weights_only=False, map_location='cuda')
model = GPT(checkpoint['config'])
model.load_state_dict(checkpoint['model'])
model.eval()
enc = tiktoken.get_encoding('gpt2')
EOT = enc._special_tokens['<|endoftext|>']
def chat(prompt, max_new_tokens=200, temperature=0.7, top_k=40):
formatted = f"<|user|>\n{prompt}\n<|assistant|>\n"
tokens = enc.encode(formatted)
x = torch.tensor(tokens, dtype=torch.long).unsqueeze(0).cuda()
with torch.no_grad():
for _ in range(max_new_tokens):
logits = model(x)[:, -1, :].float() / temperature
v, _ = torch.topk(logits, top_k)
logits[logits < v[:, [-1]]] = float('-inf')
next_tok = torch.multinomial(F.softmax(logits, dim=-1), 1)
if next_tok.item() == EOT:
break
x = torch.cat([x, next_tok], dim=1)
return enc.decode(x[0, len(tokens):].tolist())
print(chat("What are the benefits of exercise?"))