百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

candle

> 编程语言
开源

Rust最小ML框架

20.8K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Rust最小ML框架

candle

Candle is a minimalist ML framework for Rust with a focus on performance (including GPU support) and ease of use. Try our online demos: whisper, LLaMA2, T5, yolo, Segment Anything.

Get started

Make sure that you have candle-core correctly installed as described in Installation.

Let's see how to run a simple matrix multiplication. Write the following to your myapp/src/main.rs file:

use candle_core::{Device, Tensor};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let device = Device::Cpu;

    let a = Tensor::randn(0f32, 1., (2, 3), &device)?;
    let b = Tensor::randn(0f32, 1., (3, 4), &device)?;

    let c = a.matmul(&b)?;
    println!("{c}");
    Ok(())
}

cargo run should display a tensor of shape Tensor[[2, 4], f32].

Having installed candle with Cuda support, simply define the device to be on GPU:

- let device = Device::Cpu;
+ let device = Device::new_cuda(0)?;

For more advanced examples, please have a look at the following section.

Check out our examples

These online demos run entirely in your browser:

  • yolo: pose estimation and object recognition.
  • whisper: speech recognition.
  • LLaMA2: text generation.
  • T5: text generation.
  • Phi-1.5, and Phi-2: text generation.
  • Segment Anything Model: Image segmentation.
  • BLIP: image captioning.

We also provide some command line based examples using state of the art models:

  • LLaMA v1, v2, and v3: general LLM, includes the SOLAR-10.7B variant.

  • Falcon: general LLM.

  • Codegeex4: Code completion, code interpreter, web search, function calling, repository-level

  • GLM4: Open Multilingual Multimodal Chat LMs by THUDM

  • Gemma v1 and v2: 2b and 7b+/9b general LLMs from Google Deepmind.

  • RecurrentGemma: 2b and 7b Griffin based models from Google that mix attention with a RNN like state.

  • Phi-1, Phi-1.5, Phi-2, and Phi-3: 1.3b, 2.7b, and 3.8b general LLMs with performance on par with 7b models.

  • StableLM-3B-4E1T: a 3b general LLM pre-trained on 1T tokens of English and code datasets. Also supports StableLM-2, a 1.6b LLM trained on 2T tokens, as well as the code variants.

  • Mamba: an inference only implementation of the Mamba state space model.

  • Mistral7b-v0.1: a 7b general LLM with better performance than all publicly available 13b models as of 2023-09-28.

  • Mixtral8x7b-v0.1: a sparse mixture of experts 8x7b general LLM with better performance than a Llama 2 70B model with much faster inference.

  • StarCoder and StarCoder2: LLM specialized to code generation.

  • Qwen1.5: Bilingual (English/Chinese) LLMs.

  • RWKV v5 and v6: An RNN with transformer level LLM performance.

  • Replit-code-v1.5: a 3.3b LLM specialized for code completion.

  • Yi-6B / Yi-34B: two bilingual (English/Chinese) general LLMs with 6b and 34b parameters.

  • Quantized LLaMA: quantized version of the LLaMA model using the same quantization techniques as llama.cpp.

  • Quantized Qwen3 MoE: support gguf quantized models of Qwen3 MoE models.

  • Stable Diffusion: text to image generative model, support for the 1.5, 2.1, SDXL 1.0 and Turbo versions.

  • Wuerstchen: another text to image generative model.

  • yolo-v3 and yolo-v8: object detection and pose estimation models.

  • segment-anything: image segmentation model with prompt.

  • SegFormer: transformer based semantic segmentation model.

  • Whisper: speech recognition model.

  • EnCodec: high-quality audio compression model using residual vector quantization.

  • MetaVoice: foundational model for text-to-speech.

  • Parler-TTS: large text-to-speech model.

  • T5, Bert, JinaBert : useful for sentence embeddings.

  • DINOv2: computer vision model trained using self-supervision (can be used for imagenet classification, depth evaluation, segmentation).

  • VGG, RepVGG: computer vision models.

  • BLIP: image to text model, can be used to generate captions for an image.

  • CLIP: multi-model vision and language model.

  • TrOCR: a transformer OCR model, with dedicated submodels for hand-writing and printed recognition.

  • Marian-MT: neural machine translation model, generates the translated text from the input text.

  • Moondream: tiny computer-vision model that can answer real-world questions about images.

