huggingface/candle
Rust ML SDK for embedding local model inference without a Python runtime
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
Candle is a Rust ML SDK organized as a Cargo workspace using edition 2021 and resolver 2. candle-core owns Tensor, device selection, and core operators; candle-nn supplies neural-network building blocks; and candle-transformers provides model implementations and utilities. candle-examples/examples/llama/ is a concrete starting point for integrating a model. The matrix-multiplication example shows the execution model: create tensors on a Device, then call matmul; a CUDA-enabled build can select Device::new_cuda(0) instead of Device::Cpu.
The extension point is a custom operator or kernel embedded in the Rust application, not a network protocol. FlashAttention v2 illustrates that boundary. The tree also contains CUDA and Metal kernel directories, a separate FlashAttention v3 directory, and candle-onnx for model evaluation. Those directories are excluded from workspace membership, so their presence does not mean they are built by default. accelerate-src is listed as a workspace dependency for native acceleration.
Key Capabilities & Differentiators
Candle combines a PyTorch-like tensor API and training support with implementations for LLaMA, Gemma, Mamba, and Qwen3 MoE, among others. Quantized paths include LLaMA, Mistral, Mixtral, and Qwen3 MoE. The examples extend beyond text generation: T5 and Marian MT cover text-to-text workloads, Whisper handles speech recognition, and Stable Diffusion covers image generation.
The CPU backend can use optional MKL on x86 or Accelerate on macOS. CUDA supports multi-GPU distribution through NCCL, and selected models can execute in the browser through WebAssembly. Safetensors helpers load and save tensors; ONNX evaluation lives in candle-onnx. Verify the exact checkpoint, dtype, operators, and backend together: a supported model family or file format does not establish that every variant or graph will run on every target.
Trade-offs & Limitations
Candle's main advantage over tch-rs is that a native Candle application need not ship LibTorch or use a Python runtime. That is useful when deploying a Rust binary, but it shifts model integration work onto the application: a PyTorch model without a matching Candle implementation may need porting and operator validation. Burn is worth evaluating if backend choice is the primary requirement. If you need a ready-made HTTP model server, budget for a separate serving layer rather than treating the Candle SDK as one.
The lightweight packaging goal does not remove GPU drivers, native libraries, or model artifacts. Optional MKL and Accelerate can fail at link time when their native dependencies are not linked correctly. End-to-end cold-start performance also depends on storage: under WSL, loading weights from /mnt/c can be materially slower. Benchmark startup, model loading, and inference separately on the target system.
Hardware & Deployment Guide
For a first integration, add candle-core to a Cargo application and validate the CPU path with cargo run. Add the model and tokenizer artifacts separately; package them with the application for offline use if their terms permit it. Gated checkpoints such as LLaMA 2 require accepting the model terms and authenticating to download. The browser path uses the wasm32-unknown-unknown target; the llama2-c example uses Trunk to serve the application and needs model.bin and tokenizer.json.
For NVIDIA builds, align the CUDA toolkit, host compiler, and target GPU. Set CUDA_COMPUTE_CAP explicitly for a Docker build that cannot detect the target GPU. If FlashAttention hits the documented GCC 11 compilation failure, NVCC_CCBIN can select a compatible host compiler. Validate model load time, peak memory, and generation under the intended workload before choosing an instance type. Cargo.toml lists workspace version 0.11.1; no latest GitHub release is listed, so the manifest version alone does not establish release timing or cadence.
candle-core owns tensors and devices, candle-nn supplies neural-network building blocks, and candle-transformers houses model code.candle-kernels, candle-metal-kernels, and separate FlashAttention and FlashAttention v3 directories; FlashAttention v2 is the concrete integration example.candle-wasm-examples/llama2-c targets wasm32-unknown-unknown and uses model.bin and tokenizer.json.candle-onnx crate provides ONNX evaluation.Rust teams embedding a supported model into a local tool, application, or inference worker, especially when avoiding Python and LibTorch matters and the team can validate the target backend.
You need a turnkey model server, rely on unported PyTorch models or operators, or cannot test the exact checkpoint and backend on production hardware.
Quick Start & Installation
cargo run --example quantized --release
Comparison vs. Top LLMs & Inference Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| candle ★ | 21.5k | +81 | Rust | Apache-2.0 | Rust ML SDK for embedding local model inference without a Python runtime |
| transformers | 169.6k | +337 | Python | Apache-2.0 | A PyTorch model-definition SDK for unified inference and training across modalit |
| tokenizers | 11.4k | +62 | Rust | Apache-2.0 | Embeddable Rust tokenization for model-compatible text encoding and decoding |
| burn | 16.4k | +39 | Rust | Apache-2.0 | Rust tensor framework for shared training and inference code across CPU and GPU |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/huggingface/candle.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about candle
How do I integrate a model into an existing Rust application?
candle-core for tensors and device selection. Add candle-nn for layer building blocks and candle-transformers if it implements your model. Use the matching example to check weight loading, tokenization, and generation. Moving tensors to CUDA with to_device does not guarantee that every operation in the model is supported on that backend.How much RAM or VRAM should I budget?
Can we self-host Candle commercially or redistribute it with model weights?
MIT OR Apache-2.0, and both license files are present. Review the notice and redistribution obligations for the license you choose and for dependencies you ship. Model terms are separate: check the exact checkpoint's commercial-use and redistribution conditions. For gated LLaMA 2 weights, accepting the model terms and authenticating grants download access; it does not by itself establish redistribution rights.When should I choose Candle instead of tch-rs or Burn?
tch-rs when access to Torch from Rust matters more than removing that runtime dependency. Evaluate Burn when choosing among execution backends is a central design requirement. Test the exact model and operations on the intended target before committing to any of them.Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy