Crate rustorch

Crate rustorch 

Source
Expand description

§RusTorch 🚀

A production-ready deep learning library in Rust with PyTorch-like API, data validation, debugging tools, and enterprise-grade reliability

RusTorch v0.5.14 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, GPU acceleration, unified error handling system, advanced memory optimization features, data validation & quality assurance, and comprehensive debug & logging systems.

§✨ Key Features

  • 🔥 Comprehensive Tensor Operations: Math operations, broadcasting, indexing, and statistics
  • 🤖 Transformer Architecture: Complete transformer implementation with multi-head attention
  • ⚡ SIMD Optimizations: AVX2/SSE4.1 vectorized operations for high performance
  • 🔄 Unified Parallel Operations: Trait-based parallel tensor operations with intelligent scheduling
  • 🎮 GPU Integration: CUDA/Metal/OpenCL support with automatic device selection
  • 💾 Advanced Memory Management: Zero-copy operations, SIMD-aligned allocation, and memory pools
  • 🧠 Automatic Differentiation: Tape-based computational graph for gradient computation
  • 🏗️ Neural Network Layers: Linear, Conv1d/2d/3d, ConvTranspose, RNN/LSTM/GRU, BatchNorm, Dropout, and more
  • 🛡️ Unified Error Handling: Single RusTorchError type with 61+ specialized helper functions and RusTorchResult<T> for cleaner APIs
  • 🔧 Safe Operations: Type-safe tensor operations with comprehensive error handling and ReLU activation
  • ⚙️ Shared Base Traits: Reusable convolution and pooling base implementations for code efficiency
  • 🌐 WebAssembly Support: Browser-compatible WASM bindings with optimized performance
  • 🔍 Data Validation & Quality Assurance: Statistical analysis, anomaly detection, consistency checking, real-time monitoring
  • 🐛 Comprehensive Debug & Logging: Structured logging, performance profiling, memory tracking, automated alerts
  • 💾 Phase 9 Serialization: Model save/load, JIT compilation, PyTorch compatibility, cross-platform format support

§🚀 Quick Start

use rustorch::prelude::*;

// 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
let c = &a + &b;  // Addition
let d = a.matmul(&b);  // Matrix multiplication

// Mathematical functions (using methods from tensor ops)
let e = a.data.mapv(|x| x.sin());  // Sine function
let f = a.data.mapv(|x| x.exp());  // Exponential function

println!("Shape: {:?}", c.shape());
println!("Result: {:?}", c.as_slice());

§🔧 Safe Operations with Error Handling

use rustorch::nn::safe_ops::SafeOps;

// Create variables safely with validation
let var = SafeOps::create_variable(vec![-1.0, 0.0, 1.0], vec![3], false).unwrap();

// Apply ReLU activation function
let relu_result = SafeOps::relu(&var).unwrap();
println!("ReLU: {:?}", relu_result.data().read().unwrap().as_array()); // [0.0, 0.0, 1.0]

// Get tensor statistics
let stats = SafeOps::get_stats(&var).unwrap();
println!("Mean: {:.2}, Std: {:.2}", stats.mean, stats.std_dev());

§🏗️ Architecture Overview

The library is organized into several key modules:

  • tensor: Core tensor operations with parallel and GPU acceleration
  • nn: Neural network layers and building blocks
    • nn::safe_ops: Safe tensor operations with error handling and ReLU activation
    • nn::conv_base: Shared base traits for convolution and pooling layers
  • autograd: Automatic differentiation system
  • vision: Computer vision utilities including transforms and datasets
  • optim: Optimization algorithms (SGD, Adam, etc.)
  • gpu: GPU acceleration support (CUDA, Metal, OpenCL)
  • simd: SIMD vectorized operations
  • wasm: WebAssembly bindings for browser deployment
  • memory: Advanced memory management and pooling
  • data: Phase 5 data loading API with modern Dataset and DataLoader traits

§🔄 Parallel Operations

RusTorch provides a unified trait-based system for parallel tensor operations:

use rustorch::tensor::{Tensor, parallel_traits::*};

