RFANN ๐ง โก
Rust Fast Artificial Neural Network - A modern, high-performance neural network library built in pure Rust
RFANN is a feature-rich, GPU-accelerated neural network library inspired by the original FANN (Fast Artificial Neural Network) but rebuilt from the ground up in Rust. It combines classical neural network algorithms with modern GPU acceleration, WebAssembly support, and professional-grade memory management.
๐ Key Features
โก High Performance
- WebGPU Acceleration: Native GPU compute support for training and inference
- WASM + WebGPU: Full neural networks running in browsers with GPU acceleration
- SIMD Optimizations: Vectorized CPU operations for enhanced performance
- Multi-threaded Training: Parallel processing with automatic CPU utilization
๐ง Advanced Neural Networks
- 18+ Activation Functions: From standard (ReLU, Sigmoid) to specialized (Elliott, Gaussian)
- Cascade Correlation: Unique dynamic topology optimization that grows networks during training
- Multiple Training Algorithms: Backprop, RProp, Quickprop, Adam, AdamW
- Generic Float Support: Works with f32, f64, and custom numeric types
๐ Cross-Platform Deployment
- Native: Linux, macOS, Windows with full GPU support
- WebAssembly: Complete library functionality in browsers
- no_std Support: Embedded and resource-constrained environments
- Automatic Fallback: Seamless CPU/GPU backend switching
๐ง Professional Features
- Advanced Memory Management: 5-tier buffer pooling with pressure monitoring
- Circuit Breaker Protection: Predictive analytics preventing memory exhaustion
- Multiple I/O Formats: FANN, JSON, Binary, with compression support
- Real-time Monitoring: Performance metrics and auto-tuning
๐ฆ Installation
Add to your Cargo.toml:
[]
= "0.1"
# For GPU acceleration
= { = "0.1", = ["gpu"] }
# For WebAssembly
= { = "0.1", = ["wasm"] }
# For browser GPU acceleration
= { = "0.1", = ["wasm-gpu"] }
๐ฅ Quick Start
Basic Neural Network
use ;
use ;
// Create a 3-layer network: 2 inputs, 3 hidden, 1 output
let mut network = new
.input_layer
.hidden_layer
.output_layer
.build?;
// Prepare training data
let training_data = new?;
// Train the network
let mut trainer = new?;
trainer.train?;
// Make predictions
let output = network.run?;
println!;
GPU-Accelerated Training
use ;
use ;
// Create network with GPU support
let mut network = new
.input_layer // MNIST-sized input
.hidden_layer
.hidden_layer
.output_layer
.enable_gpu
.build?;
// GPU-accelerated batch training
let mut trainer = new?; // batch size 32
trainer.train.await?;
WebAssembly Deployment
use ;
use *;
Cascade Correlation (Dynamic Networks)
use ;
use CascadeCorrelation;
// Start with minimal network
let mut network = new
.input_layer
.output_layer
.build?;
// Cascade correlation automatically adds hidden neurons
let mut cascade = new?;
cascade.train?; // Max 50 hidden neurons
println!;
๐ฏ Training Algorithms
Classical Algorithms
- Backpropagation: Incremental and batch variants
- RProp: Resilient backpropagation with adaptive learning rates
- Quickprop: Quasi-Newton method for faster convergence
Modern Optimizers
- Adam: Adaptive moment estimation
- AdamW: Adam with decoupled weight decay
Unique Features
- Cascade Correlation: Dynamic topology optimization
- GPU Acceleration: All algorithms support GPU training
- Automatic Tuning: Learning rate adaptation and momentum optimization
๐ Use Cases
๐ฎ Real-Time Applications
- Game AI with GPU-accelerated inference
- Interactive web applications with WASM deployment
- Real-time signal processing and control systems
๐ฌ Research & Development
- Algorithm comparison and benchmarking
- Custom activation function development
- Neural architecture search with cascade correlation
๐ญ Production Systems
- High-throughput batch inference
- Edge deployment with no_std support
- Microservice architectures with minimal dependencies
๐ Education & Prototyping
- Learning neural network fundamentals
- Rapid prototyping with fluent API
- Network visualization and analysis
๐ Performance
RFANN delivers exceptional performance across different deployment scenarios:
Real Benchmark Results (Apple M2 Max)
๐งช GPU Training with Validation (50โ100โ50โ10 network, 800 samples)
โข CPU Training: 1.67s (0.025s/epoch)
โข GPU Training: 0.72s (0.012s/epoch)
โข Speedup: 2.32x with identical convergence
Performance Characteristics
- GPU Acceleration: 2-10x speedup on Apple Silicon, up to 100x on discrete GPUs
- WASM Performance: Near-native speeds in browsers with WebGPU support
- Memory Efficiency: Advanced 5-tier pooling reduces allocation overhead by 80%
- Batch Processing: Optimized matrix operations for high-throughput inference
- Early Stopping: Intelligent validation monitoring prevents overfitting
๐๏ธ Feature Flags
Customize RFANN for your specific needs:
[]
= "0.1"
= false
= [
"std", # Standard library support
"serde", # Serialization support
"parallel", # Multi-threading
"gpu", # GPU acceleration
"wasm", # WebAssembly support
"wasm-gpu", # WASM + WebGPU
"simd", # SIMD optimizations
"compression" # Gzip compression
]
๐ Documentation
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Run tests
# Run with GPU features
# Run benchmarks
# Test WASM build
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Inspired by the original FANN library
- Built with wgpu for cross-platform GPU compute
- Powered by the Rust ecosystem's excellent crates
Ready to supercharge your neural networks? Get started with RFANN today! ๐