Welcome to ML Algorithms in Rust, a repository dedicated to implementing machine learning algorithms using the Rust programming language. The aim of this repository is to explore the performance benefits and challenges of building ML models in Rust, focusing on safety, speed, and scalability.
Machine Learning (ML) has predominantly been implemented in Python, thanks to libraries like TensorFlow and PyTorch. However, Rust is emerging as a compelling alternative due to its performance, memory safety, and concurrency features. This repository demonstrates how core ML algorithms can be built in Rust, leveraging libraries like tch-rs
for deep learning and ndarray
for general numerical operations.
Branch: feature/vision_transformer
- Description: Implementation of the Vision Transformer (ViT) using Rust's
tch-rs
library. - Features:
- End-to-end model definition and training pipeline in Rust.
- Performance benchmarking against a Python implementation using PyTorch.
- Codebase designed for modularity and extensibility.
- Goals:
- Evaluate the feasibility of training and deploying large ML models in Rust.
- Benchmark Rust's performance in training speed, inference time, and resource utilization.
To work with this repository, ensure the following tools are installed:
- Rust (latest stable version) – Install Rust
- Cargo (Rust package manager)
- Python (for performance comparison)
libtorch
library for Rust - libtorch-cpu- PyTorch for Python benchmarking
-
Clone the repository:
git clone https://github.com/ramendrasingla/ml_algorithms_in_rust.git cd ml_algorithms_in_rust
-
Navigate to the desired branch for a specific project (e.g., Vision Transformer):
git checkout feature/vision_transformer
-
Build the Rust project:
cargo build --release
-
Set up the Python environment for comparison:
pip install -r requirements.txt
-
Run the Vision Transformer in Rust:
cargo run --bin benchmark
-
Benchmark against Python (if applicable):
python src/benchmarks/python/benchmark_vit.py
Detailed benchmarking results comparing Rust and Python implementations can be found in the benchmarks
directory. Key metrics include:
- Training time
- Inference speed
- Memory usage
Contributions are welcome! If you'd like to contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/<feature_name>
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature/<feature_name>
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.