let tensor1 = Tensor::<f32>::ones(&[4, 4]);  // 2D matrices for simplicity
let tensor2 = Tensor::<f32>::ones(&[4, 4]);

// Basic tensor operations
let result = &tensor1 + &tensor2; // Element-wise addition

// Matrix multiplication
let matmul_result = tensor1.matmul(&tensor2);

// Basic reduction operations
let sum = tensor1.sum();

§🎮 GPU Integration

Seamless GPU acceleration with automatic device selection:

use rustorch::tensor::Tensor;

let tensor1 = Tensor::<f32>::ones(&[4, 4]);
let tensor2 = Tensor::<f32>::ones(&[4, 4]);

// GPU-accelerated operations (when available)
let result = &tensor1 + &tensor2;  // Basic tensor operations

§💾 Memory Optimization

Advanced memory management for optimal performance:

use rustorch::tensor::Tensor;

let tensor = Tensor::<f32>::ones(&[4, 4]);

// Basic tensor operations
let result = &tensor * &tensor; // Element-wise multiplication

§🌐 WebAssembly Integration

Run neural networks directly in browsers with optimized WASM bindings:

// Browser usage (JavaScript)
import init, * as rustorch from './pkg/rustorch.js';

await init();

// Create and manipulate tensors
const tensor1 = rustorch.WasmTensor.ones([2, 3]);
const tensor2 = rustorch.WasmTensor.random([2, 3]);
const sum = tensor1.add(tensor2);

// Neural network inference
const model = new rustorch.WasmModel();
model.add_linear(10, 5, true);
model.add_relu();

const input = rustorch.WasmTensor.random([1, 10]);
const output = model.forward(input);

console.log('Output:', output.data());

Modules§