Run them using commands like:

cargo run --example quantized --release

In order to use CUDA add --features cuda to the example command line. If you have cuDNN installed, use --features cudnn for even more speedups. The opt-in cutile feature supports writing JIT-compiled CUDA kernels in Rust; see the cuTile guide for setup and interop details.

There are also some wasm examples for whisper and llama2.c. You can either build them with trunk or try them online: whisper, llama2, T5, Phi-1.5, and Phi-2, Segment Anything Model.

For LLaMA2, run the following command to retrieve the weight files and start a test server:

# install target platform 'wasm32-unknown-unknown'
rustup target add wasm32-unknown-unknown

cd candle-wasm-examples/llama2-c
wget https://huggingface.co/spaces/lmz/candle-llama2/resolve/main/model.bin
wget https://huggingface.co/spaces/lmz/candle-llama2/resolve/main/tokenizer.json
trunk serve --release --port 8081

And then head over to http://localhost:8081/.

Useful External Resources

  • candle-tutorial: A very detailed tutorial showing how to convert a PyTorch model to Candle.
  • candle-lora: Efficient and ergonomic LoRA implementation for Candle. candle-lora has
    out-of-the-box LoRA support for many models from Candle, which can be found here.
  • candle-video: Rust library for text-to-video generation (LTX-Video and related models) built on Candle, focused on fast, Python-free inference.
  • optimisers: A collection of optimisers including SGD with momentum, AdaGrad, AdaDelta, AdaMax, NAdam, RAdam, and RMSprop.
  • candle-vllm: Efficient platform for inference and serving local LLMs including an OpenAI compatible API server.
  • candle-ext: An extension library to Candle that provides PyTorch functions not currently available in Candle.
  • candle-coursera-ml: Implementation of ML algorithms from Coursera's Machine Learning Specialization course.
  • kalosm: A multi-modal meta-framework in Rust for interfacing with local pre-trained models with support for controlled generation, custom samplers, in-memory vector databases, audio transcription, and more.
  • candle-sampling: Sampling techniques for Candle.
  • gpt-from-scratch-rs: A port of Andrej Karpathy's Let's build GPT tutorial on YouTube showcasing the Candle API on a toy problem.
  • candle-einops: A pure rust implementation of the python einops library.
  • atoma-infer: A Rust library for fast inference at scale, leveraging FlashAttention2 for efficient attention computation, PagedAttention for efficient KV-cache memory management, and multi-GPU support. It is OpenAI api compatible.
  • llms-from-scratch-rs: A comprehensive Rust translation of the code from Sebastian Raschka's Build an LLM from Scratch book.
  • vllm.rs: A minimalist vLLM implementation in Rust based on Candle.

If you have an addition to this list, please submit a pull request.

Features

  • Simple syntax, looks and feels like PyTorch.
    • Model training.
    • Embed user-defined ops/kernels, such as flash-attention v2.
  • Backends.
    • Optimized CPU backend with optional MKL support for x86 and Accelerate for macs.
    • CUDA backend for efficiently running on GPUs, multiple GPU distribution via NCCL.
    • WASM support, run your models in a browser.
  • Included models.
    • Language Models.
      • LLaMA v1, v2, and v3 with variants such as SOLAR-10.7B.
      • Falcon.
      • StarCoder, StarCoder2.
      • Phi 1, 1.5, 2, and 3.
      • Mamba, Minimal Mamba
      • Gemma v1 2b and 7b+, v2 2b and 9b.
      • Mistral 7b v0.1.
      • Mixtral 8x7b v0.1.
      • StableLM-3B-4E1T, StableLM-2-1.6B, Stable-Code-3B.
      • Replit-code-v1.5-3B.
      • Bert.
      • Yi-6B and Yi-34B.
      • Qwen1.5, Qwen1.5 MoE, Qwen3 MoE.
      • RWKV v5 and v6.
    • Quantized LLMs.
      • L

Issues· 907 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言