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

Method forward

modelscope/models/nlp/bert/backbone.py:720–927  ·  view source on GitHub ↗

r""" Args: input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`BertTokenizer`]. See [`PreTrainedTokenizer.encode`] and [`PreTr

(self,
                input_ids=None,
                attention_mask=None,
                token_type_ids=None,
                position_ids=None,
                head_mask=None,
                inputs_embeds=None,
                encoder_hidden_states=None,
                encoder_attention_mask=None,
                past_key_values=None,
                use_cache=None,
                output_attentions=None,
                output_hidden_states=None,
                return_dict=None,
                **kwargs)

Source from the content-addressed store, hash-verified

718 self.encoder.layer[layer].attention.prune_heads(heads)
719
720 def forward(self,
721 input_ids=None,
722 attention_mask=None,
723 token_type_ids=None,
724 position_ids=None,
725 head_mask=None,
726 inputs_embeds=None,
727 encoder_hidden_states=None,
728 encoder_attention_mask=None,
729 past_key_values=None,
730 use_cache=None,
731 output_attentions=None,
732 output_hidden_states=None,
733 return_dict=None,
734 **kwargs) -> AttentionBackboneModelOutput:
735 r"""
736 Args:
737 input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
738 Indices of input sequence tokens in the vocabulary.
739
740 Indices can be obtained using [`BertTokenizer`]. See
741 [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`]
742 for details.
743
744 [What are input IDs?](../glossary#input-ids)
745 attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
746 Mask to avoid performing attention on padding token indices. Mask
747 values selected in `[0, 1]`:
748
749 - 1 for tokens that are **not masked**,
750 - 0 for tokens that are **masked**.
751
752 [What are attention masks?](../glossary#attention-mask)
753 token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
754 Segment token indices to indicate first and second portions of the
755 inputs. Indices are selected in `[0, 1]`:
756
757 - 0 corresponds to a *sentence A* token,
758 - 1 corresponds to a *sentence B* token.
759
760 [What are token type IDs?](../glossary#token-type-ids)
761 position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
762 Indices of positions of each input sequence tokens in the position
763 embeddings. Selected in the range `[0,
764 config.max_position_embeddings - 1]`.
765
766 [What are position IDs?](../glossary#position-ids)
767 head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers,
768 num_heads)`, *optional*):
769 Mask to nullify selected heads of the self-attention modules. Mask
770 values selected in `[0, 1]`:
771
772 - 1 indicates the head is **not masked**,
773 - 0 indicates the head is **masked**.
774
775 inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`,
776 *optional*):
777 Optionally, instead of passing `input_ids` you can choose to

Callers

nothing calls this directly

Calls 5

encoderMethod · 0.80
poolerMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected