source
stringclasses
470 values
url
stringlengths
49
167
file_type
stringclasses
1 value
chunk
stringlengths
1
512
chunk_id
stringlengths
5
9
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#react-agents
.md
This agent that solves the given task step by step, using the ReAct framework: While the objective is not reached, the agent will perform a cycle of thinking and acting. The action will be parsed from the LLM output: it consists in calls to tools from the toolbox, with arguments chosen by the LLM engine. This agent t...
449_5_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#react-agents
.md
While the objective is not reached, the agent will perform a cycle of thinking and acting. The tool calls will be formulated by the LLM in JSON format, then parsed and executed. This agent that solves the given task step by step, using the ReAct framework: While the objective is not reached, the agent will perform a ...
449_5_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#managedagent
.md
ManagedAgent
449_6_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#loadtool
.md
Main function to quickly load a tool, be it on the Hub or in the Transformers library. <Tip warning={true}> Loading a tool means that you'll download the tool and execute it locally. ALWAYS inspect the tool you're downloading before loading it within your runtime, as you would do when installing a package using pip...
449_7_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#loadtool
.md
The task for which to load the tool or a repo ID of a tool on the Hub. Tasks implemented in Transformers are: - `"document_question_answering"` - `"image_question_answering"` - `"speech_to_text"` - `"text_to_speech"` - `"translation"` model_repo_id (`str`, *optional*): Use this argument to use a different model tha...
449_7_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#loadtool
.md
The token to identify you on hf.co. If unset, will use the token generated when running `huggingface-cli login` (stored in `~/.huggingface`). kwargs (additional keyword arguments, *optional*): Additional keyword arguments that will be split in two: all arguments relevant to the Hub (such as `cache_dir`, `revision`, `su...
449_7_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#tool
.md
Converts a function into an instance of a Tool subclass. Args: tool_function: Your function. Should have type hints for each input and a type hint for the output. Should also have a docstring description including an 'Args:' part where each argument is described.
449_8_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#tool
.md
A base class for the functions used by the agent. Subclass this and implement the `__call__` method as well as the following class attributes: - **description** (`str`) -- A short description of what your tool does, the inputs it expects and the output(s) it will return. For instance 'This is a tool that downloads a ...
449_9_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#tool
.md
returns the text contained in the file'. - **name** (`str`) -- A performative name that will be used for your tool in the prompt to the agent. For instance `"text-classifier"` or `"image_generator"`. - **inputs** (`Dict[str, Dict[str, Union[str, type]]]`) -- The dict of modalities expected for the inputs. It has one `t...
449_9_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#tool
.md
description for your tool. - **output_type** (`type`) -- The type of the tool output. This is used by `launch_gradio_demo` or to make a nice space from your tool, and also can be used in the generated description for your tool. You can also override the method [`~Tool.setup`] if your tool as an expensive operation to...
449_9_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#toolbox
.md
A base class for the functions used by the agent. Subclass this and implement the `__call__` method as well as the following class attributes: - **description** (`str`) -- A short description of what your tool does, the inputs it expects and the output(s) it will return. For instance 'This is a tool that downloads a ...
449_10_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#toolbox
.md
returns the text contained in the file'. - **name** (`str`) -- A performative name that will be used for your tool in the prompt to the agent. For instance `"text-classifier"` or `"image_generator"`. - **inputs** (`Dict[str, Dict[str, Union[str, type]]]`) -- The dict of modalities expected for the inputs. It has one `t...
449_10_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#toolbox
.md
description for your tool. - **output_type** (`type`) -- The type of the tool output. This is used by `launch_gradio_demo` or to make a nice space from your tool, and also can be used in the generated description for your tool. You can also override the method [`~Tool.setup`] if your tool as an expensive operation to...
449_10_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#pipelinetool
.md
A [`Tool`] tailored towards Transformer models. On top of the class attributes of the base class [`Tool`], you will need to specify: - **model_class** (`type`) -- The class to use to load the model in this tool. - **default_checkpoint** (`str`) -- The default checkpoint that should be used when the user doesn't speci...
449_11_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#pipelinetool
.md
- **pre_processor_class** (`type`, *optional*, defaults to [`AutoProcessor`]) -- The class to use to load the pre-processor - **post_processor_class** (`type`, *optional*, defaults to [`AutoProcessor`]) -- The class to use to load the post-processor (when different from the pre-processor). Args: model (`str` or [`Pre...
449_11_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#pipelinetool
.md
value of the class attribute `default_checkpoint`. pre_processor (`str` or `Any`, *optional*): The name of the checkpoint to use for the pre-processor, or the instantiated pre-processor (can be a tokenizer, an image processor, a feature extractor or a processor). Will default to the value of `model` if unset. post_proc...
449_11_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#pipelinetool
.md
The name of the checkpoint to use for the post-processor, or the instantiated pre-processor (can be a tokenizer, an image processor, a feature extractor or a processor). Will default to the `pre_processor` if unset. device (`int`, `str` or `torch.device`, *optional*): The device on which to execute the model. Will defa...
449_11_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#pipelinetool
.md
CPU otherwise. device_map (`str` or `dict`, *optional*): If passed along, will be used to instantiate the model. model_kwargs (`dict`, *optional*): Any keyword argument to send to the model instantiation. token (`str`, *optional*): The token to use as HTTP bearer authorization for remote files. If unset, will use the t...
449_11_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#pipelinetool
.md
running `huggingface-cli login` (stored in `~/.huggingface`). hub_kwargs (additional keyword arguments, *optional*): Any additional keyword argument to send to the methods that will load the data from the Hub.
449_11_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#launchgradiodemo
.md
Launches a gradio demo for a tool. The corresponding tool class needs to properly implement the class attributes `inputs` and `output_type`. Args: tool_class (`type`): The class of the tool for which to launch the demo.
449_12_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#streamtogradio
.md
Runs an agent with the given task and streams the messages from the agent as gradio ChatMessages.
449_13_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#toolcollection
.md
A base class for the functions used by the agent. Subclass this and implement the `__call__` method as well as the following class attributes: - **description** (`str`) -- A short description of what your tool does, the inputs it expects and the output(s) it will return. For instance 'This is a tool that downloads a ...
449_14_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#toolcollection
.md
returns the text contained in the file'. - **name** (`str`) -- A performative name that will be used for your tool in the prompt to the agent. For instance `"text-classifier"` or `"image_generator"`. - **inputs** (`Dict[str, Dict[str, Union[str, type]]]`) -- The dict of modalities expected for the inputs. It has one `t...
449_14_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#toolcollection
.md
description for your tool. - **output_type** (`type`) -- The type of the tool output. This is used by `launch_gradio_demo` or to make a nice space from your tool, and also can be used in the generated description for your tool. You can also override the method [`~Tool.setup`] if your tool as an expensive operation to...
449_14_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#engines
.md
You're free to create and use your own engines to be usable by the Agents framework. These engines have the following specification: 1. Follow the [messages format](../chat_templating.md) for its input (`List[Dict[str, str]]`) and return a string. 2. Stop generating outputs *before* the sequences passed in the argument...
449_15_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#transformersengine
.md
For convenience, we have added a `TransformersEngine` that implements the points above, taking a pre-initialized `Pipeline` as input. ```python >>> from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, TransformersEngine >>> model_name = "HuggingFaceTB/SmolLM-135M-Instruct" >>> tokenizer = AutoToke...
449_16_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#transformersengine
.md
>>> pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) >>> engine = TransformersEngine(pipe) >>> engine([{"role": "user", "content": "Ok!"}], stop_sequences=["great"]) "What a " ``` This engine uses a pre-initialized local text-generation pipeline.
449_16_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#hfapiengine
.md
The `HfApiEngine` is an engine that wraps an [HF Inference API](https://huggingface.co/docs/api-inference/index) client for the execution of the LLM. ```python >>> from transformers import HfApiEngine >>> messages = [ ... {"role": "user", "content": "Hello, how are you?"}, ... {"role": "assistant", "content": "I...
449_17_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#hfapiengine
.md
"That's very kind of you to say! It's always nice to have a relaxed " ``` A class to interact with Hugging Face's Inference API for language model interaction. This engine allows you to communicate with Hugging Face's models using the Inference API. It can be used in both serverless mode or with a dedicated endpoin...
449_17_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#hfapiengine
.md
Parameters: model (`str`, *optional*, defaults to `"meta-llama/Meta-Llama-3.1-8B-Instruct"`): The Hugging Face model ID to be used for inference. This can be a path or model identifier from the Hugging Face model hub. token (`str`, *optional*): Token used by the Hugging Face API for authentication. If not provided, the...
449_17_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#hfapiengine
.md
max_tokens (`int`, *optional*, defaults to 1500): The maximum number of tokens allowed in the output. timeout (`int`, *optional*, defaults to 120): Timeout for the API request, in seconds. Raises: ValueError: If the model name is not provided.
449_17_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#agent-types
.md
Agents can handle any type of object in-between tools; tools, being completely multimodal, can accept and return text, image, audio, video, among other types. In order to increase compatibility between tools, as well as to correctly render these returns in ipython (jupyter, colab, ipython notebooks, ...), we implement ...
449_18_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#agent-types
.md
The wrapped objects should continue behaving as initially; a text object should still behave as a string, an image object should still behave as a `PIL.Image`. These types have three specific purposes: - Calling `to_raw` on the type should return the underlying object - Calling `to_string` on the type should return...
449_18_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#agent-types
.md
but will be the path of the serialized version of the object in other instances - Displaying it in an ipython kernel should display the object correctly
449_18_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#agenttext
.md
Text type returned by the agent. Behaves as a string.
449_19_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#agentimage
.md
Image type returned by the agent. Behaves as a PIL.Image.
449_20_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/agent.md
https://huggingface.co/docs/transformers/en/main_classes/agent/#agentaudio
.md
Audio type returned by the agent.
449_21_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/
.md
<!--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 agr...
450_0_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be rendered ...
450_0_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/#feature-extractor
.md
A feature extractor is in charge of preparing input features for audio or vision models. This includes feature extraction from sequences, e.g., pre-processing audio files to generate Log-Mel Spectrogram features, feature extraction from images, e.g., cropping image files, but also padding, normalization, and conversion...
450_1_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/#featureextractionmixin
.md
feature_extraction_utils.FeatureExtractionMixin This is a feature extraction mixin used to provide saving/loading functionality for sequential and image feature extractors. - from_pretrained - save_pretrained
450_2_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/#sequencefeatureextractor
.md
This is a general feature extraction class for speech recognition. Args: feature_size (`int`): The feature dimension of the extracted features. sampling_rate (`int`): The sampling rate at which the audio files should be digitalized expressed in hertz (Hz). padding_value (`float`): The value that is used to fill the p...
450_3_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/#batchfeature
.md
Holds the output of the [`~SequenceFeatureExtractor.pad`] and feature extractor specific `__call__` methods. This class is derived from a python dictionary and can be used as a dictionary. Args: data (`dict`, *optional*): Dictionary of lists/arrays/tensors returned by the __call__/pad methods ('input_values', 'atte...
450_4_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/#batchfeature
.md
You can give a tensor_type here to convert the lists of integers in PyTorch/TensorFlow/Numpy Tensors at initialization.
450_4_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/feature_extractor.md
https://huggingface.co/docs/transformers/en/main_classes/feature_extractor/#imagefeatureextractionmixin
.md
image_utils.ImageFeatureExtractionMixin Mixin that contain utilities for preparing image features.
450_5_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/executorch.md
https://huggingface.co/docs/transformers/en/main_classes/executorch/
.md
<!--Copyright (c) Meta Platforms, Inc. and affiliates. 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 applica...
451_0_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/executorch.md
https://huggingface.co/docs/transformers/en/main_classes/executorch/
.md
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ⚠️ Note that...
451_0_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/executorch.md
https://huggingface.co/docs/transformers/en/main_classes/executorch/#executorch
.md
[`ExecuTorch`](https://github.com/pytorch/executorch) is an end-to-end solution for enabling on-device inference capabilities across mobile and edge devices including wearables, embedded devices and microcontrollers. It is part of the PyTorch ecosystem and supports the deployment of PyTorch models with a focus on porta...
451_1_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/executorch.md
https://huggingface.co/docs/transformers/en/main_classes/executorch/#executorch
.md
ExecuTorch introduces well defined entry points to perform model, device, and/or use-case specific optimizations such as backend delegation, user-defined compiler transformations, memory planning, and more. The first step in preparing a PyTorch model for execution on an edge device using ExecuTorch is to export the mod...
451_1_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/executorch.md
https://huggingface.co/docs/transformers/en/main_classes/executorch/#executorch-integration
.md
An integration point is being developed to ensure that 🤗 Transformers can be exported using `torch.export`. The goal of this integration is not only to enable export but also to ensure that the exported artifact can be further lowered and optimized to run efficiently in `ExecuTorch`, particularly for mobile and edge u...
451_2_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/executorch.md
https://huggingface.co/docs/transformers/en/main_classes/executorch/#executorch-integration
.md
specifically for use with static caching. This module ensures that the exported model is compatible with further lowering and execution in `ExecuTorch`. Note: This class is specifically designed to support export process using `torch.export` in a way that ensures the model can be further lowered and run efficiently i...
451_2_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/executorch.md
https://huggingface.co/docs/transformers/en/main_classes/executorch/#executorch-integration
.md
ensuring the exported model is compatible with `ExecuTorch`. Args: model (`PreTrainedModel`): The pretrained model to be exported. example_input_ids (`torch.Tensor`): Example input token id used by `torch.export`. example_cache_position (`torch.Tensor`): Example current cache position used by `torch.export`. Return...
451_2_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/
.md
<!--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...
452_0_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be rendered ...
452_0_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generation
.md
Each framework has a generate method for text generation implemented in their respective `GenerationMixin` class: - PyTorch [`~generation.GenerationMixin.generate`] is implemented in [`~generation.GenerationMixin`]. - TensorFlow [`~generation.TFGenerationMixin.generate`] is implemented in [`~generation.TFGenerationMi...
452_1_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generation
.md
- Flax/JAX [`~generation.FlaxGenerationMixin.generate`] is implemented in [`~generation.FlaxGenerationMixin`]. Regardless of your framework of choice, you can parameterize the generate method with a [`~generation.GenerationConfig`] class instance. Please refer to this class for the complete list of generation paramet...
452_1_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generation
.md
To learn how to inspect a model's generation configuration, what are the defaults, how to change the parameters ad hoc, and how to create and save a customized generation configuration, refer to the [text generation strategies guide](../generation_strategies). The guide also explains how to use related features, like t...
452_1_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
generation.GenerationConfig Class that holds a configuration for a generation task. A `generate` call supports the following generation methods for text-decoder, text-to-text, speech-to-text, and vision-to-text models: - *greedy decoding* if `num_beams=1` and `do_sample=False` - *contrastive search* if `penalty_alp...
452_2_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
- *multinomial sampling* if `num_beams=1` and `do_sample=True` - *beam-search decoding* if `num_beams>1` and `do_sample=False` - *beam-search multinomial sampling* if `num_beams>1` and `do_sample=True` - *diverse beam-search decoding* if `num_beams>1` and `num_beam_groups>1` - *constrained beam-search decoding* if `con...
452_2_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
- *assisted decoding* if `assistant_model` or `prompt_lookup_num_tokens` is passed to `.generate()` - *dola decoding* if `dola_layers` is passed to `.generate()` To learn more about decoding strategies refer to the [text generation strategies guide](../generation_strategies). <Tip> A large number of these flags c...
452_2_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
the [generate-related classes](https://huggingface.co/docs/transformers/internal/generation_utils) for a full description of the possible manipulations, as well as examples of their usage. </Tip> Arg: > Parameters that control the length of the output max_length (`int`, *optional*, defaults to 20): The maximum le...
452_2_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
`max_new_tokens`. Its effect is overridden by `max_new_tokens`, if also set. max_new_tokens (`int`, *optional*): The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt. min_length (`int`, *optional*, defaults to 0): The minimum length of the sequence to be generated. Corresponds to the l...
452_2_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
`min_new_tokens`. Its effect is overridden by `min_new_tokens`, if also set. min_new_tokens (`int`, *optional*): The minimum numbers of tokens to generate, ignoring the number of tokens in the prompt. early_stopping (`bool` or `str`, *optional*, defaults to `False`): Controls the stopping condition for beam-based metho...
452_2_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
`True`, where the generation stops as soon as there are `num_beams` complete candidates; `False`, where an heuristic is applied and the generation stops when is it very unlikely to find better candidates; `"never"`, where the beam search procedure only stops when there cannot be better candidates (canonical beam search...
452_2_6
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
The maximum amount of time you allow the computation to run for in seconds. generation will still finish the current pass after allocated time has been passed. stop_strings (`str or List[str]`, *optional*): A string or a list of strings that should terminate generation if the model outputs them. > Parameters that con...
452_2_7
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
do_sample (`bool`, *optional*, defaults to `False`): Whether or not to use sampling ; use greedy decoding otherwise. num_beams (`int`, *optional*, defaults to 1): Number of beams for beam search. 1 means no beam search. num_beam_groups (`int`, *optional*, defaults to 1): Number of groups to divide `num_beams` into in o...
452_2_8
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
[this paper](https://arxiv.org/pdf/1610.02424.pdf) for more details. penalty_alpha (`float`, *optional*): The values balance the model confidence and the degeneration penalty in contrastive search decoding. dola_layers (`str` or `List[int]`, *optional*): The layers to use for DoLa decoding. If `None`, DoLa decoding is ...
452_2_9
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
be one of "low" or "high", which means using the lower part or higher part of the model layers, respectively. "low" means the first half of the layers up to the first 20 layers, and "high" means the last half of the layers up to the last 20 layers. If a list of integers, it must contain the indices of the layers to use...
452_2_10
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
The 0-th layer is the word embedding layer of the model. Set to `'low'` to improve long-answer reasoning tasks, `'high'` to improve short-answer tasks. Check the [documentation](https://github.com/huggingface/transformers/blob/main/docs/source/en/generation_strategies.md) or [the paper](https://arxiv.org/abs/2309.03883...
452_2_11
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
> Parameters that control the cache use_cache (`bool`, *optional*, defaults to `True`): Whether or not the model should use the past last key/values attentions (if applicable to the model) to speed up decoding. cache_implementation (`str`, *optional*, default to `None`): Name of the cache class that will be instantia...
452_2_12
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
- `"static"`: [`StaticCache`] - `"offloaded_static"`: [`OffloadedStaticCache`] - `"sliding_window"`: [`SlidingWindowCache`] - `"hybrid"`: [`HybridCache`] - `"mamba"`: [`MambaCache`] - `"quantized"`: [`QuantizedCache`] We support other cache types, but they must be manually instantiated and passed to `generate` throug...
452_2_13
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
[cache documentation](https://huggingface.co/docs/transformers/en/kv_cache) for further information. cache_config (`CacheConfig` or `dict`, *optional*, default to `None`): Arguments used in the key-value cache class can be passed in `cache_config`. Can be passed as a `Dict` and it will be converted to its repsective `C...
452_2_14
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
return_legacy_cache (`bool`, *optional*, default to `True`): Whether to return the legacy or new format of the cache when `DynamicCache` is used by default. > Parameters for manipulation of the model output logits temperature (`float`, *optional*, defaults to 1.0): The value used to module the next token probabilit...
452_2_15
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
top_k (`int`, *optional*, defaults to 50): The number of highest probability vocabulary tokens to keep for top-k-filtering. This value is set in a model's `generation_config.json` file. If it isn't set, the default value is 50. top_p (`float`, *optional*, defaults to 1.0): If set to float < 1, only the smallest set of ...
452_2_16
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
If set to float < 1, only the smallest set of most probable tokens with probabilities that add up to `top_p` or higher are kept for generation. This value is set in a model's `generation_config.json` file. If it isn't set, the default value is 1.0 min_p (`float`, *optional*): Minimum token probability, which will be sc...
452_2_17
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
value between 0 and 1. Typical values are in the 0.01-0.2 range, comparably selective as setting `top_p` in the 0.99-0.8 range (use the opposite of normal `top_p` values). typical_p (`float`, *optional*, defaults to 1.0): Local typicality measures how similar the conditional probability of predicting a target token nex...
452_2_18
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
the expected conditional probability of predicting a random token next, given the partial text already generated. If set to float < 1, the smallest set of the most locally typical tokens with probabilities that add up to `typical_p` or higher are kept for generation. See [this paper](https://arxiv.org/pdf/2202.00666.pd...
452_2_19
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
If set to float strictly between 0 and 1, only tokens with a conditional probability greater than `epsilon_cutoff` will be sampled. In the paper, suggested values range from 3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for mo...
452_2_20
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to float strictly between 0 and 1, a token is only considered if it is greater than either `eta_cutoff` or `sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits)))`. The latter term is intuitively the expected next token probability,...
452_2_21
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
depending on the size of the model. See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details. diversity_penalty (`float`, *optional*, defaults to 0.0): This value is subtracted from a beam's score if it generates a token same as any beam from other group at a particular...
452_2_22
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
repetition_penalty (`float`, *optional*, defaults to 1.0): The parameter for repetition penalty. 1.0 means no penalty. See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details. encoder_repetition_penalty (`float`, *optional*, defaults to 1.0): The paramater for encoder_repetition_penalty. An exponential ...
452_2_23
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
original input. 1.0 means no penalty. length_penalty (`float`, *optional*, defaults to 1.0): Exponential penalty to the length that is used with beam-based generation. It is applied as an exponent to the sequence length, which in turn is used to divide the score of the sequence. Since the score is the log likelihood of...
452_2_24
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
`length_penalty` < 0.0 encourages shorter sequences. no_repeat_ngram_size (`int`, *optional*, defaults to 0): If set to int > 0, all ngrams of that size can only occur once. bad_words_ids (`List[List[int]]`, *optional*): List of list of token ids that are not allowed to be generated. Check [`~generation.NoBadWordsLogit...
452_2_25
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
force_words_ids (`List[List[int]]` or `List[List[List[int]]]`, *optional*): List of token ids that must be generated. If given a `List[List[int]]`, this is treated as a simple list of words that must be included, the opposite to `bad_words_ids`. If given `List[List[List[int]]]`, this triggers a [disjunctive constraint]...
452_2_26
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
can allow different forms of each word. renormalize_logits (`bool`, *optional*, defaults to `False`): Whether to renormalize the logits after applying all the logits processors (including the custom ones). It's highly recommended to set this flag to `True` as the search algorithms suppose the score logits are normalize...
452_2_27
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
are normalized but some logit processors break the normalization. constraints (`List[Constraint]`, *optional*): Custom constraints that can be added to the generation to ensure that the output will contain the use of certain tokens as defined by `Constraint` objects, in the most sensible way possible. forced_bos_token_...
452_2_28
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
The id of the token to force as the first generated token after the `decoder_start_token_id`. Useful for multilingual models like [mBART](../model_doc/mbart) where the first generated token needs to be the target language token. forced_eos_token_id (`int` or List[int]`, *optional*, defaults to `model.config.forced_eos_...
452_2_29
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
list to set multiple *end-of-sequence* tokens. remove_invalid_values (`bool`, *optional*, defaults to `model.config.remove_invalid_values`): Whether to remove possible *nan* and *inf* outputs of the model to prevent the generation method to crash. Note that using `remove_invalid_values` can slow down generation. expone...
452_2_30
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
This Tuple adds an exponentially increasing length penalty, after a certain amount of tokens have been generated. The tuple shall consist of: `(start_index, decay_factor)` where `start_index` indicates where penalty starts and `decay_factor` represents the factor of exponential decay suppress_tokens (`List[int]`, *opti...
452_2_31
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
log probs to `-inf` so that they are not sampled. begin_suppress_tokens (`List[int]`, *optional*): A list of tokens that will be suppressed at the beginning of the generation. The `SupressBeginTokens` logit processor will set their log probs to `-inf` so that they are not sampled. forced_decoder_ids (`List[List[int]]`...
452_2_32
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
A list of pairs of integers which indicates a mapping from generation indices to token indices that will be forced before sampling. For example, `[[1, 123]]` means the second generated token will always be a token of index 123. sequence_bias (`Dict[Tuple[int], float]`, *optional*)): Dictionary that maps a sequence of t...
452_2_33
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
sequence being selected, while negative biases do the opposite. Check [`~generation.SequenceBiasLogitsProcessor`] for further documentation and examples. token_healing (`bool`, *optional*, defaults to `False`): Heal tail tokens of prompts by replacing them with their appropriate extensions. This enhances the quality of...
452_2_34
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
guidance_scale (`float`, *optional*): The guidance scale for classifier free guidance (CFG). CFG is enabled by setting `guidance_scale > 1`. Higher guidance scale encourages the model to generate samples that are more closely linked to the input prompt, usually at the expense of poorer quality. low_memory (`bool`, *opt...
452_2_35
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
Used with beam search and contrastive search. watermarking_config (`BaseWatermarkingConfig` or `dict`, *optional*): Arguments used to watermark the model outputs by adding a small bias to randomly selected set of "green" tokens. See the docs of [`SynthIDTextWatermarkingConfig`] and [`WatermarkingConfig`] for more detai...
452_2_36
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
> Parameters that define the output variables of generate num_return_sequences (`int`, *optional*, defaults to 1): The number of independently computed returned sequences for each element in the batch. output_attentions (`bool`, *optional*, defaults to `False`): Whether or not to return the attentions tensors of all ...
452_2_37
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
tensors for more details. output_hidden_states (`bool`, *optional*, defaults to `False`): Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for more details. output_scores (`bool`, *optional*, defaults to `False`): Whether or not to return the prediction scores. See `s...
452_2_38
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
Whether or not to return the unprocessed prediction logit scores. See `logits` under returned tensors for more details. return_dict_in_generate (`bool`, *optional*, defaults to `False`): Whether or not to return a [`~utils.ModelOutput`], as opposed to returning exclusively the generated sequence. This flag must be set ...
452_2_39
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
or optional outputs (see flags starting with `output_`) > Special tokens that can be used at generation time pad_token_id (`int`, *optional*): The id of the *padding* token. bos_token_id (`int`, *optional*): The id of the *beginning-of-sequence* token. eos_token_id (`Union[int, List[int]]`, *optional*): The id of t...
452_2_40
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
> Generation parameters exclusive to encoder-decoder models encoder_no_repeat_ngram_size (`int`, *optional*, defaults to 0): If set to int > 0, all ngrams of that size that occur in the `encoder_input_ids` cannot occur in the `decoder_input_ids`. decoder_start_token_id (`int` or `List[int]`, *optional*): If an encode...
452_2_41
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/main_classes/text_generation.md
https://huggingface.co/docs/transformers/en/main_classes/text_generation/#generationconfig
.md
If an encoder-decoder model starts decoding with a different token than *bos*, the id of that token or a list of length `batch_size`. Indicating a list enables different start ids for each element in the batch (e.g. multilingual models with different target languages in one batch) > Generation parameters exclusive to...
452_2_42