| 12 | using ReplicaPoolHelper::ReplicaPoolHelper; |
| 13 | |
| 14 | std::variant<std::vector<GenerationResult>, |
| 15 | std::vector<AsyncResult<GenerationResult>>> |
| 16 | generate_batch(const BatchTokens& tokens, |
| 17 | size_t max_batch_size, |
| 18 | const std::string& batch_type_str, |
| 19 | bool asynchronous, |
| 20 | size_t beam_size, |
| 21 | float patience, |
| 22 | size_t num_hypotheses, |
| 23 | float length_penalty, |
| 24 | float repetition_penalty, |
| 25 | size_t no_repeat_ngram_size, |
| 26 | bool disable_unk, |
| 27 | const std::optional<std::vector<std::vector<std::string>>>& suppress_sequences, |
| 28 | const std::optional<EndToken>& end_token, |
| 29 | bool return_end_token, |
| 30 | size_t max_length, |
| 31 | size_t min_length, |
| 32 | const std::optional<std::vector<std::string>>& static_prompt, |
| 33 | bool cache_static_prompt, |
| 34 | bool include_prompt_in_result, |
| 35 | bool return_scores, |
| 36 | bool return_logits_vocab, |
| 37 | bool return_alternatives, |
| 38 | float min_alternative_expansion_prob, |
| 39 | size_t sampling_topk, |
| 40 | float sampling_topp, |
| 41 | float sampling_temperature, |
| 42 | std::function<bool(GenerationStepResult)> callback) { |
| 43 | if (tokens.empty()) |
| 44 | return {}; |
| 45 | |
| 46 | BatchType batch_type = str_to_batch_type(batch_type_str); |
| 47 | GenerationOptions options; |
| 48 | options.beam_size = beam_size; |
| 49 | options.patience = patience; |
| 50 | options.length_penalty = length_penalty; |
| 51 | options.repetition_penalty = repetition_penalty; |
| 52 | options.no_repeat_ngram_size = no_repeat_ngram_size; |
| 53 | options.disable_unk = disable_unk; |
| 54 | options.sampling_topk = sampling_topk; |
| 55 | options.sampling_topp = sampling_topp; |
| 56 | options.sampling_temperature = sampling_temperature; |
| 57 | options.max_length = max_length; |
| 58 | options.min_length = min_length; |
| 59 | options.num_hypotheses = num_hypotheses; |
| 60 | options.return_end_token = return_end_token; |
| 61 | options.return_scores = return_scores; |
| 62 | options.return_logits_vocab = return_logits_vocab; |
| 63 | options.return_alternatives = return_alternatives; |
| 64 | options.cache_static_prompt = cache_static_prompt; |
| 65 | options.include_prompt_in_result = include_prompt_in_result; |
| 66 | options.min_alternative_expansion_prob = min_alternative_expansion_prob; |
| 67 | options.callback = std::move(callback); |
| 68 | if (suppress_sequences) |
| 69 | options.suppress_sequences = suppress_sequences.value(); |
| 70 | if (end_token) |
| 71 | options.end_token = end_token.value(); |