CoolFace
Modelpublic

Aadit-032/LiteGPT-16M

sourceHugging Facemitupdated 3mo agoView on Hugging Face
0likes16downloads
Model Card

Model Architecture

The goal of LiteGPT-16M is not to achieve state-of-the-art performance, but to provide a clean and understandable implementation of a GPT-style language model that can be trained from scratch and extended with modern techniques in future experiments.

Overview

  • Model type: Decoder-only Transformer
  • Parameters: ~16M
  • Context length: 128
  • Vocabulary size: 50,257
  • Attention: Causal Self-Attention
  • Positional Encoding: Learned Position Embeddings

Architecture Diagram

text
Input Tokens [B, T]
        │
        ▼
┌─────────────────────┐
│  Token Embeddings   │
│  [vocab, d_model]   │
└─────────────────────┘
        │
        ├──────────────┐
        ▼              │
┌─────────────────────┐│
│ Position Embeddings ││
│ [seq_len, d_model]  ││
└─────────────────────┘│
        │              │
        └──────┬───────┘
               ▼
          x = tok + pos
               │
               ▼
╔══════════════════════════════╗
║ Transformer Block × 4        ║
║                              ║
║       LayerNorm              ║
║           │                  ║
║           ▼                  ║
║     Multi-Head Attention     ║
║           │                  ║
║           ▼                  ║
║       Residual Add           ║
║           │                  ║
║           ▼                  ║
║       LayerNorm              ║
║           │                  ║
║           ▼                  ║
║          FFN                 ║
║           │                  ║
║           ▼                  ║
║      Residual Add            ║
╚══════════════════════════════╝
            │
            ▼
┌─────────────────────┐
│   Final LayerNorm   │
└─────────────────────┘
            │
            ▼
┌─────────────────────┐
│      LM Head        │
└─────────────────────┘
            │
            ▼
      Logits [B,T,V]

Configuration

ParameterValue
batch_size16
gradaccumsteps4
n_layers4
d_model256
n_heads4
head_dim64
ffn_dim1024
context_length128
vocab_size50257

Transformer Block

Attention

  • Multi-Head Self Attention
  • Causal Masking

Feed Forward Network

FFN(x) = W2(GELU(W1(x)))

Expansion ratio: 4×

Residual Connections

x = x + Attention(x)

x = x + FFN(x)

Normalization

  • LayerNorm

Parameter Count

ComponentParams
Token Embeddings(nvocab x dmodel) 50257 x 256 = 12,865,792
Position Embeddings(seqlen x dmodel) 128 x 256 = 32,768
Attention([QKV + O] x n_layers) [256 x (3 x 256) + 256 x 256] x 4 = 1,048,576
FFN[(dmodel x (4 x dmodel) + (4 x dmodel) + dmodel)] x n_layers = [256 x 1024 + 1024 x 256] x 4 = 2,097,152
Norm[(2 x dmodel) x nlayers] (2 x 256 x 4) = 2048
Final Norm256
LM Headweight tying with token embeddings
Total~16M

Design Decisions

This model is intentionally kept as close to GPT-2 as possible to build a strong understanding of decoder-only transformers before introducing modern architectural improvements.

GPT-2 Baseline

The model uses:

  • Learned token embeddings
  • Learned positional embeddings
  • Multi-Head Self Attention (MHSA)
  • GELU activations
  • LayerNorm
  • Causal masking

Simplicity Over Performance

Features such as RoPE, GQA, FlashAttention, SwiGLU, RMSNorm, and Mixture-of-Experts are intentionally omitted. While these improve efficiency or performance, they add implementation complexity and make it harder to study the core transformer architecture.

Small Scale Training

The model is designed to train on a single NVIDIA T4 GPU using Google Colab. Model size, context length, and batch size are chosen to fit within limited compute resources.

Dataset

MetricValue
Characters1,115,394
GPT-2 Tokens~338,000
Vocabulary Used~11,706
Full GPT-2 Vocabulary50,257
text
shakespeare.txt
       │
       ▼
┌──────────────────┐
│ GPT-2 Tokenizer  │
│ (tiktoken)       │
└────────┬─────────┘
         │
         ▼
   Token IDs
         │
         ▼
┌──────────────────┐
│ 90/10 Split      │
│ Train / Val      │
└────────┬─────────┘
         │
    ┌────┴────┐
    ▼         ▼
train.bin  val.bin
(uint16)   (uint16)

Tokenizer

  • Type: tiktoken
  • Encoding: gpt2
  • Vocabulary size: 50,257

Storage Format

train.bin

val.bin

dtype = uint16

Training

Hyperparameters

ParameterValue
Batch Size16
Sequence Length256
Learning Rate3e-4
Weight Decay0.1
Warmup Steps2000
Max Steps40000

Results

Final Results

MetricValue
Train Loss2.878491520881653
Val Loss5.985600624084473
Perplexity397.6612944866264