TFTRT Convert using trt.TrtGraphConverterV2 failed due to “Attribute _tftrt_convert_function was not found”
@Weili17,
In order to expedite the trouble-shooting process, could you please provide a complete code you are using, it helps to analyse the issue in an effective way. Thank you!
 > @Weili17, In order to expedite the trouble-shooting process, could you please provide a complete code you are using, it helps to analyse the issue in an effective way. Thank you!

Thanks for your reply. I use the trt converter api to optimize my saved model, but when I test the converted model, found out there is no performance(latency) gain when predict. So I print the tf log and found that the conversion process failed with the log “Attribute _tftrt_convert_function was not found”, but I don't know what to do in next step.

This is my code.

from __future__ import absolute_import, division, print_function, unicode_literals

import numpy as np
import matplotlib.pyplot as plt

import tensorflow as tf
from tensorflow import keras
from tensorflow.python.compiler.tensorrt import trt_convert as trt
from tensorflow.python.saved_model import tag_constants

conversion_params = trt.DEFAULT_TRT_CONVERSION_PARAMS._replace(
                                                               precision_mode=trt.TrtPrecisionMode.FP32,
                                                               max_workspace_size_bytes=2000000000,
                                                               minimum_segment_size= 50)

converter = trt.TrtGraphConverterV2(input_saved_model_dir='my_saved_model',
                                    input_saved_model_signature_key='serving_default',
                                    conversion_params=conversion_params)
converter.convert()
converter.save(output_saved_model_dir='tftrt_saved_model')
print('Done Converting to TF-TRT FP32') @Weili17,
I was facing a different error while executing the mentioned code. Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/e430fae8f49dc675986f8bdeed4cdb68/untitled1076.ipynb) and provide the colab gist with the reported error. 

The converter takes a SavedModel as input, and processes it:

1. Load the SavedModel using **tf.saved_model.load**.
2. Extract the default serving signature from the .signatures map.
3. Run a grappler optimization pass on the signature function. This returns a GraphDef.
4. Create a new ConcreteFunction by importing the GraphDef with wrap_function.
6. Save a new SavedModel using tf.saved_model.save, with the converted signature function as the default serving signature.
`A note about the input: `the input SavedModel's default signature function must be labeled with a specific **attribute (_tftrt_convert_function),** otherwise the optimization will not run. 

Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Closing this as stale. Please reopen if this is still a valid request. Thank you! Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60185">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60185">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

tf2.8.0

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

3.10.6

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

11.6/8

### GPU model and memory

_No response_

### Current Behaviour?

```shell
A bug happened!
```


### Standalone code to reproduce the issue

```shell
convert my custom model using trt.TrtGraphConverterV2. There is no benefit in comparing the performance before and after conversion. Inspect the tf log, found that the conversion actually failed with the log “Attribute _tftrt_convert_function was not found”
```


### Relevant log output

```shell
2023-03-31 15:29:29.663291: I tensorflow/compiler/tf2tensorrt/convert/trt_optimization_pass.cc:167] Attribute _tftrt_convert_function was not found.
2023-03-31 15:29:29.663297: I tensorflow/compiler/tf2tensorrt/convert/trt_optimization_pass.cc:375] Not optimizing this grappler item: TRTEngineOp_0_2_native_segment
```
</details>