Repolode
no-magic-ai

no-magic-ai/no-magic

A collection of 54 single-file, dependency-free Python scripts that implement modern AI algorithms from scratch so their internals are readable.

Stars
1,433
Forks
105
Open issues
3
Last commit
5 days ago

What is it?

no-magic is a curated set of single-file Python programs, each implementing one AI algorithm using only the standard library. Topics span foundations such as tokenizers, GPT, RNN/LSTM, BERT, CNN, ViT, GAN, VAE and diffusion; alignment and training methods such as LoRA, QLoRA, DPO, PPO, GRPO, distillation and mixture of experts; systems and inference techniques such as Flash Attention, KV-cache, PagedAttention, quantization, speculative decoding and state space models; and basic agent methods such as MCTS, ReAct and bandits.

The scripts are written to be read as guided walkthroughs rather than production code. Most train a small model on a CPU and then run inference, while some compare alternative variants side by side or demonstrate untrained forward passes or non-learning algorithms. Each script's type is recorded in the repository catalog. Many scripts download a names dataset on first run; the rest generate their own data.

The project is aimed at ML engineers who want to understand the internals of frameworks they use, students moving from theory to code, and researchers who need minimal reference implementations. It also includes animated visualizations, challenges, flashcards and an offline EPUB book.

Key features

  • 01Each algorithm lives in one self-contained Python file with no third-party dependencies.
  • 02Covers 54 algorithms across foundations, alignment, systems and agents.
  • 03Most scripts train a small model on a CPU and then run inference.
  • 04Includes side-by-side comparison programs such as RNN vs GRU and Adam vs SGD.
  • 05Provides animated visualizations for each algorithm and Anki flashcard decks.

Use cases

  • Learning how GPT, attention or LoRA work by reading and running minimal code.
  • Preparing for ML interviews by walking through core algorithm implementations.
  • Teaching a course on neural network internals with runnable reference code.
  • Prototyping an idea from a paper without pulling in a large framework.

Quick start

  1. 1

    Clone the repository

  2. 2

    Run a script with Python 3.10+

Things to know

  • Scripts are educational reimplementations, not production tools or replacements for PyTorch or TensorFlow.
  • Requires Python 3.10 or newer.

Topics

FAQ

What is no-magic?
A collection of 54 single-file, dependency-free Python scripts that implement modern AI algorithms from scratch so their internals are readable. no-magic is a curated set of single-file Python programs, each implementing one AI algorithm using only the standard library. Topics span foundations such as tokenizers, GPT, RNN/LSTM, BERT, CNN, ViT, GAN, VAE and diffusion; alignment and training methods such as LoRA, QLoRA, DPO, PPO, GRPO, distillation and mixture of experts; systems and inference techniques such as Flash Attention, KV-cache, PagedAttention, quantization, speculative decoding and state space models; and basic agent methods such as MCTS, ReAct and bandits.
Is no-magic free to use? What license does it have?
no-magic is open source under the MIT license. Check the license terms before using it in commercial products.
Is no-magic still maintained?
Actively maintained. The last commit to no-magic was on Oct 15, 2026.
What can I use no-magic for?
Learning how GPT, attention or LoRA work by reading and running minimal code. Preparing for ML interviews by walking through core algorithm implementations. Teaching a course on neural network internals with runnable reference code. Prototyping an idea from a paper without pulling in a large framework.
How do I install no-magic?
Clone the repository Run a script with Python 3.10+
Where can I get no-magic?
The source code and installation instructions are on GitHub: https://github.com/no-magic-ai/no-magic

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects