A learner-friendly, DIY-ready deep learning framework
designed to reveal neural network internals and facilitate custom hardware experimentation.
๐ Tutorials โข ๐ Docs โข ๐ Quick Start โข ๐ก Why TensorPlay?
TensorPlay is built on the philosophy of transparency, allowing learners to trace every operation from Python to C++ core without getting lost in abstraction layers.
|
Clean, readable implementations that let you dive deep into the logic of every operatorโfrom autograd to memory management. No black boxes. |
Simplified CPU and CUDA backend implementations serve as the perfect playground for experimenting with custom hardware kernels and understanding parallel computing principles. |
|
Through the decoupled TPX engine, computation graphs are built explicitly, making it easy to understand the magic of backpropagation and simple to extend. |
Highly extensible design allows you to prototype new layer types, optimizers, and storage formats with minimal boilerplate code. |
Choose your installation method:
pip install tensorplay --upgrade# CUDA 13.0
pip install tensorplay --index-url https://download.tensorplay.cn/whl/cu130/Note: Ensure your Python version matches the wheel tags (e.g.,
cp310for Python 3.10). If you encounter connection issues, please verify access to the above URLs.
git clone https://github.com/bluemoon-o2/TensorPlay.git
cd TensorPlay
pip install -e .TensorPlay is built upon four decoupled core libraries that can work together or independently:
| Library | Core Responsibility | Design Philosophy |
|---|---|---|
| P10 | ๐ง Core Engine | Provides clean, readable memory management and foundational tensor kernel implementationsโthe cornerstone of the computation engine |
| TPX | ๐ Autograd | Explicit automatic differentiation layer that lets you understand or modify how computation graphs are built, completely transparent |
| Stax | โก JIT & Optimization | Experiment with operator fusion and static graph capture in a simplified environmentโa pure optimization playground |
| NN | ๐งฉ High-level API | PyTorch-compatible modular business layer; components like Linear/Conv2d serve as blueprints for custom layers |
- Full Autograd: Automatic gradient computation based on
requires_grad, fully aligned with PyTorch behavior - Broadcasting: NumPy-compatible tensor broadcasting mechanisms
- Activations: ReLU, Sigmoid, Tanh, Softmax, GELU, and other common activation functions
- Device Management: Seamless CPU/CUDA switching with explicit memory location control
- Linear/Dense: Fully connected layers with weight initialization strategies
- Conv2d: 2D convolutional layers for understanding parameter calculation and receptive fields
- Module System: Inherit from
tp.nn.Modulefor automatic parameter registration and architecture visualization - Loss Functions: MSE, NLL, CrossEntropy, SSE, etc.
- Optimizers: SGD, Adam, AdamW with learning rate scheduling and weight decay support
- DataLoader: Multi-worker batch processing, prefetching, and automatic shuffling
- Early Stopping: Built-in early stopping callback to prevent overfitting
Follow our structured tutorials to master deep learning principles from scratch:
- Linear Regression from Scratch - Understand
requires_gradand backpropagation fundamentals - MNIST CNN Image Classification - Build your first neural network using
Conv2d,MaxPool, andDataLoader
- Custom Datasets & Transforms - Master the
Datasetclass and data preprocessing pipelines - Model Saving & Loading - Use
tp.save()/tp.load()andstate_dictto manage training states
๐ View full tutorials: tutorials
import tensorplay as tp
# Create trainable tensors
x = tp.Tensor([[1.0, 2.0], [3.0, 4.0]], requires_grad=True)
y = tp.Tensor([[5.0, 6.0], [7.0, 8.0]], requires_grad=True)
# Forward pass + Backward pass
z = x.matmul(y) + tp.ones_like(x)
loss = z.sum()
loss.backward()
# View gradients (consistent with PyTorch behavior)
print(x.grad) # [[6., 6.], [6., 6.]]import tensorplay as tp
from tensorplay.nn import Module, Linear, ReLU, Sigmoid
class MLP(Module):
def __init__(self, input_dim: int, hidden_dim: int, output_dim: int):
super().__init__()
self.fc1 = Linear(input_dim, hidden_dim)
self.relu = ReLU()
self.fc2 = Linear(hidden_dim, output_dim)
self.sigmoid = Sigmoid()
def forward(self, x: tp.Tensor) -> tp.Tensor:
x = self.relu(self.fc1(x))
return self.sigmoid(self.fc2(x))
# Initialize and view structure
model = MLP(10, 32, 1)
print(model) # Auto-generated architecture visualizationfrom tensorplay.data import DataLoader, TensorDataset
# Prepare data
train_data = TensorDataset(tp.randn(100, 10), tp.randn(100, 1))
train_loader = DataLoader(dataset=train_data, batch_size=8, shuffle=True)
# Training iteration (API almost identical to PyTorch)
for batch_x, batch_y in train_loader:
predictions = model(batch_x)
# ... compute loss and backpropagateWe provide detailed performance comparisons on standard datasets, demonstrating TensorPlay's efficiency in small-scale experiments. View the complete Benchmark Report.
This project is licensed under the Apache 2.0 License.
We welcome contributions in all forms! Whether it's bug fixes, documentation improvements, or new feature suggestions.

