RusTorch ๐
A production-ready deep learning library in Rust with PyTorch-like API, GPU acceleration, and enterprise-grade performance
ๆฌ็ช็ฐๅขๅฏพๅฟใฎRust่ฃฝใใฃใผใใฉใผใใณใฐใฉใคใใฉใช - PyTorchใฉใคใฏใชAPIใGPUๅ ้ใใจใณใฟใผใใฉใคใบใฐใฌใผใใใใฉใผใใณใน
RusTorch is a fully functional deep learning library that leverages Rust's safety and performance, providing comprehensive tensor operations, automatic differentiation, neural network layers, transformer architectures, multi-backend GPU acceleration (CUDA/Metal/OpenCL), advanced SIMD optimizations, enterprise-grade memory management, data validation & quality assurance, and comprehensive debug & logging systems.
โจ Features
- ๐ฅ Comprehensive Tensor Operations: Math operations, broadcasting, indexing, and statistics
- ๐ค Transformer Architecture: Complete transformer implementation with multi-head attention
- ๐งฎ Matrix Decomposition: SVD, QR, eigenvalue decomposition with PyTorch compatibility
- ๐ง Automatic Differentiation: Tape-based computational graph for gradient computation
- ๐ Dynamic Execution Engine: JIT compilation and runtime optimization
- ๐๏ธ Neural Network Layers: Linear, Conv1d/2d/3d, ConvTranspose, RNN/LSTM/GRU, BatchNorm, Dropout, and more
- โก Cross-Platform Optimizations: SIMD (AVX2/SSE/NEON), platform-specific, and hardware-aware optimizations
- ๐ฎ GPU Integration: CUDA/Metal/OpenCL support with automatic device selection
- ๐ WebAssembly Support: Complete browser ML with Neural Network layers, Computer Vision, and real-time inference
- ๐ฎ WebGPU Integration: Chrome-optimized GPU acceleration with CPU fallback for cross-browser compatibility
- ๐ Model Format Support: Safetensors, ONNX inference, PyTorch state dict compatibility
- โ Production Ready: 968 tests passing, unified error handling system
- ๐ Enhanced Mathematical Functions: Complete set of mathematical functions (exp, ln, sin, cos, tan, sqrt, abs, pow)
- ๐ง Advanced Operator Overloads: Full operator support for tensors with scalar operations and in-place assignments
- ๐ Advanced Optimizers: SGD, Adam, AdamW, RMSprop, AdaGrad with learning rate schedulers
- ๐ Data Validation & Quality Assurance: Statistical analysis, anomaly detection, consistency checking, real-time monitoring
- ๐ Comprehensive Debug & Logging: Structured logging, performance profiling, memory tracking, automated alerts
For detailed features, see Features Documentation.
๐ Quick Start
Python Jupyter Lab Demo
Standard CPU Demo
Launch RusTorch with Jupyter Lab in one command:
WebGPU Accelerated Demo
Launch RusTorch with WebGPU support for browser-based GPU acceleration:
Both scripts will:
- ๐ฆ Create virtual environment automatically
- ๐ง Build RusTorch Python bindings
- ๐ Launch Jupyter Lab with demo notebook
- ๐ Open demo notebook ready to run
WebGPU Features:
- ๐ Browser-based GPU acceleration
- โก High-performance matrix operations in browser
- ๐ Automatic fallback to CPU when GPU unavailable
- ๐ฏ Chrome/Edge optimized (recommended browsers)
Installation
Add this to your Cargo.toml
:
[]
= "0.5.5"
# Optional features
[]
= ["linalg"]
= ["rustorch/linalg"] # Linear algebra operations (SVD, QR, eigenvalue)
= ["rustorch/cuda"]
= ["rustorch/metal"]
= ["rustorch/opencl"]
= ["rustorch/safetensors"]
= ["rustorch/onnx"]
= ["rustorch/wasm"] # WebAssembly support for browser ML
= ["rustorch/webgpu"] # Chrome-optimized WebGPU acceleration
# To disable linalg features (avoid OpenBLAS/LAPACK dependencies):
= { = "0.5.5", = false }
Basic Usage
use Tensor;
use ;
WebAssembly Usage
For browser-based ML applications:
import init * as rustorch from './pkg/rustorch.js';
WebGPU Acceleration (Chrome Optimized)
For Chrome browsers with WebGPU support:
import init * as rustorch from './pkg/rustorch.js';
Run examples:
# Basic functionality examples
# Machine learning examples
# Linear algebra examples (requires linalg feature)
# Mathematical functions
For more examples, see Getting Started Guide and WebAssembly Guide.
๐ Documentation
- Getting Started - Basic usage and examples
- Features - Complete feature list and specifications
- Performance - Benchmarks and optimization details
- Architecture - System design and project structure
- Examples - Comprehensive code examples
- API Documentation - Detailed API reference
WebAssembly & Browser ML
- WebAssembly Guide - Complete WASM integration and API reference
- Jupyter WASM Guide - Step-by-step Jupyter Notebook setup (ๆฅๆฌ่ช)
- Jupyter WASM Guide (English) - Step-by-step Jupyter Notebook setup
- WebGPU Integration - Chrome-optimized GPU acceleration
- Browser Compatibility - Cross-browser support matrix
- WASM Performance - Benchmarking and optimization strategies
Production & Operations
- GPU Acceleration Guide - GPU setup and usage
- Production Guide - Deployment and scaling
- Data Validation Guide - Quality assurance and validation
- Debug & Logging Guide - Comprehensive debugging tools
๐ Performance
Latest benchmark results:
Operation | Performance | Details |
---|---|---|
SVD Decomposition | ~1ms (8x8 matrix) | โ LAPACK-based |
QR Decomposition | ~24ฮผs (8x8 matrix) | โ Fast decomposition |
Eigenvalue | ~165ฮผs (8x8 matrix) | โ Symmetric matrices |
Complex FFT | 10-312ฮผs (8-64 samples) | โ Cooley-Tukey optimized |
Neural Network | 1-7s training | โ Boston housing demo |
Activation Functions | <1ฮผs | โ ReLU, Sigmoid, Tanh |
Run benchmarks:
# Basic benchmarks (no external dependencies)
# Linear algebra benchmarks (requires linalg feature)
# Quick manual benchmark
For detailed performance analysis, see Performance Documentation.
๐งช Testing
968 tests passing - Production-ready quality assurance with unified error handling system.
# Run all tests (recommended for CI/development)
# Run tests with linear algebra features
# Run doctests
# Test specific modules
๐ Production Deployment
Docker
# Production deployment
# GPU-enabled deployment
For complete deployment guide, see Production Guide.
๐ค Contributing
We welcome contributions! See areas where help is especially needed:
- ๐ฏ Special Functions Precision: Improve numerical accuracy
- โก Performance Optimization: SIMD improvements, GPU optimization
- ๐งช Testing: More comprehensive test cases
- ๐ Documentation: Examples, tutorials, improvements
- ๐ Platform Support: WebAssembly, mobile platforms
Development Setup
# Run tests
# Check formatting
# Run clippy
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.