百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rust-mlops-template

> DevOps
开源

正在进行的工作,目的是为 MLOps 构建 Rust 解决方案

382 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

正在进行的工作,目的是为 MLOps 构建 Rust 解决方案

Pragmatic AI Labs | Join 1M+ ML Engineers

Hot Course Offers:

  • Master GenAI Engineering - Build Production AI Systems
  • Learn Professional Rust - Industry-Grade Development
  • AWS AI & Analytics - Scale Your ML in Cloud
  • ⚡ Production GenAI on AWS - Deploy at Enterprise Scale
  • ️ Rust DevOps Mastery - Automate Everything

Level Up Your Career:

  • Production ML Program - Complete MLOps & Cloud Mastery
  • Start Learning Now - Fast-Track Your ML Career
  • Trusted by Fortune 500 Teams

Learn end-to-end ML engineering from industry veterans at PAIML.COM

rust-mlops-template

A work in progress to build out solutions in Rust for MLOPs. This repo is more of a cookbook style. For a more gentle step by step guide to MLOps with Rust, please see my lecture notes as a Rust MDBook here.

Update, one of the more compelling projects to look at is https://github.com/huggingface/candle

Take the Coursera Course!

You can learn Rust from this Duke Coursera MLOps course:

Take course here. Direct link: https://www.coursera.org/learn/devops-dataops-mlops-duke

Demo Hitlist (Will Solve hopefully almost every day/weekly)

  • Do an inline python example
  • Train a model in PyTorch with CPU: https://github.com/LaurentMazare/tch-rs
  • Train a model in PyTorch with GPU: https://github.com/LaurentMazare/tch-rs
  • Serve out ONNX with a Rust web framework like Actix
  • ONNX Command-Line Tool
  • Simple async network example: (network discovery or chat system)
  • Rust SQLite Example
  • Rust AWS Lambda
  • Simple Rust GUI
  • Rust Whisper Tool with C++ Bindings
  • Fast Keyword Extraction (NLP)
  • Emit Random Mediterranean Meals via CLI
  • Web Assembly Rust

Advanced Aspirational Demos

  • Building a database in Rust
  • Building a search engine in Rust
  • Building a web server in Rust
  • Building a batch processing systems in Rust
  • Build a command-line chat system
  • Build a locate clone
  • Build a load-testing tool

Motivation

One of the key goals of this project is to determine workflows that do not involve the #jcpennys (Jupyter, Conda, Pandas, Numpy, Sklearn) stack for #mlops. In particular I am not a fan of the conda installation tool (it is superfluous as I demonstrate in the Python MLOps Template) vs containerized workflows that use the Python Standard Library (Docker + pip + virtualenv) and this is a good excuse to find other solutions outside of that stack. For example:

  • Why not also find a more performant Data Frame library, faster speed, etc.
  • Why not have a compiler?
  • Why not have a simple packaging solution?
  • Why not have a very fast computational speed?
  • Why not be able to write both for the Linux Kernel and general purpose scripting?
  • Why not see if there is a better solution than Python (which is essentially two languages scientific python and regular Python)?
  • Python is one of the least green languages in terms of energy efficiency, but Rust is one of the best.

In The Beginning Was the Command-Line

What could #mlops and #datascience look like in 2023 without #jupyternotebook and "God Tools" as the center of the universe? It could be the command line. In the beginning, it was the command line, and it may be the best solution for this domain.

"What would the engineer say after you had explained your problem and enumerated all the dissatisfactions in your life? He would probably tell you that life is a very hard and complicated thing; that no interface can change that; that anyone who believes otherwise is a sucker; and that if you don't like having choices made for you, you should start making your own." -Neal Stephensen

Using Data (i.e. Data Science)

  • StackOverflow https://survey.stackoverflow.co/2022/#section-most-loved-dreaded-and-wanted-programming-scripting-and-markup-languages[states that #rust is on 7th year as the most loved language 87% of developers want to continue developing](https://survey.stackoverflow.co/2022/#section-most-loved-dreaded-and-wanted-programming-scripting-and-markup-languages) in and ties with Python as the most wanted technology. Clearly there is traction.
  • According to http://www.modulecounts.com/[Modulecounts] it looks like an exponential growth curve to Rust.

Getting Started

This repository is a GitHub Template and you can use it to create a new repository that uses GitHub Codespaces. It is pre-configured with Rust, Cargo and other useful extensions like GitHub Copilot.

Install and Setup

There are a few options:

  • You can follow the Official Install Guide for Rust
  • Create a repo with this template

Once you install you should check to see things work:

rustc --version

Other option is to run make rust-version which checks both the cargo and rust version. To run everything locally do: make all and this will format/lint/test all projects in this repository.

Rust CLI Tools Ecosystem

You can see there several tools which help you get things done in Rust:

makefile
rust-version:
	@echo "Rust command-line utility versions:"
	rustc --version 			#rust compiler
	cargo --version 			#rust package manager
	rustfmt --version			#rust code formatter
	rustup --version			#rust toolchain manager
	clippy-driver --version		#rust linter

Hello World Setup

