LLMs from Scratch is the free code for Sebastian Raschka's book Build a Large Language Model (From Scratch): Jupyter notebooks that build a small GPT-style language model in PyTorch, one piece at a time, without any LLM library. You write the tokenizer and data loader, code the attention mechanism, assemble the GPT model, pretrain it on a short story, load OpenAI's GPT-2 weights into it, then fine-tune it to sort spam and to follow instructions. In the first ten minutes you can open chapter 2 and run the tokenizer cells, which need nothing more than an ordinary laptop.
It earns its place because it shows what sits inside ChatGPT-style models instead of hiding it behind an API. Every chapter has a main notebook, a short summary script and exercise solutions, and the bonus folders go much further: KV caching, grouped-query and latent attention, mixture of experts, DPO alignment, LoRA, and from-scratch versions of Llama 3.2, Qwen3, Gemma 3 and Olmo 3. The chapter code is also on PyPI as llms-from-scratch, so you can import it into your own experiments.
The code is Apache-2.0 licensed, with the book text and images excluded from the licence, and is maintained by Raschka with 79 contributors and about 109,000 stars since July 2023. The book itself is paid, published by Manning in 2024, and the repo's homepage is an Amazon affiliate link to it. There are no GitHub releases; the PyPI package reached 1.0.20 on 25 November 2026, and the code was last updated on 26 November 2026.
- Repository: github.com/rasbt/LLMs-from-scratch
- Licence: custom (Other)
- Language: Jupyter Notebook. Stars: 109.2K. Forks: 16.9K. Last push: Nov 26, 2026.
- Scan: safe, Nov 28, 2026, commit f03d8e8
Who it is for
Developers who know Python and want to understand how LLMs work inside, machine learning students, and readers of the book. Strong Python is the main prerequisite; PyTorch basics help (appendix A teaches them), and the main chapters run on an ordinary laptop, using a GPU if you have one.
Getting started
1. Read the chapters on GitHub, starting with chapter 2 (working with text)
https://github.com/rasbt/LLMs-from-scratch/tree/main/ch02/01_main-chapter-code2. Clone the code
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git3. Inside the folder, install the packages and open the notebooks
pip install -r requirements.txt && jupyter lab4. Or import the chapter code into your own project
pip install llms-from-scratchrequirements.txt installs PyTorch, JupyterLab, tiktoken, Matplotlib, pandas and TensorFlow, which is used only to read OpenAI's GPT-2 checkpoint in chapters 5 to 7; a virtual environment keeps them apart from your other projects. Chapter 5 downloads the GPT-2 weights from OpenAI, with the author's Backblaze copy as a backup. The setup guide's optional uv and pixi installers pipe a script to the shell. The reasoning-from-scratch folder links to a separate repo, which our scan does not cover.
Safety scan
We cloned rasbt/LLMs-from-scratch at commit f03d8e8 on Nov 28, 2026 and ran the checks described on the GitHub Tools page: credential patterns, decode-and-execute code, install-time scripts, committed binaries, risky CI workflows, every host the code talks to, known vulnerabilities in pinned dependencies, and project hygiene. A person read every hit. This is what we found.
- 0 secret hits and 0 committed binaries across 368 files and about 131,000 lines, mostly notebooks and Python. No model weights are stored in the repo; the notebooks fetch them when you run the cells that need them.
- 0 pattern hits. We read the places that matter anyway: the subprocess calls are in test files that run the chapter scripts, and the one torch.load without weights_only is in a package test that loads random weights it saved a moment earlier. The chapter 7 evaluation notebooks call the OpenAI API or a local Ollama model only if you open and run them.
- No install hooks, setup.py scripts or installer scripts. pyproject.toml builds the optional llms-from-scratch package with setuptools, and requirements.txt installs public PyPI packages. The setup docs show the official uv and pixi installers, which pipe a download to sh; they are optional, and plain pip works.
- 0 advisories, because there is nothing pinned to look up: requirements.txt and pyproject.toml give minimum versions such as torch>=2.2.2, so pip installs current releases. There is no lockfile, so what you get depends on the day you install.
- The hosts are GitHub, sebastianraschka.com, Manning, Hugging Face, arXiv, OpenAI's public storage for the GPT-2 weights and the author's Backblaze bucket for backup weights and the spam dataset; we found no analytics or telemetry. 13 active workflows run tests and link, spelling and style checks; none uses pull_request_target, and a retry workflow with a write token reads only GitHub metadata and never checks out pull request code. The one third-party action is pinned to a commit. No security policy, Dependabot or CodeQL.
What the scanner counted
| Check | Result |
|---|---|
| Secrets | None found. |
| Suspicious code | None found. |
| Install-time code | None: nothing runs at install beyond the package manager itself. |
| Committed binaries | None. |
| CI workflows | 13 workflows. None use pull_request_target. 0 of 1 third-party action pinned to a tag rather than a commit. |
| Network hosts | 39 distinct hosts referenced from source; most often github.com, sebastianraschka.com, mng.bz, www.manning.com. No URLs to bare IP addresses. |
| Known vulnerabilities | No lockfile to check: dependencies are declared as ranges, so what gets installed is whatever is current on the day. |
| Project hygiene | Has licence file. Missing security policy, automated dependency updates, CodeQL, contributing guide. |
| OpenSSF Scorecard | Not scored: the project is not in Scorecard's weekly index. |
By the numbers
| Stars | 109.2K |
|---|---|
| Forks | 16.9K |
| Contributors | 79 |
| Commits | 1,099 |
| Open issues | 1 |
| Open pull requests | 4 |
| Releases | 0 |
| Latest release | none tagged |
| Licence | custom |
| Main language | Jupyter Notebook |
| Project age | 3 years |
| Last push | Nov 26, 2026 |
| Tracked files | 368 |
| Lines of code | 130.9K |
| Checkout size | 7 MB |
Lines by language: Jupyter 71.8K, Python 35.1K, JSON 16.9K, Markdown 5,908, YAML 1,138, TOML 125.
Questions
Is LLMs from Scratch free?
The code is free and Apache-2.0 licensed; the book it accompanies is not. Build a Large Language Model (From Scratch) is a paid Manning book, the repo's Amazon link is an affiliate link, and there is a paid 17-hour video course. The notebooks work on their own, and Manning offers a free 170-page quiz PDF.
Will I end up with my own ChatGPT?
A small one. You build and pretrain a GPT-2-sized model, then load OpenAI's GPT-2 weights and fine-tune them to follow instructions; it answers simple prompts but is far from ChatGPT. The point is understanding every layer, which carries over to larger models.
What hardware do I need?
An ordinary laptop for the main chapters; the README says they run in reasonable time without special hardware. A GPU, including Apple Silicon, is used automatically if you have one, and some bonus folders with larger models want one.
Do I need to know how to code?
Yes. Strong Python is the one prerequisite the README insists on. PyTorch you can pick up along the way from appendix A.
This post is part of GitHub Tools, where every repository is cloned and scanned before it is written up. The scan is a snapshot of one commit on one day; the repository has moved on since, so check it before you install.
