licongwei commited on
Commit
aed5947
·
verified ·
1 Parent(s): 9538fae

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
+ xLAM-2-3b-fc-r-SpinQuant.pte filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,308 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ datasets:
4
+ - Salesforce/APIGen-MT-5k
5
+ - Salesforce/xlam-function-calling-60k
6
+ language:
7
+ - en
8
+ pipeline_tag: text-generation
9
+ tags:
10
+ - function-calling
11
+ - LLM Agent
12
+ - tool-use
13
+ - llama
14
+ - qwen
15
+ - pytorch
16
+ - LLaMA-factory
17
+ library_name: transformers
18
+ ---
19
+
20
+ <p align="center">
21
+ <img width="500px" alt="xLAM" src="https://huggingface.co/datasets/jianguozhang/logos/resolve/main/xlam-no-background.png">
22
+ </p>
23
+
24
+
25
+ <p align="center">
26
+ <a href="https://arxiv.org/abs/2504.03601">[Paper]</a> |
27
+ <a href="https://apigen-mt.github.io/">[Homepage]</a> |
28
+ <a href="https://huggingface.co/datasets/Salesforce/APIGen-MT-5k">[Dataset]</a> |
29
+ <a href="https://github.com/SalesforceAIResearch/xLAM">[Github]</a>
30
+ </p>
31
+ <hr>
32
+
33
+ # Welcome to the xLAM-2 Model Family!
34
+
35
+ [Large Action Models (LAMs)](https://blog.salesforceairesearch.com/large-action-models/) are advanced language models designed to enhance decision-making by translating user intentions into executable actions. As the **brains of AI agents**, LAMs autonomously plan and execute tasks to achieve specific goals, making them invaluable for automating workflows across diverse domains.
36
+ **This model release is for research purposes only.**
37
+
38
+ The new **xLAM-2** series, built on our most advanced data synthesis, processing, and training pipelines, marks a significant leap in **multi-turn conversation** and **tool usage**. Trained using our novel APIGen-MT framework, which generates high-quality training data through simulated agent-human interactions. Our models achieve state-of-the-art performance on [**BFCL**](https://gorilla.cs.berkeley.edu/leaderboard.html) and **τ-bench** benchmarks, outperforming frontier models like GPT-4o and Claude 3.5. Notably, even our smaller models demonstrate superior capabilities in multi-turn scenarios while maintaining exceptional consistency across trials.
39
+
40
+ We've also refined the **chat template** and **vLLM integration**, making it easier to build advanced AI agents. Compared to previous xLAM models, xLAM-2 offers superior performance and seamless deployment across applications.
41
+
42
+ <p align="center">
43
+ <img width="100%" alt="Model Performance Overview" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/model_board.png?raw=true">
44
+ <br>
45
+ <small><i>Comparative performance of larger xLAM-2-fc-r models (8B-70B, trained with APIGen-MT data) against state-of-the-art baselines on function-calling (BFCL v3, as of date 04/02/2025) and agentic (τ-bench) capabilities.</i></small>
46
+ </p>
47
+
48
+
49
+ ## Table of Contents
50
+ - [Usage](#usage)
51
+ - [Basic Usage with Huggingface Chat Template](#basic-usage-with-huggingface-chat-template)
52
+ - [Using vLLM for Inference](#using-vllm-for-inference)
53
+ - [Setup and Serving](#setup-and-serving)
54
+ - [Testing with OpenAI API](#testing-with-openai-api)
55
+ - [Benchmark Results](#benchmark-results)
56
+ - [Citation](#citation)
57
+
58
+ ---
59
+
60
+ ## Model Series
61
+
62
+ [xLAM](https://huggingface.co/collections/Salesforce/xlam-models-65f00e2a0a63bbcd1c2dade4) series are significant better at many things including general tasks and function calling.
63
+ For the same number of parameters, the model have been fine-tuned across a wide range of agent tasks and scenarios, all while preserving the capabilities of the original model.
64
+
65
+
66
+ | Model | # Total Params | Context Length | Category | Download Model | Download GGUF files |
67
+ |------------------------|----------------|------------|-------|----------------|----------|
68
+ | Llama-xLAM-2-70b-fc-r | 70B | 128k | Multi-turn Conversation, Function-calling | [🤗 Link](https://huggingface.co/Salesforce/Llama-xLAM-2-70b-fc-r) | NA |
69
+ | Llama-xLAM-2-8b-fc-r | 8B | 128k | Multi-turn Conversation, Function-calling | [🤗 Link](https://huggingface.co/Salesforce/Llama-xLAM-2-8b-fc-r) | [🤗 Link](https://huggingface.co/Salesforce/Llama-xLAM-2-8b-fc-r-gguf) |
70
+ | xLAM-2-32b-fc-r | 32B | 32k (max 128k)* | Multi-turn Conversation, Function-calling | [🤗 Link](https://huggingface.co/Salesforce/xLAM-2-32b-fc-r) | NA |
71
+ | xLAM-2-3b-fc-r | 3B | 32k (max 128k)* | Multi-turn Conversation, Function-calling | [🤗 Link](https://huggingface.co/Salesforce/xLAM-2-3b-fc-r) | [🤗 Link](https://huggingface.co/Salesforce/xLAM-2-3b-fc-r-gguf) |
72
+ | xLAM-2-1b-fc-r | 1B | 32k (max 128k)* | Multi-turn Conversation, Function-calling | [🤗 Link](https://huggingface.co/Salesforce/xLAM-2-1b-fc-r) | [🤗 Link](https://huggingface.co/Salesforce/xLAM-2-1b-fc-r-gguf) |
73
+
74
+ ***Note:** The default context length for Qwen-2.5-based models is 32k, but you can use techniques like YaRN (Yet Another Recursive Network) to achieve maximum 128k context length. Please refer to [here](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct#processing-long-texts) for more details.
75
+
76
+ You can also explore our previous xLAM series [here](https://huggingface.co/collections/Salesforce/xlam-models-65f00e2a0a63bbcd1c2dade4).
77
+
78
+ The `-fc` suffix indicates that the models are fine-tuned for **function calling** tasks, while the `-r` suffix signifies a **research** release.
79
+
80
+ ✅ All models are fully compatible with vLLM and Transformers-based inference frameworks.
81
+
82
+
83
+ ## Usage
84
+
85
+ ### Framework versions
86
+
87
+ - Transformers 4.46.1 (or later)
88
+ - PyTorch 2.5.1+cu124 (or later)
89
+ - Datasets 3.1.0 (or later)
90
+ - Tokenizers 0.20.3 (or later)
91
+
92
+ ### Basic Usage with Huggingface Chat Template
93
+
94
+ The new xLAM models are designed to work seamlessly with the Hugging Face Transformers library and utilize natural chat templates for an easy and intuitive conversational experience. Below are examples of how to use these models.
95
+
96
+ ```python
97
+ import torch
98
+ from transformers import AutoModelForCausalLM, AutoTokenizer
99
+
100
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/Llama-xLAM-2-3b-fc-r")
101
+ model = AutoModelForCausalLM.from_pretrained("Salesforce/Llama-xLAM-2-3b-fc-r", torch_dtype=torch.bfloat16, device_map="auto")
102
+
103
+ # Example conversation with a tool call
104
+ messages = [
105
+ {"role": "user", "content": "Hi, how are you?"},
106
+ {"role": "assistant", "content": "Thanks. I am doing well. How can I help you?"},
107
+ {"role": "user", "content": "What's the weather like in London?"},
108
+ ]
109
+
110
+ tools = [
111
+ {
112
+ "name": "get_weather",
113
+ "description": "Get the current weather for a location",
114
+ "parameters": {
115
+ "type": "object",
116
+ "properties": {
117
+ "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"},
118
+ "unit": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "The unit of temperature to return"}
119
+ },
120
+ "required": ["location"]
121
+ }
122
+ }
123
+ ]
124
+
125
+ print("====== prompt after applying chat template ======")
126
+ print(tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, tokenize=False))
127
+
128
+ inputs = tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, return_dict=True, return_tensors="pt")
129
+ input_ids_len = inputs["input_ids"].shape[-1] # Get the length of the input tokens
130
+ inputs = {k: v.to(model.device) for k, v in inputs.items()}
131
+ print("====== model response ======")
132
+ outputs = model.generate(**inputs, max_new_tokens=256)
133
+ generated_tokens = outputs[:, input_ids_len:] # Slice the output to get only the newly generated tokens
134
+ print(tokenizer.decode(generated_tokens[0], skip_special_tokens=True))
135
+ ```
136
+
137
+ ### Using vLLM for Inference
138
+
139
+ The xLAM models can also be efficiently served using vLLM for high-throughput inference. Please use `vllm>=0.6.5` since earlier versions will cause degraded performance for Qwen-based models.
140
+
141
+ #### Setup and Serving
142
+
143
+ 1. Install vLLM with the required version:
144
+ ```bash
145
+ pip install "vllm>=0.6.5"
146
+ ```
147
+
148
+ 2. Download the tool parser plugin to your local path:
149
+ ```bash
150
+ wget https://huggingface.co/Salesforce/xLAM-2-1b-fc-r/raw/main/xlam_tool_call_parser.py
151
+ ```
152
+
153
+ 3. Start the OpenAI API-compatible endpoint:
154
+ ```bash
155
+ vllm serve Salesforce/xLAM-2-1b-fc-r \
156
+ --enable-auto-tool-choice \
157
+ --tool-parser-plugin ./xlam_tool_call_parser.py \
158
+ --tool-call-parser xlam \
159
+ --tensor-parallel-size 1
160
+ ```
161
+
162
+ Note: Ensure that the tool parser plugin file is downloaded and that the path specified in `--tool-parser-plugin` correctly points to your local copy of the file. The xLAM series models all utilize the **same** tool call parser, so you only need to download it **once** for all models.
163
+
164
+ #### Testing with OpenAI API
165
+
166
+ Here's a minimal example to test tool usage with the served endpoint:
167
+
168
+ ```python
169
+ import openai
170
+ import json
171
+
172
+ # Configure the client to use your local vLLM endpoint
173
+ client = openai.OpenAI(
174
+ base_url="http://localhost:8000/v1", # Default vLLM server URL
175
+ api_key="empty" # Can be any string
176
+ )
177
+
178
+ # Define a tool/function
179
+ tools = [
180
+ {
181
+ "type": "function",
182
+ "function": {
183
+ "name": "get_weather",
184
+ "description": "Get the current weather for a location",
185
+ "parameters": {
186
+ "type": "object",
187
+ "properties": {
188
+ "location": {
189
+ "type": "string",
190
+ "description": "The city and state, e.g. San Francisco, CA"
191
+ },
192
+ "unit": {
193
+ "type": "string",
194
+ "enum": ["celsius", "fahrenheit"],
195
+ "description": "The unit of temperature to return"
196
+ }
197
+ },
198
+ "required": ["location"]
199
+ }
200
+ }
201
+ }
202
+ ]
203
+
204
+ # Create a chat completion
205
+ response = client.chat.completions.create(
206
+ model="Salesforce/xLAM-2-1b-fc-r", # Model name doesn't matter, vLLM uses the served model
207
+ messages=[
208
+ {"role": "system", "content": "You are a helpful assistant that can use tools."},
209
+ {"role": "user", "content": "What's the weather like in San Francisco?"}
210
+ ],
211
+ tools=tools,
212
+ tool_choice="auto"
213
+ )
214
+
215
+ # Print the response
216
+ print("Assistant's response:")
217
+ print(json.dumps(response.model_dump(), indent=2))
218
+ ```
219
+
220
+ For more advanced configurations and deployment options, please refer to the [vLLM documentation](https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html).
221
+
222
+ ## Benchmark Results
223
+
224
+ ### Berkeley Function-Calling Leaderboard (BFCL v3)
225
+ <p align="center">
226
+ <img width="80%" alt="BFCL Results" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/bfcl-result.png?raw=true">
227
+ <br>
228
+ <small><i>Performance comparison of different models on [BFCL leaderboard](https://gorilla.cs.berkeley.edu/leaderboard.html). The rank is based on the overall accuracy, which is a weighted average of different evaluation categories. "FC" stands for function-calling mode in contrast to using a customized "prompt" to extract the function calls.</i></small>
229
+ </p>
230
+
231
+ ### τ-bench Benchmark
232
+
233
+ <p align="center">
234
+ <img width="80%" alt="Tau-bench Results" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/taubench-result.png?raw=true">
235
+ <br>
236
+ <small><i>Success Rate (pass@1) on τ-bench benchmark averaged across at least 5 trials. Our xLAM-2-70b-fc-r model achieves an overall success rate of 56.2% on τ-bench, significantly outperforming the base Llama 3.1 70B Instruct model (38.2%) and other open-source models like DeepSeek v3 (40.6%). Notably, our best model even outperforms proprietary models such as GPT-4o (52.9%) and approaches the performance of more recent models like Claude 3.5 Sonnet (new) (60.1%).</i></small>
237
+ </p>
238
+
239
+ <p align="center">
240
+ <img width="80%" alt="Pass^k curves" src="https://github.com/apigen-mt/apigen-mt.github.io/blob/main/img/pass_k_curves_retail_airline.png?raw=true">
241
+ <br>
242
+ <small><i>Pass^k curves measuring the probability that all 5 independent trials succeed for a given task, averaged across all tasks for τ-retail (left) and τ-airline (right) domains. Higher values indicate better consistency of the models.</i></small>
243
+ </p>
244
+
245
+
246
+ ## Ethical Considerations
247
+
248
+ This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact people's lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.
249
+
250
+ ### Model Licenses
251
+
252
+ For all Llama relevant models, please also follow corresponding Llama license and terms. Meta Llama 3 is licensed under the Meta Llama 3 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
253
+
254
+ ## Citation
255
+
256
+ If you use our model or dataset in your work, please cite our paper:
257
+
258
+ ```bibtex
259
+ @article{prabhakar2025apigen,
260
+ title={APIGen-MT: Agentic PIpeline for Multi-Turn Data Generation via Simulated Agent-Human Interplay},
261
+ 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},
262
+ journal={arXiv preprint arXiv:2504.03601},
263
+ year={2025}
264
+ }
265
+ ```
266
+
267
+ Additionally, please check our other awesome related works regarding xLAM series and consider citing them as well:
268
+
269
+
270
+ ```bibtex
271
+ @article{zhang2025actionstudio,
272
+ title={ActionStudio: A Lightweight Framework for Data and Training of Action Models},
273
+ 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},
274
+ journal={arXiv preprint arXiv:2503.22673},
275
+ year={2025}
276
+ }
277
+ ```
278
+
279
+ ```bibtex
280
+ @article{zhang2024xlam,
281
+ title={xLAM: A Family of Large Action Models to Empower AI Agent Systems},
282
+ 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},
283
+ journal={arXiv preprint arXiv:2409.03215},
284
+ year={2024}
285
+ }
286
+
287
+ ```
288
+
289
+ ```bibtex
290
+ @article{liu2024apigen,
291
+ title={Apigen: Automated pipeline for generating verifiable and diverse function-calling datasets},
292
+ 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},
293
+ journal={Advances in Neural Information Processing Systems},
294
+ volume={37},
295
+ pages={54463--54482},
296
+ year={2024}
297
+ }
298
+ ```
299
+
300
+ ```bibtex
301
+ @article{zhang2024agentohana,
302
+ title={AgentOhana: Design Unified Data and Training Pipeline for Effective Agent Learning},
303
+ 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},
304
+ journal={arXiv preprint arXiv:2402.15506},
305
+ year={2024}
306
+ }
307
+ ```
308
+
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Salesforce/xLAM-2-3b-fc-r",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 2048,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 11008,
13
+ "max_position_embeddings": 32768,
14
+ "max_window_layers": 70,
15
+ "model_type": "qwen2",
16
+ "num_attention_heads": 16,
17
+ "num_hidden_layers": 36,
18
+ "num_key_value_heads": 2,
19
+ "rms_norm_eps": 1e-06,
20
+ "rope_scaling": null,
21
+ "rope_theta": 1000000.0,
22
+ "sliding_window": null,
23
+ "tie_word_embeddings": true,
24
+ "torch_dtype": "bfloat16",
25
+ "transformers_version": "4.46.1",
26
+ "use_cache": false,
27
+ "use_sliding_window": false,
28
+ "vocab_size": 151936
29
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "repetition_penalty": 1.05,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "4.46.1"
14
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
3
+ size 11421896
tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{# System message #}\n{{- \"<|im_start|>system\\n\" }}\n{%- if messages[0]['role'] == 'system' %}\n {%- set system_message = messages[0]['content'] | trim %}\n {%- set messages = messages[1:] %}\n {{- system_message + \"\\n\" }}\n{%- else %}\n {%- set system_message = \"You are a helpful assistant that can use tools. You are developed by Salesforce xLAM team.\" %}\n {% set format_instruction %}You have access to a set of tools. When using tools, make calls in a single JSON array: \n\n[{\"name\": \"tool_call_name\", \"arguments\": {\"arg1\": \"value1\", \"arg2\": \"value2\"}}, ... (additional parallel tool calls as needed)]\n\nIf no tool is suitable, state that explicitly. If the user's input lacks required parameters, ask for clarification. Do not interpret or respond until tool results are returned. Once they are available, process them or make additional calls if needed. For tasks that don't require tools, such as casual conversation or general advice, respond directly in plain text. The available tools are:{% endset %}\n {{- system_message + \"\\n\" }}\n {%- if tools is not none %}\n {{- format_instruction + \"\\n\\n\" }}\n {%- endif %}\n{%- endif %}\n\n{%- if tools is not none %}\n {%- for func in tools %}\n {{- func | tojson(indent=4) }}\n {{- \"\\n\\n\" }}\n {%- endfor %}\n{%- endif %}\n{{- \"<|im_end|>\" }}\n{%- for message in messages %}\n {%- if message['role'] == 'tool' %}\n {{- \"<|im_start|>tool\\n\" }}\n {%- if message.content is defined and message.content.content is defined %}\n {%- set content = message.content.content %}\n {%- else %}\n {%- set content = message.content %}\n {%- endif %}\n {%- if content is mapping or content is iterable and content is not string %}\n {{- content | tojson }}\n {%- else %}\n {{- content }}\n {%- endif %}\n {{- \"<|im_end|>\" }}\n {%- elif 'tool_calls' in message %}\n {{- \"<|im_start|>assistant\\n\" }}\n {%- if message['tool_calls'] %}\n {{- \"[\" }}\n {%- for tool_call in message.tool_calls %}\n {%- set out = tool_call.function | tojson %}\n {{- out }}\n {%- if not loop.last %}\n {{- \", \" }}\n {%- endif %}\n {%- endfor %}\n {{- \"]\"}}\n {%- elif message['content'] %}\n {{- message['content'] | trim }}\n {%- else %}\n {{- \"[]\\n\" }}\n {%- endif %}\n {{- \"<|im_end|>\" }}\n {%- else %}\n {{- \"<|im_start|>\" + message['role'] + \"\\n\" + message['content'] | trim + \"<|im_end|>\" }}\n {%- endif %}\n{%- endfor %}\n\n{%- if add_generation_prompt %}\n {{- \"<|im_start|>assistant\\n\" }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "model_max_length": 16384,
203
+ "pad_token": "<|endoftext|>",
204
+ "padding_side": "right",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
xLAM-2-3b-fc-r-SpinQuant.pte ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b947c3a9ef9de261d7281396f2252ad9ea1ce1e321e88bb8156438e729d76b05
3
+ size 2362543232
xlam_tool_call_parser.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import re
3
+ from typing import Dict, List, Sequence, Union
4
+ import partial_json_parser
5
+ from partial_json_parser.core.options import Allow
6
+
7
+ from vllm.entrypoints.openai.protocol import (
8
+ ChatCompletionRequest, DeltaMessage, DeltaToolCall,
9
+ DeltaFunctionCall, ExtractedToolCallInformation, ToolCall, FunctionCall
10
+ )
11
+ from vllm.entrypoints.openai.tool_parsers.abstract_tool_parser import ToolParser, ToolParserManager
12
+ from vllm.utils import random_uuid
13
+ from vllm.logger import init_logger
14
+ from transformers import PreTrainedTokenizerBase
15
+ from vllm.entrypoints.openai.tool_parsers.utils import (find_common_prefix,
16
+ is_complete_json,
17
+ partial_json_loads)
18
+
19
+ logger = init_logger(__name__)
20
+
21
+ @ToolParserManager.register_module("xlam")
22
+ class xLAMToolParser(ToolParser):
23
+ def __init__(self, tokenizer: PreTrainedTokenizerBase):
24
+ super().__init__(tokenizer)
25
+ # State for streaming mode
26
+ self.prev_tool_calls: List[Dict] = []
27
+ self.current_tools_sent: List[bool] = []
28
+ self.streamed_args: List[str] = []
29
+ # Remove regex since we're parsing direct JSON
30
+
31
+ def extract_tool_calls(
32
+ self,
33
+ model_output: str,
34
+ request: ChatCompletionRequest
35
+ ) -> ExtractedToolCallInformation:
36
+ try:
37
+ # Modified: Direct JSON parsing without looking for ```
38
+ if not model_output.strip().startswith('['):
39
+ return ExtractedToolCallInformation(
40
+ tools_called=False,
41
+ tool_calls=[],
42
+ content=model_output
43
+ )
44
+
45
+ tool_calls_data = json.loads(model_output)
46
+ tool_calls: List[ToolCall] = []
47
+
48
+ for idx, call in enumerate(tool_calls_data):
49
+ tool_call = ToolCall(
50
+ id=f"call_{idx}_{random_uuid()}",
51
+ type="function",
52
+ function=FunctionCall(
53
+ name=call["name"],
54
+ arguments=json.dumps(call["arguments"])
55
+ )
56
+ )
57
+ tool_calls.append(tool_call)
58
+
59
+ return ExtractedToolCallInformation(
60
+ tools_called=True,
61
+ tool_calls=tool_calls,
62
+ content=None
63
+ )
64
+
65
+ except Exception:
66
+ logger.exception("Error extracting tool calls")
67
+ return ExtractedToolCallInformation(
68
+ tools_called=False,
69
+ tool_calls=[],
70
+ content=model_output
71
+ )
72
+
73
+ def extract_tool_calls_streaming(
74
+ self,
75
+ previous_text: str,
76
+ current_text: str,
77
+ delta_text: str,
78
+ previous_token_ids: Sequence[int],
79
+ current_token_ids: Sequence[int],
80
+ delta_token_ids: Sequence[int],
81
+ request: ChatCompletionRequest,
82
+ ) -> Union[DeltaMessage, None]:
83
+ if not current_text.strip().startswith('['):
84
+ return DeltaMessage(content=delta_text)
85
+
86
+ flags = Allow.ALL if self.current_tool_name_sent else Allow.ALL & ~Allow.STR
87
+
88
+ try:
89
+ tool_call_arr = []
90
+ is_complete = []
91
+ try:
92
+ # Parse the JSON array
93
+ start_idx = 0
94
+ while start_idx < len(current_text):
95
+ obj, end_idx = partial_json_loads(current_text[start_idx:], flags)
96
+ is_complete.append(
97
+ is_complete_json(current_text[start_idx:start_idx + end_idx])
98
+ )
99
+ start_idx += end_idx
100
+ tool_call_arr.append(obj)
101
+ except partial_json_parser.core.exceptions.MalformedJSON:
102
+ logger.debug('not enough tokens to parse into JSON yet')
103
+ return None
104
+
105
+ # Get current tool call based on state
106
+ current_tool_call: Dict = tool_call_arr[self.current_tool_id] \
107
+ if len(tool_call_arr) > 0 else {}
108
+
109
+ # Case 1: No tools parsed yet
110
+ if len(tool_call_arr) == 0:
111
+ return None
112
+
113
+ # Case 2: Starting a new tool in array
114
+ elif (len(tool_call_arr) > 0
115
+ and len(tool_call_arr) > self.current_tool_id + 1):
116
+
117
+ # Handle any remaining arguments from previous tool
118
+ if self.current_tool_id >= 0:
119
+ cur_arguments = current_tool_call.get("arguments")
120
+ if cur_arguments:
121
+ cur_args_json = json.dumps(cur_arguments)
122
+ sent = len(self.streamed_args[self.current_tool_id])
123
+ argument_diff = cur_args_json[sent:]
124
+
125
+ if argument_diff:
126
+ delta = DeltaMessage(tool_calls=[
127
+ DeltaToolCall(
128
+ index=self.current_tool_id,
129
+ function=DeltaFunctionCall(
130
+ arguments=argument_diff
131
+ ).model_dump(exclude_none=True)
132
+ )
133
+ ])
134
+ self.streamed_args[self.current_tool_id] += argument_diff
135
+ return delta
136
+
137
+ # Setup new tool
138
+ self.current_tool_id = len(tool_call_arr) - 1
139
+ self.current_tools_sent.append(False)
140
+ self.streamed_args.append("")
141
+ logger.debug("starting new tool %d", self.current_tool_id)
142
+ return None
143
+
144
+ # Case 3: Send tool name if not sent yet
145
+ elif not self.current_tools_sent[self.current_tool_id]:
146
+ function_name = current_tool_call.get("name")
147
+ if function_name:
148
+ delta = DeltaMessage(tool_calls=[
149
+ DeltaToolCall(
150
+ index=self.current_tool_id,
151
+ type="function",
152
+ id=f"call_{self.current_tool_id}_{random_uuid()}",
153
+ function=DeltaFunctionCall(
154
+ name=function_name
155
+ ).model_dump(exclude_none=True)
156
+ )
157
+ ])
158
+ self.current_tools_sent[self.current_tool_id] = True
159
+ return delta
160
+ return None
161
+
162
+ # Case 4: Stream arguments
163
+ else:
164
+ cur_arguments = current_tool_call.get("arguments")
165
+ if cur_arguments:
166
+ sent = len(self.streamed_args[self.current_tool_id])
167
+ cur_args_json = json.dumps(cur_arguments)
168
+ prev_arguments = self.prev_tool_calls[self.current_tool_id].get("arguments")
169
+
170
+ argument_diff = None
171
+ if is_complete[self.current_tool_id]:
172
+ argument_diff = cur_args_json[sent:]
173
+ elif prev_arguments:
174
+ prev_args_json = json.dumps(prev_arguments)
175
+ if cur_args_json != prev_args_json:
176
+ prefix = find_common_prefix(prev_args_json, cur_args_json)
177
+ argument_diff = prefix[sent:]
178
+
179
+ if argument_diff is not None:
180
+ delta = DeltaMessage(tool_calls=[
181
+ DeltaToolCall(
182
+ index=self.current_tool_id,
183
+ function=DeltaFunctionCall(
184
+ arguments=argument_diff
185
+ ).model_dump(exclude_none=True)
186
+ )
187
+ ])
188
+ self.streamed_args[self.current_tool_id] += argument_diff
189
+ return delta
190
+
191
+ self.prev_tool_calls = tool_call_arr
192
+ return None
193
+
194
+ except Exception:
195
+ logger.exception("Error in streaming tool calls")
196
+ logger.debug("Skipping chunk due to streaming error")
197
+ return None
198
+