rust-ml
Skill1 starsChanged 40 days agoMITView on GitHub
Machine learning and numerical computing in Rust — tensors, framework choice (candle/burn/tch/ort/linfa), dtypes and determinism, avoiding needless copies of large tensors, GPU management, and serving a model without blocking the async runtime. Use for inference or training, loading a model (safetensors/ONNX), tokenizing, a data pipeline (polars/arrow), or deploying behind an API. Triggers: candle, burn, tch, ort, ONNX, ndarray, polars, safetensors, inference, GPU, spawn_blocking.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- adxptived/Rust-Skillstheir own version, first seen Oct 17, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- adxptived/Rust-Skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- addressing-findingsSkill
- auditSkill
- codebase-onboardingSkill
- codex-reviewSkill
- compatibilitySkill
- debuggingSkill
- developSkill
- distributed-racesSkill
- memorySkill
- nix-dev-envSkill
- nix-flakesSkill
- nixosSkill
- nix-packagingSkill
- nix-reviewSkill
- refactoringSkill
- retroSkill
- review-initSkill
- review-rulesSkill
- rust-architecture-reviewSkill
- rust-architectureSkill
- rust-cliSkill
- rust-cloud-nativeSkill
- rust-concurrencySkill
- rust-ecosystemSkill
- rust-embeddedSkill
- rust-errorsSkill
- rust-fintechSkill
- rust-idiomsSkill
- rust-macrosSkill
- rust-navigationSkill
- rust-ownershipSkill
- rust-performanceSkill
- rust-pluginsSkill
- rust-reviewSkill
- rust-securitySkill
- rust-testingSkill
- rust-traitsSkill
- rust-unsafeSkill
- rust-webSkill
- specsSkill
- sql-reviewSkill
The file
Files
Rust ML
Rust in ML is mostly an inference and data-plane language: you rarely train large models here, you serve them fast, safely, and without a GIL. The cardinal skill is picking the right stack for the job (classical vs deep, train vs infer-only, CPU vs GPU) and then not fighting it — most Rust ML pain comes from choosing the wrong framework or copying tensors around. Framework choice → frameworks.md; putting a model behind an API → serving.md.
When to Use
- Inference: loading a model (safetensors / ONNX / GGUF) and running it in a Rust service
- Embeddings, tokenization, classical ML (regression, trees, clustering)
- Numerical / tensor computing (ndarray, linear algebra)
- Data pipelines feeding a model (Polars / Arrow)
- Training, when you deliberately choose Rust (burn / candle / tch) — the rarer case
The cardinal rule: don't reinvent BLAS, and don't fight the framework
Numeric kernels (matmul, conv) are decades of hand-tuned BLAS/cuDNN. Never hand-roll them. Pick a framework that binds the right backend and use its tensor type end-to-end. The wrong choice — a training framework for pure inference, a pure-Rust one where you needed libtorch parity — is the #1 source of pain. Decide deliberately → frameworks.md.
# Inference-first, pure-Rust, HF ecosystem — the common default:
candle-core = "0.8"
candle-nn = "0.8"
candle-transformers = "0.8" # ready model architectures
tokenizers = "0.20" # HF tokenizers, no Python
safetensors = "0.4" # safe, zero-copy weights (never pickle)Versions drift fast in this ecosystem — resolve the ones actually pinned in the project
(cargo metadata --locked) and check the crate's current API rather than trusting memory (→ rust-ecosystem,
and context7 for live docs).
Tensors are big — treat copies as bugs
A tensor is not a Vec<f32> you clone freely; it can be gigabytes. The ownership discipline from
rust-ownership matters more here, not less:
- Pass tensors by reference; slice/view instead of copying.
ndarrayhas.view()/.slice(); candle ops borrow. A stray.to_vec()/.clone()in a hot path can copy hundreds of MB. - Load weights zero-copy with
safetensors(memory-maps the file) — never deserialize a pickle (.pt/.bin) from an untrusted source: pickle is arbitrary code execution (→rust-security). - Move a model to the device once, at load; don't re-upload per request.
Dtype and determinism are explicit decisions
- Dtype is a correctness/perf knob, not a default.
f32is the safe baseline;f16/bf16halve memory and speed up GPU inference but change numerics — choose per model, and know thatbf16(wider exponent) tolerates the dynamic range of activations better thanf16. CPU math inf16is usually emulated and slow. - Determinism must be engineered. Seed every RNG (
rand+ the framework's own seed); note that GPU reductions and multi-threaded CPU ops are not bit-reproducible by default. If you assert exact outputs in tests, pin threads/backend or assert with a tolerance (assert_relative_eq!fromapprox), never==on floats.
CPU parallelism vs GPU — and never block the runtime
- CPU-bound tensor work parallelizes with rayon (data parallelism), not async — see
rust-concurrencyfor threads-vs-async.ndarrayintegrates with rayon viandarray = { features = ["rayon"] }. - A forward pass is a blocking, CPU/GPU-bound call. In an async service it must run on
tokio::task::spawn_blocking(or a dedicated thread pool / inference actor), never inline in a handler — one inference on the async worker stalls every other connection. Full serving pattern → serving.md.
Data pipelines
- Polars (Arrow-backed DataFrame) for tabular ETL/feature engineering — lazy, multi-threaded, columnar; the pandas replacement. arrow directly when interop with other Arrow systems matters.
- ndarray for dense numeric arrays and classical-ML feature matrices (
linfabuilds on it). - Stream large datasets; don't materialize the whole set into
Vecbefore feeding a model — batch.
Testing ML code
Exactness lives behind floating point and randomness, so test invariants and tolerances, not
exact bytes (→ rust-testing):
- Shape/dtype contracts: output shape and dtype are what the next stage expects.
- Numerical tolerance: compare against a reference with
approx, not==. - Determinism where you claimed it: same seed → same result (within tolerance).
- A golden/regression sample: pin one known input→output pair so a silent model/preprocessing change (wrong normalization, tokenizer drift) fails the build.
- Property tests for preprocessing (normalize→denormalize round-trips, tokenizer encode/decode).
Boundaries
- Framework decision matrix (candle / burn / tch / ort / dfdx / linfa / smartcore) → frameworks.md.
- Serving a model behind an API (load-once
Arc, batching,spawn_blocking, GPU device, warmup) → serving.md, and the HTTP wiring →rust-web, deployment/observability →rust-cloud-native. - Avoiding tensor copies / view semantics →
rust-ownership; rayon vs async →rust-concurrency. - Profiling a slow pipeline, dtype/alloc tuning →
rust-performance. - Choosing/pinning crates, features, MSRV →
rust-ecosystem. - Untrusted model files / pickle RCE / dependency vulns →
rust-security.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

