Skip to content

FunctionGemma: Fine-tuned model outputs different format than base model #273

@DenisovAV

Description

@DenisovAV

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:

  1. Missing call: prefix before function name
  2. 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

  1. Fine-tune FunctionGemma using the cookbook: [FunctionGemma]Finetune_FunctionGemma_270M_for_Mobile_Actions_with_Hugging_Face.ipynb
  2. Convert to TFLite and bundle as .task
  3. Run inference on mobile device
  4. 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

  1. Is apply_chat_template() supposed to produce the same format as the base model's native output?
  2. Should the cookbook be updated to use manual formatting to preserve the native format?
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions