dasdasddds/i_like_purple
116
GPT-300M
A 334,808,064 parameter autoregressive transformer language model built entirely from scratch in PyTorch. No pretrained weights. No fine-tuning. Everything from zero.
Architecture
Input Token IDs
↓
Token Embedding (32,000 × 1,024) — 32.8M params
↓
Rotary Position Embeddings (RoPE) — 0 learned params
↓
┌─────────────────────────────────────────────────────┐
│ Transformer Block × 24 layers (12.6M each) │
│ │
│ RMSNorm → Multi-Head Attention → ⊕ Residual │
│ 16 heads × 64d │
│ 4,194,304 params │
│ │
│ RMSNorm → FFN (GELU) → ⊕ Residual │
│ 1,024 → 4,096 → 1,024 │
│ 8,388,608 params │
└─────────────────────────────────────────────────────┘
↓
Final RMSNorm
↓
LM Head (weight-tied with embedding) — 0 extra params
↓
Softmax → Next Token ProbabilitiesParameter Breakdown
Model Details
Training Configuration
Usage
Loading the Model
from model import GPT300M
from config import GPT300MConfig
from tokenizer import BPETokenizer
import torch
# Load config, model, and tokenizer
config = GPT300MConfig()
model = GPT300M(config)
# Load trained weights
checkpoint = torch.load("pytorch_model.bin", map_location="cpu")
model.load_state_dict(checkpoint)
model.eval()
# Load tokenizer
tokenizer = BPETokenizer.load("tokenizer.json")Chat with the Model
from chat import ChatBot
chatbot = ChatBot(model, tokenizer, config)
response = chatbot.chat("Hello! What is machine learning?")
print(response)Interactive Chat
python chat.py --checkpoint pytorch_model.binTraining from Scratch
# Quick test (tiny model)
python train.py --tiny
# Full 300M model
python train.py --data your_training_data.txt
# Multi-GPU
torchrun --nproc_per_node=4 train.py --data your_data.txtFiles
Hardware Requirements
Key Features
- 100% from scratch — no pretrained weights, no HuggingFace Transformers dependency
- Rotary Position Embeddings — better length generalization than learned positions
- RMSNorm — faster than LayerNorm, equally effective
- Flash Attention — via PyTorch 2.0 SDPA
- KV-Cache — efficient autoregressive generation
- Weight tying — saves ~33M parameters
- Chat template — built-in support for multi-turn conversations
- torch.compile — ready for PyTorch 2.0+ compilation
Citation
@misc{gpt300m,
title={GPT-300M: A 300-Million Parameter Language Model From Scratch},
year={2025},
url={https://huggingface.co/YOUR_USERNAME/gpt-300m}
}License
MIT
