OpenArch – PyTorch implementations of modern LLM architectures
TL;DR Highlight
Readable from-scratch PyTorch files for Llama, Qwen, DeepSeek and other open LLM architectures
Who Should Read
A backend developer who uses LLM APIs and wants to compare how model internals like attention and MoE differ in code
Core Mechanics
- One readable file per model
- Llama, Qwen, DeepSeek, Gemma, GPT-OSS, Kimi and more are hand-written in PyTorch.
- Each model folder has a model.py and a short README.md.
- The goal is readability, not production speed.
- Architecture differences at a glance
- The README table lists normalization, positional encoding, attention type and MoE for each model.
- For example, Llama 3 uses GQA with no MoE, while DeepSeek R1 uses Multihead Latent Attention with MoE.
- Gemma 3 and GPT-OSS 20B are listed as GQA with sliding window.
- Only some models are done
- GPT-2 XL, Llama 2/3/4 Maverick, Qwen 3, Kimi K2 and GLM 4.5 are marked ✅ for forward passes.
- Qwen3 Next, Qwen3-VL and Dall-e are marked 🚧 as under construction.
- The target list follows the 103 architectures in Sebastian Raschka's Architecture Gallery.
- Explicitly not for production
- The author says it is not meant to compete with transformers or other production libraries.
- It recommends official implementations or transformers for production use.
- Any implementation errors are stated to be the author's own.
- Looking for contributors
- Good first contributions include adding a model.py for an unimplemented model or a README for an existing one.
- Adding forward-pass tests that match official weights' outputs on a few tokens is also suggested.
Community Reactions
- Question about how correctness is verified
- A commenter pointed out the README has no details on how correctness is confirmed.
- The README itself lists output-matching tests against official weights as a contribution task.
- Suspicious Kimi K2 router code
- A comment noted that kimi-K2 model.py calls torch.topk with k=self.num_experts.
- Other MoE models use k=self.top_k, and the constructor's top_k=8 is never stored.
- They asked whether dense routing was intentional or a bug.
- Surprise that open-weight models need custom code
- One commenter said they only just learned that weights alone need architecture-specific code to run.
- They asked whether hosting providers differ in inference engine implementation, not just quantization and configuration.
- Concern about solo maintenance
- A commenter asked whether one individual maintainer can keep up with future model releases.
- Another was struck by how short and simple the implementations are.
How to Apply
- Open two models' model.py files side by side
- Clone the Llama 3 and DeepSeek folders today and compare their attention code.
- Ask an AI to explain how GQA and Multihead Latent Attention differ in the code.
- Tabulate the architecture of models you use
- Find the open models your team uses in the README table and note attention and MoE.
- Add one line on architecture differences to your model selection doc.
- Cross-check what you read against official code
- When using it for learning, compare the same parts with the official transformers implementation.
- For services, follow the author's advice and use official implementations or transformers.
Try It
# Paste into Claude or ChatGPT (simple study prompt using OpenArch)
Below is the model.py code for {{Model A name}} and {{Model B name}}.
[Model A code]
{{paste Model A model.py}}
[Model B code]
{{paste Model B model.py}}
Compare the two implementations in a table by: normalization, positional encoding, attention type, MoE presence and routing. Explain with analogies a backend developer would understand.
Next: if any router or attention code looks suspicious, ask how it differs from the official implementation.Terminology
Related Papers
Gemini 4 Neon is the new #1 on the Models Engineering Index
Gemini 4 Neon ranks first on the Models Engineering Index with 68.0, combining multiple benchmarks.
LLMs can read and write executables byte by byte from a hex dump
Given only a hex dump and no tools, an LLM analyzed, patched and wrote working executables.
Claude was trained on protein sequences at scale
Next-amino-acid tests on obscure proteins show only the latest Claude models predict them
Remembered as Brief: Stored Preferences SilentlyRemove Decision-Critical Information
A stored 'keep it short' preference silently drops warnings; listing must-know points first restores content.
All AI-generated code should be Open Source
A blog argues AI-generated code should be open source; most HN commenters disagreed.
What thousands of conversations look like inside a language model
Mapping Qwen3-1.7B states showed Chinese sitting apart from English, while German and Croatian overlapped it.
AI, activity, and outcomes in software engineering
AI sped up writing code, but shipping speed did not rise as much, says a talk
LLMs Play Zachtronics' TIS-100
16 LLMs played TIS-100 and set 133 new Pareto frontier points across 18 puzzles