Fine-Tuning FunctionGemma on TPU to Create a Virtual Fitness Coach in 10 Minutes, $0.50
tengomucho
• • 13How to use tengomucho/functiongemma-fitness-coach with Transformers:
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("tengomucho/functiongemma-fitness-coach", dtype="auto")A LoRA adapter for google/functiongemma-270m-it fine-tuned on the tengomucho/fitness-coach-function-calling dataset to enable accurate function calling for fitness and health-related queries.
This is a parameter-efficient fine-tuned version of Google's FunctionGemma-270M-it model, specialized for mapping natural language fitness queries to function calls. The model uses LoRA (Low-Rank Adaptation) to add only ~8M trainable parameters on top of the 270M base model.
The model is trained to handle the following fitness-related function calls:
get_steps() - Retrieve today's step countget_daily_step_goal() - Get the user's daily step goalget_goal_progress() - Calculate progress toward step goalget_sleeping_minutes() - Get sleep durationget_active_minutes() - Get active minutes countget_heart_rate() - Get current heart rateget_body_battery_level() - Get body battery level (energy/fatigue indicator)The model was fine-tuned on tengomucho/fitness-coach-function-calling, a synthetic dataset containing:
Dataset split:
LoraConfig(
r=32,
lora_alpha=64,
lora_dropout=0.05,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
task_type="CAUSAL_LM"
)
xla_fsdp_grad_ckptpip install transformers peft torch
import peft # This import will enable automatic loading from adapters
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model
model = AutoModelForCausalLM.from_pretrained("tengomucho/functiongemma-fitness-coach")
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("google/functiongemma-270m-it")
import json
# Define your fitness functions
tools = [
{
"type": "function",
"function": {
"name": "get_steps",
"description": "Get the number of steps taken today",
"parameters": {"type": "object", "properties": {}}
}
},
{
"type": "function",
"function": {
"name": "get_heart_rate",
"description": "Get the current heart rate",
"parameters": {"type": "object", "properties": {}}
}
}
# ... add other functions
]
# Create conversation
messages = [
{
"role": "developer",
"content": "You are a fitness coach assistant that helps users track their health and fitness data."
},
{
"role": "user",
"content": "How many steps have I taken today?"
}
]
# Format input
input_text = tokenizer.apply_chat_template(
messages,
tools=tools,
tokenize=False,
add_generation_prompt=True
)
# Generate
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
# Expected output: {"name": "get_steps", "arguments": {}}