roneneldan/TinyStories
Viewer • Updated • 2.14M • 89.9k • 980
A GPT model trained on the TinyStories dataset using PyTorch.
The model uses a transformer architecture with:
from transformers import AutoTokenizer
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
import json
import torch
from sp_lm import GPT
repo_id = "wizardoftrap/SP-LM-alpha"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
config_dict = json.load(open(hf_hub_download(repo_id=repo_id, filename="config.json")))
config = type('Config', (), config_dict)()
model_weights = load_file(hf_hub_download(repo_id=repo_id, filename="model.safetensors"))
model = GPT(config)
model.load_state_dict(model_weights)
prompt = "Once upon a time"
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
generated_ids = model.generate(inputs["input_ids"], max_new_tokens=50, temperature=1.0, top_k=50)
print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
Download sp_lm.py file from this repo for GPT model.
Install required packages:
pip install transformers safetensors huggingface-hub torch