OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Models

Train LLM From Scratch

Train LLM From Scratch is a Python and PyTorch project that teaches a language-model training pipeline, from preparing raw text and training a transformer to generating text, evaluating models and exploring post-training methods.

Independent OpenViST project profile, based on linked sources.

Train LLM From Scratch — OpenViST project profile in AI Models.
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use it as a learning resource when you want to follow an LLM pipeline in code, from data preparation through generation and post-training. The project describes a CPU path for small models and GPU requirements for larger experiments.

Who it is for

  • Students learning how transformer language models are trained.
  • Developers who want to read or adapt the project’s scripts.
  • Researchers exploring small-model post-training methods.

Documented uses

  • Learn how raw text is prepared and converted into tokens for training.
  • Study transformer components and next-token pretraining.
  • Train a small model and generate text.
  • Explore supervised fine-tuning, reward modeling and preference or reinforcement-learning methods.
Before you choose

Requirements & limits

The GitHub repository is public and lists an MIT license.

  • The tutorial expects basic object-oriented programming, neural-network and PyTorch knowledge.
  • A CPU laptop track is described for small models; larger training runs require a GPU.
  • The repository presents both an original transformer and a more modern model path.
  • The project demonstrates a small model’s output, which may be incoherent; training a model does not itself establish fluent performance.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Set up the project and install its core package

Clone the repository and install the project in editable mode.

Before you start

  • Python 3.10 or later, as indicated by the repository badge.
  • Git and pip.

Steps

  1. Clone the repository with the command below.

    Documented command
    git clone https://github.com/FareedKhan-dev/train-llm-from-scratch.git
  2. Change into the project directory with cd train-llm-from-scratch.

  3. Install the project in editable mode with the command below.

    Documented command
    pip install -e .

Expected outcome

The project is installed in editable mode, which puts `config`, `src`, `data_loader`, and `ui` on the import path.

Guide limitations

  • On Linux without an NVIDIA GPU, the README says to install the CPU build of PyTorch before the project, using pip install torch --index-url https://download.pytorch.org/whl/cpu.
  • Optional training, UI, and documentation dependencies are installed separately through the listed extras; the core install alone does not install them.
Source-based practical guide

Train a small language model on a laptop CPU and generate text

Prepare TinyStories data, train the documented tiny model on CPU, and generate a story.

Before you start

  • A project environment with Python and dependencies installed.
  • A laptop CPU; the README presents this track for use without a GPU.

Steps

  1. Run the command below to download TinyStories and train a BPE tokenizer from scratch.

    Documented command
    python scripts/prepare_tiny_data.py
  2. Run the command below to train the 369K-parameter model.

    Documented command
    python scripts/train_transformer.py --preset tiny --arch modern
  3. Run the command below to write a story.

    Documented command
    python scripts/generate_text.py --model_path models/tiny.pt

Expected outcome

The documented pipeline prepares data, trains a small model, and writes generated text.

Guide limitations

  • The README estimates about five minutes for training and about ten minutes for the complete laptop track; these are estimates, not guaranteed timings.
  • The data-preparation command downloads 25 MB of TinyStories.
  • The recipe covers the tiny laptop model, not larger models.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
7 October 2026
Original website title
FareedKhan-dev/train-llm-from-scratch · Official homepage title · retained in its source language