What does it take to reproduce a foundational language model—not by fine-tuning an existing checkpoint, but by constructing the network, preparing the corpus, and carrying a random initialization through a complete pretraining run?
This project implements GPT-2 small as a compact, readable PyTorch system. It includes causal multi-head self-attention, pre-normalized residual blocks, tied token and output weights, distributed-aware data loading, bfloat16 training, deterministic evaluation, and exact checkpoint resume. The final model processed 9,999,745,024 tokens over 19,073 optimizer steps.
The result is intentionally modest in scale and unusually complete in documentation. The model, training record, public demo, metrics, checkpoint verification, recovery chronology, and source code can all be inspected independently.
02 · Architecture
A small Transformer, shown all the way through.
GPT-2 is a decoder-only Transformer: every token can attend only to itself and earlier tokens. The implementation uses learned token and position embeddings, twelve identical pre-LN Transformer blocks, a final layer norm, and a vocabulary projection whose weights are shared with the input embedding table.
12× Transformer blocks
Both sublayers use pre-normalization and residual addition. Attention calls
PyTorch’s scaled dot-product kernel with is_causal=True; the MLP
expands the channel width by 4× before projecting back.
Weight tying reuses the 38.6M-token embedding matrix for output logits, avoiding a second vocabulary projection with the same shape.
03 · Data
Ten billion educational tokens, verified shard by shard.
Training used the FineWeb-Edu
sample-10BT configuration. Documents were encoded with the GPT-2
tiktoken vocabulary, prefixed with the end-of-text token, stored as
compact uint16 arrays, and divided into 100 verified shards.
- 01FineWeb-Edusample-10BT documents
- 02GPT-2 tokenizerEOT + ordinary tokens
- 03NumPy shardsup to 100M uint16 tokens
- 04Verify & hashreadability, size, SHA-256
- 05Manifest complete100 shards · ~19.9 GB
Ordered loading
Shard names are validated and numerically ordered before training. A malformed, duplicated, or missing shard causes a preflight failure rather than an expensive partial run.
Deterministic position
DataLoaderLite records the rank-zero data position plus batch,
sequence, and world-size metadata, allowing every distributed rank to reconstruct
its exact position after resume.
04 · Training
A production recipe small enough to audit.
Each optimizer step aggregates 32 micro-batches of 16 sequences × 1,024 tokens, producing an effective batch of 524,288 tokens. The run uses AdamW, bfloat16 autocasting, gradient clipping, linear warmup, and cosine learning-rate decay.
- Maximum learning rate
- 6 × 10−4
- Minimum learning rate
- 6 × 10−5
- Warmup
- 715 steps
- Weight decay
- 0.1
- Gradient clipping
- 1.0
- Precision
- bfloat16
- Initialization seed
- 42
- Compilation
- Disabled
The complete schedule is defined by the run configuration; the committed scalar history contains the final continuation segment.
05 · Results
The terminal checkpoint improved cleanly to the end.
The final checkpoint records a training loss of 3.1033, validation loss of 3.0308, and validation perplexity of 20.71. The graphs below are generated directly from the committed CSV and clearly mark the observed continuation window.
3,016 / 10,042 correct. The 29.4% reference is Karpathy’s evaluation of the released checkpoint, not a number from OpenAI’s original paper. The datasets differ and the reference is rounded, so this is a descriptive—not controlled—comparison.
06 · Reliability
The run survived because state was treated as a product.
The most consequential engineering work was not another model layer. It was making a multi-hour paid run recoverable: atomic local checkpoints, complete optimizer and RNG state, verified uploads, bounded retries, resumable downloads, and a latest pointer that advances only after integrity checks pass.
-
01
Artifact channel overflowMoved to progressive, verified object-storage uploads.
The tokenized dataset exceeded the 5 GiB batch artifact path.
-
02
Preparation retriesRestored the ordered original loader and retained completed shards.
Runtime image, tokenizer resources, and workspace constraints surfaced.
-
03
Checkpoint response lossSwitched to local SHA-256 plus remote size and sidecar checks.
A synchronizer lost a response while rereading a large object.
-
04
Interrupted transfersAdded bounded retries, range resume, and atomic finalization.
Transient upload and download failures threatened continuation.
-
05
Verified continuationResumed at completed step + 1 and finished step 19,073.
Model, optimizer, loader, RNG, token count, and W&B identity restored.
019073.ptformat v1
- Model149 tensors · 124.48M parameters
- OptimizerAdamW momentum and variance state
- Data loaderShard, position, batch, and rank state
- RandomnessCPU, CUDA, Python, and NumPy RNG
- ProvenanceConfig, Git SHA, W&B ID, elapsed time
- IntegritySize, SHA-256, sidecar, and latest pointer
SHA-256e519d993d20c98c841ef061f76a1dec3e6ee24d5e55162bdea2a3e2da280fd40
07 · Samples
What the base model continues.
These fixed-seed samples use top-50 sampling and a 72-token total sequence limit. They are qualitative examples, not benchmark scores. Their unevenness is representative of a small, unaligned completion model.
The future of artificial intelligence is
The future of artificial intelligence is also expanding. As artificial intelligence and its algorithms have increasingly grown, the field continues to rely heavily on human experts and computer vision researchers to guide its operations and its algorithms remain largely untrained…
In a surprising scientific discovery,
In a surprising scientific discovery, Professor O’Donovan describes how our eyes react to food and what the science means. “I just love that, since it reminds me I can.” “What’s next,” Sitting and listening to our voices…
Once upon a time in a small village,
Once upon a time in a small village, two Indians (Atharaswadasa, Aayogyaas, Surya, etc.) tried to make their neighbors disappear forever, even after only a few months…
To solve a difficult problem, first
To solve a difficult problem, first evaluate the problem. A good method to help the system identify, solve, and resolve any problem is to first define “problems” using a given number concept…
08 · Intended use and limitations
Useful as a learning artifact. Limited as a language system.
Research and education
- Studying a readable GPT-2 implementation.
- Reproducing training and checkpoint mechanics.
- Exploring base-model text continuation.
- Benchmarking small-model infrastructure.
Autonomous or high-stakes use
- Conversational instruction following.
- Medical, legal, financial, or safety decisions.
- Unsafeguarded public content generation.
- Claims requiring factual reliability.
Scale
124M parameters and one approximately 10B-token pass are not competitive with modern frontier systems.
Alignment
No instruction tuning, preference optimization, refusal training, or dedicated safety tuning was performed.
Content risks
Outputs may be incorrect, incoherent, biased, unsafe, or stylistically derivative of pretraining data.
Evaluation coverage
HellaSwag is the only full downstream benchmark; no broad safety, bias, memorization, or toxicity suite was run.
Evidence window
The committed scalar history covers the final continuation segment, while terminal metrics come from the verified final checkpoint.
09 · Reproducibility and resources
Follow every important claim back to evidence.
The public release separates narrative from evidence. Human-readable reports explain the run; JSON, CSV, configuration, source, and checkpoint records make its central claims inspectable.
Use the model
Hugging Face modelWeights, tokenizer, configuration ↗ Live demoCPU text-completion interface ↗ Weights & Biases runFinished history at step 19,073 ↗Inspect the evidence
Final metricsMachine-readable terminal record ↗ Checkpoint verificationSize, hash, state, and load checks ↗ Training historyCommitted scalar continuation ↗ Generated samplesPrompts and reproduction settings ↗Read the implementation
Model architectureAttention, MLP, blocks, GPT forward ↗ Data loaderDeterministic DDP-aware shard traversal ↗ Checkpoint statePayload creation and exact restore ↗ Dataset preparationTokenization and shard creation ↗Methods and context
Original GPT-2 reportArchitecture and WebText framing ↗ HellaSwagDataset and evaluation source ↗ GPT-2 reproduction baseline29.4% comparison source ↗python train_gpt2.py --smoke-test --benchmark-steps 1