This is an intentionally simple full end-to-end hello world example. I used some excellent ideas from @kyclark, author of the command-line-rust book from O'Reilly here. You can recreate on your own following these steps

Create a project directory

  • cargo new hello

This creates a structure you can see with tree hello

bash
hello/
├── Cargo.toml
└── src
    └── main.rs
1 directory, 2 files

The Cargo.toml file is where the project is configured, i.e. if you needed to add a dependency. The source code file has the following content in main.rs. It looks a lot like Python or any other modern language and this function prints a message.

fn main() {
    println!("Hello, world MLOPs!");
}

To run the project you cd into hello and run cargo run i.e. cd hello && cargo run. The output looks like the following:

bash
@noahgift ➜ /workspaces/rust-mlops-template/hello (main ✗) $ cargo run
   Compiling hello v0.1.0 (/workspaces/rust-mlops-template/hello)
    Finished dev [unoptimized + debuginfo] target(s) in 0.36s
     Running `target/debug/hello`
Hello, world MLOPs!

To run without all of the noise: cargo run --quiet. To run the binary created ./target/debug/hello

Run with GitHub Actions

GitHub Actions uses a Makefile to simplify automation

…

To run everything locally do: make all.

Simple Marco-Polo Game

Change into MarcoPolo directory and run cargo run -- play --name Marco and you should see the following output:

bash
Polo

First Big Project: Deduplication Command-Line Tool

I have written command-line deduplication tools in many languages so this is what I choose to build a substantial example. The general approach I use is as follows:

  1. Walk the filesystem and create a checksum for each file
  2. If the checksum matches an existing checksum, then mark it as a duplicate file

Getting Started

  • Create new project: crate new dedupe
  • Check latest clap version: https://crates.io/crates/clap and put this version in the Cargo.toml The file should look similar to this.
toml
[package]
name = "dedupe"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = "4.0.32"

[dev-dependencies]
assert_cmd = "2"
  • Next up make a test directory: mkdir tests that is parallel to src and put a cli.rs inside
  • touch a lib.rs file and use this for the logic then run cargo run
  • Inside this project I also created a Makefile to easily do everything at once:
makefile
format:
	cargo fmt --quiet

lint:
	cargo clippy --quiet

test:
	cargo test --quiet

run:
	cargo run --quiet

all: format lint test run

Now as I build code, I can simply do: make all and get a high quality build.

Next, let's create some test files:

bash
echo "foo" > /tmp/one.txt
echo "foo" > /tmp/two.txt
echo "bar" > /tmp/three.txt

The final version works: cargo run -- --path /tmp

bash
@noahgift ➜ /workspaces/rust-mlops-template/dedupe (main ✗) $ cargo run -- --path /tmp
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/dedupe --path /tmp`
Searching path: "/tmp"
Found 5 files
Found 1 duplicates
Duplicate files: ["/tmp/two.txt", "/tmp/one.txt"]

Next things to complete for dedupe (in another repo):

  • Switch to subcommands and create a search and dedupe subcommand
  • Add better testing with sample test files
  • Figure out how to release packages for multiple OS versions in GitHub

More MLOps project ideas

  • Query Hugging Face dataset cli
  • Summarize News CLI
  • Microservice Web Framework, trying actix to start, that has a calculator API
  • Microservice Web Framework deploys pre-trained model
  • Descriptive Statistics on a well known dataset using https://www.pola.rs/[Polars] inside a CLI
  • Train a model with PyTorch (probably via bindings to Rust)

Actix Microservice

  • Refer to Actix getting started guide
  • cargo new calc && cd calc
  • add dependency to Cargo.toml
toml
[package]
name = "calc"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = "4"
  • create a src/lib.rs and place inside
rust
//calculator functions

//Add two numbers
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

//Subtract two numbers
pub fn subtract(a: i32, b: i32) -> i32 {
    a - b
}

//Multiply two numbers
pub fn multiply(a: i32, b: i32) -> i32 {
    a * b
}

//Divide two numbers
pub fn divide(a: i32, b: i32) -> i32 {
    a / b
}

In the main.rs put the following:

…

Next, use a Makefile to ensure a simple workflow

makefile
format:
	cargo fmt --quiet

lint:
	cargo clippy --quiet

test:
	cargo test --quiet

run:
	cargo run 

all: format lint test run

Run make all then test out the route by adding two numbers at /add/2/2

Hugging Face Example

  • Uses rust-bert crate
  • Create new project cargo new hfdemo and cd into it: cd hfdemo
  • Create a new library file: touch src/lib.rs
  • Add packages to Cargo.toml
toml
[package]
name = "hfdemo"
version = "0.1.0"
edition = "2021"

[dependencies]
rust-bert = "0.19.0"
clap = {version="4.0.32", features=["derive"]}
wikipedia = "0.3.4"

The library code is in lib.rs and the subcommands from clap live in main.rs. Here is the tool in action:

bash
@noahgift ➜ /workspaces/rust-mlops-template/hfdemo (main ✗) $ cargo run sumwiki --page argentina
    Finished dev [unoptimized + debuginfo] target(s) in 4.59s
     Running `target/debug/hfdemo sumwiki --pa

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustactix-webawsazurecloud

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理