Upload 28 files
Browse files- .gitattributes +36 -35
- .gitignore +4 -0
- README.md +14 -60
- app.py +30 -0
- inference/__pycache__/analyze.cpython-312.pyc +0 -0
- inference/analyze.py +59 -0
- inference/test.py +51 -0
- model/README.md +58 -0
- model/final/added_tokens.json +24 -0
- model/final/chat_template.jinja +54 -0
- model/final/config.json +55 -0
- model/final/generation_config.json +8 -0
- model/final/merges.txt +0 -0
- model/final/model.safetensors +3 -0
- model/final/special_tokens_map.json +25 -0
- model/final/tokenizer.json +3 -0
- model/final/tokenizer_config.json +207 -0
- model/final/vocab.json +0 -0
- rag/__pycache__/search.cpython-312.pyc +0 -0
- rag/build_index.py +32 -0
- rag/corpus/malware_knowledge.txt +13 -0
- rag/ingest.py +14 -0
- rag/search.py +20 -0
- rag/vectorstore/index.faiss +0 -0
- rag/vectorstore/meta.pkl +3 -0
- requirements.txt +9 -0
- yara/__pycache__/generate.cpython-312.pyc +0 -0
- yara/generate.py +19 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,36 @@
|
|
| 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
|
|
|
|
|
|
| 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 |
+
model/final/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.env
|
| 4 |
+
.cache/
|
README.md
CHANGED
|
@@ -1,60 +1,14 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
- yara
|
| 16 |
-
- rag
|
| 17 |
-
- llm
|
| 18 |
-
- automation
|
| 19 |
-
---
|
| 20 |
-
|
| 21 |
-
# 🛡️ MCMA – Malware Static Analyzer
|
| 22 |
-
|
| 23 |
-
**MCMA (Malware Classification & Malware Analysis)** is an AI-powered framework designed to assist security analysts and threat hunters. It performs **static analysis** on suspicious files and automatically generates **YARA rules** for detection.
|
| 24 |
-
|
| 25 |
-
Using a combination of Retrieval-Augmented Generation (RAG) and Large Language Models (LLMs), MCMA identifies suspicious patterns without executing the file, making it a safe initial step in the malware analysis pipeline.
|
| 26 |
-
|
| 27 |
-
## 🚀 Key Features
|
| 28 |
-
|
| 29 |
-
* **Static Analysis:** Extracts metadata, strings, and headers without running the binary.
|
| 30 |
-
* **AI-Driven Insights:** Uses an LLM to interpret raw file data and explain *why* a file looks suspicious.
|
| 31 |
-
* **Auto-YARA Generation:** Automatically writes syntactically correct YARA rules based on the analysis logic.
|
| 32 |
-
* **RAG Integration:** (Optional/If applicable) Retrieves context from a vector database of known malware families to improve classification accuracy.
|
| 33 |
-
|
| 34 |
-
## ⚙️ How It Works
|
| 35 |
-
|
| 36 |
-
1. **Input:** User uploads a suspicious file (PE, ELF, Script, etc.) via the Gradio UI.
|
| 37 |
-
2. **Preprocessing:** The system extracts static features (hashes, imports, exports, entropy).
|
| 38 |
-
3. **Inference:**
|
| 39 |
-
* The features are formatted into a prompt.
|
| 40 |
-
* The LLM analyzes the features against known malware behaviors.
|
| 41 |
-
4. **Output:**
|
| 42 |
-
* A JSON report detailed the findings.
|
| 43 |
-
* A generated YARA rule to detect similar samples.
|
| 44 |
-
|
| 45 |
-
## 🛠️ Installation & Usage
|
| 46 |
-
|
| 47 |
-
You can try the live demo in the [Spaces tab](https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME).
|
| 48 |
-
|
| 49 |
-
### Local Setup
|
| 50 |
-
|
| 51 |
-
To run this tool locally, clone the repository and install the dependencies.
|
| 52 |
-
|
| 53 |
-
```bash
|
| 54 |
-
git clone https://huggingface.co/spaces/zeltera/mcma
|
| 55 |
-
cd mcma
|
| 56 |
-
pip install -r requirements.txt
|
| 57 |
-
python app.py
|
| 58 |
-
|
| 59 |
-
license: mit
|
| 60 |
-
---
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Mcma Space
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.1.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: AI Malware Analysis
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tempfile
|
| 3 |
+
from inference.analyze import analyze
|
| 4 |
+
from yara.generate import generate_yara
|
| 5 |
+
|
| 6 |
+
def analyze_file(file):
|
| 7 |
+
if file is None:
|
| 8 |
+
return None, None
|
| 9 |
+
|
| 10 |
+
path = file.name
|
| 11 |
+
prompt = f"Suspicious file uploaded: {path}"
|
| 12 |
+
|
| 13 |
+
result = analyze(prompt)
|
| 14 |
+
yara = generate_yara(result)
|
| 15 |
+
|
| 16 |
+
return result, yara
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
gr.Markdown("# 🛡️ MCMA – Malware Static Analyzer")
|
| 20 |
+
|
| 21 |
+
file = gr.File(label="Drag & drop malware sample (static analysis only)")
|
| 22 |
+
json_out = gr.JSON(label="Analysis Result")
|
| 23 |
+
|
| 24 |
+
# CHANGED: language="yara" -> language="c"
|
| 25 |
+
yara_out = gr.Code(label="Generated YARA Rule", language="c")
|
| 26 |
+
|
| 27 |
+
btn = gr.Button("Analyze")
|
| 28 |
+
btn.click(analyze_file, inputs=file, outputs=[json_out, yara_out])
|
| 29 |
+
|
| 30 |
+
demo.launch()
|
inference/__pycache__/analyze.cpython-312.pyc
ADDED
|
Binary file (2.07 kB). View file
|
|
|
inference/analyze.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
from rag.search import search_context
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
| 7 |
+
|
| 8 |
+
MODEL_PATH = os.path.join(BASE_DIR, "model", "final")
|
| 9 |
+
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 11 |
+
MODEL_PATH,
|
| 12 |
+
local_files_only=True,
|
| 13 |
+
trust_remote_code=True,
|
| 14 |
+
fix_mistral_regex=True
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 18 |
+
MODEL_PATH,
|
| 19 |
+
local_files_only=True,
|
| 20 |
+
trust_remote_code=True,
|
| 21 |
+
device_map="auto",
|
| 22 |
+
dtype=torch.float16
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def analyze(user_input: str):
|
| 27 |
+
context = search_context(user_input)
|
| 28 |
+
|
| 29 |
+
prompt = f"""
|
| 30 |
+
You are a cybersecurity malware analysis assistant.
|
| 31 |
+
Respond ONLY in valid JSON.
|
| 32 |
+
Use these fields exactly once:
|
| 33 |
+
- reasoning (array of strings)
|
| 34 |
+
- indicators (array)
|
| 35 |
+
- confidence (float 0-1)
|
| 36 |
+
- recommendation (string)
|
| 37 |
+
- mitre_attack (array)
|
| 38 |
+
|
| 39 |
+
Context:
|
| 40 |
+
{context}
|
| 41 |
+
|
| 42 |
+
Input:
|
| 43 |
+
{user_input}
|
| 44 |
+
|
| 45 |
+
Response:
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 49 |
+
|
| 50 |
+
with torch.no_grad():
|
| 51 |
+
output = model.generate(
|
| 52 |
+
**inputs,
|
| 53 |
+
max_new_tokens=256,
|
| 54 |
+
do_sample=True,
|
| 55 |
+
temperature=0.2,
|
| 56 |
+
top_p=0.9
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
inference/test.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
import torch
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
MODEL_PATH = os.path.abspath(
|
| 6 |
+
r"C:\Users\USER\OneDrive\Desktop\work\mcma\micro-cyber-llm\model\final"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 10 |
+
MODEL_PATH,
|
| 11 |
+
local_files_only=True,
|
| 12 |
+
fix_mistral_regex=True
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
+
MODEL_PATH,
|
| 17 |
+
device_map="auto",
|
| 18 |
+
dtype=torch.float16,
|
| 19 |
+
local_files_only=True
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
prompt = """### Instruction:
|
| 23 |
+
You are a cybersecurity malware analysis assistant.
|
| 24 |
+
Respond ONLY in valid JSON.
|
| 25 |
+
Use these fields exactly once:
|
| 26 |
+
- reasoning (array of strings)
|
| 27 |
+
- indicators (array)
|
| 28 |
+
- confidence (float 0-1)
|
| 29 |
+
- recommendation (string)
|
| 30 |
+
- mitre_attack (array)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
### Input:
|
| 34 |
+
APK requests READ_SMS and communicates with api.telegram.org
|
| 35 |
+
|
| 36 |
+
### Response:
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 40 |
+
|
| 41 |
+
with torch.no_grad():
|
| 42 |
+
output = model.generate(
|
| 43 |
+
**inputs,
|
| 44 |
+
max_new_tokens=256,
|
| 45 |
+
do_sample=True,
|
| 46 |
+
temperature=0.2,
|
| 47 |
+
top_p=0.9
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
model/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: Qwen/Qwen2.5-0.5B
|
| 3 |
+
library_name: transformers
|
| 4 |
+
model_name: model
|
| 5 |
+
tags:
|
| 6 |
+
- generated_from_trainer
|
| 7 |
+
- trl
|
| 8 |
+
- sft
|
| 9 |
+
licence: license
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Model Card for model
|
| 13 |
+
|
| 14 |
+
This model is a fine-tuned version of [Qwen/Qwen2.5-0.5B](https://huggingface.co/Qwen/Qwen2.5-0.5B).
|
| 15 |
+
It has been trained using [TRL](https://github.com/huggingface/trl).
|
| 16 |
+
|
| 17 |
+
## Quick start
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
from transformers import pipeline
|
| 21 |
+
|
| 22 |
+
question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
|
| 23 |
+
generator = pipeline("text-generation", model="None", device="cuda")
|
| 24 |
+
output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
|
| 25 |
+
print(output["generated_text"])
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## Training procedure
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
This model was trained with SFT.
|
| 34 |
+
|
| 35 |
+
### Framework versions
|
| 36 |
+
|
| 37 |
+
- TRL: 0.26.1
|
| 38 |
+
- Transformers: 4.57.3
|
| 39 |
+
- Pytorch: 2.7.1+cu118
|
| 40 |
+
- Datasets: 4.4.1
|
| 41 |
+
- Tokenizers: 0.22.1
|
| 42 |
+
|
| 43 |
+
## Citations
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Cite TRL as:
|
| 48 |
+
|
| 49 |
+
```bibtex
|
| 50 |
+
@misc{vonwerra2022trl,
|
| 51 |
+
title = {{TRL: Transformer Reinforcement Learning}},
|
| 52 |
+
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
|
| 53 |
+
year = 2020,
|
| 54 |
+
journal = {GitHub repository},
|
| 55 |
+
publisher = {GitHub},
|
| 56 |
+
howpublished = {\url{https://github.com/huggingface/trl}}
|
| 57 |
+
}
|
| 58 |
+
```
|
model/final/added_tokens.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"</tool_call>": 151658,
|
| 3 |
+
"<tool_call>": 151657,
|
| 4 |
+
"<|box_end|>": 151649,
|
| 5 |
+
"<|box_start|>": 151648,
|
| 6 |
+
"<|endoftext|>": 151643,
|
| 7 |
+
"<|file_sep|>": 151664,
|
| 8 |
+
"<|fim_middle|>": 151660,
|
| 9 |
+
"<|fim_pad|>": 151662,
|
| 10 |
+
"<|fim_prefix|>": 151659,
|
| 11 |
+
"<|fim_suffix|>": 151661,
|
| 12 |
+
"<|im_end|>": 151645,
|
| 13 |
+
"<|im_start|>": 151644,
|
| 14 |
+
"<|image_pad|>": 151655,
|
| 15 |
+
"<|object_ref_end|>": 151647,
|
| 16 |
+
"<|object_ref_start|>": 151646,
|
| 17 |
+
"<|quad_end|>": 151651,
|
| 18 |
+
"<|quad_start|>": 151650,
|
| 19 |
+
"<|repo_name|>": 151663,
|
| 20 |
+
"<|video_pad|>": 151656,
|
| 21 |
+
"<|vision_end|>": 151653,
|
| 22 |
+
"<|vision_pad|>": 151654,
|
| 23 |
+
"<|vision_start|>": 151652
|
| 24 |
+
}
|
model/final/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 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 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 %}
|
model/final/config.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen2ForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_dropout": 0.0,
|
| 6 |
+
"dtype": "float16",
|
| 7 |
+
"eos_token_id": 151643,
|
| 8 |
+
"hidden_act": "silu",
|
| 9 |
+
"hidden_size": 896,
|
| 10 |
+
"initializer_range": 0.02,
|
| 11 |
+
"intermediate_size": 4864,
|
| 12 |
+
"layer_types": [
|
| 13 |
+
"full_attention",
|
| 14 |
+
"full_attention",
|
| 15 |
+
"full_attention",
|
| 16 |
+
"full_attention",
|
| 17 |
+
"full_attention",
|
| 18 |
+
"full_attention",
|
| 19 |
+
"full_attention",
|
| 20 |
+
"full_attention",
|
| 21 |
+
"full_attention",
|
| 22 |
+
"full_attention",
|
| 23 |
+
"full_attention",
|
| 24 |
+
"full_attention",
|
| 25 |
+
"full_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"full_attention",
|
| 28 |
+
"full_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"full_attention",
|
| 32 |
+
"full_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"full_attention",
|
| 36 |
+
"full_attention"
|
| 37 |
+
],
|
| 38 |
+
"max_position_embeddings": 32768,
|
| 39 |
+
"max_window_layers": 24,
|
| 40 |
+
"model_type": "qwen2",
|
| 41 |
+
"num_attention_heads": 14,
|
| 42 |
+
"num_hidden_layers": 24,
|
| 43 |
+
"num_key_value_heads": 2,
|
| 44 |
+
"pad_token_id": 151643,
|
| 45 |
+
"rms_norm_eps": 1e-06,
|
| 46 |
+
"rope_scaling": null,
|
| 47 |
+
"rope_theta": 1000000.0,
|
| 48 |
+
"sliding_window": null,
|
| 49 |
+
"tie_word_embeddings": true,
|
| 50 |
+
"transformers_version": "4.57.3",
|
| 51 |
+
"use_cache": true,
|
| 52 |
+
"use_mrope": false,
|
| 53 |
+
"use_sliding_window": false,
|
| 54 |
+
"vocab_size": 151936
|
| 55 |
+
}
|
model/final/generation_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"eos_token_id": [
|
| 3 |
+
151643
|
| 4 |
+
],
|
| 5 |
+
"max_new_tokens": 2048,
|
| 6 |
+
"pad_token_id": 151643,
|
| 7 |
+
"transformers_version": "4.57.3"
|
| 8 |
+
}
|
model/final/merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model/final/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0af69765ea46511ab63e74660ec5b6532aca5b49f89aee3b9f84edcc178410ef
|
| 3 |
+
size 988097536
|
model/final/special_tokens_map.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": "<|endoftext|>",
|
| 19 |
+
"lstrip": false,
|
| 20 |
+
"normalized": false,
|
| 21 |
+
"rstrip": false,
|
| 22 |
+
"single_word": false
|
| 23 |
+
},
|
| 24 |
+
"pad_token": "<|endoftext|>"
|
| 25 |
+
}
|
model/final/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
|
| 3 |
+
size 11421896
|
model/final/tokenizer_config.json
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"clean_up_tokenization_spaces": false,
|
| 199 |
+
"eos_token": "<|endoftext|>",
|
| 200 |
+
"errors": "replace",
|
| 201 |
+
"extra_special_tokens": {},
|
| 202 |
+
"model_max_length": 131072,
|
| 203 |
+
"pad_token": "<|endoftext|>",
|
| 204 |
+
"split_special_tokens": false,
|
| 205 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 206 |
+
"unk_token": null
|
| 207 |
+
}
|
model/final/vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
rag/__pycache__/search.cpython-312.pyc
ADDED
|
Binary file (1.52 kB). View file
|
|
|
rag/build_index.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import faiss
|
| 3 |
+
import pickle
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
|
| 6 |
+
CORPUS_PATH = "../mcma/micro-cyber-llm/rag/corpus/malware_knowledge.txt"
|
| 7 |
+
OUT_DIR = "../mcma/micro-cyber-llm/rag/vectorstore"
|
| 8 |
+
|
| 9 |
+
os.makedirs(OUT_DIR, exist_ok=True)
|
| 10 |
+
|
| 11 |
+
print("[*] Loading embedding model...")
|
| 12 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 13 |
+
|
| 14 |
+
print("[*] Reading corpus...")
|
| 15 |
+
with open(CORPUS_PATH, "r", encoding="utf-8") as f:
|
| 16 |
+
documents = [line.strip() for line in f if line.strip()]
|
| 17 |
+
|
| 18 |
+
print(f"[*] Embedding {len(documents)} documents...")
|
| 19 |
+
embeddings = model.encode(documents, show_progress_bar=True)
|
| 20 |
+
|
| 21 |
+
dim = embeddings.shape[1]
|
| 22 |
+
index = faiss.IndexFlatL2(dim)
|
| 23 |
+
index.add(embeddings)
|
| 24 |
+
|
| 25 |
+
print("[*] Saving FAISS index...")
|
| 26 |
+
faiss.write_index(index, f"{OUT_DIR}/index.faiss")
|
| 27 |
+
|
| 28 |
+
print("[*] Saving metadata...")
|
| 29 |
+
with open(f"{OUT_DIR}/meta.pkl", "wb") as f:
|
| 30 |
+
pickle.dump(documents, f)
|
| 31 |
+
|
| 32 |
+
print("[✓] RAG index built successfully!")
|
rag/corpus/malware_knowledge.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Android malware often abuses READ_SMS to intercept OTP messages.
|
| 2 |
+
Communication with api.telegram.org is commonly used for C2 exfiltration.
|
| 3 |
+
Banking trojans target SMS permissions and overlay attacks.
|
| 4 |
+
APK files requesting SMS and internet permissions are high risk.
|
| 5 |
+
|
| 6 |
+
Windows malware may use CreateRemoteThread for process injection.
|
| 7 |
+
Suspicious EXE files often drop persistence via registry Run keys.
|
| 8 |
+
C2 traffic over HTTPS to unknown domains is a red flag.
|
| 9 |
+
PowerShell abuse is common in post-exploitation.
|
| 10 |
+
|
| 11 |
+
MITRE T1406 refers to SMS Control.
|
| 12 |
+
MITRE T1055 refers to Process Injection.
|
| 13 |
+
MITRE T1059 refers to Command and Scripting Interpreter.
|
rag/ingest.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sentence_transformers import SentenceTransformer
|
| 2 |
+
import faiss, os, pickle
|
| 3 |
+
|
| 4 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 5 |
+
index = faiss.IndexFlatL2(384)
|
| 6 |
+
docs = []
|
| 7 |
+
|
| 8 |
+
def ingest(text):
|
| 9 |
+
emb = model.encode([text])
|
| 10 |
+
index.add(emb)
|
| 11 |
+
docs.append(text)
|
| 12 |
+
|
| 13 |
+
faiss.write_index(index, "rag/vectorstore/index.faiss")
|
| 14 |
+
pickle.dump(docs, open("rag/vectorstore/docs.pkl", "wb"))
|
rag/search.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import faiss
|
| 3 |
+
import pickle
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
|
| 6 |
+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
| 7 |
+
VECTOR_DIR = os.path.join(BASE_DIR, "rag", "vectorstore")
|
| 8 |
+
|
| 9 |
+
index = faiss.read_index(os.path.join(VECTOR_DIR, "index.faiss"))
|
| 10 |
+
|
| 11 |
+
with open(os.path.join(VECTOR_DIR, "meta.pkl"), "rb") as f:
|
| 12 |
+
documents = pickle.load(f)
|
| 13 |
+
|
| 14 |
+
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def search_context(query, top_k=3):
|
| 18 |
+
q_emb = model.encode([query])
|
| 19 |
+
D, I = index.search(q_emb, top_k)
|
| 20 |
+
return "\n".join([documents[i] for i in I[0]])
|
rag/vectorstore/index.faiss
ADDED
|
Binary file (16.9 kB). View file
|
|
|
rag/vectorstore/meta.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:043712a56c3aa8d0e33c60438f2a3d2fed218fe29a3e62b04f10f30ce7bf98ff
|
| 3 |
+
size 673
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy<2
|
| 2 |
+
torch
|
| 3 |
+
transformers
|
| 4 |
+
accelerate
|
| 5 |
+
huggingface_hub
|
| 6 |
+
faiss-cpu
|
| 7 |
+
sentence-transformers
|
| 8 |
+
gradio
|
| 9 |
+
tqdm
|
yara/__pycache__/generate.cpython-312.pyc
ADDED
|
Binary file (726 Bytes). View file
|
|
|
yara/generate.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def generate_yara(result):
|
| 2 |
+
indicators = result["indicators"]
|
| 3 |
+
|
| 4 |
+
rule = f"""
|
| 5 |
+
rule AutoGenerated_Malware {{
|
| 6 |
+
meta:
|
| 7 |
+
author = "MicroCyberLLM"
|
| 8 |
+
confidence = "{result['confidence']}"
|
| 9 |
+
strings:
|
| 10 |
+
"""
|
| 11 |
+
for i, ind in enumerate(indicators):
|
| 12 |
+
rule += f' $s{i} = "{ind}"\n'
|
| 13 |
+
|
| 14 |
+
rule += """
|
| 15 |
+
condition:
|
| 16 |
+
any of them
|
| 17 |
+
}
|
| 18 |
+
"""
|
| 19 |
+
return rule
|