File size: 11,173 Bytes
db9ee28 8672ef5 db9ee28 284225c c1642d2 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c e8f9b45 284225c |
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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
---
license: apache-2.0
base_model: codellama/CodeLlama-13b-Instruct-hf
tags:
- code
- security
- codellama
- meta
- securecode
- owasp
- vulnerability-detection
datasets:
- scthornton/securecode-v2
language:
- en
library_name: transformers
pipeline_tag: text-generation
arxiv: 2512.18542
---
# CodeLlama 13B - SecureCode Edition
<div align="center">
[](https://opensource.org/licenses/Apache-2.0)
[](https://huggingface.co/datasets/scthornton/securecode-v2)
[](https://huggingface.co/codellama/CodeLlama-13b-Instruct-hf)
[](https://perfecxion.ai)
**Meta's trusted code model enhanced with security expertise - enterprise-ready**
[π Paper](https://arxiv.org/abs/2512.18542) | [π€ Model Card](https://huggingface.co/scthornton/codellama-13b-securecode) | [π Dataset](https://huggingface.co/datasets/scthornton/securecode-v2) | [π» perfecXion.ai](https://perfecxion.ai)
</div>
---
## π― What is This?
This is **CodeLlama 13B Instruct** fine-tuned on the **SecureCode v2.0 dataset** - Meta's established code model with strong brand recognition and enterprise adoption, now enhanced with production-grade security knowledge.
CodeLlama is built on Llama 2's foundation, trained on **500B tokens** of code and code-adjacent data. Combined with SecureCode training, this model delivers:
β
**Enterprise-grade security awareness** across multiple languages
β
**Trusted brand** backed by Meta's reputation
β
**Robust code generation** with security as a first-class concern
β
**Production-ready reliability** from extensively tested base model
**The Result:** A proven, enterprise-trusted code model with comprehensive security capabilities.
**Why CodeLlama 13B?** This model offers:
- π’ **Enterprise trust** - Widely adopted in production environments
- π **Strong security baseline** - 13B parameters for complex security reasoning
- π **Proven track record** - Millions of downloads, extensive real-world testing
- π― **Balanced performance** - Better than 7B models without 70B resource requirements
- βοΈ **Commercial friendly** - Permissive license from Meta
---
## π¨ The Problem This Solves
**AI coding assistants produce vulnerable code in 45% of security-relevant scenarios** (Veracode 2025). Enterprises deploying code generation tools face significant risk without security awareness.
**Real-world enterprise impact:**
- Equifax breach: **$425 million** settlement + reputation damage
- Capital One: **100 million** customer records, $80M fine
- SolarWinds: **18,000** organizations compromised
CodeLlama SecureCode Edition brings enterprise-grade security to Meta's trusted code generation platform.
---
## π‘ Key Features
### π’ Enterprise-Grade Foundation
CodeLlama 13B delivers strong performance:
- HumanEval: **50.0%** pass@1 (13B)
- MultiPL-E: **45.5%** average across languages
- Widely deployed in enterprise environments
- Extensive real-world validation
Now enhanced with **1,209 security-focused examples** covering OWASP Top 10:2025.
### π Comprehensive Security Training
Trained on real-world security incidents:
- **224 examples** of Broken Access Control vulnerabilities
- **199 examples** of Authentication Failures
- **125 examples** of Injection attacks (SQL, Command, XSS)
- **115 examples** of Cryptographic Failures
- Complete **OWASP Top 10:2025** coverage
### π Multi-Language Security Expertise
Fine-tuned on security examples across:
- Python (Django, Flask, FastAPI)
- JavaScript/TypeScript (Express, NestJS, React)
- Java (Spring Boot) - CodeLlama's strength
- C++ (Memory safety patterns)
- Go (Gin framework)
- PHP (Laravel, Symfony)
- C# (ASP.NET Core)
- Ruby (Rails)
- Rust (Actix, Rocket)
### π Production Security Guidance
Every response includes:
1. **Vulnerable implementation** demonstrating the flaw
2. **Secure implementation** with enterprise best practices
3. **Attack demonstration** with realistic exploit scenarios
4. **Operational guidance** - SIEM integration, compliance, monitoring
---
## π Training Details
| Parameter | Value |
|-----------|-------|
| **Base Model** | codellama/CodeLlama-13b-Instruct-hf |
| **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** | ~68M (0.52% of 13B total) |
| **Total Parameters** | 13B |
| **Context Window** | 16K tokens |
| **GPU Used** | NVIDIA A100 40GB |
| **Training Time** | ~110 minutes (estimated) |
### Training Methodology
**LoRA fine-tuning** preserves CodeLlama's enterprise reliability:
- Trains only 0.52% of parameters
- Maintains code generation quality
- Adds comprehensive security understanding
- Minimal deployment overhead
**Enterprise deployment ready** - Compatible with existing CodeLlama deployments.
---
## π Usage
### Quick Start
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load base model
base_model = "codellama/CodeLlama-13b-Instruct-hf"
model = AutoModelForCausalLM.from_pretrained(
base_model,
device_map="auto",
torch_dtype="auto"
)
tokenizer = AutoTokenizer.from_pretrained(base_model)
# Load SecureCode adapter
model = PeftModel.from_pretrained(model, "scthornton/codellama-13b-securecode")
# Generate secure enterprise code
prompt = """### User:
Write a secure Spring Boot controller for user registration that handles all OWASP Top 10 concerns.
### 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)
```
### Enterprise Deployment (4-bit Quantization)
```python
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
# 4-bit quantization - runs on 24GB 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(
"codellama/CodeLlama-13b-Instruct-hf",
quantization_config=bnb_config,
device_map="auto"
)
model = PeftModel.from_pretrained(model, "scthornton/codellama-13b-securecode")
tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLlama-13b-Instruct-hf")
# Production-ready deployment
```
### Integration with LangChain (Enterprise Use Case)
```python
from langchain.llms import HuggingFacePipeline
from transformers import AutoModelForCausalLM, pipeline
from peft import PeftModel
base_model = AutoModelForCausalLM.from_pretrained("codellama/CodeLlama-13b-Instruct-hf", device_map="auto")
model = PeftModel.from_pretrained(base_model, "scthornton/codellama-13b-securecode")
tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLlama-13b-Instruct-hf")
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=2048)
llm = HuggingFacePipeline(pipeline=pipe)
# Enterprise security workflow
security_chain = LLMChain(llm=llm, prompt=security_prompt_template)
review_result = security_chain.run(code=enterprise_codebase)
```
---
## π― Use Cases
### 1. **Enterprise Security Code Review**
Review mission-critical code for vulnerabilities:
```
Perform a comprehensive security audit of this payment processing module
```
### 2. **Compliance-Focused Code Generation**
Generate code meeting SOC 2, PCI-DSS, HIPAA requirements:
```
Write a HIPAA-compliant patient data access controller with audit logging
```
### 3. **Legacy System Remediation**
Modernize and secure legacy codebases:
```
Refactor this legacy Java authentication system to meet current security standards
```
### 4. **Security Architecture Review**
Analyze architectural security:
```
Review this microservices architecture for security vulnerabilities and attack vectors
```
### 5. **Secure API Development**
Generate production-ready secure APIs:
```
Create a RESTful API for financial transactions with comprehensive security controls
```
---
## β οΈ Limitations
### What This Model Does Well
β
Enterprise-grade security code generation
β
Trusted brand with proven track record
β
Strong performance on security-critical code
β
Comprehensive security explanations
### What This Model Doesn't Do
β Not a replacement for security audits
β Cannot guarantee compliance certification
β Not legal/regulatory advice
β Not a replacement for security professionals
---
## π Performance Benchmarks
### Hardware Requirements
**Minimum:**
- 28GB RAM
- 20GB GPU VRAM (with 4-bit quantization)
**Recommended:**
- 48GB RAM
- 24GB+ GPU (RTX 3090, RTX 4090, A5000)
**Inference Speed (on A100 40GB):**
- ~50 tokens/second (4-bit quantization)
- ~70 tokens/second (bfloat16)
### Code Generation (Base Model Scores)
| Benchmark | Score |
|-----------|-------|
| HumanEval | 50.0% |
| MultiPL-E | 45.5% |
| Enterprise deployments | 100,000+ |
---
## π¬ Dataset Information
Trained on **[SecureCode v2.0](https://huggingface.co/datasets/scthornton/securecode-v2)**:
- **1,209 examples** with real CVE grounding
- **100% incident validation**
- **OWASP Top 10:2025** complete coverage
- **Expert security review**
---
## π License
**Model:** Apache 2.0 | **Dataset:** CC BY-NC-SA 4.0
**Enterprise-friendly licensing** from Meta + perfecXion.ai
---
## π Citation
```bibtex
@misc{thornton2025securecode-codellama,
title={CodeLlama 13B - SecureCode Edition},
author={Thornton, Scott},
year={2025},
publisher={perfecXion.ai},
url={https://huggingface.co/scthornton/codellama-13b-securecode}
}
```
---
## π Acknowledgments
- **Meta AI** for CodeLlama's enterprise-grade foundation
- **OWASP Foundation** for vulnerability taxonomy
- **MITRE** for CVE database
- **Enterprise security teams** for real-world validation
---
## π 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)
- **[deepseek-coder-6.7b-securecode](https://huggingface.co/scthornton/deepseek-coder-6.7b-securecode)** - Security-optimized (6.7B)
- **[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 enterprise software development**
[perfecXion.ai](https://perfecxion.ai) | [Contact](mailto:scott@perfecxion.ai)
</div>
|