How to use model.save() in tf2 when using TFBertModel
Author: leisurehippo
Pull request: no

tensorflow==2.3.1

transformers==4.2.1

My model define as:
```
import tensorflow as tf
from tensorflow.keras import Model 
from tensorflow.keras.layers import *
from transformers import TFAutoModel

input_ids = Input(shape=(3000), name='INPUT_input_ids', dtype=tf.int32)
input_mask = Input(shape=(3000), name='INPUT_input_mask', dtype=tf.int32)
segment_ids = Input(shape=(3000), name='INPUT_segment_ids', dtype=tf.int32)
passage_mask = Input(shape=(10), name='INPUT_passage_mask', dtype=tf.int32)
input_ids_reshape = K.reshape(input_ids,(-1, 300))
input_mask_reshape = K.reshape(input_mask,(-1, 300))
segment_ids_reshape = K.reshape(segment_ids,(-1, 300))
transformer = TFAutoModel.from_pretrained('hfl/chinese-roberta-wwm-ext', from_pt=False)
transformer_output = transformer([input_ids_reshape, input_mask_reshape, segment_ids_reshape])[0]
......
model = Model(
    inputs  = [input_ids, input_mask, segment_ids, passage_mask], 
    outputs = [start_prob, end_prob]
)
```
I try to save model in this way:
```
model.save(path)
```
but I got error
```
/lib/python3.6/site-packages/transformers/modeling_tf_utils.py in input_processing(func, config, input_ids, **kwargs)
    364                     output[tensor_name] = input
    365                 else:
--> 366                     output[parameter_names[i]] = input
    367             elif isinstance(input, allowed_types) or input is None:
    368                 output[parameter_names[i]] = input

IndexError: list index out of range
```
model.predict() and model.save_weights() is working.

How to use model.save() with huggingface-transformers? OR How to write model with huggingface-transformers? I just want to use transformers as a keras layer in my model.

Comments:
Hi @leisurehippo , not all of our models work well with `model.save()`. If you want to get a SavedModel output, please try the `model.save_pretrained()` method with `saved_model=True`. You can see more about that method [here](https://huggingface.co/transformers/main_classes/model.html#transformers.TFPreTrainedModel.save_pretrained).

If you still encounter the same problem when using `save_pretrained`, let me know and I'll try to reproduce the issue.

> Hi @leisurehippo , not all of our models work well with `model.save()`. If you want to get a SavedModel output, please try the `model.save_pretrained()` method with `saved_model=True`. You can see more about that method [here](https://huggingface.co/transformers/main_classes/model.html#transformers.TFPreTrainedModel.save_pretrained).
> 
> If you still encounter the same problem when using `save_pretrained`, let me know and I'll try to reproduce the issue.

I try to save in this way:
```
model.save_pretrained(path,saved_model=True)
```
But I got error
```
AttributeError: 'Functional' object has no attribute 'save_pretrained'
```

> Hi @leisurehippo , not all of our models work well with `model.save()`. If you want to get a SavedModel output, please try the `model.save_pretrained()` method with `saved_model=True`. You can see more about that method [here](https://huggingface.co/transformers/main_classes/model.html#transformers.TFPreTrainedModel.save_pretrained).
> 
> If you still encounter the same problem when using `save_pretrained`, let me know and I'll try to reproduce the issue.

 I try to save with SavedModelBuilder class in this way:
```
signature = tf.compat.v1.saved_model.predict_signature_def(
    inputs={t.name: t for t in model.inputs}, 
    outputs={t.name: t for t in model.output}
)
builder = tf.compat.v1.saved_model.Builder(export_path)
builder.add_meta_graph_and_variables(
    sess=tf.compat.v1.keras.backend.get_session(),
    tags=[tf.compat.v1.saved_model.tag_constants.SERVING],
    signature_def_map = {'predict':signature},)
builder.save()
```
But it seems that the session is not the one in my model, and the .pb file is very small

> > 嗨@leisurehippo，并非我们所有的模型都能很好地与`model.save()`. 如果您想获得 SavedModel 输出，请尝试`model.save_pretrained()`使用`saved_model=True`. 您可以[在此处](https://huggingface.co/transformers/main_classes/model.html#transformers.TFPreTrainedModel.save_pretrained)查看有关该方法的更多信息。
> > 如果您在使用时仍然遇到同样的问题`save_pretrained`，请告诉我，我会尝试重现该问题。
> 
> 我尝试以这种方式使用 SavedModelBuilder 类进行保存：
> 
> ```
> signature = tf.compat.v1.saved_model.predict_signature_def(
>     inputs={t.name: t for t in model.inputs}, 
>     outputs={t.name: t for t in model.output}
> )
> builder = tf.compat.v1.saved_model.Builder(export_path)
> builder.add_meta_graph_and_variables(
>     sess=tf.compat.v1.keras.backend.get_session(),
>     tags=[tf.compat.v1.saved_model.tag_constants.SERVING],
>     signature_def_map = {'predict':signature},)
> builder.save()
> ```
> 
> 但是好像session不是我模型里的那个，.pb文件很小

hi, do you fix this problem? and how? thx.

I have the same problem? how to fix?