Generates sequences of token ids. The generation-controlling parameters are set in the sampling_config; it will be set to a default one if not passed. You can override any sampling_config's attributes by passing corresponding parameters. Args: batch_inpu
(self,
batch_input_ids: List[torch.Tensor],
position_ids: List[torch.Tensor] = None,
sampling_config: Optional[SamplingConfig] = None,
prompt_table: Optional[Union[str, torch.Tensor]] = None,
prompt_tasks: Optional[str] = None,
lora_uids: Optional[list] = None,
streaming: bool = False,
output_generation_logits: bool = False,
stopping_criteria: Optional[StoppingCriteria] = None,
logits_processor: Optional[LogitsProcessor] = None,
medusa_choices: Optional[List[List[int]]] = None,
encoder_max_input_length: int = None,
encoder_input_features: List[torch.Tensor] = None,
encoder_output_lengths: List[torch.Tensor] = None,
cross_attention_masks: List[torch.Tensor] = None,
**kwargs)
| 834 | return self.session.gather_generation_logits |
| 835 | |
| 836 | def generate(self, |
| 837 | batch_input_ids: List[torch.Tensor], |
| 838 | position_ids: List[torch.Tensor] = None, |
| 839 | sampling_config: Optional[SamplingConfig] = None, |
| 840 | prompt_table: Optional[Union[str, torch.Tensor]] = None, |
| 841 | prompt_tasks: Optional[str] = None, |
| 842 | lora_uids: Optional[list] = None, |
| 843 | streaming: bool = False, |
| 844 | output_generation_logits: bool = False, |
| 845 | stopping_criteria: Optional[StoppingCriteria] = None, |
| 846 | logits_processor: Optional[LogitsProcessor] = None, |
| 847 | medusa_choices: Optional[List[List[int]]] = None, |
| 848 | encoder_max_input_length: int = None, |
| 849 | encoder_input_features: List[torch.Tensor] = None, |
| 850 | encoder_output_lengths: List[torch.Tensor] = None, |
| 851 | cross_attention_masks: List[torch.Tensor] = None, |
| 852 | **kwargs) -> Union[torch.Tensor, dict]: |
| 853 | """ |
| 854 | Generates sequences of token ids. |
| 855 | The generation-controlling parameters are set in the sampling_config; it will be set to a default one if not passed. |
| 856 | You can override any sampling_config's attributes by passing corresponding parameters. |
| 857 | |
| 858 | Args: |
| 859 | batch_input_ids (List[torch.Tensor]): |
| 860 | A list of input id tensors. Each tensor is of shape (sequence_length, ). |
| 861 | sampling_config (SamplingConfig): |
| 862 | The sampling configuration to be used as base parametrization for the generation call. |
| 863 | The passed **kwargs matching the sampling_config's attributes will override them. |
| 864 | If the sampling_config is not provided, a default will be used. |
| 865 | prompt_table (str or torch.Tensor): |
| 866 | The file path of prompt table (.npy format, exported by nemo_prompt_convert.py) or the prompt table itself. |
| 867 | prompt_tasks (str): |
| 868 | The prompt tuning task ids for the input batch, in format of comma-separated list (e.g., 0,3,1,0). |
| 869 | lora_uids (list): |
| 870 | The uids of LoRA weights for the input batch. Use -1 to disable the LoRA module. |
| 871 | streaming (bool): |
| 872 | Whether or not to use streaming mode for generation. |
| 873 | stopping_criteria (StoppingCriteria): |
| 874 | Custom stopping criteria. |
| 875 | logits_processor (LogitsProcessor): |
| 876 | Custom logits processors. |
| 877 | medusa_choices (List[List[int]]): |
| 878 | Medusa decoding choices. |
| 879 | kwargs (Dict[str, Any]: |
| 880 | Ad hoc parametrization of sampling_config. |
| 881 | The passed **kwargs matching the sampling_config's attributes will override them. |
| 882 | Returns: |
| 883 | torch.Tensor or dict: |
| 884 | If return_dict=False, the method returns generated output_ids. |
| 885 | If return_dict=True, the method returns a dict of output_ids, |
| 886 | sequence_lengths (if sampling_config.output_sequence_lengths=True), |
| 887 | context_logits and generation_logits (if self.gather_context_logits=True |
| 888 | and self.gather_generation_logits=True, respectively). |
| 889 | """ |
| 890 | # Use sampling_config like HF's generation_config |
| 891 | if sampling_config is None: |
| 892 | sampling_config = SamplingConfig(end_id=None, pad_id=None) |
| 893 | else: |
nothing calls this directly
no test coverage detected