Inference method that computes logits and past key values. Args: input_ids (torch.Tensor): The input IDs tensor. attention_mask (torch.Tensor): The attention mask tensor. past_key_values (Optional[Tuple[torch.Tensor]]): The past key values tuple.
(
self,
input_ids: torch.Tensor,
attention_mask: torch.Tensor,
past_key_values: Optional[Tuple[torch.Tensor]],
)
| 313 | return logits |
| 314 | |
| 315 | def infer_( |
| 316 | self, |
| 317 | input_ids: torch.Tensor, |
| 318 | attention_mask: torch.Tensor, |
| 319 | past_key_values: Optional[Tuple[torch.Tensor]], |
| 320 | ) -> Tuple[torch.Tensor, Tuple[torch.Tensor]]: |
| 321 | """ |
| 322 | Inference method that computes logits and past key values. |
| 323 | |
| 324 | Args: |
| 325 | input_ids (torch.Tensor): The input IDs tensor. |
| 326 | attention_mask (torch.Tensor): The attention mask tensor. |
| 327 | past_key_values (Optional[Tuple[torch.Tensor]]): The past key values tuple. |
| 328 | |
| 329 | Returns: |
| 330 | Tuple[torch.Tensor, Tuple[torch.Tensor]]: A tuple containing the logits and past key values. |
| 331 | """ |
| 332 | inputs = { |
| 333 | "input_ids": input_ids, |
| 334 | "attention_mask": attention_mask, |
| 335 | "past_key_values": past_key_values, |
| 336 | } |
| 337 | with torch.no_grad(): |
| 338 | outputs: BaseModelOutputWithPast = self.model(**inputs) |
| 339 | |
| 340 | return outputs.logits, outputs.past_key_values |
| 341 | |
| 342 | def __call__(self, input): |
| 343 | return self.forward(input) |
no outgoing calls
no test coverage detected