Unverified Commit eaf5e98e authored by David Reguera's avatar David Reguera Committed by GitHub
Browse files

Add type hints for tf models batch 1 (#25853)

* Add type hints to `TFBlipTextModel`

* Add missing type hints to DPR family models

* Add type hints to `TFLEDModel`

* Add type hints to `TFLxmertForPreTraining`

* Add missing type hints to `TFMarianMTModel` and `TFMarianModel`

* Add missing type hints to `TFRagModel` & `TFRagTokenForGeneration`

* Make type hints annotations consistent
parent 9c5acca0
...@@ -27,6 +27,7 @@ from ...modeling_tf_outputs import ( ...@@ -27,6 +27,7 @@ from ...modeling_tf_outputs import (
TFCausalLMOutputWithCrossAttentions, TFCausalLMOutputWithCrossAttentions,
) )
from ...modeling_tf_utils import ( from ...modeling_tf_utils import (
TFModelInputType,
TFPreTrainedModel, TFPreTrainedModel,
get_initializer, get_initializer,
get_tf_activation, get_tf_activation,
...@@ -668,22 +669,22 @@ class TFBlipTextModel(TFBlipTextPreTrainedModel): ...@@ -668,22 +669,22 @@ class TFBlipTextModel(TFBlipTextPreTrainedModel):
@unpack_inputs @unpack_inputs
def call( def call(
self, self,
input_ids=None, input_ids: TFModelInputType | None = None,
attention_mask=None, attention_mask: tf.Tensor | None = None,
position_ids=None, position_ids: tf.Tensor | None = None,
head_mask=None, head_mask: tf.Tensor | None = None,
inputs_embeds=None, inputs_embeds: tf.Tensor | None = None,
encoder_embeds=None, encoder_embeds: tf.Tensor | None = None,
encoder_hidden_states=None, encoder_hidden_states: tf.Tensor | None = None,
encoder_attention_mask=None, encoder_attention_mask: tf.Tensor | None = None,
past_key_values=None, past_key_values: Tuple[Tuple[tf.Tensor]] | None = None,
use_cache=None, use_cache: bool | None = None,
output_attentions=None, output_attentions: bool | None = None,
output_hidden_states=None, output_hidden_states: bool | None = None,
return_dict=None, return_dict: bool | None = None,
is_decoder=False, is_decoder: bool = False,
training=None, training: bool = False,
): ) -> Tuple[tf.Tensor] | TFBaseModelOutputWithPoolingAndCrossAttentions:
r""" r"""
encoder_hidden_states (`tf.Tensor`, *optional*): encoder_hidden_states (`tf.Tensor`, *optional*):
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
......
...@@ -23,7 +23,7 @@ from typing import Tuple, Union ...@@ -23,7 +23,7 @@ from typing import Tuple, Union
import tensorflow as tf import tensorflow as tf
from ...modeling_tf_outputs import TFBaseModelOutputWithPooling from ...modeling_tf_outputs import TFBaseModelOutputWithPooling
from ...modeling_tf_utils import TFPreTrainedModel, get_initializer, shape_list, unpack_inputs from ...modeling_tf_utils import TFModelInputType, TFPreTrainedModel, get_initializer, shape_list, unpack_inputs
from ...utils import ( from ...utils import (
ModelOutput, ModelOutput,
add_start_docstrings, add_start_docstrings,
...@@ -540,15 +540,15 @@ class TFDPRContextEncoder(TFDPRPretrainedContextEncoder): ...@@ -540,15 +540,15 @@ class TFDPRContextEncoder(TFDPRPretrainedContextEncoder):
@replace_return_docstrings(output_type=TFDPRContextEncoderOutput, config_class=_CONFIG_FOR_DOC) @replace_return_docstrings(output_type=TFDPRContextEncoderOutput, config_class=_CONFIG_FOR_DOC)
def call( def call(
self, self,
input_ids=None, input_ids: TFModelInputType | None = None,
attention_mask: tf.Tensor | None = None, attention_mask: tf.Tensor | None = None,
token_type_ids: tf.Tensor | None = None, token_type_ids: tf.Tensor | None = None,
inputs_embeds: tf.Tensor | None = None, inputs_embeds: tf.Tensor | None = None,
output_attentions=None, output_attentions: bool | None = None,
output_hidden_states=None, output_hidden_states: bool | None = None,
return_dict=None, return_dict: bool | None = None,
training: bool = False, training: bool = False,
) -> Union[TFDPRContextEncoderOutput, Tuple[tf.Tensor, ...]]: ) -> TFDPRContextEncoderOutput | Tuple[tf.Tensor, ...]:
r""" r"""
Return: Return:
...@@ -621,15 +621,15 @@ class TFDPRQuestionEncoder(TFDPRPretrainedQuestionEncoder): ...@@ -621,15 +621,15 @@ class TFDPRQuestionEncoder(TFDPRPretrainedQuestionEncoder):
@replace_return_docstrings(output_type=TFDPRQuestionEncoderOutput, config_class=_CONFIG_FOR_DOC) @replace_return_docstrings(output_type=TFDPRQuestionEncoderOutput, config_class=_CONFIG_FOR_DOC)
def call( def call(
self, self,
input_ids=None, input_ids: TFModelInputType | None = None,
attention_mask: tf.Tensor | None = None, attention_mask: tf.Tensor | None = None,
token_type_ids: tf.Tensor | None = None, token_type_ids: tf.Tensor | None = None,
inputs_embeds: tf.Tensor | None = None, inputs_embeds: tf.Tensor | None = None,
output_attentions=None, output_attentions: bool | None = None,
output_hidden_states=None, output_hidden_states: bool | None = None,
return_dict=None, return_dict: bool | None = None,
training: bool = False, training: bool = False,
) -> Union[TFDPRQuestionEncoderOutput, Tuple[tf.Tensor, ...]]: ) -> TFDPRQuestionEncoderOutput | Tuple[tf.Tensor, ...]:
r""" r"""
Return: Return:
...@@ -701,14 +701,14 @@ class TFDPRReader(TFDPRPretrainedReader): ...@@ -701,14 +701,14 @@ class TFDPRReader(TFDPRPretrainedReader):
@replace_return_docstrings(output_type=TFDPRReaderOutput, config_class=_CONFIG_FOR_DOC) @replace_return_docstrings(output_type=TFDPRReaderOutput, config_class=_CONFIG_FOR_DOC)
def call( def call(
self, self,
input_ids=None, input_ids: TFModelInputType | None = None,
attention_mask: tf.Tensor | None = None, attention_mask: tf.Tensor | None = None,
inputs_embeds: tf.Tensor | None = None, inputs_embeds: tf.Tensor | None = None,
output_attentions: bool = None, output_attentions: bool | None = None,
output_hidden_states: bool = None, output_hidden_states: bool | None = None,
return_dict=None, return_dict: bool | None = None,
training: bool = False, training: bool = False,
) -> Union[TFDPRReaderOutput, Tuple[tf.Tensor, ...]]: ) -> TFDPRReaderOutput | Tuple[tf.Tensor, ...]:
r""" r"""
Return: Return:
......
...@@ -1571,7 +1571,7 @@ LED_INPUTS_DOCSTRING = r""" ...@@ -1571,7 +1571,7 @@ LED_INPUTS_DOCSTRING = r"""
- 0 for tokens that are **masked**. - 0 for tokens that are **masked**.
[What are attention masks?](../glossary#attention-mask) [What are attention masks?](../glossary#attention-mask)
decoder_input_ids (`tf.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*): decoder_input_ids (`tf.Tensor` of shape `(batch_size, target_sequence_length)`, *optional*):
Indices of decoder input sequence tokens in the vocabulary. Indices of decoder input sequence tokens in the vocabulary.
Indices can be obtained using [`LedTokenizer`]. See [`PreTrainedTokenizer.encode`] and Indices can be obtained using [`LedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
...@@ -1595,7 +1595,7 @@ LED_INPUTS_DOCSTRING = r""" ...@@ -1595,7 +1595,7 @@ LED_INPUTS_DOCSTRING = r"""
- 1 indicates the head is **not masked**, - 1 indicates the head is **not masked**,
- 0 indicates the head is **masked**. - 0 indicates the head is **masked**.
encoder_outputs (`tf.FloatTensor`, *optional*): encoder_outputs (`tf.Tensor`, *optional*):
hidden states at the output of the last layer of the encoder. Used in the cross-attention of the decoder. hidden states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
of shape `(batch_size, sequence_length, hidden_size)` is a sequence of of shape `(batch_size, sequence_length, hidden_size)` is a sequence of
past_key_values (`Tuple[Tuple[tf.Tensor]]` of length `config.n_layers`) past_key_values (`Tuple[Tuple[tf.Tensor]]` of length `config.n_layers`)
...@@ -2236,24 +2236,24 @@ class TFLEDModel(TFLEDPreTrainedModel): ...@@ -2236,24 +2236,24 @@ class TFLEDModel(TFLEDPreTrainedModel):
) )
def call( def call(
self, self,
input_ids=None, input_ids: TFModelInputType | None = None,
attention_mask=None, attention_mask: tf.Tensor | None = None,
decoder_input_ids=None, decoder_input_ids: tf.Tensor | None = None,
decoder_attention_mask=None, decoder_attention_mask: tf.Tensor | None = None,
head_mask=None, head_mask: tf.Tensor | None = None,
decoder_head_mask=None, decoder_head_mask: tf.Tensor | None = None,
encoder_outputs: Optional[Union[Tuple, TFLEDEncoderBaseModelOutput]] = None, encoder_outputs: tf.Tensor | None = None,
global_attention_mask=None, global_attention_mask: tf.Tensor | None = None,
past_key_values=None, past_key_values: Tuple[Tuple[tf.Tensor]] | None = None,
inputs_embeds=None, inputs_embeds: tf.Tensor | None = None,
decoder_inputs_embeds=None, decoder_inputs_embeds: tf.Tensor | None = None,
use_cache=None, use_cache: bool | None = None,
output_attentions=None, output_attentions: bool | None = None,
output_hidden_states=None, output_hidden_states: bool | None = None,
return_dict=None, return_dict: bool | None = None,
training=False, training: bool = False,
**kwargs, **kwargs,
): ) -> Tuple[tf.Tensor] | TFLEDSeq2SeqModelOutput:
outputs = self.led( outputs = self.led(
input_ids=input_ids, input_ids=input_ids,
attention_mask=attention_mask, attention_mask=attention_mask,
...@@ -2371,18 +2371,18 @@ class TFLEDForConditionalGeneration(TFLEDPreTrainedModel): ...@@ -2371,18 +2371,18 @@ class TFLEDForConditionalGeneration(TFLEDPreTrainedModel):
decoder_attention_mask: np.ndarray | tf.Tensor | None = None, decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None = None, head_mask: np.ndarray | tf.Tensor | None = None,
decoder_head_mask: np.ndarray | tf.Tensor | None = None, decoder_head_mask: np.ndarray | tf.Tensor | None = None,
encoder_outputs: Optional[TFLEDEncoderBaseModelOutput] = None, encoder_outputs: TFLEDEncoderBaseModelOutput | None = None,
global_attention_mask: np.ndarray | tf.Tensor | None = None, global_attention_mask: np.ndarray | tf.Tensor | None = None,
past_key_values: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]] = None, past_key_values: Tuple[Tuple[Union[np.ndarray, tf.Tensor]]] | None = None,
inputs_embeds: np.ndarray | tf.Tensor | None = None, inputs_embeds: np.ndarray | tf.Tensor | None = None,
decoder_inputs_embeds: np.ndarray | tf.Tensor | None = None, decoder_inputs_embeds: np.ndarray | tf.Tensor | None = None,
use_cache: Optional[bool] = None, use_cache: bool | None = None,
output_attentions: Optional[bool] = None, output_attentions: bool | None = None,
output_hidden_states: Optional[bool] = None, output_hidden_states: bool | None = None,
return_dict: Optional[bool] = None, return_dict: bool | None = None,
labels: tf.Tensor | None = None, labels: tf.Tensor | None = None,
training: bool = False, training: bool = False,
): ) -> Tuple[tf.Tensor] | TFLEDSeq2SeqLMOutput:
""" """
Returns: Returns:
......
...@@ -1251,22 +1251,22 @@ class TFLxmertForPreTraining(TFLxmertPreTrainedModel): ...@@ -1251,22 +1251,22 @@ class TFLxmertForPreTraining(TFLxmertPreTrainedModel):
@replace_return_docstrings(output_type=TFLxmertForPreTrainingOutput, config_class=_CONFIG_FOR_DOC) @replace_return_docstrings(output_type=TFLxmertForPreTrainingOutput, config_class=_CONFIG_FOR_DOC)
def call( def call(
self, self,
input_ids=None, input_ids: TFModelInputType | None = None,
visual_feats=None, visual_feats: tf.Tensor | None = None,
visual_pos=None, visual_pos: tf.Tensor | None = None,
attention_mask=None, attention_mask: tf.Tensor | None = None,
visual_attention_mask=None, visual_attention_mask: tf.Tensor | None = None,
token_type_ids=None, token_type_ids: tf.Tensor | None = None,
inputs_embeds=None, inputs_embeds: tf.Tensor | None = None,
masked_lm_labels=None, masked_lm_labels: tf.Tensor | None = None,
obj_labels=None, obj_labels: Dict[str, Tuple[tf.Tensor, tf.Tensor]] | None = None,
matched_label=None, matched_label: tf.Tensor | None = None,
ans=None, ans: tf.Tensor | None = None,
output_attentions=None, output_attentions: bool | None = None,
output_hidden_states=None, output_hidden_states: bool | None = None,
return_dict=None, return_dict: bool | None = None,
training=False, training: bool = False,
): ) -> Tuple[tf.Tensor] | TFLxmertForPreTrainingOutput:
r""" r"""
masked_lm_labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*): masked_lm_labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ..., Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
...@@ -1282,7 +1282,7 @@ class TFLxmertForPreTraining(TFLxmertPreTrainedModel): ...@@ -1282,7 +1282,7 @@ class TFLxmertForPreTraining(TFLxmertPreTrainedModel):
- 0 indicates that the sentence does not match the image, - 0 indicates that the sentence does not match the image,
- 1 indicates that the sentence does match the image. - 1 indicates that the sentence does match the image.
ans (`Torch.Tensor` of shape `(batch_size)`, *optional*, defaults to `None`): ans (`tf.Tensor` of shape `(batch_size)`, *optional*, defaults to `None`):
a one hot representation hof the correct answer *optional* a one hot representation hof the correct answer *optional*
Returns: Returns:
......
...@@ -1187,13 +1187,13 @@ class TFMarianModel(TFMarianPreTrainedModel): ...@@ -1187,13 +1187,13 @@ class TFMarianModel(TFMarianPreTrainedModel):
past_key_values: Tuple[Tuple[tf.Tensor]] | None = None, past_key_values: Tuple[Tuple[tf.Tensor]] | None = None,
inputs_embeds: tf.Tensor | None = None, inputs_embeds: tf.Tensor | None = None,
decoder_inputs_embeds: tf.Tensor | None = None, decoder_inputs_embeds: tf.Tensor | None = None,
use_cache: Optional[bool] = None, use_cache: bool | None = None,
output_attentions: Optional[bool] = None, output_attentions: bool | None = None,
output_hidden_states: Optional[bool] = None, output_hidden_states: bool | None = None,
return_dict: Optional[bool] = None, return_dict: bool | None = None,
training: bool = False, training: bool = False,
**kwargs, **kwargs,
): ) -> Tuple[tf.Tensor] | TFSeq2SeqModelOutput:
outputs = self.model( outputs = self.model(
input_ids=input_ids, input_ids=input_ids,
attention_mask=attention_mask, attention_mask=attention_mask,
...@@ -1311,17 +1311,17 @@ class TFMarianMTModel(TFMarianPreTrainedModel, TFCausalLanguageModelingLoss): ...@@ -1311,17 +1311,17 @@ class TFMarianMTModel(TFMarianPreTrainedModel, TFCausalLanguageModelingLoss):
head_mask: tf.Tensor | None = None, head_mask: tf.Tensor | None = None,
decoder_head_mask: tf.Tensor | None = None, decoder_head_mask: tf.Tensor | None = None,
cross_attn_head_mask: tf.Tensor | None = None, cross_attn_head_mask: tf.Tensor | None = None,
encoder_outputs: Optional[TFBaseModelOutput] = None, encoder_outputs: TFBaseModelOutput | None = None,
past_key_values: Tuple[Tuple[tf.Tensor]] | None = None, past_key_values: Tuple[Tuple[tf.Tensor]] | None = None,
inputs_embeds: tf.Tensor | None = None, inputs_embeds: tf.Tensor | None = None,
decoder_inputs_embeds: tf.Tensor | None = None, decoder_inputs_embeds: tf.Tensor | None = None,
use_cache: Optional[bool] = None, use_cache: bool | None = None,
output_attentions: Optional[bool] = None, output_attentions: bool | None = None,
output_hidden_states: Optional[bool] = None, output_hidden_states: bool | None = None,
return_dict: Optional[bool] = None, return_dict: bool | None = None,
labels: tf.Tensor | None = None, labels: tf.Tensor | None = None,
training: bool = False, training: bool = False,
): ) -> Tuple[tf.Tensor] | TFSeq2SeqLMOutput:
r""" r"""
labels (`tf.tensor` of shape `(batch_size, sequence_length)`, *optional*): labels (`tf.tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ..., Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
......
...@@ -553,19 +553,19 @@ class TFRagModel(TFRagPreTrainedModel): ...@@ -553,19 +553,19 @@ class TFRagModel(TFRagPreTrainedModel):
encoder_outputs: np.ndarray | tf.Tensor | None = None, encoder_outputs: np.ndarray | tf.Tensor | None = None,
decoder_input_ids: np.ndarray | tf.Tensor | None = None, decoder_input_ids: np.ndarray | tf.Tensor | None = None,
decoder_attention_mask: np.ndarray | tf.Tensor | None = None, decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
past_key_values: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]] = None, past_key_values: Tuple[Tuple[Union[np.ndarray, tf.Tensor]]] | None = None,
doc_scores: np.ndarray | tf.Tensor | None = None, doc_scores: np.ndarray | tf.Tensor | None = None,
context_input_ids: np.ndarray | tf.Tensor | None = None, context_input_ids: np.ndarray | tf.Tensor | None = None,
context_attention_mask: np.ndarray | tf.Tensor | None = None, context_attention_mask: np.ndarray | tf.Tensor | None = None,
use_cache: Optional[bool] = None, use_cache: bool | None = None,
output_attentions: Optional[bool] = None, output_attentions: bool | None = None,
output_hidden_states: Optional[bool] = None, output_hidden_states: bool | None = None,
output_retrieved: Optional[bool] = None, output_retrieved: bool | None = None,
n_docs: Optional[int] = None, n_docs: int | None = None,
return_dict: Optional[bool] = None, return_dict: bool | None = None,
training: bool = False, training: bool = False,
**kwargs, **kwargs,
): ) -> TFRetrievAugLMOutput:
r""" r"""
Returns: Returns:
...@@ -849,22 +849,22 @@ class TFRagTokenForGeneration(TFRagPreTrainedModel, TFCausalLanguageModelingLoss ...@@ -849,22 +849,22 @@ class TFRagTokenForGeneration(TFRagPreTrainedModel, TFCausalLanguageModelingLoss
decoder_input_ids: np.ndarray | tf.Tensor | None = None, decoder_input_ids: np.ndarray | tf.Tensor | None = None,
decoder_attention_mask: np.ndarray | tf.Tensor | None = None, decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
encoder_outputs: np.ndarray | tf.Tensor | None = None, encoder_outputs: np.ndarray | tf.Tensor | None = None,
past_key_values: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]] = None, past_key_values: Tuple[Tuple[Union[np.ndarray, tf.Tensor]]] | None = None,
doc_scores: np.ndarray | tf.Tensor | None = None, doc_scores: np.ndarray | tf.Tensor | None = None,
context_input_ids: np.ndarray | tf.Tensor | None = None, context_input_ids: np.ndarray | tf.Tensor | None = None,
context_attention_mask: np.ndarray | tf.Tensor | None = None, context_attention_mask: np.ndarray | tf.Tensor | None = None,
use_cache: Optional[bool] = None, use_cache: bool | None = None,
output_attentions: Optional[bool] = None, output_attentions: bool | None = None,
output_hidden_states: Optional[bool] = None, output_hidden_states: bool | None = None,
output_retrieved: Optional[bool] = None, output_retrieved: bool | None = None,
n_docs: Optional[int] = None, n_docs: int | None = None,
do_marginalize: Optional[bool] = None, do_marginalize: bool | None = None,
labels: np.ndarray | tf.Tensor | None = None, labels: np.ndarray | tf.Tensor | None = None,
reduce_loss: Optional[bool] = None, reduce_loss: bool | None = None,
return_dict: Optional[bool] = None, return_dict: bool | None = None,
training: bool = False, training: bool = False,
**kwargs, # needs kwargs for generation **kwargs, # needs kwargs for generation
): ) -> TFRetrievAugLMMarginOutput:
r""" r"""
do_marginalize (`bool`, *optional*): do_marginalize (`bool`, *optional*):
If `True`, the logits are marginalized over all documents by making use of If `True`, the logits are marginalized over all documents by making use of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment