메뉴
HN
Hacker News • 12일 전

OpenArch – 최신 LLM 아키텍처의 PyTorch 구현 모음

IMP
7/10
핵심 요약

OpenArch는 Sebastian Raschka의 LLM 아키텍처 갤러리에 수록된 모델들을 원 논문과 config.json 파일 기반으로 순수 PyTorch로 직접 구현한 오픈소스 저장소입니다. GPT-2부터 DeepSeek R1, Kimi K2, GLM 4.5 등 15개 이상 모델을 아키텍처별 하나의 읽기 쉬운 파일로 제공하며, 어텐션 방식(MHA/GQA/MLA), 정규화, 위치 인코딩, MoE 라우팅 등 구조적 차이를 나란히 비교할 수 있게 합니다. 속도나 배포 최적화보다 학습과 명확성을 목표로 하는 리소스로, 기여자도 모집 중입니다.

번역된 본문

OpenArch – 최신 오픈소스 LLM 아키텍처의 Python 구현

OpenArch는 최신 오픈소스 LLM 아키텍처를 한 모델씩 처음부터 직접 작성한 Python 구현 모음입니다. 이 저장소에는 Sebastian Raschka의 LLM Architecture Gallery에 수록된 모델 아키텍처들을 직접 손으로 작성한 PyTorch 구현이 담겨 있습니다. 각 모델은 원 논문, 기술 보고서, 참고용 config.json 파일, 그리고 Sebastian Raschka와 Machine Learning Mastery의 훌륭한 해설 글을 바탕으로 최선을 다해 구현되었습니다.

이 프로젝트의 목표는 transformers 같은 프로덕션 라이브러리와 경쟁하는 것이 아닙니다. 목표는 명확성과 학습입니다. 아키텍처당 하나의 읽기 쉬운 파일로, 구조적 선택 사항(어텐션 유형, 정규화, 레이어 구성, MoE 라우팅, 위치 인코딩)을 명시적으로 드러내 나란히 비교하기 쉽게 만드는 것이 목적입니다.

왜 이 저장소인가?

현대 LLM 아키텍처는 공통된 뼈대를 공유하지만 수십 가지의 작지만 중요한 선택에서 차이가 납니다:

  • 어텐션(Attention): MHA, GQA, MQA, MLA, 슬라이딩 윈도우(sliding-window), 선형(linear)/DeltaNet 하이브리드
  • 정규화(Normalization): pre-norm, post-norm, QK-Norm, 샌드위치 norm, RMSNorm
  • 위치 인코딩(Positional Encoding): RoPE, NoPE, 부분 RoPE, YaRN
  • 디코더 유형: dense vs sparse MoE(공유 전문가 shared experts 포함 여부), Mamba/어텐션 하이브리드
  • 학습 기법: Multi-token-prediction, latent experts, gated attention

공식 모델 코드를 읽기는 어렵습니다. 프로덕션 저장소는 속도, 샤딩(sharding), 하위 호환성에 최적화되어 있기 때문입니다. 이 저장소는 읽기 쉬움에 최적화되어 있습니다.

현재까지 구현된 내용

✅ 표시된 구현은 순방향 패스(forward pass)가 가능하며, 🚧 표시는 구현 중입니다.

분야 모델 상태 모델 크기 정규화 위치 인코딩 어텐션 MoE
텍스트 GPT-2 XL ✅ 1.5B - 절대 위치 멀티헤드 어텐션 아니오
Llama 2 ✅ 7B RMS Norm RoPE 멀티헤드 어텐션 아니오
Llama 3 ✅ 8B RMS Norm RoPE 그룹화 쿼리 어텐션(GQA) 아니오
OLMo 2 ✅ 7B RMS Norm & QK-Norm RoPE 멀티헤드 어텐션 아니오
DeepSeek R1 ✅ 671B RMS Norm & QK-Norm RoPE 멀티헤드 잠재 어텐션(MLA) 예
Gemma 3 ✅ 27B RMS Norm & QK-Norm RoPE 슬라이딩 윈도우 GQA 아니오
Mistral 3 ✅ 24B RMS Norm RoPE 슬라이딩 윈도우 GQA 아니오
Llama 4 Maverick ✅ 400B RMS Norm RoPE GQA 예
Qwen 3 ✅ 4B RMS Norm & QK-Norm RoPE GQA 아니오
Qwen 3 30B-A3B 30B RMS Norm & QK-Norm RoPE GQA 예
Kimi K2 ✅ 1T RMS Norm RoPE MLA 예
GLM 4.5 ✅ 355B RMS Norm & QK-Norm RoPE GQA & Multi-Token Prediction 예
GPT-OSS ✅ 20B RMS Norm RoPE 슬라이딩 윈도우 GQA 예
Grok-2.5 🚧 270B RMS Norm RoPE GQA 예
멀티모달 PaliGemma ✅ 3B RMS Norm RoPE 멀티헤드 어텐션 아니오
Qwen3 🚧 3B RMS Norm RoPE 멀티헤드 어텐션 아니오
이미지 Dall-e 🚧 - - - Transformer -

전체 목표 목록은 Architecture Gallery의 72개 아키텍처와 일치합니다. 어느 것이든 기여를 환영합니다.

저장소 구조

OpenArch/
├── text/
│   ├── gpt2/
│   │   ├── model.py
│   │   └── README.md
│   ├── llama3/
│   ├── qwen3/
│   ├── grok2.5/
│   └── deepseek_v3/
├── multimodal/
│   └── pali-gemma/
│       ├── model.py
│       └── README.md
├── README.md
└── requirements.txt

각 모델은 자체 폴더에 model.py와 아키텍처 선택 사항 및 참고 자료를 설명하는 간단한 README.md가 함께 있습니다.

기여 안내

적극적으로 기여자를 찾고 있습니다. 모델 논문을 읽는 것을 즐기거나, config.json 파일을 비교하는 것을 좋아하거나, 아니면 단순히 현대 LLM이 어떻게 만들어지는지 이해를 깊게 하고 싶다면 좋은 시작점이 될 수 있습니다.

좋은 첫 기여 예시:

  • 갤러리에서 아직 구현되지 않은 모델을 골라 model.py 추가하기
  • 기존 모델의 아키텍처 선택 사항을 문서화하는 README.md 작성하기
  • 공식 가중치를 로드해 몇 개 토큰에서 출력이 일치하는지 확인하는 순방향 패스 테스트 추가하기
  • 버그 수정, docstring 개선, 공용 컴포넌트 리팩토링

큰 작업을 시작하기 전에는 이슈를 열어 중복 노력을 피해 주세요. 구현은 성능보다 가독성을 우선해야 합니다 — 이것은 무엇보다 학습 자료입니다. 자세한 내용은 CONTRIBUTING.md를 참고하세요.

원문 보기
원문 보기 (영어)
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.py for it Add a README.md for 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 .