Views
No views yet
transformers model classes were used. Every component (attention, MLP, blocks, embeddings, the training loop) was hand-coded as part of a learning project to understand the full LLM training pipeline.| Parameters | 77.2M |
| Architecture | Decoder-only GPT (pre-LayerNorm) |
| Layers | 8 |
| Heads | 8 |
| Embedding dim | 512 |
| Context length | 1024 |
| Vocabulary | GPT-2 BPE (50,257) |
| Attention | Flash Attention via PyTorch SDPA |
| Precision | weights stored fp32, trained in bf16 |
| Data | OpenWebText |
| Steps | 5,000 |
| Tokens seen | ~80M |
| Optimizer | AdamW, cosine LR with warmup, weight decay on 2D params |
| Hardware | 1x RTX 5070 Ti (16GB) |
| Wall time | ~20 min |
| Validation loss | 5.24 |
The meaning of life isThe meaning of life is the first ever-to-to-mused of self-lab and the first time period of time.
The difference between these systems, and even the potential difference to be an example of these
two seasons. The reason it might be, but the first time that it's very well worth noting that we
can build up a new one as a result of the whole way we're talking about...model.safetensors — model weights, fp32, optimizer state strippedmodel.py — the from-scratch model definition needed to load these weightsconfig.json — architecture and training metadatatransformers architecture, so load it with the included model.py.1import json, torch
2from safetensors.torch import load_file
3from model import GPT, GPTConfig
4
5cfg = json.load(open("config.json"))
6model = GPT(GPTConfig(
7 n_layer=cfg["n_layer"], n_head=cfg["n_head"], n_embd=cfg["n_embd"],
8 block_size=cfg["block_size"], vocab_size=cfg["vocab_size"], dropout=0.0,
9))
10model.load_state_dict(load_file("model.safetensors"))
11model.eval()
12
13# tokenize with GPT-2 BPE, e.g. via tiktoken:
14import tiktoken
15enc = tiktoken.get_encoding("gpt2")
16ids = torch.tensor([enc.encode("The meaning of life is")])
17
18with torch.no_grad():
19 for _ in range(50):
20 logits, _ = model(ids[:, -cfg["block_size"]:])
21 nxt = torch.softmax(logits[:, -1, :] / 0.8, dim=-1).multinomial(1)
22 ids = torch.cat([ids, nxt], dim=1)
23print(enc.decode(ids[0].tolist()))