MCPcopy Create free account
hub / github.com/modelscope/modelscope / forward

Method forward

modelscope/models/nlp/T5/backbone.py:1309–1536  ·  view source on GitHub ↗

r""" Args: input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you should be able to pad the inputs on both the right and th

(
        self,
        input_ids: Optional[torch.LongTensor] = None,
        attention_mask: Optional[torch.FloatTensor] = None,
        decoder_input_ids: Optional[torch.LongTensor] = None,
        decoder_attention_mask: Optional[torch.BoolTensor] = None,
        head_mask: Optional[torch.FloatTensor] = None,
        decoder_head_mask: Optional[torch.FloatTensor] = None,
        cross_attn_head_mask: Optional[torch.Tensor] = None,
        encoder_outputs: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
        past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
        inputs_embeds: Optional[torch.Tensor] = None,
        decoder_inputs_embeds: Optional[torch.Tensor] = None,
        use_cache: Optional[bool] = None,
        output_attentions: Optional[bool] = None,
        output_hidden_states: Optional[bool] = None,
        return_dict: Optional[bool] = None,
    )

Source from the content-addressed store, hash-verified

1307 self.encoder.layer[layer].attention.prune_heads(heads)
1308
1309 def forward(
1310 self,
1311 input_ids: Optional[torch.LongTensor] = None,
1312 attention_mask: Optional[torch.FloatTensor] = None,
1313 decoder_input_ids: Optional[torch.LongTensor] = None,
1314 decoder_attention_mask: Optional[torch.BoolTensor] = None,
1315 head_mask: Optional[torch.FloatTensor] = None,
1316 decoder_head_mask: Optional[torch.FloatTensor] = None,
1317 cross_attn_head_mask: Optional[torch.Tensor] = None,
1318 encoder_outputs: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
1319 past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
1320 inputs_embeds: Optional[torch.Tensor] = None,
1321 decoder_inputs_embeds: Optional[torch.Tensor] = None,
1322 use_cache: Optional[bool] = None,
1323 output_attentions: Optional[bool] = None,
1324 output_hidden_states: Optional[bool] = None,
1325 return_dict: Optional[bool] = None,
1326 ) -> Union[Tuple[torch.FloatTensor], Seq2SeqModelOutput]:
1327 r"""
1328 Args:
1329 input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
1330 Indices of input sequence tokens in the vocabulary. T5 is a model
1331 with relative position embeddings so you should be able to pad the
1332 inputs on both the right and the left.
1333
1334 Indices can be obtained using [`T5Tokenizer`]. See
1335 [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`]
1336 for detail.
1337
1338 [What are input IDs?](../glossary#input-ids)
1339
1340 To know more on how to prepare `input_ids` for pretraining take a
1341 look a [T5 Training](./t5#training).
1342 attention_mask (`torch.FloatTensor` of shape `(batch_size,
1343 sequence_length)`, *optional*):
1344 Mask to avoid performing attention on padding token indices. Mask
1345 values selected in `[0, 1]`:
1346
1347 - 1 for tokens that are **not masked**,
1348 - 0 for tokens that are **masked**.
1349
1350 [What are attention masks?](../glossary#attention-mask)
1351 decoder_input_ids (`torch.LongTensor` of shape `(batch_size,
1352 target_sequence_length)`, *optional*):
1353 Indices of decoder input sequence tokens in the vocabulary.
1354
1355 Indices can be obtained using [`T5Tokenizer`]. See
1356 [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`]
1357 for details.
1358
1359 [What are decoder input IDs?](../glossary#decoder-input-ids)
1360
1361 T5 uses the `pad_token_id` as the starting token for
1362 `decoder_input_ids` generation. If `past_key_values` is used,
1363 optionally only the last `decoder_input_ids` have to be input (see
1364 `past_key_values`).
1365
1366 To know more on how to prepare `decoder_input_ids` for pretraining

Callers

nothing calls this directly

Calls 5

Seq2SeqModelOutputClass · 0.90
encoderMethod · 0.80
set_deviceMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected