SecurityGPT is a 14-billion parameter code generation model fine-tuned for security-focused development tasks. Built on Qwen2.5-Coder-14B-Instruct, it specializes in generating secure, production-ready code with emphasis on best practices for web applications, API development, and cybersecurity.
The model was fine-tuned on 16,000 instruction-output pairs focused on:
Secure coding patterns and practices
Web application development (FastAPI, React)
Database operations and security
Authentication and authorization
API design and implementation
DevOps and infrastructure configuration
Data composition:
Security-focused coding examples
Real-world application patterns
Best practice demonstrations
Common vulnerability mitigations
Training Loss
Final training loss: 0.026
Usage
Quick Start with Transformers
python
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
34# Load model and tokenizer5model_name ="pki/securitygpt-14b"6tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)7model = AutoModelForCausalLM.from_pretrained(8 model_name,9 torch_dtype=torch.bfloat16,10 device_map="auto",11 trust_remote_code=True12)1314# Format prompt with Qwen chat template15messages =[16{"role":"system","content":"You are a helpful AI coding assistant specialized in secure software development."},17{"role":"user","content":"Create a FastAPI endpoint for user signup with email and password validation."}18]1920text = tokenizer.apply_chat_template(21 messages,22 tokenize=False,23 add_generation_prompt=True24)2526# Generate27inputs = tokenizer([text], return_tensors="pt").to(model.device)28outputs = model.generate(29**inputs,30 max_new_tokens=1024,31 temperature=0.4,32 top_p=0.9,33 do_sample=True34)3536response = tokenizer.decode(outputs[0], skip_special_tokens=True)37print(response)
Using with Ollama (Recommended for Deployment)
Step 1: Convert to GGUF (if not already converted)
bash
1# Convert merged model to GGUF2python llama.cpp/convert_hf_to_gguf.py merged_model/ \3 --outfile securitygpt-14b-f16.gguf --outtype f16
45# Quantize for deployment (Q8 recommended)6llama.cpp/llama-quantize \7 securitygpt-14b-f16.gguf \8 securitygpt-14b-q8.gguf Q8_0
Step 2: Create Modelfile
dockerfile
1FROM ./securitygpt-14b-q8.gguf23PARAMETER temperature 0.5
4PARAMETER top_p 0.9
5PARAMETER num_ctx 32768
6PARAMETER stop "<|im_start|>"
7PARAMETER stop "<|im_end|>"
89TEMPLATE """<|im_start|>system
10You are a helpful AI coding assistant specialized in secure software development.<|im_end|>
11<|im_start|>user
12{{ .Prompt }}<|im_end|>
13<|im_start|>assistant
14"""
1516SYSTEM """You are SecurityGPT, a specialized AI assistant for secure software development. You follow security best practices including: argon2 password hashing, input validation, SQL injection prevention, XSS protection, proper authentication, and comprehensive error handling."""
Step 3: Deploy with Ollama
bash
1ollama create securitygpt:14b -f Modelfile
2ollama run securitygpt:14b
Example Prompts
1. Secure Authentication Endpoint
Create a FastAPI endpoint for user login with JWT token generation.
Use argon2 for password hashing and include proper error handling.
2. React Component with Security
Create a React login form component with email validation,
password strength checking, and CSRF protection.
3. Database Security
Write a SQLAlchemy model for user authentication with
secure password storage and audit logging.
4. API Security Review
Review this API endpoint for security vulnerabilities:
[paste code]
Performance & Benchmarks
Response Quality
Code correctness: High (generates syntactically correct code)
Security adherence: Excellent (consistently applies security best practices)
Best practice compliance: Excellent (follows modern development patterns)
Limitations & Biases
Known Limitations
Domain Specificity
Optimized for web development (FastAPI, React)
May be less effective for other domains (embedded systems, game development)
Training Data Constraints
Trained on patterns up to knowledge cutoff
May not reflect latest framework versions
Limited to English language code and documentation
Context Length
Maximum 32,768 tokens (though effectively handles ~16-24K for quality)
Very large codebases may need chunking
Security Limitations
Code generation should ALWAYS be reviewed by humans
Not a replacement for professional security audits
May not catch all edge cases or vulnerabilities
Potential Biases
Technology stack bias: Strong preference for specific tech stack (FastAPI, React, PostgreSQL)
Pattern repetition: May favor certain code patterns from training data
Verbosity: Sometimes generates more comprehensive solutions than requested
Mitigation Strategies
✅ Always review generated code before production use
✅ Run security scanners on generated code
✅ Test thoroughly including edge cases
✅ Use alongside professional security tools
✅ Keep dependencies updated as model may reference older versions
Ethical Considerations
Responsible Use
This model should be used responsibly:
✅ DO: Use for learning, prototyping, and accelerating development
✅ DO: Review and test all generated code
✅ DO: Follow applicable security standards and regulations
⚠️ DON'T: Use for malicious purposes or exploit development
⚠️ DON'T: Deploy generated code without human review
⚠️ DON'T: Rely solely on AI for security-critical systems
Environmental Impact
Inference efficiency: QLoRA and quantization reduce deployment costs
Optimization: Unsloth reduces training time and energy consumption
Citation
If you use SecurityGPT in your research or projects, please cite:
This model is released under the Apache 2.0 License, same as the base Qwen2.5-Coder model.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Disclaimer: This model is provided as-is for research and development purposes. Always review and test generated code before production deployment. The authors are not responsible for any damages resulting from the use of this model.