OpenArch is a specialized GitHub repository providing hand-written PyTorch implementations of modern Large Language Model (LLM) architectures, designed primarily as a pedagogical resource rather than a high-performance production library. By prioritizing code readability and structural clarity, the project offers single-file implementations for various models cataloged in Sebastian Raschka's LLM Architecture Gallery. The implementations explicitly expose critical architectural nuances, including diverse attention mechanisms such as Multi-Head Attention (MHA), Grouped Query Attention (GQA), Multi-Query Attention (MQA), and Multi-head Latent Attention (MLA). Additionally, the repository covers various normalization techniques like RMSNorm and QK-Norm, as well as positional encoding methods including RoPE, NoPE, and YaRN. The library spans a wide range of model scales, from 3B parameter models like PaliGemma to massive architectures like the 1T parameter Kimi K2 and the 671B parameter DeepSeek R1, which utilizes Mixture of Experts (MoE) and MLA. Currently, the repository features functional forward-pass implementations for several text and multimodal models, including Llama 3 (8B), Mistral 3 (24B), and Grok-2.5 (270B), while other models like Qwen3 Next remain under construction. The project aims to facilitate side-by-side architectural comparisons by documenting specific design choices like sliding-window attention and multi-token prediction.

Read original