(self,
input_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional[Tuple[torch.Tensor]] = None,
use_cache: Optional[bool] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
return_last_logit: Optional[bool] = False,
)
| 895 | return response, history |
| 896 | |
| 897 | def ppl(self, |
| 898 | input_ids: Optional[torch.Tensor] = None, |
| 899 | position_ids: Optional[torch.Tensor] = None, |
| 900 | attention_mask: Optional[torch.Tensor] = None, |
| 901 | past_key_values: Optional[Tuple[torch.FloatTensor]] = None, |
| 902 | inputs_embeds: Optional[torch.Tensor] = None, |
| 903 | labels: Optional[Tuple[torch.Tensor]] = None, |
| 904 | use_cache: Optional[bool] = None, |
| 905 | output_attentions: Optional[bool] = None, |
| 906 | output_hidden_states: Optional[bool] = None, |
| 907 | return_dict: Optional[bool] = None, |
| 908 | return_last_logit: Optional[bool] = False, |
| 909 | ): |
| 910 | use_cache = use_cache if use_cache is not None else self.config.use_cache |
| 911 | return_dict = return_dict if return_dict is not None else self.config.use_return_dict |
| 912 | |
| 913 | transformer_outputs = self.transformer( |
| 914 | input_ids=input_ids, |
| 915 | position_ids=position_ids, |
| 916 | attention_mask=attention_mask, |
| 917 | past_key_values=past_key_values, |
| 918 | inputs_embeds=inputs_embeds, |
| 919 | use_cache=use_cache, |
| 920 | output_hidden_states=output_hidden_states, |
| 921 | return_dict=return_dict, |
| 922 | ) |
| 923 | |
| 924 | hidden_states = transformer_outputs[0] |
| 925 | if return_last_logit: |
| 926 | hidden_states = hidden_states[-1:] |
| 927 | lm_logits = self.transformer.output_layer(hidden_states) |
| 928 | lm_logits = lm_logits.transpose(0, 1).contiguous() |
| 929 | |
| 930 | loss = None |
| 931 | if labels is not None: |
| 932 | lm_logits = lm_logits.to(torch.float32) |
| 933 | # Shift so that tokens < n predict n |
| 934 | shift_logits = lm_logits[..., :-1, :].contiguous() |
| 935 | shift_labels = labels[..., 1:].contiguous() |
| 936 | |
| 937 | loss_fct = CrossEntropyLoss(ignore_index=-100, reduction='none') |
| 938 | loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1).to(shift_logits.device)) |
| 939 | |
| 940 | lm_logits = lm_logits.to(hidden_states.dtype) |
| 941 | loss = loss.to(hidden_states.dtype) |
| 942 | |
| 943 | return loss |
nothing calls this directly
no outgoing calls
no test coverage detected