MrTechKing

4 min read

LLMs from Scratch: Build a ChatGPT-Like Model in PyTorch (GitHub, Scanned)

Sebastian Raschka's free code for building a GPT-style LLM in PyTorch, from tokenizer to fine-tuning, on an ordinary laptop.

LLMs from Scratch logo
✅
Scan: safe. Nothing to warn about. No secrets, no suspicious code and no binaries; the notebooks download model weights from OpenAI and the author's own storage only when you run them. Scanned Nov 28, 2026; the full report is below.

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.

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-code

2. Clone the code

git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git

3. Inside the folder, install the packages and open the notebooks

pip install -r requirements.txt && jupyter lab

4. Or import the chapter code into your own project

pip install llms-from-scratch

requirements.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

CheckResult
SecretsNone found.
Suspicious codeNone found.
Install-time codeNone: nothing runs at install beyond the package manager itself.
Committed binariesNone.
CI workflows13 workflows. None use pull_request_target. 0 of 1 third-party action pinned to a tag rather than a commit.
Network hosts39 distinct hosts referenced from source; most often github.com, sebastianraschka.com, mng.bz, www.manning.com. No URLs to bare IP addresses.
Known vulnerabilitiesNo lockfile to check: dependencies are declared as ranges, so what gets installed is whatever is current on the day.
Project hygieneHas licence file. Missing security policy, automated dependency updates, CodeQL, contributing guide.
OpenSSF ScorecardNot scored: the project is not in Scorecard's weekly index.

By the numbers

Stars109.2K
Forks16.9K
Contributors79
Commits1,099
Open issues1
Open pull requests4
Releases0
Latest releasenone tagged
Licencecustom
Main languageJupyter Notebook
Project age3 years
Last pushNov 26, 2026
Tracked files368
Lines of code130.9K
Checkout size7 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.