Qwen-style LM from scratch

Decoder-only transformer in PyTorch with GQA, RoPE, RMSNorm, and SwiGLU. Trained on Tiny Shakespeare.

Model on Hugging FaceGitHub

A Qwen-like decoder-only model written from scratch in PyTorch. Not a thin wrap around transformers model classes. I wanted the pieces modern small LMs actually use under my fingers.

Architecture#

Implemented in model.py:

Hyperparameters for the Shakespeare run (see config.json) stay small on purpose. This is not full Qwen scale:

SettingValue
n_dim512
hidden_dim768
n_heads8
n_groups4 (GQA)
depth12
seq_len128
tokenizerGPT-2 vocab (~50k)

Training and inference#

Tokenizer files under tokenizer/ keep encode and decode aligned with training.

Why it exists#

I wanted one stack that owns GQA, RoPE, SwiGLU, and RMSNorm end to end: train, checkpoint, sample, publish. Handy when I want to poke group count, depth, or seq len without first wrestling a huge open-weight codebase.