Crate candle_core

Source
Expand description

ML framework for Rust

use candle_core::{Tensor, DType, Device};

let a = Tensor::arange(0f32, 6f32, &Device::Cpu)?.reshape((2, 3))?;
let b = Tensor::arange(0f32, 12f32, &Device::Cpu)?.reshape((3, 4))?;
let c = a.matmul(&b)?;

§Features

  • Simple syntax (looks and feels like PyTorch)
  • CPU and Cuda backends (and M1 support)
  • Enable serverless (CPU) small and fast deployments
  • Model training
  • Distributed computing (NCCL).
  • Models out of the box (Llama, Whisper, Falcon, …)

§FAQ

  • Why Candle?

Candle stems from the need to reduce binary size in order to enable serverless possible by making the whole engine smaller than PyTorch very large library volume

And simply removing Python from production workloads. Python can really add overhead in more complex workflows and the GIL is a notorious source of headaches.

Rust is cool, and a lot of the HF ecosystem already has Rust crates safetensors and tokenizers

§Other Crates

Candle consists of a number of crates. This crate holds core the common data structures but you may wish to look at the docs for the other crates which can be found here:

Re-exports§

Modules§

  • Traits to Define Backend Behavior
  • Methods for backpropagation of gradients.
  • 1D and 2D Convolutions
  • Traits and methods for CPU-backed Tensors
  • Implementation of Backend Fns for CPU
  • Pretty printing of tensors
  • Implementation of the Cuda backend when Cuda support has not been compiled in.
  • Candle-specific Error and Result
  • Tensor Layouts including contiguous or sparse strides
  • Numpy support for tensors.
  • Tensor Opertion Enums and Traits
  • Just enough pickle support to be able to read PyTorch checkpoints.
  • Code for GGML and GGUF files
  • Module to load safetensor files into CPU/GPU memory.
  • TensorScalar Enum and Trait
  • The shape of a tensor is a tuple with the size of each of its dimensions.
  • StreamTensror useful for streaming ops.
  • Useful functions for checking features.

Macros§

Structs§

  • An iterator over offset position for items of an N-dimensional arrays stored in a flat buffer using some potential strides.
  • The core struct for manipulating tensors.
  • Unique identifier for tensors.
  • A variable is a wrapper around a tensor, however variables can have their content modified whereas tensors are immutable.

Enums§

Traits§