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