Text Generation
Transformers
Safetensors
English
lfm2
cybersecurity
security
ner
threat-intelligence
phishing
http
fine-tuned
small-language-model
conversational
Eval Results (legacy)
Instructions to use YoungHungGayGymBoy/Cyber-Prime-1-2.6B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use YoungHungGayGymBoy/Cyber-Prime-1-2.6B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="YoungHungGayGymBoy/Cyber-Prime-1-2.6B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("YoungHungGayGymBoy/Cyber-Prime-1-2.6B") model = AutoModelForCausalLM.from_pretrained("YoungHungGayGymBoy/Cyber-Prime-1-2.6B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use YoungHungGayGymBoy/Cyber-Prime-1-2.6B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "YoungHungGayGymBoy/Cyber-Prime-1-2.6B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "YoungHungGayGymBoy/Cyber-Prime-1-2.6B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/YoungHungGayGymBoy/Cyber-Prime-1-2.6B
- SGLang
How to use YoungHungGayGymBoy/Cyber-Prime-1-2.6B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "YoungHungGayGymBoy/Cyber-Prime-1-2.6B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "YoungHungGayGymBoy/Cyber-Prime-1-2.6B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "YoungHungGayGymBoy/Cyber-Prime-1-2.6B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "YoungHungGayGymBoy/Cyber-Prime-1-2.6B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use YoungHungGayGymBoy/Cyber-Prime-1-2.6B with Docker Model Runner:
docker model run hf.co/YoungHungGayGymBoy/Cyber-Prime-1-2.6B
Commit ·
4d54ab2
0
Parent(s):
Duplicate from Akahsizrr/Cyber-Prime-1-2.6B
Browse filesCo-authored-by: Vasko Djack <Akahsizrr@users.noreply.huggingface.co>
- .gitattributes +37 -0
- README.md +186 -0
- benchmark.png +3 -0
- chat_template.jinja +125 -0
- config.json +73 -0
- generation_config.json +16 -0
- model.safetensors +3 -0
- tokenizer.json +3 -0
- tokenizer_config.json +13 -0
- training_args.bin +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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 |
+
benchmark.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
library_name: transformers
|
| 6 |
+
tags:
|
| 7 |
+
- cybersecurity
|
| 8 |
+
- security
|
| 9 |
+
- ner
|
| 10 |
+
- threat-intelligence
|
| 11 |
+
- phishing
|
| 12 |
+
- http
|
| 13 |
+
- fine-tuned
|
| 14 |
+
- small-language-model
|
| 15 |
+
base_model: LiquidAI/LFM2-2.6B
|
| 16 |
+
model-index:
|
| 17 |
+
- name: Cyber-Prime-1-2.6B
|
| 18 |
+
results:
|
| 19 |
+
- task:
|
| 20 |
+
type: named-entity-recognition
|
| 21 |
+
name: CyNER
|
| 22 |
+
dataset:
|
| 23 |
+
name: CyNER
|
| 24 |
+
type: cyberbench
|
| 25 |
+
metrics:
|
| 26 |
+
- type: f1
|
| 27 |
+
value: 0.382
|
| 28 |
+
name: F1
|
| 29 |
+
- task:
|
| 30 |
+
type: named-entity-recognition
|
| 31 |
+
name: APTNER
|
| 32 |
+
dataset:
|
| 33 |
+
name: APTNER
|
| 34 |
+
type: cyberbench
|
| 35 |
+
metrics:
|
| 36 |
+
- type: f1
|
| 37 |
+
value: 0.413
|
| 38 |
+
name: F1
|
| 39 |
+
- task:
|
| 40 |
+
type: summarization
|
| 41 |
+
name: CyNews
|
| 42 |
+
dataset:
|
| 43 |
+
name: CyNews
|
| 44 |
+
type: cyberbench
|
| 45 |
+
metrics:
|
| 46 |
+
- type: rouge1
|
| 47 |
+
value: 0.354
|
| 48 |
+
name: ROUGE-1
|
| 49 |
+
- task:
|
| 50 |
+
type: multiple-choice
|
| 51 |
+
name: SecMMLU
|
| 52 |
+
dataset:
|
| 53 |
+
name: SecMMLU
|
| 54 |
+
type: cyberbench
|
| 55 |
+
metrics:
|
| 56 |
+
- type: accuracy
|
| 57 |
+
value: 0.580
|
| 58 |
+
name: Accuracy
|
| 59 |
+
- task:
|
| 60 |
+
type: multiple-choice
|
| 61 |
+
name: CyQuiz
|
| 62 |
+
dataset:
|
| 63 |
+
name: CyQuiz
|
| 64 |
+
type: cyberbench
|
| 65 |
+
metrics:
|
| 66 |
+
- type: accuracy
|
| 67 |
+
value: 0.570
|
| 68 |
+
name: Accuracy
|
| 69 |
+
- task:
|
| 70 |
+
type: text-classification
|
| 71 |
+
name: Email Phishing Detection
|
| 72 |
+
dataset:
|
| 73 |
+
name: Email
|
| 74 |
+
type: cyberbench
|
| 75 |
+
metrics:
|
| 76 |
+
- type: f1
|
| 77 |
+
value: 0.728
|
| 78 |
+
name: F1
|
| 79 |
+
- task:
|
| 80 |
+
type: text-classification
|
| 81 |
+
name: HTTP Attack Detection
|
| 82 |
+
dataset:
|
| 83 |
+
name: HTTP
|
| 84 |
+
type: cyberbench
|
| 85 |
+
metrics:
|
| 86 |
+
- type: f1
|
| 87 |
+
value: 0.483
|
| 88 |
+
name: F1
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
# Cyber-Prime 1 (2.6B)
|
| 92 |
+
|
| 93 |
+
A fine-tuned cybersecurity specialist built on [LiquidAI/LFM2-2.6B](https://huggingface.co/LiquidAI/LFM2-2.6B). Despite having only 2.6 billion parameters, Cyber-Prime 1 outperforms Llama-2-7B on every CyberBench task and beats GPT-3.5-Turbo on named entity recognition and threat intelligence summarization.
|
| 94 |
+
|
| 95 |
+

|
| 96 |
+
|
| 97 |
+
## Overview
|
| 98 |
+
|
| 99 |
+
Cyber-Prime 1 is a surgical fine-tune of the LFM2.5-2.6B base model, trained on a curated mix of:
|
| 100 |
+
|
| 101 |
+
- **NER repair data** — 6,000+ rows fixing JSON format extraction for cybersecurity entities
|
| 102 |
+
- **HTTP reasoning traces** — 5,000 rows with authored chain-of-thought reasoning for attack detection (XSS, SQLi, path traversal, command injection)
|
| 103 |
+
- **Email classification** — 5,000 direct-mode rows for phishing vs. safe classification
|
| 104 |
+
- **CyNews summarization** — 2,000 rows for threat intelligence headline generation
|
| 105 |
+
- **Source data** — 2,000 rows from GHSA, KEV, and ATT&CK sources
|
| 106 |
+
- **Multiple choice** — security knowledge and cyber quiz gold rows
|
| 107 |
+
|
| 108 |
+
The model uses two distinct modes:
|
| 109 |
+
- **Direct mode** for simple classification (email phishing, HTTP detection) and summarization
|
| 110 |
+
- **Think mode** (chain-of-thought) for tasks benefiting from reasoning (HTTP analysis, NER extraction)
|
| 111 |
+
|
| 112 |
+
## Benchmark Results
|
| 113 |
+
|
| 114 |
+
Evaluated on [CyberBench](https://github.com/jpmorganchase/CyberBench) (Liu et al., AAAI-24 AICS Workshop).
|
| 115 |
+
|
| 116 |
+
| Dataset | Metric | GPT-4 | GPT-3.5 Turbo | Mistral-7B Instruct | Llama-2-7B | **Cyber-Prime 1 (2.6B)** |
|
| 117 |
+
|---------|--------|-------|---------------|---------------------|------------|----------------|
|
| 118 |
+
| CyNER | F1 | 0.554 | 0.334 | 0.323 | 0.263 | **0.382** |
|
| 119 |
+
| APTNER | F1 | 0.500 | 0.409 | 0.262 | 0.280 | **0.413** |
|
| 120 |
+
| CyNews | ROUGE-1 | 0.275 | 0.271 | 0.217 | 0.003 | **0.354** |
|
| 121 |
+
| SecMMLU | Accuracy | 0.830 | 0.780 | 0.720 | 0.630 | **0.580** |
|
| 122 |
+
| CyQuiz | Accuracy | 0.810 | 0.830 | 0.690 | 0.620 | **0.570** |
|
| 123 |
+
| Email | F1 | 0.939 | 0.789 | 0.889 | 0.942 | **0.728** |
|
| 124 |
+
| HTTP | F1 | 0.841 | 0.831 | 0.472 | 0.428 | **0.483** |
|
| 125 |
+
| **Average** | — | **0.721** | **0.609** | **0.511** | **0.451** | **0.501** |
|
| 126 |
+
|
| 127 |
+
### Key Results
|
| 128 |
+
|
| 129 |
+
- **Beats Llama-2-7B on all 7 tasks** — a 2.6B model sweeping a 7B model across the board
|
| 130 |
+
- **Beats Mistral-7B-Instruct on 4/7 tasks** — APTNER (+0.151), CyNews (+0.137), CyNER (+0.059), HTTP (+0.011)
|
| 131 |
+
- **Beats GPT-3.5-Turbo on 3/7 tasks** — CyNews (+0.083), APTNER (+0.004), CyNER (+0.048)
|
| 132 |
+
- **Beats GPT-4 on CyNews** — 0.354 vs 0.275 ROUGE-1 (+0.079), a 2.6B model out-summarizing GPT-4
|
| 133 |
+
|
| 134 |
+
## Usage
|
| 135 |
+
|
| 136 |
+
```python
|
| 137 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 138 |
+
|
| 139 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 140 |
+
"Akahsizrr/Cyber-Prime-1-2.6B",
|
| 141 |
+
torch_dtype="auto",
|
| 142 |
+
device_map="auto",
|
| 143 |
+
)
|
| 144 |
+
tokenizer = AutoTokenizer.from_pretrained("Akahsizrr/Cyber-Prime-1-2.6B")
|
| 145 |
+
|
| 146 |
+
# NER extraction (Alpaca format)
|
| 147 |
+
prompt = """### Instruction:
|
| 148 |
+
Extract cybersecurity entities from the given text.
|
| 149 |
+
|
| 150 |
+
### Input:
|
| 151 |
+
APT29 used WELLMAIL to compromise Microsoft Exchange servers via CVE-2021-26855.
|
| 152 |
+
|
| 153 |
+
### Response:
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 157 |
+
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
|
| 158 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
## Limitations
|
| 162 |
+
|
| 163 |
+
- **Knowledge tasks (SecMMLU, CyQuiz):** Limited by parameter count — a 2.6B model cannot store broad cybersecurity knowledge as well as larger models
|
| 164 |
+
- **Email classification:** Slightly below GPT-3.5-Turbo due to reasoning mode interference from HTTP training data
|
| 165 |
+
- **HTTP detection:** Reasoning improves detection of obvious attacks but may miss subtle injection patterns
|
| 166 |
+
- **Not a security tool:** This model is a research artifact for benchmark evaluation, not a production security system
|
| 167 |
+
|
| 168 |
+
## Citation
|
| 169 |
+
|
| 170 |
+
```bibtex
|
| 171 |
+
@misc{cyberprime1,
|
| 172 |
+
title={Cyber-Prime 1: A Small Cybersecurity Language Model},
|
| 173 |
+
author={Akahsizrr},
|
| 174 |
+
year={2025},
|
| 175 |
+
url={https://huggingface.co/Akahsizrr/Cyber-Prime-1-2.6B}
|
| 176 |
+
}
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
```bibtex
|
| 180 |
+
@misc{liu2024cyberbench,
|
| 181 |
+
title={Cyberbench: A multi-task benchmark for evaluating large language models in cybersecurity},
|
| 182 |
+
author={Liu, Zefang and Shi, Jialei and Buford, John F},
|
| 183 |
+
howpublished={AAAI-24 Workshop on Artificial Intelligence for Cyber Security (AICS)},
|
| 184 |
+
year={2024}
|
| 185 |
+
}
|
| 186 |
+
```
|
benchmark.png
ADDED
|
Git LFS Details
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{- bos_token -}}
|
| 2 |
+
{%- set preserve_thinking = preserve_thinking | default(false) -%}
|
| 3 |
+
|
| 4 |
+
{%- macro format_arg_value(arg_value) -%}
|
| 5 |
+
{%- if arg_value is string -%}
|
| 6 |
+
{{- "'" + (arg_value | replace("\\", "\\\\") | replace("'", "\\'") | replace("\n", "\\n") | replace("\r", "\\r")) + "'" -}}
|
| 7 |
+
{%- elif arg_value is mapping or arg_value is iterable -%}
|
| 8 |
+
{{- arg_value | tojson -}}
|
| 9 |
+
{%- else -%}
|
| 10 |
+
{{- arg_value | string -}}
|
| 11 |
+
{%- endif -%}
|
| 12 |
+
{%- endmacro -%}
|
| 13 |
+
|
| 14 |
+
{%- macro parse_content(content) -%}
|
| 15 |
+
{%- if content is string -%}
|
| 16 |
+
{{- content -}}
|
| 17 |
+
{%- elif content is mapping -%}
|
| 18 |
+
{{- content | tojson -}}
|
| 19 |
+
{%- elif content is iterable -%}
|
| 20 |
+
{%- set _ns = namespace(result="") -%}
|
| 21 |
+
{%- for item in content -%}
|
| 22 |
+
{%- if item is string -%}
|
| 23 |
+
{%- set _ns.result = _ns.result + item -%}
|
| 24 |
+
{%- elif item is mapping and item.get("type") == "image" -%}
|
| 25 |
+
{%- set _ns.result = _ns.result + "<image>" -%}
|
| 26 |
+
{%- elif item is mapping and item.get("type") == "text" -%}
|
| 27 |
+
{%- set _ns.result = _ns.result + ((item.get("text") or "") | string) -%}
|
| 28 |
+
{%- else -%}
|
| 29 |
+
{%- set _ns.result = _ns.result + (item | tojson) -%}
|
| 30 |
+
{%- endif -%}
|
| 31 |
+
{%- endfor -%}
|
| 32 |
+
{{- _ns.result -}}
|
| 33 |
+
{%- endif -%}
|
| 34 |
+
{%- endmacro -%}
|
| 35 |
+
|
| 36 |
+
{%- macro render_tool_calls(tool_calls) -%}
|
| 37 |
+
{%- set tool_calls_ns = namespace(tool_calls=[]) -%}
|
| 38 |
+
{%- for tool_call in tool_calls -%}
|
| 39 |
+
{%- set func = tool_call["function"] if "function" in tool_call else tool_call -%}
|
| 40 |
+
{%- set func_name = func["name"] -%}
|
| 41 |
+
{%- set func_args = func.get("arguments") -%}
|
| 42 |
+
{%- set args_ns = namespace(arg_strings=[]) -%}
|
| 43 |
+
{%- if func_args is mapping -%}
|
| 44 |
+
{%- for arg_name, arg_value in func_args.items() -%}
|
| 45 |
+
{%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + "=" + format_arg_value(arg_value)] -%}
|
| 46 |
+
{%- endfor -%}
|
| 47 |
+
{%- elif func_args is string and (func_args | trim) not in ["", "{}", "null"] -%}
|
| 48 |
+
{{- raise_exception("Tool call arguments must be a mapping, got a JSON-encoded string: parse arguments with json.loads() before applying the chat template") -}}
|
| 49 |
+
{%- endif -%}
|
| 50 |
+
{%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + (args_ns.arg_strings | join(", ")) + ")"] -%}
|
| 51 |
+
{%- endfor -%}
|
| 52 |
+
{{- "<|tool_call_start|>[" + (tool_calls_ns.tool_calls | join(", ")) + "]<|tool_call_end|>" -}}
|
| 53 |
+
{%- endmacro -%}
|
| 54 |
+
|
| 55 |
+
{%- set ns = namespace(system_prompt="", last_user_index=-1) -%}
|
| 56 |
+
{%- if messages and messages[0]["role"] == "system" -%}
|
| 57 |
+
{%- if messages[0].get("content") -%}
|
| 58 |
+
{%- set ns.system_prompt = parse_content(messages[0]["content"]) -%}
|
| 59 |
+
{%- endif -%}
|
| 60 |
+
{%- set messages = messages[1:] -%}
|
| 61 |
+
{%- endif -%}
|
| 62 |
+
{%- if tools -%}
|
| 63 |
+
{%- set ns.system_prompt = ns.system_prompt + ("\n" if ns.system_prompt else "") + "List of tools: [" -%}
|
| 64 |
+
{%- for tool in tools -%}
|
| 65 |
+
{%- if tool is not string -%}
|
| 66 |
+
{%- set tool = tool | tojson -%}
|
| 67 |
+
{%- endif -%}
|
| 68 |
+
{%- set ns.system_prompt = ns.system_prompt + tool -%}
|
| 69 |
+
{%- if not loop.last -%}
|
| 70 |
+
{%- set ns.system_prompt = ns.system_prompt + ", " -%}
|
| 71 |
+
{%- endif -%}
|
| 72 |
+
{%- endfor -%}
|
| 73 |
+
{%- set ns.system_prompt = ns.system_prompt + "]" -%}
|
| 74 |
+
{%- endif -%}
|
| 75 |
+
{%- if ns.system_prompt -%}
|
| 76 |
+
{{- "<|im_start|>system\n" + ns.system_prompt + "<|im_end|>\n" -}}
|
| 77 |
+
{%- endif -%}
|
| 78 |
+
{%- for message in messages -%}
|
| 79 |
+
{%- if message["role"] == "user" -%}
|
| 80 |
+
{%- set ns.last_user_index = loop.index0 -%}
|
| 81 |
+
{%- endif -%}
|
| 82 |
+
{%- endfor -%}
|
| 83 |
+
{%- for message in messages -%}
|
| 84 |
+
{{- "<|im_start|>" + message.role + "\n" -}}
|
| 85 |
+
{%- if message.role == "assistant" -%}
|
| 86 |
+
{%- generation -%}
|
| 87 |
+
{%- set keep_thinking = preserve_thinking or loop.index0 > ns.last_user_index -%}
|
| 88 |
+
{%- set thinking = message.thinking or message.reasoning or message.reasoning_content -%}
|
| 89 |
+
{%- set thinking = thinking if thinking is string else "" -%}
|
| 90 |
+
{%- if thinking and keep_thinking -%}
|
| 91 |
+
{{- "<think>" + thinking + "</think>" -}}
|
| 92 |
+
{%- endif -%}
|
| 93 |
+
{%- set _cfm_tag = "CONTINUE_FINAL_MESSAGE_TAG " -%}
|
| 94 |
+
{%- set _has_cfm = false -%}
|
| 95 |
+
{%- set content = "" -%}
|
| 96 |
+
{%- if message.get("content") -%}
|
| 97 |
+
{%- set content = parse_content(message.content) -%}
|
| 98 |
+
{%- endif -%}
|
| 99 |
+
{%- if not keep_thinking and "</think>" in content -%}
|
| 100 |
+
{%- set content = content.split("</think>")[-1] | trim -%}
|
| 101 |
+
{%- endif -%}
|
| 102 |
+
{%- if content.endswith(_cfm_tag) -%}
|
| 103 |
+
{%- set _has_cfm = true -%}
|
| 104 |
+
{%- set _trunc_len = (content | length) - (_cfm_tag | length) -%}
|
| 105 |
+
{%- set content = content[:_trunc_len] -%}
|
| 106 |
+
{%- endif -%}
|
| 107 |
+
{{- content -}}
|
| 108 |
+
{%- if message.tool_calls -%}
|
| 109 |
+
{{- render_tool_calls(message.tool_calls) -}}
|
| 110 |
+
{%- endif -%}
|
| 111 |
+
{%- if _has_cfm -%}
|
| 112 |
+
{{- _cfm_tag -}}
|
| 113 |
+
{%- endif -%}
|
| 114 |
+
{{- "<|im_end|>\n" -}}
|
| 115 |
+
{%- endgeneration -%}
|
| 116 |
+
{%- else %}
|
| 117 |
+
{%- if message.get("content") -%}
|
| 118 |
+
{{- parse_content(message["content"]) -}}
|
| 119 |
+
{%- endif -%}
|
| 120 |
+
{{- "<|im_end|>\n" -}}
|
| 121 |
+
{%- endif %}
|
| 122 |
+
{%- endfor -%}
|
| 123 |
+
{%- if add_generation_prompt -%}
|
| 124 |
+
{{- "<|im_start|>assistant\n<think>" -}}
|
| 125 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Lfm2ForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"block_auto_adjust_ff_dim": false,
|
| 6 |
+
"block_dim": 2048,
|
| 7 |
+
"block_ffn_dim_multiplier": 1.0,
|
| 8 |
+
"block_mlp_init_scale": 1.0,
|
| 9 |
+
"block_multiple_of": 256,
|
| 10 |
+
"block_norm_eps": 1e-05,
|
| 11 |
+
"block_out_init_scale": 1.0,
|
| 12 |
+
"block_use_swiglu": true,
|
| 13 |
+
"block_use_xavier_init": true,
|
| 14 |
+
"bos_token_id": 124894,
|
| 15 |
+
"conv_L_cache": 3,
|
| 16 |
+
"conv_bias": false,
|
| 17 |
+
"conv_dim": 2048,
|
| 18 |
+
"conv_use_xavier_init": true,
|
| 19 |
+
"dtype": "bfloat16",
|
| 20 |
+
"eos_token_id": 124900,
|
| 21 |
+
"hidden_size": 2048,
|
| 22 |
+
"initializer_range": 0.02,
|
| 23 |
+
"intermediate_size": 10752,
|
| 24 |
+
"layer_types": [
|
| 25 |
+
"conv",
|
| 26 |
+
"conv",
|
| 27 |
+
"full_attention",
|
| 28 |
+
"conv",
|
| 29 |
+
"conv",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"conv",
|
| 32 |
+
"conv",
|
| 33 |
+
"conv",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"conv",
|
| 36 |
+
"conv",
|
| 37 |
+
"conv",
|
| 38 |
+
"full_attention",
|
| 39 |
+
"conv",
|
| 40 |
+
"conv",
|
| 41 |
+
"conv",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"conv",
|
| 44 |
+
"conv",
|
| 45 |
+
"conv",
|
| 46 |
+
"full_attention",
|
| 47 |
+
"conv",
|
| 48 |
+
"conv",
|
| 49 |
+
"full_attention",
|
| 50 |
+
"conv",
|
| 51 |
+
"conv",
|
| 52 |
+
"full_attention",
|
| 53 |
+
"conv",
|
| 54 |
+
"conv"
|
| 55 |
+
],
|
| 56 |
+
"max_position_embeddings": 131072,
|
| 57 |
+
"model_type": "lfm2",
|
| 58 |
+
"norm_eps": 1e-05,
|
| 59 |
+
"num_attention_heads": 32,
|
| 60 |
+
"num_heads": 32,
|
| 61 |
+
"num_hidden_layers": 30,
|
| 62 |
+
"num_key_value_heads": 8,
|
| 63 |
+
"pad_token_id": 124893,
|
| 64 |
+
"rope_parameters": {
|
| 65 |
+
"rope_theta": 10000000.0,
|
| 66 |
+
"rope_type": "default"
|
| 67 |
+
},
|
| 68 |
+
"tie_word_embeddings": true,
|
| 69 |
+
"transformers_version": "5.2.0",
|
| 70 |
+
"use_cache": false,
|
| 71 |
+
"use_pos_enc": true,
|
| 72 |
+
"vocab_size": 128000
|
| 73 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 124894,
|
| 4 |
+
"do_sample": true,
|
| 5 |
+
"eos_token_id": [
|
| 6 |
+
124900
|
| 7 |
+
],
|
| 8 |
+
"output_attentions": false,
|
| 9 |
+
"output_hidden_states": false,
|
| 10 |
+
"pad_token_id": 124893,
|
| 11 |
+
"repetition_penalty": 1.1,
|
| 12 |
+
"temperature": 0.1,
|
| 13 |
+
"top_k": 50,
|
| 14 |
+
"transformers_version": "5.2.0",
|
| 15 |
+
"use_cache": true
|
| 16 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d470990718d31720ee64ea4806d0d5007e17707a833ea988eeaf0784511b3fe0
|
| 3 |
+
size 5394427448
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:695be7802a0e4b8a81048f0ff5ebb7fc811a0ba5a6be63dbb24deb5a81096f41
|
| 3 |
+
size 17905598
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<|startoftext|>",
|
| 4 |
+
"clean_up_tokenization_spaces": false,
|
| 5 |
+
"eos_token": "<|im_end|>",
|
| 6 |
+
"is_local": true,
|
| 7 |
+
"legacy": false,
|
| 8 |
+
"local_files_only": false,
|
| 9 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 10 |
+
"pad_token": "<|pad|>",
|
| 11 |
+
"tokenizer_class": "TokenizersBackend",
|
| 12 |
+
"use_default_system_prompt": false
|
| 13 |
+
}
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5d0a27e6886682ee007bd67a9fe8ab7e5e500be7282f54b2e2fba3b0e4ec09ff
|
| 3 |
+
size 5201
|