Cannot export tflite using optimum for a fine-tuned gemma 3 model for task : question answering

python3 -m optimum.commands.optimum_cli export tflite --model merged_gemma3_aie_finetuned_hf --task question-answering --sequence_length 1024 gemma_tflite/

we are using this command but the error we are facing is transformer doesnt recognize gemma 3 text config.

1 Like

Gemma 3 is maybe not yet supported except for the dev versions of Transformers and optimum, which can be installed from the github source.

I think that the conversion itself can be done by installing these dev versions, but I think there would be still a lot of problems.

If you have any questions about ONNX, the best way to get a reliable answer is to contact the ONNX Community within Hugging Face.

pip uninstall transformers optimum
pip install git+https://github.com/huggingface/optimum git+https://github.com/huggingface/transformers

Thankyou for your response, i fine tuned a gemma 3 model and now i need to convert it into .tflite, what are all the ways to do it, i used the dev version of Transformers and optimum but still it throwing error like “Gemma3 Text config is not recognized by the transformer”.

What are all the ways to convert it?

And also if I convert it into onnx then can i convert into .tflite? if yes, how to convert it into onnx?

1 Like

this is the error i am getting

Traceback (most recent call last):
File “C:\Users\aiehy\OneDrive\Desktop\training1\tflite.py”, line 46, in
tf_model = TFAutoModelForCausalLM.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\aiehy\OneDrive\Desktop\training1.venv\Lib\site-packages\transformers\models\auto\auto_factory.py”, line 576, in from_pretrained
raise ValueError(
ValueError: Unrecognized configuration class <class ‘transformers.models.gemma3.configuration_gemma3.Gemma3TextConfig’> for this kind of AutoModel: TFAutoModelForCausalLM.
Model type should be one of BertConfig, CamembertConfig, CTRLConfig, GPT2Config, GPT2Config, GPTJConfig, MistralConfig, OpenAIGPTConfig, OPTConfig, RemBertConfig, RobertaConfig, RobertaPreLayerNormConfig, RoFormerConfig, TransfoXLConfig, XGLMConfig, XLMConfig, XLMRobertaConfig, XLNetConfig.

1 Like

Hmm…

or perhaps:

#python3 -m optimum.commands.optimum_cli export tflite --model merged_gemma3_aie_finetuned_hf --task question-answering --sequence_length 1024 gemma_tflite/
python3 -m optimum.commands.optimum_cli export tflite --model merged_gemma3_aie_finetuned_hf --task text-generation --sequence_length 1024 gemma_tflite/

transformers.models.gemma3.configuration_gemma3.Gemma3TextConfig

Oh…