NNRT is a lightweight deep learning framework built from scratch in Python.
It is designed to replicate core concepts of modern frameworks like PyTorch, including tensors, autograd, neural networks, and optimizers.
NNRT provides core deep learning components including:
- Multi dimensional Tensor support
- Autograd (automatic differentiation)
- Basic math operations
- CPU (and optional CUDA support via nnrt.cuda)
- Linear (Fully Connected)
- Conv2D
- MaxPool2D
- BatchNorm1d
- LayerNorm
- Embedding
- ReLU
- LeakyReLU
- Sigmoid
- Tanh
- GELU
- Softmax
- LogSoftmax
- Sequential API
- Module / Parameter system
- ModuleList support
- Dropout
- Flatten layer
- MSELoss
- CrossEntropyLoss
- NLLLoss
- BCELoss
- BCEWithLogitsLoss
- SGD
- Adam
- RMSProp
- StepLR
- ExponentialLR
- CosineAnnealingLR
- Model save / load
- No-grad context manager
pip install nnrtpip install nnrt[cuda11x]pip install nnrt[cuda12x]import nnrt as nn
model = nn.Sequential(
nn.Linear(784, 256),
nn.ReLU(),
nn.Linear(256, 10)
)
loss_fn = nn.CrossEntropyLoss()
optimizer = nn.Adam(model.parameters(), lr=0.001)
x = nn.randn(32, 784)
y = nn.randint(0, 10, (32,))
out = model(x)
loss = loss_fn(out, y)
loss.backward()
optimizer.step()
optimizer.zero_grad()- Learning how deep learning frameworks work internally
- Understanding autograd systems
- Experimenting with custom neural network architectures
This is an educational framework and not optimized for production-scale workloads.
If you find NNRT useful, consider giving it a star on GitHub!