amp
Automatic Mixed Precision (AMP) training support 自動混合精度(AMP)学習サポート Automatic Mixed Precision (AMP) training support 自動混合精度学習のサポート
autograd
Automatic differentiation module 自動微分モジュール
backends
Unified compute backend abstraction layer
統一計算バックエンド抽象化レイヤー Unified compute backend abstraction for RusTorch v0.4.0 RusTorch v0.4.0の統一計算バックエンド抽象化
common
Common utilities and shared functionality 共通ユーティリティと共有機能 Common utilities and shared functionality for RusTorch RusTorchの共通ユーティリティと共有機能
convert
PyTorch to RusTorch conversion system PyTorchからRusTorch変換システム PyTorch to RusTorch conversion module PyTorchからRusTorchへの変換モジュール
data
Data loading and processing utilities (Phase 5 API) データ読み込みと処理のユーティリティ(フェーズ5 API)
debug
Debug and logging system デバッグ・ログシステム RusTorch Debug & Logging Framework
distributed
Distributed training support for multi-GPU and multi-machine training マルチGPUおよびマルチマシン学習用分散学習サポート Distributed training support for RusTorch RusTorchの分散学習サポート
distributions
Statistical distributions module providing PyTorch-compatible probability distributions PyTorch互換の確率分布を提供する統計分布モジュール
dtype
Data types for tensors テンソル用データ型
error
Unified error handling system 統一エラーハンドリングシステム Unified error handling system for RusTorch RusTorch用統一エラーハンドリングシステム
execution
Dynamic execution engine for runtime graph optimization 実行時グラフ最適化のための動的実行エンジン Dynamic execution engine for runtime graph optimization 実行時グラフ最適化のための動的実行エンジン
formats
Model format support and conversion utilities モデル形式サポートと変換ユーティリティ Model format support for RusTorch RusTorchのモデルフォーマットサポート
gpu
GPU acceleration support (CUDA, Metal, OpenCL) GPU加速サポート(CUDA、Metal、OpenCL)
linalg
High-performance linear algebra with BLAS integration BLAS統合による高性能線形代数 Linear Algebra Module with High-Performance Optimizations 高性能最適化付き線形代数モジュール
memory
Memory management and pooling utilities メモリ管理とプーリングユーティリティ Enhanced Memory Management System for RusTorch RusTorch用の高度メモリ管理システム
model_import
Model import functionality for PyTorch and ONNX models PyTorchとONNXモデルのインポート機能
models
Pre-built models and architectures 事前構築モデルとアーキテクチャ 機械学習モデルアーキテクチャ Machine learning model architectures
nn
Neural network layers and building blocks ニューラルネットワークレイヤーと構成要素 ニューラルネットワークモジュールの定義 Neural network module definitions.
optim
Optimization algorithms 最適化アルゴリズム
optimization
Cross-platform optimization module クロスプラットフォーム最適化モジュール Cross-platform optimization module クロスプラットフォーム最適化モジュール
parallel
Parallel processing utilities 並列処理ユーティリティ
prelude
Re-exports of commonly used items
profiler
Performance profiler パフォーマンスプロファイラー Performance Profiling & Benchmarking Framework (Phase 1 Component 5) パフォーマンスプロファイリング・ベンチマーキングフレームワーク(フェーズ1コンポーネント5)
serialization
Serialization and model I/O system (Phase 9) シリアライゼーション・モデルI/Oシステム(フェーズ9) Serialization system for Phase 9 フェーズ9用シリアライゼーションシステム
simd
SIMD vectorized operations for performance optimization パフォーマンス最適化のためのSIMDベクトル化操作
special
Special mathematical functions (gamma, Bessel, error functions) 特殊数学関数(ガンマ、ベッセル、誤差関数) Special mathematical functions module 特殊数学関数モジュール
tensor
Tensor operations and data structures テンソル操作とデータ構造
tensorboard
TensorBoard integration TensorBoard統合 TensorBoard integration for RusTorch RusTorch用TensorBoard統合
training
Training loop abstractions and utilities
学習ループの抽象化とユーティリティ
utils
Utility functions ユーティリティ関数 Utility functions and types
validation
Data validation and quality assurance system データ検証・品質保証システム Data Validation & Quality Assurance Framework (Phase 1 Component 6) データ検証・品質保証フレームワーク(フェーズ1コンポーネント6)
vision
Computer vision module providing image transforms, data augmentation, and built-in datasets 画像変換、データ拡張、組み込みデータセットを提供するコンピュータビジョンモジュール Computer Vision utilities for RusTorch RusTorch用コンピュータビジョンユーティリティ
visualization
Visualization tools for plots, graphs, and data analysis プロット、グラフ、データ解析用の可視化ツール
wasm
WebAssembly support and bindings WebAssemblyサポートとバインディング WebAssembly bindings for RusTorch RusTorch用WebAssemblyバインディング

Macros§

autocast_op
Macro for autocast-aware operations
diagnostic_context
Macro for easy diagnostic context creation
distributed_error
Macro for creating distributed errors easily 分散エラーを簡単に作成するためのマクロ
error_context
Macro for creating error context with file location ファイル位置付きのエラーコンテキストを作成するマクロ
gpu_error
Macro for creating GPU errors easily GPUエラーを簡単に作成するためのマクロ
impl_wasm_analyzer
Macro for implementing analyzer trait
impl_wasm_operation
Convenience macro for implementing basic WasmOperation
impl_wasm_standard
Macro for implementing standard WASM operation boilerplate
impl_wasm_transform
Macro for implementing transform trait with validation
impl_wasm_versioned
Convenience macro for implementing WasmVersioned
log_structured
Convenience macro for structured logging
perf_timer
Macro for performance timing
profile
Profile a code block コードブロックをプロファイル
profile_fn
Profile a function 関数をプロファイル
shape_ops
Convenience macro for chaining shape operations 形状操作連鎖の便利マクロ
tb_log
Macro for easy TensorBoard logging 簡単なTensorBoardログ用マクロ
tensor_error
Helper macros for error creation エラー作成用ヘルパーマクロ Macro for creating tensor errors easily テンソルエラーを簡単に作成するためのマクロ
time_block
Macro for timed code blocks
track_allocation
Convenience macro for tracking allocations
track_deallocation
wasm_error
Macro for quick error generation
with_context
Macro for adding context to results 結果にコンテキストを追加するマクロ