Tiny-PyTorch 🧠
Unravel the magic of modern deep learning by building a PyTorch-like framework from the ground up.
Tiny-PyTorch is an educational deep learning framework built entirely in Python. It demystifies the core machinery of libraries like PyTorch by providing a clean, focused, and from-scratch implementation of the essential components.
Philosophy: Understanding by Building
The best way to truly understand how complex systems work is to build them yourself. Tiny-PyTorch is born from this philosophy. While production frameworks like PyTorch and TensorFlow provide powerful, high-level abstractions, their internal complexity can be a barrier to learning.
This project strips away those abstractions, allowing you to:
- See the Core Logic: Grasp the fundamental algorithms and data structures that power deep learning, from the
Tensorobject to the backpropagation process. - Connect Theory to Code: Bridge the gap between the mathematical concepts of deep learning and their concrete implementation.
- Become a Better Practitioner: Use high-level frameworks more effectively by understanding their internal mechanics, performance trade-offs, and potential pitfalls.
✨ Core Features
- Dynamic Computation Graph: Tensors track their history, allowing for flexible model architectures.
- Reverse-Mode Automatic Differentiation: An efficient gradient calculation engine (
autograd) built from scratch. - Extensible
nn.ModuleSystem: A familiar API for building complex neural network layers and models. - Standard Optimizers: Implementations of
SGDandAdamto handle parameter updates. - Hardware Acceleration: A pluggable backend system supporting
NumPy, customCPU(C++), andCUDA(GPU) operations. - Data Loading Utilities:
DatasetandDataLoaderclasses for efficient data pipelines.
🏗️ Project Architecture
The framework is built in a bottom-up fashion, where each layer of abstraction relies on the one below it. This mirrors the logical structure of major deep learning libraries.
graph TD
subgraph "High-Level API"
C[nn.Module] --> D[Optimizers]
B[Tensors & Autograd] --> C
end
subgraph "Low-Level Engine"
A[NDArray] --> B
subgraph "Backends"
direction LR
np[NumPy]
cpu[CPU]
gpu[CUDA]
end
Backend --> A
end
style C fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#ccf,stroke:#333,stroke-width:2px
style A fill:#cfc,stroke:#333,stroke-width:2px
- Backends (NumPy, CPU, CUDA): Perform the actual mathematical computations on flat arrays of data.
- NDArray: A generic, strided N-dimensional array class that provides a unified interface over different backends.
- Tensor & Autograd: The heart of the framework. A
Tensorwraps anNDArrayand builds a dynamic computation graph. Theautogradengine traverses this graph to perform reverse-mode automatic differentiation. - High-Level API (
nn,optimizer): Provides the familiar modules, layers, and optimization algorithms for building and training neural networks.
🚀 Quick Start
To install Tiny-PyTorch, you have two main options:
Install from PyPI (using pip)
You can install the latest stable version directly from PyPI using pip:
pip install tiny-pytorch
Install from Source (GitHub Repository)
To get the very latest development version or if you plan to contribute, you can install from the GitHub repository:
- Clone the repository:
git clone https://github.com/your-username/tiny-pytorch.git
- Navigate to the project directory:
cd tiny-pytorch
- Install in editable mode: This allows you to make changes to the source code and have them reflected without reinstalling.
pip install -e .
Here's a simple example of defining a model and running a forward/backward pass.
import numpy as np
import tiny_pytorch as tp
import tiny_pytorch.nn as nn
import tiny_pytorch.optim as optim
from tiny_pytorch import init
# 1. Define a simple classifier
class SimpleNet(nn.Module):
def __init__(self, in_features, num_classes):
super().__init__()
self.fc1 = nn.Linear(in_features, 64)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(64, num_classes)
def forward(self, x):
x = self.fc1(x)
x = self.relu(x)
return self.fc2(x)
# 2. Initialize model, optimizer, and loss function
model = SimpleNet(in_features=10, num_classes=3)
optimizer = optim.Adam(model.parameters(), lr=0.001)
loss_fn = nn.SoftmaxLoss()
# 3. Create dummy data
x_train = init.randn(32, 10)
y_true = tp.Tensor(np.random.randint(0, 3, size=(32,)))
# 4. Perform a single training step
optimizer.reset_grad() # Reset gradients
logits = model(x_train) # Forward pass
loss = loss_fn(logits, y_true) # Compute loss
loss.backward() # Backward pass (autograd)
optimizer.step() # Update weights
print(f"Loss: {loss.numpy().item():.4f}")
🗺️ Roadmap
The project is developed in two main phases. Our current progress is tracked below.
- Phase I: Core Framework (NumPy Backend)
-
Tensor: The main multi-dimensional array with autograd support. -
Op: The base class for all tensor operations. -
Automatic Differentiation: Reverse-mode autograd engine. -
init: Parameter initialization functions (kaiming,xavier, etc.). -
nn: Core neural network layers (Linear,ReLU,BatchNorm,Conv2d). -
optimizer:SGDandAdamoptimizers. -
data:DatasetandDataLoaderfor data handling.
-
- Phase II: Hardware Acceleration & Advanced Models
-
NDArray: Generic, strided N-dimensional array. - NumPy Backend
- CPU Backend (C++)
- CUDA Backend (GPU)
- Advanced CNN operations (e.g.,
padding,dilation). - ResNet implementation.
- RNN and LSTM layers.
- A simple Language Model.
-
📚 Documentation
The official documentation, including detailed API references and tutorials, is hosted at: https://imaddabbura.github.io/tiny-pytorch/
⚠️ Limitations
As an educational project, Tiny-PyTorch has some intentional simplifications:
- Explicit Broadcasting: Broadcasting for element-wise operations must be done manually if tensor shapes do not match.
- Single Data Type:
NDArrayonly supports thefloat32dtype. - Contiguous Memory: Operations on the underlying 1D array require a call to
compact()to ensure the data is in a contiguous memory block. - Limited Reductions: Reduction operations (e.g.,
sum,max) can only be performed on a single axis or all axes at once.
🙏 Acknowledgements
This project was inspired by and built upon ideas from the following resources:
- Deep Learning Systems by J. Zico Kolter and Tianqi Chen
- micrograd by Andrej Karpathy
- Machine Learning Systems by Tianqi Chen and Zhihao Jia
License
Tiny-PyTorch is licensed under the Apache License 2.0. See the LICENSE file for details.
Metadata
Release files for tiny-pytorch 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| tiny_pytorch-0.2.0-cp313-cp313-musllinux_1_2_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux musl 1.2+ x86-64 | Details |
| tiny_pytorch-0.2.0-cp313-cp313-musllinux_1_2_i686.whl | CPython 3.13 | CPython 3.13 | Linux musl 1.2+ x86-32 | Details |
| tiny_pytorch-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.17+ x86-64 | Details |
| tiny_pytorch-0.2.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.17+ x86-32 | Details |
| tiny_pytorch-0.2.0-cp313-cp313-macosx_11_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 11.0+ ARM64 | Details |
Total release size: 8.8 MB
Release files / tiny_pytorch-0.2.0-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | tiny_pytorch-0.2.0-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
b5d8a20d0801b155eef941dec4aeb9f5bea029448ccf01e90e0ac08a8e767a00
|
|
BLAKE2b-256 checksum How to use checksums |
12d274dd2cb049c6aa3c79b5181b1e13f3933eb838b43ea6681fe3a1a62dfd71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency logRelease files / tiny_pytorch-0.2.0-cp313-cp313-musllinux_1_2_i686.whl
| Download URL | tiny_pytorch-0.2.0-cp313-cp313-musllinux_1_2_i686.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
3891caf68ffb991ebc4583e940b0d5ccb89fbb81c2d293ec7f8d616e83c7bd20
|
|
BLAKE2b-256 checksum How to use checksums |
151041c4e01a1a7d91826c547c0dbc3678a89561458c96371136a21efc2732d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency logRelease files / tiny_pytorch-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | tiny_pytorch-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
c95ed39291ff2fab50bb80e2f6c3780ec242a90a39564df111e794247ddd1715
|
|
BLAKE2b-256 checksum How to use checksums |
a0dfb4f48039a61d5e17b9c61b2eb0f0c67019e58a9b029eaa1f3b19646bdb5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency logRelease files / tiny_pytorch-0.2.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | tiny_pytorch-0.2.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
a346904e32c18e54909e2e3b9737445e4f20298531ed25abe92aa1635ab0f430
|
|
BLAKE2b-256 checksum How to use checksums |
339b0f9fb7b828703d2256bfb0c6332f3c8ffe4e12da4fbcfd62731c250a6f5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency logRelease files / tiny_pytorch-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | tiny_pytorch-0.2.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 186.2 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fc9400536616dc261f9394360b4efc84239a5e3b73146f3b42a4cbfb325d3924
|
|
BLAKE2b-256 checksum How to use checksums |
617d3bf3d9a273101d9e77fd79e298c840a99472b5a94526835e3ac5ac11df92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency logSecurity for tiny-pytorch 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for tiny_pytorch-0.2.0-cp313-cp313-musllinux_1_2_x86_64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.