|
|
--- |
|
|
license: apache-2.0 |
|
|
base_model: meta-llama/Llama-3.2-3B-Instruct |
|
|
tags: |
|
|
- code |
|
|
- security |
|
|
- llama |
|
|
- meta |
|
|
- securecode |
|
|
- owasp |
|
|
- vulnerability-detection |
|
|
datasets: |
|
|
- scthornton/securecode-v2 |
|
|
language: |
|
|
- en |
|
|
library_name: transformers |
|
|
pipeline_tag: text-generation |
|
|
arxiv: 2512.18542 |
|
|
--- |
|
|
|
|
|
# Llama 3.2 3B - SecureCode Edition |
|
|
|
|
|
<div align="center"> |
|
|
|
|
|
[](https://opensource.org/licenses/Apache-2.0) |
|
|
[](https://huggingface.co/datasets/scthornton/securecode-v2) |
|
|
[](https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct) |
|
|
[](https://perfecxion.ai) |
|
|
|
|
|
**π The most accessible security-aware code model - runs anywhere** |
|
|
|
|
|
Security expertise meets consumer-grade hardware. Perfect for developers who want enterprise-level security guidance without datacenter infrastructure. |
|
|
|
|
|
[π Paper](https://arxiv.org/abs/2512.18542) | [π€ Model Hub](https://huggingface.co/scthornton/llama-3.2-3b-securecode) | [π Dataset](https://huggingface.co/datasets/scthornton/securecode-v2) | [π» perfecXion.ai](https://perfecxion.ai) | [π Collection](https://huggingface.co/collections/scthornton/securecode) |
|
|
|
|
|
</div> |
|
|
|
|
|
--- |
|
|
|
|
|
## π― Quick Decision Guide |
|
|
|
|
|
**Choose This Model If:** |
|
|
- β
You need security guidance on **consumer hardware** (8GB+ RAM) |
|
|
- β
You're running on **Apple Silicon Macs** (M1/M2/M3/M4) |
|
|
- β
You want **fast inference** for IDE integration |
|
|
- β
You're building security tools for **developer workstations** |
|
|
- β
You need **low-cost deployment** in production |
|
|
- β
You're creating **educational security tools** for students |
|
|
|
|
|
**Consider Larger Models If:** |
|
|
- β οΈ You need deep multi-file codebase analysis (β Qwen 14B, Granite 20B) |
|
|
- β οΈ You're handling complex enterprise architectures (β CodeLlama 13B, Granite 20B) |
|
|
- β οΈ You need maximum code understanding (β Qwen 7B/14B) |
|
|
|
|
|
--- |
|
|
|
|
|
## π Collection Positioning |
|
|
|
|
|
| Model | Size | Best For | Hardware | Inference Speed | Unique Strength | |
|
|
|-------|------|----------|----------|-----------------|-----------------| |
|
|
| **Llama 3.2 3B** | **3B** | **Consumer deployment** | **8GB RAM** | **β‘β‘β‘ Fastest** | **Most accessible** | |
|
|
| DeepSeek 6.7B | 6.7B | Security-optimized baseline | 16GB RAM | β‘β‘ Fast | Security architecture | |
|
|
| Qwen 7B | 7B | Best code understanding | 16GB RAM | β‘β‘ Fast | Best-in-class 7B | |
|
|
| CodeGemma 7B | 7B | Google ecosystem | 16GB RAM | β‘β‘ Fast | Instruction following | |
|
|
| CodeLlama 13B | 13B | Enterprise trust | 24GB RAM | β‘ Medium | Meta brand, proven | |
|
|
| Qwen 14B | 14B | Advanced analysis | 32GB RAM | β‘ Medium | 128K context window | |
|
|
| StarCoder2 15B | 15B | Multi-language specialist | 32GB RAM | β‘ Medium | 600+ languages | |
|
|
| Granite 20B | 20B | Enterprise-scale | 48GB RAM | Medium | IBM trust, largest | |
|
|
|
|
|
**This Model's Sweet Spot:** Maximum accessibility + solid security guidance. Ideal for developer tools, educational platforms, and consumer applications. |
|
|
|
|
|
--- |
|
|
|
|
|
## π¨ The Problem This Solves |
|
|
|
|
|
**AI coding assistants produce vulnerable code in 45% of security-relevant scenarios** (Veracode 2025). When developers rely on standard code models for security-sensitive features like authentication, authorization, or data handling, they unknowingly introduce critical vulnerabilities. |
|
|
|
|
|
**Real-world costs:** |
|
|
- **Equifax breach** (SQL injection): $425 million in damages + brand destruction |
|
|
- **Capital One** (SSRF attack): 100 million customer records exposed, $80M fine |
|
|
- **SolarWinds** (authentication bypass): 18,000 organizations compromised |
|
|
- **LastPass** (cryptographic failures): 30 million users' password vaults at risk |
|
|
|
|
|
This model was trained to prevent these exact scenarios by understanding security at the code level. |
|
|
|
|
|
--- |
|
|
|
|
|
## π‘ What is This? |
|
|
|
|
|
This is **Llama 3.2 3B Instruct** fine-tuned on the **SecureCode v2.0 dataset** - a production-grade collection of 1,209 security-focused coding examples covering the complete OWASP Top 10:2025. |
|
|
|
|
|
Unlike standard code models that frequently generate vulnerable code, this model has been specifically trained to: |
|
|
|
|
|
β
**Recognize security vulnerabilities** in code across 11 programming languages |
|
|
β
**Generate secure implementations** with defense-in-depth patterns |
|
|
β
**Explain attack vectors** with concrete exploitation examples |
|
|
β
**Provide operational guidance** including SIEM integration, logging, and monitoring |
|
|
|
|
|
**The Result:** A code assistant that thinks like a security engineer, not just a developer. |
|
|
|
|
|
**Why 3B Parameters?** At only 3B parameters, this is the **most accessible** security-focused code model. It runs on: |
|
|
- π» Consumer laptops with 8GB+ RAM |
|
|
- π± Apple Silicon Macs (M1/M2/M3/M4) |
|
|
- π₯οΈ Desktop GPUs (RTX 3060+, even RTX 2060) |
|
|
- βοΈ Free Colab/Kaggle notebooks |
|
|
- π Edge devices and embedded systems |
|
|
|
|
|
Perfect for developers who want security guidance without requiring datacenter infrastructure. |
|
|
|
|
|
--- |
|
|
|
|
|
## π Security Training Coverage |
|
|
|
|
|
### Real-World Vulnerability Distribution |
|
|
|
|
|
Trained on 1,209 security examples with real CVE grounding: |
|
|
|
|
|
| OWASP Category | Examples | Real Incidents | |
|
|
|----------------|----------|----------------| |
|
|
| **Broken Access Control** | 224 | Equifax, Facebook, Uber | |
|
|
| **Authentication Failures** | 199 | SolarWinds, Okta, LastPass | |
|
|
| **Injection Attacks** | 125 | Capital One, Yahoo, LinkedIn | |
|
|
| **Cryptographic Failures** | 115 | LastPass, Adobe, Dropbox | |
|
|
| **Security Misconfiguration** | 98 | Tesla, MongoDB, Elasticsearch | |
|
|
| **Vulnerable Components** | 87 | Log4Shell, Heartbleed, Struts | |
|
|
| **Identification/Auth Failures** | 84 | Twitter, GitHub, Reddit | |
|
|
| **Software/Data Integrity** | 78 | SolarWinds, Codecov, npm | |
|
|
| **Logging Failures** | 71 | Various incident responses | |
|
|
| **SSRF** | 69 | Capital One, Shopify | |
|
|
| **Insecure Design** | 59 | Architectural flaws | |
|
|
|
|
|
### Multi-Language Support |
|
|
|
|
|
Fine-tuned on security examples across: |
|
|
- **Python** (Django, Flask, FastAPI) - 280 examples |
|
|
- **JavaScript/TypeScript** (Express, NestJS, React) - 245 examples |
|
|
- **Java** (Spring Boot) - 178 examples |
|
|
- **Go** (Gin framework) - 145 examples |
|
|
- **PHP** (Laravel, Symfony) - 112 examples |
|
|
- **C#** (ASP.NET Core) - 89 examples |
|
|
- **Ruby** (Rails) - 67 examples |
|
|
- **Rust** (Actix, Rocket) - 45 examples |
|
|
- **C/C++** (Memory safety) - 28 examples |
|
|
- **Kotlin, Swift** - 20 examples |
|
|
|
|
|
--- |
|
|
|
|
|
## π― Deployment Scenarios |
|
|
|
|
|
### Scenario 1: IDE Integration (VS Code / Cursor / JetBrains) |
|
|
|
|
|
**Perfect fit for real-time security suggestions in developer IDEs.** |
|
|
|
|
|
**Hardware:** Developer laptop with 8GB+ RAM |
|
|
**Latency:** ~50ms per completion (local inference) |
|
|
**Use Case:** Real-time security linting and code review |
|
|
|
|
|
```python |
|
|
# Example: Cursor IDE integration |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig |
|
|
from peft import PeftModel |
|
|
|
|
|
# Load quantized for fast IDE response |
|
|
bnb_config = BitsAndBytesConfig(load_in_4bit=True) |
|
|
model = AutoModelForCausalLM.from_pretrained( |
|
|
"meta-llama/Llama-3.2-3B-Instruct", |
|
|
quantization_config=bnb_config, |
|
|
device_map="auto" |
|
|
) |
|
|
model = PeftModel.from_pretrained(model, "scthornton/llama-3.2-3b-securecode") |
|
|
|
|
|
# Now: Real-time security suggestions as you code |
|
|
``` |
|
|
|
|
|
**ROI:** Catch vulnerabilities **before** they reach code review. Typical enterprise saves **$100K-$500K/year** in remediation costs. |
|
|
|
|
|
--- |
|
|
|
|
|
### Scenario 2: Educational Platform (Coding Bootcamps / Universities) |
|
|
|
|
|
**Teach secure coding without expensive infrastructure.** |
|
|
|
|
|
**Hardware:** Student laptops (8GB RAM minimum) |
|
|
**Deployment:** Self-hosted or free tier cloud |
|
|
**Use Case:** Interactive security training for developers |
|
|
|
|
|
**Value Proposition:** |
|
|
- Students learn secure patterns from day 1 |
|
|
- No cloud costs - runs on student hardware |
|
|
- Scalable to thousands of students |
|
|
- Real vulnerability examples from actual breaches |
|
|
|
|
|
--- |
|
|
|
|
|
### Scenario 3: CI/CD Security Check |
|
|
|
|
|
**Automated security review in build pipeline.** |
|
|
|
|
|
**Hardware:** Standard CI runner (8GB RAM) |
|
|
**Latency:** ~2-3 minutes for 1,000-line review |
|
|
**Use Case:** Pre-merge security validation |
|
|
|
|
|
```yaml |
|
|
# GitHub Actions example |
|
|
- name: Security Code Review |
|
|
run: | |
|
|
docker run --gpus all \ |
|
|
-v $(pwd):/code \ |
|
|
securecode/llama-3b-securecode:latest \ |
|
|
review /code --format json |
|
|
``` |
|
|
|
|
|
**ROI:** Block vulnerabilities before merge. Reduces post-deploy security fixes by **70-80%**. |
|
|
|
|
|
--- |
|
|
|
|
|
### Scenario 4: Security Training Chatbot |
|
|
|
|
|
**24/7 security knowledge base for development teams.** |
|
|
|
|
|
**Hardware:** Single GPU server (RTX 3090 / A5000) |
|
|
**Capacity:** 50-100 concurrent users |
|
|
**Use Case:** On-demand security expertise |
|
|
|
|
|
**Metrics:** |
|
|
- Reduces security team tickets by **40%** |
|
|
- Answers common questions instantly |
|
|
- Scales security knowledge across entire org |
|
|
|
|
|
--- |
|
|
|
|
|
## π Training Details |
|
|
|
|
|
| Parameter | Value | Why This Matters | |
|
|
|-----------|-------|------------------| |
|
|
| **Base Model** | meta-llama/Llama-3.2-3B-Instruct | Proven foundation, optimized for instruction following | |
|
|
| **Fine-tuning Method** | LoRA (Low-Rank Adaptation) | Efficient training, preserves base capabilities | |
|
|
| **Training Dataset** | [SecureCode v2.0](https://huggingface.co/datasets/scthornton/securecode-v2) | 100% incident-grounded, expert-validated | |
|
|
| **Dataset Size** | 841 training examples | Focused on quality over quantity | |
|
|
| **Training Epochs** | 3 | Optimal convergence without overfitting | |
|
|
| **LoRA Rank (r)** | 16 | Balanced parameter efficiency | |
|
|
| **LoRA Alpha** | 32 | Learning rate scaling factor | |
|
|
| **Learning Rate** | 2e-4 | Standard for LoRA fine-tuning | |
|
|
| **Quantization** | 4-bit (bitsandbytes) | Enables consumer hardware training | |
|
|
| **Trainable Parameters** | 24.3M (0.75% of 3.2B total) | Minimal parameters, maximum impact | |
|
|
| **Total Parameters** | 3.2B | Small enough for edge deployment | |
|
|
| **GPU Used** | NVIDIA A100 40GB | Enterprise training infrastructure | |
|
|
| **Training Time** | 22 minutes | Fast iteration cycles | |
|
|
| **Final Training Loss** | 0.824 | Strong convergence, solid learning | |
|
|
|
|
|
### Training Methodology |
|
|
|
|
|
**LoRA (Low-Rank Adaptation)** was chosen for three critical reasons: |
|
|
1. **Efficiency:** Trains only 0.75% of model parameters (24.3M vs 3.2B) |
|
|
2. **Quality:** Preserves base model's code generation capabilities |
|
|
3. **Deployability:** Minimal memory overhead enables consumer hardware deployment |
|
|
|
|
|
**Loss Progression Analysis:** |
|
|
- Epoch 1: 1.156 (baseline understanding) |
|
|
- Epoch 2: 0.912 (security pattern recognition) |
|
|
- Epoch 3: 0.824 (full convergence) |
|
|
|
|
|
**Result:** Excellent convergence showing strong security knowledge integration without catastrophic forgetting. |
|
|
|
|
|
--- |
|
|
|
|
|
## π Usage |
|
|
|
|
|
### Quick Start (Fastest Path to Secure Code) |
|
|
|
|
|
```python |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
from peft import PeftModel |
|
|
|
|
|
# Load base model and tokenizer |
|
|
base_model = "meta-llama/Llama-3.2-3B-Instruct" |
|
|
model = AutoModelForCausalLM.from_pretrained( |
|
|
base_model, |
|
|
device_map="auto", |
|
|
torch_dtype="auto" |
|
|
) |
|
|
tokenizer = AutoTokenizer.from_pretrained(base_model) |
|
|
|
|
|
# Load SecureCode LoRA adapter |
|
|
model = PeftModel.from_pretrained(model, "scthornton/llama-3.2-3b-securecode") |
|
|
|
|
|
# Generate secure code |
|
|
prompt = """### User: |
|
|
How do I implement JWT authentication in Express.js? |
|
|
|
|
|
### Assistant: |
|
|
""" |
|
|
|
|
|
inputs = tokenizer(prompt, return_tensors="pt").to(model.device) |
|
|
outputs = model.generate( |
|
|
**inputs, |
|
|
max_new_tokens=2048, |
|
|
temperature=0.7, |
|
|
top_p=0.95, |
|
|
do_sample=True |
|
|
) |
|
|
|
|
|
response = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
print(response) |
|
|
``` |
|
|
|
|
|
--- |
|
|
|
|
|
### Consumer Hardware Deployment (8GB RAM) |
|
|
|
|
|
```python |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig |
|
|
from peft import PeftModel |
|
|
|
|
|
# 4-bit quantization for consumer GPUs |
|
|
bnb_config = BitsAndBytesConfig( |
|
|
load_in_4bit=True, |
|
|
bnb_4bit_use_double_quant=True, |
|
|
bnb_4bit_quant_type="nf4", |
|
|
bnb_4bit_compute_dtype="bfloat16" |
|
|
) |
|
|
|
|
|
base_model = AutoModelForCausalLM.from_pretrained( |
|
|
"meta-llama/Llama-3.2-3B-Instruct", |
|
|
quantization_config=bnb_config, |
|
|
device_map="auto" |
|
|
) |
|
|
|
|
|
model = PeftModel.from_pretrained(base_model, "scthornton/llama-3.2-3b-securecode") |
|
|
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct") |
|
|
|
|
|
# Now runs on: |
|
|
# - MacBook Air M1 (8GB) |
|
|
# - RTX 3060 (12GB) |
|
|
# - RTX 2060 (6GB) |
|
|
# - Free Google Colab |
|
|
``` |
|
|
|
|
|
--- |
|
|
|
|
|
### Production Deployment (Merge for Speed) |
|
|
|
|
|
For production deployment, merge the adapter for 2-3x faster inference: |
|
|
|
|
|
```python |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
from peft import PeftModel |
|
|
|
|
|
# Load base + adapter |
|
|
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct") |
|
|
model = PeftModel.from_pretrained(base_model, "scthornton/llama-3.2-3b-securecode") |
|
|
|
|
|
# Merge and save |
|
|
merged_model = model.merge_and_unload() |
|
|
merged_model.save_pretrained("./securecode-merged") |
|
|
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct") |
|
|
tokenizer.save_pretrained("./securecode-merged") |
|
|
|
|
|
# Deploy merged model for fastest inference |
|
|
``` |
|
|
|
|
|
**Performance gain:** 2-3x faster than adapter loading, critical for production APIs. |
|
|
|
|
|
--- |
|
|
|
|
|
### Integration with LangChain (Enterprise Workflow) |
|
|
|
|
|
```python |
|
|
from langchain.llms import HuggingFacePipeline |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline |
|
|
from peft import PeftModel |
|
|
|
|
|
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct") |
|
|
model = PeftModel.from_pretrained(base_model, "scthornton/llama-3.2-3b-securecode") |
|
|
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct") |
|
|
|
|
|
pipe = pipeline( |
|
|
"text-generation", |
|
|
model=model, |
|
|
tokenizer=tokenizer, |
|
|
max_new_tokens=2048, |
|
|
temperature=0.7 |
|
|
) |
|
|
|
|
|
llm = HuggingFacePipeline(pipeline=pipe) |
|
|
|
|
|
# Use in LangChain |
|
|
from langchain.prompts import PromptTemplate |
|
|
from langchain.chains import LLMChain |
|
|
|
|
|
security_template = """Review this code for OWASP Top 10 vulnerabilities: |
|
|
|
|
|
{code} |
|
|
|
|
|
Provide specific vulnerability details and secure alternatives.""" |
|
|
|
|
|
prompt = PromptTemplate(template=security_template, input_variables=["code"]) |
|
|
chain = LLMChain(llm=llm, prompt=prompt) |
|
|
|
|
|
# Automated security review workflow |
|
|
result = chain.run(code=user_submitted_code) |
|
|
``` |
|
|
|
|
|
--- |
|
|
|
|
|
## π Performance & Benchmarks |
|
|
|
|
|
### Hardware Requirements |
|
|
|
|
|
| Deployment | RAM | GPU VRAM | Tokens/Second | Latency (2K response) | Cost/Month | |
|
|
|-----------|-----|----------|---------------|----------------------|------------| |
|
|
| **4-bit Quantized** | 8GB | 4GB | ~20 tok/s | ~100 seconds | $0 (local) | |
|
|
| **8-bit Quantized** | 12GB | 6GB | ~25 tok/s | ~80 seconds | $0 (local) | |
|
|
| **Full Precision (bf16)** | 16GB | 8GB | ~35 tok/s | ~57 seconds | $0 (local) | |
|
|
| **Cloud (Replicate)** | N/A | N/A | ~40 tok/s | ~50 seconds | ~$15-30 | |
|
|
|
|
|
**Winner:** Local deployment. Zero ongoing costs, full data privacy. |
|
|
|
|
|
### Real-World Performance |
|
|
|
|
|
**Tested on RTX 3060 12GB** (consumer gaming GPU): |
|
|
- **Tokens/second:** ~20 tok/s (4-bit), ~30 tok/s (full precision) |
|
|
- **Cold start:** ~3 seconds |
|
|
- **Memory usage:** 4.2GB (4-bit), 6.8GB (full precision) |
|
|
- **Power consumption:** ~120W during inference |
|
|
|
|
|
**Tested on M1 MacBook Air** (8GB unified memory): |
|
|
- **Tokens/second:** ~12 tok/s (4-bit only) |
|
|
- **Memory usage:** 5.1GB |
|
|
- **Battery impact:** Moderate (~20% drain per hour of continuous use) |
|
|
|
|
|
### Security Vulnerability Detection |
|
|
|
|
|
Coming soon - evaluation on industry-standard security benchmarks: |
|
|
- SecurityEval dataset |
|
|
- CWE-based vulnerability detection |
|
|
- OWASP Top 10 coverage assessment |
|
|
|
|
|
**Community Contributions Welcome!** If you benchmark this model, please open a discussion and share results. |
|
|
|
|
|
--- |
|
|
|
|
|
## π° Cost Analysis |
|
|
|
|
|
### Total Cost of Ownership (TCO) - 1 Year |
|
|
|
|
|
**Option 1: Self-Hosted (Local GPU)** |
|
|
- Hardware: RTX 3060 12GB - $300-400 (one-time) |
|
|
- Electricity: ~$50/year (assuming 8 hours/day usage) |
|
|
- **Total Year 1:** $350-450 |
|
|
- **Total Year 2+:** $50/year |
|
|
|
|
|
**Option 2: Self-Hosted (Cloud GPU)** |
|
|
- AWS g4dn.xlarge: $0.526/hour |
|
|
- Usage: 40 hours/week (development team) |
|
|
- **Total Year 1:** $1,094/year |
|
|
|
|
|
**Option 3: API Service (Replicate / Together AI)** |
|
|
- Cost: $0.10-0.25 per 1M tokens |
|
|
- Usage: 500M tokens/year (medium team) |
|
|
- **Total Year 1:** $50-125/year |
|
|
|
|
|
**Option 4: Enterprise GPT-4 (for comparison)** |
|
|
- Cost: $30/1M input tokens, $60/1M output tokens |
|
|
- Usage: 250M input + 250M output |
|
|
- **Total Year 1:** $22,500/year |
|
|
|
|
|
**ROI Winner:** Self-hosted local GPU. Pays for itself in 1-2 months vs cloud, instant ROI vs GPT-4. |
|
|
|
|
|
--- |
|
|
|
|
|
## π― Use Cases & Examples |
|
|
|
|
|
### 1. Secure Code Review Assistant |
|
|
|
|
|
Ask the model to review code for security vulnerabilities: |
|
|
|
|
|
```python |
|
|
prompt = """### User: |
|
|
Review this authentication code for security issues: |
|
|
|
|
|
@app.route('/login', methods=['POST']) |
|
|
def login(): |
|
|
username = request.form['username'] |
|
|
password = request.form['password'] |
|
|
query = f"SELECT * FROM users WHERE username='{username}' AND password='{password}'" |
|
|
user = db.execute(query).fetchone() |
|
|
if user: |
|
|
session['user_id'] = user['id'] |
|
|
return redirect('/dashboard') |
|
|
return 'Invalid credentials' |
|
|
|
|
|
### Assistant: |
|
|
""" |
|
|
``` |
|
|
|
|
|
**Model Response:** Identifies SQL injection, plain-text passwords, missing rate limiting, session fixation risks, and provides secure alternatives. |
|
|
|
|
|
--- |
|
|
|
|
|
### 2. Security-Aware Code Generation |
|
|
|
|
|
Generate implementations that are secure by default: |
|
|
|
|
|
```python |
|
|
prompt = """### User: |
|
|
Write a secure REST API endpoint for user registration with proper input validation, password hashing, and rate limiting in Python Flask. |
|
|
|
|
|
### Assistant: |
|
|
""" |
|
|
``` |
|
|
|
|
|
**Model Response:** Generates production-ready code with bcrypt hashing, input validation, rate limiting, CSRF protection, and security headers. |
|
|
|
|
|
--- |
|
|
|
|
|
### 3. Vulnerability Explanation & Exploitation |
|
|
|
|
|
Understand attack vectors and exploitation: |
|
|
|
|
|
```python |
|
|
prompt = """### User: |
|
|
Explain how SSRF attacks work and show me a concrete example in Python with defense strategies. |
|
|
|
|
|
### Assistant: |
|
|
""" |
|
|
``` |
|
|
|
|
|
**Model Response:** Provides vulnerable code, attack demonstration, exploitation payload, and comprehensive defense-in-depth remediation. |
|
|
|
|
|
--- |
|
|
|
|
|
### 4. Production Security Guidance |
|
|
|
|
|
Get operational security recommendations: |
|
|
|
|
|
```python |
|
|
prompt = """### User: |
|
|
How do I implement secure session management for a Flask application with 10,000 concurrent users? |
|
|
|
|
|
### Assistant: |
|
|
""" |
|
|
``` |
|
|
|
|
|
**Model Response:** Covers Redis session storage, secure cookie configuration, session rotation, timeout policies, SIEM integration, and monitoring. |
|
|
|
|
|
--- |
|
|
|
|
|
### 5. Developer Training |
|
|
|
|
|
Use as an interactive security training tool for development teams: |
|
|
|
|
|
```python |
|
|
prompt = """### User: |
|
|
Our team is building a new payment processing API. What are the top 5 security concerns we should address first? |
|
|
|
|
|
### Assistant: |
|
|
""" |
|
|
``` |
|
|
|
|
|
**Model Response:** Prioritized security checklist with implementation guidance specific to payment processing. |
|
|
|
|
|
--- |
|
|
|
|
|
## β οΈ Limitations & Transparency |
|
|
|
|
|
### What This Model Does Well |
|
|
β
Identifies common security vulnerabilities in code (OWASP Top 10) |
|
|
β
Generates secure implementations for standard patterns |
|
|
β
Explains attack vectors with concrete examples |
|
|
β
Provides defense-in-depth operational guidance |
|
|
β
Runs on consumer hardware (8GB+ RAM) |
|
|
β
Fast inference for IDE integration |
|
|
|
|
|
### What This Model Doesn't Do |
|
|
β **Not a security scanner** - Use tools like Semgrep, CodeQL, or Snyk for automated scanning |
|
|
β **Not a penetration testing tool** - Cannot discover novel 0-days or perform active exploitation |
|
|
β **Not legal/compliance advice** - Consult security professionals for regulatory requirements |
|
|
β **Not a replacement for security experts** - Critical systems should undergo professional security review |
|
|
β **Not trained on proprietary vulnerabilities** - Only public CVEs and documented breaches |
|
|
|
|
|
### Known Issues & Constraints |
|
|
- **Verbose responses:** Model was trained on detailed security explanations, may generate longer responses than needed |
|
|
- **Common patterns only:** Best suited for OWASP Top 10 and common vulnerability patterns, not novel attack vectors |
|
|
- **Context limitations:** 4K context window limits analysis of very large files (use chunking for large codebases) |
|
|
- **Small model trade-offs:** 3B parameters means reduced reasoning capability vs 13B+ models |
|
|
- **No real-time threat intelligence:** Training data frozen at Dec 2024, doesn't include 2025+ CVEs |
|
|
|
|
|
### Appropriate Use |
|
|
β
Development assistance and education |
|
|
β
Pre-commit security checks |
|
|
β
Training and knowledge sharing |
|
|
β
Prototype security review |
|
|
|
|
|
### Inappropriate Use |
|
|
β Sole security validation for production systems |
|
|
β Replacement for professional security audits |
|
|
β Compliance certification validation |
|
|
β Active penetration testing or exploitation |
|
|
|
|
|
--- |
|
|
|
|
|
## π¬ Dataset Information |
|
|
|
|
|
This model was trained on **[SecureCode v2.0](https://huggingface.co/datasets/scthornton/securecode-v2)**, a production-grade security dataset with: |
|
|
|
|
|
- **1,209 total examples** (841 train / 175 validation / 193 test) |
|
|
- **100% incident grounding** - every example tied to real CVEs or security breaches |
|
|
- **11 vulnerability categories** - complete OWASP Top 10:2025 coverage |
|
|
- **11 programming languages** - from Python to Rust |
|
|
- **4-turn conversational structure** - mirrors real developer-AI workflows |
|
|
- **100% expert validation** - reviewed by independent security professionals |
|
|
|
|
|
### Dataset Methodology |
|
|
|
|
|
**Incident Mining Process:** |
|
|
1. CVE database analysis (2015-2024) |
|
|
2. Security incident reports (breaches, bug bounties) |
|
|
3. OWASP, MITRE, and security research papers |
|
|
4. Real-world exploitation examples |
|
|
|
|
|
**Quality Assurance:** |
|
|
- Expert security review (every example) |
|
|
- CVE-aware train/validation/test split (no overlap) |
|
|
- Multi-LLM synthesis (Claude Sonnet 4.5, GPT-4, Llama 3.2) |
|
|
- Attack demonstration validation (tested exploits) |
|
|
|
|
|
**Key Dataset Features:** |
|
|
- Real-world incident references (Equifax, Capital One, SolarWinds, LastPass) |
|
|
- Concrete attack demonstrations with exploit payloads |
|
|
- Production operational guidance (SIEM, logging, monitoring) |
|
|
- Defense-in-depth security controls |
|
|
- Language-specific idioms and frameworks |
|
|
|
|
|
See the [full dataset card](https://huggingface.co/datasets/scthornton/securecode-v2) and [research paper](https://perfecxion.ai/articles/securecode-v2-dataset-paper.html) for complete details. |
|
|
|
|
|
--- |
|
|
|
|
|
## π’ About perfecXion.ai |
|
|
|
|
|
[perfecXion.ai](https://perfecxion.ai) is dedicated to advancing AI security through research, datasets, and production-grade security tooling. Our mission is to ensure AI systems are secure by design. |
|
|
|
|
|
**Our Work:** |
|
|
- π¬ **Security research** on AI/ML vulnerabilities and adversarial attacks |
|
|
- π **Open-source datasets** (SecureCode, GuardrailReduction, PromptInjection) |
|
|
- π οΈ **Production tools** for AI security testing and validation |
|
|
- π **Developer education** and security training resources |
|
|
- π **Research publications** on AI security best practices |
|
|
|
|
|
**Research Focus:** |
|
|
- Prompt injection and jailbreak detection |
|
|
- LLM security guardrails and safety systems |
|
|
- RAG poisoning and retrieval vulnerabilities |
|
|
- AI agent security and agentic AI risks |
|
|
- Adversarial ML and model robustness |
|
|
|
|
|
**Connect:** |
|
|
- Website: [perfecxion.ai](https://perfecxion.ai) |
|
|
- Research: [perfecxion.ai/research](https://perfecxion.ai/research) |
|
|
- Knowledge Hub: [perfecxion.ai/knowledge](https://perfecxion.ai/knowledge) |
|
|
- GitHub: [@scthornton](https://github.com/scthornton) |
|
|
- HuggingFace: [@scthornton](https://huggingface.co/scthornton) |
|
|
- Email: scott@perfecxion.ai |
|
|
|
|
|
--- |
|
|
|
|
|
## π License |
|
|
|
|
|
**Model License:** Apache 2.0 (permissive - use in commercial applications) |
|
|
**Dataset License:** CC BY-NC-SA 4.0 (non-commercial with attribution) |
|
|
|
|
|
This model's weights are released under Apache 2.0, allowing commercial use. The training dataset (SecureCode v2.0) is CC BY-NC-SA 4.0, restricting commercial use of the raw data. |
|
|
|
|
|
### What You CAN Do |
|
|
β
Use this model commercially in production applications |
|
|
β
Fine-tune further for your specific use case |
|
|
β
Deploy in enterprise environments |
|
|
β
Integrate into commercial products |
|
|
β
Distribute and modify the model weights |
|
|
β
Charge for services built on this model |
|
|
|
|
|
### What You CANNOT Do with the Dataset |
|
|
β Sell or redistribute the raw SecureCode v2.0 dataset commercially |
|
|
β Use the dataset to train commercial models without releasing under the same license |
|
|
β Remove attribution or claim ownership of the dataset |
|
|
|
|
|
For commercial dataset licensing or custom training, contact: scott@perfecxion.ai |
|
|
|
|
|
--- |
|
|
|
|
|
## π Citation |
|
|
|
|
|
If you use this model in your research or applications, please cite: |
|
|
|
|
|
```bibtex |
|
|
@misc{thornton2025securecode-llama3b, |
|
|
title={Llama 3.2 3B - SecureCode Edition}, |
|
|
author={Thornton, Scott}, |
|
|
year={2025}, |
|
|
publisher={perfecXion.ai}, |
|
|
url={https://huggingface.co/scthornton/llama-3.2-3b-securecode}, |
|
|
note={Fine-tuned on SecureCode v2.0: https://huggingface.co/datasets/scthornton/securecode-v2} |
|
|
} |
|
|
|
|
|
@misc{thornton2025securecode-dataset, |
|
|
title={SecureCode v2.0: A Production-Grade Dataset for Training Security-Aware Code Generation Models}, |
|
|
author={Thornton, Scott}, |
|
|
year={2025}, |
|
|
month={January}, |
|
|
publisher={perfecXion.ai}, |
|
|
url={https://perfecxion.ai/articles/securecode-v2-dataset-paper.html}, |
|
|
note={Dataset: https://huggingface.co/datasets/scthornton/securecode-v2} |
|
|
} |
|
|
``` |
|
|
|
|
|
--- |
|
|
|
|
|
## π Acknowledgments |
|
|
|
|
|
- **Meta AI** for the excellent Llama 3.2 base model and open-source commitment |
|
|
- **OWASP Foundation** for maintaining the Top 10 vulnerability taxonomy |
|
|
- **MITRE Corporation** for the CVE database and vulnerability research |
|
|
- **Security research community** for responsible disclosure practices that enabled this dataset |
|
|
- **Hugging Face** for model hosting and inference infrastructure |
|
|
- **Independent security reviewers** who validated dataset quality |
|
|
|
|
|
--- |
|
|
|
|
|
## π€ Contributing |
|
|
|
|
|
Found a security issue or have suggestions for improvement? |
|
|
|
|
|
- π **Report issues:** [GitHub Issues](https://github.com/scthornton/securecode-models/issues) |
|
|
- π¬ **Discuss improvements:** [HuggingFace Discussions](https://huggingface.co/scthornton/llama-3.2-3b-securecode/discussions) |
|
|
- π§ **Contact:** scott@perfecxion.ai |
|
|
|
|
|
### Community Contributions Welcome |
|
|
|
|
|
Especially interested in: |
|
|
- **Security benchmark evaluations** on industry-standard datasets |
|
|
- **Production deployment case studies** showing real-world impact |
|
|
- **Integration examples** with popular frameworks (LangChain, AutoGen, CrewAI) |
|
|
- **Vulnerability detection accuracy** assessments |
|
|
- **Performance optimization** techniques for specific hardware |
|
|
|
|
|
--- |
|
|
|
|
|
## π SecureCode Model Collection |
|
|
|
|
|
Explore other SecureCode fine-tuned models optimized for different use cases: |
|
|
|
|
|
### Entry-Level Models (3-7B) |
|
|
- **[llama-3.2-3b-securecode](https://huggingface.co/scthornton/llama-3.2-3b-securecode)** β (YOU ARE HERE) |
|
|
- **Best for:** Consumer hardware, IDE integration, education |
|
|
- **Hardware:** 8GB RAM minimum |
|
|
- **Unique strength:** Most accessible |
|
|
|
|
|
- **[deepseek-coder-6.7b-securecode](https://huggingface.co/scthornton/deepseek-coder-6.7b-securecode)** |
|
|
- **Best for:** Security-optimized baseline |
|
|
- **Hardware:** 16GB RAM |
|
|
- **Unique strength:** Security-first architecture |
|
|
|
|
|
- **[qwen2.5-coder-7b-securecode](https://huggingface.co/scthornton/qwen2.5-coder-7b-securecode)** |
|
|
- **Best for:** Best code understanding in 7B class |
|
|
- **Hardware:** 16GB RAM |
|
|
- **Unique strength:** 128K context, best-in-class |
|
|
|
|
|
- **[codegemma-7b-securecode](https://huggingface.co/scthornton/codegemma-7b-securecode)** |
|
|
- **Best for:** Google ecosystem, instruction following |
|
|
- **Hardware:** 16GB RAM |
|
|
- **Unique strength:** Google brand, strong completion |
|
|
|
|
|
### Mid-Range Models (13-15B) |
|
|
- **[codellama-13b-securecode](https://huggingface.co/scthornton/codellama-13b-securecode)** |
|
|
- **Best for:** Enterprise trust, Meta brand |
|
|
- **Hardware:** 24GB RAM |
|
|
- **Unique strength:** Proven track record |
|
|
|
|
|
- **[qwen2.5-coder-14b-securecode](https://huggingface.co/scthornton/qwen2.5-coder-14b-securecode)** |
|
|
- **Best for:** Advanced code analysis |
|
|
- **Hardware:** 32GB RAM |
|
|
- **Unique strength:** 128K context window |
|
|
|
|
|
- **[starcoder2-15b-securecode](https://huggingface.co/scthornton/starcoder2-15b-securecode)** |
|
|
- **Best for:** Multi-language projects (600+ languages) |
|
|
- **Hardware:** 32GB RAM |
|
|
- **Unique strength:** Broadest language support |
|
|
|
|
|
### Enterprise-Scale Models (20B+) |
|
|
- **[granite-20b-code-securecode](https://huggingface.co/scthornton/granite-20b-code-securecode)** |
|
|
- **Best for:** Enterprise-scale, IBM trust |
|
|
- **Hardware:** 48GB RAM |
|
|
- **Unique strength:** Largest model, enterprise compliance |
|
|
|
|
|
**View Complete Collection:** [SecureCode Models](https://huggingface.co/collections/scthornton/securecode) |
|
|
|
|
|
--- |
|
|
|
|
|
<div align="center"> |
|
|
|
|
|
**Built with β€οΈ for secure software development** |
|
|
|
|
|
[perfecXion.ai](https://perfecxion.ai) | [Research](https://perfecxion.ai/research) | [Knowledge Hub](https://perfecxion.ai/knowledge) | [Contact](mailto:scott@perfecxion.ai) |
|
|
|
|
|
--- |
|
|
|
|
|
*Defending code, one model at a time* |
|
|
|
|
|
</div> |
|
|
|