OpenArch – PyTorch implementations of modern LLM architectures
Summary
OpenArch is a GitHub repository providing hand-written PyTorch implementations of modern LLM architectures for educational clarity and side-by-side comparison of structural choices.
View Cached Full Text
Cached at: 09/14/26, 11:45 AM
anuj0456/OpenArch
Source: https://github.com/anuj0456/OpenArch
OpenArch
Python implementations of modern open-source LLM architectures — written from scratch, one model at a time.
This repository contains hand-written PyTorch implementations of the model architectures cataloged in Sebastian Raschka’s LLM Architecture Gallery. Each model is implemented to the best of my knowledge from the original papers, technical reports, reference config.json files, and the excellent writeups by Sebastian Raschka and Machine Learning Mastery.
The goal is not to compete with transformers or other production libraries. The goal is clarity and learning: a single readable file per architecture, with the structural choices (attention type, normalization, layer mix, MoE routing, positional encoding) made explicit and easy to compare side-by-side.
Why this repo?
Modern LLM architectures share a common skeleton but differ in dozens of small, important choices:
- Attention: MHA, GQA, MQA, MLA, sliding-window, linear/DeltaNet hybrids
- Normalization: pre-norm, post-norm, QK-Norm, sandwich norm, RMSNorm
- Positional encodings: RoPE, NoPE, partial RoPE, YaRN
- Decoder type: dense vs sparse MoE (with or without shared experts), hybrid Mamba/attention
- Training-time tricks: Multi-token-prediction, latent experts, gated attention
Reading the official model code can be hard because production repos optimize for speed, sharding, and backward compatibility. This repo optimizes for reading.
What’s implemented (so far)
Implementations marked ✅ are usable for forward passes; those marked 🚧 are under construction.
| Modality | Model | Status | Model Size | Normalization | Positional Encoding | Attention | Mixture of Experts |
|---|---|---|---|---|---|---|---|
| Text | GPT-2 XL | ✅ | 1.5B | - | Absolute | Multihead Attention | No |
| Llama 2 | ✅ | 7B | RMS Norm | RoPE | Multihead Attention | No | |
| Llama 3 | ✅ | 8B | RMS Norm | RoPE | Grouped Query Attention | No | |
| OLMo 2 | ✅ | 7B | RMS Norm & QK-Norm | RoPE | Multihead Attention | No | |
| DeepSeek R1 | ✅ | 671B | RMS Norm & QK-Norm | RoPE | Multihead Latent Attention | Yes | |
| Gemma 3 | ✅ | 27B | RMS Norm & QK-Norm | RoPE | Grouped Query Attention with Sliding Window | No | |
| Mistral 3 | ✅ | 24B | RMS Norm | RoPE | Grouped Query Attention with Sliding Window | No | |
| Llama 4 Maverick | ✅ | 400B | RMS Norm | RoPE | Grouped Query Attention | Yes | |
| Qwen 3 | ✅ | 4B | RMS Norm & QK-Norm | RoPE | Grouped Query Attention | No | |
| 30B-A3B | RMS Norm & QK-Norm | RoPE | Grouped Query Attention | Yes | |||
| Kimi K2 | ✅ | 1T | RMS Norm | RoPE | Multihead Latent Attention | Yes | |
| GLM 4.5 | ✅ | 355B | RMS Norm & QK-Norm | RoPE | Grouped Query Attention & Multi-Token Prediction | Yes | |
| GPT-OSS | ✅ | 20B | RMS Norm | RoPE | Grouped Query Attention with Sliding Window | Yes | |
| Grok-2.5 | 🚧 | 270B | RMS Norm | RoPE | Grouped Query Attention | Yes | |
| Multimodal | PaliGemma | ✅ | 3B | RMS Norm | RoPE | Multihead Attention | No |
| Qwen3 | 🚧 | 3B | RMS Norm | RoPE | Multihead Attention | No | |
| Image | Dall-e | 🚧 | - | - | - | Transformer | - |
The full target list mirrors the 72 architectures in the Architecture Gallery. Contributions toward any of them are welcome.
Repository layout
OpenArch/
├── text/
│ ├── gpt2/
│ │ ├── model.py
│ │ └── README.md
│ ├── llama3/
│ ├── qwen3/
| ├── grok2.5/
│ └── deepseek_v3/
├── multimodal/
│ └── pali-gemma/
│ ├── model.py
│ └── README.md
├── README.md
└── requirements.txt
Each model lives in its own folder with respective model.py and a short README.md describing the architectural choices and references used.
Contributing
I am actively looking for contributors. If you enjoy reading model papers, comparing config.json files, or just want to deepen your understanding of how modern LLMs are built, this is a friendly place to start.
Good first contributions:
- Pick an unimplemented model from the gallery and add a
model.pyfor it - Add a
README.mdfor an existing model documenting its architectural choices - Add a forward-pass test that loads the official weights and matches outputs on a few tokens
- Fix bugs, improve docstrings, or refactor shared components
Please open an issue before starting a large piece of work so we can avoid duplicating effort. Implementations should prioritize readability over performance — this is a learning resource first.
See CONTRIBUTING.md for more details.
Acknowledgements
This repository would not exist without the work of two outstanding educators:
- Sebastian Raschka — for the LLM Architecture Gallery, the Big LLM Architecture Comparison series, and the LLMs From Scratch book and codebase. The architecture diagrams, fact sheets, and side-by-side comparisons in the gallery are the primary reference behind every model in this repo.
- Jason Brownlee and the team at Machine Learning Mastery — for years of clear, accessible tutorials that have helped countless practitioners (myself included) build a working understanding of deep learning and transformer architectures from the ground up.
Any errors in the implementations here are entirely my own.
License
This project is licensed under the Apache License 2.0 — see LICENSE for details. Individual model implementations follow the licenses of the original models where applicable; see each model’s folder for specifics.
Disclaimer
These implementations are written to the best of my knowledge based on publicly available papers, technical reports, configuration files, and educational material. They are intended as a learning resource and are not affiliated with or endorsed by the original model authors. For production use, please use the official implementations or transformers.
Similar Articles
@rasbt: A little talk on what we can learn from implementing LLM architectures from scratch in Python and PyTorch. And how I ap…
Sebastian Raschka discusses the value of implementing LLM architectures from scratch in Python/PyTorch, sharing his workflow for understanding new open-weight models by dissecting configs, coding, and layer-by-layer debugging.
Developing open source LLM from ground up from pretrain - rlhf(PPO/GRPO)
A developer shares progress on training a 7B parameter open source LLM from scratch using a DeepSeek architecture optimized for low VRAM, with the goal of democratizing AI development and eventually surpassing large proprietary models.
@_rohit_tiwari_: Builds GPT-like LLMs from scratch in PyTorch > Breaks the LLM architecture into simple parts. > Beginner friendly. > Fu…
A beginner-friendly, hands-on GitHub repository that breaks down GPT-like LLM architecture into simple parts, with 10 Jupyter notebooks covering tokenization, attention, transformer blocks, and a mini GPT implementation in PyTorch.
Ornith-1.0: Self-scaffolding LLMs for agentic coding
Deep Reinforce releases Ornith-1.0, a family of open-source self-improving LLMs for agentic coding, spanning 9B to 397B parameters and achieving state-of-the-art performance on benchmarks like SWE-Bench Verified and Terminal-Bench 2.1, surpassing Claude Opus 4.7 and other leading open-source models.
@_avichawla: 8 AI model architectures, visually explained: There's a tendency to treat LLMs as the whole field. But they're one fami…
A visual breakdown of 8 major AI model architectures including LLMs, VLMs, MoE, SLMs, and more, plus a bonus mention of recursive language models from MIT.