Skip to main content

Lightweight native deep learning framework with PyTorch-style API

Project description

Texor - Native Deep Learning Framework

Python License Version

Texor is a lightweight, native deep learning framework built from scratch in Python. It provides a PyTorch-style API without the overhead of large ML frameworks like TensorFlow or PyTorch.

🚀 Key Features

  • 🎯 Native Implementation: 100% Python/NumPy/Numba - no TensorFlow or PyTorch dependencies
  • ⚡ Lightweight: ~260MB total size vs ~4GB for TensorFlow + PyTorch
  • 🧠 Complete ML Stack: Automatic differentiation, neural networks, optimizers
  • 🔧 PyTorch-style API: Familiar interface for ML practitioners
  • ⚡ JIT Compilation: Numba-optimized operations for performance
  • 🖥️ GPU Ready: Optional CUDA support via CuPy
  • 📦 Easy Installation: Simple pip install with minimal dependencies

🏗️ Architecture

texor/
├── core/           # Tensor operations, autograd, backend
├── nn/             # Neural network layers and models
├── optim/          # Optimizers (SGD, Adam, RMSprop)
├── data/           # Dataset utilities and data loaders
└── cli/            # Command-line interface

📦 Installation

# Basic installation
pip install numpy numba

# For GPU support (optional)
pip install cupy

# Install Texor
git clone https://github.com/letho1608/texor
cd texor
pip install -e .

🔥 Quick Start

Basic Tensor Operations

import texor
from texor.core import Tensor, randn

# Create tensors
x = randn((3, 4))
y = randn((4, 2))

# Matrix operations with autograd
z = x @ y
z.backward()
print(x.grad)  # Gradients computed automatically

Neural Networks

from texor.nn import Sequential, Linear, ReLU
from texor.nn.loss import MSELoss
from texor.optim import Adam

# Define model
model = Sequential([
    Linear(784, 128),
    ReLU(),
    Linear(128, 64), 
    ReLU(),
    Linear(64, 10)
])

# Setup training
optimizer = Adam(model.parameters(), lr=0.001)
criterion = MSELoss()

# Training loop
for epoch in range(epochs):
    # Forward pass
    predictions = model(x_train)
    loss = criterion(predictions, y_train)
    
    # Backward pass
    loss.backward()
    optimizer.step()
    optimizer.zero_grad()

High-level API

# Keras-style high-level API
model.compile(optimizer='adam', loss='mse')
model.fit(x_train, y_train, epochs=10, batch_size=32)

🧪 Complete Example

from texor.core import randn
from texor.nn import Sequential, Linear, ReLU
from texor.nn.loss import CrossEntropyLoss
from texor.optim import Adam

# Generate sample data
x_train = randn((1000, 20))
y_train = randn((1000, 10))

# Create model
model = Sequential([
    Linear(20, 50),
    ReLU(),
    Linear(50, 10)
])

# Setup training
optimizer = Adam(model.parameters())
criterion = CrossEntropyLoss()

# Train
for epoch in range(50):
    pred = model(x_train)
    loss = criterion(pred, y_train)
    
    loss.backward()
    optimizer.step()
    optimizer.zero_grad()
    
    if epoch % 10 == 0:
        print(f'Epoch {epoch}, Loss: {loss.data.item():.4f}')

🛠️ Available Components

Core

  • Tensor: N-dimensional arrays with automatic differentiation
  • Operations: Matrix multiplication, element-wise ops, reshaping
  • Backend: CPU/GPU abstraction with device management

Neural Networks

  • Layers: Linear, Conv2D, MaxPool2D, BatchNorm2D, Dropout
  • Activations: ReLU, Sigmoid, Tanh, ELU, GELU
  • Models: Sequential container for layer composition

Loss Functions

  • MSELoss, CrossEntropyLoss, BCELoss
  • L1Loss, HuberLoss, SmoothL1Loss, KLDivLoss

Optimizers

  • SGD, Adam, RMSprop, AdamW, Adadelta
  • Learning rate scheduling and momentum support

🎯 Performance Comparison

Framework Size Dependencies GPU Support Installation Time
Texor ~260MB 3 packages ✅ (CuPy) < 1 min
TensorFlow ~2.1GB 50+ packages 5-10 min
PyTorch ~1.9GB 30+ packages 3-7 min

🔧 Command Line Interface

# Get framework information
python -m texor.cli.main info

# Check dependencies
python -m texor.cli.main check

# List available modules
python -m texor.cli.main list

🧪 Testing

# Run all tests
python -m pytest tests/ -v

# Run specific test category
python -m pytest tests/test_tensor.py -v
python -m pytest tests/test_model.py -v

🎯 Use Cases

✅ Great For:

  • Rapid Prototyping: Quick ML experiments
  • Educational Projects: Learning ML algorithms
  • Edge Deployment: Resource-constrained environments
  • Custom Research: Need for framework modifications
  • Lightweight Applications: Minimal dependency requirements

⚠️ Consider Alternatives For:

  • Large-scale distributed training
  • Production systems requiring extensive ecosystem
  • Complex pre-trained models from model zoos
  • Heavy computer vision pipelines

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by PyTorch's elegant API design
  • Built on the shoulders of NumPy and Numba
  • Community feedback and contributions

Made with ❤️ for the ML community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

texor-0.1.1.tar.gz (52.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

texor-0.1.1-py3-none-any.whl (48.7 kB view details)

Uploaded Python 3

File details

Details for the file texor-0.1.1.tar.gz.

File metadata

  • Download URL: texor-0.1.1.tar.gz
  • Upload date:
  • Size: 52.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for texor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bef9416f064dea54084d8b2dfd0dfdeb153fcb3cf51d8d6d5d05fe7e1318d10e
MD5 d683c9ed9a5249b870e6a040cb62a779
BLAKE2b-256 691b122a8e2f2bcdcf36dcff9a0a750cc629c0b1cc09a68bf82524ac4512c3e0

See more details on using hashes here.

File details

Details for the file texor-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: texor-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 48.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for texor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68e79a483330acbd92fb4b58748b5fb3d979b035359b460683e20b57d8250978
MD5 efcbf4e2cccea000ed6c21e2d6e2eba6
BLAKE2b-256 e1e29d73fd441afebac103eb07aef6895e53237d948b708444109a1cf5ee995a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page