HuggingFaceFW/fineweb-edu
Viewer • Updated • 3.5B • 367k • 1.19k
A 44M parameter GPT-2 style language model built from scratch in PyTorch. The BPE tokenizer and the transformer architecture are written by hand. Trained on 99M tokens from FineWeb-edu on Apple Silicon MPS.
This is my parallel track. While the applied post-training work fine-tunes existing models, Phi-4 on dotnet/runtime then the Gemma 3 reasoning adapter then the Gemma 4 GlucoLens adapter, here I go underneath all of it and build the transformer by hand so I understand every part I later adapt. The systems analysis of this run, where the compute and memory walls sit and why the run reached only a small fraction of peak hardware, is written up as a scaling article at https://huggingface.co/blog/kotlarmilos/gpt2-nano.
| Component | Detail |
|---|---|
| Parameters | 44M |
| Layers | 12 |
| Embedding dim | 512 |
| Attention heads | 8 (head_dim = 64) |
| MLP expansion | 4x (512 to 2048 to 512) |
| Context length | 1024 tokens |
| Positional encoding | Sinusoidal, fixed |
| Normalization | Pre-norm LayerNorm |
| Vocab size | 9,157, custom BPE |
import torch
from src.gpt import GPT, generate
from data.bpe_tokenizer import encode, decode, load_tokenizer
ckpt = torch.load("checkpoints/final.pt", map_location="cpu")
gpt = GPT(**ckpt["config"])
gpt.load_state_dict(ckpt["model_state_dict"])
gpt.eval()
merges, vocab = load_tokenizer()
prompt_tokens = encode("The ", merges, vocab)
text = generate(gpt, merges, vocab, prompt_tokens, context_len=1024, max_new_tokens=50)
print(text)
checkpoints/final.pt, model weights, optimizer state, and configbpe-tokenizer/merges.json, BPE merge rulesbpe-tokenizer/vocab.json, token to id mappingbpe-shards/*.bin, pre-tokenized training data in binary format