text stringlengths 7 324k | id stringlengths 14 166 | metadata dict | __index_level_0__ int64 0 463 |
|---|---|---|---|
# coding=utf-8
# Copyright 2023 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/vits/test_modeling_vits.py/0 | {
"file_path": "transformers/tests/models/vits/test_modeling_vits.py",
"repo_id": "transformers",
"token_count": 8472
} | 400 |
# 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/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py/0 | {
"file_path": "transformers/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py",
"repo_id": "transformers",
"token_count": 17966
} | 401 |
# 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/optimization/test_optimization_tf.py/0 | {
"file_path": "transformers/tests/optimization/test_optimization_tf.py",
"repo_id": "transformers",
"token_count": 1782
} | 402 |
# 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... | transformers/tests/pipelines/test_pipelines_mask_generation.py/0 | {
"file_path": "transformers/tests/pipelines/test_pipelines_mask_generation.py",
"repo_id": "transformers",
"token_count": 3309
} | 403 |
# Copyright 2021 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_zero_shot_object_detection.py/0 | {
"file_path": "transformers/tests/pipelines/test_pipelines_zero_shot_object_detection.py",
"repo_id": "transformers",
"token_count": 5064
} | 404 |
# Testing new Hugging Face Deep Learning Container.
This document explains the testing strategy for releasing the new Hugging Face Deep Learning Container. AWS maintains 14 days of currency with framework releases. Besides framework releases, AWS release train is bi-weekly on Monday. Code cutoff date for any changes i... | transformers/tests/sagemaker/README.md/0 | {
"file_path": "transformers/tests/sagemaker/README.md",
"repo_id": "transformers",
"token_count": 3293
} | 405 |
# coding=utf-8
# Copyright 2021 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/test_feature_extraction_common.py/0 | {
"file_path": "transformers/tests/test_feature_extraction_common.py",
"repo_id": "transformers",
"token_count": 828
} | 406 |
# coding=utf-8
# Copyright 2023 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/tools/test_translation.py/0 | {
"file_path": "transformers/tests/tools/test_translation.py",
"repo_id": "transformers",
"token_count": 1249
} | 407 |
import unittest
import warnings
from dataclasses import dataclass
from transformers.convert_slow_tokenizer import SpmConverter
from transformers.testing_utils import get_tests_dir
@dataclass
class FakeOriginalTokenizer:
vocab_file: str
class ConvertSlowTokenizerTest(unittest.TestCase):
def test_spm_convert... | transformers/tests/utils/test_convert_slow_tokenizer.py/0 | {
"file_path": "transformers/tests/utils/test_convert_slow_tokenizer.py",
"repo_id": "transformers",
"token_count": 524
} | 408 |
{
"ASTForAudioClassification": {
"tokenizer_classes": [],
"processor_classes": [
"ASTFeatureExtractor"
],
"model_classes": [
"ASTForAudioClassification"
],
"sha": "83d6e076db7768a3645401bad3204624985e1d08"
},
"ASTModel": {
"toke... | transformers/tests/utils/tiny_model_summary.json/0 | {
"file_path": "transformers/tests/utils/tiny_model_summary.json",
"repo_id": "transformers",
"token_count": 116904
} | 409 |
# coding=utf-8
# Copyright 2023 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_task_guides.py/0 | {
"file_path": "transformers/utils/check_task_guides.py",
"repo_id": "transformers",
"token_count": 2721
} | 410 |
# coding=utf-8
# Copyright 2021 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/utils/release.py/0 | {
"file_path": "transformers/utils/release.py",
"repo_id": "transformers",
"token_count": 2931
} | 411 |
# coding=utf-8
# Copyright 2023 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/update_tiny_models.py/0 | {
"file_path": "transformers/utils/update_tiny_models.py",
"repo_id": "transformers",
"token_count": 3072
} | 412 |
import argparse
import math
import os
import shlex
import subprocess
import uuid
from distutils.util import strtobool
import requests
def parse_args():
# fmt: off
parser = argparse.ArgumentParser()
parser.add_argument("--command", type=str, default="",
help="the command to run")
parser.add_ar... | trl/benchmark/benchmark.py/0 | {
"file_path": "trl/benchmark/benchmark.py",
"repo_id": "trl",
"token_count": 2824
} | 413 |
# Models
With the `AutoModelForCausalLMWithValueHead` class TRL supports all decoder model architectures in transformers such as GPT-2, OPT, and GPT-Neo. In addition, with `AutoModelForSeq2SeqLMWithValueHead` you can use encoder-decoder architectures such as T5. TRL also requires reference models which are frozen copi... | trl/docs/source/models.mdx/0 | {
"file_path": "trl/docs/source/models.mdx",
"repo_id": "trl",
"token_count": 283
} | 414 |
# 0. imports
import os
from dataclasses import dataclass, field
from typing import Dict, Optional
import torch
from accelerate import Accelerator
from datasets import Dataset, load_dataset
from peft import LoraConfig
from transformers import AutoModelForCausalLM, AutoTokenizer, HfArgumentParser, TrainingArguments, set... | trl/examples/research_projects/stack_llama_2/scripts/dpo_llama2.py/0 | {
"file_path": "trl/examples/research_projects/stack_llama_2/scripts/dpo_llama2.py",
"repo_id": "trl",
"token_count": 3863
} | 415 |
[tool.ruff]
target-version = "py37"
line-length = 119
[tool.ruff.lint]
ignore = [
"B028", # warning without explicit stacklevel
"C408", # dict() calls (stylistic)
"C901", # function complexity
"E501",
]
extend-select = ["E", "F", "I", "W", "UP", "B", "T", "C"]
[tool.ruff.lint.per-file-ignores]
# Allow... | trl/pyproject.toml/0 | {
"file_path": "trl/pyproject.toml",
"repo_id": "trl",
"token_count": 211
} | 416 |
# Copyright 2023 metric-space, 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 require... | trl/tests/test_ddpo_trainer.py/0 | {
"file_path": "trl/tests/test_ddpo_trainer.py",
"repo_id": "trl",
"token_count": 1784
} | 417 |
# flake8: noqa
from .base_environment import TextEnvironment, TextHistory
| trl/trl/environment/__init__.py/0 | {
"file_path": "trl/trl/environment/__init__.py",
"repo_id": "trl",
"token_count": 21
} | 418 |
# DPO Authors: Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, and Chelsea Finn 2023
# 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.
# ... | trl/trl/trainer/dpo_trainer.py/0 | {
"file_path": "trl/trl/trainer/dpo_trainer.py",
"repo_id": "trl",
"token_count": 27898
} | 419 |
- sections:
- local: index
title: 🤗 Accelerate
- local: basic_tutorials/install
title: Installation
- local: quicktour
title: Quicktour
title: Getting started
- sections:
- local: basic_tutorials/overview
title: Overview
- local: basic_tutorials/migration
title: Add Accelerate to your c... | accelerate/docs/source/_toctree.yml/0 | {
"file_path": "accelerate/docs/source/_toctree.yml",
"repo_id": "accelerate",
"token_count": 1290
} | 0 |
<!--Copyright 2021 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/package_reference/utilities.md/0 | {
"file_path": "accelerate/docs/source/package_reference/utilities.md",
"repo_id": "accelerate",
"token_count": 1962
} | 1 |
<!--Copyright 2021 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/usage_guides/sagemaker.md/0 | {
"file_path": "accelerate/docs/source/usage_guides/sagemaker.md",
"repo_id": "accelerate",
"token_count": 2261
} | 2 |
#!/usr/bin/env python
# Copyright 2021 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/accelerate_cli.py/0 | {
"file_path": "accelerate/src/accelerate/commands/accelerate_cli.py",
"repo_id": "accelerate",
"token_count": 558
} | 3 |
# Copyright 2022 The HuggingFace Team and Brian Chao. 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... | accelerate/src/accelerate/commands/menu/keymap.py/0 | {
"file_path": "accelerate/src/accelerate/commands/menu/keymap.py",
"repo_id": "accelerate",
"token_count": 2054
} | 4 |
#!/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/test_utils/examples.py/0 | {
"file_path": "accelerate/src/accelerate/test_utils/examples.py",
"repo_id": "accelerate",
"token_count": 2735
} | 5 |
# 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/tracking.py/0 | {
"file_path": "accelerate/src/accelerate/tracking.py",
"repo_id": "accelerate",
"token_count": 17060
} | 6 |
# 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/random.py/0 | {
"file_path": "accelerate/src/accelerate/utils/random.py",
"repo_id": "accelerate",
"token_count": 1743
} | 7 |
# Model arguments
model_name_or_path: alignment-handbook/zephyr-7b-sft-full
torch_dtype: null
# Data training arguments
dataset_mixer:
HuggingFaceH4/ultrafeedback_binarized: 1.0
dataset_splits:
- train_prefs
- test_prefs
preprocessing_num_workers: 12
# Training arguments with sensible defaults
bf16: true
beta: 0.01... | alignment-handbook/recipes/pref_align_scan/dpo/config_zephyr.yaml/0 | {
"file_path": "alignment-handbook/recipes/pref_align_scan/dpo/config_zephyr.yaml",
"repo_id": "alignment-handbook",
"token_count": 359
} | 8 |
#!/usr/bin/env python
# coding=utf-8
# Copyright 2023 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/LI... | alignment-handbook/scripts/run_sft.py/0 | {
"file_path": "alignment-handbook/scripts/run_sft.py",
"repo_id": "alignment-handbook",
"token_count": 3115
} | 9 |
[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"] | candle/.cargo/config.toml/0 | {
"file_path": "candle/.cargo/config.toml",
"repo_id": "candle",
"token_count": 84
} | 10 |
# Introduction
{{#include ../../README.md:features}}
This book will introduce step by step how to use `candle`.
| candle/candle-book/src/README.md/0 | {
"file_path": "candle/candle-book/src/README.md",
"repo_id": "candle",
"token_count": 34
} | 11 |
# Porting a custom kernel
| candle/candle-book/src/inference/cuda/porting.md/0 | {
"file_path": "candle/candle-book/src/inference/cuda/porting.md",
"repo_id": "candle",
"token_count": 7
} | 12 |
use crate::benchmarks::{BenchDevice, BenchDeviceHandler};
use candle_core::{DType, Device, Tensor};
use criterion::{black_box, criterion_group, Criterion, Throughput};
use std::time::Instant;
fn run(a: &Tensor, b: &Tensor) {
a.matmul(&b.t().unwrap()).unwrap();
}
fn run_bench(c: &mut Criterion, device: &Device) {
... | candle/candle-core/benches/benchmarks/matmul.rs/0 | {
"file_path": "candle/candle-core/benches/benchmarks/matmul.rs",
"repo_id": "candle",
"token_count": 551
} | 13 |
pub mod erf;
pub mod kernels;
trait Cpu<const ARR: usize> {
type Unit;
type Array;
const STEP: usize;
const EPR: usize;
fn n() -> usize;
unsafe fn zero() -> Self::Unit;
unsafe fn zero_array() -> Self::Array;
unsafe fn load(mem_addr: *const f32) -> Self::Unit;
unsafe fn vec_add(a: S... | candle/candle-core/src/cpu/mod.rs/0 | {
"file_path": "candle/candle-core/src/cpu/mod.rs",
"repo_id": "candle",
"token_count": 2416
} | 14 |
#![allow(dead_code)]
use libc::{c_char, c_double, c_float, c_int};
mod ffi {
use super::*;
extern "C" {
pub fn vsTanh(n: c_int, a: *const c_float, y: *mut c_float);
pub fn vdTanh(n: c_int, a: *const c_double, y: *mut c_double);
pub fn vsExp(n: c_int, a: *const c_float, y: *mut c_float);... | candle/candle-core/src/mkl.rs/0 | {
"file_path": "candle/candle-core/src/mkl.rs",
"repo_id": "candle",
"token_count": 6463
} | 15 |
use crate::{DType, Device, Error, Result, Tensor, WithDType};
use safetensors::tensor as st;
use safetensors::tensor::SafeTensors;
use std::borrow::Cow;
use std::collections::HashMap;
use std::path::Path;
impl From<DType> for st::Dtype {
fn from(value: DType) -> Self {
match value {
DType::U8 =... | candle/candle-core/src/safetensors.rs/0 | {
"file_path": "candle/candle-core/src/safetensors.rs",
"repo_id": "candle",
"token_count": 7743
} | 16 |
import numpy as np
x = np.arange(10)
# Write a npy file.
np.save("test.npy", x)
# Write multiple values to a npz file.
values = { "x": x, "x_plus_one": x + 1 }
np.savez("test.npz", **values)
| candle/candle-core/tests/npy.py/0 | {
"file_path": "candle/candle-core/tests/npy.py",
"repo_id": "candle",
"token_count": 83
} | 17 |
pub mod tinystories;
| candle/candle-datasets/src/nlp/mod.rs/0 | {
"file_path": "candle/candle-datasets/src/nlp/mod.rs",
"repo_id": "candle",
"token_count": 6
} | 18 |
# candle-convnext
[A ConvNet for the 2020s](https://arxiv.org/abs/2201.03545) and
[ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders](https://arxiv.org/abs/2301.00808).
This candle implementation uses a pre-trained ConvNeXt network for inference. The
classification head has been trained on the I... | candle/candle-examples/examples/convnext/README.md/0 | {
"file_path": "candle/candle-examples/examples/convnext/README.md",
"repo_id": "candle",
"token_count": 293
} | 19 |
# 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
} | 20 |
# 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... | candle/candle-examples/examples/marian-mt/README.md/0 | {
"file_path": "candle/candle-examples/examples/marian-mt/README.md",
"repo_id": "candle",
"token_count": 497
} | 21 |
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... | candle/candle-examples/examples/onnx_basics.rs/0 | {
"file_path": "candle/candle-examples/examples/onnx_basics.rs",
"repo_id": "candle",
"token_count": 2016
} | 22 |
# 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... | candle/candle-examples/examples/replit-code/README.md/0 | {
"file_path": "candle/candle-examples/examples/replit-code/README.md",
"repo_id": "candle",
"token_count": 426
} | 23 |
//! 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... | candle/candle-examples/examples/segment-anything/main.rs/0 | {
"file_path": "candle/candle-examples/examples/segment-anything/main.rs",
"repo_id": "candle",
"token_count": 3129
} | 24 |
# 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
} | 25 |
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)
| candle/candle-examples/examples/yolo-v3/extract-weights.py/0 | {
"file_path": "candle/candle-examples/examples/yolo-v3/extract-weights.py",
"repo_id": "candle",
"token_count": 98
} | 26 |
use std::io::prelude::*;
pub trait Sample {
fn to_i16(&self) -> i16;
}
impl Sample for f32 {
fn to_i16(&self) -> i16 {
(self.clamp(-1.0, 1.0) * 32767.0) as i16
}
}
impl Sample for f64 {
fn to_i16(&self) -> i16 {
(self.clamp(-1.0, 1.0) * 32767.0) as i16
}
}
impl Sample for i16 {
... | candle/candle-examples/src/wav.rs/0 | {
"file_path": "candle/candle-examples/src/wav.rs",
"repo_id": "candle",
"token_count": 729
} | 27 |
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,
alibi_slopes_ptr: *const c_void,
cu_seqlens_q_ptr: *const i32,
... | candle/candle-flash-attn/src/ffi.rs/0 | {
"file_path": "candle/candle-flash-attn/src/ffi.rs",
"repo_id": "candle",
"token_count": 670
} | 28 |
// Kernels adapted from llama.cpp ggml-cuda.cu
// https://github.com/ggerganov/llama.cpp/blob/master/ggml-cuda.cu
#include "cuda_fp16.h"
#include "cuda_bf16.h"
#include<stdint.h>
#ifdef GGML_QKK_64
#define QK_K 64
#define K_SCALE_SIZE 4
#else
#define QK_K 256
#define K_SCALE_SIZE 12
#endif
#undef GGML_CUDA_F16
#defin... | candle/candle-kernels/src/quantized.cu/0 | {
"file_path": "candle/candle-kernels/src/quantized.cu",
"repo_id": "candle",
"token_count": 30648
} | 29 |
#include <metal_stdlib>
#
using namespace metal;
METAL_FUNC uint get_strided_index(
uint idx,
constant size_t &num_dims,
constant size_t *dims,
constant size_t *strides
) {
uint strided_i = 0;
for (uint d = 0; d < num_dims; d++) {
uint dim_idx = num_dims - 1 - d;
strided_i += (i... | candle/candle-metal-kernels/src/ternary.metal/0 | {
"file_path": "candle/candle-metal-kernels/src/ternary.metal",
"repo_id": "candle",
"token_count": 2209
} | 30 |
//! Layers defined by closures.
use candle::{Result, Tensor};
use std::sync::Arc;
/// A layer defined by a simple closure.
#[derive(Clone)]
pub struct Func<'a> {
#[allow(clippy::type_complexity)]
f: Arc<dyn 'a + Fn(&Tensor) -> Result<Tensor> + Send + Sync>,
}
impl<'a> std::fmt::Debug for Func<'a> {
fn fmt... | candle/candle-nn/src/func.rs/0 | {
"file_path": "candle/candle-nn/src/func.rs",
"repo_id": "candle",
"token_count": 804
} | 31 |
#[cfg(feature = "mkl")]
extern crate intel_mkl_src;
#[cfg(feature = "accelerate")]
extern crate accelerate_src;
use candle::test_utils::to_vec0_round;
use candle::{Device, Result, Tensor};
/* Equivalent python code:
import torch
import torch.nn.functional as F
input = torch.tensor([
[ 1.1050, 0.3013, -1.5394, -... | candle/candle-nn/tests/loss.rs/0 | {
"file_path": "candle/candle-nn/tests/loss.rs",
"repo_id": "candle",
"token_count": 1344
} | 32 |
from typing import Union, Sequence
class Tensor:
"""
This contains the type hints for the magic methodes of the `candle.Tensor` class.
"""
def __add__(self, rhs: Union["Tensor", "Scalar"]) -> "Tensor":
"""
Add a scalar to a tensor or two tensors together.
"""
pass
... | candle/candle-pyo3/_additional_typing/__init__.py/0 | {
"file_path": "candle/candle-pyo3/_additional_typing/__init__.py",
"repo_id": "candle",
"token_count": 1174
} | 33 |
# Generated content DO NOT EDIT
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, Sequence
from os import PathLike
from candle.typing import _ArrayLike, Device, Scalar, Index, Shape
from candle import Tensor, DType, QTensor
class ONNXModel:
"""
A wrapper around an ONNX model.
"""
d... | candle/candle-pyo3/py_src/candle/onnx/__init__.pyi/0 | {
"file_path": "candle/candle-pyo3/py_src/candle/onnx/__init__.pyi",
"repo_id": "candle",
"token_count": 939
} | 34 |
import candle
from candle import Tensor, QTensor
from candle.nn import Module, Linear
from candle.utils import cuda_is_available
import pytest
def test_module_can_be_constructed():
class A(Module):
pass
a = A()
assert a is not None
assert len(list(a.buffers())) == 0
def test_module_registe... | candle/candle-pyo3/tests/bindings/test_module.py/0 | {
"file_path": "candle/candle-pyo3/tests/bindings/test_module.py",
"repo_id": "candle",
"token_count": 1853
} | 35 |
use candle::{IndexOp, Result, Tensor, D};
use candle_nn::{layer_norm, LayerNorm, Linear, Module, VarBuilder};
const IMG_SIZE: usize = 518;
const PATCH_SIZE: usize = 14;
const NUM_CLASSES: usize = 1000;
fn linear(vb: VarBuilder, in_dim: usize, out_dim: usize, bias: bool) -> Result<Linear> {
if bias {
candl... | candle/candle-transformers/src/models/dinov2.rs/0 | {
"file_path": "candle/candle-transformers/src/models/dinov2.rs",
"repo_id": "candle",
"token_count": 4376
} | 36 |
use crate::models::with_tracing::{linear_no_bias, Linear};
/// Mixtral Model
/// https://github.com/huggingface/transformers/blob/main/src/transformers/models/mixtral/modeling_mixtral.py
/// https://mistral.ai/news/mixtral-of-experts/
use candle::{DType, Device, Module, Result, Tensor, D};
use candle_nn::{Activation, V... | candle/candle-transformers/src/models/mixtral.rs/0 | {
"file_path": "candle/candle-transformers/src/models/mixtral.rs",
"repo_id": "candle",
"token_count": 9339
} | 37 |
use crate::quantized_nn::{layer_norm, linear, linear_no_bias, Embedding, Linear};
pub use crate::quantized_var_builder::VarBuilder;
use candle::{DType, Device, Module, Result, Tensor, D};
use candle_nn::{Activation, LayerNorm};
use std::sync::Arc;
pub use crate::models::stable_lm::Config;
use crate::models::stable_lm:... | candle/candle-transformers/src/models/quantized_stable_lm.rs/0 | {
"file_path": "candle/candle-transformers/src/models/quantized_stable_lm.rs",
"repo_id": "candle",
"token_count": 5441
} | 38 |
//! Contrastive Language-Image Pre-Training
//!
//! Contrastive Language-Image Pre-Training (CLIP) is an architecture trained on
//! pairs of images with related texts.
//!
//! https://github.com/openai/CLIP
use candle::{DType, Device, Result, Tensor, D};
use candle_nn as nn;
use candle_nn::Module;
#[derive(Debug, Clo... | candle/candle-transformers/src/models/stable_diffusion/clip.rs/0 | {
"file_path": "candle/candle-transformers/src/models/stable_diffusion/clip.rs",
"repo_id": "candle",
"token_count": 6474
} | 39 |
//! VGG-16 model implementation.
//!
//! See Very Deep Convolutional Networks for Large-Scale Image Recognition
//! <https://arxiv.org/abs/1409.1556>
use candle::{ModuleT, Result, Tensor};
use candle_nn::{FuncT, VarBuilder};
// Enum representing the different VGG models
pub enum Models {
Vgg13,
Vgg16,
Vgg1... | candle/candle-transformers/src/models/vgg.rs/0 | {
"file_path": "candle/candle-transformers/src/models/vgg.rs",
"repo_id": "candle",
"token_count": 4303
} | 40 |
pub mod text_generation;
| candle/candle-transformers/src/pipelines/mod.rs/0 | {
"file_path": "candle/candle-transformers/src/pipelines/mod.rs",
"repo_id": "candle",
"token_count": 7
} | 41 |
import init, { Model } from "./build/m.js";
async function fetchArrayBuffer(url, cacheFile = true) {
if (!cacheFile) return new Uint8Array(await (await fetch(url)).arrayBuffer());
const cacheName = "blip-candle-cache";
const cache = await caches.open(cacheName);
const cachedResponse = await cache.match(url);
... | candle/candle-wasm-examples/blip/blipWorker.js/0 | {
"file_path": "candle/candle-wasm-examples/blip/blipWorker.js",
"repo_id": "candle",
"token_count": 815
} | 42 |
mod app;
pub mod model;
pub mod worker;
pub use app::App;
pub use worker::Worker;
| candle/candle-wasm-examples/llama2-c/src/lib.rs/0 | {
"file_path": "candle/candle-wasm-examples/llama2-c/src/lib.rs",
"repo_id": "candle",
"token_count": 29
} | 43 |
import init, { run_app } from './pkg/candle_wasm_example_whisper.js';
async function main() {
await init('/pkg/candle_wasm_example_whisper_bg.wasm');
run_app();
}
main()
| candle/candle-wasm-examples/whisper/main.js/0 | {
"file_path": "candle/candle-wasm-examples/whisper/main.js",
"repo_id": "candle",
"token_count": 73
} | 44 |
fn main() {
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
console_error_panic_hook::set_once();
yew::Renderer::<candle_wasm_example_yolo::App>::new().render();
}
| candle/candle-wasm-examples/yolo/src/bin/app.rs/0 | {
"file_path": "candle/candle-wasm-examples/yolo/src/bin/app.rs",
"repo_id": "candle",
"token_count": 82
} | 45 |
MONGODB_URL=mongodb://localhost:27017/ | chat-ui/.env.ci/0 | {
"file_path": "chat-ui/.env.ci",
"repo_id": "chat-ui",
"token_count": 16
} | 46 |
{
"name": "chat-ui",
"version": "0.7.0",
"private": true,
"packageManager": "npm@9.5.0",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./ts... | chat-ui/package.json/0 | {
"file_path": "chat-ui/package.json",
"repo_id": "chat-ui",
"token_count": 1447
} | 47 |
<script lang="ts">
import { onDestroy } from "svelte";
import IconCopy from "./icons/IconCopy.svelte";
import Tooltip from "./Tooltip.svelte";
export let classNames = "";
export let value: string;
let isSuccess = false;
let timeout: ReturnType<typeof setTimeout>;
const handleClick = async () => {
// write... | chat-ui/src/lib/components/CopyToClipBoardBtn.svelte/0 | {
"file_path": "chat-ui/src/lib/components/CopyToClipBoardBtn.svelte",
"repo_id": "chat-ui",
"token_count": 433
} | 48 |
<script lang="ts">
export let checked: boolean;
export let name: string;
</script>
<input bind:checked type="checkbox" {name} class="peer pointer-events-none absolute opacity-0" />
<div
aria-checked={checked}
aria-roledescription="switch"
aria-label="switch"
role="switch"
tabindex="0"
class="relative inline-fl... | chat-ui/src/lib/components/Switch.svelte/0 | {
"file_path": "chat-ui/src/lib/components/Switch.svelte",
"repo_id": "chat-ui",
"token_count": 239
} | 49 |
<script lang="ts">
export let classNames = "";
</script>
<div class={"inline-flex h-8 flex-none items-center gap-1 " + classNames}>
<div
class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400"
style="animation-delay: 0.25s;"
/>
<div
class="h-1 w-1 flex-none animate-bounce rounded-f... | chat-ui/src/lib/components/icons/IconLoading.svelte/0 | {
"file_path": "chat-ui/src/lib/components/icons/IconLoading.svelte",
"repo_id": "chat-ui",
"token_count": 223
} | 50 |
import { z } from "zod";
import type { EmbeddingEndpoint } from "../embeddingEndpoints";
import type { Tensor, Pipeline } from "@xenova/transformers";
import { pipeline } from "@xenova/transformers";
export const embeddingEndpointTransformersJSParametersSchema = z.object({
weight: z.number().int().positive().default(... | chat-ui/src/lib/server/embeddingEndpoints/transformersjs/embeddingEndpoints.ts/0 | {
"file_path": "chat-ui/src/lib/server/embeddingEndpoints/transformersjs/embeddingEndpoints.ts",
"repo_id": "chat-ui",
"token_count": 483
} | 51 |
import { LLM_SUMMERIZATION } from "$env/static/private";
import { generateFromDefaultEndpoint } from "$lib/server/generateFromDefaultEndpoint";
import type { Message } from "$lib/types/Message";
export async function summarize(prompt: string) {
if (!LLM_SUMMERIZATION) {
return prompt.split(/\s+/g).slice(0, 5).join(... | chat-ui/src/lib/server/summarize.ts/0 | {
"file_path": "chat-ui/src/lib/server/summarize.ts",
"repo_id": "chat-ui",
"token_count": 638
} | 52 |
export function switchTheme() {
const { classList } = document.querySelector("html") as HTMLElement;
const metaTheme = document.querySelector('meta[name="theme-color"]') as HTMLMetaElement;
if (classList.contains("dark")) {
classList.remove("dark");
metaTheme.setAttribute("content", "rgb(249, 250, 251)");
loc... | chat-ui/src/lib/switchTheme.ts/0 | {
"file_path": "chat-ui/src/lib/switchTheme.ts",
"repo_id": "chat-ui",
"token_count": 164
} | 53 |
import type { Message } from "./Message";
export type LegacyParamatersTemplateInput = {
preprompt?: string;
userMessageToken: string;
userMessageEndToken: string;
assistantMessageToken: string;
assistantMessageEndToken: string;
};
export type ChatTemplateInput = {
messages: Pick<Message, "from" | "content">[];
... | chat-ui/src/lib/types/Template.ts/0 | {
"file_path": "chat-ui/src/lib/types/Template.ts",
"repo_id": "chat-ui",
"token_count": 105
} | 54 |
// Approximate width from which we disable autofocus
const TABLET_VIEWPORT_WIDTH = 768;
export function isDesktop(window: Window) {
const { innerWidth } = window;
return innerWidth > TABLET_VIEWPORT_WIDTH;
}
| chat-ui/src/lib/utils/isDesktop.ts/0 | {
"file_path": "chat-ui/src/lib/utils/isDesktop.ts",
"repo_id": "chat-ui",
"token_count": 67
} | 55 |
import { collections } from "$lib/server/database";
import { ObjectId } from "mongodb";
import { describe, expect, it } from "vitest";
import {
insertLegacyConversation,
insertLinearBranchConversation,
insertSideBranchesConversation,
} from "./treeHelpers.spec";
import { buildSubtree } from "./buildSubtree";
descr... | chat-ui/src/lib/utils/tree/buildSubtree.spec.ts/0 | {
"file_path": "chat-ui/src/lib/utils/tree/buildSubtree.spec.ts",
"repo_id": "chat-ui",
"token_count": 1375
} | 56 |
export async function GET({ locals }) {
if (locals.user) {
const res = {
id: locals.user._id,
username: locals.user.username,
name: locals.user.name,
email: locals.user.email,
avatarUrl: locals.user.avatarUrl,
hfUserId: locals.user.hfUserId,
};
return Response.json(res);
}
return Response.js... | chat-ui/src/routes/api/user/+server.ts/0 | {
"file_path": "chat-ui/src/routes/api/user/+server.ts",
"repo_id": "chat-ui",
"token_count": 148
} | 57 |
import { base } from "$app/paths";
import { authCondition } from "$lib/server/auth";
import { collections } from "$lib/server/database";
import { redirect } from "@sveltejs/kit";
export const actions = {
async delete({ locals }) {
// double check we have a user to delete conversations for
if (locals.user?._id || ... | chat-ui/src/routes/conversations/+page.server.ts/0 | {
"file_path": "chat-ui/src/routes/conversations/+page.server.ts",
"repo_id": "chat-ui",
"token_count": 158
} | 58 |
<script lang="ts">
import { page } from "$app/stores";
import { base } from "$app/paths";
import { PUBLIC_ORIGIN } from "$env/static/public";
import type { BackendModel } from "$lib/server/models";
import { useSettingsStore } from "$lib/stores/settings";
import CopyToClipBoardBtn from "$lib/components/CopyToClipB... | chat-ui/src/routes/settings/(nav)/[...model]/+page.svelte/0 | {
"file_path": "chat-ui/src/routes/settings/(nav)/[...model]/+page.svelte",
"repo_id": "chat-ui",
"token_count": 1518
} | 59 |
{
"license": "Apache-2.0",
"creators": [
{
"affiliation": "Hugging Face",
"name": "Quentin Lhoest"
},
{
"orcid": "0000-0003-1727-1045",
"affiliation": "Hugging Face",
"name": "Albert Villanova del Moral"
},
{
... | datasets/.zenodo.json/0 | {
"file_path": "datasets/.zenodo.json",
"repo_id": "datasets",
"token_count": 1953
} | 60 |
import json
import sys
def format_json_to_md(input_json_file, output_md_file):
with open(input_json_file, encoding="utf-8") as f:
results = json.load(f)
output_md = ["<details>", "<summary>Show updated benchmarks!</summary>", " "]
for benchmark_name in sorted(results):
benchmark_res = re... | datasets/benchmarks/format.py/0 | {
"file_path": "datasets/benchmarks/format.py",
"repo_id": "datasets",
"token_count": 746
} | 61 |
# Batch mapping
Combining the utility of [`Dataset.map`] with batch mode is very powerful. It allows you to speed up processing, and freely control the size of the generated dataset.
## Need for speed
The primary objective of batch mapping is to speed up processing. Often times, it is faster to work with batches of... | datasets/docs/source/about_map_batch.mdx/0 | {
"file_path": "datasets/docs/source/about_map_batch.mdx",
"repo_id": "datasets",
"token_count": 722
} | 62 |
# Metrics
<Tip warning={true}>
Metrics is deprecated in 🤗 Datasets. To learn more about how to use metrics, take a look at the library 🤗 [Evaluate](https://huggingface.co/docs/evaluate/index)! In addition to metrics, you can find more tools for evaluating models and datasets.
</Tip>
Metrics are important for eval... | datasets/docs/source/how_to_metrics.mdx/0 | {
"file_path": "datasets/docs/source/how_to_metrics.mdx",
"repo_id": "datasets",
"token_count": 3350
} | 63 |
# Loading methods
Methods for listing and loading datasets and metrics:
## Datasets
[[autodoc]] datasets.list_datasets
[[autodoc]] datasets.load_dataset
[[autodoc]] datasets.load_from_disk
[[autodoc]] datasets.load_dataset_builder
[[autodoc]] datasets.get_dataset_config_names
[[autodoc]] datasets.get_dataset_in... | datasets/docs/source/package_reference/loading_methods.mdx/0 | {
"file_path": "datasets/docs/source/package_reference/loading_methods.mdx",
"repo_id": "datasets",
"token_count": 809
} | 64 |
# Use with JAX
This document is a quick introduction to using `datasets` with JAX, with a particular focus on how to get
`jax.Array` objects out of our datasets, and how to use them to train JAX models.
<Tip>
`jax` and `jaxlib` are required to reproduce to code above, so please make sure you
install them as `pip ins... | datasets/docs/source/use_with_jax.mdx/0 | {
"file_path": "datasets/docs/source/use_with_jax.mdx",
"repo_id": "datasets",
"token_count": 2646
} | 65 |
# Copyright 2021 The HuggingFace Datasets Authors.
#
# 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 ... | datasets/metrics/chrf/chrf.py/0 | {
"file_path": "datasets/metrics/chrf/chrf.py",
"repo_id": "datasets",
"token_count": 3170
} | 66 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.... | datasets/metrics/f1/f1.py/0 | {
"file_path": "datasets/metrics/f1/f1.py",
"repo_id": "datasets",
"token_count": 2364
} | 67 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors.
#
# 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 app... | datasets/metrics/mauve/mauve.py/0 | {
"file_path": "datasets/metrics/mauve/mauve.py",
"repo_id": "datasets",
"token_count": 2588
} | 68 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.... | datasets/metrics/roc_auc/roc_auc.py/0 | {
"file_path": "datasets/metrics/roc_auc/roc_auc.py",
"repo_id": "datasets",
"token_count": 3792
} | 69 |
# Copyright 2020 The HuggingFace Datasets Authors.
#
# 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 ... | datasets/metrics/squad_v2/squad_v2.py/0 | {
"file_path": "datasets/metrics/squad_v2/squad_v2.py",
"repo_id": "datasets",
"token_count": 2564
} | 70 |
[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": 236
} | 71 |
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 import get_fs_token_paths
from fsspec.implementations.http import HTTPFileSystem
from huggingface_hub i... | datasets/src/datasets/data_files.py/0 | {
"file_path": "datasets/src/datasets/data_files.py",
"repo_id": "datasets",
"token_count": 13516
} | 72 |
import s3fs
from ..utils.deprecation_utils import deprecated
@deprecated("Use s3fs.S3FileSystem instead.")
class S3FileSystem(s3fs.S3FileSystem):
"""
`datasets.filesystems.S3FileSystem` is a subclass of [`s3fs.S3FileSystem`](https://s3fs.readthedocs.io/en/latest/api.html).
Users can use this class to ac... | datasets/src/datasets/filesystems/s3filesystem.py/0 | {
"file_path": "datasets/src/datasets/filesystems/s3filesystem.py",
"repo_id": "datasets",
"token_count": 2170
} | 73 |
import os
from typing import BinaryIO, Optional, Union
import fsspec
import numpy as np
import pyarrow.parquet as pq
from .. import Audio, Dataset, Features, Image, NamedSplit, Value, config
from ..features.features import FeatureType, _visit
from ..formatting import query_table
from ..packaged_modules import _PACKAG... | datasets/src/datasets/io/parquet.py/0 | {
"file_path": "datasets/src/datasets/io/parquet.py",
"repo_id": "datasets",
"token_count": 2585
} | 74 |
import abc
import copy
import dataclasses
from dataclasses import dataclass
from typing import ClassVar, Dict, Type, TypeVar
from ..features import Features
T = TypeVar("T", bound="TaskTemplate")
@dataclass(frozen=True)
class TaskTemplate(abc.ABC):
# `task` is not a ClassVar since we want it to be part of the ... | datasets/src/datasets/tasks/base.py/0 | {
"file_path": "datasets/src/datasets/tasks/base.py",
"repo_id": "datasets",
"token_count": 417
} | 75 |
"""
Utilities for working with the local dataset cache.
This file is adapted from the AllenNLP library at https://github.com/allenai/allennlp
Copyright by the AllenNLP authors.
"""
import copy
import io
import json
import multiprocessing
import os
import posixpath
import re
import shutil
import sys
import time
import ... | datasets/src/datasets/utils/file_utils.py/0 | {
"file_path": "datasets/src/datasets/utils/file_utils.py",
"repo_id": "datasets",
"token_count": 11169
} | 76 |
import numpy as np
def approximate_mode(class_counts, n_draws, rng):
"""Computes approximate mode of multivariate hypergeometric.
This is an approximation to the mode of the multivariate
hypergeometric given by class_counts and n_draws.
It shouldn't be off by more than one.
It is the mostly likely... | datasets/src/datasets/utils/stratify.py/0 | {
"file_path": "datasets/src/datasets/utils/stratify.py",
"repo_id": "datasets",
"token_count": 1674
} | 77 |
import pytest
import datasets
import datasets.config
# Import fixture modules as plugins
pytest_plugins = ["tests.fixtures.files", "tests.fixtures.hub", "tests.fixtures.fsspec"]
def pytest_collection_modifyitems(config, items):
# Mark tests as "unit" by default if not marked as "integration" (or already marked... | datasets/tests/conftest.py/0 | {
"file_path": "datasets/tests/conftest.py",
"repo_id": "datasets",
"token_count": 957
} | 78 |
import posixpath
from pathlib import Path
from unittest.mock import patch
import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry
class MockFileSystem(AbstractFileSystem):
protocol = "mock"
def __ini... | datasets/tests/fixtures/fsspec.py/0 | {
"file_path": "datasets/tests/fixtures/fsspec.py",
"repo_id": "datasets",
"token_count": 1757
} | 79 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.