r/LocalAIStack • u/BitPoper29 • 18m ago
Built 3 LLM architectures from scratch in pure PyTorch (42M Dense vs. 117M-A67M MoE vs. 20M Looped) – Code & HF Checkpoints
/r/OpenSourceeAI/comments/1yawux4/built_3_llm_architectures_from_scratch_in_pure/I built `Spell-Talker` to compare three transformer architectures from scratch in pure PyTorch without high-level training wrappers, keeping the backbone fixed (`512` context, `8` heads, `512` dim, `RMSNorm`, `SwiGLU`, weight-tied `32k` vocab):
Dense (`CustomGPT` – 41.8M): Standard 8-layer decoder baseline.
Sparse MoE (`CustomMoEGPT` – 117.3M total / 67.0M active): Top-2 gating across 4 SwiGLU experts per layer with auxiliary load-balancing loss.
Looped Recurrent (`LoopedCustomGPT` – 20.3M): Single weight-tied transformer block unrolled 8 times during training using truncated BPTT (`bptt_steps=8`), scalable up to 32 steps at inference.
Trained on TinyStories on a single consumer GPU (RTX 3050).
GitHub: https://github.com/BitGeek29/spell-talker
Happy to share training curves or discuss MoE router stability and truncated BPTT in looped blocks!