模型简介
模型特点
模型能力
使用案例
🚀 xLAM-2-3b-fc-r GGUF模型
xLAM-2-3b-fc-r GGUF模型是基于特定量化方法生成的文本生成模型,可用于函数调用、LLM代理、工具使用等场景。该模型在多轮对话和工具使用方面表现出色,在多个基准测试中取得了优异的成绩。
元数据信息
属性 | 详情 |
---|---|
模型类型 | 文本生成 |
训练数据 | Salesforce/APIGen-MT-5k、Salesforce/xlam-function-calling-60k |
语言 | en |
标签 | function-calling、LLM Agent、tool-use、llama、qwen、pytorch、LLaMA-factory |
库名称 | transformers |
许可证 | cc-by-nc-4.0 |
🚀 快速开始
框架版本要求
- Transformers 4.46.1(或更高版本)
- PyTorch 2.5.1+cu124(或更高版本)
- Datasets 3.1.0(或更高版本)
- Tokenizers 0.20.3(或更高版本)
基本使用示例
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("Salesforce/Llama-xLAM-2-3b-fc-r")
model = AutoModelForCausalLM.from_pretrained("Salesforce/Llama-xLAM-2-3b-fc-r", torch_dtype=torch.bfloat16, device_map="auto")
# 示例对话与工具调用
messages = [
{"role": "user", "content": "Hi, how are you?"},
{"role": "assistant", "content": "Thanks. I am doing well. How can I help you?"},
{"role": "user", "content": "What's the weather like in London?"},
]
tools = [
{
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "The unit of temperature to return"}
},
"required": ["location"]
}
}
]
print("====== 应用聊天模板后的提示 ======")
print(tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, tokenize=False))
inputs = tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, return_dict=True, return_tensors="pt")
input_ids_len = inputs["input_ids"].shape[-1] # 获取输入令牌的长度
inputs = {k: v.to(model.device) for k, v in inputs.items()}
print("====== 模型响应 ======")
outputs = model.generate(**inputs, max_new_tokens=256)
generated_tokens = outputs[:, input_ids_len:] # 切片输出以仅获取新生成的令牌
print(tokenizer.decode(generated_tokens[0], skip_special_tokens=True))
✨ 主要特性
- 多轮对话能力:能够处理复杂的多轮对话场景,在实际应用中表现出色。
- 函数调用功能:支持函数调用,可与实时网络服务进行交互。
- 高精度量化:采用新的量化方法,提高了模型在低比特深度下的精度。
- 广泛兼容性:与vLLM和基于Transformers的推理框架完全兼容。
📦 安装指南
使用vLLM进行推理
- 安装指定版本的vLLM:
pip install "vllm>=0.6.5"
- 下载工具解析器插件到本地路径:
wget https://huggingface.co/Salesforce/xLAM-2-1b-fc-r/raw/main/xlam_tool_call_parser.py
- 启动与OpenAI API兼容的端点:
vllm serve Salesforce/xLAM-2-1b-fc-r \
--enable-auto-tool-choice \
--tool-parser-plugin ./xlam_tool_call_parser.py \
--tool-call-parser xlam \
--tensor-parallel-size 1
💻 使用示例
基础用法
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("Salesforce/Llama-xLAM-2-3b-fc-r")
model = AutoModelForCausalLM.from_pretrained("Salesforce/Llama-xLAM-2-3b-fc-r", torch_dtype=torch.bfloat16, device_map="auto")
# 示例对话与工具调用
messages = [
{"role": "user", "content": "Hi, how are you?"},
{"role": "assistant", "content": "Thanks. I am doing well. How can I help you?"},
{"role": "user", "content": "What's the weather like in London?"},
]
tools = [
{
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "The unit of temperature to return"}
},
"required": ["location"]
}
}
]
print("====== 应用聊天模板后的提示 ======")
print(tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, tokenize=False))
inputs = tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, return_dict=True, return_tensors="pt")
input_ids_len = inputs["input_ids"].shape[-1] # 获取输入令牌的长度
inputs = {k: v.to(model.device) for k, v in inputs.items()}
print("====== 模型响应 ======")
outputs = model.generate(**inputs, max_new_tokens=256)
generated_tokens = outputs[:, input_ids_len:] # 切片输出以仅获取新生成的令牌
print(tokenizer.decode(generated_tokens[0], skip_special_tokens=True))
高级用法
import openai
import json
# 配置客户端以使用本地vLLM端点
client = openai.OpenAI(
base_url="http://localhost:8000/v1", # 默认vLLM服务器URL
api_key="empty" # 可以是任何字符串
)
# 定义工具/函数
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit of temperature to return"
}
},
"required": ["location"]
}
}
}
]
# 创建聊天完成
response = client.chat.completions.create(
model="Salesforce/xLAM-2-1b-fc-r", # 模型名称无关紧要,vLLM使用服务的模型
messages=[
{"role": "system", "content": "You are a helpful assistant that can use tools."},
{"role": "user", "content": "What's the weather like in San Francisco?"}
],
tools=tools,
tool_choice="auto"
)
# 打印响应
print("Assistant's response:")
print(json.dumps(response.model_dump(), indent=2))
📚 详细文档
模型系列
模型 | 总参数数量 | 上下文长度 | 类别 | 下载模型 | 下载GGUF文件 |
---|---|---|---|---|---|
Llama-xLAM-2-70b-fc-r | 70B | 128k | 多轮对话、函数调用 | 链接 | NA |
Llama-xLAM-2-8b-fc-r | 8B | 128k | 多轮对话、函数调用 | 链接 | 链接 |
xLAM-2-32b-fc-r | 32B | 32k (最大128k)* | 多轮对话、函数调用 | 链接 | NA |
xLAM-2-3b-fc-r | 3B | 32k (最大128k)* | 多轮对话、函数调用 | 链接 | 链接 |
xLAM-2-1b-fc-r | 1B | 32k (最大128k)* | 多轮对话、函数调用 | 链接 | 链接 |
*注意:基于Qwen-2.5的模型默认上下文长度为32k,但可以使用YaRN等技术实现最大128k的上下文长度。更多详细信息请参考此处。
基准测试结果
Berkeley Function-Calling Leaderboard (BFCL v3)
不同模型在BFCL排行榜上的性能比较。排名基于整体准确率,这是不同评估类别的加权平均值。“FC”表示函数调用模式,与使用自定义“提示”提取函数调用相对。
œÑ-bench基准测试
在œÑ-bench基准测试中,至少进行5次试验的平均成功率(pass@1)。我们的xLAM-2-70b-fc-r模型在œÑ-bench上的整体成功率达到56.2%,显著优于基础Llama 3.1 70B Instruct模型(38.2%)和其他开源模型,如DeepSeek v3(40.6%)。值得注意的是,我们的最佳模型甚至优于专有模型,如GPT-4o(52.9%),并接近更近期模型,如Claude 3.5 Sonnet (new)(60.1%)的性能。
Pass^k曲线衡量给定任务的所有5次独立试验成功的概率,在œÑ-retail(左)和œÑ-airline(右)领域的所有任务上进行平均。值越高表示模型的一致性越好。
🔧 技术细节
模型生成细节
该模型使用llama.cpp在提交版本6adc3c3e
时生成。
量化方法
尝试了一种新的量化方法,该方法选择性地提高关键层的精度,超越了默认IMatrix配置提供的精度。在测试中,标准IMatrix量化在低比特深度下表现不佳,特别是对于混合专家(MoE)模型。为了解决这个问题,使用llama.cpp
中的--tensor-type
选项手动将重要层的精度提高。具体实现可参考:使用llama.cpp进行层提升。虽然这会增加模型文件的大小,但显著提高了给定量化级别的精度。
📄 许可证
本模型采用CC BY-NC 4.0许可证。对于所有与Llama相关的模型,请遵循相应的Llama许可证和条款。Meta Llama 3根据Meta Llama 3社区许可证授权,版权所有 © Meta Platforms, Inc. 保留所有权利。
引用
如果您在工作中使用了我们的模型或数据集,请引用我们的论文:
@article{prabhakar2025apigen,
title={APIGen-MT: Agentic PIpeline for Multi-Turn Data Generation via Simulated Agent-Human Interplay},
author={Prabhakar, Akshara and Liu, Zuxin and Zhu, Ming and Zhang, Jianguo and Awalgaonkar, Tulika and Wang, Shiyu and Liu, Zhiwei and Chen, Haolin and Hoang, Thai and others},
journal={arXiv preprint arXiv:2504.03601},
year={2025}
}
此外,请查看我们关于xLAM系列的其他优秀相关工作,并考虑也引用它们:
@article{zhang2025actionstudio,
title={ActionStudio: A Lightweight Framework for Data and Training of Action Models},
author={Zhang, Jianguo and Hoang, Thai and Zhu, Ming and Liu, Zuxin and Wang, Shiyu and Awalgaonkar, Tulika and Prabhakar, Akshara and Chen, Haolin and Yao, Weiran and Liu, Zhiwei and others},
journal={arXiv preprint arXiv:2503.22673},
year={2025}
}
@article{zhang2024xlam,
title={xLAM: A Family of Large Action Models to Empower AI Agent Systems},
author={Zhang, Jianguo and Lan, Tian and Zhu, Ming and Liu, Zuxin and Hoang, Thai and Kokane, Shirley and Yao, Weiran and Tan, Juntao and Prabhakar, Akshara and Chen, Haolin and others},
journal={arXiv preprint arXiv:2409.03215},
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 Tan, Juntao and Yao, Weiran and Liu, Zhiwei and Feng, Yihao and RN, Rithesh and others},
journal={Advances in Neural Information Processing Systems},
volume={37},
pages={54463--54482},
year={2024}
}
@article{zhang2024agentohana,
title={AgentOhana: Design Unified Data and Training Pipeline for Effective Agent Learning},
author={Zhang, Jianguo and Lan, Tian and Murthy, Rithesh and Liu, Zhiwei and Yao, Weiran and Tan, Juntao and Hoang, Thai and Yang, Liangwei and Feng, Yihao and Liu, Zuxin and others},
journal={arXiv preprint arXiv:2402.15506},
year={2024}
}
其他信息
模型测试邀请
如果您发现这些模型有用,请帮助测试AI驱动的量子网络监控助手,进行量子就绪安全检查。 量子网络监控
量子网络监控服务的完整开源代码可在GitHub仓库中找到:量子网络监控源代码。如果您想自己进行模型量化,也可以找到相关代码:GGUFModelBuilder
测试说明
- 选择AI助手类型:
TurboLLM
(GPT-4.1-mini)HugLLM
(Huggingface开源模型)TestLLM
(仅支持CPU的实验性模型)
- 测试内容:
- 对实时网络服务进行函数调用
- 测试小模型在自动化Nmap安全扫描、量子就绪检查和网络监控任务中的性能
不同助手特点
- TestLLM:当前的实验性模型(在Hugging Face Docker空间的2个CPU线程上运行llama.cpp):
- 零配置设置
- 加载时间约30秒(推理速度慢,但无API成本),无令牌限制
- 寻求合作:如果您对边缘设备AI感兴趣,欢迎合作!
- TurboLLM:使用gpt-4.1-mini:
- 性能出色,但OpenAI按令牌收费,因此令牌使用受限
- 创建自定义命令处理器,在量子网络监控代理上运行.NET代码
- 实时网络诊断和监控
- 安全审计
- 渗透测试(Nmap/Metasploit)
- HugLLM:最新的开源模型:
- 在Hugging Face推理API上运行,使用Novita托管的最新模型表现出色
示例测试命令
"Give me info on my websites SSL certificate"
"Check if my server is using quantum safe encyption for communication"
"Run a comprehensive security audit on my server"
"Create a cmd processor to .. (what ever you want)"
(需要安装量子网络监控代理以运行.NET代码)
支持请求
本项目的服务器费用、推理费用均由个人承担。如果您认可这项工作,请考虑请我喝杯咖啡。您的支持将有助于支付服务成本,并提高令牌使用限制。同时,也欢迎工作机会或赞助合作。感谢您的支持!



