LLMs-from-scratch (从零构建大语言模型)
108,245
Stars
16,731
Forks
869
Watchers
4
Open Issues
NOASSERTION
许可证
Jupyter Notebook
语言
2023-07-23
创建时间
2026-11-09
最近更新
项目能做什么
使用 PyTorch 从零开始、循序渐进实现类似 ChatGPT 的大语言模型教程。
来源:基于仓库元数据
· 内容以仓库实际 README 为准
使用说明 查看原始 README 原仓库文档
项目简介
LLMs-from-scratch 是图书《Build a Large Language Model (From Scratch)》的官方代码仓库。本项目带你通过 PyTorch 从零开始一步步搭建、预训练并微调一个类似 ChatGPT 的 GPT 架构大语言模型(LLM)。通过纯手写代码的方式,帮助开发者由内而外彻底理解大模型的工作原理。
核心功能
- 从零构建核心模块:包含文本数据处理与 DataLoader 构建、自注意力与多头注意力机制(Attention Mechanisms)实现,以及完整的 GPT 模型结构代码。
- 预训练与微调流程:涵盖在无标注数据上的预训练方法,以及模型微调技术。
- 加载外部预训练权重:支持载入更大规模的预训练模型权重用于后续微调。
- 配套学习代码与习题解答:按章节提供核心 Jupyter Notebook(如
ch02.ipynb、ch03.ipynb、gpt.py等)及练习题解答(exercise-solutions.ipynb)。
适合谁用
适合希望深入理解大语言模型底层运行机制、通过动手写代码掌握模型架构,并具备基础 Python / 深度学习背景的开发者与学习者。
安装步骤
你可以通过 GitHub 页面下载 ZIP 压缩包,或在终端中运行以下命令克隆仓库:
# 克隆仓库(浅克隆深度为 1)
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git
注意:关于 Python 版本要求及依赖包的具体安装步骤,README 原文未在此处详细展开,建议查阅仓库内
setup/README.md说明文档。
配置说明
此部分原文未说明,请查看原仓库(环境配置及指引请参见 setup/README.md)。
常见问题
- 代码报错与排错:项目提供了专门的排错指南,可查阅仓库根目录下的
troubleshooting.md。 - 文档查看建议:本地查看建议使用 Markdown 编辑器(如免费的 Ghostwriter)或直接在 GitHub 网页端阅读。
- 其他常见问题此部分原文未详细列出,请查看原仓库。
原始 README 摘录(英文原文,节选前 3000 字符)
# 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)](https://amzn.to/4fqvn0D). <br> <br> <a href="https://amzn.to/4fqvn0D"><img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/cover.jpg?123" width="250px"></a> <br> In [*Build a Large Language Model (From Scratch)*](http://mng.bz/orYv), 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](https://github.com/rasbt/LLMs-from-scratch) - [Link to the book at Manning (the publisher's website)](http://mng.bz/orYv) - [Link to the book page on Amazon.com](https://www.amazon.com/gp/product/1633437167) - ISBN 9781633437166 <a href="http://mng.bz/orYv#reviews"><img src="https://sebastianraschka.com//images/LLMs-from-scratch-images/other/reviews.png" width="220px"></a> <br> <br> To download a copy of this repository, click on the [Download ZIP](https://github.com/rasbt/LLMs-from-scratch/archive/refs/heads/main.zip) button or execute the following command in your terminal: ```bash git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git ``` <br> (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](https://github.com/rasbt/LLMs-from-scratch) for the latest updates.) <br> <br> # 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](https://ghostwriter.kde.org) is a good free option. You can alternatively view this and other files on GitHub at [https://github.com/rasbt/LLMs-from-scratch](https://github.com/rasbt/LLMs-from-scratch) in your browser, which renders Markdown automatically. <br> <br> > **Tip:** > If you're seeking guidance on installing Python and Python packages and setting up your code environment, I suggest reading the [README.md](setup/README.md) file located in the [setup](setup) directory. <br> <br> []阅读完整原文
商业机会分析 规则生成(AI 未配置)
综合评分 64.2 分。该项目在“个人可实施性”维度得 35 分,“付费可能性”维度得 64.0 分,差异化空间 70.0 分(评分依据见评分卡)。
将 LLMs-from-scratch 改造为垂直场景 SaaS
| 产品构想 | 保留核心能力,针对某一类用户(如某行业团队)做托管版,收取月费。 |
| 目标用户 | 有该需求的中小团队 / 独立站长 |
| 难度/周期 | 较高 · 2~4 周(MVP) |
| 收费模式 | 订阅制(如 ¥29~99/月) |
| 竞争风险 | 需验证付费意愿;注意许可证合规 |
| 依据 | 数据支持的判断:许可证与关键词显示存在商用与付费场景 |
面向细分需求的二次开发产品
| 产品构想 | 基于 LLMs-from-scratch 的核心能力,聚焦一个更窄的场景(如某平台、某行业)做差异化。 |
| 目标用户 | 该细分场景用户 |
| 难度/周期 | 中 · 2~6 周 |
| 收费模式 | 买断制 / 订阅制 / 广告 |
| 竞争风险 | 细分需求规模需验证 |
| 依据 | AI 推测:基于项目主题标签的判断 |
以上为规则引擎基于仓库公开数据生成的参考结论,包含推测成分,不构成投资或创业承诺;配置 AI 后可获得更深入的分析。
报告会保存到 个人中心
竞品与相似项目 GitHub Search 真实检索
| 项目 | 中文简介 | Stars | 语言 |
|---|---|---|---|
| morluto/rea | 利用 Agent 逆向工程各类软件,涵盖应用行为到原生二进制文件。 | 450,393 | TypeScript |
| openclaw/openclaw | 一款支持多操作系统与跨平台、能够实际执行任务的 AI 工具。 | 394,308 | TypeScript |
| obra/superpowers | 一套实用的 Agent 技能框架与软件开发方法论。 | 315,808 | Shell |
| NousResearch/hermes-agent | 一款能够伴随用户共同成长的 AI Agent。 | 262,494 | Python |
| n8n-io/n8n | 内置原生 AI 能力的工作流自动化平台,支持可视化与自定义代码构建。 | 210,037 | TypeScript |
| firecrawl/firecrawl | 从网络等渠道抓取并提取数据,为 AI Agent 提供数据支持。 | 200,597 | TypeScript |
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。
项目优势与风险
| 技术成熟度 | 创建于 2023-07-23,近 30 天仍在推送 |
| 社区活跃 | Star 108,245 / Fork 16,731 / Issue 4(数据支持,可自行核实) |
| 许可证 | NOASSERTION |
| 主要风险 | 上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价 |
安装与使用
快速开始(以仓库 README 为准)
git clone https://github.com/rasbt/LLMs-from-scratch.git cd LLMs-from-scratch # 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。