Unverified Commit de4159a3 authored by Matt's avatar Matt Committed by GitHub
Browse files

More TF int dtype fixes (#20384)

* Add a test to ensure int dummy inputs are int64

* Move the test into the existing int64 test and update a lot of existing dummies

* Fix remaining dummies

* Fix remaining dummies

* Test for int64 serving sigs as well

* Update core tests to use tf.int64

* Add better messages to the assertions

* Update all serving sigs to int64

* More sneaky hiding tf.int32s

* Add an optional int32 signature in save_pretrained

* make fixup

* Add Amy's suggestions

* Switch all serving sigs back to tf.int32

* Switch all dummies to tf.int32

* Adjust tests to check for tf.int32 instead of tf.int64

* Fix base dummy_inputs dtype

* Start casting to tf.int32 in input_processing

* Change dtype for unpack_inputs test

* Add proper tf.int32 test

* Make the alternate serving signature int64
parent 72b19ca6
...@@ -585,10 +585,10 @@ def input_processing(func, config, **kwargs): ...@@ -585,10 +585,10 @@ def input_processing(func, config, **kwargs):
cast_output = dict() cast_output = dict()
for key, val in output.items(): for key, val in output.items():
if isinstance(val, tf.Tensor) and val.dtype == tf.int32: if isinstance(val, tf.Tensor) and val.dtype == tf.int64:
cast_output[key] = tf.cast(val, tf.int64) cast_output[key] = tf.cast(val, tf.int32)
elif isinstance(val, np.ndarray) and val.dtype == np.int32: elif isinstance(val, np.ndarray) and val.dtype == np.int64:
cast_output[key] = val.astype(np.int64) cast_output[key] = val.astype(np.int32)
else: else:
cast_output[key] = val cast_output[key] = val
...@@ -1115,7 +1115,7 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu ...@@ -1115,7 +1115,7 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu
`Dict[str, tf.Tensor]`: The dummy inputs. `Dict[str, tf.Tensor]`: The dummy inputs.
""" """
return { return {
"input_ids": tf.constant(DUMMY_INPUTS), "input_ids": tf.constant(DUMMY_INPUTS, dtype=tf.int32),
} }
@property @property
...@@ -1155,12 +1155,25 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu ...@@ -1155,12 +1155,25 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu
""" """
return cls(config, **kwargs) return cls(config, **kwargs)
def eager_serving(self, inputs):
"""
Method used for serving the model. Intended not to be compiled with a tf.function decorator so that we can use
it to generate multiple signatures later.
Args:
inputs (`Dict[str, tf.Tensor]`):
The input of the saved model as a dictionary of tensors.
"""
output = self.call(inputs)
return self.serving_output(output)
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
"token_type_ids": tf.TensorSpec((None, None), tf.int64, name="token_type_ids"), "token_type_ids": tf.TensorSpec((None, None), tf.int32, name="token_type_ids"),
} }
] ]
) )
...@@ -2253,7 +2266,17 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu ...@@ -2253,7 +2266,17 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu
if saved_model: if saved_model:
if signatures is None: if signatures is None:
signatures = self.serving if any(spec.dtype == tf.int32 for spec in self.serving.input_signature[0].values()):
int64_spec = {
key: tf.TensorSpec(
shape=spec.shape, dtype=tf.int64 if spec.dtype == tf.int32 else spec.dtype, name=spec.name
)
for key, spec in self.serving.input_signature[0].items()
}
int64_serving = tf.function(self.eager_serving, input_signature=[int64_spec])
signatures = {"serving_default": self.serving, "int64_serving": int64_serving}
else:
signatures = self.serving
saved_model_dir = os.path.join(save_directory, "saved_model", str(version)) saved_model_dir = os.path.join(save_directory, "saved_model", str(version))
self.save(saved_model_dir, include_optimizer=False, signatures=signatures) self.save(saved_model_dir, include_optimizer=False, signatures=signatures)
logger.info(f"Saved model created in {saved_model_dir}") logger.info(f"Saved model created in {saved_model_dir}")
......
...@@ -1396,7 +1396,7 @@ class TFAlbertForMultipleChoice(TFAlbertPreTrainedModel, TFMultipleChoiceLoss): ...@@ -1396,7 +1396,7 @@ class TFAlbertForMultipleChoice(TFAlbertPreTrainedModel, TFMultipleChoiceLoss):
Returns: Returns:
tf.Tensor with dummy inputs tf.Tensor with dummy inputs
""" """
return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS)} return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32)}
@unpack_inputs @unpack_inputs
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length")) @add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
......
...@@ -467,11 +467,11 @@ class TFBartPretrainedModel(TFPreTrainedModel): ...@@ -467,11 +467,11 @@ class TFBartPretrainedModel(TFPreTrainedModel):
@property @property
def dummy_inputs(self): def dummy_inputs(self):
pad_token = 1 pad_token = 1
input_ids = tf.cast(tf.convert_to_tensor(DUMMY_INPUTS), tf.int32) input_ids = tf.convert_to_tensor(DUMMY_INPUTS, dtype=tf.int32)
decoder_input_ids = tf.cast(tf.convert_to_tensor(DUMMY_INPUTS), tf.int32) decoder_input_ids = tf.convert_to_tensor(DUMMY_INPUTS, dtype=tf.int32)
dummy_inputs = { dummy_inputs = {
"decoder_input_ids": decoder_input_ids, "decoder_input_ids": decoder_input_ids,
"attention_mask": tf.math.not_equal(input_ids, pad_token), "attention_mask": tf.cast(input_ids != pad_token, tf.int32),
"input_ids": input_ids, "input_ids": input_ids,
} }
return dummy_inputs return dummy_inputs
...@@ -479,10 +479,10 @@ class TFBartPretrainedModel(TFPreTrainedModel): ...@@ -479,10 +479,10 @@ class TFBartPretrainedModel(TFPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
"decoder_input_ids": tf.TensorSpec((None, None), tf.int64, name="decoder_input_ids"), "decoder_input_ids": tf.TensorSpec((None, None), tf.int32, name="decoder_input_ids"),
"decoder_attention_mask": tf.TensorSpec((None, None), tf.int64, name="decoder_attention_mask"), "decoder_attention_mask": tf.TensorSpec((None, None), tf.int32, name="decoder_attention_mask"),
} }
] ]
) )
......
...@@ -920,7 +920,7 @@ class TFBertPreTrainedModel(TFPreTrainedModel): ...@@ -920,7 +920,7 @@ class TFBertPreTrainedModel(TFPreTrainedModel):
Returns: Returns:
`Dict[str, tf.Tensor]`: The dummy inputs. `Dict[str, tf.Tensor]`: The dummy inputs.
""" """
dummy = {"input_ids": tf.constant(DUMMY_INPUTS)} dummy = {"input_ids": tf.constant(DUMMY_INPUTS, dtype=tf.int32)}
# Add `encoder_hidden_states` to make the cross-attention layers' weights initialized # Add `encoder_hidden_states` to make the cross-attention layers' weights initialized
if self.config.add_cross_attention: if self.config.add_cross_attention:
batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape
...@@ -1726,7 +1726,7 @@ class TFBertForMultipleChoice(TFBertPreTrainedModel, TFMultipleChoiceLoss): ...@@ -1726,7 +1726,7 @@ class TFBertForMultipleChoice(TFBertPreTrainedModel, TFMultipleChoiceLoss):
Returns: Returns:
tf.Tensor with dummy inputs tf.Tensor with dummy inputs
""" """
return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS)} return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32)}
@unpack_inputs @unpack_inputs
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length")) @add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
...@@ -1809,9 +1809,9 @@ class TFBertForMultipleChoice(TFBertPreTrainedModel, TFMultipleChoiceLoss): ...@@ -1809,9 +1809,9 @@ class TFBertForMultipleChoice(TFBertPreTrainedModel, TFMultipleChoiceLoss):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None, None), tf.int32, name="attention_mask"),
"token_type_ids": tf.TensorSpec((None, None, None), tf.int64, name="token_type_ids"), "token_type_ids": tf.TensorSpec((None, None, None), tf.int32, name="token_type_ids"),
} }
] ]
) )
......
...@@ -466,11 +466,11 @@ class TFBlenderbotPreTrainedModel(TFPreTrainedModel): ...@@ -466,11 +466,11 @@ class TFBlenderbotPreTrainedModel(TFPreTrainedModel):
@property @property
def dummy_inputs(self): def dummy_inputs(self):
pad_token = 1 pad_token = 1
input_ids = tf.cast(tf.convert_to_tensor(DUMMY_INPUTS), tf.int32) input_ids = tf.convert_to_tensor(DUMMY_INPUTS, dtype=tf.int32)
decoder_input_ids = tf.cast(tf.convert_to_tensor(DUMMY_INPUTS), tf.int32) decoder_input_ids = tf.convert_to_tensor(DUMMY_INPUTS, dtype=tf.int32)
dummy_inputs = { dummy_inputs = {
"decoder_input_ids": decoder_input_ids, "decoder_input_ids": decoder_input_ids,
"attention_mask": tf.math.not_equal(input_ids, pad_token), "attention_mask": tf.cast(input_ids != pad_token, tf.int32),
"input_ids": input_ids, "input_ids": input_ids,
} }
return dummy_inputs return dummy_inputs
......
...@@ -466,11 +466,11 @@ class TFBlenderbotSmallPreTrainedModel(TFPreTrainedModel): ...@@ -466,11 +466,11 @@ class TFBlenderbotSmallPreTrainedModel(TFPreTrainedModel):
@property @property
def dummy_inputs(self): def dummy_inputs(self):
pad_token = 1 pad_token = 1
input_ids = tf.cast(tf.convert_to_tensor(DUMMY_INPUTS), tf.int32) input_ids = tf.convert_to_tensor(DUMMY_INPUTS, dtype=tf.int32)
decoder_input_ids = tf.cast(tf.convert_to_tensor(DUMMY_INPUTS), tf.int32) decoder_input_ids = tf.convert_to_tensor(DUMMY_INPUTS, dtype=tf.int32)
dummy_inputs = { dummy_inputs = {
"decoder_input_ids": decoder_input_ids, "decoder_input_ids": decoder_input_ids,
"attention_mask": tf.math.not_equal(input_ids, pad_token), "attention_mask": tf.cast(input_ids != pad_token, tf.int32),
"input_ids": input_ids, "input_ids": input_ids,
} }
return dummy_inputs return dummy_inputs
......
...@@ -891,7 +891,7 @@ class TFCamembertPreTrainedModel(TFPreTrainedModel): ...@@ -891,7 +891,7 @@ class TFCamembertPreTrainedModel(TFPreTrainedModel):
Returns: Returns:
`Dict[str, tf.Tensor]`: The dummy inputs. `Dict[str, tf.Tensor]`: The dummy inputs.
""" """
dummy = {"input_ids": tf.constant(DUMMY_INPUTS)} dummy = {"input_ids": tf.constant(DUMMY_INPUTS, dtype=tf.int32)}
# Add `encoder_hidden_states` to make the cross-attention layers' weights initialized # Add `encoder_hidden_states` to make the cross-attention layers' weights initialized
if self.config.add_cross_attention: if self.config.add_cross_attention:
batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape
...@@ -904,8 +904,8 @@ class TFCamembertPreTrainedModel(TFPreTrainedModel): ...@@ -904,8 +904,8 @@ class TFCamembertPreTrainedModel(TFPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
...@@ -1390,7 +1390,7 @@ class TFCamembertForMultipleChoice(TFCamembertPreTrainedModel, TFMultipleChoiceL ...@@ -1390,7 +1390,7 @@ class TFCamembertForMultipleChoice(TFCamembertPreTrainedModel, TFMultipleChoiceL
Returns: Returns:
tf.Tensor with dummy inputs tf.Tensor with dummy inputs
""" """
return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS)} return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32)}
@unpack_inputs @unpack_inputs
@add_start_docstrings_to_model_forward( @add_start_docstrings_to_model_forward(
......
...@@ -1107,8 +1107,8 @@ class TFCLIPTextModel(TFCLIPPreTrainedModel): ...@@ -1107,8 +1107,8 @@ class TFCLIPTextModel(TFCLIPPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
......
...@@ -1058,7 +1058,7 @@ class TFConvBertForMultipleChoice(TFConvBertPreTrainedModel, TFMultipleChoiceLos ...@@ -1058,7 +1058,7 @@ class TFConvBertForMultipleChoice(TFConvBertPreTrainedModel, TFMultipleChoiceLos
Returns: Returns:
tf.Tensor with dummy inputs tf.Tensor with dummy inputs
""" """
return {"input_ids": tf.convert_to_tensor(MULTIPLE_CHOICE_DUMMY_INPUTS)} return {"input_ids": tf.convert_to_tensor(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32)}
@unpack_inputs @unpack_inputs
@add_start_docstrings_to_model_forward( @add_start_docstrings_to_model_forward(
...@@ -1137,9 +1137,9 @@ class TFConvBertForMultipleChoice(TFConvBertPreTrainedModel, TFMultipleChoiceLos ...@@ -1137,9 +1137,9 @@ class TFConvBertForMultipleChoice(TFConvBertPreTrainedModel, TFMultipleChoiceLos
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None, None), tf.int32, name="attention_mask"),
"token_type_ids": tf.TensorSpec((None, None, None), tf.int64, name="token_type_ids"), "token_type_ids": tf.TensorSpec((None, None, None), tf.int32, name="token_type_ids"),
} }
] ]
) )
......
...@@ -434,8 +434,8 @@ class TFDistilBertPreTrainedModel(TFPreTrainedModel): ...@@ -434,8 +434,8 @@ class TFDistilBertPreTrainedModel(TFPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
...@@ -898,7 +898,7 @@ class TFDistilBertForMultipleChoice(TFDistilBertPreTrainedModel, TFMultipleChoic ...@@ -898,7 +898,7 @@ class TFDistilBertForMultipleChoice(TFDistilBertPreTrainedModel, TFMultipleChoic
Returns: Returns:
tf.Tensor with dummy inputs tf.Tensor with dummy inputs
""" """
return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS)} return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32)}
@unpack_inputs @unpack_inputs
@add_start_docstrings_to_model_forward( @add_start_docstrings_to_model_forward(
......
...@@ -376,8 +376,8 @@ class TFDPRPretrainedReader(TFPreTrainedModel): ...@@ -376,8 +376,8 @@ class TFDPRPretrainedReader(TFPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
......
...@@ -613,7 +613,7 @@ class TFElectraPreTrainedModel(TFPreTrainedModel): ...@@ -613,7 +613,7 @@ class TFElectraPreTrainedModel(TFPreTrainedModel):
Returns: Returns:
`Dict[str, tf.Tensor]`: The dummy inputs. `Dict[str, tf.Tensor]`: The dummy inputs.
""" """
dummy = {"input_ids": tf.constant(DUMMY_INPUTS)} dummy = {"input_ids": tf.constant(DUMMY_INPUTS, dtype=tf.int32)}
# Add `encoder_hidden_states` to make the cross-attention layers' weights initialized # Add `encoder_hidden_states` to make the cross-attention layers' weights initialized
if self.config.add_cross_attention: if self.config.add_cross_attention:
batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape
...@@ -1375,7 +1375,7 @@ class TFElectraForMultipleChoice(TFElectraPreTrainedModel, TFMultipleChoiceLoss) ...@@ -1375,7 +1375,7 @@ class TFElectraForMultipleChoice(TFElectraPreTrainedModel, TFMultipleChoiceLoss)
Returns: Returns:
tf.Tensor with dummy inputs tf.Tensor with dummy inputs
""" """
return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS)} return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32)}
@unpack_inputs @unpack_inputs
@add_start_docstrings_to_model_forward(ELECTRA_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length")) @add_start_docstrings_to_model_forward(ELECTRA_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
......
...@@ -271,7 +271,7 @@ class TFEncoderDecoderModel(TFPreTrainedModel, TFCausalLanguageModelingLoss): ...@@ -271,7 +271,7 @@ class TFEncoderDecoderModel(TFPreTrainedModel, TFCausalLanguageModelingLoss):
`Dict[str, tf.Tensor]`: The dummy inputs. `Dict[str, tf.Tensor]`: The dummy inputs.
""" """
# Add `decoder_input_ids` because `self.decoder` requires it. # Add `decoder_input_ids` because `self.decoder` requires it.
input_ids = tf.constant(DUMMY_INPUTS) input_ids = tf.constant(DUMMY_INPUTS, dtype=tf.int32)
dummy = {"input_ids": input_ids, "decoder_input_ids": input_ids} dummy = {"input_ids": input_ids, "decoder_input_ids": input_ids}
return dummy return dummy
......
...@@ -981,8 +981,8 @@ class TFEsmModel(TFEsmPreTrainedModel): ...@@ -981,8 +981,8 @@ class TFEsmModel(TFEsmPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
...@@ -1113,8 +1113,8 @@ class TFEsmForMaskedLM(TFEsmPreTrainedModel, TFMaskedLanguageModelingLoss): ...@@ -1113,8 +1113,8 @@ class TFEsmForMaskedLM(TFEsmPreTrainedModel, TFMaskedLanguageModelingLoss):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
...@@ -1247,8 +1247,8 @@ class TFEsmForSequenceClassification(TFEsmPreTrainedModel, TFSequenceClassificat ...@@ -1247,8 +1247,8 @@ class TFEsmForSequenceClassification(TFEsmPreTrainedModel, TFSequenceClassificat
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
...@@ -1344,8 +1344,8 @@ class TFEsmForTokenClassification(TFEsmPreTrainedModel, TFTokenClassificationLos ...@@ -1344,8 +1344,8 @@ class TFEsmForTokenClassification(TFEsmPreTrainedModel, TFTokenClassificationLos
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
......
...@@ -226,13 +226,13 @@ class TFFlaubertPreTrainedModel(TFPreTrainedModel): ...@@ -226,13 +226,13 @@ class TFFlaubertPreTrainedModel(TFPreTrainedModel):
@property @property
def dummy_inputs(self): def dummy_inputs(self):
# Sometimes Flaubert has language embeddings so don't forget to build them as well if needed # Sometimes Flaubert has language embeddings so don't forget to build them as well if needed
inputs_list = tf.constant([[7, 6, 0, 0, 1], [1, 2, 3, 0, 0], [0, 0, 0, 4, 5]]) inputs_list = tf.constant([[7, 6, 0, 0, 1], [1, 2, 3, 0, 0], [0, 0, 0, 4, 5]], dtype=tf.int32)
attns_list = tf.constant([[1, 1, 0, 0, 1], [1, 1, 1, 0, 0], [1, 0, 0, 1, 1]]) attns_list = tf.constant([[1, 1, 0, 0, 1], [1, 1, 1, 0, 0], [1, 0, 0, 1, 1]], dtype=tf.int32)
if self.config.use_lang_emb and self.config.n_langs > 1: if self.config.use_lang_emb and self.config.n_langs > 1:
return { return {
"input_ids": inputs_list, "input_ids": inputs_list,
"attention_mask": attns_list, "attention_mask": attns_list,
"langs": tf.constant([[1, 1, 0, 0, 1], [1, 1, 1, 0, 0], [1, 0, 0, 1, 1]]), "langs": tf.constant([[1, 1, 0, 0, 1], [1, 1, 1, 0, 0], [1, 0, 0, 1, 1]], dtype=tf.int32),
} }
else: else:
return {"input_ids": inputs_list, "attention_mask": attns_list} return {"input_ids": inputs_list, "attention_mask": attns_list}
...@@ -1169,12 +1169,12 @@ class TFFlaubertForMultipleChoice(TFFlaubertPreTrainedModel, TFMultipleChoiceLos ...@@ -1169,12 +1169,12 @@ class TFFlaubertForMultipleChoice(TFFlaubertPreTrainedModel, TFMultipleChoiceLos
# Sometimes Flaubert has language embeddings so don't forget to build them as well if needed # Sometimes Flaubert has language embeddings so don't forget to build them as well if needed
if self.config.use_lang_emb and self.config.n_langs > 1: if self.config.use_lang_emb and self.config.n_langs > 1:
return { return {
"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS), "input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32),
"langs": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS), "langs": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32),
} }
else: else:
return { return {
"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS), "input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32),
} }
@unpack_inputs @unpack_inputs
......
...@@ -1446,7 +1446,7 @@ class TFFunnelForMultipleChoice(TFFunnelPreTrainedModel, TFMultipleChoiceLoss): ...@@ -1446,7 +1446,7 @@ class TFFunnelForMultipleChoice(TFFunnelPreTrainedModel, TFMultipleChoiceLoss):
Returns: Returns:
tf.Tensor with dummy inputs tf.Tensor with dummy inputs
""" """
return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS)} return {"input_ids": tf.constant(MULTIPLE_CHOICE_DUMMY_INPUTS, dtype=tf.int32)}
@unpack_inputs @unpack_inputs
@add_start_docstrings_to_model_forward(FUNNEL_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length")) @add_start_docstrings_to_model_forward(FUNNEL_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
...@@ -1521,9 +1521,9 @@ class TFFunnelForMultipleChoice(TFFunnelPreTrainedModel, TFMultipleChoiceLoss): ...@@ -1521,9 +1521,9 @@ class TFFunnelForMultipleChoice(TFFunnelPreTrainedModel, TFMultipleChoiceLoss):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.float32, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.float32, name="attention_mask"),
"token_type_ids": tf.TensorSpec((None, None), tf.int64, name="token_type_ids"), "token_type_ids": tf.TensorSpec((None, None), tf.int32, name="token_type_ids"),
} }
] ]
) )
......
...@@ -545,7 +545,7 @@ class TFGPT2PreTrainedModel(TFPreTrainedModel): ...@@ -545,7 +545,7 @@ class TFGPT2PreTrainedModel(TFPreTrainedModel):
Returns: Returns:
`Dict[str, tf.Tensor]`: The dummy inputs. `Dict[str, tf.Tensor]`: The dummy inputs.
""" """
dummy = {"input_ids": tf.constant(DUMMY_INPUTS)} dummy = {"input_ids": tf.constant(DUMMY_INPUTS, dtype=tf.int32)}
# Add `encoder_hidden_states` to make the cross-attention layers' weights initialized # Add `encoder_hidden_states` to make the cross-attention layers' weights initialized
if self.config.add_cross_attention: if self.config.add_cross_attention:
batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape batch_size, seq_len = tf.constant(DUMMY_INPUTS).shape
...@@ -558,8 +558,8 @@ class TFGPT2PreTrainedModel(TFPreTrainedModel): ...@@ -558,8 +558,8 @@ class TFGPT2PreTrainedModel(TFPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
......
...@@ -531,14 +531,14 @@ class TFGPTJPreTrainedModel(TFPreTrainedModel): ...@@ -531,14 +531,14 @@ class TFGPTJPreTrainedModel(TFPreTrainedModel):
Returns: Returns:
`Dict[str, tf.Tensor]`: The dummy inputs. `Dict[str, tf.Tensor]`: The dummy inputs.
""" """
dummy = {"input_ids": tf.constant(DUMMY_INPUTS)} dummy = {"input_ids": tf.constant(DUMMY_INPUTS, dtype=tf.int32)}
return dummy return dummy
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
......
...@@ -1640,8 +1640,8 @@ class TFGroupViTTextModel(TFGroupViTPreTrainedModel): ...@@ -1640,8 +1640,8 @@ class TFGroupViTTextModel(TFGroupViTPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
...@@ -1828,9 +1828,9 @@ class TFGroupViTModel(TFGroupViTPreTrainedModel): ...@@ -1828,9 +1828,9 @@ class TFGroupViTModel(TFGroupViTPreTrainedModel):
@tf.function( @tf.function(
input_signature=[ input_signature=[
{ {
"input_ids": tf.TensorSpec((None, None), tf.int64, name="input_ids"), "input_ids": tf.TensorSpec((None, None), tf.int32, name="input_ids"),
"pixel_values": tf.TensorSpec((None, None, None, None), tf.float64, name="pixel_values"), "pixel_values": tf.TensorSpec((None, None, None, None), tf.float64, name="pixel_values"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
} }
] ]
) )
......
...@@ -1312,8 +1312,8 @@ class TFHubertPreTrainedModel(TFPreTrainedModel): ...@@ -1312,8 +1312,8 @@ class TFHubertPreTrainedModel(TFPreTrainedModel):
input_signature=[ input_signature=[
{ {
"input_values": tf.TensorSpec((None, None), tf.float32, name="input_values"), "input_values": tf.TensorSpec((None, None), tf.float32, name="input_values"),
"attention_mask": tf.TensorSpec((None, None), tf.int64, name="attention_mask"), "attention_mask": tf.TensorSpec((None, None), tf.int32, name="attention_mask"),
"token_type_ids": tf.TensorSpec((None, None), tf.int64, name="token_type_ids"), "token_type_ids": tf.TensorSpec((None, None), tf.int32, name="token_type_ids"),
} }
] ]
) )
......
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