# LLMs-from-scratch

> Code for building, pretraining and finetuning a GPT-like language model in PyTorch, from the book Build a Large Language Model.

- Type: skill
- Field: Learning & Education
- Repository: https://github.com/rasbt/LLMs-from-scratch
- GitHub stars: 109353
- Licence: NOASSERTION
- Language: Jupyter Notebook
- Last push: 2026-11-26
- Page: https://imutechz.in/agents/llms-from-scratch

## What it is
This repository holds the official code for the book Build a Large Language Model (From Scratch). It walks through coding a GPT-like model step by step, from working with text data and attention mechanisms to pretraining and finetuning. It is for learners who want to understand how LLMs work from the inside. The code also covers loading weights of larger pretrained models for finetuning.

## Features
- Chapter-by-chapter Jupyter notebooks
- Coding attention mechanisms
- Implementing a GPT model
- Pretraining on unlabeled data
- Finetuning for text classification
- Finetuning to follow instructions

## Best for
- Learning how LLMs work by building one
- Following the book chapter by chapter
- Studying attention and GPT code in PyTorch
- Practicing finetuning on small models

## Pros
- Step-by-step explanations with diagrams and examples
- Includes exercise solutions
- Has a troubleshooting guide and setup notes

## Cons
- Meant for education with a small model, not a production system

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

Tags: llm, pytorch, gpt, education, finetuning, attention, jupyter, from-scratch
