vikramdgx commited on
Commit
2c8eefc
·
verified ·
1 Parent(s): 389246b

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ 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
README.md ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ license: apache-2.0
4
+ base_model: Qwen/Qwen2.5-Coder-7B-Instruct
5
+ tags:
6
+ - security
7
+ - vulnerability-detection
8
+ - injection
9
+ - code-analysis
10
+ - lora
11
+ - qwen2
12
+ - cybersecurity
13
+ - sast
14
+ - cwe
15
+ datasets:
16
+ - hitoshura25/cvefixes
17
+ - claudios/DiverseVul
18
+ - CyberNative/Code_Vulnerability_Security_DPO
19
+ - UCSB-SURFI/VulnLLM-R-Train-Data
20
+ - CIRCL/vulnerability-cwe-patch
21
+ language:
22
+ - en
23
+ - code
24
+ pipeline_tag: text-generation
25
+ model-index:
26
+ - name: injection-vulnerability-detector
27
+ results:
28
+ - task:
29
+ type: text-generation
30
+ name: Injection Vulnerability Detection
31
+ dataset:
32
+ name: Injection Vulnerability Novel Test Set (leakage-controlled)
33
+ type: injection-vuln-novel
34
+ metrics:
35
+ - name: F1
36
+ type: f1
37
+ value: 0.6803519061583577
38
+ verified: false
39
+ - name: Precision
40
+ type: precision
41
+ value: 0.8169014084507042
42
+ verified: false
43
+ - name: Recall
44
+ type: recall
45
+ value: 0.5829145728643216
46
+ verified: false
47
+ ---
48
+
49
+ # Injection Vulnerability Detector v1.0
50
+
51
+ A fine-tuned **Qwen2.5-Coder-7B-Instruct** model specialized in detecting injection
52
+ vulnerabilities in source code. Built with LoRA (Low-Rank Adaptation) for efficient
53
+ fine-tuning on consumer/workstation hardware.
54
+
55
+ **Key contribution:** Existing vulnerability datasets lack CWE-specific labels for
56
+ injection subtypes — most group all injections generically, and rare types like LDAP,
57
+ XPath, EL injection, and SSTI have near-zero representation. We solved this with a
58
+ **template-based synthetic data generator** (151 templates, 9 CWEs) that produces
59
+ CWE-specific injection samples at scale without requiring an LLM, combined with
60
+ filtered real-world vulnerability data from open-source datasets.
61
+
62
+ ## What it does
63
+
64
+ Given a code snippet, the model identifies whether it contains an **injection vulnerability**
65
+ and, if so, classifies the specific CWE (Common Weakness Enumeration) type. It outputs
66
+ structured JSON with a verdict, CWE ID, vulnerability type, tainted data-flow analysis,
67
+ an explanation, and a fix suggestion.
68
+
69
+ ### Supported vulnerability types (9 CWEs)
70
+
71
+ | CWE | Vulnerability Type |
72
+ |-----|-------------------|
73
+ | CWE-89 | SQL Injection |
74
+ | CWE-78 | OS Command Injection |
75
+ | CWE-94 | Code Injection |
76
+ | CWE-611 | XXE (XML External Entity) |
77
+ | CWE-90 | LDAP Injection |
78
+ | CWE-643 | XPath Injection |
79
+ | CWE-917 | Expression Language Injection |
80
+ | CWE-1336 | Server-Side Template Injection (SSTI) |
81
+ | CWE-113 | HTTP Response Splitting / Header Injection |
82
+
83
+ ## Evaluation results
84
+
85
+ **Our primary metrics are computed on novel code only** (template clones removed; the full-set figure is shown for comparison) — test samples verified
86
+ to be structurally distinct from all training data. Of 1572 total
87
+ test samples, 1007 (64.1%) were identified as structural
88
+ clones of training data and excluded (see Evaluation Methodology below).
89
+
90
+ ### Evaluation: three levels of rigor
91
+
92
+ | Evaluation set | Precision | Recall | F1 |
93
+ |---|---|---|---|
94
+ | Full test set (includes template clones) | 96.2% | 83.6% | **89.5%** |
95
+ | Novel code, all injection-related CWEs (n=565) | 82.8% | 46.6% | 59.7% |
96
+ | **Novel code, in-scope 9 target CWEs (n=496)** | **81.7%** | **58.3%** | **68.0%** |
97
+
98
+ Our **primary metric is the in-scope novel row** — performance on the 9 CWEs the model targets, on code it has never seen in any structural form. The full-set figure is what most detectors report; we consider it inflated by template-clone memorisation (see Evaluation Methodology). The all-CWE novel row additionally counts out-of-scope vulnerability types the model does not target.
99
+
100
+ ### Primary metrics (novel code, in-scope 9 CWEs, n=496)
101
+
102
+ | Metric | Score |
103
+ |--------|-------|
104
+ | **Precision** | 81.7% |
105
+ | **Recall** | 58.3% |
106
+ | **F1 Score** | 68.0% |
107
+ | **Accuracy** | 78.0% |
108
+ | JSON Parse Rate | 94.9% |
109
+
110
+ ### Per-CWE performance (novel code)
111
+
112
+ | CWE | Vulnerability | Precision | Recall | F1 | Samples |
113
+ |-----|--------------|-----------|--------|-----|---------|
114
+ | CWE-89 | SQL Injection | 76.5% | 67.2% | 71.6% | 58 |
115
+ | CWE-78 | OS Command Injection | 75.9% | 42.3% | 54.3% | 52 |
116
+ | CWE-94 | Code Injection | 77.4% | 46.2% | 57.8% | 52 |
117
+ | CWE-611 | XXE (XML External Entity) | 100.0% | 75.0% | 85.7% | 16 |
118
+ | CWE-90 | LDAP Injection | 100.0% | 60.0% | 75.0% | 5 |
119
+ | CWE-643 | XPath Injection | 100.0% | 100.0% | 100.0% | 4 |
120
+ | CWE-917 | Expression Language Injection | 100.0% | 100.0% | 100.0% | 2 |
121
+ | CWE-1336 | Server-Side Template Injection | 100.0% | 100.0% | 100.0% | 6 |
122
+ | CWE-113 | HTTP Response Splitting | 100.0% | 100.0% | 100.0% | 4 |
123
+
124
+ ### Evaluation methodology
125
+
126
+ Standard group-aware splitting (by CVE ID / project) prevents the *same* code
127
+ from appearing in both train and test, but it does not prevent **template
128
+ clones** — structurally identical code differing only in variable names,
129
+ string literals, and numeric constants — from leaking across the split. A
130
+ skeleton-hashing analysis revealed that 64.1% of the initial test set
131
+ were structural clones of training samples, scoring near-perfect F1 from
132
+ memorisation rather than generalisation.
133
+
134
+ **Skeleton hashing method:** strip comments, string literals, identifiers, and
135
+ numeric literals from each code sample, then SHA-256 hash the normalised
136
+ skeleton. Any test sample whose skeleton matches a training sample is
137
+ classified as a clone and excluded from the metrics reported above.
138
+
139
+ The scores above therefore reflect performance on genuinely novel code that
140
+ the model has never seen in any structural form during training. We report
141
+ these numbers — not the inflated full-test-set figures — because they are
142
+ what matters for real-world deployment.
143
+
144
+ ## Usage
145
+
146
+ ### Quick start with transformers + PEFT
147
+
148
+ ```python
149
+ from peft import PeftModel
150
+ from transformers import AutoModelForCausalLM, AutoTokenizer
151
+
152
+ # Load base model + LoRA adapter
153
+ base_model = AutoModelForCausalLM.from_pretrained(
154
+ "Qwen/Qwen2.5-Coder-7B-Instruct",
155
+ torch_dtype="auto",
156
+ device_map="auto",
157
+ )
158
+ model = PeftModel.from_pretrained(base_model, "vikramdgx/injection-vulnerability-detector")
159
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct")
160
+
161
+ # Analyze code — use the EXACT prompt format the model was trained on
162
+ code_snippet = '''import sqlite3
163
+ def get_user(username):
164
+ conn = sqlite3.connect("app.db")
165
+ query = f"SELECT * FROM users WHERE name = '{username}'"
166
+ return conn.execute(query).fetchone()
167
+ '''
168
+
169
+ SYSTEM_PROMPT = (
170
+ "You are a code security analyzer specialized in detecting injection "
171
+ "vulnerabilities. Analyze the provided code and respond with a JSON "
172
+ "object containing: verdict, cwe, vulnerability_type, tainted_flow, "
173
+ "explanation, and fix_suggestion."
174
+ )
175
+
176
+ user_message = (
177
+ "Analyze the following code for injection vulnerabilities. "
178
+ "Respond with JSON.\n\n"
179
+ + code_snippet
180
+ )
181
+
182
+ messages = [
183
+ {"role": "system", "content": SYSTEM_PROMPT},
184
+ {"role": "user", "content": user_message},
185
+ ]
186
+
187
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
188
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
189
+ outputs = model.generate(**inputs, max_new_tokens=768, do_sample=False)
190
+ response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
191
+ print(response)
192
+ ```
193
+
194
+ ### Expected output format
195
+
196
+ The model returns structured JSON matching its training schema:
197
+
198
+ ```json
199
+ {
200
+ "verdict": "VULNERABLE",
201
+ "cwe": "CWE-89",
202
+ "vulnerability_type": "SQL Injection",
203
+ "tainted_flow": {
204
+ "source": "username parameter",
205
+ "sink": "conn.execute(query)",
206
+ "sanitizer": null
207
+ },
208
+ "explanation": "User input is directly interpolated into SQL query string via f-string without parameterization, enabling SQL injection.",
209
+ "fix_suggestion": "Use parameterized queries: conn.execute('SELECT * FROM users WHERE name = ?', (username,))"
210
+ }
211
+ ```
212
+
213
+ For safe code, the model returns:
214
+
215
+ ```json
216
+ {
217
+ "verdict": "SAFE",
218
+ "cwe": null,
219
+ "vulnerability_type": null,
220
+ "tainted_flow": null,
221
+ "explanation": "No injection vulnerability detected.",
222
+ "fix_suggestion": null
223
+ }
224
+ ```
225
+
226
+ ## Training details
227
+
228
+ ### Hardware
229
+
230
+ - **NVIDIA DGX Spark** (Grace Blackwell GB10)
231
+ - 128 GB unified LPDDR5X memory
232
+ - CUDA 13.0, compute capability sm_121
233
+
234
+ ### Configuration
235
+
236
+ | Parameter | Value |
237
+ |-----------|-------|
238
+ | Base model | Qwen/Qwen2.5-Coder-7B-Instruct |
239
+ | Method | LoRA (PEFT) |
240
+ | LoRA rank (r) | 16 |
241
+ | LoRA alpha | 32 |
242
+ | Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
243
+ | Trainable parameters | 40.3M (0.53% of total) |
244
+ | Epochs | 3 |
245
+ | Batch size | 2 (gradient accumulation: 4, effective 8) |
246
+ | Learning rate | 2e-4 |
247
+ | Max sequence length | 4096 |
248
+ | Optimizer | AdamW (8-bit) |
249
+ | LR scheduler | Cosine |
250
+ | Packing | Enabled |
251
+ | Loss | Completion-only |
252
+
253
+ ### Why we built a custom dataset
254
+
255
+ Existing open-source vulnerability datasets (CVEfixes, DiverseVul, BigVul, etc.)
256
+ provide valuable real-world code samples, but they share a common gap: **they lack
257
+ fine-grained, CWE-specific labels for injection subtypes.** Most label code broadly
258
+ as "vulnerable" or group all injections under generic categories like CWE-74 or
259
+ CWE-20 — without distinguishing SQL injection (CWE-89) from command injection
260
+ (CWE-78) from SSTI (CWE-1336). For niche injection types like LDAP injection
261
+ (CWE-90), XPath injection (CWE-643), or EL injection (CWE-917), labeled samples
262
+ in public datasets are extremely scarce (often single digits).
263
+
264
+ This makes it impossible to train a detector that both identifies vulnerabilities
265
+ AND classifies the specific CWE type — which is what security engineers actually
266
+ need for triage.
267
+
268
+ ### Our approach: template-based synthetic generation
269
+
270
+ To solve this, we built a **procedural code generator** that produces CWE-specific
271
+ injection samples at scale — no LLM in the loop, pure template expansion:
272
+
273
+ - **151 handcrafted code templates** covering all 9 target CWEs, each with
274
+ `@@PLACEHOLDER@@` tokens for variable names, function names, table names,
275
+ database fields, and code patterns
276
+ - **Randomized variable pools** (200+ variable names, 100+ function names, 50+
277
+ table names per CWE) ensure each generated sample is syntactically unique
278
+ - **Paired generation**: every vulnerable template has a corresponding safe version
279
+ that uses parameterized queries, input validation, or proper escaping — teaching
280
+ the model the difference, not just the pattern
281
+ - **~5,000 synthetic samples** generated in seconds, balanced across all 9 CWEs
282
+ including the rare ones that have near-zero representation in public datasets
283
+
284
+ This approach is deterministic, reproducible, and produces exactly the CWE
285
+ distribution the model needs — no data collection bottleneck, no labeling errors,
286
+ no class imbalance.
287
+
288
+ ### Dataset composition
289
+
290
+ The final training set combines three sources:
291
+
292
+ 1. **Real-world vulnerabilities** — filtered from open-source CVE/vulnerability
293
+ datasets, keeping only injection-related CWEs. Provides realistic code patterns
294
+ from production software.
295
+ 2. **Template-based synthetic data** (~5,000 samples) — our original procedural
296
+ generator. Fills the CWE-specific gap that public datasets leave open,
297
+ especially for rare injection types (LDAP, XPath, EL, SSTI, Header Injection).
298
+ 3. **Hard negatives** — safe code samples including post-patch fixes and
299
+ non-vulnerable functions from vulnerability-adjacent codebases. Teaches the
300
+ model what secure code looks like.
301
+
302
+ Group-aware splitting ensures no data leakage between train and test sets (samples
303
+ sharing a CVE ID or project stay together). Additionally, a skeleton-hashing pass
304
+ excludes structural template clones from the evaluation set (see Evaluation
305
+ Methodology above).
306
+
307
+ ## Dataset sources and attribution
308
+
309
+ This model was trained on data from the following open-source datasets, combined
310
+ with our original synthetic generation. We gratefully acknowledge the dataset creators:
311
+
312
+ | Dataset | Source | License | Role |
313
+ |---------|--------|---------|------|
314
+ | [CVEfixes](https://huggingface.co/datasets/hitoshura25/cvefixes) | Bhandari et al. | Apache 2.0 (data: CC BY 4.0) | Real-world vuln + patch pairs |
315
+ | [DiverseVul](https://huggingface.co/datasets/claudios/DiverseVul) | Chen & Bhatt (RAID 2023) | Not specified on HF card | Safe code (non-vuln functions) |
316
+ | [Code Vulnerability Security DPO](https://huggingface.co/datasets/CyberNative/Code_Vulnerability_Security_DPO) | CyberNative AI | Apache 2.0 | Injection code examples |
317
+ | [VulnLLM-R Train Data](https://huggingface.co/datasets/UCSB-SURFI/VulnLLM-R-Train-Data) | UCSB SURFI | Not specified on HF card | Real-world vuln functions |
318
+ | [CIRCL Vulnerability CWE Patch](https://huggingface.co/datasets/CIRCL/vulnerability-cwe-patch) | CIRCL (Luxembourg CERT) | Not specified on HF card | Vuln + patch pairs |
319
+ | **Template-based synthetic generator** | **Original work** | **Apache 2.0** | **CWE-specific injection samples (core contribution)** |
320
+
321
+ **License notes:**
322
+
323
+ - The `securecode-web` dataset (CC BY-NC-SA 4.0) is **not** included in this
324
+ release. It is available as an opt-in source via `--include-nc` for non-commercial use only.
325
+ - Three source datasets (DiverseVul, VulnLLM-R, CIRCL) do not declare an explicit
326
+ license on their HuggingFace cards as of this writing. This model's own adapter
327
+ weights are original work released under Apache 2.0, but users should check the
328
+ current licensing status of these upstream datasets before commercial deployment.
329
+
330
+ ## Limitations
331
+
332
+ - **Injection-only scope:** This model detects 9 injection-related CWEs. It does not
333
+ cover other vulnerability classes (buffer overflow, authentication, crypto, etc.).
334
+ - **Synthetic training bias:** The model is trained partly on template-generated code.
335
+ While this solves the CWE-distribution problem, performance on novel real-world
336
+ patterns is lower than on template-similar code, reflecting the generalisation gap
337
+ that template-based training introduces. See Evaluation Results for exact numbers.
338
+ - **Rare CWEs are synthetic-validated only:** The five rare injection types (LDAP,
339
+ XPath, EL, SSTI, Header) have near-zero representation in public vulnerability
340
+ datasets. Our evaluation on novel code therefore cannot validate these CWEs —
341
+ their coverage relies entirely on synthetic templates. Real-world performance on
342
+ these types is unknown.
343
+ - **CWE classification accuracy:** While detection (vulnerable vs. safe) is reliable,
344
+ the specific CWE label assigned to a detected vulnerability may be incorrect in some
345
+ cases — particularly between similar injection types (e.g. CWE-94 vs CWE-74).
346
+ - **Code context:** The model analyzes individual functions/snippets. It cannot trace
347
+ data flow across files or understand application-level sanitization.
348
+ - **Language coverage:** Primarily trained on Python, Java, PHP, C/C++, and JavaScript.
349
+ Performance on other languages may vary.
350
+ - **Not a replacement for manual review:** Use as a triage/prioritization tool alongside
351
+ established SAST tooling and expert code review.
352
+
353
+ ## License
354
+
355
+ This model adapter is released under the **Apache 2.0** license. The base model
356
+ (Qwen2.5-Coder-7B-Instruct) is also Apache 2.0.
357
+
358
+ ## Citation
359
+
360
+ If you use this model in your research, please cite:
361
+
362
+ ```bibtex
363
+ @misc{injection-detector-v10,
364
+ title={Injection Vulnerability Detector v1.0},
365
+ author={Thrivikram Gujarathi},
366
+ year={2026},
367
+ publisher={HuggingFace},
368
+ url={https://huggingface.co/vikramdgx/injection-vulnerability-detector}
369
+ }
370
+ ```
adapter_config.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": {
6
+ "base_model_class": "Qwen2ForCausalLM",
7
+ "parent_library": "transformers.models.qwen2.modeling_qwen2",
8
+ "unsloth_fixed": true
9
+ },
10
+ "base_model_name_or_path": "unsloth/Qwen2.5-Coder-7B-Instruct",
11
+ "bias": "none",
12
+ "corda_config": null,
13
+ "ensure_weight_tying": false,
14
+ "eva_config": null,
15
+ "exclude_modules": null,
16
+ "fan_in_fan_out": false,
17
+ "inference_mode": true,
18
+ "init_lora_weights": true,
19
+ "layer_replication": null,
20
+ "layers_pattern": null,
21
+ "layers_to_transform": null,
22
+ "loftq_config": {},
23
+ "lora_alpha": 32,
24
+ "lora_bias": false,
25
+ "lora_dropout": 0.0,
26
+ "lora_ga_config": null,
27
+ "megatron_config": null,
28
+ "megatron_core": "megatron.core",
29
+ "modules_to_save": null,
30
+ "monteclora_config": null,
31
+ "peft_type": "LORA",
32
+ "peft_version": "0.20.0",
33
+ "qalora_group_size": 16,
34
+ "r": 16,
35
+ "rank_pattern": {},
36
+ "revision": null,
37
+ "target_modules": [
38
+ "o_proj",
39
+ "gate_proj",
40
+ "q_proj",
41
+ "up_proj",
42
+ "v_proj",
43
+ "k_proj",
44
+ "down_proj"
45
+ ],
46
+ "target_parameters": null,
47
+ "task_type": "CAUSAL_LM",
48
+ "trainable_token_indices": null,
49
+ "use_bdlora": null,
50
+ "use_dora": false,
51
+ "use_qalora": false,
52
+ "use_rslora": false,
53
+ "velora_config": null
54
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:39010a870e8136d374b66bf242f86fa23cdd9f2fa1e971394ef8982c3ef84229
3
+ size 161533192
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\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>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\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" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea43b288542655d72d632195ab9b58ca2cd9532c292bf6667827ce899ad196bc
3
+ size 11422082
tokenizer_config.json ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "local_files_only": false,
25
+ "model_max_length": 32768,
26
+ "pad_token": "<|PAD_TOKEN|>",
27
+ "padding_side": "left",
28
+ "split_special_tokens": false,
29
+ "tokenizer_class": "Qwen2Tokenizer",
30
+ "unk_token": null,
31
+ "added_tokens_decoder": {
32
+ "151643": {
33
+ "content": "<|endoftext|>",
34
+ "single_word": false,
35
+ "lstrip": false,
36
+ "rstrip": false,
37
+ "normalized": false,
38
+ "special": true
39
+ },
40
+ "151644": {
41
+ "content": "<|im_start|>",
42
+ "single_word": false,
43
+ "lstrip": false,
44
+ "rstrip": false,
45
+ "normalized": false,
46
+ "special": true
47
+ },
48
+ "151645": {
49
+ "content": "<|im_end|>",
50
+ "single_word": false,
51
+ "lstrip": false,
52
+ "rstrip": false,
53
+ "normalized": false,
54
+ "special": true
55
+ },
56
+ "151646": {
57
+ "content": "<|object_ref_start|>",
58
+ "single_word": false,
59
+ "lstrip": false,
60
+ "rstrip": false,
61
+ "normalized": false,
62
+ "special": true
63
+ },
64
+ "151647": {
65
+ "content": "<|object_ref_end|>",
66
+ "single_word": false,
67
+ "lstrip": false,
68
+ "rstrip": false,
69
+ "normalized": false,
70
+ "special": true
71
+ },
72
+ "151648": {
73
+ "content": "<|box_start|>",
74
+ "single_word": false,
75
+ "lstrip": false,
76
+ "rstrip": false,
77
+ "normalized": false,
78
+ "special": true
79
+ },
80
+ "151649": {
81
+ "content": "<|box_end|>",
82
+ "single_word": false,
83
+ "lstrip": false,
84
+ "rstrip": false,
85
+ "normalized": false,
86
+ "special": true
87
+ },
88
+ "151650": {
89
+ "content": "<|quad_start|>",
90
+ "single_word": false,
91
+ "lstrip": false,
92
+ "rstrip": false,
93
+ "normalized": false,
94
+ "special": true
95
+ },
96
+ "151651": {
97
+ "content": "<|quad_end|>",
98
+ "single_word": false,
99
+ "lstrip": false,
100
+ "rstrip": false,
101
+ "normalized": false,
102
+ "special": true
103
+ },
104
+ "151652": {
105
+ "content": "<|vision_start|>",
106
+ "single_word": false,
107
+ "lstrip": false,
108
+ "rstrip": false,
109
+ "normalized": false,
110
+ "special": true
111
+ },
112
+ "151653": {
113
+ "content": "<|vision_end|>",
114
+ "single_word": false,
115
+ "lstrip": false,
116
+ "rstrip": false,
117
+ "normalized": false,
118
+ "special": true
119
+ },
120
+ "151654": {
121
+ "content": "<|vision_pad|>",
122
+ "single_word": false,
123
+ "lstrip": false,
124
+ "rstrip": false,
125
+ "normalized": false,
126
+ "special": true
127
+ },
128
+ "151655": {
129
+ "content": "<|image_pad|>",
130
+ "single_word": false,
131
+ "lstrip": false,
132
+ "rstrip": false,
133
+ "normalized": false,
134
+ "special": true
135
+ },
136
+ "151656": {
137
+ "content": "<|video_pad|>",
138
+ "single_word": false,
139
+ "lstrip": false,
140
+ "rstrip": false,
141
+ "normalized": false,
142
+ "special": true
143
+ },
144
+ "151657": {
145
+ "content": "<tool_call>",
146
+ "single_word": false,
147
+ "lstrip": false,
148
+ "rstrip": false,
149
+ "normalized": false,
150
+ "special": false
151
+ },
152
+ "151658": {
153
+ "content": "</tool_call>",
154
+ "single_word": false,
155
+ "lstrip": false,
156
+ "rstrip": false,
157
+ "normalized": false,
158
+ "special": false
159
+ },
160
+ "151659": {
161
+ "content": "<|fim_prefix|>",
162
+ "single_word": false,
163
+ "lstrip": false,
164
+ "rstrip": false,
165
+ "normalized": false,
166
+ "special": false
167
+ },
168
+ "151660": {
169
+ "content": "<|fim_middle|>",
170
+ "single_word": false,
171
+ "lstrip": false,
172
+ "rstrip": false,
173
+ "normalized": false,
174
+ "special": false
175
+ },
176
+ "151661": {
177
+ "content": "<|fim_suffix|>",
178
+ "single_word": false,
179
+ "lstrip": false,
180
+ "rstrip": false,
181
+ "normalized": false,
182
+ "special": false
183
+ },
184
+ "151662": {
185
+ "content": "<|fim_pad|>",
186
+ "single_word": false,
187
+ "lstrip": false,
188
+ "rstrip": false,
189
+ "normalized": false,
190
+ "special": false
191
+ },
192
+ "151663": {
193
+ "content": "<|repo_name|>",
194
+ "single_word": false,
195
+ "lstrip": false,
196
+ "rstrip": false,
197
+ "normalized": false,
198
+ "special": false
199
+ },
200
+ "151664": {
201
+ "content": "<|file_sep|>",
202
+ "single_word": false,
203
+ "lstrip": false,
204
+ "rstrip": false,
205
+ "normalized": false,
206
+ "special": false
207
+ },
208
+ "151665": {
209
+ "content": "<|PAD_TOKEN|>",
210
+ "single_word": false,
211
+ "lstrip": false,
212
+ "rstrip": false,
213
+ "normalized": false,
214
+ "special": true
215
+ }
216
+ }
217
+ }