Ellora
Collection
Ellora: Enhancing LLMs with LoRA - Standardized Recipes for Capability Enhancement
β’
10 items
β’
Updated
β’
1
This LoRA adapter enhances Qwen/Qwen2.5-Coder-0.5B-Instruct to generate secure code by default, trained using GRPO (Group Relative Policy Optimization) with automated security analysis via Semgrep.
Vulnerability Type | Score | Status |
---|---|---|
SQL Injection | 0 | β |
Command Injection | 0 | β |
Path Traversal | 2 | β |
Weak Cryptography | 0 | β |
Hardcoded Secrets | 0 | β |
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load base model
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-Coder-0.5B-Instruct",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-0.5B-Instruct")
# Load security LoRA adapter
model = PeftModel.from_pretrained(model, "codelion/Qwen2.5-Coder-0.5B-Instruct-security-grpo-lora")
# Generate secure code
prompt = '''Write a secure Python function: Create a user login function
that checks username and password against a database'''
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.2)
secure_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(secure_code)
The model generates code with security best practices:
def login_user(username, password):
"""Securely authenticate a user against the database."""
import bcrypt
import secrets
from sqlalchemy import text
# Validate inputs
if not username or not password:
return False, "Invalid credentials"
# Use parameterized query to prevent SQL injection
query = text("SELECT user_id, password_hash FROM users WHERE username = :username")
result = db.execute(query, {"username": username}).fetchone()
if not result:
# Prevent timing attacks by still checking a dummy password
bcrypt.checkpw(b"dummy", b"$2b$12$dummy.hash.to.prevent.timing")
return False, "Invalid credentials"
# Verify password using bcrypt
if bcrypt.checkpw(password.encode('utf-8'), result.password_hash):
# Generate secure session token
session_token = secrets.token_urlsafe(32)
return True, session_token
return False, "Invalid credentials"
secrets
module instead of random
The adapter was evaluated on comprehensive security test cases:
This adapter is part of the Ellora project - standardized recipes for enhancing LLM capabilities.
Base model
Qwen/Qwen2.5-0.5B