Crates.io | rai-core |
lib.rs | rai-core |
version | 0.11.0 |
source | src |
created_at | 2023-12-28 15:11:20.772147 |
updated_at | 2024-05-14 00:27:09.34198 |
description | ML framework with Ergonomic APIs in Rust |
homepage | https://github.com/cksac/rai |
repository | https://github.com/cksac/rai |
max_upload_size | |
id | 1082474 |
size | 318,658 |
cargo add rai
use rai::{grad, Cpu, Tensor, F32};
fn f(x: &Tensor) -> Tensor {
x.sin()
}
fn main() {
let grad_fn = grad(grad(f));
let x = &Tensor::ones([1], F32, &Cpu);
let grad = grad_fn(x);
println!("{}", grad.dot_graph());
println!("{}", grad);
}
fn loss_fn<M: TrainableModule<Input = Tensor, Output = Tensor>>(
model: &M,
input: &Tensor,
labels: &Tensor,
) -> (Tensor, Aux<Tensor>) {
let logits = model.forward(input);
let loss = softmax_cross_entropy(&logits, labels).mean(..);
(loss, Aux(logits))
}
fn train_step<M: TrainableModule<Input = Tensor, Output = Tensor>, O: Optimizer>(
optimizer: &mut O,
model: &M,
input: &Tensor,
labels: &Tensor,
) {
let vg_fn = value_and_grad(loss_fn);
let ((_loss, Aux(_logits)), (grads, ..)) = vg_fn((model, input, labels));
let mut params = optimizer.step(&grads);
eval(¶ms);
model.update_params(&mut params);
}
cargo run --bin linear_regression --release
cargo run --bin mnist --release
cargo run --bin mnist --release --features=cuda
cargo run --bin mnist-cnn --release
cargo run --bin mnist-cnn --release --features=cuda
cargo run --bin phi2 --release
cargo run --bin phi2 --release --features=cuda
cargo run --bin phi3 --release
cargo run --bin phi3 --release --features=cuda
cargo run --bin qwen2 --release
cargo run --bin qwen2 --release --features=cuda
pip install huggingface_hub
huggingface-cli login
cargo run --bin gemma --release
cargo run --bin gemma --release --features=cuda
cargo run --bin vit --release
cargo run --bin vit --release --features=cuda
This project is licensed under either of
at your option.