Problem
After fine-tuning FunctionGemma 270M using the official cookbook notebook, the model outputs a different format than the base (non-fine-tuned) model.
Base model output (correct):
<start_function_call>call:change_background_color{color:<escape>red<escape>}<end_function_call>
Fine-tuned model output (incorrect):
<start_function_call>change_background_color{color:{description:<escape>red<escape>}}<end_function_call>
Issues:
- Missing
call: prefix before function name
- Wrong parameter format (
{description:<escape>value<escape>} instead of <escape>value<escape>)
Context
We're building a Flutter plugin (flutter_gemma) that runs FunctionGemma on mobile devices via MediaPipe. The parser expects the official Google FunctionGemma format as documented at https://huggingface.co/google/functiongemma-270m-it
Steps to Reproduce
- Fine-tune FunctionGemma using the cookbook:
[FunctionGemma]Finetune_FunctionGemma_270M_for_Mobile_Actions_with_Hugging_Face.ipynb
- Convert to TFLite and bundle as .task
- Run inference on mobile device
- Observe output format differs from base model
Root Cause Hypothesis
The cookbook uses HuggingFace's apply_chat_template() for formatting training data:
prompt_and_completion = tokenizer.apply_chat_template(
template_inputs['messages'],
tools=template_inputs['tools'],
tokenize=False,
)
This produces a format that differs from the native FunctionGemma format. When the model is fine-tuned on this format, it "forgets" the original format.
Workaround
We created our own fine-tuning notebook that manually formats training data in the exact Google FunctionGemma format:
https://github.com/DenisovAV/flutter_gemma/blob/main/colabs/functiongemma_finetuning.ipynb
Questions
- Is
apply_chat_template() supposed to produce the same format as the base model's native output?
- Should the cookbook be updated to use manual formatting to preserve the native format?
- Is there a recommended way to fine-tune FunctionGemma while preserving the exact output format?
Environment
- FunctionGemma: google/functiongemma-270m-it
- Transformers: 4.57.3
- TRL: 0.26.2
- Platform: iOS/Android via MediaPipe
Problem
After fine-tuning FunctionGemma 270M using the official cookbook notebook, the model outputs a different format than the base (non-fine-tuned) model.
Base model output (correct):
Fine-tuned model output (incorrect):
Issues:
call:prefix before function name{description:<escape>value<escape>}instead of<escape>value<escape>)Context
We're building a Flutter plugin (flutter_gemma) that runs FunctionGemma on mobile devices via MediaPipe. The parser expects the official Google FunctionGemma format as documented at https://huggingface.co/google/functiongemma-270m-it
Steps to Reproduce
[FunctionGemma]Finetune_FunctionGemma_270M_for_Mobile_Actions_with_Hugging_Face.ipynbRoot Cause Hypothesis
The cookbook uses HuggingFace's
apply_chat_template()for formatting training data:This produces a format that differs from the native FunctionGemma format. When the model is fine-tuned on this format, it "forgets" the original format.
Workaround
We created our own fine-tuning notebook that manually formats training data in the exact Google FunctionGemma format:
https://github.com/DenisovAV/flutter_gemma/blob/main/colabs/functiongemma_finetuning.ipynb
Questions
apply_chat_template()supposed to produce the same format as the base model's native output?Environment