Advanced Decentralized Tensor Library with Next-Gen Autograd Engine
Omega Tensor is a custom-built tensor computation library featuring a revolutionary autograd engine, decentralized tensor storage, and post-autograd optimizations for high-performance deep learning.
- Unique ID-based tensor registry for distributed computation
- Efficient memory management with version tracking
- Support for distributed tensor operations across nodes
- Automatic differentiation with dynamic computational graph
- Topological sorting for efficient gradient computation
- Support for complex gradient flows and broadcasting
- Custom Function API for extending with new differentiable operations
- Gradient Checkpointing: Trade computation for memory by recomputing activations during backward pass
- Lazy Evaluation: Delay computation and automatically fuse operations for efficiency
- Distributed Autograd: Coordinate gradient computation across distributed nodes
- Modular
nn.Modulesystem similar to PyTorch - Common layers: Linear, Conv2d, BatchNorm, Dropout, etc.
- Activation functions: ReLU, Sigmoid, Tanh with automatic gradient support
- Loss functions: MSE, CrossEntropy
- SGD with momentum
- Adam (Adaptive Moment Estimation)
- AdamW (Adam with decoupled weight decay)
- RMSprop
pip install -e .Or install with development dependencies:
pip install -e ".[dev]"from omega_tensor import Tensor
# Create tensors
x = Tensor([1.0, 2.0, 3.0], requires_grad=True)
y = Tensor([4.0, 5.0, 6.0], requires_grad=True)
# Perform operations
z = x + y
w = z * 2
loss = w.sum()
# Compute gradients automatically
loss.backward()
print(f"x.grad = {x.grad}") # Gradients computed!from omega_tensor import Tensor, nn, optim
# Define a neural network
model = nn.Sequential(
nn.Linear(10, 20),
nn.ReLU(),
nn.Linear(20, 1)
)
# Create optimizer
optimizer = optim.Adam(model.parameters(), lr=0.01)
# Training loop
for epoch in range(100):
# Forward pass
predictions = model(X)
loss = ((predictions - y) ** 2).mean()
# Backward pass
optimizer.zero_grad()
loss.backward()
# Update weights
optimizer.step()Omega Tensor supports a wide range of operations with automatic gradient computation:
Arithmetic Operations:
- Addition, subtraction, multiplication, division
- Power, negation
- Broadcasting support
Matrix Operations:
- Matrix multiplication (
@) - Transpose, reshape
Reduction Operations:
- Sum, mean (with axis support)
Activation Functions:
- ReLU, Sigmoid, Tanh
- Exponential, logarithm
The autograd engine automatically tracks operations and computes gradients:
x = Tensor([2.0], requires_grad=True)
y = x ** 2 # y = 4
y.backward()
print(x.grad) # dy/dx = 2x = 4.0The engine:
- Builds a computational graph during forward pass
- Uses topological sorting for efficient traversal
- Applies the chain rule in reverse order
- Handles broadcasting and shape changes correctly
Each tensor gets a unique UUID and is registered in a decentralized storage system:
t = Tensor([1, 2, 3])
print(t.id) # Unique identifier
print(Tensor._tensor_registry[t.id]) # Access from registryThis enables:
- Distributed computation across nodes
- Efficient tensor lookup and sharing
- Version tracking for tensor updates
Save memory by recomputing activations during backward pass:
from omega_tensor.autograd import checkpoint
def expensive_function(x):
return x.exp().tanh()
# Only stores input, recomputes during backward
output = checkpoint(expensive_function, x)Operations are automatically fused for efficiency:
from omega_tensor.autograd import LazyEvaluation
lazy = LazyEvaluation()
# Operations are queued and fused
lazy.add_operation('add', x, y)
lazy.add_operation('mul', result, 2)
lazy.evaluate() # Executes as single fused kernelCoordinate gradient computation across distributed nodes:
from omega_tensor.autograd import enable_distributed
x = Tensor([1, 2, 3], requires_grad=True)
x = enable_distributed(x)
# Gradient computation is now distributedSee examples.py for comprehensive examples including:
- Basic operations and autograd
- Matrix multiplication
- Neural network training
- Activation functions
- Decentralized storage
- Computational graphs
- Broadcasting
- Optimizer comparison
Run examples:
python examples.pyRun the test suite:
python tests.pyOr with pytest:
pip install pytest
pytest tests.py -vomega_tensor/
βββ tensor.py # Core Tensor class with operations
βββ autograd.py # Autograd engine and advanced features
βββ nn.py # Neural network modules
βββ optim.py # Optimization algorithms
The Tensor class is the fundamental building block:
- Wraps numpy arrays for computation
- Tracks computational graph for autograd
- Unique ID for decentralized storage
- Lazy evaluation support
The autograd engine provides:
- Dynamic computational graph construction
- Reverse-mode automatic differentiation
- Custom backward functions for each operation
- Efficient topological sorting
- Simplicity: Clean, readable code that's easy to understand and extend
- Modularity: Separate concerns with clear interfaces
- Efficiency: Optimized operations with numpy backend
- Flexibility: Easy to add custom operations and layers
- Innovation: Revolutionary features like gradient checkpointing and lazy evaluation
Contributions are welcome! Areas for improvement:
- Additional optimizers (LAMB, RAdam, etc.)
- More neural network layers
- GPU support with CuPy
- Distributed training features
- Performance optimizations
- Documentation improvements
MIT License - feel free to use in your projects!
Inspired by PyTorch, TensorFlow, and JAX, but built from scratch with revolutionary features for next-generation deep learning.
Built with β€οΈ by MASSIVEMAGNETICS