Skip to content

Creating Machine Learning and Deep Learning Algorithms in Rust

License

Notifications You must be signed in to change notification settings

ramendrasingla/ml_algorithms_in_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ML Algorithms in Rust

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.

About the Project

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.

Current Projects

Vision Transformer (ViT)

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.

Getting Started

Prerequisites

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

Installation

  1. Clone the repository:

    git clone https://github.com/ramendrasingla/ml_algorithms_in_rust.git
    cd ml_algorithms_in_rust
  2. Navigate to the desired branch for a specific project (e.g., Vision Transformer):

git checkout feature/vision_transformer
  1. Build the Rust project:

    cargo build --release
  2. Set up the Python environment for comparison:

    pip install -r requirements.txt

Usage

  1. Run the Vision Transformer in Rust:

    cargo run --bin benchmark
  2. Benchmark against Python (if applicable):

python src/benchmarks/python/benchmark_vit.py

Benchmarks

Detailed benchmarking results comparing Rust and Python implementations can be found in the benchmarks directory. Key metrics include:

  • Training time
  • Inference speed
  • Memory usage

Contributing

Contributions are welcome! If you'd like to contribute:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/<feature_name>).
  3. Commit your changes (git commit -m 'Add new feature').
  4. Push to the branch (git push origin feature/<feature_name>).
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Creating Machine Learning and Deep Learning Algorithms in Rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published