text
stringlengths
5
409k
id
stringlengths
14
178
metadata
dict
__index_level_0__
int64
0
572
# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # 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 r...
transformers/tests/models/yolos/test_modeling_yolos.py/0
{ "file_path": "transformers/tests/models/yolos/test_modeling_yolos.py", "repo_id": "transformers", "token_count": 6820 }
487
# Copyright 2020 The HuggingFace Team. All rights reserved. # # 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 applicabl...
transformers/tests/pipelines/test_pipelines_table_question_answering.py/0
{ "file_path": "transformers/tests/pipelines/test_pipelines_table_question_answering.py", "repo_id": "transformers", "token_count": 14916 }
488
# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # 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 requir...
transformers/tests/quantization/autoawq/test_awq.py/0
{ "file_path": "transformers/tests/quantization/autoawq/test_awq.py", "repo_id": "transformers", "token_count": 8896 }
489
# coding=utf-8 # Copyright 2025 The HuggingFace Team. All rights reserved. # # 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 requir...
transformers/tests/quantization/finegrained_fp8/test_fp8.py/0
{ "file_path": "transformers/tests/quantization/finegrained_fp8/test_fp8.py", "repo_id": "transformers", "token_count": 4642 }
490
import os import sys import unittest ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) sys.path.append(os.path.join(ROOT_DIR, "utils")) import create_dependency_mapping # noqa: E402 # This is equivalent to `all` in the current library state (as of 09/01/2025) MODEL_ROOT = os....
transformers/tests/repo_utils/modular/test_conversion_order.py/0
{ "file_path": "transformers/tests/repo_utils/modular/test_conversion_order.py", "repo_id": "transformers", "token_count": 1424 }
491
import json import os import subprocess import unittest from ast import literal_eval import pytest from parameterized import parameterized, parameterized_class from . import is_sagemaker_available if is_sagemaker_available(): from sagemaker import Session, TrainingJobAnalytics from sagemaker.huggingface imp...
transformers/tests/sagemaker/test_multi_node_model_parallel.py/0
{ "file_path": "transformers/tests/sagemaker/test_multi_node_model_parallel.py", "repo_id": "transformers", "token_count": 2103 }
492
# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # 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 law or ag...
transformers/tests/tokenization/test_tokenization_fast.py/0
{ "file_path": "transformers/tests/tokenization/test_tokenization_fast.py", "repo_id": "transformers", "token_count": 5886 }
493
# Copyright 2024 The HuggingFace Team. All rights reserved. # # 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 applicabl...
transformers/tests/utils/import_structures/import_structure_register_with_comments.py/0
{ "file_path": "transformers/tests/utils/import_structures/import_structure_register_with_comments.py", "repo_id": "transformers", "token_count": 517 }
494
# Copyright 2020 The HuggingFace Team. All rights reserved. # # 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 applicabl...
transformers/tests/utils/test_file_utils.py/0
{ "file_path": "transformers/tests/utils/test_file_utils.py", "repo_id": "transformers", "token_count": 2005 }
495
# Copyright 2020 The HuggingFace Team. All rights reserved. # # 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 applicabl...
transformers/tests/utils/test_offline.py/0
{ "file_path": "transformers/tests/utils/test_offline.py", "repo_id": "transformers", "token_count": 2964 }
496
# coding=utf-8 # Copyright 2020 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...
transformers/utils/check_inits.py/0
{ "file_path": "transformers/utils/check_inits.py", "repo_id": "transformers", "token_count": 6585 }
497
# coding=utf-8 # Copyright 2024 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...
transformers/utils/process_test_artifacts.py/0
{ "file_path": "transformers/utils/process_test_artifacts.py", "repo_id": "transformers", "token_count": 939 }
498
# Judges <Tip warning={true}> TRL Judges is an experimental API which is subject to change at any time. </Tip> TRL provides judges to easily compare two completions. Make sure to have installed the required dependencies by running: ```bash pip install trl[judges] ``` ## Using the provided judges TRL provides se...
trl/docs/source/judges.md/0
{ "file_path": "trl/docs/source/judges.md", "repo_id": "trl", "token_count": 732 }
499
# Research projects that use TRL Welcome to the research projects folder! Here you can find the scripts used for some research projects that used TRL and maintained by the developers and the community (LM de-toxification, Stack-Llama, etc.). Check out the READMEs in the subfolders for more information! - [De-detoxify...
trl/examples/research_projects/README.md/0
{ "file_path": "trl/examples/research_projects/README.md", "repo_id": "trl", "token_count": 189 }
500
# Copyright 2025 The HuggingFace Team. All rights reserved. # # 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 applicabl...
trl/examples/scripts/alignprop.py/0
{ "file_path": "trl/examples/scripts/alignprop.py", "repo_id": "trl", "token_count": 2005 }
501
# Copyright 2025 The HuggingFace Team. All rights reserved. # # 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 applicabl...
trl/examples/scripts/rloo/rloo.py/0
{ "file_path": "trl/examples/scripts/rloo/rloo.py", "repo_id": "trl", "token_count": 2007 }
502
# Copyright 2025 The HuggingFace Team. All rights reserved. # # 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 applicabl...
trl/tests/test_dataset_formatting.py/0
{ "file_path": "trl/tests/test_dataset_formatting.py", "repo_id": "trl", "token_count": 3322 }
503
# Copyright 2025 The HuggingFace Team. All rights reserved. # # 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 applicabl...
trl/tests/test_prm_trainer.py/0
{ "file_path": "trl/tests/test_prm_trainer.py", "repo_id": "trl", "token_count": 7912 }
504
# Copyright 2025 The HuggingFace Team. All rights reserved. # # 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 applicabl...
trl/trl/scripts/env.py/0
{ "file_path": "trl/trl/scripts/env.py", "repo_id": "trl", "token_count": 1096 }
505
# Copyright 2025 The HuggingFace Team. All rights reserved. # # 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 applicabl...
trl/trl/trainer/dpo_config.py/0
{ "file_path": "trl/trl/trainer/dpo_config.py", "repo_id": "trl", "token_count": 8149 }
506
# Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # 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 appl...
accelerate/benchmarks/fp8/ms_amp/non_distributed.py/0
{ "file_path": "accelerate/benchmarks/fp8/ms_amp/non_distributed.py", "repo_id": "accelerate", "token_count": 1773 }
0
# Builds CPU-only Docker image of PyTorch # Uses multi-staged approach to reduce size # Stage 1 FROM python:3.9-slim as compile-image ARG DEBIAN_FRONTEND=noninteractive RUN apt update RUN apt-get install -y --no-install-recommends \ build-essential \ git \ gcc # Setup virtual environment for Docker ENV V...
accelerate/docker/accelerate-cpu/Dockerfile/0
{ "file_path": "accelerate/docker/accelerate-cpu/Dockerfile", "repo_id": "accelerate", "token_count": 380 }
1
<!--Copyright 2024 The HuggingFace Team. All rights reserved. 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 law or agreed...
accelerate/docs/source/concept_guides/fsdp_and_deepspeed.md/0
{ "file_path": "accelerate/docs/source/concept_guides/fsdp_and_deepspeed.md", "repo_id": "accelerate", "token_count": 3525 }
2
# Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # 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 appl...
accelerate/examples/complete_cv_example.py/0
{ "file_path": "accelerate/examples/complete_cv_example.py", "repo_id": "accelerate", "token_count": 5557 }
3
# Distributed inference examples This folder contains a variety of tutorials for running distributed inference with the following strategy: Load an entire model onto each GPU and sending chunks of a batch through each GPU’s model copy at a time ## Installation ```bash pip install accelerate torch ``` ## Running c...
accelerate/examples/inference/distributed/README.md/0
{ "file_path": "accelerate/examples/inference/distributed/README.md", "repo_id": "accelerate", "token_count": 175 }
4
#!/bin/bash -l #SBATCH --job-name=multicpu #SBATCH --nodes=2 # number of Nodes #SBATCH --ntasks-per-node=1 # number of MP tasks #SBATCH --exclusive #SBATCH --output=O-%x.%j #SBATCH --error=E-%x.%j ###################### ### Set enviroment ### ###################### source activateEnv...
accelerate/examples/slurm/submit_multicpu.sh/0
{ "file_path": "accelerate/examples/slurm/submit_multicpu.sh", "repo_id": "accelerate", "token_count": 767 }
5
# Copyright 2024 The HuggingFace Team. All rights reserved. # # 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 applicabl...
accelerate/manim_animations/dataloaders/stage_7.py/0
{ "file_path": "accelerate/manim_animations/dataloaders/stage_7.py", "repo_id": "accelerate", "token_count": 4184 }
6
#!/usr/bin/env python # Copyright 2022 The HuggingFace Team. All rights reserved. # # 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 # # Unles...
accelerate/src/accelerate/commands/config/update.py/0
{ "file_path": "accelerate/src/accelerate/commands/config/update.py", "repo_id": "accelerate", "token_count": 774 }
7
# Copyright 2024 The HuggingFace Team. All rights reserved. # # 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 applicabl...
accelerate/src/accelerate/inference.py/0
{ "file_path": "accelerate/src/accelerate/inference.py", "repo_id": "accelerate", "token_count": 2855 }
8
# Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # 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 appl...
accelerate/src/accelerate/test_utils/scripts/external_deps/test_performance.py/0
{ "file_path": "accelerate/src/accelerate/test_utils/scripts/external_deps/test_performance.py", "repo_id": "accelerate", "token_count": 4147 }
9
# Copyright 2023 The HuggingFace Team. All rights reserved. # # 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 applicabl...
accelerate/src/accelerate/utils/bnb.py/0
{ "file_path": "accelerate/src/accelerate/utils/bnb.py", "repo_id": "accelerate", "token_count": 8856 }
10
# Copyright 2022 The HuggingFace Team. All rights reserved. # # 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 applicabl...
accelerate/src/accelerate/utils/torch_xla.py/0
{ "file_path": "accelerate/src/accelerate/utils/torch_xla.py", "repo_id": "accelerate", "token_count": 691 }
11
# Copyright 2022 The HuggingFace Team. All rights reserved. # # 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 applicabl...
accelerate/tests/test_memory_utils.py/0
{ "file_path": "accelerate/tests/test_memory_utils.py", "repo_id": "accelerate", "token_count": 1740 }
12
# Copyright 2022 The HuggingFace Team. All rights reserved. # # 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 applicabl...
accelerate/tests/tp/test_tp.py/0
{ "file_path": "accelerate/tests/tp/test_tp.py", "repo_id": "accelerate", "token_count": 814 }
13
# Let's Fine-Tune Your Model for Function-Calling We're now ready to fine-tune our first model for function-calling 🔥. ## How do we train our model for function-calling? > Answer: We need **data** A model training process can be divided into 3 steps: 1. **The model is pre-trained on a large quantity of data**. Th...
agents-course/units/en/bonus-unit1/fine-tuning.mdx/0
{ "file_path": "agents-course/units/en/bonus-unit1/fine-tuning.mdx", "repo_id": "agents-course", "token_count": 1068 }
14
# Observe: Integrating Feedback to Reflect and Adapt Observations are **how an Agent perceives the consequences of its actions**. They provide crucial information that fuels the Agent's thought process and guides future actions. They are **signals from the environment**—whether it’s data from an API, error messages,...
agents-course/units/en/unit1/observations.mdx/0
{ "file_path": "agents-course/units/en/unit1/observations.mdx", "repo_id": "agents-course", "token_count": 748 }
15
repos: - repo: https://github.com/Narsil/pre-commit-rust rev: 2eed6366172ef2a5186e8785ec0e67243d7d73d0 hooks: - id: fmt name: "Rust (fmt)" - id: clippy name: "Rust (clippy)" args: [ "--tests", "--examples", "--", "-D...
candle/.pre-commit-config.yaml/0
{ "file_path": "candle/.pre-commit-config.yaml", "repo_id": "candle", "token_count": 210 }
16
# Creating a REST api webserver
candle/candle-book/src/apps/rest.md/0
{ "file_path": "candle/candle-book/src/apps/rest.md", "repo_id": "candle", "token_count": 8 }
17
//! #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...
candle/candle-book/src/simplified.rs/0
{ "file_path": "candle/candle-book/src/simplified.rs", "repo_id": "candle", "token_count": 2903 }
18
use crate::benchmarks::{BenchDevice, BenchDeviceHandler}; use candle_core::{DType, Device, Tensor}; use criterion::{black_box, criterion_group, Criterion, Throughput}; use half::{bf16, f16}; use std::time::Instant; fn run_sum(a: &Tensor) { a.sum_keepdim(2).unwrap(); } fn run_arg_min(a: &Tensor) { a.argmin_keep...
candle/candle-core/benches/benchmarks/reduce.rs/0
{ "file_path": "candle/candle-core/benches/benchmarks/reduce.rs", "repo_id": "candle", "token_count": 2382 }
19
use super::Cpu; #[cfg(target_arch = "arm")] use core::arch::arm::*; #[cfg(target_arch = "aarch64")] use core::arch::aarch64::*; pub struct CurrentCpu {} const STEP: usize = 16; const EPR: usize = 4; const ARR: usize = STEP / EPR; impl CurrentCpu { #[cfg(target_arch = "aarch64")] unsafe fn reduce_one(x: floa...
candle/candle-core/src/cpu/neon.rs/0
{ "file_path": "candle/candle-core/src/cpu/neon.rs", "repo_id": "candle", "token_count": 897 }
20
use crate::{Error, Tensor}; use std::ops::{ Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive, }; impl Tensor { /// Intended to be use by the trait `.i()` /// /// ``` /// # use candle_core::{Tensor, DType, Device, IndexOp}; /// let a = Tensor::zeros((2, ...
candle/candle-core/src/indexer.rs/0
{ "file_path": "candle/candle-core/src/indexer.rs", "repo_id": "candle", "token_count": 4032 }
21
use super::{GgmlDType, QStorage}; use crate::backend::BackendStorage; use crate::{DType, MetalDevice, MetalStorage, Result, Shape}; use metal::Buffer; use std::sync::Arc; pub struct QMetalStorage { dtype: GgmlDType, device: MetalDevice, buffer: Arc<Buffer>, } impl QMetalStorage { pub fn zeros(device: ...
candle/candle-core/src/quantized/metal.rs/0
{ "file_path": "candle/candle-core/src/quantized/metal.rs", "repo_id": "candle", "token_count": 4704 }
22
// Variables are wrappers around tensors that can be modified, they are typically used for holding // weights and being modified by gradient descent. // We do not expose a public way to create variables as this would break the invariant that the // tensor within a variable is actually with `is_variable` set to `true`. ...
candle/candle-core/src/variable.rs/0
{ "file_path": "candle/candle-core/src/variable.rs", "repo_id": "candle", "token_count": 2150 }
23
#![allow(unused)] use anyhow::{Context, Result}; use std::io::Write; use std::path::PathBuf; struct KernelDirectories { kernel_glob: &'static str, rust_target: &'static str, include_dirs: &'static [&'static str], } const KERNEL_DIRS: [KernelDirectories; 1] = [KernelDirectories { kernel_glob: "examples...
candle/candle-examples/build.rs/0
{ "file_path": "candle/candle-examples/build.rs", "repo_id": "candle", "token_count": 391 }
24
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:...
candle/candle-examples/examples/codegeex4-9b/main.rs/0
{ "file_path": "candle/candle-examples/examples/codegeex4-9b/main.rs", "repo_id": "candle", "token_count": 3921 }
25
//! Depth Anything V2 //! https://huggingface.co/spaces/depth-anything/Depth-Anything-V2 #[cfg(feature = "accelerate")] extern crate accelerate_src; #[cfg(feature = "mkl")] extern crate intel_mkl_src; use clap::Parser; use std::{ffi::OsString, path::PathBuf, sync::Arc}; use candle::DType::{F32, U8}; use candle::{DTy...
candle/candle-examples/examples/depth_anything_v2/main.rs/0
{ "file_path": "candle/candle-examples/examples/depth_anything_v2/main.rs", "repo_id": "candle", "token_count": 2544 }
26
# candle-falcon Falcon is a general large language model.
candle/candle-examples/examples/falcon/README.md/0
{ "file_path": "candle/candle-examples/examples/falcon/README.md", "repo_id": "candle", "token_count": 17 }
27
# candle-helium: 2b LLM with CC-BY licensed weights Helium-1 is a lightweight model with around 2B parameters, the preview version currently supports 6 languages, showing strong capabilities in those languages compared to existing open weights models. - [Blog Post](https://kyutai.org/2025/01/13/helium.html) announcin...
candle/candle-examples/examples/helium/README.md/0
{ "file_path": "candle/candle-examples/examples/helium/README.md", "repo_id": "candle", "token_count": 174 }
28
# candle-mamba-minimal: minimal implementation of Mamba This is based on [mamba-minimal](https://github.com/johnma2006/mamba-minimal). Compared to the mamba example, this version can handle training but is much slower. ## Running the example ```bash $ cargo run --example mamba-minimal --release -- --prompt "Mamba i...
candle/candle-examples/examples/mamba-minimal/README.md/0
{ "file_path": "candle/candle-examples/examples/mamba-minimal/README.md", "repo_id": "candle", "token_count": 206 }
29
# candle-olmo: Open Language Models designed to enable the science of language models OLMo is a series of Open Language Models designed to enable the science of language models. - **Project Page:** https://allenai.org/olmo - **Paper:** [Link](https://arxiv.org/abs/2402.00838) - **Technical blog post:** https://blog.a...
candle/candle-examples/examples/olmo/README.md/0
{ "file_path": "candle/candle-examples/examples/olmo/README.md", "repo_id": "candle", "token_count": 504 }
30
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...
candle/candle-examples/examples/reinforcement-learning/policy_gradient.rs/0
{ "file_path": "candle/candle-examples/examples/reinforcement-learning/policy_gradient.rs", "repo_id": "candle", "token_count": 2332 }
31
# 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...
candle/candle-examples/examples/vit/README.md/0
{ "file_path": "candle/candle-examples/examples/vit/README.md", "repo_id": "candle", "token_count": 219 }
32
use candle::{Device, Result, Tensor}; pub const IMAGENET_MEAN: [f32; 3] = [0.485f32, 0.456, 0.406]; pub const IMAGENET_STD: [f32; 3] = [0.229f32, 0.224, 0.225]; /// Loads an image from disk using the image crate at the requested resolution, /// using the given std and mean parameters. /// This returns a tensor with s...
candle/candle-examples/src/imagenet.rs/0
{ "file_path": "candle/candle-examples/src/imagenet.rs", "repo_id": "candle", "token_count": 13048 }
33
// This header is not specific to our application and you'll probably want // something like this for any extension you're building. This includes the // infrastructure needed to serialize descriptors that are used with the // "opaque" parameter of the GPU custom call. In our example we'll use this // parameter to pass...
candle/candle-flash-attn/kernels/kernel_helpers.h/0
{ "file_path": "candle/candle-flash-attn/kernels/kernel_helpers.h", "repo_id": "candle", "token_count": 600 }
34
#include "cuda_utils.cuh" #include<stdint.h> #define AFFINE_OP(TYPENAME, FN_NAME) \ extern "C" __global__ void FN_NAME( \ const size_t numel, \ const size_t num_dims, \ const size_t *info, \ const TYPENAME *inp, \ TYPENAME *out, \ const TYPENAME mul, \ const TYPENAME add \ ) { \ cons...
candle/candle-kernels/src/affine.cu/0
{ "file_path": "candle/candle-kernels/src/affine.cu", "repo_id": "candle", "token_count": 659 }
35
# candle-metal-kernels This crate contains Metal kernels used from candle.
candle/candle-metal-kernels/README.md/0
{ "file_path": "candle/candle-metal-kernels/README.md", "repo_id": "candle", "token_count": 18 }
36
// Imported from https://github.com/ggerganov/llama.cpp/blob/master/ggml-metal.metal #include <metal_stdlib> using namespace metal; #define SWAP(x, y) { auto tmp = (x); (x) = (y); (y) = tmp; } #define SORT_ASC 1 #define SORT_DESC 0 template<int order, typename T> METAL_FUNC void argsort( device const T ...
candle/candle-metal-kernels/src/sort.metal/0
{ "file_path": "candle/candle-metal-kernels/src/sort.metal", "repo_id": "candle", "token_count": 1748 }
37
pub(crate) mod conv; pub(crate) mod layer_norm; pub(crate) mod softmax; use candle::{Device, Result}; pub(crate) trait BenchDevice { fn sync(&self) -> Result<()>; fn bench_name<S: Into<String>>(&self, name: S) -> String; } impl BenchDevice for Device { fn sync(&self) -> Result<()> { match self {...
candle/candle-nn/benches/benchmarks/mod.rs/0
{ "file_path": "candle/candle-nn/benches/benchmarks/mod.rs", "repo_id": "candle", "token_count": 1006 }
38
//! 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 tru...
candle/candle-nn/src/loss.rs/0
{ "file_path": "candle/candle-nn/src/loss.rs", "repo_id": "candle", "token_count": 1049 }
39
#[cfg(feature = "mkl")] extern crate intel_mkl_src; #[cfg(feature = "accelerate")] extern crate accelerate_src; use candle::{test_utils::to_vec2_round, DType, Device, Result, Tensor}; use candle_nn::RNN; /* The following test can be verified against PyTorch using the following snippet. import torch from torch import...
candle/candle-nn/tests/rnn.rs/0
{ "file_path": "candle/candle-nn/tests/rnn.rs", "repo_id": "candle", "token_count": 2010 }
40
import logging try: from .candle import * except ImportError as e: # If we are in development mode, or we did not bundle the DLLs, we try to locate them here # PyO3 wont give us any information about what DLLs are missing, so we can only try to load # the DLLs and re-import the module logging.warni...
candle/candle-pyo3/py_src/candle/__init__.py/0
{ "file_path": "candle/candle-pyo3/py_src/candle/__init__.py", "repo_id": "candle", "token_count": 919 }
41
from typing import TypeVar, Union, Sequence _T = TypeVar("_T") _ArrayLike = Union[ _T, Sequence[_T], Sequence[Sequence[_T]], Sequence[Sequence[Sequence[_T]]], Sequence[Sequence[Sequence[Sequence[_T]]]], ] CPU: str = "cpu" CUDA: str = "cuda" Device = TypeVar("Device", CPU, CUDA) Scalar = Union[i...
candle/candle-pyo3/py_src/candle/typing/__init__.py/0
{ "file_path": "candle/candle-pyo3/py_src/candle/typing/__init__.py", "repo_id": "candle", "token_count": 166 }
42
from candle import Tensor from candle import rand import pytest def test_absolute_shapes_are_valid(): a = rand((10, 20)) assert a.shape == (10, 20) b = rand(10, 20) assert b.shape == (10, 20) pytest.raises(OverflowError, lambda: rand((10, 20, -1))) pytest.raises(OverflowError, lambda: rand(-1...
candle/candle-pyo3/tests/native/test_shape.py/0
{ "file_path": "candle/candle-pyo3/tests/native/test_shape.py", "repo_id": "candle", "token_count": 385 }
43
//! Chinese contrastive Language-Image Pre-Training //! //! Chinese contrastive Language-Image Pre-Training (CLIP) is an architecture trained on //! pairs of images with related texts. //! //! - 💻 [Chinese-CLIP](https://github.com/OFA-Sys/Chinese-CLIP) //! - 💻 [GH](https://github.com/huggingface/transformers/blob/5af...
candle/candle-transformers/src/models/chinese_clip/vision_model.rs/0
{ "file_path": "candle/candle-transformers/src/models/chinese_clip/vision_model.rs", "repo_id": "candle", "token_count": 6262 }
44
//! EfficientViT (MSRA) inference implementation based on timm. //! //! This crate provides an implementation of the EfficientViT model from Microsoft Research Asia //! for efficient image classification. The model uses cascaded group attention modules //! to achieve strong performance while maintaining low memory usag...
candle/candle-transformers/src/models/efficientvit.rs/0
{ "file_path": "candle/candle-transformers/src/models/efficientvit.rs", "repo_id": "candle", "token_count": 7414 }
45
//! # JinaBERT inference implementation //! //! Based on implementation from huggingface for Jina BERT and its variants //! //! See: [Jina Embeddings on HuggingFace](https://huggingface.co/jinaai/jina-embeddings-v2-base-en) use super::with_tracing::{linear, linear_no_bias, Embedding, Linear}; use candle::{DType, Devic...
candle/candle-transformers/src/models/jina_bert.rs/0
{ "file_path": "candle/candle-transformers/src/models/jina_bert.rs", "repo_id": "candle", "token_count": 6364 }
46
//! Mixtral Model, based on the Mistral architecture //! //! See Mistral and Mixtral at: //! - [Hugging Face](https://huggingface.co/docs/transformers/model_doc/mixtral) //! - [Github](https://github.com/mistralai/mistral-src) //! use crate::models::with_tracing::{linear_no_bias, Linear, RmsNorm}; /// Mistral LLM, htt...
candle/candle-transformers/src/models/mistral.rs/0
{ "file_path": "candle/candle-transformers/src/models/mistral.rs", "repo_id": "candle", "token_count": 8059 }
47
//! NV-Embed-v2 //! //! NV-Embed-v2 is a text embedding model that combines a Mistral decoder with a latent attention mechanism to produce high-quality text embeddings. //! //! This implementation is based on the [paper](https://arxiv.org/pdf/2405.17428) and [weights](https://huggingface.co/nvidia/NV-Embed-v2) //! //! ...
candle/candle-transformers/src/models/nvembed_v2/mod.rs/0
{ "file_path": "candle/candle-transformers/src/models/nvembed_v2/mod.rs", "repo_id": "candle", "token_count": 211 }
48
//! Quantized Llama2 model implementation. //! //! This provides an 8-bit quantized implementation of Meta's LLaMA2 language model //! for reduced memory usage and faster inference. //! //! Key characteristics: //! - Decoder-only transformer architecture //! - RoPE position embeddings //! - Grouped Query Attention //! ...
candle/candle-transformers/src/models/quantized_llama2_c.rs/0
{ "file_path": "candle/candle-transformers/src/models/quantized_llama2_c.rs", "repo_id": "candle", "token_count": 4607 }
49
//! Recurrent Gemma model implementation //! //! Recurrent Gemma is a version of the Gemma language model that incorporates recurrent memory. //! This allows the model to maintain state between predictions and have longer-range memory. //! //! Key characteristics: //! - Real-gated linear recurrent units (RGLRU) //! - 1...
candle/candle-transformers/src/models/recurrent_gemma.rs/0
{ "file_path": "candle/candle-transformers/src/models/recurrent_gemma.rs", "repo_id": "candle", "token_count": 12053 }
50
//! # Denoising Diffusion Implicit Models //! //! The Denoising Diffusion Implicit Models (DDIM) is a simple scheduler //! similar to Denoising Diffusion Probabilistic Models (DDPM). The DDPM //! generative process is the reverse of a Markovian process, DDIM generalizes //! this to non-Markovian guidance. //! //! Denoi...
candle/candle-transformers/src/models/stable_diffusion/ddim.rs/0
{ "file_path": "candle/candle-transformers/src/models/stable_diffusion/ddim.rs", "repo_id": "candle", "token_count": 3954 }
51
//! TrOCR model implementation. //! //! TrOCR is a Transformer-based OCR model that uses a Vision Transformer encoder //! and a BART-like decoder for optical character recognition. //! //! Key characteristics: //! - Vision Transformer encoder for image processing //! - BART-style decoder for text generation //! - Learn...
candle/candle-transformers/src/models/trocr.rs/0
{ "file_path": "candle/candle-transformers/src/models/trocr.rs", "repo_id": "candle", "token_count": 8631 }
52
//! Yi model implementation. //! //! This candle implementation uses a pre-trained Yi decoder-only large language model for inference. //! The model was trained by 01.AI and follows a standard transformer architecture similar to LLaMA. //! //! Original code: //! - 💻 [Yi Model](https://huggingface.co/01-ai/Yi-6B) //! -...
candle/candle-transformers/src/models/yi.rs/0
{ "file_path": "candle/candle-transformers/src/models/yi.rs", "repo_id": "candle", "token_count": 6426 }
53
export async function getEmbeddings( worker, weightsURL, tokenizerURL, configURL, modelID, sentences, updateStatus = null ) { return new Promise((resolve, reject) => { worker.postMessage({ weightsURL, tokenizerURL, configURL, modelID, sentences, }); function mes...
candle/candle-wasm-examples/bert/utils.js/0
{ "file_path": "candle/candle-wasm-examples/bert/utils.js", "repo_id": "candle", "token_count": 1250 }
54
fn main() { wasm_logger::init(wasm_logger::Config::new(log::Level::Trace)); console_error_panic_hook::set_once(); yew::Renderer::<candle_wasm_example_llama2::App>::new().render(); }
candle/candle-wasm-examples/llama2-c/src/bin/app.rs/0
{ "file_path": "candle/candle-wasm-examples/llama2-c/src/bin/app.rs", "repo_id": "candle", "token_count": 83 }
55
cargo build --target wasm32-unknown-unknown --release wasm-bindgen ../../target/wasm32-unknown-unknown/release/m.wasm --out-dir build --target web wasm-bindgen ../../target/wasm32-unknown-unknown/release/m-quantized.wasm --out-dir build --target web
candle/candle-wasm-examples/t5/build-lib.sh/0
{ "file_path": "candle/candle-wasm-examples/t5/build-lib.sh", "repo_id": "candle", "token_count": 84 }
56
use yew_agent::PublicWorker; fn main() { candle_wasm_example_whisper::Worker::register(); }
candle/candle-wasm-examples/whisper/src/bin/worker.rs/0
{ "file_path": "candle/candle-wasm-examples/whisper/src/bin/worker.rs", "repo_id": "candle", "token_count": 38 }
57
use candle::{DType, IndexOp, Result, Tensor, D}; use candle_nn::{ batch_norm, conv2d, conv2d_no_bias, BatchNorm, Conv2d, Conv2dConfig, Module, VarBuilder, }; use image::DynamicImage; // Model architecture from https://github.com/ultralytics/ultralytics/issues/189 // https://github.com/tinygrad/tinygrad/blob/master...
candle/candle-wasm-examples/yolo/src/model.rs/0
{ "file_path": "candle/candle-wasm-examples/yolo/src/model.rs", "repo_id": "candle", "token_count": 14731 }
58
{ "$schema": "https://vega.github.io/schema/vega-lite/v4.json", "data": { "values": "<DVC_METRIC_DATA>" }, "title": "<DVC_METRIC_TITLE>", "mark": { "type": "line" }, "encoding": { "x": { "field": "<DVC_METRIC_X>", "type": "quantitative", ...
datasets/.dvc/plots/smooth.json/0
{ "file_path": "datasets/.dvc/plots/smooth.json", "repo_id": "datasets", "token_count": 569 }
59
import timeit import numpy as np import datasets from datasets.arrow_writer import ArrowWriter from datasets.features.features import _ArrayXD def get_duration(func): def wrapper(*args, **kwargs): starttime = timeit.default_timer() _ = func(*args, **kwargs) delta = timeit.default_timer()...
datasets/benchmarks/utils.py/0
{ "file_path": "datasets/benchmarks/utils.py", "repo_id": "datasets", "token_count": 927 }
60
# Command Line Interface (CLI) 🤗 Datasets provides a command line interface (CLI) with useful shell commands to interact with your dataset. You can check the available commands: ```bash >>> datasets-cli --help usage: datasets-cli <command> [<args>] positional arguments: {convert,env,test,convert_to_parquet} ...
datasets/docs/source/cli.mdx/0
{ "file_path": "datasets/docs/source/cli.mdx", "repo_id": "datasets", "token_count": 1038 }
61
# Load a dataset from the Hub Finding high-quality datasets that are reproducible and accessible can be difficult. One of 🤗 Datasets main goals is to provide a simple way to load a dataset of any format or type. The easiest way to get started is to discover an existing dataset on the [Hugging Face Hub](https://huggin...
datasets/docs/source/load_hub.mdx/0
{ "file_path": "datasets/docs/source/load_hub.mdx", "repo_id": "datasets", "token_count": 1655 }
62
# Load tabular data A tabular dataset is a generic dataset used to describe any data stored in rows and columns, where the rows represent an example and the columns represent a feature (can be continuous or categorical). These datasets are commonly stored in CSV files, Pandas DataFrames, and in database tables. This g...
datasets/docs/source/tabular_load.mdx/0
{ "file_path": "datasets/docs/source/tabular_load.mdx", "repo_id": "datasets", "token_count": 1868 }
63
[tool.ruff] line-length = 119 [tool.ruff.lint] # Ignored rules: # "E501" -> line length violation # "F821" -> undefined named in type annotation (e.g. Literal["something"]) # "C901" -> `function_name` is too complex ignore = ["E501", "F821", "C901"] select = ["C", "E", "F", "I", "W"] [tool.ruff.lint.isort] line...
datasets/pyproject.toml/0
{ "file_path": "datasets/pyproject.toml", "repo_id": "datasets", "token_count": 274 }
64
import os import re from functools import partial from glob import has_magic from pathlib import Path, PurePath from typing import Callable, Dict, List, Optional, Set, Tuple, Union import huggingface_hub from fsspec.core import url_to_fs from fsspec.implementations.http import HTTPFileSystem from huggingface_hub impor...
datasets/src/datasets/data_files.py/0
{ "file_path": "datasets/src/datasets/data_files.py", "repo_id": "datasets", "token_count": 13818 }
65
import inspect import os import random import shutil import tempfile import weakref from functools import wraps from pathlib import Path from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union import numpy as np import xxhash from . import config from .naming import INVALID_WINDOWS_CHARACT...
datasets/src/datasets/fingerprint.py/0
{ "file_path": "datasets/src/datasets/fingerprint.py", "repo_id": "datasets", "token_count": 7526 }
66
import os from typing import BinaryIO, Optional, Union import fsspec import pyarrow.parquet as pq from .. import Dataset, Features, NamedSplit, config from ..arrow_writer import get_writer_batch_size from ..formatting import query_table from ..packaged_modules import _PACKAGED_DATASETS_MODULES from ..packaged_modules...
datasets/src/datasets/io/parquet.py/0
{ "file_path": "datasets/src/datasets/io/parquet.py", "repo_id": "datasets", "token_count": 2023 }
67
import itertools from dataclasses import dataclass from typing import Any, Callable, Dict, List, Optional, Union import pandas as pd import pyarrow as pa import datasets import datasets.config from datasets.features.features import require_storage_cast from datasets.table import table_cast from datasets.utils.py_util...
datasets/src/datasets/packaged_modules/csv/csv.py/0
{ "file_path": "datasets/src/datasets/packaged_modules/csv/csv.py", "repo_id": "datasets", "token_count": 3889 }
68
import sys from dataclasses import dataclass from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union import pandas as pd import pyarrow as pa import datasets import datasets.config from datasets.features.features import require_storage_cast from datasets.table import table_cast if TYPE_CHECKING: im...
datasets/src/datasets/packaged_modules/sql/sql.py/0
{ "file_path": "datasets/src/datasets/packaged_modules/sql/sql.py", "repo_id": "datasets", "token_count": 1979 }
69
## Add Dummy data test **Important** In order to pass the `load_dataset_<dataset_name>` test, dummy data is required for all possible config names. First we distinguish between datasets scripts that - A) have no config class and - B) have a config class For A) the dummy data folder structure, will always look as fol...
datasets/tests/README.md/0
{ "file_path": "datasets/tests/README.md", "repo_id": "datasets", "token_count": 928 }
70
import fsspec import pyarrow.parquet as pq import pytest from datasets import Audio, Dataset, DatasetDict, Features, IterableDatasetDict, NamedSplit, Sequence, Value, config from datasets.features.image import Image from datasets.info import DatasetInfo from datasets.io.parquet import ParquetDatasetReader, ParquetData...
datasets/tests/io/test_parquet.py/0
{ "file_path": "datasets/tests/io/test_parquet.py", "repo_id": "datasets", "token_count": 3919 }
71
import json import tarfile import numpy as np import pytest from datasets import Audio, DownloadManager, Features, Image, Sequence, Value from datasets.packaged_modules.webdataset.webdataset import WebDataset from ..utils import require_librosa, require_numpy1_on_windows, require_pil, require_sndfile, require_torch ...
datasets/tests/packaged_modules/test_webdataset.py/0
{ "file_path": "datasets/tests/packaged_modules/test_webdataset.py", "repo_id": "datasets", "token_count": 4039 }
72
import json import os import pickle import subprocess from functools import partial from pathlib import Path from tempfile import gettempdir from textwrap import dedent from types import FunctionType from unittest import TestCase from unittest.mock import patch import numpy as np import pytest from multiprocess import...
datasets/tests/test_fingerprint.py/0
{ "file_path": "datasets/tests/test_fingerprint.py", "repo_id": "datasets", "token_count": 6756 }
73
import json import os import pytest from datasets.download.streaming_download_manager import ( StreamingDownloadManager, xbasename, xglob, xjoin, xopen, ) from datasets.filesystems import COMPRESSION_FILESYSTEMS from .utils import require_lz4, require_zstandard, slow TEST_GG_DRIVE_FILENAME = "t...
datasets/tests/test_streaming_download_manager.py/0
{ "file_path": "datasets/tests/test_streaming_download_manager.py", "repo_id": "datasets", "token_count": 3201 }
74
import argparse import sys sys.path.append(".") from base_classes import IPAdapterTextToImageBenchmark # noqa: E402 IP_ADAPTER_CKPTS = { # because original SD v1.5 has been taken down. "Lykon/DreamShaper": ("h94/IP-Adapter", "ip-adapter_sd15.bin"), "stabilityai/stable-diffusion-xl-base-1.0": ("h94/IP-A...
diffusers/benchmarks/benchmark_ip_adapters.py/0
{ "file_path": "diffusers/benchmarks/benchmark_ip_adapters.py", "repo_id": "diffusers", "token_count": 450 }
75
<!--Copyright 2024 The HuggingFace Team. All rights reserved. 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 law or agreed...
diffusers/docs/source/en/api/loaders/peft.md/0
{ "file_path": "diffusers/docs/source/en/api/loaders/peft.md", "repo_id": "diffusers", "token_count": 332 }
76
<!-- Copyright 2024 The HuggingFace Team. All rights reserved. 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 law or agree...
diffusers/docs/source/en/api/models/hunyuan_video_transformer_3d.md/0
{ "file_path": "diffusers/docs/source/en/api/models/hunyuan_video_transformer_3d.md", "repo_id": "diffusers", "token_count": 351 }
77
<!--Copyright 2024 The HuggingFace Team. All rights reserved. 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 law or agreed...
diffusers/docs/source/en/api/pipelines/stable_diffusion/overview.md/0
{ "file_path": "diffusers/docs/source/en/api/pipelines/stable_diffusion/overview.md", "repo_id": "diffusers", "token_count": 4821 }
78
<!--Copyright 2024 The HuggingFace Team. All rights reserved. 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 law or agreed...
diffusers/docs/source/en/api/quantization.md/0
{ "file_path": "diffusers/docs/source/en/api/quantization.md", "repo_id": "diffusers", "token_count": 374 }
79