Cannot convert RoBERTa to tflite model
See original GitHub issue🐛 Bug
Information
Model I am using: RoBERTa (roberta-base)
Language I am using the model on: English
The problem arises when using: Conversion based on https://github.com/huggingface/tflite-android-transformers/blob/master/models_generation/distilbert.py
The tasks I am working on is: It is irrelevant on this step.
To reproduce
- Build python conversion script.
- Run it.
Conversion script
import tensorflow as tf
from transformers import TFRobertaForSequenceClassification
model = TFRobertaForSequenceClassification.from_pretrained('roberta-base')
input_spec = tf.TensorSpec([1, 384], tf.int32)
model._set_inputs(input_spec, training=False)
converter = tf.lite.TFLiteConverter.from_keras_model(model)
# For conversion with hybrid quantization:
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
converter.experimental_new_converter = True
tflite_model = converter.convert()
open("test.tflite", "wb").write(tflite_model)
Error: tf.Cumsum op is neither a custom op nor a flex op and needs a custom implementation
Expected behavior
No errors.
Environment info
- Transformers version: 2.8.0
- Platform: Windows 10
- Python version: 3.7.0
- Tensorflow version: 2.1.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Why is my tensorflow Roberta Model unable to train/finetune?
I have tokenized the sentences, however I can't convert it to a tf.dataset using the following code: ` features= ['OptionA', 'OptionB', 'OptionC ...
Read more >Model conversion overview | TensorFlow Lite
The diagram below shows the high level steps in converting a model. TFLite conversion workflow. Figure 1. TensorFlow Lite conversion ...
Read more >RoBERTa - Hugging Face
The RoBERTa model was proposed in RoBERTa: A Robustly Optimized BERT ... RoBERTa has the same architecture as BERT, but uses a byte-level...
Read more >TFLite BERT: DataType error: cannot resolve ... - Google Groups
It will be helpful if you can attach your conversion script, the tflite model, and your inference code. From the error message, it...
Read more >Training RoBERTa from scratch - the missing guide
At this point, I've decided to go with RoBERTa model. ... If you're changing the input dataset, you cannot use existing scheduler.pt and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Pierrci thanks! It also seems to be have been solved in the latest release of
tf-nightly
: https://github.com/tensorflow/tensorflow/issues/42382#issuecomment-675000451I believe this is because
tf.Cumsum
is not a supported operation and not an issue relating to this repo. Here is a link to the tensorflow documentation on supported ops. [https://www.tensorflow.org/lite/guide/ops_compatibility] In the past, I’ve been able to get around unsupported ops by reimplementing the operator with supported ops or replacing the unsupported portion with another op. ie.relu
in place ofgelu
.