projects / proj-flag-011
Next task →
Projects/Deep Learning/Reproduce GPT-2 small from scratch on OpenWebText
Level 5 · research · ~70 h

Reproduce GPT-2 small from scratch on OpenWebText

Implement GPT-2 small (124M parameters) from scratch and train it on a reduced OpenWebText corpus, matching the original architecture, tokenizer and training recipe, then evaluate zero-shot perplexity on standard datasets.
Add to portfolio →

Problem statement

  • 01Implement GPT-2 small (124M parameters) from scratch and train it on a reduced OpenWebText corpus, matching the original architecture, tokenizer and training recipe, then evaluate zero-shot perplexity on standard datasets.

Real-world motivation

  • 01GPT-2 is small enough to reproduce yet large enough that training-detail errors become visible in perplexity and sample quality.

Learning objectives

  • 01Implement the exact GPT-2 architecture and BPE tokenizer
  • 02Train with the original hyperparameters at reduced scale
  • 03Report zero-shot perplexity and sampling quality

Technical architecture

  • 0112-layer decoder-only transformer, 768 hidden, 12 heads
  • 02learned positional embeddings and GELU activations
  • 03weight tying between embeddings and lm_head

Mathematical foundations

  • 01causal language modeling loss $-\sum_t\log p(x_t|x_{<t})$
  • 02AdamW with linear warmup and cosine decay

Dataset and sources

  • 01OpenWebText reduced corpus (1B tokens or scaled subset)
  • 02WikiText-103 and PTB for zero-shot evaluation

Step-by-step tasks

  • 01Implement the BPE tokenizer and verify round trips
  • 02Build the model with exact parameter count
  • 03Set up distributed training with gradient accumulation
  • 04Train with the schedule and gradient clipping
  • 05Evaluate zero-shot perplexity on WikiText-103
  • 06Sample completions and analyze repetition

Implementation requirements

  • 01Use GPT-2 BPE ranks from the public vocab
  • 02Enable activation checkpointing
  • 03Log loss and gradient norm every step

Testing requirements

  • 01Verify parameter count equals 124M
  • 02Check tokenizer round trip on 1000 strings
  • 03Run an overfit test on a small corpus

Evaluation metrics

  • 01zero-shot perplexity
  • 02Bits per token
  • 03sample repetition rate
  • 04tokens per second

Expected outputs

  • 01model implementation
  • 02trained checkpoint
  • 03perplexity table
  • 04sample generations

Common failure modes

  • 01weight tying omitted increases parameter count
  • 02wrong BPE decoding produces invalid text
  • 03insufficient warmup causes loss spikes

Stretch goals

  • 01implement mixed precision with bf16
  • 02compare with the official GPT-2 weights on the same eval

Research extensions

  • 01study the effect of data repetition on perplexity
  • 02analyze emergent capabilities at this scale

GitHub submission requirements

  • 01Full training code
  • 02Tokenizer implementation and tests
  • 03Evaluation report
  • 04Generation samples and seeds

Completion rubric

  • 01architecture matches GPT-2 exactly
  • 02tokenizer verified
  • 03training recipe reproduced
  • 04perplexity reported
  • 05failures documented

Submit when every rubric item is satisfied and your repository contains runnable code plus a reproduction command.