huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
132.34k stars 26.36k forks source link

Any ideas on how we can convert a model from huggingface (transformers library )to tensorflow lite? #19908

Closed BENSAFOUAN-Abdelhalim closed 1 year ago

BENSAFOUAN-Abdelhalim commented 1 year ago

System Info

I want to convert CamembertQuestionAnsewring model to tensoflow lite, i download it from huggingface platform, because when i want to save the model locally it gives me the model with 'bin' format. i'm asking here because huggingface use pytorch pretrained models.

Who can help?

No response

Information

Tasks

Reproduction

when i try to convert the model it gives me this error : AttributeError: 'CamembertForQuestionAnswering' object has no attribute 'call' by using tf_model.h5 file. Also i can't load it using : tf.keras.models.load_model() it gives me : ValueError: No model config found in the file at <tensorflow.python.platform.gfile.GFile object at 0x7f27cceb1810>. when i want to save the transformers model locally it gives me the model with 'bin' format, so i download it from the platform.

Expected behavior

https://huggingface.co/etalab-ia/camembert-base-squadFR-fquad-piaf?context=Etalab+est+une+administration+publique+fran%C3%A7aise+qui+fait+notamment+office+de+Chief+Data+Officer+de+l%27%C3%89tat+et+coordonne+la+conception+et+la+mise+en+%C5%93uvre+de+sa+strat%C3%A9gie+dans+le+domaine+de+la+donn%C3%A9e+%28ouverture+et+partage+des+donn%C3%A9es+publiques+ou+open+data%2C+exploitation+des+donn%C3%A9es+et+intelligence+artificielle...%29.+Ainsi%2C+Etalab+d%C3%A9veloppe+et+maintient+le+portail+des+donn%C3%A9es+ouvertes+du+gouvernement+fran%C3%A7ais+data.gouv.fr.+Etalab+promeut+%C3%A9galement+une+plus+grande+ouverture+l%27administration+sur+la+soci%C3%A9t%C3%A9+%28gouvernement+ouvert%29+%3A+transparence+de+l%27action+publique%2C+innovation+ouverte%2C+participation+citoyenne...+elle+promeut+l%E2%80%99innovation%2C+l%E2%80%99exp%C3%A9rimentation%2C+les+m%C3%A9thodes+de+travail+ouvertes%2C+agiles+et+it%C3%A9ratives%2C+ainsi+que+les+synergies+avec+la+soci%C3%A9t%C3%A9+civile+pour+d%C3%A9cloisonner+l%E2%80%99administration+et+favoriser+l%E2%80%99adoption+des+meilleures+pratiques+professionnelles+dans+le+domaine+du+num%C3%A9rique.+%C3%80+ce+titre+elle+%C3%A9tudie+notamment+l%E2%80%99opportunit%C3%A9+de+recourir+%C3%A0+des+technologies+en+voie+de+maturation+issues+du+monde+de+la+recherche.+Cette+entit%C3%A9+charg%C3%A9e+de+l%27innovation+au+sein+de+l%27administration+doit+contribuer+%C3%A0+l%27am%C3%A9lioration+du+service+public+gr%C3%A2ce+au+num%C3%A9rique.+Elle+est+rattach%C3%A9e+%C3%A0+la+Direction+interminist%C3%A9rielle+du+num%C3%A9rique%2C+dont+les+missions+et+l%E2%80%99organisation+ont+%C3%A9t%C3%A9+fix%C3%A9es+par+le+d%C3%A9cret+du+30+octobre+2019.%E2%80%89+Dirig%C3%A9+par+Laure+Lucchesi+depuis+2016%2C+elle+rassemble+une+%C3%A9quipe+pluridisciplinaire+d%27une+trentaine+de+personnes.&question=Comment+s%27appelle+le+portail+open+data+du+gouvernement+%3F

LysandreJik commented 1 year ago

Maybe of interest to @gante @Rocketknight1

Rocketknight1 commented 1 year ago

Hi @BENSAFOUAN-Abdelhalim, CamembertForQuestionAnswering is a PyTorch model. The TF model is TFCamembertForQuestionAnswering. That's why you're seeing the missing methods on that model!

In general, though, we don't support TFLite conversions for all of our models. There are some operations that TFLite can't support, and we don't guarantee that everything in a model will work for it. However, you can absolutely try to convert it and see what you get!

BENSAFOUAN-Abdelhalim commented 1 year ago

ok, thanks @Rocketknight1 for your answer.

nyadla-sys commented 1 year ago

@BENSAFOUAN-Abdelhalim Refer this colab for more details on how to convert HF TF model to TFlite model https://colab.research.google.com/github/usefulsensors/openai-whisper/blob/main/notebooks/tflite_from_huggingface_whisper.ipynb

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.