text
stringlengths
5
58.6k
source
stringclasses
470 values
url
stringlengths
49
167
source_section
stringlengths
0
90
file_type
stringclasses
1 value
id
stringlengths
3
6
Sometimes, older CUDA versions may refuse to build with newer compilers. For example, if you have `gcc-9` but CUDA wants `gcc-7`. Usually, installing the latest CUDA toolkit enables support for the newer compiler. You could also install an older version of the compiler in addition to the one you're currently using (o...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/debugging.md
https://huggingface.co/docs/transformers/en/debugging/#older-cuda-versions
#older-cuda-versions
.md
60_5
If you're still having issues with installing DeepSpeed or if you're building DeepSpeed at run time, you can try to prebuild the DeepSpeed modules before installing them. To make a local build for DeepSpeed: ```bash git clone https://github.com/microsoft/DeepSpeed/ cd DeepSpeed rm -rf build TORCH_CUDA_ARCH_LIST="8.6"...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/debugging.md
https://huggingface.co/docs/transformers/en/debugging/#prebuild
#prebuild
.md
60_6
When training or inferencing with `DistributedDataParallel` and multiple GPU, if you run into issue of inter-communication between processes and/or nodes, you can use the following script to diagnose network issues. ```bash wget https://raw.githubusercontent.com/huggingface/transformers/main/scripts/distributed/torch...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/debugging.md
https://huggingface.co/docs/transformers/en/debugging/#multi-gpu-network-issues-debug
#multi-gpu-network-issues-debug
.md
60_7
<Tip> This feature is currently available for PyTorch-only. </Tip> <Tip> For multi-GPU training it requires DDP (`torch.distributed.launch`). </Tip> <Tip> This feature can be used with any `nn.Module`-based model. </Tip> If you start getting `loss=NaN` or the model exhibits some other abnormal behavio...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/debugging.md
https://huggingface.co/docs/transformers/en/debugging/#underflow-and-overflow-detection
#underflow-and-overflow-detection
.md
60_8
The same debugging class can be used for per-batch tracing with the underflow/overflow detection feature turned off. Let's say you want to watch the absolute min and max values for all the ingredients of each `forward` call of a given batch, and only do that for batches 1 and 3. Then you instantiate this class as: ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/debugging.md
https://huggingface.co/docs/transformers/en/debugging/#specific-batch-absolute-min-and-max-value-tracing
#specific-batch-absolute-min-and-max-value-tracing
.md
60_9
<!--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 applicable law or agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/
.md
61_0
An [`AutoClass`](model_doc/auto) automatically infers the model architecture and downloads pretrained configuration and weights. Generally, we recommend using an `AutoClass` to produce checkpoint-agnostic code. But users who want more control over specific model parameters can create a custom 🤗 Transformers model from...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#create-a-custom-architecture
#create-a-custom-architecture
.md
61_1
A [configuration](main_classes/configuration) refers to a model's specific attributes. Each model configuration has different attributes; for instance, all NLP models have the `hidden_size`, `num_attention_heads`, `num_hidden_layers` and `vocab_size` attributes in common. These attributes specify the number of attentio...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#configuration
#configuration
.md
61_2
The next step is to create a [model](main_classes/models). The model - also loosely referred to as the architecture - defines what each layer is doing and what operations are happening. Attributes like `num_hidden_layers` from the configuration are used to define the architecture. Every model shares the base class [`Pr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#model
#model
.md
61_3
At this point, you have a base DistilBERT model which outputs the *hidden states*. The hidden states are passed as inputs to a model head to produce the final output. 🤗 Transformers provides a different model head for each task as long as a model supports the task (i.e., you can't use DistilBERT for a sequence-to-sequ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#model-heads
#model-heads
.md
61_4
The last base class you need before using a model for textual data is a [tokenizer](main_classes/tokenizer) to convert raw text to tensors. There are two types of tokenizers you can use with 🤗 Transformers: - [`PreTrainedTokenizer`]: a Python implementation of a tokenizer. - [`PreTrainedTokenizerFast`]: a tokenizer ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#tokenizer
#tokenizer
.md
61_5
An image processor processes vision inputs. It inherits from the base [`~image_processing_utils.ImageProcessingMixin`] class. To use, create an image processor associated with the model you're using. For example, create a default [`ViTImageProcessor`] if you are using [ViT](model_doc/vit) for image classification: ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#image-processor
#image-processor
.md
61_6
<div style="text-align: center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/Backbone.png"> </div> Computer vision models consist of a backbone, neck, and head. The backbone extracts features from an input image, the neck combines and enhances the extracted fea...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#backbone
#backbone
.md
61_7
A feature extractor processes audio inputs. It inherits from the base [`~feature_extraction_utils.FeatureExtractionMixin`] class, and may also inherit from the [`SequenceFeatureExtractor`] class for processing audio inputs. To use, create a feature extractor associated with the model you're using. For example, create...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#feature-extractor
#feature-extractor
.md
61_8
For models that support multimodal tasks, 🤗 Transformers offers a processor class that conveniently wraps processing classes such as a feature extractor and a tokenizer into a single object. For example, let's use the [`Wav2Vec2Processor`] for an automatic speech recognition task (ASR). ASR transcribes audio to text, ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/create_a_model.md
https://huggingface.co/docs/transformers/en/create_a_model/#processor
#processor
.md
61_9
<!--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 applicable law or agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/
.md
62_0
This guide demonstrates practical techniques that you can use to increase the efficiency of your model's training by optimizing memory utilization, speeding up the training, or both. If you'd like to understand how GPU is utilized during training, please refer to the [Model training anatomy](model_memory_anatomy) conce...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#methods-and-tools-for-efficient-training-on-a-single-gpu
#methods-and-tools-for-efficient-training-on-a-single-gpu
.md
62_1
To achieve optimal performance, start by identifying the appropriate batch size. It is recommended to use batch sizes and input/output neuron counts that are of size 2^N. Often it's a multiple of 8, but it can be higher depending on the hardware being used and the model's dtype. For reference, check out NVIDIA's reco...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#batch-size-choice
#batch-size-choice
.md
62_2
The **gradient accumulation** method aims to calculate gradients in smaller increments instead of computing them for the entire batch at once. This approach involves iteratively calculating gradients in smaller batches by performing forward and backward passes through the model and accumulating the gradients during the...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#gradient-accumulation
#gradient-accumulation
.md
62_3
Some large models may still face memory issues even when the batch size is set to 1 and gradient accumulation is used. This is because there are other components that also require memory storage. Saving all activations from the forward pass in order to compute the gradients during the backward pass can result in sign...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#gradient-checkpointing
#gradient-checkpointing
.md
62_4
**Mixed precision training** is a technique that aims to optimize the computational efficiency of training models by utilizing lower-precision numerical formats for certain variables. Traditionally, most models use 32-bit floating point precision (fp32 or float32) to represent and process variables. However, not all va...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#mixed-precision-training
#mixed-precision-training
.md
62_5
The main advantage of mixed precision training comes from saving the activations in half precision (fp16). Although the gradients are also computed in half precision they are converted back to full precision for the optimization step so no memory is saved here. While mixed precision training results in faster computati...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#fp16
#fp16
.md
62_6
If you have access to an Ampere or newer hardware you can use bf16 for mixed precision training and evaluation. While bf16 has a worse precision than fp16, it has a much bigger dynamic range. In fp16 the biggest number you can have is `65504` and any number above that will result in an overflow. A bf16 number can be as...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#bf16
#bf16
.md
62_7
The Ampere hardware uses a magical data type called tf32. It has the same numerical range as fp32 (8-bits), but instead of 23 bits precision it has only 10 bits (same as fp16) and uses only 19 bits in total. It's "magical" in the sense that you can use the normal fp32 training and/or inference code and by enabling tf32...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#tf32
#tf32
.md
62_8
You can speedup the training throughput by using Flash Attention 2 integration in transformers. Check out the appropriate section in the [single GPU section](./perf_infer_gpu_one#Flash-Attention-2) to learn more about how to load a model with Flash Attention 2 modules.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#flash-attention-2
#flash-attention-2
.md
62_9
The most common optimizer used to train transformer models is Adam or AdamW (Adam with weight decay). Adam achieves good convergence by storing the rolling average of the previous gradients; however, it adds an additional memory footprint of the order of the number of model parameters. To remedy this, you can use an al...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#optimizer-choice
#optimizer-choice
.md
62_10
Adafactor doesn't store rolling averages for each element in weight matrices. Instead, it keeps aggregated information (sums of rolling averages row- and column-wise), significantly reducing its footprint. However, compared to Adam, Adafactor may have slower convergence in certain cases. You can switch to Adafactor b...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#adafactor
#adafactor
.md
62_11
Instead of aggregating optimizer states like Adafactor, 8-bit Adam keeps the full state and quantizes it. Quantization means that it stores the state with lower precision and dequantizes it only for the optimization. This is similar to the idea behind mixed precision training. To use `adamw_bnb_8bit`, you simply need...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#8-bit-adam
#8-bit-adam
.md
62_12
pytorch-nightly introduced `torch.optim._multi_tensor` which should significantly speed up the optimizers for situations with lots of small feature tensors. It should eventually become the default, but if you want to experiment with it sooner, take a look at this GitHub [issue](https://github.com/huggingface/transforme...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#multitensor
#multitensor
.md
62_13
One of the important requirements to reach great training speed is the ability to feed the GPU at the maximum speed it can handle. By default, everything happens in the main process, and it might not be able to read the data from disk fast enough, and thus create a bottleneck, leading to GPU under-utilization. Configur...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#data-preloading
#data-preloading
.md
62_14
DeepSpeed is an open-source deep learning optimization library that is integrated with 🤗 Transformers and 🤗 Accelerate. It provides a wide range of features and optimizations designed to improve the efficiency and scalability of large-scale deep learning training. If your model fits onto a single GPU and you have e...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#deepspeed-zero
#deepspeed-zero
.md
62_15
PyTorch 2.0 introduced a new compile function that doesn't require any modification to existing PyTorch code but can optimize your code by adding a single line of code: `model = torch.compile(model)`. If using [`Trainer`], you only need `to` pass the `torch_compile` option in the [`TrainingArguments`]: ```python tr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#using-torchcompile
#using-torchcompile
.md
62_16
[Parameter-Efficient Fine Tuning (PEFT)](https://huggingface.co/blog/peft) methods freeze the pretrained model parameters during fine-tuning and add a small number of trainable parameters (the adapters) on top of it. As a result the [memory associated to the optimizer states and gradients](https://huggingface.co/docs...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#using--peft
#using--peft
.md
62_17
With [🤗 Accelerate](https://huggingface.co/docs/accelerate/index) you can use the above methods while gaining full control over the training loop and can essentially write the loop in pure PyTorch with some minor modifications. Suppose you have combined the methods in the [`TrainingArguments`] like so: ```py train...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#using--accelerate
#using--accelerate
.md
62_18
PyTorch's [pip and conda builds](https://pytorch.org/get-started/locally/#start-locally) come prebuilt with the cuda toolkit which is enough to run PyTorch, but it is insufficient if you need to build cuda extensions. At times, additional efforts may be required to pre-build some components. For instance, if you're u...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#efficient-software-prebuilds
#efficient-software-prebuilds
.md
62_19
Some recent papers reported a 4-5x training speedup and a faster inference by integrating Mixture of Experts (MoE) into the Transformer models. Since it has been discovered that more parameters lead to better performance, this technique allows to increase the number of parameters by an order of magnitude without incr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#mixture-of-experts
#mixture-of-experts
.md
62_20
PyTorch's [`torch.nn.functional.scaled_dot_product_attention`](https://pytorch.org/docs/master/generated/torch.nn.functional.scaled_dot_product_attention.html) (SDPA) can also call FlashAttention and memory-efficient attention kernels under the hood. SDPA support is currently being added natively in Transformers and is...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_gpu_one.md
https://huggingface.co/docs/transformers/en/perf_train_gpu_one/#using-pytorch-native-attention-and-flash-attention
#using-pytorch-native-attention-and-flash-attention
.md
62_21
<!--- 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 applicable law or a...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/
.md
63_0
Install 🤗 Transformers for whichever deep learning library you're working with, setup your cache, and optionally configure 🤗 Transformers to run offline. 🤗 Transformers is tested on Python 3.6+, PyTorch 1.1.0+, TensorFlow 2.0+, and Flax. Follow the installation instructions below for the deep learning library you ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#installation
#installation
.md
63_1
You should install 🤗 Transformers in a [virtual environment](https://docs.python.org/3/library/venv.html). If you're unfamiliar with Python virtual environments, take a look at this [guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/). A virtual environment makes it easier to man...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#install-with-pip
#install-with-pip
.md
63_2
Install 🤗 Transformers from source with the following command: ```bash pip install git+https://github.com/huggingface/transformers ``` This command installs the bleeding edge `main` version rather than the latest `stable` version. The `main` version is useful for staying up-to-date with the latest developments. Fo...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#install-from-source
#install-from-source
.md
63_3
You will need an editable install if you'd like to: * Use the `main` version of the source code. * Contribute to 🤗 Transformers and need to test changes in the code. Clone the repository and install 🤗 Transformers with the following commands: ```bash git clone https://github.com/huggingface/transformers.git cd ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#editable-install
#editable-install
.md
63_4
Install from the conda channel `conda-forge`: ```bash conda install conda-forge::transformers ```
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#install-with-conda
#install-with-conda
.md
63_5
Pretrained models are downloaded and locally cached at: `~/.cache/huggingface/hub`. This is the default directory given by the shell environment variable `TRANSFORMERS_CACHE`. On Windows, the default directory is given by `C:\Users\username\.cache\huggingface\hub`. You can change the shell environment variables shown b...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#cache-setup
#cache-setup
.md
63_6
Run 🤗 Transformers in a firewalled or offline environment with locally cached files by setting the environment variable `HF_HUB_OFFLINE=1`. <Tip> Add [🤗 Datasets](https://huggingface.co/docs/datasets/) to your offline training workflow with the environment variable `HF_DATASETS_OFFLINE=1`. </Tip> ```bash HF_D...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#offline-mode
#offline-mode
.md
63_7
Another option for using 🤗 Transformers offline is to download the files ahead of time, and then point to their local path when you need to use them offline. There are three ways to do this: * Download a file through the user interface on the [Model Hub](https://huggingface.co/models) by clicking on the ↓ icon. ![...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#fetch-models-and-tokenizers-to-use-offline
#fetch-models-and-tokenizers-to-use-offline
.md
63_8
See below for some of the more common installation issues and how to resolve them.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#troubleshooting
#troubleshooting
.md
63_9
Ensure you are using Python 3.9 or later. Run the command below to check your Python version. ``` python --version ```
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#unsupported-python-version
#unsupported-python-version
.md
63_10
Install all required dependencies by running the following command. Ensure you’re in the project directory before executing the command. ``` pip install -r requirements.txt ```
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#missing-dependencies
#missing-dependencies
.md
63_11
If you encounter issues on Windows, you may need to activate Developer Mode. Navigate to Windows Settings > For Developers > Developer Mode. Alternatively, create and activate a virtual environment as shown below. ``` python -m venv env .\env\Scripts\activate ```
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/installation.md
https://huggingface.co/docs/transformers/en/installation/#windows-specific
#windows-specific
.md
63_12
<!--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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/
.md
64_0
[[open-in-colab]]
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#agents-supercharged---multi-agents-external-tools-and-more
#agents-supercharged---multi-agents-external-tools-and-more
.md
64_1
> [!TIP] > If you're new to `transformers.agents`, make sure to first read the main [agents documentation](./agents). In this page we're going to highlight several advanced uses of `transformers.agents`.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#what-is-an-agent
#what-is-an-agent
.md
64_2
Multi-agent has been introduced in Microsoft's framework [Autogen](https://huggingface.co/papers/2308.08155). It simply means having several agents working together to solve your task instead of only one. It empirically yields better performance on most benchmarks. The reason for this better performance is conceptually...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#multi-agents
#multi-agents
.md
64_3
Let's take again the tool example from main documentation, for which we had implemented a `tool` decorator. If you need to add variation, like custom attributes for your tool, you can build your tool following the fine-grained method: building a class that inherits from the [`Tool`] superclass. The custom tool need...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#directly-define-a-tool-by-subclassing-tool-and-share-it-to-the-hub
#directly-define-a-tool-by-subclassing-tool-and-share-it-to-the-hub
.md
64_4
You can directly import a Space from the Hub as a tool using the [`Tool.from_space`] method! You only need to provide the id of the Space on the Hub, its name, and a description that will help you agent understand what the tool does. Under the hood, this will use [`gradio-client`](https://pypi.org/project/gradio-clie...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#import-a-space-as-a-tool-
#import-a-space-as-a-tool-
.md
64_5
[gradio-tools](https://github.com/freddyaboulton/gradio-tools) is a powerful library that allows using Hugging Face Spaces as tools. It supports many existing Spaces as well as custom Spaces. Transformers supports `gradio_tools` with the [`Tool.from_gradio`] method. For example, let's use the [`StableDiffusionPromptG...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#use-gradio-tools
#use-gradio-tools
.md
64_6
We love Langchain and think it has a very compelling suite of tools. To import a tool from LangChain, use the `from_langchain()` method. Here is how you can use it to recreate the intro's search result using a LangChain web search tool. This tool will need `pip install google-search-results` to work properly. ```pyth...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#use-langchain-tools
#use-langchain-tools
.md
64_7
You can leverage `gradio.Chatbot` to display your agent's thoughts using `stream_to_gradio`, here is an example: ```py import gradio as gr from transformers import ( load_tool, ReactCodeAgent, HfApiEngine, stream_to_gradio, ) # Import tool from Hub image_generation_tool = load_tool("m-ric/text-to-image") llm_engine...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/agents_advanced.md
https://huggingface.co/docs/transformers/en/agents_advanced/#display-your-agent-run-in-a-cool-gradio-interface
#display-your-agent-run-in-a-cool-gradio-interface
.md
64_8
<!--- 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 applicable law or a...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/pr_checks.md
https://huggingface.co/docs/transformers/en/pr_checks/
.md
65_0
When you open a pull request on 🤗 Transformers, a fair number of checks will be run to make sure the patch you are adding is not breaking anything existing. Those checks are of four types: - regular tests - documentation build - code and documentation style - general repository consistency In this document, we will ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/pr_checks.md
https://huggingface.co/docs/transformers/en/pr_checks/#checks-on-a-pull-request
#checks-on-a-pull-request
.md
65_1
All the jobs that begin with `ci/circleci: run_tests_` run parts of the Transformers testing suite. Each of those jobs focuses on a part of the library in a certain environment: for instance `ci/circleci: run_tests_pipelines_tf` runs the pipelines test in an environment where TensorFlow only is installed. Note that t...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/pr_checks.md
https://huggingface.co/docs/transformers/en/pr_checks/#tests
#tests
.md
65_2
The `build_pr_documentation` job builds and generates a preview of the documentation to make sure everything looks okay once your PR is merged. A bot will add a link to preview the documentation in your PR. Any changes you make to the PR are automatically updated in the preview. If the documentation fails to build, cli...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/pr_checks.md
https://huggingface.co/docs/transformers/en/pr_checks/#documentation-build
#documentation-build
.md
65_3
Code formatting is applied to all the source files, the examples and the tests using `black` and `ruff`. We also have a custom tool taking care of the formatting of docstrings and `rst` files (`utils/style_doc.py`), as well as the order of the lazy imports performed in the Transformers `__init__.py` files (`utils/custo...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/pr_checks.md
https://huggingface.co/docs/transformers/en/pr_checks/#code-and-documentation-style
#code-and-documentation-style
.md
65_4
This regroups all the tests to make sure your PR leaves the repository in a good state, and is performed by the `ci/circleci: check_repository_consistency` check. You can locally run that check by executing the following: ```bash make repo-consistency ``` This checks that: - All objects added to the init are docu...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/pr_checks.md
https://huggingface.co/docs/transformers/en/pr_checks/#repository-consistency
#repository-consistency
.md
65_5
Since the Transformers library is very opinionated with respect to model code, and each model should fully be implemented in a single file without relying on other models, we have added a mechanism that checks whether a copy of the code of a layer of a given model stays consistent with the original. This way, when ther...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/pr_checks.md
https://huggingface.co/docs/transformers/en/pr_checks/#check-copies
#check-copies
.md
65_6
<!--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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_infer_gpu_multi.md
https://huggingface.co/docs/transformers/en/perf_infer_gpu_multi/
.md
66_0
Built-in Tensor Parallelism (TP) is now available with certain models using PyTorch. Tensor parallelism shards a model onto multiple GPUs, enabling larger model sizes, and parallelizes computations such as matrix multiplication. To enable tensor parallel, pass the argument `tp_plan="auto"` to [`~AutoModelForCausalLM....
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_infer_gpu_multi.md
https://huggingface.co/docs/transformers/en/perf_infer_gpu_multi/#multi-gpu-inference
#multi-gpu-inference
.md
66_1
You can benefit from considerable speedups for inference, especially for inputs with large batch size or long sequences. For a single forward pass on [Llama](https://huggingface.co/docs/transformers/model_doc/llama#transformers.LlamaModel) with a sequence length of 512 and various batch sizes, the expected speedup is...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_infer_gpu_multi.md
https://huggingface.co/docs/transformers/en/perf_infer_gpu_multi/#expected-speedups
#expected-speedups
.md
66_2
<!--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 applicable law or agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tflite.md
https://huggingface.co/docs/transformers/en/tflite/
.md
67_0
[TensorFlow Lite](https://www.tensorflow.org/lite/guide) is a lightweight framework for deploying machine learning models on resource-constrained devices, such as mobile phones, embedded systems, and Internet of Things (IoT) devices. TFLite is designed to optimize and run models efficiently on these devices with limite...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tflite.md
https://huggingface.co/docs/transformers/en/tflite/#export-to-tflite
#export-to-tflite
.md
67_1
<!--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 applicable law or agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/
.md
68_0
This guide aims to provide a benchmark on the inference speed-ups introduced with [`torch.compile()`](https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html)for [computer vision models in 🤗 Transformers](https://huggingface.co/models?pipeline_tag=image-classification&library=transformers&sort=trending)...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#optimize-inference-using-torchcompile
#optimize-inference-using-torchcompile
.md
68_1
Depending on the model and the GPU, `torch.compile()` yields up to 30% speed-up during inference. To use `torch.compile()`, simply install any version of `torch` above 2.0. Compiling a model takes time, so it's useful if you are compiling the model only once instead of every time you infer. To compile any computer vi...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#benefits-of-torchcompile
#benefits-of-torchcompile
.md
68_2
Below you can find the benchmarking code for each task. We warm up the GPU before inference and take the mean time of 300 inferences, using the same image each time.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#benchmarking-code
#benchmarking-code
.md
68_3
```python import torch from PIL import Image import requests import numpy as np from transformers import AutoImageProcessor, AutoModelForImageClassification from accelerate.test_utils.testing import get_backend device, _, _ = get_backend() # automatically detects the underlying device type (CUDA, CPU, XPU, MPS, etc.) ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#image-classification-with-vit
#image-classification-with-vit
.md
68_4
```python from transformers import AutoImageProcessor, AutoModelForObjectDetection from accelerate.test_utils.testing import get_backend device, _, _ = get_backend() # automatically detects the underlying device type (CUDA, CPU, XPU, MPS, etc.) processor = AutoImageProcessor.from_pretrained("facebook/detr-resnet-50") ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#object-detection-with-detr
#object-detection-with-detr
.md
68_5
```python from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation from accelerate.test_utils.testing import get_backend device, _, _ = get_backend() # automatically detects the underlying device type (CUDA, CPU, XPU, MPS, etc.) processor = SegformerImageProcessor.from_pretrained("nvidia/segf...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#image-segmentation-with-segformer
#image-segmentation-with-segformer
.md
68_6
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 9.325 | 7.584 | | Image Segmentation/Segformer | 11.759 | 10.500 | | Object Detection/OwlViT | 24.978 | 18.420 | | Image Classification/BeiT | 11.282 | 8.448 | | Object Detection/DETR | 34....
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#a100-batch-size-1
#a100-batch-size-1
.md
68_7
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 14.832 | 14.499 | | Image Segmentation/Segformer | 18.838 | 16.476 | | Image Classification/BeiT | 13.205 | 13.048 | | Object Detection/DETR | 48.657 | 32.418| | Image Classification/ConvNe...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#a100-batch-size-4
#a100-batch-size-4
.md
68_8
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 40.944 | 40.010 | | Image Segmentation/Segformer | 37.005 | 31.144 | | Image Classification/BeiT | 41.854 | 41.048 | | Object Detection/DETR | 164.382 | 161.902 | | Image Classification/Con...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#a100-batch-size-16
#a100-batch-size-16
.md
68_9
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 10.495 | 6.00 | | Image Segmentation/Segformer | 13.321 | 5.862 | | Object Detection/OwlViT | 25.769 | 22.395 | | Image Classification/BeiT | 11.347 | 7.234 | | Object Detection/DETR | 33.9...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#v100-batch-size-1
#v100-batch-size-1
.md
68_10
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 15.181 | 14.501 | | Image Segmentation/Segformer | 16.787 | 16.188 | | Image Classification/BeiT | 15.171 | 14.753 | | Object Detection/DETR | 88.529 | 64.195 | | Image Classification/ConvN...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#v100-batch-size-4
#v100-batch-size-4
.md
68_11
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 52.209 | 51.633 | | Image Segmentation/Segformer | 61.013 | 55.499 | | Image Classification/BeiT | 53.938 | 53.581 | | Object Detection/DETR | OOM | OOM | | Image Classification/ConvNeXT |...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#v100-batch-size-16
#v100-batch-size-16
.md
68_12
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 16.520 | 15.786 | | Image Segmentation/Segformer | 16.116 | 14.205 | | Object Detection/OwlViT | 53.634 | 51.105 | | Image Classification/BeiT | 16.464 | 15.710 | | Object Detection/DETR | ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#t4-batch-size-1
#t4-batch-size-1
.md
68_13
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 43.653 | 43.626 | | Image Segmentation/Segformer | 45.327 | 42.445 | | Image Classification/BeiT | 52.007 | 51.354 | | Object Detection/DETR | 277.850 | 268.003 | | Image Classification/Con...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#t4-batch-size-4
#t4-batch-size-4
.md
68_14
| **Task/Model** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:| | Image Classification/ViT | 163.914 | 160.907 | | Image Segmentation/Segformer | 192.412 | 163.620 | | Image Classification/BeiT | 188.978 | 187.976 | | Object Detection/DETR | OOM | OOM | | Image Classification/ConvN...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#t4-batch-size-16
#t4-batch-size-16
.md
68_15
We also benchmarked on PyTorch nightly (2.1.0dev, find the wheel [here](https://download.pytorch.org/whl/nightly/cu118)) and observed improvement in latency both for uncompiled and compiled models.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#pytorch-nightly
#pytorch-nightly
.md
68_16
| **Task/Model** | **Batch Size** | **torch 2.0 - no compile** | **torch 2.0 -<br> compile** | |:---:|:---:|:---:|:---:| | Image Classification/BeiT | Unbatched | 12.462 | 6.954 | | Image Classification/BeiT | 4 | 14.109 | 12.851 | | Image Classification/BeiT | 16 | 42.179 | 42.147 | | Object Detection/DETR | Unbatched...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#a100
#a100
.md
68_17
| **Task/Model** | **Batch Size** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:|:---:| | Image Classification/BeiT | Unbatched | 14.408 | 14.052 | | Image Classification/BeiT | 4 | 47.381 | 46.604 | | Image Classification/BeiT | 16 | 42.179 | 42.147 | | Object Detection/DETR | Unb...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#t4
#t4
.md
68_18
| **Task/Model** | **Batch Size** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:|:---:| | Image Classification/BeiT | Unbatched | 13.477 | 7.926 | | Image Classification/BeiT | 4 | 15.103 | 14.378 | | Image Classification/BeiT | 16 | 52.517 | 51.691 | | Object Detection/DETR | Unba...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#v100
#v100
.md
68_19
We benchmarked `reduce-overhead` compilation mode for A100 and T4 in Nightly.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#reduce-overhead
#reduce-overhead
.md
68_20
| **Task/Model** | **Batch Size** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:|:---:| | Image Classification/ConvNeXT | Unbatched | 11.758 | 7.335 | | Image Classification/ConvNeXT | 4 | 23.171 | 21.490 | | Image Classification/ResNet | Unbatched | 7.435 | 3.801 | | Image Classifi...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#a100
#a100
.md
68_21
| **Task/Model** | **Batch Size** | **torch 2.0 - <br>no compile** | **torch 2.0 - <br>compile** | |:---:|:---:|:---:|:---:| | Image Classification/ConvNeXT | Unbatched | 32.137 | 31.84 | | Image Classification/ConvNeXT | 4 | 120.944 | 110.209 | | Image Classification/ResNet | Unbatched | 9.761 | 7.698 | | Image Classi...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_torch_compile.md
https://huggingface.co/docs/transformers/en/perf_torch_compile/#t4
#t4
.md
68_22
<!--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 applicable law or agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_special.md
https://huggingface.co/docs/transformers/en/perf_train_special/
.md
69_0
Previously, training models on a Mac was limited to the CPU only. With the release of PyTorch v1.12, you can take advantage of training models with Apple's silicon GPUs for significantly faster performance and training. This is powered in PyTorch by integrating Apple's Metal Performance Shaders (MPS) as a backend. The ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/perf_train_special.md
https://huggingface.co/docs/transformers/en/perf_train_special/#pytorch-training-on-apple-silicon
#pytorch-training-on-apple-silicon
.md
69_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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tiktoken.md
https://huggingface.co/docs/transformers/en/tiktoken/
.md
70_0
Support for tiktoken model files is seamlessly integrated in 🤗 transformers when loading models `from_pretrained` with a `tokenizer.model` tiktoken file on the Hub, which is automatically converted into our [fast tokenizer](https://huggingface.co/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrained...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tiktoken.md
https://huggingface.co/docs/transformers/en/tiktoken/#tiktoken-and-interaction-with-transformers
#tiktoken-and-interaction-with-transformers
.md
70_1
- gpt2 - llama3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tiktoken.md
https://huggingface.co/docs/transformers/en/tiktoken/#known-models-that-were-released-with-a-tiktokenmodel
#known-models-that-were-released-with-a-tiktokenmodel
.md
70_2
In order to load `tiktoken` files in `transformers`, ensure that the `tokenizer.model` file is a tiktoken file and it will automatically be loaded when loading `from_pretrained`. Here is how one would load a tokenizer and a model, which can be loaded from the exact same file: ```py from transformers import AutoTokeni...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tiktoken.md
https://huggingface.co/docs/transformers/en/tiktoken/#example-usage
#example-usage
.md
70_3