模型简介
模型特点
模型能力
使用案例
🚀 xLAM-2 模型家族
大型行动模型(LAMs)是一种先进的语言模型,旨在将用户意图转化为可执行的行动,从而增强决策能力。作为 AI 智能体的“大脑”,LAMs 能够自主规划和执行任务以实现特定目标,在不同领域的工作流自动化中具有重要价值。本模型仅用于研究目的。
全新的 xLAM-2 系列基于我们最先进的数据合成、处理和训练管道构建,在多轮对话和工具使用方面取得了显著进展。该系列模型采用我们新颖的 APIGen - MT 框架进行训练,该框架通过模拟智能体与人类的交互生成高质量的训练数据。我们的模型在 BFCL 和 τ - bench 基准测试中达到了最先进的性能,超越了 GPT - 4o 和 Claude 3.5 等前沿模型。值得注意的是,即使是我们的小型模型在多轮场景中也展现出了卓越的能力,并且在多次试验中保持了出色的一致性。
我们还优化了聊天模板和 vLLM 集成,使得构建先进的 AI 智能体更加容易。与之前的 xLAM 模型相比,xLAM - 2 提供了更出色的性能和无缝的应用部署体验。
[论文] | [主页] | [数据集] | [Github]
🚀 快速开始
本部分将为你介绍 xLAM - 2 模型家族的基本信息和使用方法。
✨ 主要特性
- 先进架构:基于最先进的数据合成、处理和训练管道构建,在多轮对话和工具使用方面表现卓越。
- 高质量数据:采用 APIGen - MT 框架生成的高质量训练数据进行训练。
- 优异性能:在 BFCL 和 τ - bench 基准测试中达到了最先进的性能,超越了 GPT - 4o 和 Claude 3.5 等前沿模型。
- 易用性:优化了聊天模板和 vLLM 集成,便于构建先进的 AI 智能体。
📦 安装指南
框架版本要求
- 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")
# Example conversation with a tool call
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("====== prompt after applying chat template ======")
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] # Get the length of the input tokens
inputs = {k: v.to(model.device) for k, v in inputs.items()}
print("====== model response ======")
outputs = model.generate(**inputs, max_new_tokens=256)
generated_tokens = outputs[:, input_ids_len:] # Slice the output to get only the newly generated tokens
print(tokenizer.decode(generated_tokens[0], skip_special_tokens=True))
高级用法
使用 vLLM 进行推理
安装和服务启动
pip install "vllm>=0.6.5"
wget https://huggingface.co/Salesforce/xLAM-2-1b-fc-r/raw/main/xlam_tool_call_parser.py
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
# Configure the client to use your local vLLM endpoint
client = openai.OpenAI(
base_url="http://localhost:8000/v1", # Default vLLM server URL
api_key="empty" # Can be any string
)
# Define a tool/function
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"]
}
}
}
]
# Create a chat completion
response = client.chat.completions.create(
model="Salesforce/xLAM-2-1b-fc-r", # Model name doesn't matter, vLLM uses the served model
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 the response
print("Assistant's response:")
print(json.dumps(response.model_dump(), indent=2))
如需了解更多高级配置和部署选项,请参考 vLLM 文档。
📚 详细文档
模型系列
属性 | 详情 |
---|---|
模型类型 | xLAM 系列在包括通用任务和函数调用等许多方面表现出色。对于相同数量的参数,该模型在广泛的智能体任务和场景中进行了微调,同时保留了原始模型的能力。 |
训练数据 | Salesforce/APIGen - MT - 5k、Salesforce/xlam - function - calling - 60k |
模型名称 | 总参数数量 | 上下文长度 | 类别 | 模型下载链接 | 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(Yet Another Recursive Network)等技术实现最大 128k 的上下文长度。更多详情请参考 此处。
你还可以在 此处 探索我们之前的 xLAM 系列。
-fc
后缀表示该模型针对函数调用任务进行了微调,而 -r
后缀表示这是一个研究版本。
✅ 所有模型都与 vLLM 和基于 Transformers 的推理框架完全兼容。
基准测试结果
伯克利函数调用排行榜(BFCL v3)
不同模型在 [BFCL 排行榜](https://gorilla.cs.berkeley.edu/leaderboard.html) 上的性能比较。排名基于整体准确率,即不同评估类别的加权平均值。“FC” 表示函数调用模式,与使用自定义 “提示” 提取函数调用相对。
τ - bench 基准测试
τ - bench 基准测试的成功率(pass@1),至少进行 5 次试验并取平均值。我们的 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%)等较新模型的性能。
Pass^k 曲线衡量了给定任务的 5 次独立试验全部成功的概率,分别对 τ - retail(左)和 τ - airline(右)领域的所有任务取平均值。值越高表示模型的一致性越好。
伦理考量
本版本仅用于支持学术论文的研究目的。我们的模型、数据集和代码并非专门为所有下游用途而设计或评估。我们强烈建议用户在部署此模型之前,评估并解决与准确性、安全性和公平性相关的潜在问题。我们鼓励用户考虑 AI 的常见局限性,遵守适用法律,并在选择用例时采用最佳实践,特别是在错误或滥用可能对人们的生活、权利或安全产生重大影响的高风险场景中。有关用例的更多指导,请参考我们的 AUP 和 AI AUP。
模型许可证
对于所有与 Llama 相关的模型,请同时遵循相应的 Llama 许可证和条款。Meta Llama 3 遵循 Meta Llama 3 社区许可证,版权所有 © Meta Platforms, Inc. 保留所有权利。
🔧 技术细节
本模型基于先进的 APIGen - MT 框架进行训练,该框架通过模拟智能体与人类的交互生成高质量的训练数据。在训练过程中,采用了最先进的数据合成、处理和训练管道,以提高模型在多轮对话和工具使用方面的性能。
📄 许可证
本模型采用 CC - BY - NC - 4.0 许可证。
🔖 引用
如果你在工作中使用了我们的模型或数据集,请引用我们的论文:
@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}
}



