r""" Generates sequences for models with a LM head. The method currently supports greedy decoding, beam-search decoding, sampling with temperature, sampling with top-k or nucleus sampling. Adapted in part from `Facebook's XLM beam search code`_. .. _`Facebook's XLM beam search code
(
self,
input_ids: Optional[torch.LongTensor] = None,
max_length: Optional[int] = None,
min_length: Optional[int] = None,
do_sample: Optional[bool] = None,
early_stopping: Optional[bool] = None,
num_beams: Optional[int] = None,
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
repetition_penalty: Optional[float] = None,
bad_words_ids: Optional[Iterable[int]] = None,
bos_token_id: Optional[int] = None,
pad_token_id: Optional[int] = None,
eos_token_id: Optional[int] = None,
length_penalty: Optional[float] = None,
no_repeat_ngram_size: Optional[int] = None,
num_return_sequences: Optional[int] = None,
attention_mask: Optional[torch.LongTensor] = None,
decoder_start_token_id: Optional[int] = None,
use_cache: Optional[bool] = None,
**model_specific_kwargs
)
| 99 | |
| 100 | @torch.no_grad() |
| 101 | def generate( |
| 102 | self, |
| 103 | input_ids: Optional[torch.LongTensor] = None, |
| 104 | max_length: Optional[int] = None, |
| 105 | min_length: Optional[int] = None, |
| 106 | do_sample: Optional[bool] = None, |
| 107 | early_stopping: Optional[bool] = None, |
| 108 | num_beams: Optional[int] = None, |
| 109 | temperature: Optional[float] = None, |
| 110 | top_k: Optional[int] = None, |
| 111 | top_p: Optional[float] = None, |
| 112 | repetition_penalty: Optional[float] = None, |
| 113 | bad_words_ids: Optional[Iterable[int]] = None, |
| 114 | bos_token_id: Optional[int] = None, |
| 115 | pad_token_id: Optional[int] = None, |
| 116 | eos_token_id: Optional[int] = None, |
| 117 | length_penalty: Optional[float] = None, |
| 118 | no_repeat_ngram_size: Optional[int] = None, |
| 119 | num_return_sequences: Optional[int] = None, |
| 120 | attention_mask: Optional[torch.LongTensor] = None, |
| 121 | decoder_start_token_id: Optional[int] = None, |
| 122 | use_cache: Optional[bool] = None, |
| 123 | **model_specific_kwargs |
| 124 | ) -> torch.LongTensor: |
| 125 | r""" Generates sequences for models with a LM head. The method currently supports greedy decoding, beam-search decoding, sampling with temperature, sampling with top-k or nucleus sampling. |
| 126 | |
| 127 | Adapted in part from `Facebook's XLM beam search code`_. |
| 128 | |
| 129 | .. _`Facebook's XLM beam search code`: |
| 130 | https://github.com/facebookresearch/XLM/blob/9e6f6814d17be4fe5b15f2e6c43eb2b2d76daeb4/src/model/transformer.py#L529 |
| 131 | |
| 132 | |
| 133 | Parameters: |
| 134 | |
| 135 | input_ids: (`optional`) `torch.LongTensor` of shape `(batch_size, sequence_length)` |
| 136 | The sequence used as a prompt for the generation. If `None` the method initializes |
| 137 | it as an empty `torch.LongTensor` of shape `(1,)`. |
| 138 | |
| 139 | max_length: (`optional`) int |
| 140 | The max length of the sequence to be generated. Between `min_length` and infinity. Default to 20. |
| 141 | |
| 142 | min_length: (`optional`) int |
| 143 | The min length of the sequence to be generated. Between 0 and infinity. Default to 0. |
| 144 | |
| 145 | do_sample: (`optional`) bool |
| 146 | If set to `False` greedy decoding is used. Otherwise sampling is used. Defaults to `False` as defined in `configuration_utils.PretrainedConfig`. |
| 147 | |
| 148 | early_stopping: (`optional`) bool |
| 149 | if set to `True` beam search is stopped when at least `num_beams` sentences finished per batch. Defaults to `False` as defined in `configuration_utils.PretrainedConfig`. |
| 150 | |
| 151 | num_beams: (`optional`) int |
| 152 | Number of beams for beam search. Must be between 1 and infinity. 1 means no beam search. Default to 1. |
| 153 | |
| 154 | temperature: (`optional`) float |
| 155 | The value used to module the next token probabilities. Must be strictly positive. Default to 1.0. |
| 156 | |
| 157 | top_k: (`optional`) int |
| 158 | The number of highest probability vocabulary tokens to keep for top-k-filtering. Between 1 and infinity. Default to 50. |
nothing calls this directly
no test coverage detected