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-examples/examples/voxtral/model.rs
candle-examples/examples/voxtral/model.rs
use std::path::PathBuf; use anyhow::{Context, Error, Result}; use byteorder::{LittleEndian, ReadBytesExt}; use candle::{utils, DType, Device, Tensor}; use candle_nn::VarBuilder; use candle_transformers::models::voxtral; use candle_transformers::models::voxtral::{ VoxtralCache, VoxtralConfig, VoxtralEncoderConfig, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/voxtral/main.rs
candle-examples/examples/voxtral/main.rs
use anyhow::{Context, Result}; use clap::Parser; use hf_hub::api::sync::Api; use model::VoxtralModel; mod download; mod model; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { /// Run on CPU rather than on GPU. #[arg(long, default_value_t = false)] cpu: bool, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/mixtral/main.rs
candle-examples/examples/mixtral/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use clap::Parser; use candle_transformers::models::mixtral::{Config, Model}; use candle::{DType, Device, Tensor}; use candle_examples::token_output_stream::TokenOutputStr...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/olmo/main.rs
candle-examples/examples/olmo/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use clap::{Parser, ValueEnum}; use candle_transformers::models::olmo::{Config, Model as OLMo}; use candle_transformers::models::olmo2::{Config as Config2, Model as OLMo2};...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/llava/conversation.rs
candle-examples/examples/llava/conversation.rs
pub enum SeparatorStyle { Two, Mpt, } pub struct Conversation { pub system: String, pub roles: Vec<String>, pub messages: Vec<(String, Option<String>)>, pub offset: i32, pub sep_style: SeparatorStyle, pub sep: String, pub sep2: Option<String>, pub version: String, } impl Convers...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/llava/image_processor.rs
candle-examples/examples/llava/image_processor.rs
use std::cmp::min; use candle::{bail, DType, Device, Result, Tensor}; use candle_transformers::models::llava::{ config::{HFPreProcessorConfig, LLaVAConfig}, utils::select_best_resolution, }; use hf_hub::api::sync::Api; use image::{imageops::overlay, DynamicImage, GenericImageView, Rgb, RgbImage}; use serde::{D...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/llava/main.rs
candle-examples/examples/llava/main.rs
pub mod constants; pub mod conversation; pub mod image_processor; use candle_transformers::generation::{LogitsProcessor, Sampling}; use candle_transformers::models::llama::Cache; use anyhow::{bail, Error as E, Result}; use candle::{DType, Device, IndexOp, Tensor}; use candle_nn::VarBuilder; use candle_transformers::m...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/llava/constants.rs
candle-examples/examples/llava/constants.rs
pub const DEFAULT_IMAGE_TOKEN: &str = "<image>"; pub const DEFAULT_IM_START_TOKEN: &str = "<im_start>"; pub const DEFAULT_IM_END_TOKEN: &str = "<im_end>"; pub const IMAGE_PLACEHOLDER: &str = "<image-placeholder>";
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/rwkv/main.rs
candle-examples/examples/rwkv/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::Result; use clap::{Parser, ValueEnum}; use candle_transformers::models::quantized_rwkv_v5::Model as Q5; use candle_transformers::models::quantized_rwkv_v6::Model as Q6; use candle_transformers:...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/mamba/main.rs
candle-examples/examples/mamba/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use clap::{Parser, ValueEnum}; use candle_transformers::models::mamba::{Config, Model, State}; use candle::{DType, Device, Tensor}; use candle_examples::token_output_stre...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/mistral/main.rs
candle-examples/examples/mistral/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use clap::Parser; use candle_transformers::models::mistral::{Config, Model as Mistral}; use candle_transformers::models::quantized_mistral::Model as QMistral; use candle:...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/quantized-qwen3-moe/main.rs
candle-examples/examples/quantized-qwen3-moe/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use clap::{Parser, ValueEnum}; use std::io::Write; use tokenizers::Tokenizer; use candle::Tensor; use candle::{quantized::gguf_file, DType}; use candle_transformers::generation::{LogitsProcessor, Sampling}...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/yolo-v3/darknet.rs
candle-examples/examples/yolo-v3/darknet.rs
use candle::{DType, Device, IndexOp, Result, Tensor}; use candle_nn::{batch_norm, conv2d, conv2d_no_bias, Func, Module, VarBuilder}; use std::collections::BTreeMap; use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::Path; #[derive(Debug)] struct Block { block_type: String, parameters: BTreeMa...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/yolo-v3/main.rs
candle-examples/examples/yolo-v3/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle_transformers::object_detection::{non_maximum_suppression, Bbox}; mod darknet; use anyhow::Result; use candle::{DType, Device, Tensor}; use candle_nn::{Module, VarBuilder}; use clap::Parser; use ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/t5/main.rs
candle-examples/examples/t5/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use std::io::Write; use std::path::PathBuf; use candle_transformers::models::t5; use anyhow::{Error as E, Result}; use candle::{DType, Device, Tensor}; use candle_nn::VarBuilder; use candle_transformers::g...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/whisper/multilingual.rs
candle-examples/examples/whisper/multilingual.rs
use candle::{IndexOp, Result, Tensor, D}; use tokenizers::Tokenizer; const LANGUAGES: [(&str, &str); 99] = [ ("en", "english"), ("zh", "chinese"), ("de", "german"), ("es", "spanish"), ("ru", "russian"), ("ko", "korean"), ("fr", "french"), ("ja", "japanese"), ("pt", "portuguese"), ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/whisper/main.rs
candle-examples/examples/whisper/main.rs
// https://github.com/openai/whisper/blob/main/whisper/model.py/rgs // TODO: // - Batch size greater than 1. // - More token filters (SuppressBlanks, ApplyTimestampRules). #[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use anyhow::{Error as E, Result};...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/stella-en-v5/main.rs
candle-examples/examples/stella-en-v5/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use std::path::Path; use anyhow::{anyhow, Error as E, Result}; use clap::Parser; use candle_transformers::models::stella_en_v5::{ Config, EmbedDim as StellaEmbedDim, EmbeddingModel, }; use candle::{D...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/hiera/main.rs
candle-examples/examples/hiera/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use clap::{Parser, ValueEnum}; use candle::{DType, IndexOp, D}; use candle_nn::{Module, VarBuilder}; use candle_transformers::models::hiera; #[derive(Clone, Copy, Debug, ValueEnum)] enum Which { Tiny,...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/granite/main.rs
candle-examples/examples/granite/main.rs
// An implementation of different Granite models https://www.ibm.com/granite #[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use anyhow::{bail, Error as E, Result}; use clap::{Parser, ValueEnum}; use candle::{DType, Tensor}; use candle_nn::VarBuilder; ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/orpheus/main.rs
candle-examples/examples/orpheus/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use clap::Parser; use candle::{DType, Device, IndexOp, Tensor}; use candle_nn::VarBuilder; use candle_transformers::models::llama::{Cache, Llama, LlamaConfig}; use candle_...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/nvembed_v2/main.rs
candle-examples/examples/nvembed_v2/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use candle::{DType, IndexOp, Shape, Tensor, D}; use candle_nn::VarBuilder; use candle_transformers::models::nvembed_v2::model::Model; use clap::Parser; use hf_hub::{api::sy...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/mimi/audio_io.rs
candle-examples/examples/mimi/audio_io.rs
use anyhow::{Context, Result}; use std::sync::{Arc, Mutex}; pub const SAMPLE_RATE: usize = 24_000; pub(crate) struct AudioOutputData_ { resampled_data: std::collections::VecDeque<f32>, resampler: rubato::FastFixedIn<f32>, output_buffer: Vec<f32>, input_buffer: Vec<f32>, input_len: usize, } impl A...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/mimi/main.rs
candle-examples/examples/mimi/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::Result; use candle::{DType, IndexOp, Tensor}; use candle_nn::VarBuilder; use candle_transformers::models::mimi::{Config, Model}; use clap::{Parser, ValueEnum}; use hf_hub::api::sync::Api; mod a...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/distilbert/main.rs
candle-examples/examples/distilbert/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle_transformers::models::distilbert::{ Config, DistilBertForMaskedLM, DistilBertModel, DTYPE, }; use anyhow::{Context, Error as E, Result}; use candle::{Device, Tensor}; use candle_nn::VarBuilde...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/codegeex4-9b/main.rs
candle-examples/examples/codegeex4-9b/main.rs
use candle::{DType, Device, Tensor}; use candle_nn::VarBuilder; use candle_transformers::generation::LogitsProcessor; use candle_transformers::models::codegeex4_9b::*; use clap::Parser; use hf_hub::{Repo, RepoType}; use tokenizers::Tokenizer; struct TextGeneration { model: Model, device: Device, tokenizer:...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/segformer/main.rs
candle-examples/examples/segformer/main.rs
use candle::Device; use candle::Module; use candle_nn::VarBuilder; use candle_transformers::models::segformer::{ Config, ImageClassificationModel, SemanticSegmentationModel, }; use clap::{Args, Parser, Subcommand}; use imageproc::image::Rgb; use imageproc::integral_image::ArrayData; use std::collections::HashMap; u...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/reinforcement-learning/vec_gym_env.rs
candle-examples/examples/reinforcement-learning/vec_gym_env.rs
//! Vectorized version of the gym environment. use candle::{DType, Device, Result, Tensor}; use pyo3::prelude::*; #[allow(unused)] #[derive(Debug)] pub struct Step { pub obs: Tensor, pub reward: Tensor, pub is_done: Tensor, } #[allow(unused)] pub struct VecGymEnv { env: PyObject, action_space: usi...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/reinforcement-learning/policy_gradient.rs
candle-examples/examples/reinforcement-learning/policy_gradient.rs
use super::gym_env::{GymEnv, Step}; use candle::{DType, Device, Error, Module, Result, Tensor}; use candle_nn::{ linear, ops::log_softmax, ops::softmax, sequential::seq, Activation, AdamW, Optimizer, ParamsAdamW, VarBuilder, VarMap, }; use rand::{distr::Distribution, rngs::ThreadRng, Rng}; fn new_model( in...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/reinforcement-learning/ddpg.rs
candle-examples/examples/reinforcement-learning/ddpg.rs
use std::collections::VecDeque; use candle::{DType, Device, Error, Module, Result, Tensor, Var}; use candle_nn::{ func, linear, sequential::seq, Activation, AdamW, Optimizer, ParamsAdamW, Sequential, VarBuilder, VarMap, }; use rand::{distr::Uniform, rng, Rng}; use super::gym_env::GymEnv; pub struct OuNoise {...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/reinforcement-learning/dqn.rs
candle-examples/examples/reinforcement-learning/dqn.rs
use std::collections::VecDeque; use rand::{distr::Uniform, rng, Rng}; use candle::{DType, Device, Error, Module, Result, Tensor}; use candle_nn::loss::mse; use candle_nn::{linear, seq, Activation, AdamW, Optimizer, VarBuilder, VarMap}; use crate::gym_env::GymEnv; const DEVICE: Device = Device::Cpu; const EPISODES: ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/reinforcement-learning/main.rs
candle-examples/examples/reinforcement-learning/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle::Result; use clap::{Parser, Subcommand}; mod gym_env; mod vec_gym_env; mod ddpg; mod dqn; mod policy_gradient; #[derive(Parser)] struct Args { #[command(subcommand)] command: Command, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/reinforcement-learning/gym_env.rs
candle-examples/examples/reinforcement-learning/gym_env.rs
//! Wrappers around the Python API of Gymnasium (the new version of OpenAI gym) use candle::{Device, Result, Tensor}; use pyo3::prelude::*; use pyo3::types::PyDict; /// The return value for a step. #[derive(Debug)] pub struct Step<A> { pub state: Tensor, pub action: A, pub reward: f64, pub terminated: ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/gte-qwen/main.rs
candle-examples/examples/gte-qwen/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use clap::Parser; use candle_transformers::models::qwen2::{Config, Model}; use candle::{DType, Tensor}; use candle_nn::VarBuilder; use hf_hub::{api::sync::Api, Repo, Repo...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/onnx-llm/main.rs
candle-examples/examples/onnx-llm/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::Result; use candle::{DType, Tensor}; use candle_transformers::generation::{LogitsProcessor, Sampling}; use clap::{Parser, ValueEnum}; use hf_hub::api::sync::Api; use serde::Deserialize; use std:...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/splade/main.rs
candle-examples/examples/splade/main.rs
use std::path::PathBuf; use anyhow::{Error as E, Result}; use candle::Tensor; use candle_nn::VarBuilder; use candle_transformers::models::bert::{self, BertForMaskedLM, Config}; use clap::Parser; use hf_hub::{api::sync::Api, Repo, RepoType}; use tokenizers::{PaddingParams, Tokenizer}; #[derive(Parser, Debug)] #[comman...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/replit-code/main.rs
candle-examples/examples/replit-code/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::{Error as E, Result}; use clap::Parser; use candle_transformers::models::mpt::{Config, Model as M}; use candle_transformers::models::quantized_mpt::Model as Q; use candle::{DType, Device, Tens...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/efficientnet/main.rs
candle-examples/examples/efficientnet/main.rs
//! EfficientNet implementation. //! //! https://arxiv.org/abs/1905.11946 #[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle::{DType, IndexOp, D}; use candle_nn::{Module, VarBuilder}; use candle_transformers::models::efficientnet::{EfficientNet,...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/granitemoehybrid/main.rs
candle-examples/examples/granitemoehybrid/main.rs
// Granite 4.0 Micro text generation example (GraniteMoeHybrid). #[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use anyhow::{bail, Error as E, Result}; use clap::Parser; use candle::{DType, Tensor}; use candle_nn::VarBuilder; use candle_transformers::...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/mobileone/main.rs
candle-examples/examples/mobileone/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use clap::{Parser, ValueEnum}; use candle::{DType, IndexOp, D}; use candle_nn::{Module, VarBuilder}; use candle_transformers::models::mobileone; #[derive(Clone, Copy, Debug, ValueEnum)] enum Which { S...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/llama/main.rs
candle-examples/examples/llama/main.rs
// An implementation of LLaMA https://github.com/facebookresearch/llama // // This is based on nanoGPT in a similar way to: // https://github.com/Lightning-AI/lit-llama/blob/main/lit_llama/model.py // // The tokenizer config can be retrieved from: // https://huggingface.co/hf-internal-testing/llama-tokenizer/raw/main/t...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/repvgg/main.rs
candle-examples/examples/repvgg/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use clap::{Parser, ValueEnum}; use candle::{DType, IndexOp, D}; use candle_nn::{Module, VarBuilder}; use candle_transformers::models::repvgg; #[derive(Clone, Copy, Debug, ValueEnum)] enum Which { A0, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-examples/examples/convmixer/main.rs
candle-examples/examples/convmixer/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use clap::Parser; use candle::{DType, IndexOp, D}; use candle_nn::{Module, VarBuilder}; use candle_transformers::models::convmixer; #[derive(Parser)] struct Args { #[arg(long)] model: Option<Strin...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-ug/src/lib.rs
candle-ug/src/lib.rs
//! This crate is used to re-export the `ug` crate together with `ug-cuda` & `ug-metal` gated //! behind the `cuda` and `metal` features respectively. pub use ug::*; #[cfg(feature = "cuda")] pub mod cuda { pub use ug_cuda::*; } #[cfg(feature = "metal")] pub mod metal { pub use ug_metal::*; }
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/source.rs
candle-metal-kernels/src/source.rs
pub const AFFINE: &str = include_str!("metal_src/affine.metal"); pub const BINARY: &str = include_str!("metal_src/binary.metal"); pub const CAST: &str = include_str!("metal_src/cast.metal"); pub const CONV: &str = include_str!("metal_src/conv.metal"); pub const FILL: &str = include_str!("metal_src/fill.metal"); pub con...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/lib.rs
candle-metal-kernels/src/lib.rs
pub mod err; pub mod kernel; pub mod kernels; pub mod metal; pub mod source; pub mod utils; pub use err::MetalKernelError; pub use kernel::Kernels; pub use kernels::{ affine::*, call_binary_contiguous, call_binary_strided, call_mlx_gemm, cast::*, convolution::*, fill::*, indexing::*, quantized::*, random::*, r...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/tests.rs
candle-metal-kernels/src/tests.rs
use super::*; use crate::metal::{create_command_buffer, CommandSemaphore, Commands}; use core::ffi::c_void; use half::{bf16, f16}; use rand::prelude::SliceRandom; use rand::{rng, Rng}; use std::sync::Arc; use std::thread; fn read_to_vec<T: Clone>(buffer: &Buffer, n: usize) -> Vec<T> { let ptr = buffer.contents() a...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernel.rs
candle-metal-kernels/src/kernel.rs
use crate::source::{ AFFINE, BINARY, CAST, CONV, FILL, INDEXING, MLX_GEMM, MLX_SORT, QUANTIZED, RANDOM, REDUCE, SDPA, SORT, TERNARY, UNARY, }; use crate::utils::get_env_bool; use crate::{ ComputePipeline, ConstantValues, Device, Function, Library, MTLCompileOptions, MTLMathFloatingPointFunctions, MTLMat...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/utils.rs
candle-metal-kernels/src/utils.rs
use crate::metal::{Buffer, CommandBuffer, ComputeCommandEncoder, ComputePipeline}; use crate::MTLSize; use std::ffi::OsStr; use std::ops::Deref; use std::sync::{RwLockReadGuard, RwLockWriteGuard}; /// Most kernels apply similarly across the tensors /// This creates a strategy that uses the maximum amount of threads pe...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/err.rs
candle-metal-kernels/src/err.rs
use crate::kernels::sdpa::SdpaDType; #[derive(thiserror::Error, Debug)] pub enum MetalKernelError { #[error("Command buffer had following error: {0}")] CommandBufferError(String), #[error("Could not lock resource: {0}")] LockError(String), #[error("Error while loading library: {0}")] LoadLibrar...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/encoder.rs
candle-metal-kernels/src/metal/encoder.rs
use crate::metal::{Buffer, CommandSemaphore, CommandStatus, ComputePipeline, MetalResource}; use objc2::{rc::Retained, runtime::ProtocolObject}; use objc2_foundation::{NSRange, NSString}; use objc2_metal::{ MTLBlitCommandEncoder, MTLCommandEncoder, MTLComputeCommandEncoder, MTLResourceUsage, MTLSize, }; use std::{f...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/device.rs
candle-metal-kernels/src/metal/device.rs
use crate::{ Buffer, CommandQueue, ComputePipeline, Function, Library, MTLResourceOptions, MetalKernelError, }; use objc2::{rc::Retained, runtime::ProtocolObject}; use objc2_foundation::NSString; use objc2_metal::{MTLCompileOptions, MTLCreateSystemDefaultDevice, MTLDevice}; use std::{ffi::c_void, ptr}; #[derive(Cl...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/compute_pipeline.rs
candle-metal-kernels/src/metal/compute_pipeline.rs
use objc2::{rc::Retained, runtime::ProtocolObject}; use objc2_metal::MTLComputePipelineState; #[derive(Clone, Debug)] pub struct ComputePipeline { raw: Retained<ProtocolObject<dyn MTLComputePipelineState>>, } unsafe impl Send for ComputePipeline {} unsafe impl Sync for ComputePipeline {} impl ComputePipeline { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/command_buffer.rs
candle-metal-kernels/src/metal/command_buffer.rs
use crate::{BlitCommandEncoder, ComputeCommandEncoder}; use objc2::{rc::Retained, runtime::ProtocolObject}; use objc2_foundation::NSString; use objc2_metal::{MTLCommandBuffer, MTLCommandBufferStatus}; use std::borrow::Cow; use std::sync::{Arc, Condvar, Mutex, MutexGuard}; #[derive(Clone, Debug, PartialEq)] pub enum Co...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/library.rs
candle-metal-kernels/src/metal/library.rs
use crate::MetalKernelError; use objc2::{rc::Retained, runtime::ProtocolObject}; use objc2_foundation::NSString; use objc2_metal::{MTLDataType, MTLFunction, MTLFunctionConstantValues, MTLLibrary}; use std::{ffi::c_void, ptr}; #[derive(Clone, Debug)] pub struct Library { raw: Retained<ProtocolObject<dyn MTLLibrary>...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/commands.rs
candle-metal-kernels/src/metal/commands.rs
use crate::metal::{ BlitCommandEncoder, CommandBuffer, CommandSemaphore, CommandStatus, ComputeCommandEncoder, }; use crate::MetalKernelError; use objc2::{rc::Retained, runtime::ProtocolObject}; use objc2_metal::{MTLCommandBufferStatus, MTLCommandQueue}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/mod.rs
candle-metal-kernels/src/metal/mod.rs
pub mod buffer; pub mod command_buffer; pub mod commands; pub mod compute_pipeline; pub mod device; pub mod encoder; pub mod library; pub use buffer::*; pub use command_buffer::*; pub use commands::*; pub use compute_pipeline::*; pub use device::*; pub use encoder::*; pub use library::*;
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/metal/buffer.rs
candle-metal-kernels/src/metal/buffer.rs
use objc2::{rc::Retained, runtime::ProtocolObject}; use objc2_foundation::NSRange; use objc2_metal::{MTLBuffer, MTLResource}; use std::{collections::HashMap, sync::Arc}; pub type MetalResource = ProtocolObject<dyn MTLResource>; pub type MTLResourceOptions = objc2_metal::MTLResourceOptions; #[derive(Clone, Debug, Hash...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/fill.rs
candle-metal-kernels/src/kernels/fill.rs
use crate::linear_split; use crate::{ set_params, Buffer, ComputeCommandEncoder, Device, EncoderParam, EncoderProvider, Kernels, MetalKernelError, Source, }; use objc2_metal::MTLResourceUsage; pub fn call_const_fill( device: &Device, ep: impl EncoderProvider, kernels: &Kernels, name: &'static s...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/unary.rs
candle-metal-kernels/src/kernels/unary.rs
use crate::kernels::macros::ops; use crate::utils::{BufferOffset, EncoderProvider}; use crate::{get_block_dims, get_tile_size, linear_split}; use crate::{ set_params, Buffer, ComputeCommandEncoder, Device, EncoderParam, Kernels, MetalKernelError, Source, }; use objc2_metal::{MTLResourceUsage, MTLSize}; ops!( ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/random.rs
candle-metal-kernels/src/kernels/random.rs
use crate::linear_split; use crate::utils::EncoderProvider; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::MTLResourceUsage; #[allow(clippy::too_many_arguments)] pub fn call_random_uniform( device: &Device, ep: impl EncoderProvider, kerne...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/sdpa.rs
candle-metal-kernels/src/kernels/sdpa.rs
use crate::utils::EncoderProvider; use crate::{ set_params, Buffer, ComputeCommandEncoder, ConstantValues, Device, EncoderParam, Kernels, MetalKernelError, Source, Value, }; use objc2_metal::{MTLResourceUsage, MTLSize}; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum SdpaDType { BF16, F16, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/sort.rs
candle-metal-kernels/src/kernels/sort.rs
use crate::utils::{BufferOffset, EncoderProvider}; use crate::{set_params, DType, Kernels, MetalKernelError, Source}; use crate::{Buffer, ComputeCommandEncoder, Device, MTLSize, RESOURCE_OPTIONS}; use objc2_metal::MTLResourceUsage; #[allow(clippy::too_many_arguments)] pub fn call_arg_sort( device: &Device, ep:...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/ternary.rs
candle-metal-kernels/src/kernels/ternary.rs
use crate::utils::{BufferOffset, EncoderProvider}; use crate::{get_tile_size, linear_split}; use crate::{ set_params, Buffer, ComputeCommandEncoder, ConstantValues, Device, Kernels, MetalKernelError, Source, Value, }; use objc2_metal::MTLResourceUsage; #[allow(clippy::too_many_arguments)] pub fn call_where_con...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/quantized.rs
candle-metal-kernels/src/kernels/quantized.rs
use crate::utils::EncoderProvider; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::{MTLResourceUsage, MTLSize}; #[derive(Debug, Clone, Copy)] pub enum GgmlDType { Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, Q8_1, Q2K, Q3K, Q4K, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/reduce.rs
candle-metal-kernels/src/kernels/reduce.rs
use crate::linear_split; use crate::utils::{BufferOffset, EncoderProvider}; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::{MTLResourceUsage, MTLSize}; #[allow(clippy::too_many_arguments)] pub fn call_reduce_contiguous( device: &Device, ep: i...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/mlx_gemm.rs
candle-metal-kernels/src/kernels/mlx_gemm.rs
use crate::metal::{Buffer, ComputeCommandEncoder, Device}; use crate::utils::EncoderProvider; use crate::{set_params, ConstantValues, EncoderParam, Kernels, MetalKernelError, Source, Value}; use objc2_metal::{MTLResourceUsage, MTLSize}; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum GemmDType { BF16, ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/macros.rs
candle-metal-kernels/src/kernels/macros.rs
macro_rules! ops{ ($($name:ident),+) => { pub mod contiguous { pub struct Kernel(pub &'static str); $( pub mod $name { use super::Kernel; pub const FLOAT: Kernel = Kernel(concat!(stringify!($name), "_f32")); pub const HALF: Kernel = Kernel(concat!...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/mod.rs
candle-metal-kernels/src/kernels/mod.rs
pub mod affine; pub mod binary; pub mod cast; pub mod convolution; pub mod fill; pub mod indexing; mod macros; pub mod mlx_gemm; pub mod quantized; pub mod random; pub mod reduce; pub mod sdpa; pub mod sort; pub mod ternary; pub mod unary; pub use affine::*; pub use binary::{call_binary_contiguous, call_binary_strided...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/affine.rs
candle-metal-kernels/src/kernels/affine.rs
use crate::utils::{BufferOffset, EncoderProvider}; use crate::{get_tile_size, linear_split}; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::MTLResourceUsage; #[allow(clippy::too_many_arguments)] pub fn call_affine( device: &Device, ep: impl E...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/binary.rs
candle-metal-kernels/src/kernels/binary.rs
use crate::kernels::macros::ops; use crate::utils::{BufferOffset, EncoderProvider}; use crate::{get_tile_size, linear_split}; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::MTLResourceUsage; ops!(badd, bsub, bmul, bdiv, bminimum, bmaximum, eq, ne, le...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/cast.rs
candle-metal-kernels/src/kernels/cast.rs
use crate::utils::{BufferOffset, EncoderProvider}; use crate::{get_tile_size, linear_split}; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::MTLResourceUsage; #[allow(clippy::too_many_arguments)] pub fn call_cast_contiguous( device: &Device, e...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/indexing.rs
candle-metal-kernels/src/kernels/indexing.rs
use crate::linear_split; use crate::utils::{BufferOffset, EncoderProvider}; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::MTLResourceUsage; #[allow(clippy::too_many_arguments)] pub fn call_index_select( device: &Device, ep: impl EncoderProvi...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/src/kernels/convolution.rs
candle-metal-kernels/src/kernels/convolution.rs
use crate::linear_split; use crate::utils::{BufferOffset, EncoderProvider}; use crate::{set_params, Buffer, ComputeCommandEncoder, Device, Kernels, MetalKernelError, Source}; use objc2_metal::MTLResourceUsage; #[allow(clippy::too_many_arguments)] pub fn call_im2col1d_strided( device: &Device, ep: impl EncoderP...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-metal-kernels/examples/metal_benchmarks.rs
candle-metal-kernels/examples/metal_benchmarks.rs
use anyhow::Result; use candle_metal_kernels::{ metal::{create_command_buffer, CommandSemaphore, Device}, GemmDType, RESOURCE_OPTIONS, }; /// This example contains some simple benchmarks so that it's easy to run them in perf etc. use clap::{Parser, Subcommand}; use half::f16; use std::sync::Arc; fn run_gemm(f3...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/tensor-tools/src/main.rs
tensor-tools/src/main.rs
use candle::quantized::{gguf_file, GgmlDType, QTensor}; use candle::{Device, Result}; use clap::{Parser, Subcommand, ValueEnum}; use rayon::prelude::*; #[derive(ValueEnum, Debug, Clone)] enum QuantizationMode { /// The default quantization includes all 2d tensors, except the output tensor which always /// uses...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/func.rs
candle-nn/src/func.rs
//! Layers defined by closures. use candle::{Result, Tensor}; use std::sync::Arc; /// A layer defined by a simple closure. #[derive(Clone)] pub struct Func<'a> { #[allow(clippy::type_complexity)] f: Arc<dyn 'a + Fn(&Tensor) -> Result<Tensor> + Send + Sync>, } impl std::fmt::Debug for Func<'_> { fn fmt(&se...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/cpu_flash_attention.rs
candle-nn/src/cpu_flash_attention.rs
#![allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)] use candle::{Device, Result, Storage, Tensor, WithDType}; use std::sync::LazyLock; use std::{f32, iter::Sum}; use rayon::prelude::*; use rayon::ThreadPool; #[cfg(target_os = "macos")] /// Elevate the thread QoS so macOS prefers running it on Pe...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/lib.rs
candle-nn/src/lib.rs
//! candle-nn //! //! ## Other Crates //! //! Candle consists of a number of crates. This crate holds structs and functions //! that allow you to build and train neural nets. You may wish //! to look at the docs for the other crates which can be found here: //! //! - [candle-core](https://docs.rs/candle-core/). Core Da...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/layer_norm.rs
candle-nn/src/layer_norm.rs
//! Layer Normalization. //! //! This layer applies Layer Normalization over a mini-batch of inputs as described in [`Layer //! Normalization`]. The input is expected to have three dimensions: a batch dimension, a length, //! and a hidden size, the normalization is applied over the last dimension. //! //! # Example //!...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/var_map.rs
candle-nn/src/var_map.rs
//! A `VarMap` is a store that holds named variables. //! use candle::{DType, Device, Result, Shape, Tensor, Var}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; /// A `VarMap` is a store that holds named variables. Variables can be retrieved from the stores /// and new variables can be added by providing...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/activation.rs
candle-nn/src/activation.rs
//! Activation Functions //! use candle::{Result, Tensor}; #[derive(Debug, Clone, Copy, PartialEq, serde::Deserialize, serde::Serialize, Default)] #[serde(rename_all = "lowercase")] pub enum Activation { #[default] #[serde(alias = "gelu")] Gelu, #[serde(alias = "gelu_new")] NewGelu, Relu, R...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/sampling.rs
candle-nn/src/sampling.rs
use candle::{Result, Tensor}; /// Sample according to the Gumbel-Softmax distribution. pub fn gumbel_softmax<D: candle::shape::Dim>( logits: &Tensor, temperature: f64, dim: D, ) -> Result<Tensor> { if temperature <= 0.0 { logits.argmax(dim) } else { // Cast to f32, doing the Gumbel ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/moe.rs
candle-nn/src/moe.rs
// Adapted from https://github.com/guoqingbao/attention.rs/blob/main/src/moe.rs #[cfg(feature = "cuda")] use candle::cuda_backend::kernels::ffi; #[allow(unused_imports)] use candle::quantized::{self, QTensor}; use candle::{Result, Tensor}; #[cfg(feature = "cuda")] pub fn moe_gemm( input: &Tensor, weights: &Ten...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/embedding.rs
candle-nn/src/embedding.rs
//! Embedding Layer. use candle::{Result, Tensor}; #[derive(Clone, Debug)] pub struct Embedding { embeddings: Tensor, hidden_size: usize, } impl Embedding { pub fn new(embeddings: Tensor, hidden_size: usize) -> Self { Self { embeddings, hidden_size, } } pub...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/rnn.rs
candle-nn/src/rnn.rs
//! Recurrent Neural Networks use candle::{DType, Device, IndexOp, Result, Tensor}; /// Trait for Recurrent Neural Networks. #[allow(clippy::upper_case_acronyms)] pub trait RNN { type State: Clone; /// A zero state from which the recurrent network is usually initialized. fn zero_state(&self, batch_dim: us...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/rotary_emb.rs
candle-nn/src/rotary_emb.rs
//! Rotary Embeddings //! use candle::{CpuStorage, Layout, Result, Shape, Tensor, D}; use rayon::prelude::*; /// Interleaved variant of rotary embeddings. /// The x0 and x1 value are interleaved on the n_embd (= head_dim) dimension. /// The resulting y0 and y1 are also interleaved with: /// y0 = x0*cos - x1*sin /// ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/sequential.rs
candle-nn/src/sequential.rs
//! Sequential Layer //! //! A sequential layer used to chain multiple layers and closures. use candle::{Module, Result, Tensor}; /// A sequential layer combining multiple other layers. pub struct Sequential { layers: Vec<Box<dyn Module>>, } /// Creates a new empty sequential layer. pub fn seq() -> Sequential { ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/optim.rs
candle-nn/src/optim.rs
//! Various optimization algorithms. use candle::{Result, Tensor, Var}; /// The interface optimizers should implement. pub trait Optimizer: Sized { type Config: Sized; fn new(vars: Vec<Var>, config: Self::Config) -> Result<Self>; fn step(&mut self, grads: &candle::backprop::GradStore) -> Result<()>; ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/conv.rs
candle-nn/src/conv.rs
//! Convolution Layers. use crate::BatchNorm; use candle::{conv::CudnnFwdAlgo, Result, Tensor}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Conv1dConfig { pub padding: usize, pub stride: usize, pub dilation: usize, pub groups: usize, pub cudnn_fwd_algo: Option<CudnnFwdAlgo>, } impl Def...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/batch_norm.rs
candle-nn/src/batch_norm.rs
//! Batch Normalization. //! //! This layer applies Batch Normalization over a mini-batch of inputs as described in [`Batch //! Normalization`]. The input is expected to have at least three dimensions. //! //! Note that this implementation is for inference only, there is no possibility to track the //! running stats. /...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/init.rs
candle-nn/src/init.rs
//! Variable initialization. // This is based on: // https://github.com/pytorch/pytorch/blob/07107919297db3f8ab37f11c12666b6d6d5f692e/torch/nn/init.py# use candle::{DType, Device, Result, Shape, Tensor, Var}; /// Number of features as input or output of a layer. /// In Kaiming initialization, choosing `FanIn` preserve...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/var_builder.rs
candle-nn/src/var_builder.rs
//! A `VarBuilder` for variable retrieval from models //! //! A `VarBuilder` is used to retrieve variables used by a model. These variables can either come //! from a pre-trained checkpoint, e.g. using `VarBuilder::from_mmaped_safetensors`, or initialized //! for training, e.g. using `VarBuilder::from_varmap`. use crat...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/linear.rs
candle-nn/src/linear.rs
//! Linear layer //! //! This layer applies a linear transformation to the incoming data, `y = x@w.t() + b`. //! The bias is optional. The `forward` method can be used to apply the layer, it supports input //! with a batch dimension (so of shape `(b_sz, in_c)`) or without (of shape `(in_c,)`), the //! output has shape ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/loss.rs
candle-nn/src/loss.rs
//! Loss Calculations //! use candle::{Result, Tensor}; /// The negative log likelihood loss. /// /// Arguments /// /// * [inp]: The input tensor of dimensions `N, C` where `N` is the batch size and `C` the number /// of categories. This is expected to contain log probabilities. /// * [target]: The ground truth labe...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/group_norm.rs
candle-nn/src/group_norm.rs
//! Group Normalization. //! //! This layer applies Group Normalization over a mini-batch of inputs. use candle::{DType, Result, Tensor}; // This group norm version handles both weight and bias so removes the mean. #[derive(Clone, Debug)] pub struct GroupNorm { weight: Tensor, bias: Tensor, eps: f64, n...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/kv_cache.rs
candle-nn/src/kv_cache.rs
//! Cache Implementations //! use candle::{DType, Device, Result, Tensor}; #[derive(Debug, Clone)] pub struct Cache { // all_data is an option on a Tensor, this makes it possible to only create the actual tensor // on the first call where the batch size is easily known. // Also this makes it safe to clone ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/encoding.rs
candle-nn/src/encoding.rs
//! Encoding Utilities. (e.g., one-hot/cold encoding) use candle::{bail, DType, Result, Tensor, WithDType}; /// One-hot/cold encoding. /// /// Given an input tensor of indices, this function returns a tensor of the same shape as the input /// tensor with an additional dimension of the given depth size. The values in ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/src/ops.rs
candle-nn/src/ops.rs
//! Tensor ops. //! use candle::{CpuStorage, DType, Layout, Module, Result, Shape, Tensor, D}; use rayon::prelude::*; /// Applies the softmax function to the input tensor, rescaling the element so that elements on /// a slice of fixed index on dimension `dim` are between 0 and 1 and sum to 1. /// /// ```rust /// use ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
true
huggingface/candle
https://github.com/huggingface/candle/blob/a4ad7c79666958c38b9afc0e0c3e3499ab8991d8/candle-nn/tests/one_hot.rs
candle-nn/tests/one_hot.rs
use candle::{Result, Shape, Tensor}; use candle_nn::encoding::one_hot; #[test] fn test_i64_one_hot() -> Result<()> { let device = candle::Device::Cpu; let indices = Tensor::new(vec![vec![0i64, 2], vec![1, -1]], &device)?; let depth = 4; let on_value = 1.0; let off_value = 0.0; let one_hot = ...
rust
Apache-2.0
a4ad7c79666958c38b9afc0e0c3e3499ab8991d8
2026-01-04T15:42:50.663313Z
false