Jacobi¶
A machine learning framework for Rust compiled via XLA/PJRT to CPUs, GPUs (CUDA, ROCm), and TPUs, with native AMX/SME2 and Metal acceleration on Apple Silicon.
use jacobi::prelude::*;
#[module]
struct Mlp {
l1: Linear,
l2: Linear,
}
impl Mlp {
fn forward(&self, x: &Tensor) -> Tensor {
self.l2.forward(&self.l1.forward(x).tanh())
}
}
let step = jit(move |(mut m, mut o): (Mlp, AdamW<Mlp>)| {
let (loss, grads) = value_and_grad(
|p| nn::mse_loss(&p.forward(&x), &y),
&m,
);
o.step(&mut m, &grads);
(m, o, loss)
});
Benchmarks¶
1-1024-1024-1 tanh network for 200 full-batch steps on 2,048 points of sin(x) in f32 (median of 5 runs after 1 warm-up with identical initial weights and matching convergence 0.3586 -> 0.0133).
| Framework | Nvidia B300 | Nvidia B300 CPU | Nvidia B200 | Nvidia B200 CPU | Apple M5 Max GPU | Apple M5 Max CPU |
|---|---|---|---|---|---|---|
| Jacobi 0.1.0 (jit + for_loop) | 0.0139s | 2.98s | 0.0171s | 2.66s | 0.14s | 1.13s |
| JAX 0.12.1 (jax.jit + fori_loop) | 0.0147s | 3.31s | 0.0175s | 2.67s | N/A | 1.22s |
| PyTorch (eager) | 0.0856s | 24.29s | 0.1042s | 2.73s | 0.31s | 2.23s |
PyTorch (torch.compile) |
N/A | N/A | N/A | N/A | 0.31s | 2.30s |
| MLX 0.32.5 | N/A | N/A | N/A | N/A | 0.15s | 3.86s |
Random-weight architecture replicas benchmarked on live PleIAs/SYNTH next-token cross-entropy at 4,096 token context in FP8 across single-GPU, 8x H200 Expert Parallel, and 16x H200 Data + Expert Parallel clusters, plus batched RL Rollout (4,096-token prefill + 1,024-token decode).
| Model | Hardware | Parallelism | Mode | Precision | Batch | Peak RAM (dev0 x N) | Throughput | 15-Step CE Loss | Cost / 1T |
|---|---|---|---|---|---|---|---|---|---|
| Gemma-4-E4B (7.4B) | 1x B200 180GB | Single GPU | Forward/Prefill | FP8 | 16 | 22 GB | 154,127 tok/s | N/A | $9k |
| Gemma-4-E4B (7.4B) | 1x B200 180GB | Single GPU | Train | FP8 | 8 | 155 GB | 35,021 tok/s | 12.83 -> 8.85 | $40k |
| Gemma-4-E4B (7.4B) | 1x B200 180GB | Single GPU | Rollout/Decode | FP8 | 512 | 20 GB | 30,999 tok/s | N/A | $45k |
| Inkling-2-Mini (26B) | 8x H200 141GB | Expert Parallel | Forward/Prefill | FP8 | 192 | 210 GB | 356,044 tok/s | N/A | $22k |
| Inkling-2-Mini (26B) | 8x H200 141GB | Expert Parallel | Train | FP8 | 192 | 1,015 GB | 105,420 tok/s | 12.66 -> 8.32 | $74k |
| Inkling-2-Mini (26B) | 8x H200 141GB | Expert Parallel | Rollout/Decode | FP8 | 2,048 | 150 GB | 63,084 tok/s | N/A | $123k |
| DeepSeek-V4-Flash (283B) | 16x H200 141GB | Data + Expert Parallel | Forward/Prefill | FP8 | 64 | 744 GB | 217,234 tok/s | N/A | $72k |
| DeepSeek-V4-Flash (283B) | 16x H200 141GB | Data + Expert Parallel | Train (Rank-32 EfficientAdamW) | FP8 | 80 | 2,115 GB | 52,966 tok/s | 12.57 -> 10.62 | $294k |
| DeepSeek-V4-Flash (283B) | 16x H200 141GB | Data + Expert Parallel | Rollout/Decode | FP8 | 2,048 | 797 GB | 42,924 tok/s | N/A | $362k |
EfficientAdamW vs Full AdamW (Multi-Node RDMA, 16x H200, 4k Context, PleIAs/SYNTH)¶
| Model & Hardware | Optimizer | State / GPU | Peak HBM / GPU | Throughput | 15-Step CE Loss |
|---|---|---|---|---|---|
DeepSeek-V4-Flash 16L (106B, 16x H200 DP=2 x EP=8, batch 64) |
Full AdamW |
62.56 GB | 120.00 GB | 57,865 tok/s | 12.59 -> 8.15 |
DeepSeek-V4-Flash 16L (106B, 16x H200 DP=2 x EP=8, batch 64) |
Rank-32 EfficientAdamW (gap=50, scale=2.5) |
0.60 GB (99.0% saved) |
58.88 GB | 140,018 tok/s (2.42x) |
12.59 -> 7.76 |
| DeepSeek-V4-Flash 43L (283B, 16x H200) | Full AdamW (EP=16, batch 16 min) |
>141 GB | OOM | OOM | N/A |
DeepSeek-V4-Flash 43L (283B, 16x H200 DP=2 x EP=8, batch 80) |
Rank-32 EfficientAdamW (gap=50, scale=2.5) |
1.59 GB (99.0% saved) |
132.19 GB | 52,966 tok/s | 12.57 -> 10.62 |
Peak RAM is device-0 peak HBM x GPU count for symmetric SPMD shards. Cost / 1T uses $5.00/GPU-hr (B200) and $3.50/GPU-hr (H200).
Full hardware benchmarks and MFU analysis →
Zero runtime setup¶
Run cargo add jacobi and go. PJRT plugins download automatically on first use, with no protoc or libclang required.
Composable transforms¶
Combine jit, grad, jvp, hvp, vmap, checkpoint, custom_vjp, for_loop, scan, cond, and switch across plain Rust functions and structs, with automatic buffer donation and async dispatch.
PyTorch ergonomics¶
Define models with #[module], Linear, Conv1d/2d/3d, ConvTranspose1d/2d, MultiheadAttention, RoPE, KvCache, BatchNorm2d, GroupNorm, LayerNorm, stateful AdamW and Muon, Ema, and implicit device RNG.
Mixed precision and quantization¶
Use jit_autocast for BF16 and FP16, train with dynamically scaled FP8 and FP4 matmuls, or store and multiply quantized INT8 and UINT8 tensors with i32 accumulation.
Hugging Face native¶
Built on the official Rust tokenizers, safetensors, and hf-hub crates, plus Hugging Face Datasets streaming and memory-mapped checkpoint loading.
Export and notebooks¶
Save PyTorch-compatible .safetensors, export standalone .onnx or StableHLO .mlir, or run interactive notebooks with inline SVG plots in VS Code.
Documentation¶
Start Here¶
- Getting StartedInstall Jacobi and train your first neural network.
- Learn AI with Intelligent Systems CompendiumOpen textbook covering maths, ML, and AI with PyTorch, JAX, and Jacobi examples.
- NotebooksRun interactive Rust notebooks in VS Code and JupyterLab.
- Hardware BackendsConfigure CPU, CUDA, Metal, ROCm, TPU, and caching.
Core Guide¶
- Tensors and RandomnessTensors,
einsum,top_k, Cholesky, FFT, and implicit RNG. - Transforms
jit,grad,jvp,hvp,checkpoint,custom_vjp,vmap, loops, andcond. - Models and Optimizers
#[module], attention,RoPE,KvCache, optimizers, andDataLoader. - Mixed Precision
jit_autocast,BF16,FP16,FP8,FP4, andINT8quantization. - Distributed TrainingMulti-GPU
pmap, SPMDshard_map, and multi-node hybrid DP x EP.
Ecosystem and Examples¶
- Hugging FacePretrained tokenizers, safetensors, and Datasets.
- Export and ServingSafetensors, ONNX, StableHLO MLIR, and HTTP serving.
- ExamplesComplete MLP, CNN, ViT, Mini GPT, and benchmark walkthroughs.
- API ReferenceComplete reference for tensors, transforms, layers, optimizers, runtime, and
llms.txt/llms-full.txt.