Sampling parameters for text generation. Overall, we follow the sampling parameters from the OpenAI text completion API (https://platform.openai.com/docs/api-reference/completions/create). In addition, we support beam search, which is not supported by OpenAI. Args: n: Numbe
| 21 | |
| 22 | |
| 23 | class SamplingParams: |
| 24 | """Sampling parameters for text generation. |
| 25 | |
| 26 | Overall, we follow the sampling parameters from the OpenAI text completion |
| 27 | API (https://platform.openai.com/docs/api-reference/completions/create). |
| 28 | In addition, we support beam search, which is not supported by OpenAI. |
| 29 | |
| 30 | Args: |
| 31 | n: Number of output sequences to return for the given prompt. |
| 32 | best_of: Number of output sequences that are generated from the prompt. |
| 33 | From these `best_of` sequences, the top `n` sequences are returned. |
| 34 | `best_of` must be greater than or equal to `n`. This is treated as |
| 35 | the beam width when `use_beam_search` is True. By default, `best_of` |
| 36 | is set to `n`. |
| 37 | presence_penalty: Float that penalizes new tokens based on whether they |
| 38 | appear in the generated text so far. Values > 0 encourage the model |
| 39 | to use new tokens, while values < 0 encourage the model to repeat |
| 40 | tokens. |
| 41 | frequency_penalty: Float that penalizes new tokens based on their |
| 42 | frequency in the generated text so far. Values > 0 encourage the |
| 43 | model to use new tokens, while values < 0 encourage the model to |
| 44 | repeat tokens. |
| 45 | repetition_penalty: Float that penalizes new tokens based on whether |
| 46 | they appear in the prompt and the generated text so far. Values > 1 |
| 47 | encourage the model to use new tokens, while values < 1 encourage |
| 48 | the model to repeat tokens. |
| 49 | temperature: Float that controls the randomness of the sampling. Lower |
| 50 | values make the model more deterministic, while higher values make |
| 51 | the model more random. Zero means greedy sampling. |
| 52 | top_p: Float that controls the cumulative probability of the top tokens |
| 53 | to consider. Must be in (0, 1]. Set to 1 to consider all tokens. |
| 54 | top_k: Integer that controls the number of top tokens to consider. Set |
| 55 | to -1 to consider all tokens. |
| 56 | min_p: Float that represents the minimum probability for a token to be |
| 57 | considered, relative to the probability of the most likely token. |
| 58 | Must be in [0, 1]. Set to 0 to disable this. |
| 59 | use_beam_search: Whether to use beam search instead of sampling. |
| 60 | length_penalty: Float that penalizes sequences based on their length. |
| 61 | Used in beam search. |
| 62 | early_stopping: Controls the stopping condition for beam search. It |
| 63 | accepts the following values: `True`, where the generation stops as |
| 64 | soon as there are `best_of` complete candidates; `False`, where an |
| 65 | heuristic is applied and the generation stops when is it very |
| 66 | unlikely to find better candidates; `"never"`, where the beam search |
| 67 | procedure only stops when there cannot be better candidates |
| 68 | (canonical beam search algorithm). |
| 69 | stop: List of strings that stop the generation when they are generated. |
| 70 | The returned output will not contain the stop strings. |
| 71 | stop_token_ids: List of tokens that stop the generation when they are |
| 72 | generated. The returned output will contain the stop tokens unless |
| 73 | the stop tokens are special tokens. |
| 74 | include_stop_str_in_output: Whether to include the stop strings in output |
| 75 | text. Defaults to False. |
| 76 | ignore_eos: Whether to ignore the EOS token and continue generating |
| 77 | tokens after the EOS token is generated. |
| 78 | max_tokens: Maximum number of tokens to generate per output sequence. |
| 79 | logprobs: Number of log probabilities to return per output token. |
| 80 | Note that the implementation follows the OpenAI API: The return |
no outgoing calls
no test coverage detected