rustorch 0.5.0

Production-ready PyTorch-compatible deep learning library in Rust with special mathematical functions (gamma, Bessel, error functions), statistical distributions, Fourier transforms (FFT/RFFT), matrix decomposition (SVD/QR/LU/eigenvalue), automatic differentiation, neural networks, computer vision transforms, complete GPU acceleration (CUDA/Metal/OpenCL), SIMD optimizations, parallel processing, WebAssembly browser support, comprehensive distributed learning support, and performance validation
rustorch-0.5.0 has been yanked.
Visit the last successful build: rustorch-0.6.29

RusTorch 🚀

Crates.io Documentation License Tests Build

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, and enterprise-grade memory management features.

✨ Features

  • 🔥 Comprehensive Tensor Operations: Math operations, broadcasting, indexing, and statistics
  • 🤖 Transformer Architecture: Complete transformer implementation with multi-head attention
  • 🧮 Matrix Decomposition: Complete SVD, QR, LU decomposition and eigenvalue solver with PyTorch compatibility
  • 🧠 Automatic Differentiation: Tape-based computational graph for gradient computation
  • 🏗️ Neural Network Layers: Linear, Conv1d/2d/3d, ConvTranspose, RNN/LSTM/GRU, BatchNorm, Dropout, and more
  • SIMD Optimizations: AVX2/SSE4.1 vectorized operations for high performance
  • 🎮 GPU Integration: CUDA/Metal/OpenCL support with automatic device selection
  • 🌐 WebAssembly Support: Browser-compatible WASM bindings for client-side ML
  • 📁 Model Format Support: Safetensors, ONNX inference, PyTorch state dict compatibility
  • Production Ready: 739 tests passing (99.7% success rate), 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

For detailed features, see Features Documentation.

🚀 Quick Start

Installation

Add this to your Cargo.toml:

[dependencies]
rustorch = "0.5.0"

# Optional features
[features]
default = ["linalg"]
linalg = ["rustorch/linalg"]           # Linear algebra operations (SVD, QR, LU, eigenvalue)
cuda = ["rustorch/cuda"]
metal = ["rustorch/metal"] 
opencl = ["rustorch/opencl"]
safetensors = ["rustorch/safetensors"]
onnx = ["rustorch/onnx"]

# To disable linalg features (avoid OpenBLAS/LAPACK dependencies):
rustorch = { version = "0.5.0", default-features = false }

Basic Usage

use rustorch::tensor::Tensor;
use rustorch::optim::{SGD, WarmupScheduler, OneCycleLR, AnnealStrategy};

fn main() {
    // Create tensors
    let a = Tensor::from_vec(vec![1.0f32, 2.0, 3.0, 4.0], vec![2, 2]);
    let b = Tensor::from_vec(vec![5.0f32, 6.0, 7.0, 8.0], vec![2, 2]);
    
    // Basic operations with operator overloads
    let c = &a + &b;  // Element-wise addition
    let d = &a - &b;  // Element-wise subtraction
    let e = &a * &b;  // Element-wise multiplication
    let f = &a / &b;  // Element-wise division
    
    // Scalar operations
    let g = &a + 10.0;  // Add scalar to all elements
    let h = &a * 2.0;   // Multiply by scalar
    
    // Mathematical functions
    let exp_result = a.exp();   // Exponential function
    let ln_result = a.ln();     // Natural logarithm
    let sin_result = a.sin();   // Sine function
    let sqrt_result = a.sqrt(); // Square root
    
    // Matrix operations
    let matmul_result = a.matmul(&b);  // Matrix multiplication
    
    // Advanced optimizers with learning rate scheduling
    let optimizer = SGD::new(0.01);
    let mut scheduler = WarmupScheduler::new(optimizer, 0.1, 5); // Warmup to 0.1 over 5 epochs
    
    // One-cycle learning rate policy
    let optimizer2 = SGD::new(0.01);
    let mut one_cycle = OneCycleLR::new(optimizer2, 1.0, 100, 0.3, AnnealStrategy::Cos);
    
    println!("Shape: {:?}", c.shape());
    println!("Result: {:?}", c.as_slice());
}

For more examples, see Getting Started Guide.

📚 Documentation

📊 Performance

Latest benchmark results:

Operation Performance Details
Tensor Addition 34K - 2.3M ops/sec ✅ Broadcasting support
Tensor Sum 52M+ ops/sec ✅ Consistently high performance
Matrix Multiplication 0.71 - 0.77 GFLOPS ✅ Stable scaling
Neural Network Inference 15 - 60 inferences/sec ✅ Batch processing

For detailed performance analysis, see Performance Documentation.

⚠️ 後方互換性について (Backward Compatibility)

v0.5.0での重要な変更 / Important Changes in v0.5.0:

この版では、メソッド統合リファクタリングにより、従来の_v2バージョンと古いバージョンのメソッドが統一されました。以下の点にご注意ください:

  • メソッド名の変更: _v2接尾辞が削除され、最適化版が標準になりました
  • 統一されたAPI: 旧バージョンと_v2バージョンが単一の最適化版に統合されました
  • 移行の必要性: 旧APIを使用している場合は、新しいメソッド名への移行が必要です

詳細な移行ガイドについては、CHANGELOG.mdのv0.5.0セクションをご参照ください。

🧪 Testing

All 739 tests passing - Production-ready quality assurance with unified error handling system.

# Run all tests
cargo test

# Run with release optimizations
cargo test --release

🚀 Production Deployment

Docker

# Production deployment
docker build -t rustorch:latest .
docker run -it rustorch:latest

# GPU-enabled deployment
docker build -f Dockerfile.gpu -t rustorch:gpu .
docker run --gpus all -it rustorch:gpu

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

git clone https://github.com/JunSuzukiJapan/rustorch.git
cd rustorch

# Run tests
cargo test --all-features

# Check formatting
cargo fmt --check

# Run clippy
cargo clippy --all-targets --all-features

License

Licensed under either of:

at your option.