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/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | google-bert/bert-base-uncased 8 32 1281
google-bert/bert-base-uncased 8 128 1307
google-bert/bert-base-uncased 8 512 1539
-------------------------------------------------------------------------------- | 14_2_10 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | ==================== ENVIRONMENT INFORMATION ==================== | 14_2_11 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - transformers_version: 2.11.0
- framework: PyTorch
- use_torchscript: False
- framework_version: 1.4.0
- python_version: 3.6.10
- system: Linux
- cpu: x86_64
- architecture: 64bit
- date: 2020-06-29
- time: 08:58:43.371351
- fp16: False
- use_multiprocessing: True
- only_pretrain_model: False
- cpu_ram_mb: 32088
- use... | 14_2_12 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - gpu_ram_mb: 24217
- gpu_power_watts: 280.0
- gpu_performance_state: 2
- use_tpu: False
```
</pt>
<tf>
```bash
python examples/tensorflow/benchmarking/run_benchmark_tf.py --help
```
An instantiated benchmark object can then simply be run by calling `benchmark.run()`.
```py
>>> results = benchmark.run()
>>> print(r... | 14_2_13 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | >>> print(results)
==================== INFERENCE - SPEED - RESULT ====================
--------------------------------------------------------------------------------
Model Name Batch Size Seq Length Time in s
----------------------------------------------------------------------------... | 14_2_14 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | google-bert/bert-base-uncased 8 32 0.008
google-bert/bert-base-uncased 8 128 0.022
google-bert/bert-base-uncased 8 512 0.105
-------------------------------------------------------------------------------- | 14_2_15 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | ==================== INFERENCE - MEMORY - RESULT ====================
--------------------------------------------------------------------------------
Model Name Batch Size Seq Length Memory in MB
--------------------------------------------------------------------------------
google-bert/... | 14_2_16 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | google-bert/bert-base-uncased 8 32 1330
google-bert/bert-base-uncased 8 128 1330
google-bert/bert-base-uncased 8 512 1770
-------------------------------------------------------------------------------- | 14_2_17 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | ==================== ENVIRONMENT INFORMATION ==================== | 14_2_18 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - transformers_version: 2.11.0
- framework: Tensorflow
- use_xla: False
- framework_version: 2.2.0
- python_version: 3.6.10
- system: Linux
- cpu: x86_64
- architecture: 64bit
- date: 2020-06-29
- time: 09:26:35.617317
- fp16: False
- use_multiprocessing: True
- only_pretrain_model: False
- cpu_ram_mb: 32088
- use_gpu:... | 14_2_19 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - gpu_ram_mb: 24217
- gpu_power_watts: 280.0
- gpu_performance_state: 2
- use_tpu: False
```
</tf>
</frameworkcontent>
By default, the _time_ and the _required memory_ for _inference_ are benchmarked. In the example output above the first
two sections show the result corresponding to _inference time_ and _inference m... | 14_2_20 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | information about the computing environment, _e.g._ the GPU type, the system, the library versions, etc... are printed
out in the third section under _ENVIRONMENT INFORMATION_. This information can optionally be saved in a _.csv_ file
when adding the argument `save_to_csv=True` to [`PyTorchBenchmarkArguments`] and
[`Te... | 14_2_21 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | [`TensorFlowBenchmarkArguments`] respectively. In this case, every section is saved in a separate
_.csv_ file. The path to each _.csv_ file can optionally be defined via the argument data classes.
Instead of benchmarking pre-trained models via their model identifier, _e.g._ `google-bert/bert-base-uncased`, the user c... | 14_2_22 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | configurations must be inserted with the benchmark args as follows.
<frameworkcontent>
<pt>
```py
>>> from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments, BertConfig | 14_2_23 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | >>> args = PyTorchBenchmarkArguments(
... models=["bert-base", "bert-384-hid", "bert-6-lay"], batch_sizes=[8], sequence_lengths=[8, 32, 128, 512]
... )
>>> config_base = BertConfig()
>>> config_384_hid = BertConfig(hidden_size=384)
>>> config_6_lay = BertConfig(num_hidden_layers=6) | 14_2_24 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | >>> benchmark = PyTorchBenchmark(args, configs=[config_base, config_384_hid, config_6_lay])
>>> benchmark.run()
==================== INFERENCE - SPEED - RESULT ====================
--------------------------------------------------------------------------------
Model Name Batch Size Seq Leng... | 14_2_25 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-base 8 128 0.006
bert-base 8 512 0.006
bert-base 8 128 0.018
bert-base 8 512 0.088
bert-384-hid 8 8 0.006
bert-3... | 14_2_26 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-384-hid 8 128 0.011
bert-384-hid 8 512 0.054
bert-6-lay 8 8 0.003
bert-6-lay 8 32 0.004
bert-6-lay 8 128 0.009
bert-6-... | 14_2_27 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | ==================== INFERENCE - MEMORY - RESULT ====================
--------------------------------------------------------------------------------
Model Name Batch Size Seq Length Memory in MB
--------------------------------------------------------------------------------
bert-base ... | 14_2_28 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-base 8 32 1281
bert-base 8 128 1307
bert-base 8 512 1539
bert-384-hid 8 8 1005
bert-384-hid 8 32 1027
bert-384-hid... | 14_2_29 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-384-hid 8 512 1255
bert-6-lay 8 8 1097
bert-6-lay 8 32 1101
bert-6-lay 8 128 1127
bert-6-lay 8 512 1359
-----------... | 14_2_30 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | ==================== ENVIRONMENT INFORMATION ==================== | 14_2_31 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - transformers_version: 2.11.0
- framework: PyTorch
- use_torchscript: False
- framework_version: 1.4.0
- python_version: 3.6.10
- system: Linux
- cpu: x86_64
- architecture: 64bit
- date: 2020-06-29
- time: 09:35:25.143267
- fp16: False
- use_multiprocessing: True
- only_pretrain_model: False
- cpu_ram_mb: 32088
- use... | 14_2_32 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - gpu: TITAN RTX
- gpu_ram_mb: 24217
- gpu_power_watts: 280.0
- gpu_performance_state: 2
- use_tpu: False
```
</pt>
<tf>
```py
>>> from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments, BertConfig | 14_2_33 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | >>> args = TensorFlowBenchmarkArguments(
... models=["bert-base", "bert-384-hid", "bert-6-lay"], batch_sizes=[8], sequence_lengths=[8, 32, 128, 512]
... )
>>> config_base = BertConfig()
>>> config_384_hid = BertConfig(hidden_size=384)
>>> config_6_lay = BertConfig(num_hidden_layers=6) | 14_2_34 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | >>> benchmark = TensorFlowBenchmark(args, configs=[config_base, config_384_hid, config_6_lay])
>>> benchmark.run()
==================== INFERENCE - SPEED - RESULT ====================
--------------------------------------------------------------------------------
Model Name Batch Size Seq L... | 14_2_35 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-base 8 8 0.005
bert-base 8 32 0.008
bert-base 8 128 0.022
bert-base 8 512 0.106
bert-384-hid 8 8 0.005
bert-3... | 14_2_36 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-384-hid 8 128 0.018
bert-384-hid 8 512 0.064
bert-6-lay 8 8 0.002
bert-6-lay 8 32 0.003
bert-6-lay 8 128 0.0011
bert-6... | 14_2_37 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | ==================== INFERENCE - MEMORY - RESULT ====================
--------------------------------------------------------------------------------
Model Name Batch Size Seq Length Memory in MB
--------------------------------------------------------------------------------
bert-base ... | 14_2_38 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-base 8 32 1330
bert-base 8 128 1330
bert-base 8 512 1770
bert-384-hid 8 8 1330
bert-384-hid 8 32 1330
bert-384-hid... | 14_2_39 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | bert-384-hid 8 512 1540
bert-6-lay 8 8 1330
bert-6-lay 8 32 1330
bert-6-lay 8 128 1330
bert-6-lay 8 512 1540
-----------... | 14_2_40 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | ==================== ENVIRONMENT INFORMATION ==================== | 14_2_41 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - transformers_version: 2.11.0
- framework: Tensorflow
- use_xla: False
- framework_version: 2.2.0
- python_version: 3.6.10
- system: Linux
- cpu: x86_64
- architecture: 64bit
- date: 2020-06-29
- time: 09:38:15.487125
- fp16: False
- use_multiprocessing: True
- only_pretrain_model: False
- cpu_ram_mb: 32088
- use_gpu:... | 14_2_42 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models | .md | - gpu_ram_mb: 24217
- gpu_power_watts: 280.0
- gpu_performance_state: 2
- use_tpu: False
```
</tf>
</frameworkcontent>
Again, _inference time_ and _required memory_ for _inference_ are measured, but this time for customized configurations
of the `BertModel` class. This feature can especially be helpful when deciding ... | 14_2_43 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#benchmark-best-practices | .md | This section lists a couple of best practices one should be aware of when benchmarking a model.
- Currently, only single device benchmarking is supported. When benchmarking on GPU, it is recommended that the user
specifies on which device the code should be run by setting the `CUDA_VISIBLE_DEVICES` environment variab... | 14_3_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#benchmark-best-practices | .md | - The option `no_multi_processing` should only be set to `True` for testing and debugging. To ensure accurate
memory measurement it is recommended to run each memory benchmark in a separate process by making sure
`no_multi_processing` is set to `True`.
- One should always state the environment information when sharing ... | 14_3_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#benchmark-best-practices | .md | heavily between different GPU devices, library versions, etc., as a consequence, benchmark results on their own are not very
useful for the community. | 14_3_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#sharing-your-benchmark | .md | Previously all available core models (10 at the time) have been benchmarked for _inference time_, across many different
settings: using PyTorch, with and without TorchScript, using TensorFlow, with and without XLA. All of those tests were
done across CPUs (except for TensorFlow XLA) and GPUs.
The approach is detailed... | 14_4_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md | https://huggingface.co/docs/transformers/en/benchmarks/#sharing-your-benchmark | .md | available [here](https://docs.google.com/spreadsheets/d/1sryqufw2D0XlUH4sq3e9Wnxu5EAQkaohzrJbd5HdQ_w/edit?usp=sharing).
With the new _benchmark_ tools, it is easier than ever to share your benchmark results with the community
- [PyTorch Benchmarking Results](https://github.com/huggingface/transformers/tree/main/exa... | 14_4_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/ | .md | <!--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... | 15_0_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/ | .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 ... | 15_0_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#text-generation-strategies | .md | Text generation is essential to many NLP tasks, such as open-ended text generation, summarization, translation, and
more. It also plays a role in a variety of mixed-modality applications that have text as an output like speech-to-text
and vision-to-text. Some of the models that can generate text include
GPT2, XLNet, Op... | 15_1_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#text-generation-strategies | .md | Check out a few examples that use [`~generation.GenerationMixin.generate`] method to produce
text outputs for different tasks:
* [Text summarization](./tasks/summarization#inference)
* [Image captioning](./model_doc/git#transformers.GitForCausalLM.forward.example)
* [Audio transcription](./model_doc/whisper#transformer... | 15_1_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#text-generation-strategies | .md | Note that the inputs to the generate method depend on the model's modality. They are returned by the model's preprocessor
class, such as AutoTokenizer or AutoProcessor. If a model's preprocessor creates more than one kind of input, pass all
the inputs to generate(). You can learn more about the individual model's prepr... | 15_1_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#text-generation-strategies | .md | The process of selecting output tokens to generate text is known as decoding, and you can customize the decoding strategy
that the `generate()` method will use. Modifying a decoding strategy does not change the values of any trainable parameters.
However, it can have a noticeable impact on the quality of the generated ... | 15_1_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#text-generation-strategies | .md | This guide describes:
* default generation configuration
* common decoding strategies and their main parameters
* saving and sharing custom generation configurations with your fine-tuned model on 🤗 Hub | 15_1_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#default-text-generation-configuration | .md | A decoding strategy for a model is defined in its generation configuration. When using pre-trained models for inference
within a [`pipeline`], the models call the `PreTrainedModel.generate()` method that applies a default generation
configuration under the hood. The default configuration is also used when no custom con... | 15_2_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#default-text-generation-configuration | .md | `model.generation_config`:
```python
>>> from transformers import AutoModelForCausalLM | 15_2_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#default-text-generation-configuration | .md | >>> model = AutoModelForCausalLM.from_pretrained("distilbert/distilgpt2")
>>> model.generation_config
GenerationConfig {
"bos_token_id": 50256,
"eos_token_id": 50256
}
<BLANKLINE>
```
Printing out the `model.generation_config` reveals only the values that are different from the default generation
configuration, and d... | 15_2_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#default-text-generation-configuration | .md | The default generation configuration limits the size of the output combined with the input prompt to a maximum of 20
tokens to avoid running into resource limitations. The default decoding strategy is greedy search, which is the simplest decoding strategy that picks a token with the highest probability as the next toke... | 15_2_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation | .md | You can override any `generation_config` by passing the parameters and their values directly to the [`generate`] method:
```python
>>> my_model.generate(**inputs, num_beams=4, do_sample=True) # doctest: +SKIP
```
Even if the default decoding strategy mostly works for your task, you can still tweak a few things. So... | 15_3_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation | .md | - `max_new_tokens`: the maximum number of tokens to generate. In other words, the size of the output sequence, not
including the tokens in the prompt. As an alternative to using the output's length as a stopping criteria, you can choose
to stop generation whenever the full generation exceeds some amount of time. To lea... | 15_3_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation | .md | - `num_beams`: by specifying a number of beams higher than 1, you are effectively switching from greedy search to
beam search. This strategy evaluates several hypotheses at each time step and eventually chooses the hypothesis that
has the overall highest probability for the entire sequence. This has the advantage of id... | 15_3_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation | .md | has the overall highest probability for the entire sequence. This has the advantage of identifying high-probability
sequences that start with a lower probability initial tokens and would've been ignored by the greedy search. Visualize how it works [here](https://huggingface.co/spaces/m-ric/beam_search_visualizer).
- `d... | 15_3_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation | .md | - `do_sample`: if set to `True`, this parameter enables decoding strategies such as multinomial sampling, beam-search
multinomial sampling, Top-K sampling and Top-p sampling. All these strategies select the next token from the probability
distribution over the entire vocabulary with various strategy-specific adjustment... | 15_3_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation | .md | - `num_return_sequences`: the number of sequence candidates to return for each input. This option is only available for
the decoding strategies that support multiple sequence candidates, e.g. variations of beam search and sampling. Decoding
strategies like greedy search and contrastive search return a single output seq... | 15_3_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation | .md | It is also possible to extend `generate()` with external libraries or handcrafted code. The `logits_processor` argument
allows you to pass custom [`LogitsProcessor`] instances, allowing you to manipulate the next token probability
distributions. Likewise, the `stopping_criteria` argument lets you set custom [`StoppingC... | 15_3_6 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model | .md | If you would like to share your fine-tuned model with a specific generation configuration, you can:
* Create a [`GenerationConfig`] class instance
* Specify the decoding strategy parameters
* Save your generation configuration with [`GenerationConfig.save_pretrained`], making sure to leave its `config_file_name` argume... | 15_4_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model | .md | >>> model = AutoModelForCausalLM.from_pretrained("my_account/my_model") # doctest: +SKIP
>>> generation_config = GenerationConfig(
... max_new_tokens=50, do_sample=True, top_k=50, eos_token_id=model.config.eos_token_id
... )
>>> generation_config.save_pretrained("my_account/my_model", push_to_hub=True) # doctest:... | 15_4_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model | .md | ```
You can also store several generation configurations in a single directory, making use of the `config_file_name`
argument in [`GenerationConfig.save_pretrained`]. You can later instantiate them with [`GenerationConfig.from_pretrained`]. This is useful if you want to
store several generation configurations for a s... | 15_4_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model | .md | one for summarization with beam search). You must have the right Hub permissions to add configuration files to a model.
```python
>>> from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig | 15_4_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model | .md | >>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
>>> model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-small")
>>> translation_generation_config = GenerationConfig(
... num_beams=4,
... early_stopping=True,
... decoder_start_token_id=0,
... eos_token_id=model.config.eos_tok... | 15_4_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model | .md | >>> # Tip: add `push_to_hub=True` to push to the Hub
>>> translation_generation_config.save_pretrained("/tmp", "translation_generation_config.json") | 15_4_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model | .md | >>> # You could then use the named generation config file to parameterize generation
>>> generation_config = GenerationConfig.from_pretrained("/tmp", "translation_generation_config.json")
>>> inputs = tokenizer("translate English to French: Configuration files are easy to use!", return_tensors="pt")
>>> outputs = model... | 15_4_6 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#streaming | .md | The `generate()` supports streaming, through its `streamer` input. The `streamer` input is compatible with any instance
from a class that has the following methods: `put()` and `end()`. Internally, `put()` is used to push new tokens and
`end()` is used to flag the end of text generation.
<Tip warning={true}>
The AP... | 15_5_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#streaming | .md | <Tip warning={true}>
The API for the streamer classes is still under development and may change in the future.
</Tip>
In practice, you can craft your own streaming class for all sorts of purposes! We also have basic streaming classes
ready for you to use. For example, you can use the [`TextStreamer`] class to str... | 15_5_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#streaming | .md | >>> tok = AutoTokenizer.from_pretrained("openai-community/gpt2")
>>> model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2")
>>> inputs = tok(["An increasing sequence: one,"], return_tensors="pt")
>>> streamer = TextStreamer(tok) | 15_5_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#streaming | .md | >>> # Despite returning the usual output, the streamer will also print the generated text to stdout.
>>> _ = model.generate(**inputs, streamer=streamer, max_new_tokens=20)
An increasing sequence: one, two, three, four, five, six, seven, eight, nine, ten, eleven,
``` | 15_5_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking | .md | The `generate()` supports watermarking the generated text by randomly marking a portion of tokens as "green".
When generating the "green" will have a small 'bias' value added to their logits, thus having a higher chance to be generated.
The watermarked text can be detected by calculating the proportion of "green" token... | 15_6_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking | .md | ["On the Reliability of Watermarks for Large Language Models"](https://arxiv.org/abs/2306.04634). For more information on
the inner functioning of watermarking, it is recommended to refer to the paper.
The watermarking can be used with any generative model in `tranformers` and does not require an extra classification... | 15_6_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking | .md | to detect watermarked text. To trigger watermarking, pass in a [`WatermarkingConfig`] with needed arguments directly to the
`.generate()` method or add it to the [`GenerationConfig`]. Watermarked text can be later detected with a [`WatermarkDetector`].
<Tip warning={true}>
The WatermarkDetector internally relies on... | 15_6_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking | .md | That is why it is recommended to strip off the prompt text, if it is much longer than the generated text.
This also can have an effect when one sequence in the batch is a lot longer causing other rows to be padded.
Additionally, the detector **must** be initiated with identical watermark configuration arguments used wh... | 15_6_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking | .md | </Tip>
Let's generate some text with watermarking. In the below code snippet, we set the bias to 2.5 which is a value that
will be added to "green" tokens' logits. After generating watermarked text, we can pass it directly to the `WatermarkDetector`
to check if the text is machine-generated (outputs `True` for machin... | 15_6_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking | .md | >>> model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2")
>>> tok = AutoTokenizer.from_pretrained("openai-community/gpt2")
>>> tok.pad_token_id = tok.eos_token_id
>>> tok.padding_side = "left"
>>> inputs = tok(["This is the beginning of a long story", "Alice and Bob are"], padding=True, return_tensors=... | 15_6_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking | .md | >>> watermarking_config = WatermarkingConfig(bias=2.5, seeding_scheme="selfhash")
>>> out = model.generate(**inputs, watermarking_config=watermarking_config, do_sample=False, max_length=20)
>>> detector = WatermarkDetector(model_config=model.config, device="cpu", watermarking_config=watermarking_config)
>>> detection_... | 15_6_6 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#decoding-strategies | .md | Certain combinations of the `generate()` parameters, and ultimately `generation_config`, can be used to enable specific
decoding strategies. If you are new to this concept, we recommend reading
[this blog post that illustrates how common decoding strategies work](https://huggingface.co/blog/how-to-generate).
Here, we... | 15_7_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#decoding-strategies | .md | Here, we'll show some of the parameters that control the decoding strategies and illustrate how you can use them.
<Tip>
Selecting a given decoding strategy is not the only way you can influence the outcome of `generate()` with your model.
The decoding strategies act based (mostly) on the logits, the distribution of... | 15_7_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#decoding-strategies | .md | thus selecting a good logits manipulation strategy can go a long way! In other words, manipulating the logits is another
dimension you can act upon, in addition to selecting a decoding strategy. Popular logits manipulation strategies include
`top_p`, `min_p`, and `repetition_penalty` -- you can check the full list in t... | 15_7_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#greedy-search | .md | [`generate`] uses greedy search decoding by default so you don't have to pass any parameters to enable it. This means the parameters `num_beams` is set to 1 and `do_sample=False`.
```python
>>> from transformers import AutoModelForCausalLM, AutoTokenizer
>>> prompt = "I look forward to"
>>> checkpoint = "distilbert/... | 15_8_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#greedy-search | .md | >>> tokenizer = AutoTokenizer.from_pretrained(checkpoint)
>>> inputs = tokenizer(prompt, return_tensors="pt")
>>> model = AutoModelForCausalLM.from_pretrained(checkpoint)
>>> outputs = model.generate(**inputs)
>>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
['I look forward to seeing you all again!\n\n\n... | 15_8_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#contrastive-search | .md | The contrastive search decoding strategy was proposed in the 2022 paper [A Contrastive Framework for Neural Text Generation](https://arxiv.org/abs/2202.06417).
It demonstrates superior results for generating non-repetitive yet coherent long outputs. To learn how contrastive search
works, check out [this blog post](http... | 15_9_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#contrastive-search | .md | The two main parameters that enable and control the behavior of contrastive search are `penalty_alpha` and `top_k`:
```python
>>> from transformers import AutoTokenizer, AutoModelForCausalLM | 15_9_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#contrastive-search | .md | >>> checkpoint = "openai-community/gpt2-large"
>>> tokenizer = AutoTokenizer.from_pretrained(checkpoint)
>>> model = AutoModelForCausalLM.from_pretrained(checkpoint)
>>> prompt = "Hugging Face Company is"
>>> inputs = tokenizer(prompt, return_tensors="pt") | 15_9_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#contrastive-search | .md | >>> outputs = model.generate(**inputs, penalty_alpha=0.6, top_k=4, max_new_tokens=100)
>>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
['Hugging Face Company is a family owned and operated business. We pride ourselves on being the best
in the business and our customer service is second to none.\n\nIf you ... | 15_9_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#multinomial-sampling | .md | As opposed to greedy search that always chooses a token with the highest probability as the
next token, multinomial sampling (also called ancestral sampling) randomly selects the next token based on the probability distribution over the entire
vocabulary given by the model. Every token with a non-zero probability has a... | 15_10_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#multinomial-sampling | .md | risk of repetition.
To enable multinomial sampling set `do_sample=True` and `num_beams=1`.
```python
>>> from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed
>>> set_seed(0) # For reproducibility | 15_10_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#multinomial-sampling | .md | >>> checkpoint = "openai-community/gpt2-large"
>>> tokenizer = AutoTokenizer.from_pretrained(checkpoint)
>>> model = AutoModelForCausalLM.from_pretrained(checkpoint)
>>> prompt = "Today was an amazing day because"
>>> inputs = tokenizer(prompt, return_tensors="pt") | 15_10_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#multinomial-sampling | .md | >>> outputs = model.generate(**inputs, do_sample=True, num_beams=1, max_new_tokens=100)
>>> tokenizer.batch_decode(outputs, skip_special_tokens=True) | 15_10_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#multinomial-sampling | .md | ["Today was an amazing day because we received these wonderful items by the way of a gift shop. The box arrived on a Thursday and I opened it on Monday afternoon to receive the gifts. Both bags featured pieces from all the previous years!\n\nThe box had lots of surprises in it, including some sweet little mini chocolat... | 15_10_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-decoding | .md | Unlike greedy search, beam-search decoding keeps several hypotheses at each time step and eventually chooses
the hypothesis that has the overall highest probability for the entire sequence. This has the advantage of identifying high-probability
sequences that start with lower probability initial tokens and would've bee... | 15_11_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-decoding | .md | <a href="https://huggingface.co/spaces/m-ric/beam_search_visualizer" class="flex flex-col justify-center">
<img style="max-width: 90%; margin: auto;" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/beam_search.png"/>
</a>
You can visualize how beam-search decoding works... | 15_11_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-decoding | .md | To enable this decoding strategy, specify the `num_beams` (aka number of hypotheses to keep track of) that is greater than 1.
```python
>>> from transformers import AutoModelForCausalLM, AutoTokenizer | 15_11_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-decoding | .md | >>> prompt = "It is astonishing how one can"
>>> checkpoint = "openai-community/gpt2-medium"
>>> tokenizer = AutoTokenizer.from_pretrained(checkpoint)
>>> inputs = tokenizer(prompt, return_tensors="pt")
>>> model = AutoModelForCausalLM.from_pretrained(checkpoint) | 15_11_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-decoding | .md | >>> model = AutoModelForCausalLM.from_pretrained(checkpoint)
>>> outputs = model.generate(**inputs, num_beams=5, max_new_tokens=50)
>>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
['It is astonishing how one can have such a profound impact on the lives of so many people in such a short period of
time."\n... | 15_11_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-multinomial-sampling | .md | As the name implies, this decoding strategy combines beam search with multinomial sampling. You need to specify
the `num_beams` greater than 1, and set `do_sample=True` to use this decoding strategy.
```python
>>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, set_seed
>>> set_seed(0) # For reproduci... | 15_12_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-multinomial-sampling | .md | >>> prompt = "translate English to German: The house is wonderful."
>>> checkpoint = "google-t5/t5-small"
>>> tokenizer = AutoTokenizer.from_pretrained(checkpoint)
>>> inputs = tokenizer(prompt, return_tensors="pt")
>>> model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)
>>> outputs = model.generate(**inputs, ... | 15_12_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#diverse-beam-search-decoding | .md | The diverse beam search decoding strategy is an extension of the beam search strategy that allows for generating a more diverse
set of beam sequences to choose from. To learn how it works, refer to [Diverse Beam Search: Decoding Diverse Solutions from Neural Sequence Models](https://arxiv.org/pdf/1610.02424.pdf).
This ... | 15_13_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#diverse-beam-search-decoding | .md | This approach has three main parameters: `num_beams`, `num_beam_groups`, and `diversity_penalty`.
The diversity penalty ensures the outputs are distinct across groups, and beam search is used within each group.
```python
>>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | 15_13_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#diverse-beam-search-decoding | .md | >>> checkpoint = "google/pegasus-xsum"
>>> prompt = (
... "The Permaculture Design Principles are a set of universal design principles "
... "that can be applied to any location, climate and culture, and they allow us to design "
... "the most efficient and sustainable human habitation and food production s... | 15_13_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md | https://huggingface.co/docs/transformers/en/generation_strategies/#diverse-beam-search-decoding | .md | ... "Permaculture is a design system that encompasses a wide variety of disciplines, such "
... "as ecology, landscape design, environmental science and energy conservation, and the "
... "Permaculture design principles are drawn from these various disciplines. Each individual "
... "design principle it... | 15_13_3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.