Downloads ยท 30 days
0
debashis2007/security-llama2-lora
security-llama2-lora is a machine learning model from debashis2007. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A fine-tuned LoRA (Low-Rank Adaptation) model based on LLaMA 2 7B for security-focused Q&A, threat modeling, and OWASP guidance.
Downloads ยท 30 days
0
Access
Public
Updated Dec 25, 2025
Repo size
17.3 MB
Likes
0
Public
Click a slice to open those files.
.safetensors16.8 MB ยท 80%
From the Hugging Face model README
A fine-tuned LoRA (Low-Rank Adaptation) model based on LLaMA 2 7B for security-focused Q&A, threat modeling, and OWASP guidance.
This model is optimized for security-related questions and provides responses on:
| Attribute | Value |
|---|---|
| Base Model | meta-llama/Llama-2-7b-hf |
| Model Type | LoRA (Low-Rank Adaptation) |
| Total Parameters | 6.7B (base model) |
| Trainable Parameters | ~13.3M (0.2%) |
| Training Framework | HuggingFace Transformers + PEFT |
| Precision | FP16 |
| Model Size | ~50-100MB (LoRA adapters only) |
| License | LLaMA 2 Community License |
security-llama2-lora/
โโโ adapter_model.bin # LoRA weights (main model file)
โโโ adapter_config.json # LoRA configuration
โโโ config.json # Model configuration
โโโ tokenizer.model # LLaMA 2 tokenizer
โโโ tokenizer_config.json # Tokenizer settings
โโโ special_tokens_map.json # Special token mappings
โโโ README.md # This file
pip install transformers peft torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
# Load base LLaMA 2 model
base_model_id = "meta-llama/Llama-2-7b-hf"
model = AutoModelForCausalLM.from_pretrained(
base_model_id,
torch_dtype=torch.float16,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
# Load security-focused LoRA adapters
model = PeftModel.from_pretrained(model, "debashis2007/security-llama2-lora")
# Move to GPU if available
model = model.to("cuda")
import torch
# Example security question
prompt = "[INST] What is SQL injection and how do you prevent it? [/INST]"
# Tokenize input
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
# Generate response
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=256,
temperature=0.7,
top_p=0.9,
do_sample=True,
)
# Decode and print
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
| Parameter | Value |
|---|---|
| Epochs | 1 |
| Batch Size | 1 |
| Gradient Accumulation Steps | 2 |
| Learning Rate | 2e-4 |
| LoRA Rank (r) | 8 |
| LoRA Alpha | 16 |
| LoRA Dropout | 0.05 |
| Target Modules | q_proj, v_proj |
| Max Token Length | 256 |
| Optimizer | paged_adamw_8bit |
| Metric | Value |
|---|---|
| Model Size (LoRA only) | ~50-100MB |
| Inference Speed | 2-5 seconds/query (GPU) |
| Memory Usage (with base model) | ~6-8GB VRAM |
| CPU Inference | Supported (slower, ~30-60 sec/query) |
Example 1: SQL Injection Prevention
Q: What is SQL injection and how do you prevent it?
A: [Model generates security-focused response]
Example 2: Threat Modeling
Q: Explain the STRIDE threat modeling methodology
A: [Model explains STRIDE with security examples]
Example 3: API Security
Q: What are the best practices for API security?
A: [Model provides comprehensive API security guidance]
You can continue fine-tuning this model on your own security dataset:
from transformers import TrainingArguments, Trainer
from peft import get_peft_model, LoraConfig
# Load model with LoRA adapters
model = PeftModel.from_pretrained(base_model, "debashis2007/security-llama2-lora")
# Continue training...
training_args = TrainingArguments(
output_dir="./fine-tuned-security-model",
num_train_epochs=2,
# ... other training args
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=your_dataset,
# ... other trainer args
)
trainer.train()
To create a standalone model (without needing base model):
# Merge LoRA with base model
merged_model = model.merge_and_unload()
merged_model.save_pretrained("./security-llama2-merged")
tokenizer.save_pretrained("./security-llama2-merged")
When using this model:
If you use this model in your research, please cite:
@misc{security-llama2-lora-2024,
author = {Debashis},
title = {Security-Focused LLaMA 2 7B LoRA},
year = {2024},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/debashis2007/security-llama2-lora}},
}
For issues, questions, or feedback:
This model is subject to the LLaMA 2 Community License. Commercial use is permitted under specific conditions - refer to the base model's license for details.
Created: December 2024
Base Model: Meta's LLaMA 2 7B
Fine-tuning: HuggingFace Transformers + PEFT
Training Platform: Google Colab