(
self,
input_ids: Optional[jt.Var] = None,
past_key_values: Optional[Tuple[Tuple[jt.Var]]] = None,
attention_mask: Optional[jt.Var] = None,
token_type_ids: Optional[jt.Var] = None,
position_ids: Optional[jt.Var] = None,
head_mask: Optional[jt.Var] = None,
inputs_embeds: Optional[jt.Var] = None,
use_cache: Optional[bool] = None,
)
| 253 | self.apply(partial(_init_weights, config)) |
| 254 | |
| 255 | def execute( |
| 256 | self, |
| 257 | input_ids: Optional[jt.Var] = None, |
| 258 | past_key_values: Optional[Tuple[Tuple[jt.Var]]] = None, |
| 259 | attention_mask: Optional[jt.Var] = None, |
| 260 | token_type_ids: Optional[jt.Var] = None, |
| 261 | position_ids: Optional[jt.Var] = None, |
| 262 | head_mask: Optional[jt.Var] = None, |
| 263 | inputs_embeds: Optional[jt.Var] = None, |
| 264 | use_cache: Optional[bool] = None, |
| 265 | ): |
| 266 | use_cache = use_cache if use_cache is not None else self.config.use_cache |
| 267 | if input_ids is not None and inputs_embeds is not None: |
| 268 | raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time") |
| 269 | elif input_ids is not None: |
| 270 | input_shape = input_ids.size() |
| 271 | input_ids = input_ids.view(-1, input_shape[-1]) |
| 272 | batch_size = input_ids.shape[0] |
| 273 | elif inputs_embeds is not None: |
| 274 | input_shape = inputs_embeds.size()[:-1] |
| 275 | batch_size = inputs_embeds.shape[0] |
| 276 | else: |
| 277 | raise ValueError("You have to specify either input_ids or inputs_embeds") |
| 278 | |
| 279 | if token_type_ids is not None: |
| 280 | token_type_ids = token_type_ids.view(-1, input_shape[-1]) |
| 281 | |
| 282 | if position_ids is not None: |
| 283 | position_ids = position_ids.view(-1, input_shape[-1]) |
| 284 | |
| 285 | if past_key_values is None: |
| 286 | past_length = 0 |
| 287 | past_key_values = tuple([None] * len(self.h)) |
| 288 | else: |
| 289 | past_length = past_key_values[0][0].size(-2) |
| 290 | |
| 291 | if position_ids is None: |
| 292 | position_ids = jt.arange(past_length, input_shape[-1] + past_length, dtype='int64') |
| 293 | position_ids = position_ids.unsqueeze(0).view(-1, input_shape[-1]) |
| 294 | |
| 295 | # Attention mask. |
| 296 | if attention_mask is not None: |
| 297 | if batch_size <= 0: |
| 298 | raise ValueError("batch_size has to be defined and > 0") |
| 299 | attention_mask = attention_mask.view(batch_size, -1) |
| 300 | # [batch_size, 1, 1, to_seq_length] |
| 301 | attention_mask = attention_mask[:, None, None, :] |
| 302 | |
| 303 | if jt.flags.amp_level >= 3: |
| 304 | attention_mask = attention_mask.half() # fp16 compatibility |
| 305 | attention_mask = (1.0 - attention_mask) * -65504.0 |
| 306 | else: |
| 307 | # finfo.min |
| 308 | attention_mask = (1.0 - attention_mask) * -3.402e38 |
| 309 | |
| 310 | # n_layer x batch x num_attention_heads x N x N |
| 311 | head_mask = get_head_mask(head_mask, self.config.n_layer) |
| 312 |
nothing calls this directly
no test coverage detected