DLpy is a PyTorch-like deep learning framework implemented in Python, featuring automatic differentiation through dynamic computation graphs. It provides a clean and educational implementation of core deep learning components while maintaining good performance.
- Automatic Differentiation: DAG-based autograd system supporting dynamic computational graphs
- Neural Network Components:
- Basic layers (Linear, Conv2D, BatchNorm, LayerNorm)
- Recurrent layers (LSTM, GRU)
- Various activation functions
- Advanced pooling and normalization layers
- Optimizers:
- SGD with momentum
- Adam
- RMSprop
- AdaGrad
- AdaDelta
- AdaMax
- Data Handling:
- DataLoader with customizable sampling
- Dataset abstractions
- Batch processing utilities
pip install -e .import dlpy
from dlpy.nn import Linear
from dlpy.optim import Adam
# Create a simple neural network
class SimpleNet(dlpy.Module):
def __init__(self):
super().__init__()
self.fc1 = Linear(10, 5)
self.fc2 = Linear(5, 1)
def forward(self, x):
x = self.fc1(x)
x = x.relu()
return self.fc2(x)
# Create model and optimizer
model = SimpleNet()
optimizer = Adam(model.parameters(), lr=0.01)
# Training loop
for epoch in range(num_epochs):
for batch_x, batch_y in dataloader:
# Forward pass
output = model(batch_x)
loss = ((output - batch_y) ** 2).mean()
# Backward pass
optimizer.zero_grad()
loss.backward()
optimizer.step()- NumPy >= 1.20.0
- Python >= 3.8
Detailed documentation is available in the docstrings and code comments.
Key components:
core/: Core tensor and autograd functionalitynn/: Neural network layers and utilitiesoptim/: Optimization algorithmsdata/: Data loading and processing utilities
Run the test suite with:
pytest tests/Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This implementation is inspired by PyTorch and serves both as a learning tool and a lightweight deep learning framework.