Live survey315 models · 14 providers · 23,592 auditsAudited implement · SAFE →What changedHow we verifyllms.txt

Agent skill · Audited from source

Llm From Scratch Guide

skill · brycewang-stanford/Auto-Empirical-Research-SkillsNOASSERTION licenceAudited 8 Oct 2026 · source e1ba289846fd

★ 4,537pushed 3 days ago
✓SAFEGrade B · 89/100 · 8 Oct 2026 · e1ba289
4,537repo stars · whole brycewang-stanford/Auto-Empirical-Research-Skills

Is it safe? Yes — SAFE, grade B (89/100). We read this skill's source at commit e1ba289846fd and found no filesystem, network or shell access and no hard-coded secrets. What it does: Build a ChatGPT-like LLM from scratch using PyTorch step by step

Ask an AI about this pageGChatGPTCClaudePPerplexityGeGeminiXGrok
More
Cite

Cite this page

ModelsAtlas. “Llm From Scratch Guide (brycewang-stanford/Auto-Empirical-Research-Skills)”. Retrieved 8 Oct 2026. https://modelsatlas.com/skills/brycewang-stanford/llm-from-scratch-guide

Trust audit

Audit 0.4.1 · source read 8 Oct 2026

Trust score89/100✓SAFE B
0 critical0 high0 medium0 low0 info

SAFE means nothing in the source contradicts what the skill says it does. Grade B is shared by 17,406 of 18,389 audited skills.

What the source does

  • FilesystemNone observedNo reads or writes in the source
  • NetworkNone observedNo outbound calls in the source
  • ShellNone observedNo commands run in the source
  • DependenciesPinnedNothing floats
  • SecretsNone foundNo keys in source

Five audit layers

LayerWhat we checkResultFindings
L0 ProvenanceRepo owner, licence, archive status, activityPASS0
L1 Static sourceSecrets, path traversal, supply chain, hidden codeNA0
L2 InstructionsPrompt injection, authority framing, hidden directivesPASS0
L3 InventoryThe files and declarations match the sourcePASS0
L4 SandboxRun in isolation and watch behaviourSKIPPED why0

Gates applied: no behavioural pass.

Findings (0)

No findings at any severity. We re-audit when the source changes.

Audit 0.4.1 · source sha e1ba289846fd · 8 Oct 2026Report an issue or request a re-scan

Provenance

Who published it, and what the verdict is pinned to

What it tells the agent

Full source on GitHub ↗

Its description: Build a ChatGPT-like LLM from scratch using PyTorch step by step

---
name: llm-from-scratch-guide
description: "Build a ChatGPT-like LLM from scratch using PyTorch step by step"
metadata:
  openclaw:
    emoji: "🧱"
    category: "domains"
    subcategory: "ai-ml"
    keywords: ["llm", "pytorch", "transformer", "gpt", "pretraining", "finetuning"]
    source: "https://github.com/rasbt/LLMs-from-scratch"
---

# LLM From Scratch Guide

## Overview

LLMs-from-scratch is a comprehensive educational repository with over 87,000 stars on GitHub that teaches you how to build a ChatGPT-like large language model from the ground up using PyTorch. Created by Sebastian Raschka, a machine learning researcher and author, the project provides a complete pipeline covering data preparation, tokenization, attention mechanisms, pretraining, and instruction finetuning.

Unlike tutorials that treat LLMs as black boxes, this project demystifies every component by walking through the full implementation. Each chapter corresponds to a Jupyter notebook with clear explanations, diagrams, and runnable code. The repository accompanies the book "Build a Large Language Model (From Scratch)" and serves as a standalone learning resource for researchers and engineers who want deep understanding of transformer-based language models.

The project is particularly valuable for academic researchers who need to understand the internals of LLMs for their own research, whether that involves modifying architectures, running ablation studies, or developing domain-specific language models for scientific applications.

## Installation and Setup

Clone the repository and set up a Python environment with the required dependencies:

```bash
git clone https://github.com/rasbt/LLMs-from-scratch.git
cd LLMs-from-scratch

# Create a virtual environment
python -m venv llm-env
source llm-env/bin/activate

# Install dependencies
pip install -r requirements.txt
```

The project requires Python 3.10+ and PyTorch 2.0+. For GPU-accelerated training, ensure you have CUDA installed. The notebooks can also run on CPU for smaller model configurations, though training times will be significantly longer.

Key dependencies include:

- **PyTorch** >= 2.0 for model implementation and training
- **tiktoken** for BPE tokenization compatible with OpenAI models
- **matplotlib** for training visualization
- **jupyter** for interactive notebook execution

## Core Learning Pipeline

The project is organized into sequential chapters that build on each other:

### Chapter 1: Understanding Large Language Models
Covers the conceptual foundations of LLMs, including the transformer architecture, the difference between encoder and decoder models, and how pretraining and finetuning work at a high level.

### Chapter 2: Working with Text Data
Implements text tokenization from scratch, including byte-pair encoding (BPE). You build a custom tokenizer and learn how text is converted to numerical representations:

```python
# Tokenization example from the project
import tiktoken

tokenizer = tiktoken.get_encoding("gpt2")
text = "Large language models are fascinating."
token_ids = tokenizer.encode(text)
decoded = tokenizer.decode(token_ids)
```

