r""" Return: :obj:`tuple(torch.FloatTensor)` comprising various elements depending on the configuration (:class:`~transformers.CTRLConfig`) and inputs: last_hidden_state (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`): Sequence of
(
self,
input_ids=None,
past=None,
attention_mask=None,
token_type_ids=None,
position_ids=None,
head_mask=None,
inputs_embeds=None,
use_cache=None,
output_attentions=None,
output_hidden_states=None,
)
| 330 | @add_start_docstrings_to_callable(CTRL_INPUTS_DOCSTRING) |
| 331 | @add_code_sample_docstrings(tokenizer_class=_TOKENIZER_FOR_DOC, checkpoint="ctrl") |
| 332 | def forward( |
| 333 | self, |
| 334 | input_ids=None, |
| 335 | past=None, |
| 336 | attention_mask=None, |
| 337 | token_type_ids=None, |
| 338 | position_ids=None, |
| 339 | head_mask=None, |
| 340 | inputs_embeds=None, |
| 341 | use_cache=None, |
| 342 | output_attentions=None, |
| 343 | output_hidden_states=None, |
| 344 | ): |
| 345 | r""" |
| 346 | Return: |
| 347 | :obj:`tuple(torch.FloatTensor)` comprising various elements depending on the configuration (:class:`~transformers.CTRLConfig`) and inputs: |
| 348 | last_hidden_state (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`): |
| 349 | Sequence of hidden-states at the last layer of the model. |
| 350 | past (:obj:`List[torch.FloatTensor]` of length :obj:`config.n_layers` with each tensor of shape :obj:`(2, batch_size, num_heads, sequence_length, embed_size_per_head)`): |
| 351 | Contains pre-computed hidden-states (key and values in the attention blocks). |
| 352 | Can be used (see `past` input) to speed up sequential decoding. |
| 353 | hidden_states (:obj:`tuple(torch.FloatTensor)`, `optional`, returned when ``output_hidden_states=True`` is passed or when ``config.output_hidden_states=True``): |
| 354 | Tuple of :obj:`torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) |
| 355 | of shape :obj:`(batch_size, sequence_length, hidden_size)`. |
| 356 | |
| 357 | Hidden-states of the model at the output of each layer plus the initial embedding outputs. |
| 358 | attentions (:obj:`tuple(torch.FloatTensor)`, `optional`, returned when ``output_attentions=True`` is passed or when ``config.output_attentions=True``): |
| 359 | Tuple of :obj:`torch.FloatTensor` (one for each layer) of shape |
| 360 | :obj:`(batch_size, num_heads, sequence_length, sequence_length)`. |
| 361 | |
| 362 | Attentions weights after the attention softmax, used to compute the weighted average in the self-attention |
| 363 | heads. |
| 364 | """ |
| 365 | output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions |
| 366 | use_cache = use_cache if use_cache is not None else self.config.use_cache |
| 367 | output_hidden_states = ( |
| 368 | output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states |
| 369 | ) |
| 370 | |
| 371 | if input_ids is not None and inputs_embeds is not None: |
| 372 | raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time") |
| 373 | elif input_ids is not None: |
| 374 | input_shape = input_ids.size() |
| 375 | input_ids = input_ids.view(-1, input_shape[-1]) |
| 376 | batch_size = input_ids.shape[0] |
| 377 | elif inputs_embeds is not None: |
| 378 | input_shape = inputs_embeds.size()[:-1] |
| 379 | batch_size = inputs_embeds.shape[0] |
| 380 | else: |
| 381 | raise ValueError("You have to specify either input_ids or inputs_embeds") |
| 382 | |
| 383 | if past is None: |
| 384 | past_length = 0 |
| 385 | past = [None] * len(self.h) |
| 386 | else: |
| 387 | past_length = past[0][0].size(-2) |
| 388 | if position_ids is None: |
| 389 | device = input_ids.device if input_ids is not None else inputs_embeds.device |
nothing calls this directly
no test coverage detected