TopGit
GitHub Repo Review

LLMs-from-scratch: Build LLM PyTorch Step by Step

rasbt/LLMs-from-scratch
LTopGit review image for rasbt/LLMs-from-scratch
Review by Topgit.dev for rasbt/LLMs-from-scratch, with GitHub repository stats and README context.
Quick verdict

Build a Large Language Model (From Scratch) is Sebastian Raschka's code companion to his Manning book of the same name, walking through pretraining and finetuning a GPT-style model chapter by chapter in PyTorch. Reach for it if you want to write every layer of a transformer yourself and understand why it works, not just call an API. Skip it if you want a production LLM stack, since the repository is built for learning, not deployment.

Stars
โ˜… 105.3k
Forks
โ‘‚ 16.1k
Contributors
๐Ÿ‘ฅ 68
Language
Jupyter Notebook
License
See repository
Topic
AI Tools
Updated
Sep 2026

What is it?

Build a Large Language Model (From Scratch) is the official GitHub code repository for Sebastian Raschka's Manning book of the same title, ISBN 9781633437166. It contains Jupyter notebooks and Python scripts that build a GPT-like model from raw text handling through pretraining and two kinds of finetuning, organized into seven numbered chapters plus five appendices.

Who Benefits from This Learning Resource

Developers who already know Python well and want to understand transformer internals instead of importing a library get the most out of this repo, since the README lists a strong Python foundation as the main prerequisite and treats prior deep-learning experience as a bonus, not a requirement. Appendix A gives a from-scratch PyTorch primer for readers new to the framework, so you don't need PyTorch experience going in, just patience for reading tensor code line by line. Skip it if you want a ready-made model API instead of a chapter-by-chapter build.

Comprehensive LLM Implementation Topics

  • โœ“Chapter 2 covers text data handling: tokenization, byte pair encoding, and building data loaders for training.
  • โœ“Chapter 3 codes attention mechanisms from scratch, including a multi-head attention implementation.
  • โœ“Chapter 4 implements a full GPT-style model architecture in PyTorch, with a standalone gpt.py script.
  • โœ“Chapter 5 pretrains the model on unlabeled text and includes bonus material on loading pretrained weights and converting the GPT model to a Llama architecture.
  • โœ“Chapter 6 finetunes the model for text classification; Chapter 7 finetunes it to follow instructions, including a DPO (Direct Preference Optimization) notebook for alignment.
  • โœ“Appendix E covers LoRA, a parameter-efficient finetuning method, and Appendix D adds extras like learning rate schedulers to the training loop.
  • โœ“Bonus notebooks outside the numbered chapters rebuild newer architectures from scratch too, including Qwen3, Gemma 3, Olmo 3, and Llama 3.2 variants, plus mechanisms like KV caching and grouped-query attention.
How this repository's GitHub stars have grown over time. Source: star-history.com.View the star history โ†—

Strengths

  • โœ“Chapter-by-chapter structure ties directly to a published Manning book, so the code has a fixed reference and a companion video course rather than being a loose pile of scripts.
  • โœ“Building attention, the GPT architecture, pretraining, and two finetuning approaches from scratch forces an understanding library shortcuts usually hide.
  • โœ“Runs on ordinary laptops for the main chapters and automatically uses a GPU if one's available, so you don't need a cluster to follow along.
  • โœ“Bonus material stays current with newer open architectures: Qwen3, Gemma 3, Olmo 3, and Llama 3.2 rebuilds sit alongside the core seven chapters.
  • โœ“Every chapter includes exercises with solutions summarized in Appendix C inside the repo, plus an optional 170-page self-test PDF you can download from Manning for extra practice.

Scope and Contribution Guidelines

  • โ–ณSebastian Raschka states plainly that the code exists to teach LLM mechanics, producing a compact model meant for educational purposes, not one sized or optimized for production use.
  • โ–ณThe maintainer won't accept pull requests that extend or change the main chapter code, since deviating from the printed book would break the one-to-one mapping readers rely on.
  • โ–ณThe license isn't clearly documented here. Confirm the exact terms on the GitHub repository page before reusing any of the code.
  • โ–ณSome of the study material sits outside the repository itself: the 170-page self-test PDF and parts of the book text are distributed through Manning, not bundled with the code.

Related Learning Resources

Frequently Asked Questions

What are the prerequisites for using the LLMs-from-scratch repository?

Build a Large Language Model (From Scratch) treats solid Python skills as its core requirement before you start. The README notes that prior exposure to deep neural networks helps but isn't required, and PyTorch familiarity is useful rather than mandatory since Appendix A introduces PyTorch basics.

What hardware is recommended for running the LLMs-from-scratch code?

The main chapters of Build a Large Language Model (From Scratch) run comfortably on an everyday laptop in a reasonable amount of time, with no specialized hardware needed. The code automatically switches to a GPU when one is available, per the README.

Is the LLMs-from-scratch code suitable for building production-ready LLMs?

Build a Large Language Model (From Scratch) is built to teach the mechanics behind a GPT-like model, not to hand you a production system. The README frames the resulting model as compact and meant for educational purposes, so treat this as a study project rather than a deployment-ready LLM stack.

How does this repository relate to the 'Build a Large Language Model (From Scratch)' book?

The rasbt/LLMs-from-scratch repository is the official code companion for Sebastian Raschka's Manning book Build a Large Language Model (From Scratch), ISBN 9781633437166. Every notebook and script maps to a chapter or appendix in the printed book, and a separate 17-hour, 15-minute video course mirrors the same structure.

Can I contribute code or make pull requests to the main chapters?

Pull requests that extend or change the main chapter code aren't accepted for Build a Large Language Model (From Scratch), since deviating from the printed book would break the mapping between the two. The README does welcome general feedback and questions through GitHub Discussions or the Manning Forum instead.

What is the license for the code in this repository?

The license isn't clearly documented in the facts available for Build a Large Language Model (From Scratch), so confirm the exact terms on the GitHub repository page before reusing the code elsewhere.

Best use cases

  • โ€ขWorking through Build a Large Language Model (From Scratch) chapter by chapter alongside the book or the companion video course, running each notebook as you read.
  • โ€ขUsing it as a hands-on PyTorch refresher: Appendix A's from-scratch tensor and training-loop code doubles as a standalone PyTorch primer.
  • โ€ขExtending the bonus notebooks to experiment with newer architectures the README lists as drop-in comparisons, such as Qwen3, Gemma 3, and Llama 3.2 rebuilt from scratch.
  • โ€ขTesting your understanding with the roughly 30 quiz questions per chapter in the free 170-page self-test PDF Manning distributes alongside the book.

Related repositories

Source & attribution

Facts and quotes sourced from the rasbt/LLMs-from-scratch GitHub repository and its README.

GitHub data ยท last synced Aug 14, 2026Reviewed by Henry
โ† Back to TopGit

Want a second opinion on LLMs-from-scratch?

Ask an AI that can read this page โ€” one click and you get its take on LLMs-from-scratch.

GitHub