| 118 | } |
| 119 | |
| 120 | std::variant<std::vector<TranslationResult>, |
| 121 | std::vector<AsyncResult<TranslationResult>>> |
| 122 | translate_batch(const BatchTokens& source, |
| 123 | const BatchTokensOptional& target_prefix, |
| 124 | size_t max_batch_size, |
| 125 | const std::string& batch_type_str, |
| 126 | bool asynchronous, |
| 127 | size_t beam_size, |
| 128 | float patience, |
| 129 | size_t num_hypotheses, |
| 130 | float length_penalty, |
| 131 | float coverage_penalty, |
| 132 | float repetition_penalty, |
| 133 | size_t no_repeat_ngram_size, |
| 134 | bool disable_unk, |
| 135 | const std::optional<std::vector<std::vector<std::string>>>& suppress_sequences, |
| 136 | const std::optional<EndToken>& end_token, |
| 137 | bool return_end_token, |
| 138 | float prefix_bias_beta, |
| 139 | size_t max_input_length, |
| 140 | size_t max_decoding_length, |
| 141 | size_t min_decoding_length, |
| 142 | bool use_vmap, |
| 143 | bool return_scores, |
| 144 | bool return_logits_vocab, |
| 145 | bool return_attention, |
| 146 | bool return_alternatives, |
| 147 | float min_alternative_expansion_prob, |
| 148 | size_t sampling_topk, |
| 149 | float sampling_topp, |
| 150 | float sampling_temperature, |
| 151 | bool replace_unknowns, |
| 152 | std::function<bool(GenerationStepResult)> callback) { |
| 153 | if (source.empty()) |
| 154 | return {}; |
| 155 | |
| 156 | BatchType batch_type = str_to_batch_type(batch_type_str); |
| 157 | TranslationOptions options; |
| 158 | options.beam_size = beam_size; |
| 159 | options.patience = patience; |
| 160 | options.length_penalty = length_penalty; |
| 161 | options.coverage_penalty = coverage_penalty; |
| 162 | options.repetition_penalty = repetition_penalty; |
| 163 | options.no_repeat_ngram_size = no_repeat_ngram_size; |
| 164 | options.disable_unk = disable_unk; |
| 165 | options.prefix_bias_beta = prefix_bias_beta; |
| 166 | options.sampling_topk = sampling_topk; |
| 167 | options.sampling_topp = sampling_topp; |
| 168 | options.sampling_temperature = sampling_temperature; |
| 169 | options.max_input_length = max_input_length; |
| 170 | options.max_decoding_length = max_decoding_length; |
| 171 | options.min_decoding_length = min_decoding_length; |
| 172 | options.num_hypotheses = num_hypotheses; |
| 173 | options.use_vmap = use_vmap; |
| 174 | options.return_end_token = return_end_token; |
| 175 | options.return_scores = return_scores; |
| 176 | options.return_logits_vocab = return_logits_vocab; |
| 177 | options.return_attention = return_attention; |