### Chapter 3: Coding Attention Mechanisms
Implements self-attention, multi-head attention, and causal (masked) attention from scratch. This is the core computational primitive of transformers:

```python
# Simplified multi-head attention
class MultiHeadAttention(nn.Module):
    def __init__(self, d_in, d_out, context_length, num_heads, dropout=0.0):
        super().__init__()
        self.W_query = nn.Linear(d_in, d_out, bias=False)
        self.W_key = nn.Linear(d_in, d_out, bias=False)
        self.W_value = nn.Linear(d_in, d_out, bias=False)
        self.out_proj = nn.Linear(d_out, d_out)
        self.num_heads = num_heads
        self.head_dim = d_out // num_heads
```

### Chapter 4: Implementing a GPT Model
Assembles the full GPT architecture using the attention mechanism, layer normalization, feed-forward networks, and positional embeddings.

### Chapter 5: Pretraining on Unlabeled Data
Trains the GPT model on a text corpus using next-token prediction. Covers the training loop, loss computation, learning rate scheduling, and gradient clipping.

### Chapter 6: Finetuning for Text Classification
Adapts the pretrained model for downstream classification tasks, demonstrating how to add a classification head and finetune on labeled data.

### Chapter 7: Instruction Finetuning
Converts the pretrained model into an instruction-following assistant using supervised finetuning on instruction-response pairs, similar to how ChatGPT is trained.

## Research Applications

This resource is invaluable for several research scenarios:

- **Architecture ablation studies**: Modify individual components (attention heads, layer count, embedding dimensions) and measure their impact on performance
- **Domain-specific pretraining**: Use the pipeline to pretrain models on scientific corpora (biomedical literature, physics papers, chemical databases)
- **Tokenizer research**: Experiment with different tokenization strategies for specialized vocabularies
- **Efficient training methods**: Test techniques like gradient accumulation, mixed precision, and learning rate warmup
- **Interpretability research**: Inspect attention patterns and intermediate representations at every layer

For researchers working with limited compute, the project includes configurations for small models (124M parameters) that can be trained on a single GPU in reasonable time, making it practical for experimentation and prototyping.

## Integration with Research Workflows

Combine this project with other tools in your research stack:

- Use **Weights & Biases** or **MLflow** for experiment tracking during pretraining runs
- Export trained models to **Hugging Face Hub** for sharing and reproducibility
- Integrate with **PyTorch Lightning** for distributed training across multiple GPUs
- Apply **LoRA** or **QLoRA** adapters from the bonus chapters for

Excerpt, first 6,001 characters of SKILL.md, verbatim from the audited commit. It is text from someone else’s repository, quoted so you can judge it before your agent reads it.

Install

Pinned to the audited commit e1ba289

Download folder ↗
git clone https://github.com/rasbt/LLMs-from-scratch.git
pip install -r requirements.txt

Commands as the repository documents them: shown, never run by us. Our verdict covers commit e1ba289846fd only.

Works in which agents?

What its own text says, not a test

AgentStatusMore
OpenClawMentioned in its text, not testedSkills for OpenClaw · About OpenClaw
“Mentioned” means the skill’s text names the agent. We have not run it there.

Audit history

Every audit, every source change

  1. ✓SAFE B 89 / 100

    first audit · source e1ba289846fd

README badge

For maintainers · shows the latest audit

ModelsAtlas: SAFE BMODELSATLASSAFE · B
[![ModelsAtlas: SAFE B](https://modelsatlas.com/skills/brycewang-stanford/llm-from-scratch-guide/badge.svg)](https://modelsatlas.com/skills/brycewang-stanford/llm-from-scratch-guide/)

The badge shows our verdict and grade for this skill, and links back to this page. It changes when the audit does.

Similar skills

Add this badge to your README

[![ModelsAtlas: SAFE B](https://modelsatlas.com/skills/brycewang-stanford/llm-from-scratch-guide/badge.svg)](https://modelsatlas.com/skills/brycewang-stanford/llm-from-scratch-guide/)

Questions about Llm From Scratch Guide

What does the Llm From Scratch Guide skill do?
🔬 A curated collection of 23,000+ agent skills for empirical research across 8 social science disciplines. | 精选 23,000+ AI Agent 技能库,覆盖8大社会科学学科的实证研究。CoPaper.AI 20分钟完成一篇可复现的规范实证论文,并支持用户上传 Skills。-- Maintained by CoPaper.AI from Stanford REAP.
Is Llm From Scratch Guide safe to install?
The audit found nothing in the source that contradicts what it says it does, and graded it B (89/100). Grade A is held back for packages that have also passed a sandboxed behavioural run, which is why a clean skill reads B.
What can Llm From Scratch Guide access on my machine?
The audit observed no filesystem, network or shell use at all in its source.
Which assistants does Llm From Scratch Guide work with?
Its documentation mentions openclaw. That is what the text claims, not a compatibility test we ran.
How current is this page?
The grade is for one exact copy of the source (e1ba289846fd), read on 2026-10-08. The repository is watched, and a new audit runs when it changes — this is the first audit.

Sources

Spotted something wrong? Report a correction · Methodology

Keep going in your AI

Opens with this page as the source. We add nothing else to the prompt.