question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Build python conversion script.
  2. 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dshahrokhiancommented, Dec 1, 2020

@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-675000451

2reactions
will-ricecommented, Apr 20, 2020

I 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 of gelu.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found