# ๐Ÿ”ฅ TinyTorch ### Build Your Own ML Framework From Scratch [![CI](https://img.shields.io/github/actions/workflow/status/harvard-edge/cs249r_book/tinytorch-ci.yml?branch=dev&label=CI&logo=githubactions)](https://github.com/harvard-edge/cs249r_book/actions/workflows/tinytorch-ci.yml) [![Docs](https://img.shields.io/badge/docs-mlsysbook.ai-blue?logo=readthedocs)](https://mlsysbook.ai/tinytorch) [![Python](https://img.shields.io/badge/python-3.8+-3776ab?logo=python&logoColor=white)](https://python.org) [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) [![Harvard](https://img.shields.io/badge/Harvard-CS249r-A51C30?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0xMiAyTDIgN2wxMCA1IDEwLTV6TTIgMTdsMTAgNSAxMC01TTIgMTJsMTAgNSAxMC01Ii8+PC9zdmc+)](https://mlsysbook.ai) **Most ML courses teach you to *use* frameworks. TinyTorch teaches you to *build* them.** [Get Started](#-quick-start) ยท [20 Modules](#-20-progressive-modules) ยท [Documentation](https://mlsysbook.ai/tinytorch) ยท [Contributing](CONTRIBUTING.md)
--- > ๐Ÿงช **Early Access** - TinyTorch is available for early adopters! All 20 modules are implemented with complete solutions and the `tito` CLI for streamlined workflows. > > ๐ŸŽฏ **Spring 2025**: Full public release with community features and classroom deployment resources. --- ## Why TinyTorch? **"Most ML education teaches you to _use_ frameworks. TinyTorch teaches you to _build_ them."** The difference between ML users and ML engineers determines who drives innovation versus who merely consumes it. TinyTorch bridges this gap by teaching you to build every component of modern AI systems from scratch. A Harvard University course that transforms you from framework user to systems engineer, giving you the deep understanding needed to optimize, debug, and innovate at the foundation of AI. --- ## What You'll Build A **complete ML framework** capable of: ๐ŸŽฏ **North Star Achievement**: Train CNNs for image classification - Real computer vision on standard benchmark datasets - Built entirely from scratch using only NumPy - Competitive performance with modern frameworks **Additional Capabilities**: - GPT-style language models with attention mechanisms - Modern optimizers (Adam, SGD) with learning rate scheduling - Performance profiling, optimization, and competitive benchmarking **No dependencies on PyTorch or TensorFlow - everything is YOUR code!** --- ## Quick Start ```bash # One-line install curl -sSL tinytorch.ai/install | bash # Activate and get started cd tinytorch source .venv/bin/activate tito setup # Start building! tito module start 01 ``` > **Tip**: Run the installer from a project folder (e.g., `~/projects`). It will create a `tinytorch/` directory with everything you need. Update anytime with `tito update`. --- ## 20 Progressive Modules Build your framework through four progressive parts: | Part | Modules | What You Build | |------|---------|----------------| | **I. Foundations** | 01-07 | Tensors, activations, layers, losses, autograd, optimizers, training | | **II. Vision** | 08-09 | DataLoaders, Conv2d, CNNs for image classification | | **III. Language** | 10-13 | Tokenization, embeddings, attention, transformers | | **IV. Optimization** | 14-20 | Profiling, quantization, compression, acceleration, benchmarking, capstone | Each module asks: **"Can I build this capability from scratch?"** ๐Ÿ“– **[Full curriculum and module details โ†’](https://mlsysbook.ai/tinytorch)** --- ## Historical Milestones As you progress, unlock recreations of landmark ML achievements: | Year | Milestone | Your Achievement | |------|-----------|------------------| | 1957 | Perceptron | Binary classification with gradient descent | | 1969 | XOR Crisis | Multi-layer networks solve non-linear problems | | 1986 | Backpropagation | Multi-layer network training | | 1998 | CNN Revolution | **Image classification with convolutions** | | 2017 | Transformer Era | Language generation with self-attention | | 2018+ | MLPerf | Production-ready optimization | **These aren't toy demos** - they're historically significant ML achievements rebuilt with YOUR framework! --- ## Learning Philosophy ```python # Traditional Course: import torch model.fit(X, y) # Magic happens # TinyTorch: # You implement every component # You measure memory usage # You optimize performance # You understand the systems ``` **Why Build Your Own Framework?** - **Deep Understanding** - Know exactly what `loss.backward()` does - **Systems Thinking** - Understand memory, compute, and scaling - **Debugging Skills** - Fix problems at any level of the stack - **Production Ready** - Learn patterns used in real ML systems --- ## Documentation | Audience | Resources | |----------|-----------| | **Students** | [Course Website](https://mlsysbook.ai/tinytorch) ใƒป [Quick Start](site/STUDENT_QUICKSTART.md) ใƒป [FAQ](site/faq.md) | | **Instructors** | [Instructor Guide](INSTRUCTOR.md) ใƒป [NBGrader Setup](site/nbgrader/) ใƒป [TA Guide](TA_GUIDE.md) | | **Contributors** | [Contributing Guide](CONTRIBUTING.md) ใƒป [Module Development](site/development/module-rules.md) | --- ## Repository Structure ``` TinyTorch/ โ”œโ”€โ”€ src/ # ๐Ÿ’ป Python source files (developers/contributors edit here) โ”‚ โ”œโ”€โ”€ 01_tensor/ # Module 01: Tensor operations from scratch โ”‚ โ”‚ โ”œโ”€โ”€ 01_tensor.py # Python source (version controlled) โ”‚ โ”‚ โ””โ”€โ”€ ABOUT.md # Conceptual overview & learning objectives โ”‚ โ”œโ”€โ”€ 02_activations/ # Module 02: ReLU, Softmax activations โ”‚ โ”œโ”€โ”€ 03_layers/ # Module 03: Linear layers, Module system โ”‚ โ”œโ”€โ”€ 04_losses/ # Module 04: MSE, CrossEntropy losses โ”‚ โ”œโ”€โ”€ 05_autograd/ # Module 05: Automatic differentiation โ”‚ โ”œโ”€โ”€ 06_optimizers/ # Module 06: SGD, Adam optimizers โ”‚ โ”œโ”€โ”€ 07_training/ # Module 07: Complete training loops โ”‚ โ”œโ”€โ”€ 08_dataloader/ # Module 08: Efficient data pipelines โ”‚ โ”œโ”€โ”€ 09_spatial/ # Module 09: Conv2d, MaxPool2d, CNNs โ”‚ โ”œโ”€โ”€ 10_tokenization/ # Module 10: Text processing โ”‚ โ”œโ”€โ”€ 11_embeddings/ # Module 11: Token & positional embeddings โ”‚ โ”œโ”€โ”€ 12_attention/ # Module 12: Multi-head attention โ”‚ โ”œโ”€โ”€ 13_transformers/ # Module 13: Complete transformer blocks โ”‚ โ”œโ”€โ”€ 14_profiling/ # Module 14: Performance analysis โ”‚ โ”œโ”€โ”€ 15_quantization/ # Module 15: Model compression (precision reduction) โ”‚ โ”œโ”€โ”€ 16_compression/ # Module 16: Pruning & distillation โ”‚ โ”œโ”€โ”€ 17_memoization/ # Module 17: KV-cache/memoization โ”‚ โ”œโ”€โ”€ 18_acceleration/ # Module 18: Hardware optimization โ”‚ โ”œโ”€โ”€ 19_benchmarking/ # Module 19: Performance measurement โ”‚ โ””โ”€โ”€ 20_capstone/ # Module 20: Complete ML systems โ”‚ โ”œโ”€โ”€ modules/ # ๐Ÿ““ Generated notebooks (learners work here) โ”‚ โ”œโ”€โ”€ 01_tensor/ # Auto-generated from src/ โ”‚ โ”‚ โ”œโ”€โ”€ 01_tensor.ipynb # Jupyter notebook for learning โ”‚ โ”‚ โ”œโ”€โ”€ README.md # Practical implementation guide โ”‚ โ”‚ โ””โ”€โ”€ tensor.py # Your implementation โ”‚ โ””โ”€โ”€ ... # (20 module directories) โ”‚ โ”œโ”€โ”€ site/ # ๐ŸŒ Course website & documentation (Jupyter Book) โ”‚ โ”œโ”€โ”€ intro.md # Landing page โ”‚ โ”œโ”€โ”€ _toc.yml # Site navigation (links to modules) โ”‚ โ”œโ”€โ”€ _config.yml # HTML website configuration โ”‚ โ”œโ”€โ”€ chapters/ # Course content chapters โ”‚ โ””โ”€โ”€ modules/ # Module documentation โ”‚ โ”œโ”€โ”€ milestones/ # ๐Ÿ† Historical ML evolution - prove what you built! โ”‚ โ”œโ”€โ”€ 01_1957_perceptron/ # Rosenblatt's first trainable network โ”‚ โ”œโ”€โ”€ 02_1969_xor/ # Minsky's challenge & multi-layer solution โ”‚ โ”œโ”€โ”€ 03_1986_mlp/ # Backpropagation & MNIST digits โ”‚ โ”œโ”€โ”€ 04_1998_cnn/ # LeCun's CNNs & CIFAR-10 โ”‚ โ”œโ”€โ”€ 05_2017_transformer/ # Attention mechanisms & language โ”‚ โ””โ”€โ”€ 06_2018_mlperf/ # Modern optimization & profiling โ”‚ โ”œโ”€โ”€ tito/ # ๐ŸŽ›๏ธ CLI tool for streamlined workflows โ”‚ โ”œโ”€โ”€ main.py # Entry point โ”‚ โ”œโ”€โ”€ commands/ # 23 command modules โ”‚ โ””โ”€โ”€ core/ # Core utilities โ”‚ โ”œโ”€โ”€ tinytorch/ # ๐Ÿ“ฆ Generated package (import from here) โ”‚ โ”œโ”€โ”€ core/ # Core ML components โ”‚ โ””โ”€โ”€ ... # Your built framework! โ”‚ โ””โ”€โ”€ tests/ # โœ… Comprehensive test suite (600+ tests) ``` **Key workflow**: `src/*.py` โ†’ `modules/*.ipynb` โ†’ `tinytorch/*.py` --- ## Join the Community TinyTorch is part of the [ML Systems Book](https://mlsysbook.ai) ecosystem. We're building an open community of learners and educators passionate about ML systems. **Ways to get involved:** - โญ Star this repo to show support - ๐Ÿ’ฌ Join [Discussions](https://github.com/harvard-edge/cs249r_book/discussions) to ask questions - ๐Ÿ› Report issues or suggest improvements - ๐Ÿค Contribute modules, fixes, or documentation See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. --- ## Related Projects "TinyTorch" is a popular name for educational ML frameworks. We acknowledge excellent projects with similar names: - [tinygrad](https://github.com/tinygrad/tinygrad) - George Hotz's minimalist framework - [micrograd](https://github.com/karpathy/micrograd) - Andrej Karpathy's tiny autograd - [MiniTorch](https://minitorch.github.io/) - Cornell's educational framework **Our TinyTorch** distinguishes itself through its 20-module curriculum, NBGrader integration, ML systems focus, and connection to the [ML Systems Book](https://mlsysbook.ai) ecosystem. --- ## Acknowledgments Created by [Prof. Vijay Janapa Reddi](https://vijay.seas.harvard.edu) at Harvard University. Special thanks to students and contributors who helped build this framework. --- ## License MIT License - see [LICENSE](LICENSE) for details. ---
**[๐Ÿ“– Full Documentation](https://mlsysbook.ai/tinytorch)** ใƒป **[๐Ÿ’ฌ Discussions](https://github.com/harvard-edge/cs249r_book/discussions)** ใƒป **[๐ŸŒ ML Systems Book](https://mlsysbook.ai)** **Start Small. Go Deep. Build ML Systems.**