File size: 10,166 Bytes
d966675 fb3b4ea d966675 bf3dcaf 5d852d8 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf 358b1c3 bf3dcaf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
---
license: apache-2.0
base_model: deepseek-ai/deepseek-coder-6.7b-instruct
tags:
- code
- security
- deepseek
- securecode
- owasp
- vulnerability-detection
datasets:
- scthornton/securecode-v2
language:
- en
library_name: transformers
pipeline_tag: text-generation
arxiv: 2512.18542
---
# DeepSeek-Coder 6.7B - SecureCode Edition
<div align="center">
[](https://opensource.org/licenses/Apache-2.0)
[](https://huggingface.co/datasets/scthornton/securecode-v2)
[](https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-instruct)
[](https://perfecxion.ai)
**Security-optimized code model - built for vulnerability detection**
[📄 Paper](https://arxiv.org/abs/2512.18542) | [🤗 Model Card](https://huggingface.co/scthornton/deepseek-coder-6.7b-securecode) | [📊 Dataset](https://huggingface.co/datasets/scthornton/securecode-v2) | [💻 perfecXion.ai](https://perfecxion.ai)
</div>
---
## 🎯 What is This?
This is **DeepSeek-Coder 6.7B Instruct** fine-tuned on the **SecureCode v2.0 dataset** - a code model specifically designed for **security analysis and vulnerability detection**.
DeepSeek-Coder was trained on **2 trillion tokens** with a unique focus on code understanding and generation. Combined with SecureCode training, this model excels at:
✅ **Identifying subtle security flaws** in complex codebases
✅ **Generating hardened implementations** optimized for security
✅ **Explaining vulnerability chains** with step-by-step attack demonstrations
✅ **Providing remediation guidance** with defense-in-depth patterns
**The Result:** A security-first code model that balances performance with specialized vulnerability detection capabilities.
**Why Deep Seek-Coder?** This model offers:
- 🔍 **Excellent code comprehension** - Trained specifically for understanding code structure
- 🛡️ **Security-aware architecture** - Pre-training included security-focused code
- ⚡ **Efficient inference** - Compact 6.7B size with strong performance
- 🎯 **Balanced trade-off** - Better than 3B models, more efficient than 13B+
- 💰 **Cost-effective** - Optimal performance-per-parameter ratio
---
## 🚨 The Problem This Solves
**AI coding assistants produce vulnerable code in 45% of security-relevant scenarios** (Veracode 2025). DeepSeek-Coder SecureCode Edition addresses this by combining deep code understanding with security expertise.
**Real-world impact:**
- Equifax breach (SQL injection): **$425 million**
- Capital One (SSRF): **100 million** records exposed
- SolarWinds (auth bypass): **18,000** orgs compromised
This model was specifically fine-tuned to prevent these vulnerability classes.
---
## 💡 Key Features
### 🛡️ Security-Optimized Base Model
DeepSeek-Coder outperforms many larger models on code tasks:
- HumanEval: **78.6%** pass@1 (beats CodeLlama 13B)
- MBPP: **70.2%** pass@1
- Strong performance on security-relevant code patterns
Now enhanced with **1,209 security-focused examples** covering OWASP Top 10:2025.
### 🔐 Comprehensive Vulnerability Coverage
Trained on real-world security incidents:
- **224 examples** of Broken Access Control
- **199 examples** of Authentication Failures
- **125 examples** of Injection attacks
- **115 examples** of Cryptographic Failures
- Full **OWASP Top 10:2025** coverage
### 🌍 Multi-Language Security Expertise
Fine-tuned on security examples across:
- Python (Django, Flask, FastAPI)
- JavaScript/TypeScript (Express, NestJS)
- Java (Spring Boot)
- Go (Gin framework)
- PHP (Laravel, Symfony)
- C# (ASP.NET Core)
- Ruby (Rails)
- Rust (Actix, Rocket)
### 📋 Complete Security Context
Every response includes:
1. **Vulnerable code** demonstrating the flaw
2. **Secure implementation** with best practices
3. **Attack demonstration** with exploit payloads
4. **Operational guidance** for production hardening
---
## 📊 Training Details
| Parameter | Value |
|-----------|-------|
| **Base Model** | deepseek-ai/deepseek-coder-6.7b-instruct |
| **Fine-tuning Method** | LoRA (Low-Rank Adaptation) |
| **Training Dataset** | [SecureCode v2.0](https://huggingface.co/datasets/scthornton/securecode-v2) |
| **Dataset Size** | 841 training examples |
| **Training Epochs** | 3 |
| **LoRA Rank (r)** | 16 |
| **LoRA Alpha** | 32 |
| **Learning Rate** | 2e-4 |
| **Quantization** | 4-bit (bitsandbytes) |
| **Trainable Parameters** | ~35M (0.52% of total) |
| **Total Parameters** | 6.7B |
| **Context Window** | 16K tokens |
| **GPU Used** | NVIDIA A100 40GB |
| **Training Time** | ~85 minutes (estimated) |
### Training Methodology
**LoRA fine-tuning** preserves DeepSeek-Coder's code expertise while adding security knowledge:
- Trains only 0.52% of parameters
- Maintains base model quality
- Adds OWASP-focused security understanding
- Efficient deployment with minimal overhead
---
## 🚀 Usage
### Quick Start
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load base model
base_model = "deepseek-ai/deepseek-coder-6.7b-instruct"
model = AutoModelForCausalLM.from_pretrained(
base_model,
device_map="auto",
torch_dtype="auto",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
# Load SecureCode adapter
model = PeftModel.from_pretrained(model, "scthornton/deepseek-coder-6.7b-securecode")
# Analyze code for vulnerabilities
prompt = """### User:
Identify all security vulnerabilities in this authentication middleware:
```javascript
const authenticate = async (req, res, next) => {
const token = req.headers.authorization;
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = await User.findById(decoded.userId);
next();
};
```
### Assistant:
"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=2048, temperature=0.7)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```
### Production Deployment (4-bit Quantization)
```python
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
# 4-bit quantization - runs on 12GB GPU
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype="bfloat16"
)
model = AutoModelForCausalLM.from_pretrained(
"deepseek-ai/deepseek-coder-6.7b-instruct",
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True
)
model = PeftModel.from_pretrained(model, "scthornton/deepseek-coder-6.7b-securecode")
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-instruct", trust_remote_code=True)
```
---
## 🎯 Use Cases
### 1. **Vulnerability Scanning in CI/CD**
Integrate into development pipelines for automated security checks:
```
Scan this Pull Request for OWASP Top 10 vulnerabilities
```
### 2. **Security-Focused Code Generation**
Generate implementations with security as priority:
```
Write a secure user registration endpoint with input validation, rate limiting, and SQL injection prevention
```
### 3. **Legacy Code Remediation**
Identify and fix vulnerabilities in existing code:
```
Refactor this legacy authentication system to fix all security issues
```
### 4. **Security Training & Education**
Use for developer security training:
```
Explain common authentication bypass techniques and how to prevent them
```
### 5. **Threat Modeling**
Analyze architectural security:
```
Identify potential attack vectors in this microservices architecture
```
---
## ⚠️ Limitations
### What This Model Does Well
✅ Security vulnerability identification
✅ Code understanding and analysis
✅ Generating secure implementations
✅ Explaining attack vectors
### What This Model Doesn't Do
❌ Not a replacement for static analysis tools
❌ Cannot discover novel 0-day vulnerabilities
❌ Not legal/compliance advice
❌ Not a replacement for security experts
---
## 📈 Performance Benchmarks
### Hardware Requirements
**Minimum:**
- 14GB RAM
- 10GB GPU VRAM (with 4-bit quantization)
**Recommended:**
- 24GB RAM
- 12GB+ GPU (RTX 3060 Ti, RTX 4070)
**Inference Speed (on RTX 3060 12GB):**
- ~35 tokens/second (4-bit quantization)
- ~50 tokens/second (bfloat16)
### Code Generation (Base Model Scores)
| Benchmark | Score |
|-----------|-------|
| HumanEval | 78.6% |
| MBPP | 70.2% |
| MultiPL-E | 68.9% |
---
## 🔬 Dataset Information
Trained on **[SecureCode v2.0](https://huggingface.co/datasets/scthornton/securecode-v2)**:
- **1,209 examples** with real CVE grounding
- **11 vulnerability categories** (OWASP Top 10:2025)
- **11 programming languages**
- **100% expert validation**
---
## 📄 License
**Model:** Apache 2.0 | **Dataset:** CC BY-NC-SA 4.0
---
## 📚 Citation
```bibtex
@misc{thornton2025securecode-deepseek,
title={DeepSeek-Coder 6.7B - SecureCode Edition},
author={Thornton, Scott},
year={2025},
publisher={perfecXion.ai},
url={https://huggingface.co/scthornton/deepseek-coder-6.7b-securecode}
}
```
---
## 🔗 Related Models
- **[llama-3.2-3b-securecode](https://huggingface.co/scthornton/llama-3.2-3b-securecode)** - Most accessible (3B)
- **[qwen-coder-7b-securecode](https://huggingface.co/scthornton/qwen-coder-7b-securecode)** - Best code model (7B)
- **[codellama-13b-securecode](https://huggingface.co/scthornton/codellama-13b-securecode)** - Established brand (13B)
- **[starcoder2-15b-securecode](https://huggingface.co/scthornton/starcoder2-15b-securecode)** - Multi-language (15B)
[View Collection](https://huggingface.co/collections/scthornton/securecode)
---
<div align="center">
**Built with ❤️ for secure software development**
[perfecXion.ai](https://perfecxion.ai) | [Contact](mailto:scott@perfecxion.ai)
</div>
|