-
Notifications
You must be signed in to change notification settings - Fork 25.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving TFVisionEncoderDecoderModel as SavedModel: The following keyword arguments are not supported by this model: ['attention_mask', 'token_type_ids'].
#22731
Comments
cc @ydshieh |
Hi @DevinTDHa Just a quick update: instead of "pixel_values": tf.TensorSpec((None, None, None, None), tf.float32, name="pixel_values"),
"decoder_input_ids": tf.TensorSpec((None, None), tf.int32, name="decoder_input_ids"), This change will fix the issue you mentioned, but the saving is still not working due to other problems - I am still looking how to fix them. |
Two extra steps to make the saving working are:
You can do these changes in your own fork if you want to proceed quickly. I will discuss the team about the fix in our codebase. |
Thanks a lot, especially for the suggested edits! |
In fact, what I did that works is I added the following block for the class @tf.function(
input_signature=[
{
"pixel_values": tf.TensorSpec((None, None, None, None), tf.float32, name="pixel_values"),
"decoder_input_ids": tf.TensorSpec((None, None), tf.int32, name="decoder_input_ids"),
}
]
)
def serving(self, inputs):
"""
Method used for serving the model.
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) I am not sure why using the approach in your notebook doesn't work (i.e. by specifying |
The fixes have been merged to the I will discuss with our TF experts regarding why specifying |
Hi @Rocketknight1 Since you are a TF saving expert 🔥 , could you take a look on the code snippet below, and see why it doesn't work when we specify (You have to pull Thank you in advanceeeeeeee ~ import tensorflow as tf
from transformers import TFVisionEncoderDecoderModel
# load a fine-tuned image captioning model and corresponding tokenizer and image processor
MODEL_NAME = "nlpconnect/vit-gpt2-image-captioning"
model = TFVisionEncoderDecoderModel.from_pretrained(MODEL_NAME, from_pt=True)
EXPORT_PATH = f"exports/{MODEL_NAME}"
# ========================================================================================================================
# This works
# Add this block to `TFVisionEncoderDecoderModel` in `src/transformers/models/vision_encoder_decoder/modeling_tf_vision_encoder_decoder.py`
"""
@tf.function(
input_signature=[
{
"pixel_values": tf.TensorSpec((None, None, None, None), tf.float32, name="pixel_values"),
"decoder_input_ids": tf.TensorSpec((None, None), tf.int32, name="decoder_input_ids"),
}
]
)
def serving(self, inputs):
output = self.call(inputs)
return self.serving_output(output)
"""
#model.save_pretrained(
# EXPORT_PATH,
# saved_model=True,
# # signatures={"serving_default": my_serving_fn},
#)
# ========================================================================================================================
# Not working (without changing `TFVisionEncoderDecoderModel`)
@tf.function(
input_signature=[
{
"pixel_values": tf.TensorSpec((None, None, None, None), tf.float32, name="pixel_values"),
"decoder_input_ids": tf.TensorSpec((None, None), tf.int32, name="decoder_input_ids"),
}
]
)
def my_serving_fn(inputs):
output = model.call(inputs)
return model.serving_output(output)
# This fails
model.save_pretrained(
EXPORT_PATH,
saved_model=True,
signatures={"serving_default": my_serving_fn},
)
# ======================================================================================================================== |
@ydshieh I have a question regarding this actually: Currently I'm trying to access the decoder (GPT-2) from the saved model but it seems to my knowledge that it is not possible. The default serving signature you suggested outputs the encoder (ViT) outputs only (or am I wrong in this regard?) However, trying to create a serving for the |
I believe it gives the outputs of both the encoder and decoder. But if you find it is not the case, please open a new issue and we are more than happy to look into it 🤗 .
|
System Info
transformers
version: 4.27.4Who can help?
@gante Could be related to #16400?
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
Hello,
I am trying to save a TFVisionEncoderDecoderModel in a SavedModel format. Specifically, I am using the
nlpconnect/vit-gpt2-image-captioning
pretrained model. It seems like the model is able to be intiallised from the PyTorch checkpoint. However, when trying to save it as a SavedModel, it fails with the error.Link to Google Colab Reproduction:
https://colab.research.google.com/drive/1N2TVejxiBT5S7bRJ2LSmJ8IIR45folGA#scrollTo=aIL92KqPDDjf
Thanks for your time!
Expected behavior
The model should be saved as a SavedModel without problems, similarly to other pretrained models.
The text was updated successfully, but these errors were encountered: