← 开源
angelos-p

llm-from-scratch

TutorialsLLM fundamentals
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
3.43k
Star
377
Fork
+5
本周
1
贡献者
创建于 2026-04-04 · 更新于 2026-10-15 · 今日第 7956 名
主要开发者
angelos-p

angelos-p/llm-from-scratch 排名第 7,956,有 3,427 个星标。

同类别比较

angelos-p/llm-from-scratch 排名第 7,956,此处有 8 个同类条目;girls-in-ai/Girls-In-AI 排名第 7,959。

同类别比较
名称排名指标
coleam00/ai-agents-masterclass7,926
语言:
Python
星标数:
3,474
分叉数:
1,330
简介:
Follow along with my AI Agents Masterclass videos! All of the code I create and use in this series on YouTube will be here for you to use and even build on top of!
rbhatia46/Data-Science-Interview-Resources7,929
星标数:
3,469
分叉数:
766
简介:
A repository listing out the potential sources which will help you in preparing for a Data Science/Machine Learning interview. New resources added frequently.
dair-ai/ML-Notebooks7,950
语言:
Jupyter Notebook
星标数:
3,441
分叉数:
537
简介:
:fire: Machine Learning Notebooks
data-science-on-aws/data-science-on-aws7,951
语言:
Jupyter Notebook
星标数:
3,440
分叉数:
1,077
简介:
AI and Machine Learning with Kubeflow, Amazon EKS, and SageMaker
girls-in-ai/Girls-In-AI7,959
语言:
Jupyter Notebook
星标数:
3,415
分叉数:
495
简介:
免费学代码系列:小白python入门、数据分析data analyst、机器学习machine learning、深度学习deep learning、kaggle实战
priya-dwivedi/Deep-Learning7,983
语言:
Jupyter Notebook
星标数:
3,353
分叉数:
2,428
NVIDIA-AI-IOT/jetbot7,990
语言:
Jupyter Notebook
星标数:
3,341
分叉数:
1,073
简介:
An educational AI robot based on NVIDIA Jetson Nano.
tirthajyoti/Machine-Learning-with-Python7,991
语言:
Jupyter Notebook
星标数:
3,338
分叉数:
1,828
简介:
Practice and tutorial-style notebooks covering wide variety of machine learning techniques
关键参数与规格
关键参数与规格
参数值
类别Tutorials
子类别LLM fundamentals
关键词Data processing, Education, Model architecture, Tokenizer
星标数3,427
分叉数377
贡献者1
创建日期2026-04-04
更新日期2026-10-15
1 天星标数0
7 天星标数5
排名7,956
上次排名8,058
排名变化102
7 天星标排名5,426
上次 7 天星标排名5,980
7 天星标排名变化554
总星标排名3,999
上次总星标排名3,993
总星标排名变化-6
README 摘录

Train Your Own LLM From Scratch A hands-on workshop where you write every piece of a GPT training pipeline yourself, understanding what each component does and why. Andrej Karpathy's nanoGPT was my first real exposure to LLMs and transformers. Seeing how a working language model could be built in a few hundred lines of PyTorch completely changed how I thought about AI and inspired me to go deeper into the space. This workshop is my attempt to give others

that same experience. nanoGPT targets reproducing GPT-2 (124M params) and covers a lot of ground. What You'll Build A working GPT model trained from scratch on your MacBook, capable of generating Shakespeare-like text. 12+ Comfort reading Python code (you don't need ML experience) Training uses Apple Silicon GPU (MPS), NVIDIA GPU (CUDA), or CPU automatically. Getting Started Local (recommended) Install uv if you don't have it: Then set up the project: Google Colab If you don't have a

local setup, upload the repo to Colab and install dependencies: Upload to your Colab files, then write your code in notebook cells or upload files and run them with . Each part walks you through writing a piece of the pipeline, explaining what each component does and why. By the end, you'll have a working , , and that you wrote yourself. 5M | 2 | 2 | 128 | ~5 min | | Small | ~4M | 4 | 4 | 256 | ~20 min | | **Medium (default)** | **~10M** | **6** | **6** | **384** | **~45 min

** | All configs use character-level tokenization (vocab_size=65) and block_size=256. Tokenization: Characters vs BPE This workshop uses **character-level** tokenization on Shakespeare.

常见问题

记录了多少星标和分叉?

angelos-p/llm-from-scratch 有 3,427 个星标和 377 个分叉。

仓库排名是多少?

angelos-p/llm-from-scratch 排名第 7,956。

哪个仓库排名最接近?

