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-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/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/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/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/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/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/reinforcement-learning/main.rs
#![allow(unused)] #[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 policy_gradient; #[derive(Parser)] struct Args { #[command(subcommand)] command:...
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
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/reinforcement-learning/README.md
# candle-reinforcement-learning Reinforcement Learning examples for candle. This has been tested with `gymnasium` version `0.29.1`. You can install the Python package with: ```bash pip install "gymnasium[accept-rom-license]" ``` In order to run the examples, use the following commands. Note the additional `--package...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/reinforcement-learning/gym_env.rs
#![allow(unused)] //! 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, ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/reinforcement-learning/ddpg.rs
use std::collections::VecDeque; use std::fmt::Display; 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::{distributions::Uniform, thread_rng, Rng}; use super::...
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/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::{distributions::Distribution, rngs::ThreadRng, Rng}; fn new_model...
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/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/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/mixtral/README.md
# candle-mixtral: 8x7b LLM using a sparse mixture of experts. Mixtral-8x7B-v0.1 is a pretrained generative LLM with 56 billion parameters. - [Blog post](https://mistral.ai/news/mixtral-of-experts/) from Mistral announcing the model release. - [Model card](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1) on the Hu...
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/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/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::phi::{Co...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/phi/README.md
# candle-phi: 1.3b and 2.7b LLM with state of the art performance for <10b models. [Phi-1.5](https://huggingface.co/microsoft/phi-1_5) and [Phi-2](https://huggingface.co/microsoft/phi-2) are language models using only 1.3 and 2.7 billion parameters but with state of the art performance compared to models with up to 10...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/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, ...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/repvgg/README.md
# candle-repvgg [RepVGG: Making VGG-style ConvNets Great Again](https://arxiv.org/abs/2101.03697). This candle implementation uses a pre-trained RepVGG network for inference. The classification head has been trained on the ImageNet dataset and returns the probabilities for the top-5 classes. ## Running an example `...
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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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::Tensor; use candle_transformers::generation::LogitsProcessor; use c...
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/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; #[rus...
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/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
hf_public_repos/candle/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...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/mobileone/README.md
# candle-mobileone [MobileOne: An Improved One millisecond Mobile Backbone](https://arxiv.org/abs/2206.04040). This candle implementation uses a pre-trained MobileOne network for inference. The classification head has been trained on the ImageNet dataset and returns the probabilities for the top-5 classes. ## Runnin...
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/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/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/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/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/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/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/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/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/mamba-minimal/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}; mod model; use model::{Config, Model}; use candle::{DType, Device, Module, Tensor}; use candle_examples::token_output_stream::TokenOutputSt...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/mamba-minimal/README.md
# candle-mamba-minimal: minimal implementation of Mamba This is based on [mamba-minimal](https://github.com/johnma2006/mamba-minimal). ## Running the example ```bash $ cargo run --example mamba-minimal --release -- --prompt "Mamba is the" Mamba is the most popular and best-selling game in the world. It has been down...
0
hf_public_repos/candle/candle-examples/examples
hf_public_repos/candle/candle-examples/examples/mamba-minimal/model.rs
/// This follows the lines of: /// https://github.com/johnma2006/mamba-minimal/blob/master/model.py /// Simple, minimal implementation of Mamba in one file of PyTorch. use candle::{IndexOp, Module, Result, Tensor, D}; use candle_nn::{RmsNorm, VarBuilder}; use candle_transformers::models::with_tracing::{linear, linear_...
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/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/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/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/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/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
hf_public_repos/candle/candle-examples/src/token_output_stream.rs
use candle::Result; /// This is a wrapper around a tokenizer to ensure that tokens can be returned to the user in a /// streaming way rather than having to wait for the full decoding. pub struct TokenOutputStream { tokenizer: tokenizers::Tokenizer, tokens: Vec<u32>, prev_index: usize, current_index: us...
0
hf_public_repos/candle/candle-examples
hf_public_repos/candle/candle-examples/src/lib.rs
pub mod coco_classes; pub mod imagenet; pub mod token_output_stream; use candle::utils::{cuda_is_available, metal_is_available}; use candle::{Device, Result, Tensor}; pub fn device(cpu: bool) -> Result<Device> { if cpu { Ok(Device::Cpu) } else if cuda_is_available() { Ok(Device::new_cuda(0)?) ...
0
hf_public_repos/candle/candle-examples
hf_public_repos/candle/candle-examples/src/coco_classes.rs
pub const NAMES: [&str; 80] = [ "person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", ...
0
hf_public_repos/candle/candle-examples
hf_public_repos/candle/candle-examples/src/imagenet.rs
use candle::{Device, Result, Tensor}; /// Loads an image from disk using the image crate, this returns a tensor with shape /// (3, 224, 224). imagenet normalization is applied. pub fn load_image224<P: AsRef<std::path::Path>>(p: P) -> Result<Tensor> { let img = image::io::Reader::open(p)? .decode() ...
0
hf_public_repos/candle
hf_public_repos/candle/.cargo/config.toml
[build] rustflags = ["-C", "target-cpu=native"] [target.wasm32-unknown-unknown] rustflags = ["-C", "target-feature=+simd128"] [target.x86_64-apple-darwin] rustflags = ["-C", "target-feature=-avx,-avx2"]
0
hf_public_repos/candle
hf_public_repos/candle/.vscode/settings.json
{ "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" }, "python.formatting.provider": "none", "python.testing.pytestArgs": [ "candle-pyo3" ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true }
0
hf_public_repos/candle
hf_public_repos/candle/candle-book/book.toml
[book] authors = ["Nicolas Patry"] language = "en" multilingual = false src = "src" title = "Candle Documentation"
0
hf_public_repos/candle
hf_public_repos/candle/candle-book/Cargo.toml
[package] name = "candle-book" 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/candle-book
hf_public_repos/candle/candle-book/src/lib.rs
#[cfg(test)] pub mod simplified; #[cfg(test)] mod tests { use anyhow::Result; use candle::{DType, Device, Tensor}; use parquet::file::reader::SerializedFileReader; // NOTE: Waiting on https://github.com/rust-lang/mdBook/pull/1856 #[rustfmt::skip] #[tokio::test] async fn book_hub_1() { // A...
0
hf_public_repos/candle/candle-book
hf_public_repos/candle/candle-book/src/README.md
# Introduction {{#include ../../README.md:features}} This book will introduce step by step how to use `candle`.
0
hf_public_repos/candle/candle-book
hf_public_repos/candle/candle-book/src/chapter_1.md
# Chapter 1
0
hf_public_repos/candle/candle-book
hf_public_repos/candle/candle-book/src/simplified.rs
//! #A simplified example in Rust of training a neural network and then using it based on the Candle Framework by Hugging Face. //! Author: Evgeny Igumnov 2023 igumnovnsk@gmail.com //! This program implements a neural network to predict the winner of the second round of elections based on the results of the first round...
0
hf_public_repos/candle/candle-book
hf_public_repos/candle/candle-book/src/SUMMARY.md
# Summary [Introduction](README.md) # User Guide - [Installation](guide/installation.md) - [Hello World - MNIST](guide/hello_world.md) - [PyTorch cheatsheet](guide/cheatsheet.md) # Reference Guide - [Running a model](inference/inference.md) - [Using the hub](inference/hub.md) - [Error management](error_manage....
0
hf_public_repos/candle/candle-book
hf_public_repos/candle/candle-book/src/error_manage.md
# Error management You might have seen in the code base a lot of `.unwrap()` or `?`. If you're unfamiliar with Rust check out the [Rust book](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html) for more information. What's important to know though, is that if you want to know *where* a particu...
0
hf_public_repos/candle/candle-book/src
hf_public_repos/candle/candle-book/src/advanced/mkl.md
# Using MKL
0