karpathy/tiny_shakespeare
Updated • 4.4k • 87
This is a small custom Generative Pre-trained Transformer (GPT) model trained on the Tiny Shakespeare dataset. It features a Mixture of Experts (MoE) architecture and Grouped-Query Attention (GQA).
You can use this model by cloning the original repository, as it requires the custom architecture implementation.
import torch
from src.model import GPT, GPTConfig
# Load the configuration and initialize the model
config = GPTConfig(
block_size=256,
n_layer=4,
n_head=4,
n_kv_head=2,
n_embd=128,
n_experts=8,
num_experts_per_tok=2
)
model = GPT(config)
# Load the weights from the safetensors file
from safetensors.torch import load_file
state_dict = load_file("model.safetensors")
model.load_state_dict(state_dict)
model.eval()
model.to('cuda' if torch.cuda.is_available() else 'cpu')
# You can now generate text using the `model.generate` method
# (assuming you have the tokenizer loaded from the original repo)