正在进行的工作,目的是为 MLOps 构建 Rust 解决方案
Learn end-to-end ML engineering from industry veterans at PAIML.COM
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
You can learn Rust from this Duke Coursera MLOps course:
Take course here. Direct link: https://www.coursera.org/learn/devops-dataops-mlops-duke
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:
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
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.
There are a few options:
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.
You can see there several tools which help you get things done in Rust:
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 linterThis 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 helloThis creates a structure you can see with tree hello
hello/
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 filesThe 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:
@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
GitHub Actions uses a Makefile to simplify automation
…To run everything locally do: make all.
Change into MarcoPolo directory and run cargo run -- play --name Marco and you should see the following output:
PoloI 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:
Getting Started
crate new dedupeCargo.toml
The file should look similar to this.[package]
name = "dedupe"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = "4.0.32"
[dev-dependencies]
assert_cmd = "2"mkdir tests that is parallel to src and put a cli.rs insidelib.rs file and use this for the logic then run cargo runMakefile to easily do everything at once:format:
cargo fmt --quiet
lint:
cargo clippy --quiet
test:
cargo test --quiet
run:
cargo run --quiet
all: format lint test runNow as I build code, I can simply do: make all and get a high quality build.
Next, let's create some test files:
echo "foo" > /tmp/one.txt
echo "foo" > /tmp/two.txt
echo "bar" > /tmp/three.txtThe final version works: cargo run -- --path /tmp
@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):
search and dedupe subcommandcargo new calc && cd calcCargo.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"src/lib.rs and place inside//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
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
cargo new hfdemo and cd into it: cd hfdemotouch src/lib.rsCargo.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:
@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,或尚未同步最近议题。