rasbt /LLMs-from-scratch
Implement a ChatGPT-like LLM in PyTorch from scratch, step by step
★ 108,148⑂ 16,723👁 869⑃ 622● 252▤ 0◈ 216
108,148
stars
+84+447+1,817
16,723
forks
869
watchers
622
prs
252
issues
0
releases
216
discussions
README
Build a Large Language Model (From Scratch) This repository contains the code for developing, pretraining, and finetuning a GPT-like LLM and is the official code repository for the book Build a Large Language Model (From Scratch). In Build a Large Language Model (From Scratch), you'll learn and understand how large language models (LLMs) work from the inside out by coding them from the ground up, step by step. In this book, I'll guide you through creating your own LLM, explaining each stage with clear text, diagrams, and examples. The method described in this book for training and developing your own small-but-functional model for educational purposes mirrors the approach used in creating large-scale foundational models such as those behind ChatGPT. In addition, this book includes code for loading the weights of larger pretrained models for finetuning. - Link to the official source code repository - Link to the book at Manning (the publisher's website) - Link to the book page on Amazon.com - ISBN 9781633437166 To download a copy of this repository, click on the Download ZIP button or execute the following command in your terminal: bash git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git (If you downloaded the code bundle from the Manning website, please consider visiting the official code repository on GitHub at https://github.com/rasbt/LLMs-from-scratch for the latest updates.) Table of Contents Please note that this README.md file is a Markdown (.md) file. If you have downloaded this code bundle from the Manning website and are viewing it on your local computer, I recommend using a Markdown editor or previewer for proper viewing. If you haven't installed a Markdown editor yet, Ghostwriter is a good free option. You can alternatively view this and other files on GitHub at https://github.com/rasbt/LLMs-from-scratch in your browser, which renders Markdown automatically. Tip: If you're seeking guidance on installing Python and Python packages and setting up your code environment, I suggest reading the README.md file located in the setup directory. - Troubleshooting Guide | Chapter Title | Main Code (for Quick Access) | All Code + Supplementary | |------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|-------------------------------| | Setup recommendations How to best read this book | - | - | | Ch 1: Understanding Large Language Models | No code
Top issues
Discussions
#1081Nanbeige 4.2 3b "from scratch" implementation1 comments · 2026-09-14#1067Data transfer in collate v.s. during training loop1 comments · 2026-08-15#1066Questions on variable length input data construction1 comments · 2026-08-11#1065Question on output dim in Figure 4.41 comments · 2026-08-10#1059100k stars!0 comments · 2026-08-07#1051[chapter3] Buffer usage in PyTorch1 comments · 2026-07-31#1037Chapter 5: running train_model_simple() on CPU is really slow, why?1 comments · 2026-07-03#1043ask about project4 comments · 2026-06-12
相关报道 (6)
blog.csdn【GitHub项目推荐--LLMs-from-scratch:从零实现大语言模型完全指南】2025-09-19blog.csdn大模型项目推荐 | LLMs-from-scratch中文项目 - 从零构建大模型(附教程)2025-03-28note「LLMs-from-scratch」で学ぶLLMの基礎から応用まで2024-08-01新浪网6.7 秒训练大模型:不靠硬背权重,靠检索兜底|Herman Brunborg|NanoGPT|n-gram 检索_新浪新闻2026-10-2953AI大神带你从零开始构建大语言模型,然来不过如此,清晰易懂但也确实牛皮2024-09-0151CTO《Python 机器学习》作者新作:从头开始构建大型语言模型,代码已开源2024-06-24
News & coverage (15)
Hacker NewsImplementing a ChatGPT-like LLM from scratch, step by step▲ 739 · 98 comments · 2024-01-27Hacker NewsGemma 3 270M re-implemented in pure PyTorch for local tinkering▲ 417 · 57 comments · 2025-08-20Hacker NewsFinetuning an LLM-Based Spam Classifier with LoRA from Scratch▲ 14 · 0 comments · 2024-05-11Hacker NewsImplementing the Llama 3.2 1B and 3B Architectures from Scratch▲ 5 · 0 comments · 2024-10-05Hacker NewsExplanation of Gated DeltaNet (Qwen3-Next and Kimi Linear)▲ 3 · 0 comments · 2025-11-03Hacker NewsQwen3 from Scratch▲ 3 · 0 comments · 2025-08-02Hacker NewsQwen3 Implemented from Scratch▲ 3 · 0 comments · 2025-06-20Hacker NewsDay 1 of trying to fit a Chatbot into a QR Code▲ 1 · 2 comments · 2025-04-20opentools.aiLLMs-from-scratch: Build an LLM in PyTorch2026-05-13note「LLMs-from-scratch」로 배우는 LLM의 기초부터 응용까지2024-07-31