初始化项目,由ModelHub XC社区提供模型
Model: silvermete0r/qwen2.5-nano-function-master Source: Original Platform
This commit is contained in:
36
.gitattributes
vendored
Normal file
36
.gitattributes
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||||
192
README.md
Normal file
192
README.md
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
---
|
||||||
|
license: apache-2.0
|
||||||
|
base_model: Qwen/Qwen2.5-0.5B-Instruct
|
||||||
|
tags:
|
||||||
|
- function-calling
|
||||||
|
- tool-use
|
||||||
|
- peft
|
||||||
|
- lora
|
||||||
|
- qwen2.5
|
||||||
|
- json-generation
|
||||||
|
- nano-slm
|
||||||
|
- resource-constrained
|
||||||
|
datasets:
|
||||||
|
- Salesforce/xlam-function-calling-60k
|
||||||
|
language:
|
||||||
|
- en
|
||||||
|
metrics:
|
||||||
|
- accuracy
|
||||||
|
library_name: transformers
|
||||||
|
pipeline_tag: text-generation
|
||||||
|
---
|
||||||
|
|
||||||
|
# Qwen2.5-0.5B - Nano Function Master
|
||||||
|
|
||||||
|
A lightweight, fast function-calling model fine-tuned from
|
||||||
|
[Qwen/Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct)
|
||||||
|
on the [Salesforce/xlam-function-calling-60k](https://huggingface.co/datasets/Salesforce/xlam-function-calling-60k) dataset.
|
||||||
|
|
||||||
|
Part of the **Fast Nano SLMs** project - optimizing inference and memory efficiency
|
||||||
|
for function-calling tasks in private/resource-constrained environments.
|
||||||
|
|
||||||
|
**Project repository**: [silvermete0r/nano-slms-for-local-function-calling-assistance](https://github.com/silvermete0r/nano-slms-for-local-function-calling-assistance)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Training Details
|
||||||
|
|
||||||
|
| Hyperparameter | Value |
|
||||||
|
|-------------------------|------------------------------------------------|
|
||||||
|
| LoRA rank (r) | 16 |
|
||||||
|
| LoRA alpha | 32 |
|
||||||
|
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
||||||
|
| LoRA dropout | 0.05 |
|
||||||
|
| Training samples | 9,000 |
|
||||||
|
| Eval samples | 1,000 |
|
||||||
|
| Max steps | 600 |
|
||||||
|
| Effective batch size | 16 (4 × 4 grad accumulation) |
|
||||||
|
| Learning rate | 2e-4 |
|
||||||
|
| LR scheduler | Cosine with 50 warmup steps |
|
||||||
|
| Optimizer | AdamW (fused) |
|
||||||
|
| Weight decay | 0.01 |
|
||||||
|
| Gradient clipping | 1.0 |
|
||||||
|
| Max sequence length | 1024 |
|
||||||
|
| Packing | ❌ disabled |
|
||||||
|
| Dataset | Salesforce/xlam-function-calling-60k |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Benchmark Results
|
||||||
|
|
||||||
|
Evaluated on 1,000 held-out samples from `xlam-function-calling-60k`:
|
||||||
|
|
||||||
|
*Before fine-tuning | After fine-tuning ~ Results*
|
||||||
|
|
||||||
|
```
|
||||||
|
Metric Before After Delta
|
||||||
|
--------------------------------------------------------------
|
||||||
|
json_valid_pct 45.4 98.7 +53.3
|
||||||
|
name_match_pct 15.0 93.3 +78.3
|
||||||
|
args_keys_match_pct 11.8 81.0 +69.2
|
||||||
|
args_exact_pct 8.9 69.1 +60.2
|
||||||
|
```
|
||||||
|
|
||||||
|
*Estimated during the final evaluation inference stage of the fine-tuned model.*
|
||||||
|
|
||||||
|
| Metric | Value |
|
||||||
|
| --------------------------------- | -------: |
|
||||||
|
| Average TTFT (s) | 0.0475 |
|
||||||
|
| Average Tokens per Second | 154.0545 |
|
||||||
|
| Average Tokens Generated | 51.199 |
|
||||||
|
| Average VRAM Delta (MB) | 0.0094 |
|
||||||
|
| Peak VRAM Reserved (MB) | 3120.0 |
|
||||||
|
| Average RAM Delta (MB) | -0.0666 |
|
||||||
|
| Average CPU Usage (%) | 69.2192 |
|
||||||
|
| Throughput (samples/s) | 2.06 |
|
||||||
|
| Estimated CO₂ Emissions (g CO₂eq) | 5.4236 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```python
|
||||||
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||||
|
import torch, json
|
||||||
|
|
||||||
|
model_id = "silvermete0r/qwen2.5-nano-function-master"
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
||||||
|
model = AutoModelForCausalLM.from_pretrained(
|
||||||
|
model_id, torch_dtype=torch.float16, device_map="auto")
|
||||||
|
|
||||||
|
tools = [
|
||||||
|
{
|
||||||
|
"name": "get_weather",
|
||||||
|
"description": "Get the current weather for a location",
|
||||||
|
"parameters": {
|
||||||
|
"location": {"type": "string", "description": "City name"},
|
||||||
|
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
messages = [
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": (
|
||||||
|
"You are a helpful assistant with access to the following functions. "
|
||||||
|
f"Use them if required:\n{json.dumps(tools)}\n\n"
|
||||||
|
"Respond strictly with a JSON array of function calls."
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{"role": "user", "content": "What's the weather in Aktobe?"},
|
||||||
|
]
|
||||||
|
|
||||||
|
inputs = tokenizer.apply_chat_template(
|
||||||
|
messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
|
||||||
|
|
||||||
|
outputs = model.generate(inputs, max_new_tokens=128, do_sample=False)
|
||||||
|
response = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
|
||||||
|
print(json.loads(response))
|
||||||
|
# → [{"name": "get_weather", "arguments": {"location": "Aktobe", "unit": "celsius"}}]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Batched inference (faster)
|
||||||
|
|
||||||
|
```python
|
||||||
|
tokenizer.padding_side = "left"
|
||||||
|
tokenizer.pad_token = tokenizer.eos_token
|
||||||
|
|
||||||
|
prompts = [
|
||||||
|
tokenizer.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
|
||||||
|
for msgs in list_of_message_lists
|
||||||
|
]
|
||||||
|
inputs = tokenizer(prompts, return_tensors="pt", padding=True, truncation=True,
|
||||||
|
max_length=1024).to(model.device)
|
||||||
|
|
||||||
|
with torch.no_grad():
|
||||||
|
outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False,
|
||||||
|
pad_token_id=tokenizer.pad_token_id)
|
||||||
|
|
||||||
|
responses = [
|
||||||
|
tokenizer.decode(out[inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
||||||
|
for out in outputs
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Intended Use
|
||||||
|
|
||||||
|
- ✅ Local function-calling assistants (offline / air-gapped)
|
||||||
|
- ✅ Edge deployment (laptops, Raspberry Pi 5, Jetson Nano)
|
||||||
|
- ✅ Privacy-sensitive environments (no API calls)
|
||||||
|
- ✅ Structured JSON output generation
|
||||||
|
- ❌ Not intended for open-ended conversational use
|
||||||
|
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
```
|
||||||
|
@misc{qwen2.5,
|
||||||
|
title = {Qwen2.5: A Party of Foundation Models},
|
||||||
|
url = {https://qwenlm.github.io/blog/qwen2.5/},
|
||||||
|
author = {Qwen Team},
|
||||||
|
month = {September},
|
||||||
|
year = {2024}
|
||||||
|
}
|
||||||
|
|
||||||
|
@article{qwen2,
|
||||||
|
title={Qwen2 Technical Report},
|
||||||
|
author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhihao Fan},
|
||||||
|
journal={arXiv preprint arXiv:2407.10671},
|
||||||
|
year={2024}
|
||||||
|
}
|
||||||
|
|
||||||
|
@article{liu2024apigen,
|
||||||
|
title={APIGen: Automated Pipeline for Generating Verifiable and Diverse Function-Calling Datasets},
|
||||||
|
author={Liu, Zuxin and Hoang, Thai and Zhang, Jianguo and Zhu, Ming and Lan, Tian and Kokane, Shirley and Tan, Juntao and Yao, Weiran and Liu, Zhiwei and Feng, Yihao and others},
|
||||||
|
journal={arXiv preprint arXiv:2406.18518},
|
||||||
|
year={2024}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
54
chat_template.jinja
Normal file
54
chat_template.jinja
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{%- if tools %}
|
||||||
|
{{- '<|im_start|>system\n' }}
|
||||||
|
{%- if messages[0]['role'] == 'system' %}
|
||||||
|
{{- messages[0]['content'] }}
|
||||||
|
{%- else %}
|
||||||
|
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
|
||||||
|
{%- endif %}
|
||||||
|
{{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
||||||
|
{%- for tool in tools %}
|
||||||
|
{{- "\n" }}
|
||||||
|
{{- tool | tojson }}
|
||||||
|
{%- endfor %}
|
||||||
|
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
||||||
|
{%- else %}
|
||||||
|
{%- if messages[0]['role'] == 'system' %}
|
||||||
|
{{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
|
||||||
|
{%- else %}
|
||||||
|
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- for message in messages %}
|
||||||
|
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
|
||||||
|
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
||||||
|
{%- elif message.role == "assistant" %}
|
||||||
|
{{- '<|im_start|>' + message.role }}
|
||||||
|
{%- if message.content %}
|
||||||
|
{{- '\n' + message.content }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- for tool_call in message.tool_calls %}
|
||||||
|
{%- if tool_call.function is defined %}
|
||||||
|
{%- set tool_call = tool_call.function %}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '\n<tool_call>\n{"name": "' }}
|
||||||
|
{{- tool_call.name }}
|
||||||
|
{{- '", "arguments": ' }}
|
||||||
|
{{- tool_call.arguments | tojson }}
|
||||||
|
{{- '}\n</tool_call>' }}
|
||||||
|
{%- endfor %}
|
||||||
|
{{- '<|im_end|>\n' }}
|
||||||
|
{%- elif message.role == "tool" %}
|
||||||
|
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
|
||||||
|
{{- '<|im_start|>user' }}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '\n<tool_response>\n' }}
|
||||||
|
{{- message.content }}
|
||||||
|
{{- '\n</tool_response>' }}
|
||||||
|
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
||||||
|
{{- '<|im_end|>\n' }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
|
{%- if add_generation_prompt %}
|
||||||
|
{{- '<|im_start|>assistant\n' }}
|
||||||
|
{%- endif %}
|
||||||
57
config.json
Normal file
57
config.json
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"architectures": [
|
||||||
|
"Qwen2ForCausalLM"
|
||||||
|
],
|
||||||
|
"attention_dropout": 0.0,
|
||||||
|
"bos_token_id": 151643,
|
||||||
|
"dtype": "float16",
|
||||||
|
"eos_token_id": 151645,
|
||||||
|
"hidden_act": "silu",
|
||||||
|
"hidden_size": 896,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"intermediate_size": 4864,
|
||||||
|
"layer_types": [
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention",
|
||||||
|
"full_attention"
|
||||||
|
],
|
||||||
|
"max_position_embeddings": 32768,
|
||||||
|
"max_window_layers": 21,
|
||||||
|
"model_type": "qwen2",
|
||||||
|
"num_attention_heads": 14,
|
||||||
|
"num_hidden_layers": 24,
|
||||||
|
"num_key_value_heads": 2,
|
||||||
|
"pad_token_id": null,
|
||||||
|
"rms_norm_eps": 1e-06,
|
||||||
|
"rope_parameters": {
|
||||||
|
"rope_theta": 1000000.0,
|
||||||
|
"rope_type": "default"
|
||||||
|
},
|
||||||
|
"sliding_window": null,
|
||||||
|
"tie_word_embeddings": true,
|
||||||
|
"transformers_version": "5.8.1",
|
||||||
|
"use_cache": true,
|
||||||
|
"use_sliding_window": false,
|
||||||
|
"vocab_size": 151936
|
||||||
|
}
|
||||||
14
generation_config.json
Normal file
14
generation_config.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"bos_token_id": 151643,
|
||||||
|
"do_sample": true,
|
||||||
|
"eos_token_id": [
|
||||||
|
151645,
|
||||||
|
151643
|
||||||
|
],
|
||||||
|
"pad_token_id": 151643,
|
||||||
|
"repetition_penalty": 1.1,
|
||||||
|
"temperature": 0.7,
|
||||||
|
"top_k": 20,
|
||||||
|
"top_p": 0.8,
|
||||||
|
"transformers_version": "5.8.1"
|
||||||
|
}
|
||||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:c36b4e13f0619f9c4998c910086654a67bd854d291faf1de162e8f85730923f8
|
||||||
|
size 988097536
|
||||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:4f1bd9bf67bdd2e951e840f44bf2d9c00611c636c21b7773a5e0da25d9540689
|
||||||
|
size 11422158
|
||||||
30
tokenizer_config.json
Normal file
30
tokenizer_config.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"add_prefix_space": false,
|
||||||
|
"backend": "tokenizers",
|
||||||
|
"bos_token": null,
|
||||||
|
"clean_up_tokenization_spaces": false,
|
||||||
|
"eos_token": "<|im_end|>",
|
||||||
|
"errors": "replace",
|
||||||
|
"extra_special_tokens": [
|
||||||
|
"<|im_start|>",
|
||||||
|
"<|im_end|>",
|
||||||
|
"<|object_ref_start|>",
|
||||||
|
"<|object_ref_end|>",
|
||||||
|
"<|box_start|>",
|
||||||
|
"<|box_end|>",
|
||||||
|
"<|quad_start|>",
|
||||||
|
"<|quad_end|>",
|
||||||
|
"<|vision_start|>",
|
||||||
|
"<|vision_end|>",
|
||||||
|
"<|vision_pad|>",
|
||||||
|
"<|image_pad|>",
|
||||||
|
"<|video_pad|>"
|
||||||
|
],
|
||||||
|
"is_local": false,
|
||||||
|
"local_files_only": false,
|
||||||
|
"model_max_length": 131072,
|
||||||
|
"pad_token": "<|endoftext|>",
|
||||||
|
"split_special_tokens": false,
|
||||||
|
"tokenizer_class": "Qwen2Tokenizer",
|
||||||
|
"unk_token": null
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user