# Repository Briefing: huggingface/candle
> Source: https://repoforai.com/repo/huggingface/candle (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/huggingface/candle
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Rust
- **License**: Apache-2.0
- **Engineering Health**: A+ (88/100 · Maintenance 35/35 · Adoption 22/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: Local AI, GPU
- **Momentum**: 21,505 ★ total (+21 24h / +81 7d) · 1,906 forks
- **When to Use**: Best for: 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. Skip if: You need a turnkey model server, rely on unported PyTorch models or operators, or cannot test the exact checkpoint and backend on production hardware.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Crate boundaries: `candle-core` owns tensors and devices, `candle-nn` supplies neural-network building blocks, and `candle-transformers` houses model code.
- Native backends: Optimized CPU execution with optional MKL on x86 or Accelerate on macOS, plus CUDA and NCCL for multi-GPU distribution.
- Custom operators: The tree includes `candle-kernels`, `candle-metal-kernels`, and separate FlashAttention and FlashAttention v3 directories; FlashAttention v2 is the concrete integration example.
- Model coverage: Quantized LLaMA, Mistral, Mixtral, and Qwen3 MoE implementations sit alongside examples for Whisper, Stable Diffusion, and vision models.
- Browser execution: `candle-wasm-examples/llama2-c` targets `wasm32-unknown-unknown` and uses `model.bin` and `tokenizer.json`.
- Artifact integration: Safetensors helpers load and save tensors, while the separate `candle-onnx` crate provides ONNX evaluation.
```

## Quick Start / Clone
```bash
cargo run --example quantized --release
```