angelos-p/llm-from-scratch 与 girls-in-ai/Girls-In-AI 比较,后者排名第 7,959,有 3,415 个星标。

README

Train Your Own LLM From Scratch

A hands-on workshop where you write every piece of a GPT training pipeline yourself, understanding what each component does and why.

Andrej Karpathy's nanoGPT was my first real exposure to LLMs and transformers. Seeing how a working language model could be built in a few hundred lines of PyTorch completely changed how I thought about AI and inspired me to go deeper into the space.

This workshop is my attempt to give others that same experience. nanoGPT targets reproducing GPT-2 (124M params) and covers a lot of ground. This project strips it down to the essentials and scales it to a ~10M param model that trains on a laptop in under an hour — designed to be completed in a single workshop session.

What You'll Build

A working GPT model trained from scratch on your MacBook, capable of generating Shakespeare-like text. You'll write:

  • Tokenizer — turning text into numbers the model can process
  • Model architecture — the transformer: embeddings, attention, feed-forward layers
  • Training loop — forward pass, loss, backprop, optimizer, learning rate scheduling
  • Text generation — sampling from your trained model

Prerequisites

  • Any laptop or desktop (Mac, Linux, or Windows)
  • Python 3.12+
  • Comfort reading Python code (you don't need ML experience)

Training uses Apple Silicon GPU (MPS), NVIDIA GPU (CUDA), or CPU automatically. Also works on Google Colab — upload the files and run with !python train.py.

Getting Started

Local (recommended)

Install uv if you don't have it:

# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Then set up the project:

uv sync
mkdir scratchpad && cd scratchpad

Google Colab

If you don't have a local setup, upload the repo to Colab and install dependencies:

!pip install torch numpy tqdm tiktoken

Upload data/shakespeare.txt to your Colab files, then write your code in notebook cells or upload .py files and run them with !python train.py.


Work through the docs in order. Each part walks you through writing a piece of the pipeline, explaining what each component does and why. By the end, you'll have a working model.py, train.py, and generate.py that you wrote yourself.

Part What You'll Write Concepts
Part 1: Tokenization Character-level tokenizer Character encoding, vocabulary size, why BPE fails on small data
Part 2: The Transformer Full GPT model architecture Embeddings, self-attention, layer norm, MLP blocks
Part 3: The Training Loop Complete training pipeline Loss functions, AdamW, gradient clipping, LR scheduling
Part 4: Text Generation Inference and sampling Temperature, top-k, autoregressive decoding
Part 5: Putting It All Together Train on real data, experiment Loss curves, scaling experiments, next steps
Part 6: Competition Train the best AI poet Find datasets, scale up, submit your best poem

Architecture: GPT at a Glance

Input Text
    │
    ▼
┌─────────────────┐
│   Tokenizer     │  "hello" → [20, 43, 50, 50, 53]  (character-level)
└────────┬────────┘
         ▼
┌─────────────────┐
│  Token Embed +  │  token IDs → vectors (n_embd dimensions)
│  Position Embed │  + positional information
└────────┬────────┘
         ▼
┌─────────────────┐
│  Transformer    │  × n_layer
│  Block:         │
│  ┌────────────┐ │
│  │ LayerNorm  │ │
│  │ Self-Attn  │ │  n_head parallel attention heads
│  │ + Residual │ │
│  ├────────────┤ │
│  │ LayerNorm  │ │
│  │ MLP (FFN)  │ │  expand 4x, GELU, project back
│  │ + Residual │ │
│  └────────────┘ │
└────────┬────────┘
         ▼
┌─────────────────┐
│   LayerNorm     │
│   Linear → logits│  vocab_size outputs (probability over next token)
└─────────────────┘

Model Configs for This Workshop

Config Params n_layer n_head n_embd Train Time (M3 Pro)
Tiny ~0.5M 2 2 128 ~5 min
Small ~4M 4 4 256 ~20 min
Medium (default) ~10M 6 6 384 ~45 min

All configs use character-level tokenization (vocab_size=65) and block_size=256.

Tokenization: Characters vs BPE

This workshop uses character-level tokenization on Shakespeare. BPE tokenization (GPT-2's 50k vocab) doesn't work on small datasets — most token bigrams are too rare for the model to learn patterns from.

Tokenizer Vocab Size Dataset Size Needed
Character-level ~65 Small (Shakespeare, ~1MB)
BPE (tiktoken) 50,257 Large (TinyStories+, 100MB+)

Part 5 covers switching to BPE for larger datasets.

Key References

排名相邻
同类项目