Skip to content
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

Cannot save TFTapasModel as SavedModel #18179

Closed
2 of 4 tasks
ahmedlone127 opened this issue Jul 18, 2022 · 1 comment
Closed
2 of 4 tasks

Cannot save TFTapasModel as SavedModel #18179

ahmedlone127 opened this issue Jul 18, 2022 · 1 comment
Labels

Comments

@ahmedlone127
Copy link

System Info

  • transformers version: 4.20.1
  • Platform: Linux-5.4.188+-x86_64-with-Ubuntu-18.04-bionic
  • Python version: 3.7.13
  • Huggingface_hub version: 0.8.1
  • PyTorch version (GPU?): 1.12.0+cu113 (True)
  • Tensorflow version (GPU?): 2.8.2 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No

Who can help?

@Rocketknight1 @gante

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction


from transformers import TapasTokenizer, TFTapasModel
import pandas as pd

tokenizer = TapasTokenizer.from_pretrained("google/tapas-base")
model = TFTapasModel.from_pretrained("google/tapas-base")

data = {
    "Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"],
    "Age": ["56", "45", "59"],
    "Number of movies": ["87", "53", "69"],
}
table = pd.DataFrame.from_dict(data)
queries = ["How many movies has George Clooney played in?", "How old is Brad Pitt?"]

inputs = tokenizer(table=table, queries=queries, padding="max_length", return_tensors="tf")
outputs = model(**inputs)

last_hidden_states = outputs.last_hidden_state

model.save_pretrained("test",saved_model=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-11-637c488e6341>](https://localhost:8080/#) in <module>()
----> 1 model.save_pretrained("test",saved_model=True)

2 frames
[/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py](https://localhost:8080/#) in autograph_handler(*args, **kwargs)
   1145           except Exception as e:  # pylint:disable=broad-except
   1146             if hasattr(e, "ag_error_metadata"):
-> 1147               raise e.ag_error_metadata.to_exception(e)
   1148             else:
   1149               raise

ValueError: in user code:

    File "/usr/local/lib/python3.7/dist-packages/transformers/modeling_tf_utils.py", line 806, in serving  *
        output = self.call(inputs)
    File "/usr/local/lib/python3.7/dist-packages/transformers/modeling_tf_utils.py", line 981, in run_call_with_unpacked_inputs  *
        return func(self, **unpacked_inputs)
    File "/usr/local/lib/python3.7/dist-packages/transformers/models/tapas/modeling_tf_tapas.py", line 1008, in call  *
        outputs = self.tapas(
    File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler  **
        raise e.with_traceback(filtered_tb) from None

    ValueError: Exception encountered when calling layer "tapas" (type TFTapasMainLayer).
    
    in user code:
    
        File "/usr/local/lib/python3.7/dist-packages/transformers/modeling_tf_utils.py", line 981, in run_call_with_unpacked_inputs  *
            return func(self, **unpacked_inputs)
        File "/usr/local/lib/python3.7/dist-packages/transformers/models/tapas/modeling_tf_tapas.py", line 790, in call  *
            embedding_output = self.embeddings(
        File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler  **
            raise e.with_traceback(filtered_tb) from None
    
        ValueError: Exception encountered when calling layer "embeddings" (type TFTapasEmbeddings).
        
        in user code:
        
            File "/usr/local/lib/python3.7/dist-packages/transformers/models/tapas/modeling_tf_tapas.py", line 223, in call  *
                col_index = IndexMap(token_type_ids[:, :, 1], self.type_vocab_sizes[1], batch_dims=1)
        
            ValueError: Index out of range using input dim 2; input has only 2 dims for '{{node tapas/embeddings/strided_slice_2}} = StridedSlice[Index=DT_INT32, T=DT_INT32, begin_mask=3, ellipsis_mask=0, end_mask=3, new_axis_mask=0, shrink_axis_mask=4](token_type_ids, tapas/embeddings/strided_slice_2/stack, tapas/embeddings/strided_slice_2/stack_1, tapas/embeddings/strided_slice_2/stack_2)' with input shapes: [?,?], [3], [3], [3] and with computed input tensors: input[3] = <1 1 1>.
        
        
        Call arguments received:
          • input_ids=tf.Tensor(shape=(None, None), dtype=int32)
          • position_ids=None
          • token_type_ids=tf.Tensor(shape=(None, None), dtype=int32)
          • inputs_embeds=None
          • training=False
    
    
    Call arguments received:
      • self=tf.Tensor(shape=(None, None), dtype=int32)
      • input_ids=None
      • attention_mask=tf.Tensor(shape=(None, None), dtype=int32)
      • token_type_ids=tf.Tensor(shape=(None, None), dtype=int32)
      • position_ids=None
      • head_mask=None
      • inputs_embeds=None
      • output_attentions=False
      • output_hidden_states=False
      • return_dict=True
      • training=False

Expected behavior

It is supposed to make a SavedModel but instead, I get this error mentioned above. The SavedModel is needed for TensorFlow Serving .

@amyeroberts
Copy link
Collaborator

Following merging of #18153 the reproduction snippet runs on main without error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants