← all repositories
rasbt/LLMs-from-scratch

The anti-black-box: coding a GPT from the ground up

It teaches how LLMs work by implementing tokenization, attention, pretraining, and finetuning in pure PyTorch, one notebook at a time.

99.6k stars Jupyter Notebook Language ModelsML FrameworksLearning
LLMs-from-scratch
Velocity · 7d
+64
★ / day
Trend
accelerating
star history

What it does This is the official code companion to Sebastian Raschka’s book Build a Large Language Model (From Scratch). It walks through constructing a small-but-functional GPT-like model using only PyTorch—no external LLM libraries—starting from text tokenization and culminating in instruction finetuning. The code is designed to run on conventional laptops, though it will use a GPU if one happens to be available.

The interesting bit The value is in the tedium: every attention head, layer norm, and training loop is written out explicitly in Jupyter notebooks so you can see the tensors mutate step by step. It is essentially a deliberate exercise in not using transformers or similar convenience wrappers.

Key highlights

  • Implements the full stack: tokenization, causal multi-head attention, GPT architecture, pretraining, classification finetuning, and instruction tuning.
  • Includes appendices on PyTorch basics, distributed data parallel, and parameter-efficient finetuning with LoRA.
  • Ships with exercise solutions and a 17-hour companion video course that codes through each chapter.
  • A sequel repo, Build A Reasoning Model (From Scratch), extends the work with inference-time scaling and RL.

Caveats

  • The README is upfront that this is an educational project; the resulting model is small and not competitive with production LLMs.
  • It is tightly coupled to the Manning book, so the repository reads like a course syllabus rather than a standalone framework.

Verdict Grab this if you want to stop treating LLMs as black boxes and actually watch the logits flow. Skip it if you are looking for a drop-in replacement for transformers or a recipe for training a production-grade model at scale.

Frequently asked

What is rasbt/LLMs-from-scratch?
It teaches how LLMs work by implementing tokenization, attention, pretraining, and finetuning in pure PyTorch, one notebook at a time.
Is LLMs-from-scratch open source?
Yes — rasbt/LLMs-from-scratch is an open-source project tracked on heatdrop.
What language is LLMs-from-scratch written in?
rasbt/LLMs-from-scratch is primarily written in Jupyter Notebook.
How popular is LLMs-from-scratch?
rasbt/LLMs-from-scratch has 99.6k stars on GitHub and is currently accelerating.
Where can I find LLMs-from-scratch?
rasbt/LLMs-from-scratch is on GitHub at https://github.com/rasbt/LLMs-from-scratch.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.