(
self,
input_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
inputs_embeds: Optional[torch.LongTensor] = None,
use_cache: Optional[bool] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
)
| 885 | config_class=_CONFIG_FOR_DOC, |
| 886 | ) |
| 887 | def forward( |
| 888 | self, |
| 889 | input_ids: Optional[torch.LongTensor] = None, |
| 890 | position_ids: Optional[torch.LongTensor] = None, |
| 891 | attention_mask: Optional[torch.Tensor] = None, |
| 892 | past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None, |
| 893 | inputs_embeds: Optional[torch.LongTensor] = None, |
| 894 | use_cache: Optional[bool] = None, |
| 895 | output_attentions: Optional[bool] = None, |
| 896 | output_hidden_states: Optional[bool] = None, |
| 897 | return_dict: Optional[bool] = None, |
| 898 | ) -> Union[Tuple[torch.Tensor, ...], BaseModelOutputWithPast]: |
| 899 | |
| 900 | output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions |
| 901 | output_hidden_states = ( |
| 902 | output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states |
| 903 | ) |
| 904 | use_cache = use_cache if use_cache is not None else self.config.use_cache |
| 905 | return_dict = return_dict if return_dict is not None else self.config.use_return_dict |
| 906 | |
| 907 | if input_ids is not None and inputs_embeds is not None: |
| 908 | raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time") |
| 909 | elif input_ids is not None: |
| 910 | batch_size, seq_length = input_ids.shape[:2] |
| 911 | elif inputs_embeds is not None: |
| 912 | batch_size, seq_length, _ = inputs_embeds.shape[:2] |
| 913 | else: |
| 914 | raise ValueError("You have to specify either input_ids or inputs_embeds") |
| 915 | |
| 916 | if past_key_values is None: |
| 917 | past_key_values = tuple([None] * len(self.layers)) |
| 918 | |
| 919 | MASK, gMASK = 150000, 150001 |
| 920 | mask_token = MASK if MASK in input_ids else gMASK |
| 921 | use_gmask = False if MASK in input_ids else gMASK |
| 922 | seq = input_ids[0].tolist() |
| 923 | |
| 924 | mask_position = seq.index(mask_token) |
| 925 | |
| 926 | if attention_mask is None: |
| 927 | attention_mask = self.get_masks( |
| 928 | seq=seq, |
| 929 | device=input_ids.device |
| 930 | ) |
| 931 | |
| 932 | if position_ids is None: |
| 933 | position_ids = self.get_position_ids( |
| 934 | seq=seq, |
| 935 | mask_position=mask_position, |
| 936 | device=input_ids.device, |
| 937 | gmask=use_gmask |
| 938 | ) |
| 939 | |
| 940 | if inputs_embeds is None: |
| 941 | inputs_embeds = self.word_embeddings(input_ids) |
| 942 | |
| 943 | # [seq_len, batch, hidden_size] |
| 944 | hidden_states = inputs_embeds.transpose(0, 1) |
nothing calls this directly
no test coverage detected