File size: 2,922 Bytes
1aff6d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
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 许可证