FunctionGemma 的本地运行与函数调用微调
介绍谷歌基于 Gemma 3 的 270M 参数函数调用模型 FunctionGemma,说明其全精度可在 550MB 内存的 CPU 上运行,并可用 Unsloth 在本地微调,覆盖手机部署、移动操作与多轮工具调用等场景。
FunctionGemma是Google为功能调用和微调设计的一种新的270M参数模型. [Gemma 3 (英语).](<https://unsloth.ai/docs/models/tutorials/gemma-3-how-to-run-and-fine-tune>) 270M专为文本专用工具调用而训练,其体积小使得在自己的手机上部署非常棒. 你可以运行全精度模型 在 **550MB RAM (英语).** (CPU) 你现在可以了 **fine-tune** 在本地与Unsloth合作。 谢谢Google DeepMind 与Unsloth合作提供零天支持! [正在运行的教程](<https://unsloth.ai/docs/models/tutorials/functiongemma#run-functiongemma>)[微调 FunctionGemma](<https://unsloth.ai/docs/models/tutorials/functiongemma#fine-tuning-functiongemma>) - FunctionGemma GGUF 运行: [unsloth/functiongemma-270m-it-GGUF](<https://huggingface.co/unsloth/functiongemma-270m-it-GGUF>) **免费笔记本 :** - 微调到 **工具调用前的理由/思考** 使用我们的 [FunctionGemma 笔记本](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M).ipynb>) - 执行 **调用多回合工具** 免费 [多转动工具调用笔记本](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M)-Multi-Turn-Tool-Calling.ipynb>) - 微调到 **允许移动动作** (日历,设置计时器) 在我们 [移动动作笔记本](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M)-Mobile-Actions.ipynb>) ### 使用指南 Google 建议这些设置进行推论: - `top_k = 64` - `top_p = 0.95` - `temperature = 1.0` - 最大上下文长度 = `32,768` 聊天模板格式在使用下列时找到: ``` def get_today_date(): """ Gets today's date """ return {"today_date": "18 December 2025"} tokenizer.apply_chat_template( [ {"role" : "user", "content" : "what is today's date?"}, ], tools = [get_today_date], add_generation_prompt = True, tokenize = False, ) ``` #### FunctionGemma 聊天模板格式 : FunctionGemma 需要系统或 **开发者消息** 作为 `You are a model that can do function calling with the following functions` unsloth版本有这个预建的 如果你忘了通过一个,所以请使用 [unsloth/functiongemma-270m-it](<https://huggingface.co/unsloth/functiongemma-270m-it>) ## 运行 FunctionGemma 有关本地桌面指南,请见下文,或者您可以查看我们的电话部署指南。 #### Llama.cpp 教学(GGUF): 在 lama.cpp 中运行的指示(注意我们将使用 4 - bit 来适应大多数设备) : 1 获取最新数据 `llama.cpp` 打开 [这里的GitHub](<https://github.com/ggml-org/llama.cpp>)。也可以遵循下面的构建指令。更改 `-DGGML_CUDA=ON` 改为: `-DGGML_CUDA=OFF` 如果你没有GPU 或者只是想要CPU推论. **用于 Apple Mac / 金属设备**设置 `-DGGML_CUDA=OFF` 然后照常继续 - 金属支持默认在进行。 2 您可以直接从 Hugging Face 中拉动。 由于模型如此小, 我们将使用未量化的全精度 BF16 变体 。 3 通过(安装后)下载模型 `pip install huggingface_hub hf_transfer` 。您可以选择 `BF16` 或其他量化版本(虽然由于模型尺寸小,建议不低于4 -bit). 4 然后在对话模式下运行模型 : ## 电话部署 您也可以运行和部署 FunctionGemma 在您的手机上,因为它的大小很小。 我们与 PyTorch 合作,通过量化- 意识培训创建了精简的工作流程( ) 。[QAT](<https://unsloth.ai/docs/blog/quantization-aware-training-qat>))回收70%精度,然后将其直接部署到边缘设备. - 在当地部署 FunctionGemma **像素 8**财务报告和财务报告**iPhone 15 Pro 软件**获取**推断速度 ~ 50 令牌/s** - 先获得隐私,即时响应和离线能力 - 用我们的 [免费 Colab 笔记本](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_(0_6B)-Phone_Deployment.ipynb>) 微调 Qwen3 0.6B 并导出用于电话部署 - 只需将其更改为 Gemma3 并遵循 [Gemma 3 执行文件](<https://github.com/pytorch/executorch/tree/main/examples/models/gemma3>). [在您的手机上运行 LLMs](<https://unsloth.ai/docs/basics/inference-and-deployment/deploy-llms-phone>) 查看我们的iOS和Android 教程在您的手机上部署: [iOS 教程](<https://unsloth.ai/docs/basics/inference-and-deployment/deploy-llms-phone#ios-deployment>)[Android 教学](<https://unsloth.ai/docs/basics/inference-and-deployment/deploy-llms-phone#android-deployment>) ## * 精细调整 FunctionGemma 谷歌指出, **FunctionGemma 意在微调** 用于您特定的函数调用任务, 包括多回合使用大小写。 Unsloth 现在支持对 FunctionGemma 进行微调 。 我们创建了 2 微调笔记本, 它显示您如何通过 **通过 Colab Notebook 免费进行全微调或 LoRA :** [**工具调用精细笔记前的理由**](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M).ipynb>) [.ipynb>) [**移动动作微调笔记本**](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M)-Mobile-Actions.ipynb>) [-Mobile-Actions.ipynb>) 在那个 [**工具调用精细笔记前的理由**](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M).ipynb>),我们会 **在函数调用前微调其“ 思考/ 合理性 ”**思维链推理对于提高工具使用能力越来越重要。 FunctionGemma 是一个专门用于函数调用的小模型。 它使用它自己独特的聊天模板。 当提供工具定义和用户提示时, 它会产生结构化的输出。 然后我们可以分析这个输出来执行工具, 检索结果, 并利用它们生成最后的答案 。 转动类型 内容 **开发者提示** `<start_of_turn>developer` `You can do function calling with the following functions:` **函数声明** `<start_function_declaration>declaration:get_weather{` `description: "Get weather for city",` `parameters: { city: STRING }` `}` `<end_function_declaration>` `<end_of_turn>` **用户翻转** `<start_of_turn>user` `What is the weather like in Paris?` `<end_of_turn>` **函数调用** `<start_of_turn>model` `<start_function_call>call:get_weather{` `city: "paris"` `}` `<end_function_call>` **函数响应** `<start_function_response>response:get_weather{temperature:26}` `<end_function_response>` **闭幕助理** `The weather in Paris is 26 degrees Celsius.` `<end_of_turn>` 在此,我们使用单一思维块(而不是互开推理)实施简化版本。 `<think></think>`因此,我们的模型互动看起来是这样的: **思维** + **函数调用** `<start_of_turn>model` `**<think>**` `**The user wants weather for Paris. I have the get_weather tool. I should call it with the city argument.**` `**</think>**` `<start_function_call>call:get_weather{` `city: "paris"` `}` `<end_function_call>` ## QQ 精细调试 FunctionGemma 用于移动动作 我们还创建了一本笔记本,以显示您如何让 FunctionGemma 执行移动动作。 [**移动动作微调笔记本**](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M)-Mobile-Actions.ipynb>),我们也启用了评价,并显示如何对设备操作进行微调效果良好,从评价损失中可以看出:  例如, 给定一个提示 `Please set a reminder for a "Team Sync Meeting" this Friday, June 6th, 2025, at 2 PM.` 我们微调了模型 才能输出: ## 使用 FunctionGemma 调用多转动工具 我们还创建了一个笔记本,以显示您如何让 FunctionGemma 进行多回合工具调用。 [**多转动工具调用笔记本**](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M)-Multi-Turn-Tool-Calling.ipynb>),我们显示FunctionGemma在长信息变化中如何能够调用工具,例如,见下文:  您首先需要指定如下工具 : 然后我们绘制所有工具的映射图: 我们还需要一些工具引用和解析代码: 现在我们可以叫模特儿了! 试试我们为FunctionGemma制作的3笔记本: [工具调用精细笔记前的理由](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M).ipynb>) [.ipynb>) [移动动作微调笔记本](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M)-Mobile-Actions.ipynb>) [-Mobile-Actions.ipynb>) [多转动工具调用笔记本](<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/FunctionGemma_(270M)-Multi-Turn-Tool-Calling.ipynb>) [-Multi-Turn-Tool-Calling.ipynb>) [上一个 Quen3- Next](<https://unsloth.ai/docs/models/tutorials/qwen3-next>)[下一个深层搜索 - V3 1](<https://unsloth.ai/docs/models/tutorials/deepseek-v3.1-how-to-run-locally>) 上次更新的 7 几个月前 这有帮助吗?
查看原始来源