| --- |
| language: |
| - en |
| - zh |
| license: apache-2.0 |
| base_model: lmstudio-community/functiongemma-270m-it-MLX-bf16 |
| tags: |
| - text-generation |
| - function-calling |
| - gemma3 |
| - mlx |
| - bfloat16 |
| pipeline_tag: text-generation |
| --- |
| |
| # functiongemma-270m-mika |
|
|
| 基于 [lmstudio-community/functiongemma-270m-it-MLX-bf16](https://huggingface.co/lmstudio-community/functiongemma-270m-it-MLX-bf16) 修改发布。 |
|
|
| ## 架构信息 |
|
|
| | 参数 | 值 | |
| |------|-----| |
| | 架构 | Gemma3ForCausalLM | |
| | 参数量 | ~270M | |
| | Hidden Size | 640 | |
| | 层数 | 18 (sliding + full attention混合) | |
| | 词表大小 | 262,144 | |
| | 最大上下文 | 32,768 tokens | |
| | 精度 | bfloat16 | |
|
|
| ## 修改内容 |
|
|
| - ✅ 优化了生成参数配置(temperature/top_p/top_k) |
| - ✅ 新增 `generation_config.json` |
| - ✅ 优化了支持 Function Calling 的 Chat Template |
| - ✅ 提升 max_length 至 8192 |
| |
| ## 快速开始 |
| |
| ### MLX 方式(Mac Apple Silicon 推荐) |
| ```python |
| from mlx_lm import load, generate |
|
|
| model, tokenizer = load("DarylFranxx/functiongemma-270m-mika") |
|
|
| # 普通对话 |
| response = generate(model, tokenizer, |
| prompt="你好,请介绍一下自己", |
| max_tokens=256) |
| print(response) |
| ``` |
| |
| ### Function Calling 示例 |
| ```python |
| from mlx_lm import load, generate |
| |
| model, tokenizer = load("DarylFranxx/functiongemma-270m-mika") |
| |
| tools = [ |
| { |
| "name": "get_weather", |
| "description": "获取指定城市的天气信息", |
| "parameters": { |
| "type": "object", |
| "properties": { |
| "city": {"type": "string", "description": "城市名称"}, |
| "date": {"type": "string", "description": "日期,格式YYYY-MM-DD"} |
| }, |
| "required": ["city"] |
| } |
| } |
| ] |
| |
| messages = [ |
| {"role": "user", "content": "北京今天天气怎么样?"} |
| ] |
| |
| # 使用tokenizer的chat_template格式化 |
| prompt = tokenizer.apply_chat_template( |
| messages, |
| tools=tools, |
| tokenize=False, |
| add_generation_prompt=True |
| ) |
| |
| response = generate(model, tokenizer, prompt=prompt, max_tokens=512) |
| print(response) |
| ``` |
|
|
| ### Transformers 方式 |
| ```python |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| import torch |
| |
| model_id = "DarylFranxx/functiongemma-270m-mika" |
| tokenizer = AutoTokenizer.from_pretrained(model_id) |
| model = AutoModelForCausalLM.from_pretrained( |
| model_id, |
| torch_dtype=torch.bfloat16, |
| device_map="auto" |
| ) |
| |
| messages = [{"role": "user", "content": "Hello!"}] |
| inputs = tokenizer.apply_chat_template( |
| messages, return_tensors="pt", add_generation_prompt=True |
| ).to(model.device) |
| |
| outputs = model.generate(inputs, max_new_tokens=256) |
| print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)) |
| ``` |
|
|
| ## 注意事项 |
|
|
| - 需要 `transformers >= 4.57.3` 才支持 `Gemma3ForCausalLM` |
| - MLX格式仅适用于 Apple Silicon (M1/M2/M3/M4) |
| - 遵守原始模型 Apache 2.0 许可证 |
|
|