Converting Transformers model to Tensorflow model
I am trying to convert dbmdz/bert-base-turkish-uncased to tensorflow model (.pb). It contains tf_model.h5 file.
I tried to convert from tf_model.h5 to tensorflow model. However, I couldn't handle it. Is tf_model.h5 file keras model, isn’t it?
Is there any instruction to convert huggingface non-tf models to tensorflow model(.pb)?
I don't believe we have a way of converting keras models from .h5 to .pb. What is your use case, so that we can see if we may help further?
I want to improve the inference performance. I fine-tuned the pretrained model (dbmdz/bert-base-turkish-uncased). TensorRT can be helpful to reduce inference time. Use case is converting Keras model to TensorRT model. How can I achieve this?
P.S.: I am open to any advice. Tensorflow Lite or other things can be used. I just need some guidance.
@mfuntowicz I believe you have experience with using TensorRT with the transformers models. Do you have any idea of how to enable this?
You can try a couple of ways :
- Keras -> Onnx -> TensorRT : You can use keras2onnx . You might have some operations that are not directly supported in onnx so you'll have to remove/edit those operations to convertible terms. Converting onnx to TRT can be done with a tool called "trtexec" or there are readymade scripts to do that. Do check model graph and accuracy at every step.
- Keras -> Frozen graph(.pb) -> onnx -> TensorRT
You can also use TF-TRT which again optimizes but less optimized than TensorRT.
There is another way you can explore Keras -> UFF -> TensorRT .
Thank you for leading @zerocool95
i also face this problem, and i find a exits onnx file on onnx github, and it said it was transfered from huggingface, but when i use trtexec to covert onnx ---> trt . it say it don;'t support some ops like 'NoZero'