登录 注册
AI 模型与开发框架网站与 SaaS 工具教育与学习
64,606
Stars
11,112
Forks
541
Watchers
356
Open Issues
MIT
许可证
Python
语言
2022-12-28
创建时间
2025-11-12
最近更新

项目能做什么

用于训练和微调中等规模 GPT 模型的极简、快速实现库。
来源:基于仓库元数据 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# nanoGPT

![nanoGPT](assets/nanogpt.jpg)


---

**Update Nov 2025** nanoGPT has a new and improved cousin called [nanochat](https://github.com/karpathy/nanochat). It is very likely you meant to use/find nanochat instead. nanoGPT (this repo) is now very old and deprecated but I will leave it up for posterity.

---

The simplest, fastest repository for training/finetuning medium-sized GPTs. It is a rewrite of [minGPT](https://github.com/karpathy/minGPT) that prioritizes teeth over education. Still under active development, but currently the file `train.py` reproduces GPT-2 (124M) on OpenWebText, running on a single 8XA100 40GB node in about 4 days of training. The code itself is plain and readable: `train.py` is a ~300-line boilerplate training loop and `model.py` a ~300-line GPT model definition, which can optionally load the GPT-2 weights from OpenAI. That's it.

![repro124m](assets/gpt2_124M_loss.png)

Because the code is so simple, it is very easy to hack to your needs, train new models from scratch, or finetune pretrained checkpoints (e.g. biggest one currently available as a starting point would be the GPT-2 1.3B model from OpenAI).

## install

```
pip install torch numpy transformers datasets tiktoken wandb tqdm
```

Dependencies:

- [pytorch](https://pytorch.org) <3
- [numpy](https://numpy.org/install/) <3
-  `transformers` for huggingface transformers <3 (to load GPT-2 checkpoints)
-  `datasets` for huggingface datasets <3 (if you want to download + preprocess OpenWebText)
-  `tiktoken` for OpenAI's fast BPE code <3
-  `wandb` for optional logging <3
-  `tqdm` for progress bars <3

## quick start

If you are not a deep learning professional and you just want to feel the magic and get your feet wet, the fastest way to get started is to train a character-level GPT on the works of Shakespeare. First, we download it as a single (1MB) file and turn it from raw text into one large stream of integers:

```sh
python data/shakespeare_char/prepare.py
```

This creates a `train.bin` and `val.bin` in that data directory. Now it is time to train your GPT. The size of it very much depends on the computational resources of your system:

**I have a GPU**. Great, we can quickly train a baby GPT with the settings provided in the [config/train_shakespeare_char.py](config/train_shakespeare_char.py) config file:

```sh
python train.py config/train_shakespeare_char.py
```

If you peek inside it, you'll see that we're training a GPT with a context size of up to 256 characters, 384 feature channels, and it is a 6-layer Transformer with 6 heads in each layer. On one A100 GPU this training run takes about 3 minutes and the best validation loss is 1.4697. Based on the configuration, the model checkpoints are being written into the `--out_dir` directory `out-shakespeare-char`. So once the training finishes we can sample from the best model by pointing the sampling script at this directory:

```sh
python sample.py --out_dir=out-shakespeare-char
```

This generates 
阅读完整原文

商业机会分析 规则生成(AI 未配置)

综合评分 42.4 分。该项目在“个人可实施性”维度得 20 分,“付费可能性”维度得 52.0 分,差异化空间 40.0 分(评分依据见评分卡)。

将 nanoGPT 改造为垂直场景 SaaS

产品构想保留核心能力,针对某一类用户(如某行业团队)做托管版,收取月费。
目标用户有该需求的中小团队 / 独立站长
难度/周期较高 · 2~4 周(MVP)
收费模式订阅制(如 ¥29~99/月)
竞争风险需验证付费意愿;注意许可证合规
依据 数据支持的判断:许可证与关键词显示存在商用与付费场景

面向细分需求的二次开发产品

产品构想基于 nanoGPT 的核心能力,聚焦一个更窄的场景(如某平台、某行业)做差异化。
目标用户该细分场景用户
难度/周期中 · 2~6 周
收费模式买断制 / 订阅制 / 广告
竞争风险细分需求规模需验证
依据 AI 推测:基于项目主题标签的判断
以上为规则引擎基于仓库公开数据生成的参考结论,包含推测成分,不构成投资或创业承诺;配置 AI 后可获得更深入的分析。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

项目中文简介Stars语言
Lightning-AI/lit-llama 中文介绍暂未生成
Implementation of the LLaMA language model based on nanoGPT.
6,079 Python
KellerJordan/modded-nanogpt 中文介绍暂未生成
NanoGPT (124M) in 90 seconds
6,020 Python
karpathy/build-nanogpt 中文介绍暂未生成
Video+code lecture on building nanoGPT from scratch
5,635 Python
0hq/WebGPT 中文介绍暂未生成
Run GPT model on the browser with WebGPU. An implementation
3,788 JavaScript
dabochen/spreadsheet-is-all-you-need 中文介绍暂未生成
A nanoGPT pipeline packed in a spreadsheet
2,157 -
he-yufeng/CoreCoder 中文介绍暂未生成
Minimal AI coding agent (~1,000 lines of Python) inspired by
1,905 Python
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。

项目优势与风险

技术成熟度创建于 2022-12-28,最近推送 2025-11-12
社区活跃Star 64,606 / Fork 11,112 / Issue 356(数据支持,可自行核实)
许可证MIT
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

快速开始(以仓库 README 为准)
git clone https://github.com/karpathy/nanoGPT.git
cd nanoGPT
# 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
阅读原仓库文档
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。