说明文档
<p align="center"> <img width="500px" alt="xLAM" src="https://huggingface.co/datasets/jianguozhang/logos/resolve/main/xlam-no-background.png"> </p>
<p align="center"> <a href="https://arxiv.org/abs/2504.03601">[论文]</a> | <a href="https://apigen-mt.github.io/">[主页]</a> | <a href="https://huggingface.co/datasets/Salesforce/APIGen-MT-5k">[数据集]</a> | <a href="https://github.com/SalesforceAIResearch/xLAM">[Github]</a> </p> <hr>
欢迎来到 xLAM-2 模型家族!
大型动作模型 是一种先进的语言模型,旨在通过将用户意图转化为可执行动作来增强决策能力。作为 AI 智能体的大脑,大型动作模型能够自主规划和执行任务以实现特定目标,使其在跨多个领域自动化工作流程方面具有不可估量的价值。
本模型发布仅用于研究目的。
全新的 xLAM-2 系列建立在我们最先进的数据合成、处理和训练流程之上,标志着 多轮对话 和 工具使用 能力的重大飞跃。该模型使用我们新颖的 APIGen-MT 框架进行训练,该框架通过模拟智能体-人类交互生成高质量的训练数据。我们的模型在 BFCL 和 τ-bench 基准测试中取得了最先进的性能,超越了 GPT-4o 和 Claude 3.5 等前沿模型。值得注意的是,即使是我们的较小模型也在多轮场景中展现出卓越的能力,同时在多次试验中保持出色的一致性。
我们还改进了 聊天模板 和 vLLM 集成,使其更易于构建高级 AI 智能体。与之前的 xLAM 模型相比,xLAM-2 提供了更优越的性能,并可在各种应用中无缝部署。
<p align="center"> <img width="100%" alt="模型性能概览" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/model_board.png?raw=true"> <br> <small><i>较大的 xLAM-2-fc-r 模型(8B-70B,使用 APIGen-MT 数据训练)与最先进基线模型在函数调用(BFCL v3,截至 2025 年 4 月 2 日)和智能体(τ-bench)能力方面的性能对比。</i></small> </p>
目录
模型系列
xLAM 系列在许多方面都有显著提升,包括通用任务和函数调用。对于相同数量的参数,该模型已在广泛的智能体任务和场景中进行了微调,同时保留了原始模型的能力。
| 模型 | 总参数量 | 上下文长度 | 类别 | 下载模型 | 下载 GGUF 文件 |
|---|---|---|---|---|---|
| Llama-xLAM-2-70b-fc-r | 70B | 128k | 多轮对话,函数调用 | 🤗 链接 | 暂无 |
| Llama-xLAM-2-8b-fc-r | 8B | 128k | 多轮对话,函数调用 | 🤗 链接 | 🤗 链接 |
| xLAM-2-32b-fc-r | 32B | 32k(最大 128k)* | 多轮对话,函数调用 | 🤗 链接 | 暂无 |
| xLAM-2-3b-fc-r | 3B | 32k(最大 128k)* | 多轮对话,函数调用 | 🤗 链接 | 🤗 链接 |
| xLAM-2-1b-fc-r | 1B | 32k(最大 128k)* | 多轮对话,函数调用 | 🤗 链接 | 🤗 链接 |
*注意: 基于 Qwen-2.5 的模型默认上下文长度为 32k,但您可以使用 YaRN(Yet Another Recursive Network)等技术来实现最大 128k 的上下文长度。请参阅此处了解更多详情。
您也可以在这里探索我们之前的 xLAM 系列。
-fc 后缀表示模型针对 函数调用 任务进行了微调,而 -r 后缀表示这是一个 研究 版本。
✅ 所有模型完全兼容 vLLM 和基于 Transformers 的推理框架。
使用方法
框架版本
- Transformers 4.46.1(或更高版本)
- PyTorch 2.5.1+cu124(或更高版本)
- Datasets 3.1.0(或更高版本)
- Tokenizers 0.20.3(或更高版本)
使用 Huggingface 聊天模板的基本用法
全新的 xLAM 模型设计为可与 Hugging Face Transformers 库无缝配合使用,并利用自然聊天模板提供简单直观的对话体验。以下是如何使用这些模型的示例。
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": "你好,你好吗?"},
{"role": "assistant", "content": "谢谢。我很好。有什么可以帮助你的吗?"},
{"role": "user", "content": "伦敦的天气怎么样?"},
]
tools = [
{
"name": "get_weather",
"description": "获取某个地点的当前天气",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "城市和州,例如 San Francisco, CA"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "返回的温度单位"}
},
"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] # 获取输入 token 的长度
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:] # 切片输出以仅获取新生成的 token
print(tokenizer.decode(generated_tokens[0], skip_special_tokens=True))
使用 vLLM 进行推理
xLAM 模型也可以使用 vLLM 高效部署以实现高吞吐量推理。请使用 vllm>=0.6.5,因为早期版本会导致基于 Qwen 的模型性能下降。
设置与服务
- 安装所需版本的 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
注意:请确保已下载工具解析器插件文件,并且 --tool-parser-plugin 中指定的路径正确指向您的本地文件副本。xLAM 系列模型都使用 相同 的工具调用解析器,因此您只需为所有模型下载 一次。
使用 OpenAI API 进行测试
以下是一个使用已部署端点测试工具使用的基本示例:
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": "获取某个地点的当前天气",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市和州,例如 San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "返回的温度单位"
}
},
"required": ["location"]
}
}
}
]
# 创建聊天补全
response = client.chat.completions.create(
model="Salesforce/xLAM-2-1b-fc-r", # 模型名称无关紧要,vLLM 使用已部署的模型
messages=[
{"role": "system", "content": "你是一个可以使用工具的智能助手。"},
{"role": "user", "content": "旧金山的天气怎么样?"}
],
tools=tools,
tool_choice="auto"
)
# 打印响应
print("助手的响应:")
print(json.dumps(response.model_dump(), indent=2))
有关更高级的配置和部署选项,请参阅 vLLM 文档。
基准测试结果
Berkeley 函数调用排行榜 (BFCL v3)
<p align="center"> <img width="80%" alt="BFCL 结果" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/bfcl-result.png?raw=true"> <br> <small><i>不同模型在 BFCL 排行榜 上的性能对比。排名基于总体准确率,这是不同评估类别的加权平均值。"FC" 代表函数调用模式,与使用自定义"提示词"提取函数调用相对。</i></small> </p>
τ-bench 基准测试
<p align="center"> <img width="80%" alt="Tau-bench 结果" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/taubench-result.png?raw=true"> <br> <small><i>τ-bench 基准测试上的成功率(pass@1), averaged across at least 5 trials. 我们的 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(新版)(60.1%)等更新模型的性能。</i></small> </p>
<p align="center"> <img width="80%" alt="Pass^k 曲线" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/pass_k_curves_retail_airline.png?raw=true"> <br> <small><i>Pass^k 曲线测量对于给定任务所有 5 次独立试验都成功的概率,在 τ-retail(左)和 τ-airline(右)领域的所有任务上取平均值。较高的值表示模型具有更好的一致性。</i></small> </p>
伦理考量
本次发布仅用于支持学术论文的研究目的。我们的模型、数据集和代码并非专门为所有下游用途设计或评估。我们强烈建议用户在部署此模型之前评估并解决与准确性、安全性和公平性相关的潜在问题。我们鼓励用户考虑 AI 的常见局限性,遵守适用法律,并在选择用例时利用最佳实践,特别是对于错误或滥用可能严重影响人们生活、权利或安全的高风险场景。有关用例的更多指导,请参阅我们的 AUP 和 AI AUP。
模型许可证
对于所有 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}
}
amd/Llama-xLAM-2-8b-fc-r-awq-g128-int4-asym-bfp16-onnx-hybrid
作者 amd
创建时间: 2025-05-14 17:53:55+00:00
更新时间: 2025-09-16 17:24:25+00:00
在 Hugging Face 上查看