Instructions to use deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "deer-sec/StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- StagAI-CyberSecurity-26B-A4B-v2 (Cybersecurity Reasoning Text Model)
- Performance Improvements Over the Base Model
- Available Models
- 🛡️ QLoRA Adaptation & Safety Verification (Detailed Structural & Safety Verification)
- License
- Disclaimer
- 📊 Training Details
- ⚠️ Important Notes & Best Practices
- 💡 Recommended GGUF Usage (Forcing the Inference Process)
- 🛠 Advanced: LoRA Merging Technique & Verification
- Performance Improvements Over the Base Model
- StagAI-CyberSecurity-26B-A4B-v2 (日本語版)
StagAI-CyberSecurity-26B-A4B-v2 (Cybersecurity Reasoning Text Model)
(日本語版の説明は下部に記載しています。 / English version is followed by the Japanese version below.)
StagAI-CyberSecurity-26B-A4B-v2 is a "text-only" large language model specialized in cybersecurity analysis and advanced theoretical reasoning.
Based on the stable Gemma-4-26B-A4B(MoE) architecture, fine-tuning was performed using the MLX framework (mlx_lm.lora). After training, the LoRA adjustments were merged into the base model using a unique technique to prevent weight loss, allowing you to deploy and use high-quality inference immediately. This model is designed to serve as an inference engine for security professionals, researchers, SOC analysts, and system administrators when building threat modeling, vulnerability assessments, log interpretation, and comprehensive incident response strategies.
*Please note that this model is strictly for text input and does not support multimodal inputs such as images or audio.
Performance Improvements Over the Base Model
As a result of comparative verification with the original base model using various cybersecurity questions, this model exhibits the following characteristics:
- Improved Answer Quality: Provides more accurate, contextual, and practical answers to complex cybersecurity questions. We have confirmed that the answer quality is further improved compared to our previous model, CyberStag-Security-26B-A4B-V1.
- Deeper Reasoning: We have observed a slight increase in "thinking time" (processing latency). This trade-off allows for profound, step-by-step logical deductions, yielding higher-quality analytical outputs compared to the base model.
Available Models
We provide multiple formats to accommodate various hardware environments, ranging from high-end workstations to edge devices.
🛡️ QLoRA Adaptation & Safety Verification (Detailed Structural & Safety Verification)
When fine-tuning a language model, there are two common risks:
- The model might lose its basic language skills or vision (VLM) abilities.
- To make the model answer technical questions, someone might artificially remove its safety filter (known as "Abliteration" or "Uncensoring").
For StagAI-CyberSecurity-26B-A4B-v2-VLM, we conducted two mathematical checks to prove that the model learned cybersecurity knowledge while keeping its original safety and basic skills intact:
(1) Singular Value Decomposition (SVD) of the weight difference ($\Delta W$), and (2) Refusal Vector Analysis in the internal representation space.
📊 1. Summary of Key Verification Metrics (Mid-Layer $L=15$ & Overall Stats)
| Check Item | Value ($L=15$) | Updated Layers (L12–29) | Meaning & Interpretation |
|---|---|---|---|
| Lower & Vision Layer Change | 0.000% |
0.000% (All layers) |
Proves that basic language layers (L00–11) and the Vision Tower are 100% untouched and protected. |
| Upper Reasoning Layer Change | 0.163% |
Average: 0.128% |
Careful and small parameter updates that do not break the base model's structure. |
| MoE Router Change | 0.000% |
0.000% (All layers) |
Keeps the routing path to the 128 experts fixed, updating only the knowledge inside each expert. |
| Effective Rank (Stable Rank) | 1.41 |
1.41 – 1.83 |
Out of 2,112 possible directions, the change is focused into about 1.4 main directions (proof of clean low-rank learning). |
| Top-4 Singular Value Share | 72.5% |
1st axis alone: 71.2% |
Matches our Rank=4 QLoRA design, showing that the top 4 directions hold over 70% of the total update energy. |
| Refusal Vector Similarity | 0.9994 (1.99°) |
Average: 0.9976 (3.58°) |
Proves that the internal vector used to detect harmful requests points in almost the exact same direction (99.9%+ match) as the base model. |
| Projection onto Refusal Vector | 0.0105 |
Average: 0.0257 |
Matches the theoretical value of a random, unrelated vector ($1/\sqrt{d} = 0.0188$), proving the update does not interfere with safety. |
| Similarity to Abliteration | 0.00032 |
Max: 0.00203 |
Extremely close to 0.0 (completely unrelated), proving that no artificial uncensoring (Abliteration) was performed. |
| Harmful vs. Safe Separation | 1.0000 / 17.13 |
+0.53 wider than Base |
Keeps 100% accuracy in separating malicious attacks from normal requests, with an even wider safety margin than the base model. |
| Cyber-Defense Response Rate | 100.0% |
Final Layer: 75.0% $\to$ 81.3% |
Reduces false rejections ("Over-refusal") on legitimate security work questions by +6.3 points. |
🔍 2. Detailed Explanation of Each Check
① Protecting Basic Skills & Selective QLoRA Adaptation in Upper Layers (Graph a)
For each layer, we measured how much the weight matrix changed compared to the base model ($\Vert{}\Delta W\Vert{}F / \Vert{}W{\text{base}}\Vert{}_F$):
- Full Protection of Lower Layers and Vision: Out of 30 text layers, Layers 00–11 (the lower 12 layers) and all 27 Vision Encoder layers have a
0.000%change rate (completely frozen). This prevents any loss in image recognition (VLM) or basic language skills. - Focused Updates in Upper Reasoning Layers (Layers 12–29): QLoRA updates are applied only to the upper 18 layers (Layers 12–29), which handle advanced knowledge and logical thinking (covering ~5.55 billion parameters across the 8 main modules checked). Also, by keeping the MoE router (
router.proj) at0.000%across all layers, the model updates the knowledge inside the 128 experts without breaking how experts are selected.
② Proof of the "Rank=4 QLoRA" Structure via Singular Value Decomposition (Graph d)
By applying Singular Value Decomposition (SVD: $\Delta W = U \Sigma V^\top$) to the weight difference matrix $\Delta W = W_{\text{FT}} - W_{\text{base}}$ (2,816 × 2,112 = about 5.95 million parameters in Layer 15 mlp.down_proj), we can see "which directions" and "how strongly (singular values $\sigma_i$)" the parameters were changed, up to 2,112 independent directions:
- Energy Focused in the Top 4 Directions (
Rank=4): Out of 2,112 singular values, the top 4 singular values ($\sigma_1 \dots \sigma_4$) hold72.5%of the total update energy ($\Vert{}\Delta W\Vert{}_F^2$) (with the 1st direction $\sigma_1$ alone holding71.2%), and the Effective Rank (Stable Rank) is1.41. This directly reflects ourRank=4QLoRA setting and proves mathematically that high-purity cybersecurity knowledge was added along specific reasoning axes without disturbing general skills. - Role Sharing Between Middle and Later Layers: In the middle layers (Layers 12–15), which act as the core decision center, energy is strongly focused on the 1st axis $\sigma_1$ (Stable Rank
1.41) to switch the model into "cybersecurity expert mode." In the later layers (Layers 21–27), which build the actual response text, the share of the 2nd and 3rd singular values grows by about 7 times (Stable Rank1.83) to express diverse security terms and defense code.
③ Keeping the Safety Mechanism (Refusal Vector) Intact (Graph b)
Based on established research (Arditi et al., NeurIPS 2024), we extracted the internal "refusal vector $\hat{r}$" at each layer by taking the average difference (Difference-in-Means) between harmful attack prompts and normal safe prompts:
- High Alignment with the Base Model: The cosine similarity $\cos(\hat{r}{\text{base}}, \hat{r}{\text{FT}})$ between the base model and this model is
0.9994(an angle difference of only1.99°) at the middle layer (Layer 15), and averages0.9976(average angle difference of3.58°) across all 18 updated layers. Even when we changed the number of prompt-end tokens used for calculation (last-k$\in {1, 2, 4, 8}$), the angle difference at the middle layer stayed steady between1.99°and2.27°, showing that the base model's safety compass is firmly kept.
④ Mathematical Proof of No Safety Tampering / Anti-Abliteration (Graph c)
Some public models use a technique called "Abliteration" (or Uncensoring), which artificially erases the refusal vector direction from the weights ($\Delta W_{\text{ablit}} = \hat{r}{\text{base}} \hat{r}{\text{base}}^\top W_{\text{base}}$) to disable safety filters. We verified that no such tampering was done using two metrics:
- Unrelated (Orthogonal) to the Abliteration Direction: The cosine similarity between our weight update $\Delta W$ and the refusal-removal template $\Delta W_{\text{ablit}}$ is
0.00032inmlp.down_projand0.0000048inself_attn.o_projat Layer 15 (and at most0.00203across all 30 layers). Because this is extremely close to theoretical zero (0.0), it proves that the safety filter was not intentionally removed. - Projection Ratio Matches Random Theory: The ratio of the weight update $\Delta W$ projected onto the refusal vector direction, $|\hat{r}^\top \Delta W|_2 / |\Delta W|_F$ (purple line), is
0.0105at Layer 15 (and averages0.0202in the Attention output layers). This sits right around the mathematical expectation of a completely unrelated random vector in a 2,816-dimensional space ($1/\sqrt{2816} \approx \mathbf{0.0188}$, black dashed line). In short, the model learned cybersecurity knowledge in an independent space that does not touch the safety mechanism.
⑤ Stronger Defense Against Malicious Use + Less "Over-Refusal" on Real Security Work
When using LLMs for real cybersecurity work—such as fixing SQL injection, writing Sigma/YARA detection rules, or analyzing network packets—a major problem is "Over-refusal," where the model overreacts to technical words and wrongly refuses to answer legitimate defensive questions:
- Better Separation Against Real Attacks: The accuracy of separating malicious attack requests from normal requests stays at AUROC =
1.0000(100% separation), while the separation distance (Cohen's $d$) actually improved from16.61(Base) to17.13($L=15$), and from3.22to3.60at the final layer ($L=29$). - Higher Response Rate for Legitimate Defense Queries: At the same time, the normal response rate (non-refusal rate) for legitimate cyber-defense work questions at the final output layer (Layer 29) improved from
75.0%(Base) to81.3%(81.25%, a+6.25ptimprovement). Instead of weakening safety rules, learning expert knowledge allowed the model to accurately tell the difference between malicious attacks and legitimate defensive security work.
Methodology based on Singular Value Decomposition (SVD) of parameter deltas and Difference-in-Means (DiM) activation geometry (Arditi et al., NeurIPS 2024).
MLX Format (Optimized for Apple Silicon)
StagAI-CyberSecurity-26B-A4B-v2-FP16-MLX: Unquantized (FP16) format.StagAI-CyberSecurity-26B-A4B-v2-Q8-MLX: 8-bit quantized model with the adapter merged into the QLoRA base model. A highly balanced format that maintains original inference performance. Highly recommended.StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX: 4-bit quantized model with the adapter merged into the 4-bit quantized base model. Due to a merging technique aimed at reducing the Doom Loop issue, the model size is larger than usual.
GGUF Format (For llama.cpp, LM Studio, etc.)
StagAI-CyberSecurity-26B-A4B-v2-FP16.gguf: Unquantized 16-bit GGUF model converted from StagAI-CyberSecurity-26B-A4B-v2-FP16-MLX.StagAI-CyberSecurity-26B-A4B-v2-Q8_0.gguf: 8-bit quantized GGUF model (high precision, moderate memory requirement). Quantized from StagAI-CyberSecurity-26B-A4B-v2-FP16.gguf.StagAI-CyberSecurity-26B-A4B-v2-Q4_K_M.gguf: 4-bit quantized GGUF model (very lightweight. Strongly recommended for execution in environments with limited VRAM). Quantized from StagAI-CyberSecurity-26B-A4B-v2-FP16.gguf.
License
This model inherits the license of the original base model and is provided under the Apache License 2.0. Commercial use, modification, and redistribution are freely permitted.
Disclaimer
This model is provided solely for educational purposes, learning support, defensive cybersecurity research, hardening assistance, and improving system resilience. Furthermore, the misuse of this model for unauthorized access, generation of offensive exploits, or any other cybercrime is strictly prohibited. By downloading and using this model, the user is deemed to have explicitly agreed to use it only for the purposes of enhancing security and conducting ethical research.
📊 Training Details
Dataset
We used high-quality Supervised Fine-Tuning (SFT) datasets for cybersecurity tasks spanning multiple domains.
- English Dataset: 40,000 entries
- Japanese Dataset: 40,000 entries
- Total: 80,000 entries
Training was conducted using QLoRA (8bit).
Training Parameters
Fine-tuning was performed with the following parameters and LoRA specific settings:
# Basic Parameters
fine_tune_type: "lora"
optimizer: "adamw"
num_layers: 18
learning_rate: 5e-7
mask_prompt: true
# LoRA Specific Settings
lora_parameters:
rank: 4
scale: 1.0
dropout: 0.03
keys:
- "self_attn.q_proj"
- "self_attn.k_proj"
- "self_attn.v_proj"
- "self_attn.o_proj"
- "mlp.gate_proj"
- "mlp.up_proj"
- "mlp.down_proj"
- "experts.switch_glu.gate_proj"
- "experts.switch_glu.down_proj"
- "experts.switch_glu.up_proj"
Trainable parameters: 0.397% (100.109M/25233.053M)
⚠️ Important Notes & Best Practices
To maximize the performance of this model, please keep the following in mind:
- Highest Precision is 8bit: Since training was conducted in QLoRA (8bit), the 8bit model is highly likely to have the highest precision and demonstrate its true performance.
- MLX vs. GGUF Formats: The published GGUF model was converted from the FP16 MLX format. Therefore, the native MLX format may provide higher accuracy. (If any users or experts know a more optimal method for GGUF conversion, we would greatly appreciate your contribution.)
- Doom Loop Mitigation for Low-bit (4bit) Models: In low-bit environments such as 4bit quantization, the probability of generative repetition (Doom Loops) increases. To prevent this, the MLX format(4bit) model includes a configuration file with
"temperature": 0.5. When using the low-bit GGUF model, we recommend adjusting settings such as thetemperature.
💡 Recommended GGUF Usage (Forcing the Inference Process)
To ensure the thinking process (Thinking block) unfolds reliably, the GGUF model was crafted by pre-embedding the Jinja template (chat_template.jinja) metadata into the 16bit MLX model's tokenizer_config.json before quantization.
[IMPORTANT] Notice Regarding Ollama Usage
If you register and use this model in Ollama, the native renderer may forcefully overwrite the formatting, and depending on the prompt, the reasoning (Thinking) block could be entirely skipped.
Therefore, we recommend using a combination of llama-server and Open WebUI, which applies 100% identical prompt processing to MLX.
Recommended Environment Setup (llama.cpp)
# 1. Start llama-server (Utilizing native support for Jinja2 engine [minja])
./build/bin/llama-server \
-m /path/to/StagAI-CyberSecurity-26B-A4B-v2-Q4_K_M.gguf \
--port 8080 \
-ngl 99 \
-c 49152
# 2. Open WebUI Connection Settings
# Go to Admin Settings > Connections > OpenAI API section and add:
# API Base URL: http://localhost:8080/v1 (or [http://host.docker.internal:8080/v1](http://host.docker.internal:8080/v1) for Docker)
# API Key: sk-dummy (Any string will work)
🛠 Advanced: LoRA Merging Technique & Verification
Normally, merging LoRA into a quantized base model and saving it with requantization causes the microscopic weight differences (learning effects) of LoRA to be rounded off and lost. To prevent this, our model implements a two-step countermeasure:
- Preventing Difference Loss During Merge (Modification of
mlx_lm.fuse) During the merge execution, the Python code was modified so that the target layers to which LoRA was applied are retained in full precision (e.g., FP16) without being requantized immediately. This reliably maintains the learned microscopic differences. - Preventing Requantization During Load (Adjustment of
config.json) When loading the merged model, to prevent the full precision layers from being unintentionally requantized by old quantization specifications remaining in the configuration file, the quantization settings for target layers (such asmlp.gate_proj,up_proj,down_proj) were precisely deleted fromconfig.json.
Merge Verification Results
We rigorously verified whether the above methods functioned correctly using Python code.
- Perfect Weight Match: For each target layer in
language_model.model.layers, the difference (Max Diff) between the expected merged weights and the actual weights was kept under 0.0009, confirming ✅ PERFECT MATCH (Fuse fully successful). - Logits Output Verification & Insights:
- Original LoRA effect (Base+LoRA vs BASE): 23.875
- Change due to merge (Merged vs BASE): 23.750
- The deviation from the target is minimal, proving that the LoRA weights were not lost (No Silent Dropping) and the learning effects were properly reflected in the base model.
- Validation of Method on MoE Architecture: Furthermore, the magnitude of change in these logits demonstrates the effectiveness of applying LoRA across a wide range of target modules, even with a low rank (Rank 4) and a low learning rate. It numerically confirms that in MoE (Mixture of Experts) models, such microscopic weight updates produce a definitive and meaningful shift in inference behavior.
StagAI-CyberSecurity-26B-A4B-v2 (日本語版)
StagAI-CyberSecurity-26B-A4B-v2 は、サイバーセキュリティ分野の分析と高度な理論的推論に特化して開発された、"テキスト専用"の大規模言語モデルです。
安定な Gemma-4-26B-A4B(MoE)アーキテクチャ をベースとし、MLXフレームワーク (mlx_lm.lora) を用いてファインチューニングを実施しました。学習完了後、LoRA調整は独自の工夫を用いてベースモデルにマージされており、ダウンロード後すぐにデプロイして高品質な推論を使用することが可能です。
また、本モデルは、セキュリティ専門家、研究者、SOCアナリスト、システム管理者などが、脅威モデリング、脆弱性評価、ログの解釈、そして包括的なインシデント対応戦略を構築する際の推論エンジンを目指して作られています。
※本モデルはテキスト入力専用であり、画像や音声などのマルチモーダル入力には対応していません。
ベースモデルからの性能向上
サイバーセキュリティに関する様々な質問を用いてオリジナルのベースモデルと比較検証を行った結果、本モデルには以下の特徴が確認されています。
- 回答品質の向上: 複雑なサイバーセキュリティの質問に対し、より正確で文脈に沿った、実務に直結する回答を提供します。前モデル(CyberStag-Security-26B-A4B-V1)と比較しても、回答品質がより向上していることを確認しております。
- 推論の深さ: 回答の生成を開始するまでの「思考時間(レイテンシ)」がわずかに増加する傾向が見られます。これは、表面的な回答を避け、より深くステップバイステップの論理的演繹を行うためのトレードオフであり、結果として非常に分析的で高品質な出力を生み出すものと考えます。
🛡️ QLoRA適応と安全性の内部構造検証 (Detailed Structural & Safety Verification)
ファインチューニングモデルにおいては、事後学習による「基礎言語能力や視覚認識(VLM)の劣化リスク」や、専門用語への回答率を上げるために「安全機構(拒否ベクトル)を人為的に除去(Abliteration / Uncensoring)してしまうリスク」が課題となります。
本モデル(StagAI-CyberSecurity-26B-A4B-v2-VLM)では、ベースモデルの安全性と基礎能力を損なわずにサイバーセキュリティの専門知識が注入されていることを証明するため、①パラメータ差分行列 $\Delta W$ の特異値分解(SVD) と ②残差ストリーム上の拒否ベクトル解析 を実施しました。
📊 1. 主要検証メトリクス一覧(中間層 $L=15$ および全体統計)
| 検証項目 | 実測値 ($L=15$) | 更新層(L12-29)統計 | 数値が証明する意味・解釈 |
|---|---|---|---|
| 下位層・視覚層の重み変化率 | 0.000% |
全層 0.000% |
基礎言語層(L00-11)と視覚エンコーダ(Vision Tower)が100%無傷で保護されている証明 |
| 上位推論層の重み変化率 | 0.163% |
平均 0.128% |
ベースモデルの重み構造を破壊しない、極めて低侵襲かつ精密なパラメータ更新 |
| MoEルーターの重み変化率 | 0.000% |
全層 0.000% |
128個のエキスパートへの振り分け経路(Routing)を固定し、エキスパート内部の知識のみを強化 |
| 有効ランク (Stable Rank) | 1.41 |
1.41 〜 1.83 |
最大2,112次元中、実質約1.4本分の主成分軸に変化が凝縮された純粋な低ランク学習の証拠 |
| 上位4特異値への集中度 | 72.5% |
第1軸単体 71.2% |
Rank=4 のQLoRA設計と完全に一致し、上位4方向だけで全更新エネルギーの7割以上を支配 |
| 拒否ベクトルの類似度 | 0.9994 (1.99°) |
平均 0.9976 (3.58°) |
有害要求を識別する内部ベクトルの向きがベースモデルと99.9%以上一致していることを証明 |
| 拒否ベクトルへの射影比率 | 0.0105 |
平均 0.0257 |
無相関なランダムベクトルの理論期待値($1/\sqrt{d} = 0.0188$)と同等であり、安全領域への非干渉を実証 |
| Abliteration方向との類似度 | 0.00032 |
最大 0.00203 |
理論上の完全直交(0.0)に極めて近く、人為的な検閲解除(Abliteration)を行っていない証明 |
| 有害 vs 良性 識別マージン | 1.0000 / 17.13 |
Base比 +0.53 拡大 |
悪意ある攻撃要求と一般要求の分離精度は100%を維持し、識別マージンはベースモデル以上に向上 |
| 防衛実務クエリ 正常応答率 | 100.0% |
最終層: 75.0%→**81.3%** |
正当なセキュリティ実務質問を悪用と誤認して弾く「過拒否(Over-refusal)」を +6.3pt 改善 |
🔍 2. 各検証項目の詳細解説
① 基礎能力の完全保護と、上位18層への「選択的QLoRA適応」(グラフ a)
各層の重み行列について、ベースモデルからの相対変化率(Frobeniusノルム比 $\Vert{}\Delta W\Vert{}F / \Vert{}W{\text{base}}\Vert{}_F$)を測定しました。
- 下位層・視覚能力の完全温存:全30層のうち、基本的な構文処理を担う Layer 00〜11(下位12層) および Visionエンコーダ(全27層) の変化率は
0.000%(完全凍結) です。これにより、VLMとしての画像認識能力や基礎的な言語能力の劣化を完全に防いでいます。 - 上位推論層(Layer 12〜29)への集中適用:専門的な知識判断や論理推論(Reasoning)を担う 上位18層(Layer 12〜29) に対してのみ、共有MLP・Attention・128個のMoEエキスパート層にわたるQLoRA更新(直接検証した主要8モジュールで約55.5億パラメータ規模)が適用されています。また、MoEの振り分けを担う
router.projを全層0.000%で固定することで、エキスパートのルーティング崩壊を防ぎつつ内部知識のみをアップデートしています。
② 特異値分解(SVD)が証明する「Rank=4 QLoRAの低ランク構造」(グラフ d)
重み差分行列 $\Delta W = W_{\text{FT}} - W_{\text{base}}$(中間層 mlp.down_proj で 2,816×2,112 = 約595万パラメータ)に対して特異値分解(SVD: $\Delta W = U \Sigma V^\top$)を行うと、パラメータの変化が「どの方向の軸に、どれだけの強さ(特異値 $\sigma_i$)で書き込まれたか」を最大2,112本の独立した成分として抽出できます。
- 上位4成分(Rank=4)へのエネルギー凝縮:本モデルでは、2,112個ある特異値のうち 上位4つの特異値($\sigma_1 \sim \sigma_4$)だけで全更新エネルギー($\Vert{}\Delta W\Vert{}_F^2$)の
72.5%(第1特異値 $\sigma_1$ 単体で71.2%) を占めており、有効ランク(Stable Rank)は1.41に収まっています。これはRank=4のQLoRA設計そのものであり、他の汎用能力を邪魔することなく「サイバーセキュリティの専門推論軸」だけに高純度な知識が注入された数学的証拠です。 - 中盤層と後半層の役割分担:意思決定の中核である中盤層(Layer 12〜15)では第1軸 $\sigma_1$ にエネルギーが集中(Stable Rank
1.41)して「セキュリティ専門家モードへの切り替え」を担い、具体的な回答を組み立てる後半層(Layer 21〜27)では第2・第3特異値のエネルギー比重が約7倍(Stable Rank1.83)へと広がり、多様なセキュリティ知識や対策コードを展開する階層構造となっています。
③ 安全機構(拒否ベクトル)の高度な維持(グラフ b)
先行研究(Arditi et al., NeurIPS 2024)に基づき、有害な攻撃プロンプト群と良性プロンプト群の残差ストリームの差分平均(Difference-in-Means)から、モデル内部で拒否応答を司る「拒否ベクトル $\hat{r}$」を各層で抽出しました。
- ベースモデルとの高い方向一致:ベースモデルと本モデルの拒否ベクトルのコサイン類似度 $\cos(\hat{r}{\text{base}}, \hat{r}{\text{FT}})$ は、中間層(Layer 15)で
0.9994(角度差 わずか1.99°)、更新された全18層の平均でも0.9976(平均角度差3.58°) を記録しました。プロンプト末尾のトークン集計幅(last-k$\in {1, 2, 4, 8}$)を変えた感度検証でも中間層の角度差は1.99°〜2.27°と揺らぐことがなく、ベースモデルの安全判断軸が強固に保たれています。
④ 非改ざん(Anti-Abliteration)の数学的保証(グラフ c)
公開モデルの中には、拒否ベクトル方向の重み成分を射影除去($\Delta W_{\text{ablit}} = \hat{r}{\text{base}} \hat{r}{\text{base}}^\top W_{\text{base}}$)することで安全フィルタを無効化する「Abliteration(Uncensoring)」を施したものがあります。本モデルがそのような改ざんを行っていないことを2つの指標で検証しました。
- Abliteration方向との直交性:重み差分 $\Delta W$ と拒否除去テンプレート $\Delta W_{\text{ablit}}$ のコサイン類似度は、中間層 $L=15$ の
mlp.down_projで **0.00032**、self_attn.o_projで **0.0000048**(全30層の最大値でも **0.00203**)と理論上の完全直交(0.0)に極めて近く、意図的な安全フィルタ除去が行われていないことを証明しています。 - ランダム理論値と一致する射影比率:重み更新 $\Delta W$ が拒否ベクトル方向に射影される比率 $\Vert{}\hat{r}^\top \Delta W\Vert{}_2 / \Vert{}\Delta W\Vert{}_F$(紫線)は、中間層で **
0.0105**(Attention出力層平均 **0.0202**)となり、2,816次元空間において拒否方向と全く無関係(ランダム)に重みを更新した際の数学的期待値 $1/\sqrt{2816} \approx \mathbf{0.0188}$(黒破線)の周囲に分布しています。すなわち、安全機構と直交する独立した部分空間で専門知識の学習が行われています。
⑤ 「悪用遮断の強化」と「防衛実務の過拒否(Over-refusal)抑制」の両立
セキュリティ実務でLLMを活用する際、「SQLインジェクションの修正」「Sigma/YARA検知ルールの作成」「パケット解析」といった正当な防御・診断業務の質問に対し、モデルが専門用語に過剰反応して回答を拒否してしまう「過拒否(Over-refusal)」が大きな課題となります。
- 悪意ある攻撃に対する識別力の向上:悪意ある攻撃要求と一般要求の線形分離精度は AUROC =
1.0000(100%分離) を維持しつつ、両分布の識別距離(Cohen's $d$)はベースの16.61から17.13($L=15$)、最終層($L=29$)でも3.22から3.60へと拡大しています。 - 正当な防衛実務クエリの応答率改善:同時に、正当なサイバー防衛実務クエリに対する最終出力層(Layer 29)での正常応答率(非拒否率)は、ベースモデルの
75.0%から81.3%(81.25%、+6.25pt改善) へと向上しています。これは安全基準を緩めたのではなく、専門知識の獲得によって「悪意ある攻撃」と「正当なセキュリティ防衛実務」の文脈を高精度に識別できるようになったことを示しています。
Methodology based on Singular Value Decomposition (SVD) of parameter deltas and Difference-in-Means (DiM) activation geometry (Arditi et al., NeurIPS 2024).
公開モデル
ハイエンドなワークステーションからエッジデバイスまで、様々なハードウェア環境に対応するため、複数のフォーマットを提供しています。
MLX フォーマット (Apple Silicon向け最適化)
StagAI-CyberSecurity-26B-A4B-v2-FP16-MLX: 非量子化(FP16)フォーマット。StagAI-CyberSecurity-26B-A4B-v2-Q8-MLX: QLoRAのベースモデルにアダプターをマージした8bit量子化モデル。オリジナルの推論性能を維持する、非常にバランスの取れたフォーマット。最もおすすめ。StagAI-CyberSecurity-26B-A4B-v2-Q4-MLX: 4bit量子化されたベースモデルにアダプターをマージした4bit量子化モデル。Doom Loop問題の削減を目的としたマージ手法により、モデルサイズが通常より大きくなっております。
GGUF フォーマット (llama.cpp, LM Studio 等向け)
StagAI-CyberSecurity-26B-A4B-v2-FP16.gguf: StagAI-CyberSecurity-26B-A4B-v2-FP16-MLXからGGUF形式へ変換した非量子化 16bit GGUFモデル。StagAI-CyberSecurity-26B-A4B-v2-Q8_0.gguf: 8bit 量子化 GGUFモデル (高精度、中程度のメモリ要求)。StagAI-CyberSecurity-26B-A4B-v2-FP16.ggufから量子化を実施。StagAI-CyberSecurity-26B-A4B-v2-Q4_K_M.gguf: 4bit 量子化 GGUFモデル (非常に軽量。VRAMに制限のある環境での実行に強く推奨します)。StagAI-CyberSecurity-26B-A4B-v2-FP16.ggufから量子化を実施。
ライセンス (License)
本モデルは元モデルのライセンスを継承し、Apache License 2.0 の下で提供されています。商用利用、改変、再配布が自由に可能です。
免責事項 (Disclaimer)
本モデルは、教育目的、学習の支援、防御側のサイバーセキュリティ研究、ハードニングの支援、およびシステム回復力の向上を目的としてのみ提供されています。また、本モデルを不正アクセス、攻撃用エクスプロイトの生成、その他あらゆるサイバー犯罪に悪用することを明確に禁止します。 なお、本モデルをダウンロードおよび利用した時点で、ユーザーはセキュリティの向上および倫理的な研究の目的にのみ本モデルを使用することに明示的に同意したものとみなされます。
📊 Training Details (学習データと設定)
データセット
多数の領域にわたる高品質なサイバーセキュリティタスクのSFT(Supervised Fine-Tuning)データセットを使用しています。
- 英語データセット: 40,000件
- 日本語データセット: 40,000件
- 合計: 80,000件
上記データセットを用い、QLoRA (8bit) にてトレーニングを実施しました。
学習パラメータ
ファインチューニングは以下のパラメータおよびLoRA詳細設定で行われました。
# 学習基本パラメータ
fine_tune_type: "lora"
optimizer: "adamw"
num_layers: 18
learning_rate: 5e-7
mask_prompt: true
# LoRA詳細設定
lora_parameters:
rank: 4
scale: 1.0
dropout: 0.03
keys:
- "self_attn.q_proj"
- "self_attn.k_proj"
- "self_attn.v_proj"
- "self_attn.o_proj"
- "mlp.gate_proj"
- "mlp.up_proj"
- "mlp.down_proj"
- "experts.switch_glu.gate_proj"
- "experts.switch_glu.down_proj"
- "experts.switch_glu.up_proj"
Trainable parameters: 0.397% (100.109M/25233.053M)
⚠️ Important Notes & Best Practices (使用上の注意点と推奨設定)
本モデルのパフォーマンスを最大限に引き出すため、以下の点にご留意ください。
- 最高精度は8bitモデル: QLoRA(8bit)で学習を実施している関係上、最も精度が高く本来の性能を発揮するのは 8bitモデル となる可能性が高いです。
- MLX形式とGGUF形式の差異: 公開しているGGUFモデルは、FP16のMLX形式モデルからGGUFへ変換したものです。そのため、ネイティブのMLX形式の方がより高精度になる可能性があります。(※より最適なGGUF形式への変換手法をご存知のユーザー様や有識者の方がいらっしゃいましたら、ぜひご協力をお願いいたします。)
- 低ビット(4bit)モデルにおけるDoom Loop対策: 4bit量子化モデルなど低ビット環境では、生成の反復ループ(Doom Loop)の発生確率が高まります。これを防ぐため、4bitのMLX形式のモデルには
"temperature": 0.5に下げた設定ファイルを配置しています。GGUFの低ビットモデルを使用する際も、temperature等の設定値を調整することを推奨します。
💡 GGUFモデルの推奨使用方法(推論プロセス強制)
GGUF版モデルは、思考プロセス(Thinkingブロック)を確実に展開させるため、16bitのMLXモデルの tokenizer_config.json にJinjaテンプレート(chat_template.jinja)のメタデータを事前埋め込みしてから量子化する工夫を施しています。
【重要】Ollamaでの使用に関する注意
Ollamaに登録して使用する場合、ネイティブレンダラーによる強制上書きが発生し、プロンプトの内容次第で推論(Thinking)ブロックがスキップされる可能性が十分にあります。
そのため、MLXと100%同一のプロンプト処理を適用できる llama-server と Open WebUI の連携等による運用をおすすめします。
推奨環境の構築手順 (llama.cpp)
# 1. llama-serverの起動 (Jinja2エンジン[minja]のネイティブサポートを活用)
./build/bin/llama-server \
-m /path/to/StagAI-CyberSecurity-26B-A4B-v2-Q4_K_M.gguf \
--port 8080 \
-ngl 99 \
-c 49152
# 2. Open WebUI側の接続設定
# 管理者設定 > 接続 > OpenAI APIセクションに以下を追加
# APIベースURL: http://localhost:8080/v1 (Dockerの場合は [http://host.docker.internal:8080/v1](http://host.docker.internal:8080/v1))
# APIキー: sk-dummy (任意の文字列)
🛠 Advanced: LoRAマージ手法の工夫と検証
通常、量子化されたベースモデルにLoRAをマージし、再度量子化して保存すると、LoRAの微小な重みの差分(学習効果)が丸め落とされて消失してしまう問題があります。本モデルでは、これを防ぐために以下の2段構えの対策を実施しています。
- マージ時の差分消失防止 (
mlx_lm.fuseの修正) マージの実行時、LoRAを適用した対象層を直後に再量子化せず、フル精度(FP16等)のまま保持するようPythonコードを修正しました。これにより、学習した微小な差分を確実に維持しています。 - 読み込み時の再量子化防止 (
config.jsonの調整) マージ済みモデルを読み込む際、設定ファイルに残っている古い量子化指定によってフル精度の層が意図せず再量子化されるのを防ぐため、対象層(mlp.gate_proj,up_proj,down_proj等)の量子化設定をconfig.jsonからピンポイントで削除しています。
マージ検証結果
上記の手法が正しく機能しているか、Pythonコードを用いて厳密にチェックを行いました。
- 重みの完全一致:
language_model.model.layersの各対象レイヤーにおいて、予想されるマージ後の重みと実際の重みの差分(Max Diff)が 0.0009 未満に収まり、✅ PERFECT MATCH (Fuse完全成功) を確認しました。 - 出力(Logits)の検証と考察:
- LoRAの本来の効果量(Base+LoRA vs BASE): 23.875
- マージによる変化量(Merged vs BASE): 23.750
- 目標との乖離がごくわずかであり、LoRAの重みが消失(Silent Dropping)することなく、ベースモデルに学習効果が適切に反映されていることを実証しています。
- アーキテクチャに対する手法の有効性: さらに、このLogitsの変化量は、低ランク(Rank 4)かつ低学習率であっても、幅広いモジュールにLoRAを適用する今回の手法が極めて有効であることを示しています。特にMoE(Mixture of Experts)モデルにおいて、微小な重み更新が推論結果に確かな変化をもたらすことが数値的にも裏付けられました。
- Downloads last month
- 413
4-bit