repo_id
stringlengths
15
89
file_path
stringlengths
27
180
content
stringlengths
1
2.23M
__index_level_0__
int64
0
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim192_fp16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::half_t, 192>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::half_t; // BOOL...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim96_fp16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::half_t, 96>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::half_t; // BOOL_...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/kernel_traits.h
/****************************************************************************** * Copyright (c) 2023, Tri Dao. ******************************************************************************/ #pragma once #include "cute/algorithm/copy.hpp" #include "cutlass/cutlass.h" #include "cutlass/layout/layout.h" #include <cu...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim64_bf16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::bfloat16_t, 64>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::bfloat16_t; // ...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim160_bf16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::bfloat16_t, 160>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::bfloat16_t; // ...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim256_fp16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" template<> void run_mha_fwd_<cutlass::half_t, 256>(Flash_fwd_params &params, cudaStream_t stream) { run_mha_fwd_hdim256<cutlass::half_t>(params, stream); }...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/static_switch.h
// Inspired by // https://github.com/NVIDIA/DALI/blob/main/include/dali/core/static_switch.h // and https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/Dispatch.h #pragma once /// @param COND - a boolean expression to switch by /// @param CONST_NAME - a name given for the constexpr bool variable. /// @...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash.h
/****************************************************************************** * Copyright (c) 2023, Tri Dao. ******************************************************************************/ #pragma once #include <cuda.h> #include <vector> // #ifdef OLD_GENERATOR_PATH // #include <ATen/CUDAGeneratorImpl.h> // #els...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim192_bf16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::bfloat16_t, 192>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::bfloat16_t; // ...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim96_bf16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::bfloat16_t, 96>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::bfloat16_t; // ...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/philox.cuh
// Pytorch also has an implementation of Philox RNG: https://github.com/pytorch/pytorch/blob/8ca3c881db3e3510fcb7725389f6a0633c9b992c/torch/csrc/jit/tensorexpr/cuda_random.h #pragma once // Philox CUDA. namespace flash { struct ull2 { unsigned long long x; unsigned long long y; }; inline __device__ uint2 mul...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim64_fp16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::half_t, 64>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::half_t; // if (p...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim256_bf16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" template<> void run_mha_fwd_<cutlass::bfloat16_t, 256>(Flash_fwd_params &params, cudaStream_t stream) { run_mha_fwd_hdim256<cutlass::bfloat16_t>(params, st...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/kernels/flash_fwd_hdim160_fp16_sm80.cu
// Copyright (c) 2023, Tri Dao. // Splitting the different head dimensions to different files to speed up compilation. #include "flash_fwd_launch_template.h" // template<> // void run_mha_fwd_<cutlass::half_t, 160>(Flash_fwd_params &params, cudaStream_t stream) { // using elem_type = cutlass::half_t; // BOOL...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/tests/flash_attn_tests.rs
use anyhow::Result; use candle::{DType, Device, IndexOp, Tensor, D}; fn to_vec3_round(t: Tensor, digits: i32) -> Result<Vec<Vec<Vec<f32>>>> { let b = 10f32.powi(digits); let t = t.to_vec3::<f32>()?; let t = t .iter() .map(|t| { t.iter() .map(|t| t.iter().map(|t| ...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/src/lib.rs
mod ffi; use candle::backend::BackendStorage; use candle::cuda_backend::cudarc::driver::DevicePtr; use candle::cuda_backend::WrapErr; use candle::{CpuStorage, Layout, Result, Shape, Tensor}; use half::{bf16, f16}; pub struct FlashAttn { pub softmax_scale: f32, pub causal: bool, } fn round_multiple(x: usize, ...
0
hf_public_repos/candle/candle-flash-attn
hf_public_repos/candle/candle-flash-attn/src/ffi.rs
use core::ffi::{c_int, c_void}; extern "C" { pub(crate) fn run_mha( q_ptr: *const c_void, k_ptr: *const c_void, v_ptr: *const c_void, o_ptr: *const c_void, softmax_lse_ptr: *const c_void, cu_seqlens_q_ptr: *const i32, cu_seqlens_k_ptr: *const i32, q_...
0
hf_public_repos/candle
hf_public_repos/candle/candle-examples/Cargo.toml
[package] name = "candle-examples" version.workspace = true edition.workspace = true description.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true license.workspace = true readme = "README.md" [dependencies] accelerate-src = { workspace = true, optional = true } candle ...
0
hf_public_repos/candle
hf_public_repos/candle/candle-examples/build.rs
#![allow(unused)] use anyhow::{Context, Result}; use std::io::Write; use std::path::PathBuf; struct KernelDirectories { kernel_dir: &'static str, rust_target: &'static str, include_dirs: &'static [&'static str], } const DIRS: [KernelDirectories; 1] = [KernelDirectories { kernel_dir: "examples/custom-o...
0
hf_public_repos/candle
hf_public_repos/candle/candle-examples/README.md
# candle-examples
0
hf_public_repos/candle/candle-examples
hf_public_repos/candle/candle-examples/examples/onnx_basics.rs
use anyhow::Result; use candle::{Device, Tensor}; use clap::{Parser, Subcommand}; #[derive(Subcommand, Debug, Clone)] enum Command { Print { #[arg(long)] file: String, }, SimpleEval { #[arg(long)] file: String, }, } #[derive(Parser, Debug)] #[command(author, version, a...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/custom-ops/main.rs
// This example illustrates how to implement custom operations. These operations can provide their // own forward pass (CPU and GPU versions) as well as their backward pass. // // In this example we add the RMS normalization operation and implement it for f32. #[cfg(feature = "mkl")] extern crate intel_mkl_src; #[all...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/custom-ops/cuda_kernels.rs
#[rustfmt::skip] pub const LAYERNORM_KERNELS: &str = include_str!(concat!(env!("OUT_DIR"), "/examples/custom-ops/kernels//layernorm_kernels.ptx"));
0
hf_public_repos/candle/candle-examples/examples/custom-ops
hf_public_repos/candle/candle-examples/examples/custom-ops/kernels/reduction_utils.cuh
/* * Adapted from * https://github.com/NVIDIA/FasterTransformer/blob/release/v5.3_tag/src/fastertransformer/kernels/reduce_kernel_utils.cuh * Copyright (c) 2023, The vLLM team. * Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); ...
0
hf_public_repos/candle/candle-examples/examples/custom-ops
hf_public_repos/candle/candle-examples/examples/custom-ops/kernels/layernorm_kernels.cu
#include <stdint.h> #include "reduction_utils.cuh" template <typename scalar_t> __device__ void rms_norm_kernel(scalar_t *__restrict__ out, // [num_tokens, hidden_size] const scalar_t *__restrict__ input, // [num_tokens, hidden_size] const float epsilon, const uint32_t num_token...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/quantized-t5/README.md
# candle-quantized-t5 ## Seq2Seq example This example uses a quantized version of the t5 model. ```bash $ cargo run --example quantized-t5 --release -- --prompt "translate to German: A beautiful candle." ... Eine schöne Kerze. ``` ## Generating Quantized weight files The weight file is automatically retrieved fro...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/quantized-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::quantized_t5 as t5; use anyhow::{Error as E, Result}; use candle::{Device, Tensor}; use candle_transformers::generation::LogitsP...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/llama2-c/training.rs
use crate::model::{Cache, Config, Llama}; use candle::{DType, Device, Result}; use candle_datasets::nlp::tinystories::{Dataset, DatasetRandomIter}; use candle_nn::Optimizer; fn valid_loss( dataset: &Dataset, model: &Llama, args: &crate::TrainingCmd, device: &Device, ) -> Result<f64> { let iter = Da...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/llama2-c/main.rs
// https://github.com/karpathy/llama2.c #[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use candle_transformers::models::llama2_c as model; use candle_transformers::models::llama2_c_weights as weights; use candle_transformers::models::quantized_llama2_c...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/marian-mt/convert_slow_tokenizer.py
# coding=utf-8 # Copyright 2018 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/marian-mt/README.md
# candle-marian-mt `marian-mt` is a neural machine translation model. In this example it is used to translate text from French to English. See the associated [model card](https://huggingface.co/Helsinki-NLP/opus-mt-tc-big-fr-en) for details on the model itself. ## Running an example ```bash cargo run --example maria...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/marian-mt/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::Error as E; use clap::{Parser, ValueEnum}; use candle::{DType, Tensor}; use candle_examples::token_output_stream::TokenOutputStream; use candle_nn::VarBuilder; use candle_transformers::models::...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/jina-bert/README.md
# candle-jina-bert Jina-Bert is a general large language model with a context size of 8192, [model card](https://huggingface.co/jinaai/jina-embeddings-v2-base-en). In this example it can be used for two different tasks: - Compute sentence embeddings for a prompt. - Compute similarities between a set of sentences. ##...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/jina-bert/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle_transformers::models::jina_bert::{BertModel, Config}; use anyhow::Error as E; use candle::{DType, Module, Tensor}; use candle_nn::VarBuilder; use clap::Parser; #[derive(Parser, Debug)] #[comman...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/onnx/README.md
## Using ONNX models in Candle This example demonstrates how to run ONNX based models in Candle, the model being used here is a small sequeezenet variant. You can run the example with the following command: ```bash cargo run --example squeezenet-onnx --release -- --image candle-examples/examples/yolo-v8/assets/bike....
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/onnx/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle::{IndexOp, D}; use clap::{Parser, ValueEnum}; #[derive(Clone, Copy, Debug, ValueEnum)] enum Which { SqueezeNet, EfficientNet, } #[derive(Parser)] struct Args { #[arg(long)] imag...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/segment-anything/README.md
# candle-segment-anything: Segment-Anything Model This example is based on Meta AI [Segment-Anything Model](https://github.com/facebookresearch/segment-anything). This model provides a robust and fast image segmentation pipeline that can be tweaked via some prompting (requesting some points to be in the target mask, r...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/segment-anything/main.rs
//! SAM: Segment Anything Model //! https://github.com/facebookresearch/segment-anything #[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle::DType; use candle_nn::VarBuilder; use candle_transformers::models::segment_anything::sam; use clap::Pars...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/bigcode/README.md
# candle-starcoder: code generation model [StarCoder/BigCode](https://huggingface.co/bigcode/starcoderbase-1b) is a LLM model specialized to code generation. The initial model was trained on 80 programming languages. ## Running some example ```bash cargo run --example bigcode --release -- --prompt "fn fact(n: u64) -...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/bigcode/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::bigcode::{Config, GPTBigCode}; use candle::{DType, Device, Tensor}; use candle_nn::VarBuilder; use candle_transformers:...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/wuerstchen/README.md
# candle-wuerstchen: Efficient Pretraining of Text-to-Image Models ![anthropomorphic cat dressed as a fire fighter](./assets/cat.jpg) The `wuerstchen` example is a port of the [diffusers implementation](https://github.com/huggingface/diffusers/tree/19edca82f1ff194c07317369a92b470dbae97f34/src/diffusers/pipelines/wuer...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/wuerstchen/main.rs
#[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use candle_transformers::models::stable_diffusion; use candle_transformers::models::wuerstchen; use anyhow::{Error as E, Result}; use candle::{DType, Device, IndexOp, Tensor}; use clap::Parser; use tokeniz...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/quantized/README.md
# candle-quantized-llama: Fast Inference of quantized LLaMA models This example provides a quantized LLaMA model similar to [llama.cpp](https://github.com/ggerganov/llama.cpp). This is based on candle built-in quantization methods. Supported features include: - 2-bit, 3-bit, 4-bit, 5-bit, 6-bit and 8-bit integer quan...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/quantized/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::quantized::{ggml_file, gguf_file}; use candle::{Device, Tensor}; use candle_transformers::generation::LogitsProcess...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/resnet/export_models.py
# This script exports pre-trained model weights in the safetensors format. import numpy as np import torch import torchvision from safetensors import torch as stt m = torchvision.models.resnet50(pretrained=True) stt.save_file(m.state_dict(), 'resnet50.safetensors') m = torchvision.models.resnet101(pretrained=True) stt...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/resnet/README.md
# candle-resnet A candle implementation of inference using a pre-trained [ResNet](https://arxiv.org/abs/1512.03385). This uses a classification head trained on the ImageNet dataset and returns the probabilities for the top-5 classes. ## Running an example ``` $ cargo run --example resnet --release -- --image tiger.j...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/resnet/main.rs
#[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::resnet; use clap::{Parser, ValueEnum}; #[derive(Clone, Copy, Debug, ValueEnum)] enum Which { #[val...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/replit-code/README.md
# candle-replit-code: code completion specialized model. [replit-code-v1_5-3b](https://huggingface.co/replit/replit-code-v1_5-3b) is a language model specialized for code completion. This model uses 3.3B parameters in `bfloat16` (so the GPU version will only work on recent nvidia cards). ## Running some example ```b...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/t5/README.md
# candle-t5 ## Encoder-decoder example: ```bash $ cargo run --example t5 --release -- --model-id "t5-small" --prompt "translate to German: A beautiful candle." --decode ... Eine schöne Kerze. 9 tokens generated (2.42 token/s) ``` Variants such as [flan-t5](https://huggingface.co/google/flan-t5-small), [flan-ul2](ht...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/yolo-v3/extract-weights.py
def remove_prefix(text, prefix): return text[text.startswith(prefix) and len(prefix):] nps = {} for k, v in model.state_dict().items(): k = remove_prefix(k, 'module_list.') nps[k] = v.detach().numpy() np.savez('yolo-v3.ot', **nps)
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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 ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/yolo-v3/yolo-v3.cfg
[net] # Testing batch=1 subdivisions=1 # Training # batch=64 # subdivisions=16 width= 416 height = 416 channels=3 momentum=0.9 decay=0.0005 angle=0 saturation = 1.5 exposure = 1.5 hue=.1 learning_rate=0.001 burn_in=1000 max_batches = 500200 policy=steps steps=400000,450000 scales=.1,.1 [convolutional] batch_normaliz...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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,...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/mnist-training/main.rs
// This should reach 91.5% accuracy. #[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use clap::{Parser, ValueEnum}; use rand::prelude::*; use candle::{DType, Result, Tensor, D}; use candle_nn::{loss, ops, Conv2d, Linear, Module, ModuleT, Optimizer, VarB...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/blip/README.md
# candle-blip The [blip-image-captioning](https://huggingface.co/Salesforce/blip-image-captioning-base) model can generate captions for an input image. ## Running on an example ```bash cargo run --example blip --release -- --image candle-examples/examples/yolo-v8/assets/bike.jpg ``` ``` Running on CPU, to run on GP...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/blip/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::Error as E; use clap::Parser; use candle::{DType, Device, Result, Tensor}; use candle_examples::token_output_stream::TokenOutputStream; use candle_nn::VarBuilder; use candle_transformers::model...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/stable-diffusion/README.md
# candle-stable-diffusion: A Diffusers API in Rust/Candle ![rusty robot holding a candle](./assets/stable-diffusion-xl.jpg) _A rusty robot holding a fire torch in its hand_, generated by Stable Diffusion XL using Rust and [candle](https://github.com/huggingface/candle). The `stable-diffusion` example is a conversion...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/stable-diffusion/main.rs
#[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use candle_transformers::models::stable_diffusion; use anyhow::{Error as E, Result}; use candle::{DType, Device, IndexOp, Module, Tensor, D}; use clap::Parser; use tokenizers::Tokenizer; #[derive(Parser)]...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/yi/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::yi::{Config, Model}; use candle::{DType, Device, Tensor}; use candle_examples::token_output_stream::TokenO...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/vit/README.md
# candle-vit Vision Transformer (ViT) model implementation following the lines of [vit-base-patch16-224](https://huggingface.co/google/vit-base-patch16-224) This uses a classification head trained on the ImageNet dataset and returns the probabilities for the top-5 classes. ## Running an example ``` $ cargo run --exa...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/vit/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::VarBuilder; use candle_transformers::models::vit; #[derive(Parser)] struct Args { #[arg(long)] model: Option<String>, #[arg(l...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/bert/README.md
# candle-bert Bert is a general large language model. In this example it can be used for two different tasks: - Compute sentence embeddings for a prompt. - Compute similarities between a set of sentences. ## Sentence embeddings Bert is used to compute the sentence embeddings for a prompt. The model weights are down...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/bert/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle_transformers::models::bert::{BertModel, Config, HiddenAct, DTYPE}; use anyhow::{Error as E, Result}; use candle::Tensor; use candle_nn::VarBuilder; use clap::Parser; use hf_hub::{api::sync::Api, ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/musicgen/nn.rs
use candle::Result; use candle_nn::{Conv1d, Conv1dConfig, VarBuilder}; // Applies weight norm for inference by recomputing the weight tensor. This // does not apply to training. // https://pytorch.org/docs/stable/generated/torch.nn.utils.weight_norm.html pub fn conv1d_weight_norm( in_c: usize, out_c: usize, ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/musicgen/musicgen_model.rs
use crate::encodec_model; use candle::{DType, Device, Result, Tensor, D}; use candle_nn::{ embedding, layer_norm, linear_no_bias, Activation, Embedding, LayerNorm, Linear, Module, VarBuilder, }; use candle_transformers::models::t5; // https://github.com/huggingface/transformers/blob/cd4584e3c809bb9e1392ccd3fe3...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/musicgen/main.rs
#![allow(dead_code)] // https://huggingface.co/facebook/musicgen-small/tree/main // https://github.com/huggingface/transformers/blob/cd4584e3c809bb9e1392ccd3fe38b40daba5519a/src/transformers/models/musicgen/modeling_musicgen.py // TODO: Add an offline mode. // TODO: Add a KV cache. #[cfg(feature = "mkl")] extern crate...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/musicgen/encodec_model.rs
use crate::nn::conv1d_weight_norm; use candle::{DType, IndexOp, Module, Result, Tensor}; use candle_nn::{conv1d, Conv1d, Conv1dConfig, VarBuilder}; // Encodec Model // https://github.com/huggingface/transformers/blob/main/src/transformers/models/encodec/modeling_encodec.py #[derive(Debug, Clone, PartialEq)] enum Norm...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/stable-lm/README.md
# candle-stable-lm StableLM-3B-4E1T is a 3 billion parameter decoder-only language model pre-trained on 1 trillion tokens of diverse English and code datasets for 4 epochs. See the [HuggingFace Hub Model Card](https://huggingface.co/stabilityai/stablelm-3b-4e1t). Note that this model is gated so you will have to requ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/stable-lm/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::quantized_stable_lm::Model as QStableLM; use candle_transformers::models::stable_lm::{Config, Model as StableLM}; use c...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/trocr/image_processor.rs
use image::{DynamicImage, ImageBuffer}; use serde::Deserialize; use std::collections::HashMap; use candle::{DType, Device, Result, Tensor}; #[derive(Debug, Clone, PartialEq, Deserialize)] pub struct ProcessorConfig { do_resize: bool, height: u32, width: u32, do_rescale: bool, do_normalize: bool, ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/trocr/readme.md
# candle-trocr `TrOCR` is a transformer OCR Model. In this example it is used to transcribe image text. See the associated [model card](https://huggingface.co/microsoft/trocr-base-printed) for details on the model itself. ## Running an example ```bash cargo run --example trocr --release -- --which base --cpu --imag...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/trocr/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use anyhow::Error as E; use clap::{Parser, ValueEnum}; use candle::{DType, Tensor}; use candle_examples::token_output_stream::TokenOutputStream; use candle_nn::VarBuilder; use candle_transformers::models::...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/distilbert/README.md
# candle-distilbert DistilBert is a distiled version of the Bert model. ## Sentence embeddings DistilBert is used to compute the sentence embeddings for a prompt. The model weights are downloaded from the hub on the first run. ```bash cargo run --example distilbert --release -- --prompt "Here is a test sentence" >...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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, DistilBertModel, DTYPE}; use anyhow::{Error as E, Result}; use candle::{Device, Tensor}; use candle_nn::VarBuilder; use clap::Parser; use hf_hub::{api::...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/falcon/README.md
# candle-falcon Falcon is a general large language model.
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/falcon/main.rs
// TODO: Add an offline mode. #[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use anyhow::{Error as E, Result}; use candle::{DType, Device, Tensor}; use candle_nn::VarBuilder; use candle_transformers::generation::LogitsProcessor; use clap::Parser; use h...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/llama_multiprocess/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/llama_multiprocess/model.rs
use candle::backend::BackendStorage; use candle::{CpuStorage, CustomOp1, DType, Device, IndexOp, Layout, Result, Shape, Tensor, D}; use candle_nn::{Embedding, Linear, Module, RmsNorm}; use cudarc::nccl::safe::{Comm, ReduceOp}; use half::f16; use serde::Deserialize; use std::rc::Rc; use std::sync::{Arc, Mutex}; use sup...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/phi/README.md
# candle-phi: 1.3b LLM with state of the art performance for <10b models. [Phi-1.5](https://huggingface.co/microsoft/phi-1_5) is a language model using only 1.3 billion parameters but with state of the art performance compared to models with up to 10 billion parameters. The candle implementation provides both the sta...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/phi/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::mixformer::{Config, MixFormerSequentialForCausalLM as MixFormer}; use candle_transformers::models::quantize...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/yolo-v8/README.md
# candle-yolo-v8: Object Detection and Pose Estimation This is a port of [Ultralytics YOLOv8](https://github.com/ultralytics/ultralytics). The implementation is based on the [tinygrad version](https://github.com/tinygrad/tinygrad/blob/master/examples/yolov8.py) and on the model architecture described in this [issue](h...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/yolo-v8/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; mod model; use model::{Multiples, YoloV8, YoloV8Pose}; use candle::{DType, Device, IndexOp, Result, Tensor}; use candle_nn::{Module, VarBuilder}; use candle_transformers::object_detection::{non_maximum_sup...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/yolo-v8/model.rs
use candle::{DType, IndexOp, Result, Tensor, D}; use candle_nn::{batch_norm, conv2d, conv2d_no_bias, Conv2d, Conv2dConfig, Module, VarBuilder}; #[derive(Clone, Copy, PartialEq, Debug)] pub struct Multiples { depth: f64, width: f64, ratio: f64, } impl Multiples { pub fn n() -> Self { Self { ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/mistral/README.md
# candle-mistral: 7b LLM with Apache 2.0 licensed weights Mistral-7B-v0.1 is a pretrained generative LLM with 7 billion parameters. It outperforms all the publicly available 13b models as of 2023-09-28. Weights (and the original Python model code) are released under the permissive Apache 2.0 license. - [Blog post](ht...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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:...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/vgg/README.md
## VGG Model Implementation This example demonstrates the implementation of VGG models (VGG13, VGG16, VGG19) using the Candle library. The VGG models are defined in `candle-transformers/src/models/vgg.rs`. The main function in `candle-examples/examples/vgg/main.rs` loads an image, selects the VGG model based on the p...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/vgg/main.rs
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle::{DType, IndexOp, D}; use candle_nn::{ModuleT, VarBuilder}; use candle_transformers::models::vgg::{Models, Vgg}; use clap::{Parser, ValueEnum}; #[derive(Clone, Copy, Debug, ValueEnum)] enum Whic...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/dinov2/README.md
# candle-dinov2 [DINOv2](https://github.com/facebookresearch/dinov2) is a computer vision model. In this example, it is used as an ImageNet classifier: the model returns the probability for the image to belong to each of the 1000 ImageNet categories. ## Running some example ```bash cargo run --example dinov2 --relea...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/dinov2/main.rs
//! DINOv2: Learning Robust Visual Features without Supervision //! https://github.com/facebookresearch/dinov2 #[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 c...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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"), ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/whisper/extract_weights.py
# Get the checkpoint from # https://openaipublic.azureedge.net/main/whisper/models/d3dd57d32accea0b295c96e26691aa14d8822fac7d9d27d5dc00b4ca2826dd03/tiny.en.pt import torch from safetensors.torch import save_file data = torch.load("tiny.en.pt") weights = {} for k, v in data["model_state_dict"].items(): weights[k] ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/whisper/README.md
# candle-whisper: speech recognition An implementation of [OpenAI Whisper](https://github.com/openai/whisper) using candle. Whisper is a general purpose speech recognition model, it can be used to convert audio files (in the `.wav` format) to text. Supported features include language detection as well as multilingual ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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};...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/reinforcement-learning/vec_gym_env.rs
#![allow(unused)] //! Vectorized version of the gym environment. use candle::{DType, Device, Result, Tensor}; use pyo3::prelude::*; use pyo3::types::PyDict; #[derive(Debug)] pub struct Step { pub obs: Tensor, pub reward: Tensor, pub is_done: Tensor, } pub struct VecGymEnv { env: PyObject, action_s...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/reinforcement-learning/atari_wrappers.py
import gymnasium as gym import numpy as np from collections import deque from PIL import Image from multiprocessing import Process, Pipe # atari_wrappers.py class NoopResetEnv(gym.Wrapper): def __init__(self, env, noop_max=30): """Sample initial states by taking random number of no-ops on reset. No...
0