repo
stringlengths
6
65
file_url
stringlengths
81
311
file_path
stringlengths
6
227
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:31:58
2026-01-04 20:25:31
truncated
bool
2 classes
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/whisper/model.rs
candle-transformers/src/models/whisper/model.rs
use super::Config; use crate::models::with_tracing::{linear, linear_no_bias, Linear}; use candle::{Device, IndexOp, Result, Tensor, D}; use candle_nn::{embedding, Conv1d, Conv1dConfig, Embedding, LayerNorm, Module, VarBuilder}; fn conv1d( in_channels: usize, out_channels: usize, kernel_size: usize, con...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/whisper/mod.rs
candle-transformers/src/models/whisper/mod.rs
//! Whisper Model Implementation //! //! Whisper is an automatic speech recognition (ASR) system trained on large amounts //! of multilingual and multitask supervised data collected from the web. It can be used to //! convert audio files (in the `.wav` format) to text. Supported features include //! language detection ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/whisper/audio.rs
candle-transformers/src/models/whisper/audio.rs
// Audio processing code, adapted from whisper.cpp // https://github.com/ggerganov/whisper.cpp use candle::utils::get_num_threads; use std::sync::Arc; use std::thread; pub trait Float: num_traits::Float + num_traits::FloatConst + num_traits::NumAssign + Send + Sync { } impl Float for f32 {} impl Float for f64 {}...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/resnet.rs
candle-transformers/src/models/stable_diffusion/resnet.rs
//! ResNet Building Blocks //! //! Some Residual Network blocks used in UNet models. //! //! Denoising Diffusion Implicit Models, K. He and al, 2015. //! - [Paper](https://arxiv.org/abs/1512.03385) //! use crate::models::with_tracing::{conv2d, Conv2d}; use candle::{Result, Tensor, D}; use candle_nn as nn; use candle_nn...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/embeddings.rs
candle-transformers/src/models/stable_diffusion/embeddings.rs
use candle::{Result, Tensor, D}; use candle_nn as nn; use candle_nn::Module; #[derive(Debug)] pub struct TimestepEmbedding { linear_1: nn::Linear, linear_2: nn::Linear, } impl TimestepEmbedding { // act_fn: "silu" pub fn new(vs: nn::VarBuilder, channel: usize, time_embed_dim: usize) -> Result<Self> { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/attention.rs
candle-transformers/src/models/stable_diffusion/attention.rs
//! Attention Based Building Blocks use candle::{DType, IndexOp, Result, Tensor, D}; use candle_nn as nn; use candle_nn::Module; #[derive(Debug)] struct GeGlu { proj: nn::Linear, span: tracing::Span, } impl GeGlu { fn new(vs: nn::VarBuilder, dim_in: usize, dim_out: usize) -> Result<Self> { let pro...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/schedulers.rs
candle-transformers/src/models/stable_diffusion/schedulers.rs
#![allow(dead_code)] //! # Diffusion pipelines and models //! //! Noise schedulers can be used to set the trade-off between //! inference speed and quality. use candle::{Result, Tensor}; pub trait SchedulerConfig: std::fmt::Debug + Send + Sync { fn build(&self, inference_steps: usize) -> Result<Box<dyn Scheduler>>...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/vae.rs
candle-transformers/src/models/stable_diffusion/vae.rs
#![allow(dead_code)] //! # Variational Auto-Encoder (VAE) Models. //! //! Auto-encoder models compress their input to a usually smaller latent space //! before expanding it back to its original shape. This results in the latent values //! compressing the original information. use super::unet_2d_blocks::{ DownEncode...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/ddim.rs
candle-transformers/src/models/stable_diffusion/ddim.rs
//! # Denoising Diffusion Implicit Models //! //! The Denoising Diffusion Implicit Models (DDIM) is a simple scheduler //! similar to Denoising Diffusion Probabilistic Models (DDPM). The DDPM //! generative process is the reverse of a Markovian process, DDIM generalizes //! this to non-Markovian guidance. //! //! Denoi...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/utils.rs
candle-transformers/src/models/stable_diffusion/utils.rs
use candle::{Device, Result, Tensor}; pub fn linspace(start: f64, stop: f64, steps: usize) -> Result<Tensor> { if steps == 0 { Tensor::from_vec(Vec::<f64>::new(), steps, &Device::Cpu) } else if steps == 1 { Tensor::from_vec(vec![start], steps, &Device::Cpu) } else { let delta = (sto...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/mod.rs
candle-transformers/src/models/stable_diffusion/mod.rs
//! Stable Diffusion //! //! Stable Diffusion is a latent text-to-image diffusion model capable of //! generating photo-realistic images given any text input. //! //! - 💻 [Original Repository](https://github.com/CompVis/stable-diffusion) //! - 🤗 [Hugging Face](https://huggingface.co/runwayml/stable-diffusion-v1-5) //...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/unet_2d.rs
candle-transformers/src/models/stable_diffusion/unet_2d.rs
//! 2D UNet Denoising Models //! //! The 2D Unet models take as input a noisy sample and the current diffusion //! timestep and return a denoised version of the input. use super::embeddings::{TimestepEmbedding, Timesteps}; use super::unet_2d_blocks::*; use crate::models::with_tracing::{conv2d, Conv2d}; use candle::{Res...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/clip.rs
candle-transformers/src/models/stable_diffusion/clip.rs
//! Contrastive Language-Image Pre-Training //! //! Contrastive Language-Image Pre-Training (CLIP) is an architecture trained on //! pairs of images with related texts. //! //! - [CLIP](https://github.com/openai/CLIP) use candle::{DType, Device, Result, Tensor, D}; use candle_nn as nn; use candle_nn::Module; #[derive(...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/ddpm.rs
candle-transformers/src/models/stable_diffusion/ddpm.rs
use super::schedulers::{betas_for_alpha_bar, BetaSchedule, PredictionType}; use candle::{Result, Tensor}; #[derive(Debug, Default, Clone, PartialEq, Eq)] pub enum DDPMVarianceType { #[default] FixedSmall, FixedSmallLog, FixedLarge, FixedLargeLog, Learned, } #[derive(Debug, Clone)] pub struct D...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs
candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs
//! Ancestral sampling with Euler method steps. //! //! Based on the original [`k-diffusion` implementation by Katherine Crowson]( https://github.com/crowsonkb/k-diffusion/blob/481677d114f6ea445aa009cf5bd7a9cdee909e47/k_diffusion/sampling.py#L72). //! use super::{ schedulers::{ betas_for_alpha_bar, BetaSche...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/uni_pc.rs
candle-transformers/src/models/stable_diffusion/uni_pc.rs
//! # UniPC Scheduler //! //! UniPC is a training-free framework designed for the fast sampling of diffusion models, which consists of a //! corrector (UniC) and a predictor (UniP) that share a unified analytical form and support arbitrary orders. //! //! UniPC is by design model-agnostic, supporting pixel-space/latent...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/stable_diffusion/unet_2d_blocks.rs
candle-transformers/src/models/stable_diffusion/unet_2d_blocks.rs
//! 2D UNet Building Blocks //! use super::attention::{ AttentionBlock, AttentionBlockConfig, SpatialTransformer, SpatialTransformerConfig, }; use super::resnet::{ResnetBlock2D, ResnetBlock2DConfig}; use crate::models::with_tracing::{conv2d, Conv2d}; use candle::{Module, Result, Tensor, D}; use candle_nn as nn; #[...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/nvembed_v2/embedding.rs
candle-transformers/src/models/nvembed_v2/embedding.rs
/// Mistral LLM, https://github.com/mistralai/mistral-src use crate::models::{ mistral::Config, with_tracing::{linear_no_bias, Linear, RmsNorm}, }; use crate::utils::repeat_kv; use candle::{DType, Device, Module, Result, Tensor}; use candle_nn::{Activation, VarBuilder}; use std::sync::Arc; #[derive(Debug, Clon...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/nvembed_v2/model.rs
candle-transformers/src/models/nvembed_v2/model.rs
use super::embedding::Model as EmbeddingModel; use crate::models::{ mistral::Config, with_tracing::{layer_norm, linear, linear_no_bias, LayerNorm, Linear}, }; use candle::{DType, Device, Result, Tensor, D}; use candle_nn::{ops::softmax_last_dim, LayerNormConfig, Module, VarBuilder}; // Geglu and feedforward fr...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/nvembed_v2/mod.rs
candle-transformers/src/models/nvembed_v2/mod.rs
//! NV-Embed-v2 //! //! NV-Embed-v2 is a text embedding model that combines a Mistral decoder with a latent attention mechanism to produce high-quality text embeddings. //! //! This implementation is based on the [paper](https://arxiv.org/pdf/2405.17428) and [weights](https://huggingface.co/nvidia/NV-Embed-v2) //! //! ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/mimi/mod.rs
candle-transformers/src/models/mimi/mod.rs
//! mimi model //! //! [Mimi](https://huggingface.co/kyutai/mimi) is a state of the art audio //! compression model using an encoder/decoder architecture with residual vector //! quantization. The candle implementation supports streaming meaning that it's //! possible to encode or decode a stream of audio tokens on the...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/mimi/seanet.rs
candle-transformers/src/models/mimi/seanet.rs
// Copyright (c) Kyutai, all rights reserved. // This source code is licensed under the license found in the // LICENSE file in the root directory of this source tree. use candle::{streaming, Module, Result, StreamTensor, StreamingModule, Tensor}; use candle_nn::VarBuilder; use super::conv::{StreamableConv1d, Streama...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/mimi/conv.rs
candle-transformers/src/models/mimi/conv.rs
// Copyright (c) Kyutai, all rights reserved. // This source code is licensed under the license found in the // LICENSE file in the root directory of this source tree. use candle::{Module, Result, StreamTensor, StreamingModule, Tensor, D}; use candle_nn::{Conv1d, VarBuilder}; #[allow(clippy::enum_variant_names)] #[de...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/mimi/encodec.rs
candle-transformers/src/models/mimi/encodec.rs
// Copyright (c) Kyutai, all rights reserved. // This source code is licensed under the license found in the // LICENSE file in the root directory of this source tree. use super::{conv, quantization, seanet, transformer}; use candle::{DType, Device, Module, Result, StreamTensor, StreamingModule, Tensor}; use candle_nn...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/mimi/transformer.rs
candle-transformers/src/models/mimi/transformer.rs
// Copyright (c) Kyutai, all rights reserved. // This source code is licensed under the license found in the // LICENSE file in the root directory of this source tree. use candle::{DType, Device, IndexOp, Module, Result, StreamTensor, StreamingModule, Tensor, D}; use candle_nn::{linear_no_bias, Linear, VarBuilder}; us...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/models/mimi/quantization.rs
candle-transformers/src/models/mimi/quantization.rs
// Copyright (c) Kyutai, all rights reserved. // This source code is licensed under the license found in the // LICENSE file in the root directory of this source tree. use candle::{IndexOp, Layout, Result, Shape, Tensor, D}; use candle_nn::{linear, Linear, VarBuilder}; struct CodebookEncode; impl candle::CustomOp2 f...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/pipelines/text_generation.rs
candle-transformers/src/pipelines/text_generation.rs
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/pipelines/mod.rs
candle-transformers/src/pipelines/mod.rs
pub mod text_generation;
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/src/generation/mod.rs
candle-transformers/src/generation/mod.rs
//! Logit Processing and Sampling //! //! Functionality for modeling sampling strategies and logits processing in text generation //! with support for temperature-based sampling, top-k filtering, nucleus sampling (top-p), //! and combinations thereof. use candle::{DType, Error, Result, Tensor}; use rand::{distr::Distri...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/tests/generation_tests.rs
candle-transformers/tests/generation_tests.rs
use candle::{Device, Result, Tensor}; use candle_transformers::generation::LogitsProcessor; #[test] fn sample_with_zero_temperature() -> Result<()> { let mut logits_process = LogitsProcessor::new(1337, None, None); let logits = Tensor::new(&[0.1, 0.2, 0.3, 0.4], &Device::Cpu)?; let token = logits_process.s...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-transformers/tests/nms_tests.rs
candle-transformers/tests/nms_tests.rs
use candle::Result; use candle_transformers::object_detection::{ non_maximum_suppression, soft_non_maximum_suppression, Bbox, }; #[test] fn nms_basic() -> Result<()> { // Boxes based upon https://thepythoncode.com/article/non-maximum-suppression-using-opencv-in-python let mut bboxes = vec![vec![ Bb...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-pyo3/build.rs
candle-pyo3/build.rs
fn main() { pyo3_build_config::add_extension_module_link_args(); }
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-pyo3/src/shape.rs
candle-pyo3/src/shape.rs
use ::candle::Tensor; use pyo3::prelude::*; #[derive(Clone, Debug)] /// Represents an absolute shape e.g. (1, 2, 3) pub struct PyShape(Vec<usize>); impl pyo3::FromPyObject<'_, '_> for PyShape { type Error = PyErr; fn extract(obj: Borrowed<'_, '_, PyAny>) -> PyResult<Self> { if obj.is_none() { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-pyo3/src/lib.rs
candle-pyo3/src/lib.rs
#![allow(clippy::redundant_closure_call)] #![allow(clippy::useless_conversion)] use float8::F8E4M3; use half::{bf16, f16}; use pyo3::exceptions::{PyTypeError, PyValueError}; use pyo3::prelude::*; use pyo3::pyclass::CompareOp; use pyo3::types::{IntoPyDict, PyDict, PyString, PyTuple}; use pyo3::{IntoPyObject, IntoPyObjec...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-pyo3/src/utils.rs
candle-pyo3/src/utils.rs
use pyo3::exceptions::PyValueError; use pyo3::prelude::*; pub fn wrap_err(err: ::candle::Error) -> PyErr { PyErr::new::<PyValueError, _>(format!("{err:?}")) }
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-pyo3/src/onnx.rs
candle-pyo3/src/onnx.rs
use std::collections::HashMap; use crate::utils::wrap_err; use crate::{PyDType, PyTensor}; use candle_onnx::eval::{dtype, get_tensor, simple_eval}; use candle_onnx::onnx::tensor_proto::DataType; use candle_onnx::onnx::tensor_shape_proto::dimension::Value; use candle_onnx::onnx::type_proto::{Tensor as ONNXTensor, Value...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/op.rs
candle-core/src/op.rs
//! Tensor Operation Enums and Traits //! #![allow(clippy::redundant_closure_call)] use crate::Tensor; use float8::F8E4M3 as f8e4m3; use half::{bf16, f16}; use num_traits::float::Float; #[derive(Clone, Copy, PartialEq, Eq)] pub enum CmpOp { Eq, Ne, Le, Ge, Lt, Gt, } #[derive(Debug, Clone, Copy...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/dummy_metal_backend.rs
candle-core/src/dummy_metal_backend.rs
#![allow(dead_code)] use crate::op::{BinaryOpT, CmpOp, ReduceOp, UnaryOpT}; use crate::{CpuStorage, DType, Error, Layout, Result, Shape}; #[derive(Debug, Clone)] pub struct MetalDevice; #[derive(Debug)] pub struct MetalStorage; #[derive(thiserror::Error, Debug)] pub enum MetalError { #[error("{0}")] Message(...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/tensor_cat.rs
candle-core/src/tensor_cat.rs
use crate::{shape::Dim, Context, Error, Result, Shape, Tensor}; impl Tensor { /// Concatenates two or more tensors along a particular dimension. /// /// All tensors must of the same rank, and the output will have /// the same rank /// /// ```rust /// # use candle_core::{Tensor, DType, Devic...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/variable.rs
candle-core/src/variable.rs
// Variables are wrappers around tensors that can be modified, they are typically used for holding // weights and being modified by gradient descent. // We do not expose a public way to create variables as this would break the invariant that the // tensor within a variable is actually with `is_variable` set to `true`. ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/dummy_cuda_backend.rs
candle-core/src/dummy_cuda_backend.rs
//! Implementation of the Cuda backend when Cuda support has not been compiled in. //! #![allow(dead_code)] use crate::op::{BinaryOpT, CmpOp, ReduceOp, UnaryOpT}; use crate::{CpuStorage, DType, Error, Layout, Result, Shape}; #[derive(Debug, Clone)] pub struct CudaDevice; #[derive(Debug)] pub struct CudaStorage; macr...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/accelerate.rs
candle-core/src/accelerate.rs
#![allow(dead_code)] use libc::{c_char, c_double, c_float, c_int, c_long, c_ulong}; mod ffi { use super::*; extern "C" { // It would be nice to be able to switch to the NEWLAPACK version of the function but this // seems to trigger some link error. Available function names can be seen here: ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/shape.rs
candle-core/src/shape.rs
//! The shape of a tensor is a tuple with the size of each of its dimensions. #![allow(clippy::redundant_closure_call)] use crate::{Error, Result}; #[derive(Clone, PartialEq, Eq)] pub struct Shape(Vec<usize>); pub const SCALAR: Shape = Shape(vec![]); impl std::fmt::Debug for Shape { fn fmt(&self, f: &mut std::fm...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/lib.rs
candle-core/src/lib.rs
//! ML framework for Rust //! //! ```rust //! use candle_core::{Tensor, DType, Device}; //! # use candle_core::Error; //! # fn main() -> Result<(), Error>{ //! //! 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.m...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/device.rs
candle-core/src/device.rs
use crate::backend::BackendDevice; use crate::cpu_backend::CpuDevice; use crate::{CpuStorage, DType, Result, Shape, Storage, WithDType}; /// A `DeviceLocation` represents a physical device whereas multiple `Device` /// can live on the same location (typically for cuda devices). #[derive(Debug, Copy, Clone, PartialEq, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/mkl.rs
candle-core/src/mkl.rs
#![allow(dead_code)] use libc::{c_char, c_double, c_float, c_int}; mod ffi { use super::*; extern "C" { pub fn vsTanh(n: c_int, a: *const c_float, y: *mut c_float); pub fn vdTanh(n: c_int, a: *const c_double, y: *mut c_double); pub fn vsExp(n: c_int, a: *const c_float, y: *mut c_float);...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/convert.rs
candle-core/src/convert.rs
//! Implement conversion traits for tensors use crate::{DType, Device, Error, Tensor, WithDType}; use half::{bf16, f16, slice::HalfFloatSliceExt}; use std::convert::TryFrom; impl<T: WithDType> TryFrom<&Tensor> for Vec<T> { type Error = Error; fn try_from(tensor: &Tensor) -> Result<Self, Self::Error> { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/dtype.rs
candle-core/src/dtype.rs
//! Types for elements that can be stored and manipulated using tensors. #![allow(clippy::redundant_closure_call)] use crate::backend::BackendStorage; use crate::{CpuStorage, CpuStorageRef, Error, Result}; /// The different types of elements allowed in tensors. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub en...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/sort.rs
candle-core/src/sort.rs
use crate::{Result, Tensor}; use rayon::prelude::*; #[derive(Debug, Clone, Copy)] struct ArgSort { asc: bool, last_dim: usize, } impl ArgSort { fn asort<T: crate::WithDType>(&self, vs: &[T], layout: &crate::Layout) -> Vec<u32> { #[allow(clippy::uninit_vec)] // Safety: indexes are set later...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/backend.rs
candle-core/src/backend.rs
//! Traits to Define Backend Behavior //! use crate::op::{BinaryOpT, CmpOp, ReduceOp, UnaryOpT}; use crate::{CpuStorage, DType, Layout, Result, Shape}; pub trait BackendStorage: Sized { type Device: BackendDevice; fn try_clone(&self, _: &Layout) -> Result<Self>; fn dtype(&self) -> DType; fn device(&...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/strided_index.rs
candle-core/src/strided_index.rs
use crate::Layout; /// An iterator over offset position for items of an N-dimensional arrays stored in a /// flat buffer using some potential strides. #[derive(Debug)] pub struct StridedIndex<'a> { next_storage_index: Option<usize>, multi_index: Vec<usize>, dims: &'a [usize], stride: &'a [usize], r...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/test_utils.rs
candle-core/src/test_utils.rs
use crate::{Result, Tensor}; #[macro_export] macro_rules! test_device { // TODO: Switch to generating the two last arguments automatically once concat_idents is // stable. https://github.com/rust-lang/rust/issues/29599 ($fn_name: ident, $test_cpu: ident, $test_cuda: ident, $test_metal: ident) => { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/storage.rs
candle-core/src/storage.rs
use crate::backend::BackendStorage; use crate::op::{self, CmpOp, ReduceOp}; use crate::scalar::Scalar; use crate::{CpuStorage, CudaStorage, DType, Device, Error, Layout, MetalStorage, Result, Shape}; use crate::{CustomOp1, CustomOp2, CustomOp3, InplaceOp1, InplaceOp2, InplaceOp3}; // We do not want to implement Clone ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/dummy_dtype.rs
candle-core/src/dummy_dtype.rs
//! Dummy data types for experimental/future float formats //! //! These are placeholder types for experimental floating-point formats //! that are defined in the safetensors spec but not yet fully implemented. use crate::{DType, Error, Result, WithDType}; /// 6-bit float with 2 exponent bits and 3 mantissa bits (MX6...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/error.rs
candle-core/src/error.rs
//! Candle-specific Error and Result use std::{convert::Infallible, fmt::Display}; use crate::{DType, DeviceLocation, Layout, MetalError, Shape}; #[derive(Debug, Clone)] pub struct MatMulUnexpectedStriding { pub lhs_l: Layout, pub rhs_l: Layout, pub bmnk: (usize, usize, usize, usize), pub msg: &'stati...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/safetensors.rs
candle-core/src/safetensors.rs
//! Module to load `safetensor` files into CPU/GPU memory. //! //! There are multiple ways to load tensors from safetensor files: //! - `load` function for loading directly into memory and returning a HashMap of tensors //! - `MmapedSafetensors` for memory mapping files and avoiding full allocation //! - `SliceSafetens...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/display.rs
candle-core/src/display.rs
//! Pretty printing of tensors //! //! This implementation should be in line with the [PyTorch version](https://github.com/pytorch/pytorch/blob/7b419e8513a024e172eae767e24ec1b849976b13/torch/_tensor_str.py). //! use crate::{DType, Result, Tensor, WithDType}; use half::{bf16, f16}; impl Tensor { fn fmt_dt<T: WithDT...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/tensor.rs
candle-core/src/tensor.rs
//! Tensors are N-dimensional matrixes of elements using a single data type. #![allow(clippy::redundant_closure_call)] use crate::backend::{BackendDevice, BackendStorage}; use crate::op::{BackpropOp, BinaryOp, CmpOp, Op, ReduceOp, UnaryOp}; use crate::scalar::TensorOrScalar; use crate::shape::{Dim, Dims, ShapeWithOneHo...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/npy.rs
candle-core/src/npy.rs
//! Numpy support for tensors. //! //! The spec for the npy format can be found in //! [npy-format](https://docs.scipy.org/doc/numpy-1.14.2/neps/npy-format.html). //! The functions from this module can be used to read tensors from npy/npz files //! or write tensors to these files. A npy file contains a single tensor (u...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/scalar.rs
candle-core/src/scalar.rs
//! TensorScalar Enum and Trait //! use crate::{DType, Result, Tensor, WithDType}; use float8::F8E4M3 as f8e4m3; use half::{bf16, f16}; #[derive(Debug, Clone, Copy, PartialEq)] pub enum Scalar { U8(u8), U32(u32), I16(i16), I32(i32), I64(i64), BF16(bf16), F16(f16), F32(f32), F64(f64)...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/utils.rs
candle-core/src/utils.rs
//! Useful functions for checking features. use std::str::FromStr; pub fn get_num_threads() -> usize { // Respond to the same environment variable as rayon. match std::env::var("RAYON_NUM_THREADS") .ok() .and_then(|s| usize::from_str(&s).ok()) { Some(x) if x > 0 => x, Some(_...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/layout.rs
candle-core/src/layout.rs
//! Tensor Layouts including contiguous or sparse strides use crate::{Error, Result, Shape}; #[derive(Debug, PartialEq, Eq, Clone)] pub struct Layout { shape: Shape, // The strides are given in number of elements and not in bytes. stride: Vec<usize>, start_offset: usize, } impl Layout { pub fn new...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/conv.rs
candle-core/src/conv.rs
//! 1D and 2D Convolutions //! use crate::{op::BackpropOp, op::Op, Error, Result, Tensor}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct ParamsConv1D { pub(crate) b_size: usize, // Maybe we should have a version without l_in as this bit depends on the input and not only on // the weights. pub(crate...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/backprop.rs
candle-core/src/backprop.rs
//! Methods for backpropagation of gradients. use crate::op::{BinaryOp, Op, ReduceOp, UnaryOp}; use crate::{Error, Result, Tensor, TensorId}; use std::collections::HashMap; // arg has been reduced to node via reduce_dims, expand it back to arg. // This has to handle keepdims. fn broadcast_back(arg: &Tensor, node: &Ten...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/custom_op.rs
candle-core/src/custom_op.rs
use crate::op::{BackpropOp, Op}; use crate::tensor::from_storage; use crate::{CpuStorage, CudaStorage, Layout, MetalStorage, Result, Shape, Tensor}; use std::sync::Arc; /// Unary ops that can be defined in user-land. pub trait CustomOp1 { // Box<dyn> does not support const yet, so use a function to get the name. ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/pickle.rs
candle-core/src/pickle.rs
//! Just enough pickle support to be able to read PyTorch checkpoints. // This hardcodes objects that are required for tensor reading, we may want to make this a bit more // composable/tensor agnostic at some point. use crate::{Context, DType, Error as E, Layout, Result, Tensor}; use byteorder::{LittleEndian, ReadBytes...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/indexer.rs
candle-core/src/indexer.rs
use crate::{Error, Tensor}; use std::ops::{ Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive, }; impl Tensor { /// Intended to be use by the trait `.i()` /// /// ``` /// # use candle_core::{Tensor, DType, Device, IndexOp}; /// let a = Tensor::zeros((2, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/streaming.rs
candle-core/src/streaming.rs
//! StreamTensror useful for streaming ops. //! use crate::{Result, Shape, Tensor}; pub trait Dim: crate::shape::Dim + Copy {} impl<T: crate::shape::Dim + Copy> Dim for T {} /// A stream tensor is used in streaming module. It can either contain an actual tensor or be /// empty. #[derive(Clone)] pub struct StreamTenso...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/k_quants.rs
candle-core/src/quantized/k_quants.rs
use super::utils::{ get_scale_min_k4, group_for_dequantization, group_for_quantization, make_q3_quants, make_qkx1_quants, make_qx_quants, nearest_int, }; use super::GgmlDType; use crate::quantized::utils::{make_qkx3_quants, make_qp_quants}; use crate::Result; use byteorder::{ByteOrder, LittleEndian}; use half::...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/metal.rs
candle-core/src/quantized/metal.rs
use super::{GgmlDType, QStorage}; use crate::backend::BackendStorage; use crate::{DType, MetalDevice, MetalStorage, Result, Shape, D}; use candle_metal_kernels::metal::Buffer; use std::sync::Arc; pub struct QMetalStorage { dtype: GgmlDType, device: MetalDevice, buffer: Arc<Buffer>, } impl QMetalStorage { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/avx.rs
candle-core/src/quantized/avx.rs
use super::k_quants::{ BlockQ2K, BlockQ3K, BlockQ4K, BlockQ4_0, BlockQ5K, BlockQ6K, BlockQ8K, BlockQ8_0, QK8_0, QK_K, }; use byteorder::{ByteOrder, LittleEndian}; use half::f16; #[cfg(target_arch = "x86")] use core::arch::x86::*; #[cfg(target_arch = "x86_64")] use core::arch::x86_64::*; #[inline(always)] pub(crat...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/dummy_cuda.rs
candle-core/src/quantized/dummy_cuda.rs
#![allow(unused)] use super::GgmlDType; use crate::{CudaDevice, CudaStorage, Error, Result}; pub struct QCudaStorage { dtype: GgmlDType, device: CudaDevice, } impl QCudaStorage { pub fn zeros(_: &CudaDevice, _: usize, _: GgmlDType) -> Result<Self> { Err(Error::NotCompiledWithCudaSupport) } ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/gguf_file.rs
candle-core/src/quantized/gguf_file.rs
//! Support for the [GGUF file format](https://github.com/philpax/ggml/blob/gguf-spec/docs/gguf.md). //! //! Spec: https://github.com/ggml-org/ggml/blob/master/docs/gguf.md use super::{GgmlDType, QTensor}; use crate::{Context, Device, Result}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::coll...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/imatrix_file.rs
candle-core/src/quantized/imatrix_file.rs
use std::collections::HashMap; use std::fs::File; use std::io::{Cursor, Read}; use std::path::Path; use byteorder::{LittleEndian, ReadBytesExt}; use crate::Result; pub fn load_imatrix<P: AsRef<Path>>(fname: P) -> Result<HashMap<String, Vec<f32>>> { let mut all_data = HashMap::new(); let mut file = File::ope...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/ggml_file.rs
candle-core/src/quantized/ggml_file.rs
//! Support for the GGML file format. use super::{k_quants, GgmlDType, QStorage}; use crate::{Device, Result}; use byteorder::{LittleEndian, ReadBytesExt}; use std::collections::HashMap; // https://github.com/ggerganov/llama.cpp/blob/468ea24fb4633a0d681f7ac84089566c1c6190cb/llama.h#L37 #[derive(Debug, Clone, Copy, Pa...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/utils.rs
candle-core/src/quantized/utils.rs
pub(super) fn nearest_int(v: f32) -> i32 { v.round() as i32 } /// Validates that the input and output are the right size and returns an iterator which maps each /// input region `xs` to its corresponding output block in `ys`. Each output region is guaranteed /// to be `T::BLCK_SIZE` long. pub(super) fn group_for_q...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/mod.rs
candle-core/src/quantized/mod.rs
use crate::{ backend::BackendStorage, CpuStorage, DType, Device, Result, Shape, Storage, Tensor, D, }; use k_quants::*; use std::borrow::Cow; #[cfg(target_feature = "avx2")] pub mod avx; mod dummy_cuda; mod dummy_metal; pub mod ggml_file; pub mod gguf_file; pub mod imatrix_file; pub mod k_quants; #[cfg(feature = "...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/dummy_metal.rs
candle-core/src/quantized/dummy_metal.rs
#![allow(unused)] use super::GgmlDType; use crate::{Error, MetalDevice, MetalStorage, Result}; pub struct QMetalStorage { dtype: GgmlDType, device: MetalDevice, } impl QMetalStorage { pub fn zeros(_: &MetalDevice, _: usize, _: GgmlDType) -> Result<Self> { Err(Error::NotCompiledWithMetalSupport) ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/cuda.rs
candle-core/src/quantized/cuda.rs
use super::{GgmlDType, QStorage}; use crate::quantized::k_quants::GgmlType; use crate::{backend::BackendDevice, cuda_backend::WrapErr}; use crate::{builder_arg as barg, CudaDevice, CudaStorage, Result}; use half::f16; use cudarc::driver::{CudaSlice, CudaView, PushKernelArg}; #[derive(Clone, Debug)] struct PaddedCudaS...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/neon.rs
candle-core/src/quantized/neon.rs
use super::k_quants::{ BlockQ2K, BlockQ3K, BlockQ4K, BlockQ4_0, BlockQ5K, BlockQ6K, BlockQ8K, BlockQ8_0, QK8_0, QK_K, }; use byteorder::{ByteOrder, LittleEndian}; #[allow(unused_imports)] #[cfg(target_arch = "arm")] use core::arch::arm::*; #[allow(unused_imports)] #[cfg(target_arch = "aarch64")] use core::arch::a...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/quantized/simd128.rs
candle-core/src/quantized/simd128.rs
use super::k_quants::{BlockQ2K, BlockQ4K, BlockQ4_0, BlockQ6K, BlockQ8K, BlockQ8_0, QK8_0, QK_K}; use byteorder::{ByteOrder, LittleEndian}; use half::f16; use core::arch::wasm32::*; #[inline(always)] pub(crate) fn vec_dot_q4_0_q8_0(n: usize, xs: &[BlockQ4_0], ys: &[BlockQ8_0]) -> f32 { debug_assert!( n.is...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cuda_backend/device.rs
candle-core/src/cuda_backend/device.rs
use crate::backend::{BackendDevice, BackendStorage}; use crate::{CpuStorage, CpuStorageRef, DType, Layout, Result, Shape}; pub use candle_kernels as kernels; pub use cudarc; use cudarc::driver::CudaFunction; use float8::F8E4M3; use half::{bf16, f16}; use std::collections::HashMap; use std::sync::{Arc, Mutex, RwLock}; ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cuda_backend/error.rs
candle-core/src/cuda_backend/error.rs
use crate::{DType, Layout}; /// cudarc related errors #[derive(thiserror::Error, Debug)] pub enum CudaError { #[error(transparent)] Cuda(#[from] cudarc::driver::DriverError), #[error(transparent)] Compiler(#[from] cudarc::nvrtc::CompileError), #[error(transparent)] Cublas(#[from] cudarc::cubl...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cuda_backend/utils.rs
candle-core/src/cuda_backend/utils.rs
/// Helper functions to plug cuda kernels in candle. use crate::{Layout, Result, WithDType}; pub use cudarc; use cudarc::driver::{CudaSlice, DeviceRepr, ValidAsZeroBits}; use super::{CudaDevice, CudaError, WrapErr}; pub type S = super::CudaStorageSlice; pub trait Map1 { fn f<T: DeviceRepr + WithDType + ValidAsZe...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cuda_backend/mod.rs
candle-core/src/cuda_backend/mod.rs
//! Implementation of Backend traits for CUDA device //! use crate::backend::{BackendDevice, BackendStorage}; use crate::op::{BinaryOpT, CmpOp, ReduceOp, UnaryOpT}; use crate::{builder_arg as barg, CpuStorage, DType, Layout, Result, WithDType}; pub use candle_kernels as kernels; pub use cudarc; use cudarc::cublas::{Gem...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cuda_backend/cudnn.rs
candle-core/src/cuda_backend/cudnn.rs
use crate::WithDType; use cudarc; use cudarc::cudnn::safe::{ConvForward, Cudnn}; use cudarc::driver::{CudaSlice, CudaView, DeviceRepr, ValidAsZeroBits}; use std::cell::RefCell; use std::collections::HashMap; use std::sync::Arc; // The cudnn handles are stored per thread here rather than on the CudaDevice as they are n...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu/erf.rs
candle-core/src/cpu/erf.rs
#![allow(clippy::excessive_precision)] // Code taken from https://github.com/statrs-dev/statrs //! Provides the [error](https://en.wikipedia.org/wiki/Error_function) and //! related functions mod evaluate { //! Provides functions that don't have a numerical solution and must //! be solved computationally (e.g....
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu/avx.rs
candle-core/src/cpu/avx.rs
use super::{Cpu, CpuBF16, CpuF16}; #[cfg(target_arch = "x86")] use core::arch::x86::*; #[cfg(target_arch = "x86_64")] use core::arch::x86_64::*; use half::{bf16, f16}; pub struct CurrentCpu {} const STEP: usize = 32; const EPR: usize = 8; const ARR: usize = STEP / EPR; impl Cpu<ARR> for CurrentCpu { type Unit =...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu/mod.rs
candle-core/src/cpu/mod.rs
//! Traits and methods for CPU-backed Tensors pub mod erf; pub mod kernels; #[allow(unused)] trait Cpu<const ARR: usize> { type Unit; type Array; const STEP: usize; const EPR: usize; fn n() -> usize; unsafe fn zero() -> Self::Unit; unsafe fn zero_array() -> Self::Array; unsafe fn load...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu/neon.rs
candle-core/src/cpu/neon.rs
use super::Cpu; #[cfg(target_arch = "arm")] use core::arch::arm::*; #[cfg(target_arch = "aarch64")] use core::arch::aarch64::*; pub struct CurrentCpu {} const STEP: usize = 16; const EPR: usize = 4; const ARR: usize = STEP / EPR; impl CurrentCpu { #[cfg(target_arch = "aarch64")] unsafe fn reduce_one(x: floa...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu/simd128.rs
candle-core/src/cpu/simd128.rs
use super::Cpu; use core::arch::wasm32::*; pub struct CurrentCpu {} const STEP: usize = 16; const EPR: usize = 4; const ARR: usize = STEP / EPR; impl Cpu<ARR> for CurrentCpu { type Unit = v128; type Array = [v128; ARR]; const STEP: usize = STEP; const EPR: usize = EPR; fn n() -> usize { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu/kernels.rs
candle-core/src/cpu/kernels.rs
pub trait VecOps: num_traits::NumAssign + Copy { fn min(self, rhs: Self) -> Self; fn max(self, rhs: Self) -> Self; /// Dot-product of two vectors. /// /// # Safety /// /// The length of `lhs` and `rhs` have to be at least `len`. `res` has to point to a valid /// element. #[inline(al...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/metal_backend/device.rs
candle-core/src/metal_backend/device.rs
use crate::{DType, Result}; #[cfg(feature = "ug")] use candle_metal_kernels::metal::ComputePipeline; use candle_metal_kernels::{ metal::{ BlitCommandEncoder, Buffer, BufferMap, Commands, ComputeCommandEncoder, Device, MTLResourceOptions, }, Kernels, }; use objc2_foundation::NSURL; use objc2...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/metal_backend/mod.rs
candle-core/src/metal_backend/mod.rs
//! Implementation of Backend traits for Metal //! use crate::backend::{BackendDevice, BackendStorage}; use crate::conv::{ParamsConv1D, ParamsConv2D, ParamsConvTranspose1D, ParamsConvTranspose2D}; use crate::op::{BinaryOpT, CmpOp, ReduceOp, UnaryOpT}; use crate::{CpuStorage, CpuStorageRef, DType, Error, Layout, Result,...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu_backend/utils.rs
candle-core/src/cpu_backend/utils.rs
/// Helper functions to write CPU kernels. use crate::backend::BackendStorage; use crate::{Error, Layout, Result, WithDType}; type C = super::CpuStorage; pub trait Map1 { fn f<T: WithDType>(&self, vs: &[T], layout: &Layout) -> Result<Vec<T>>; fn map(&self, vs: &C, layout: &Layout) -> Result<C> { match...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu_backend/mod.rs
candle-core/src/cpu_backend/mod.rs
//! Implementation of Backend Fns for CPU use crate::backend::{BackendDevice, BackendStorage}; use crate::op::{BinaryOpT, CmpOp, ReduceOp, UnaryOpT}; use crate::{DType, Error, IntDType, Layout, Result, Shape, WithDType}; use float8::F8E4M3; use half::{bf16, f16}; use rayon::prelude::*; mod utils; pub use utils::{ ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/src/cpu_backend/conv2d.rs
candle-core/src/cpu_backend/conv2d.rs
use std::borrow::Cow; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use crate::{ conv::ParamsConv2D, cpu_backend::{copy_strided_src_, Im2Col, Map1, Map2, MatMul}, shape::dims4, Layout, Result, WithDType, }; pub(super) struct Conv2D<'a>(pub(super) &'a crate::conv::ParamsConv2D); #[allow(...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/tests/indexing_tests.rs
candle-core/tests/indexing_tests.rs
use anyhow::Result; use candle_core::{Device, IndexOp, Tensor}; #[test] fn integer_index() -> Result<()> { let dev = Device::Cpu; let tensor = Tensor::arange(0u32, 2 * 3, &dev)?.reshape((2, 3))?; let result = tensor.i(1)?; assert_eq!(result.dims(), &[3]); assert_eq!(result.to_vec1::<u32>()?, &[3, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/tests/grad_tests.rs
candle-core/tests/grad_tests.rs
#![allow(clippy::approx_constant)] use anyhow::{Context, Result}; use candle_core::{test_device, test_utils, DType, Device, Shape, Tensor, Var}; fn simple_grad(device: &Device) -> Result<()> { let x = Var::new(&[3f32, 1., 4.], device)?; let x = x.as_tensor(); let y = (((x * x)? + x * 5f64)? + 4f64)?; l...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-core/tests/quantized_tests.rs
candle-core/tests/quantized_tests.rs
use candle_core::{ bail, quantized::{self, GgmlDType}, test_device, test_utils::to_vec2_round, DType, Device, IndexOp, Module, Result, Tensor, Var, }; use quantized::{k_quants, GgmlType}; use rand::prelude::*; const GGML_TEST_SIZE: usize = 32 * 128; const GGML_MAX_QUANTIZATION_TOTAL_ERROR: f32 = 0...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true