huggingface / tflite-android-transformers

DistilBERT / GPT-2 for on-device inference thanks to TensorFlow Lite with Android demo apps
Apache License 2.0
389 stars 79 forks source link

New method to set shape of model inputs #8

Open fuzhenxin opened 4 years ago

fuzhenxin commented 4 years ago

For tensorflow>=2.2.0, the model._set_inputs failed in https://github.com/huggingface/tflite-android-transformers/blob/dcd6da1bfb28e3cd6bc83b58a112cdcd3d6cc2fe/models_generation/gpt2.py#L7 , and the model.inputs and model.outpus are all None. The following error will happen when running in Android: java.lang.IllegalStateException: Internal error: Unexpected failure when preparing tensor allocations: tensorflow/lite/kernels/kernel_util.cc:249 d1 == d2 || d1 == 1 || d2 == 1 was not true. For tensorflow<=2.1.0, the error will not happen.

The added code set inputs shape of model by adding an additional layer, and it works for both tensorflow>=2.2 and tensorflow<2.2

jipson7 commented 4 years ago

Thank you. Can confirm this is working and necessary in TF >=2.2