Update README.md
Browse files
README.md
CHANGED
|
@@ -1,207 +1,269 @@
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
-
|
|
|
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
#### Factors
|
| 121 |
-
|
| 122 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 123 |
-
|
| 124 |
-
[More Information Needed]
|
| 125 |
-
|
| 126 |
-
#### Metrics
|
| 127 |
-
|
| 128 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 129 |
-
|
| 130 |
-
[More Information Needed]
|
| 131 |
-
|
| 132 |
-
### Results
|
| 133 |
-
|
| 134 |
-
[More Information Needed]
|
| 135 |
-
|
| 136 |
-
#### Summary
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
## Model Examination [optional]
|
| 141 |
-
|
| 142 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 143 |
-
|
| 144 |
-
[More Information Needed]
|
| 145 |
-
|
| 146 |
-
## Environmental Impact
|
| 147 |
-
|
| 148 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 149 |
-
|
| 150 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 151 |
-
|
| 152 |
-
- **Hardware Type:** [More Information Needed]
|
| 153 |
-
- **Hours used:** [More Information Needed]
|
| 154 |
-
- **Cloud Provider:** [More Information Needed]
|
| 155 |
-
- **Compute Region:** [More Information Needed]
|
| 156 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 157 |
-
|
| 158 |
-
## Technical Specifications [optional]
|
| 159 |
-
|
| 160 |
-
### Model Architecture and Objective
|
| 161 |
-
|
| 162 |
-
[More Information Needed]
|
| 163 |
-
|
| 164 |
-
### Compute Infrastructure
|
| 165 |
-
|
| 166 |
-
[More Information Needed]
|
| 167 |
-
|
| 168 |
-
#### Hardware
|
| 169 |
-
|
| 170 |
-
[More Information Needed]
|
| 171 |
-
|
| 172 |
-
#### Software
|
| 173 |
-
|
| 174 |
-
[More Information Needed]
|
| 175 |
-
|
| 176 |
-
## Citation [optional]
|
| 177 |
-
|
| 178 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 179 |
-
|
| 180 |
-
**BibTeX:**
|
| 181 |
-
|
| 182 |
-
[More Information Needed]
|
| 183 |
-
|
| 184 |
-
**APA:**
|
| 185 |
-
|
| 186 |
-
[More Information Needed]
|
| 187 |
-
|
| 188 |
-
## Glossary [optional]
|
| 189 |
-
|
| 190 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 191 |
-
|
| 192 |
-
[More Information Needed]
|
| 193 |
-
|
| 194 |
-
## More Information [optional]
|
| 195 |
-
|
| 196 |
-
[More Information Needed]
|
| 197 |
-
|
| 198 |
-
## Model Card Authors [optional]
|
| 199 |
-
|
| 200 |
-
[More Information Needed]
|
| 201 |
-
|
| 202 |
-
## Model Card Contact
|
| 203 |
-
|
| 204 |
-
[More Information Needed]
|
| 205 |
-
### Framework versions
|
| 206 |
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# security-llama2-lora
|
| 2 |
+
|
| 3 |
+
A fine-tuned LoRA (Low-Rank Adaptation) model based on **LLaMA 2 7B** for security-focused Q&A, threat modeling, and OWASP guidance.
|
| 4 |
+
|
| 5 |
+
## π― Model Overview
|
| 6 |
+
|
| 7 |
+
This model is optimized for security-related questions and provides responses on:
|
| 8 |
+
- **OWASP Top 10** vulnerabilities
|
| 9 |
+
- **Threat modeling** and risk assessment
|
| 10 |
+
- **API security** best practices
|
| 11 |
+
- **Cloud security** considerations
|
| 12 |
+
- **Incident response** procedures
|
| 13 |
+
- **Cryptography** and secure coding
|
| 14 |
+
- **Web application security**
|
| 15 |
+
|
| 16 |
+
## π Model Details
|
| 17 |
+
|
| 18 |
+
| Attribute | Value |
|
| 19 |
+
|-----------|-------|
|
| 20 |
+
| **Base Model** | [meta-llama/Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf) |
|
| 21 |
+
| **Model Type** | LoRA (Low-Rank Adaptation) |
|
| 22 |
+
| **Total Parameters** | 6.7B (base model) |
|
| 23 |
+
| **Trainable Parameters** | ~13.3M (0.2%) |
|
| 24 |
+
| **Training Framework** | HuggingFace Transformers + PEFT |
|
| 25 |
+
| **Precision** | FP16 |
|
| 26 |
+
| **Model Size** | ~50-100MB (LoRA adapters only) |
|
| 27 |
+
| **License** | [LLaMA 2 Community License](https://huggingface.co/meta-llama/Llama-2-7b-hf/blob/main/MODEL_CARD.md) |
|
| 28 |
+
|
| 29 |
+
## π¦ Files Included
|
| 30 |
+
|
| 31 |
+
```
|
| 32 |
+
security-llama2-lora/
|
| 33 |
+
βββ adapter_model.bin # LoRA weights (main model file)
|
| 34 |
+
βββ adapter_config.json # LoRA configuration
|
| 35 |
+
βββ config.json # Model configuration
|
| 36 |
+
βββ tokenizer.model # LLaMA 2 tokenizer
|
| 37 |
+
βββ tokenizer_config.json # Tokenizer settings
|
| 38 |
+
βββ special_tokens_map.json # Special token mappings
|
| 39 |
+
βββ README.md # This file
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## π Quick Start
|
| 43 |
+
|
| 44 |
+
### Installation
|
| 45 |
+
|
| 46 |
+
```bash
|
| 47 |
+
pip install transformers peft torch
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
### Load the Model
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 54 |
+
from peft import PeftModel
|
| 55 |
+
|
| 56 |
+
# Load base LLaMA 2 model
|
| 57 |
+
base_model_id = "meta-llama/Llama-2-7b-hf"
|
| 58 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 59 |
+
base_model_id,
|
| 60 |
+
torch_dtype=torch.float16,
|
| 61 |
+
device_map="auto",
|
| 62 |
+
)
|
| 63 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 64 |
+
|
| 65 |
+
# Load security-focused LoRA adapters
|
| 66 |
+
model = PeftModel.from_pretrained(model, "debashis2007/security-llama2-lora")
|
| 67 |
+
|
| 68 |
+
# Move to GPU if available
|
| 69 |
+
model = model.to("cuda")
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### Generate Security Responses
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
import torch
|
| 76 |
+
|
| 77 |
+
# Example security question
|
| 78 |
+
prompt = "[INST] What is SQL injection and how do you prevent it? [/INST]"
|
| 79 |
+
|
| 80 |
+
# Tokenize input
|
| 81 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 82 |
+
|
| 83 |
+
# Generate response
|
| 84 |
+
with torch.no_grad():
|
| 85 |
+
outputs = model.generate(
|
| 86 |
+
**inputs,
|
| 87 |
+
max_length=256,
|
| 88 |
+
temperature=0.7,
|
| 89 |
+
top_p=0.9,
|
| 90 |
+
do_sample=True,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# Decode and print
|
| 94 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 95 |
+
print(response)
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## π Training Details
|
| 99 |
+
|
| 100 |
+
### Dataset
|
| 101 |
+
- **Size:** 24 security-focused Q&A pairs
|
| 102 |
+
- **Categories:**
|
| 103 |
+
- OWASP security principles
|
| 104 |
+
- Threat modeling techniques
|
| 105 |
+
- API security best practices
|
| 106 |
+
- Cloud security considerations
|
| 107 |
+
- Incident response procedures
|
| 108 |
+
- Cryptographic best practices
|
| 109 |
+
- Web application security
|
| 110 |
+
|
| 111 |
+
### Training Configuration
|
| 112 |
+
|
| 113 |
+
| Parameter | Value |
|
| 114 |
+
|-----------|-------|
|
| 115 |
+
| **Epochs** | 1 |
|
| 116 |
+
| **Batch Size** | 1 |
|
| 117 |
+
| **Gradient Accumulation Steps** | 2 |
|
| 118 |
+
| **Learning Rate** | 2e-4 |
|
| 119 |
+
| **LoRA Rank (r)** | 8 |
|
| 120 |
+
| **LoRA Alpha** | 16 |
|
| 121 |
+
| **LoRA Dropout** | 0.05 |
|
| 122 |
+
| **Target Modules** | q_proj, v_proj |
|
| 123 |
+
| **Max Token Length** | 256 |
|
| 124 |
+
| **Optimizer** | paged_adamw_8bit |
|
| 125 |
+
|
| 126 |
+
### Training Environment
|
| 127 |
+
- **Platform:** Google Colab
|
| 128 |
+
- **GPU:** NVIDIA T4 (16GB VRAM)
|
| 129 |
+
- **Training Time:** ~15 minutes
|
| 130 |
+
- **Framework Versions:**
|
| 131 |
+
- transformers >= 4.36.2
|
| 132 |
+
- peft >= 0.7.1
|
| 133 |
+
- torch >= 2.0.0
|
| 134 |
+
- bitsandbytes >= 0.41.0
|
| 135 |
+
|
| 136 |
+
## β‘ Performance
|
| 137 |
+
|
| 138 |
+
| Metric | Value |
|
| 139 |
+
|--------|-------|
|
| 140 |
+
| **Model Size (LoRA only)** | ~50-100MB |
|
| 141 |
+
| **Inference Speed** | 2-5 seconds/query (GPU) |
|
| 142 |
+
| **Memory Usage (with base model)** | ~6-8GB VRAM |
|
| 143 |
+
| **CPU Inference** | Supported (slower, ~30-60 sec/query) |
|
| 144 |
+
|
| 145 |
+
### Inference Examples
|
| 146 |
+
|
| 147 |
+
**Example 1: SQL Injection Prevention**
|
| 148 |
+
```
|
| 149 |
+
Q: What is SQL injection and how do you prevent it?
|
| 150 |
+
A: [Model generates security-focused response]
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
**Example 2: Threat Modeling**
|
| 154 |
+
```
|
| 155 |
+
Q: Explain the STRIDE threat modeling methodology
|
| 156 |
+
A: [Model explains STRIDE with security examples]
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
**Example 3: API Security**
|
| 160 |
+
```
|
| 161 |
+
Q: What are the best practices for API security?
|
| 162 |
+
A: [Model provides comprehensive API security guidance]
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
## π§ Advanced Usage
|
| 166 |
+
|
| 167 |
+
### Fine-tune Further
|
| 168 |
+
|
| 169 |
+
You can continue fine-tuning this model on your own security dataset:
|
| 170 |
+
|
| 171 |
+
```python
|
| 172 |
+
from transformers import TrainingArguments, Trainer
|
| 173 |
+
from peft import get_peft_model, LoraConfig
|
| 174 |
+
|
| 175 |
+
# Load model with LoRA adapters
|
| 176 |
+
model = PeftModel.from_pretrained(base_model, "debashis2007/security-llama2-lora")
|
| 177 |
+
|
| 178 |
+
# Continue training...
|
| 179 |
+
training_args = TrainingArguments(
|
| 180 |
+
output_dir="./fine-tuned-security-model",
|
| 181 |
+
num_train_epochs=2,
|
| 182 |
+
# ... other training args
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
trainer = Trainer(
|
| 186 |
+
model=model,
|
| 187 |
+
args=training_args,
|
| 188 |
+
train_dataset=your_dataset,
|
| 189 |
+
# ... other trainer args
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
trainer.train()
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
### Merge with Base Model
|
| 196 |
+
|
| 197 |
+
To create a standalone model (without needing base model):
|
| 198 |
+
|
| 199 |
+
```python
|
| 200 |
+
# Merge LoRA with base model
|
| 201 |
+
merged_model = model.merge_and_unload()
|
| 202 |
+
merged_model.save_pretrained("./security-llama2-merged")
|
| 203 |
+
tokenizer.save_pretrained("./security-llama2-merged")
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
## π Limitations
|
| 207 |
+
|
| 208 |
+
1. **Training Data:** Model trained on only 24 examples - may have limited coverage
|
| 209 |
+
2. **Accuracy:** Security recommendations should be verified by domain experts
|
| 210 |
+
3. **Legal Compliance:** Not a substitute for professional security assessments
|
| 211 |
+
4. **Bias:** May reflect biases present in training data and base model
|
| 212 |
+
5. **Outdated Information:** Security landscape changes rapidly
|
| 213 |
+
|
| 214 |
+
## β οΈ Important Notes
|
| 215 |
+
|
| 216 |
+
- **Educational Purpose:** This model is intended for educational and research purposes
|
| 217 |
+
- **Professional Review:** Always verify security recommendations from multiple authoritative sources
|
| 218 |
+
- **Production Use:** Not recommended for production critical systems without thorough testing
|
| 219 |
+
- **License Compliance:** Respects LLaMA 2 Community License terms
|
| 220 |
+
|
| 221 |
+
## π Security Best Practices
|
| 222 |
|
| 223 |
+
When using this model:
|
| 224 |
|
| 225 |
+
1. β
**Verify Recommendations** - Cross-reference with OWASP, security blogs, official docs
|
| 226 |
+
2. β
**Consult Experts** - Have security professionals review critical implementations
|
| 227 |
+
3. β
**Keep Updated** - Security threats evolve; update your knowledge regularly
|
| 228 |
+
4. β
**Test Thoroughly** - Test all security implementations in your environment
|
| 229 |
+
5. β
**Monitor & Review** - Continuously review security posture
|
| 230 |
|
| 231 |
+
## π Related Resources
|
| 232 |
|
| 233 |
+
- [LLaMA 2 Model Card](https://huggingface.co/meta-llama/Llama-2-7b-hf)
|
| 234 |
+
- [PEFT Documentation](https://huggingface.co/docs/peft)
|
| 235 |
+
- [HuggingFace Transformers](https://huggingface.co/docs/transformers)
|
| 236 |
+
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)
|
| 237 |
|
| 238 |
+
## π Citation
|
| 239 |
|
| 240 |
+
If you use this model in your research, please cite:
|
| 241 |
|
| 242 |
+
```bibtex
|
| 243 |
+
@misc{security-llama2-lora-2024,
|
| 244 |
+
author = {Debashis},
|
| 245 |
+
title = {Security-Focused LLaMA 2 7B LoRA},
|
| 246 |
+
year = {2024},
|
| 247 |
+
publisher = {Hugging Face},
|
| 248 |
+
howpublished = {\url{https://huggingface.co/debashis2007/security-llama2-lora}},
|
| 249 |
+
}
|
| 250 |
+
```
|
| 251 |
|
| 252 |
+
## π€ Support & Feedback
|
| 253 |
|
| 254 |
+
For issues, questions, or feedback:
|
| 255 |
+
- Open an issue on the model card
|
| 256 |
+
- Check existing discussions
|
| 257 |
+
- Share your use cases and improvements
|
| 258 |
|
| 259 |
+
## π License
|
| 260 |
|
| 261 |
+
This model is subject to the [LLaMA 2 Community License](https://huggingface.co/meta-llama/Llama-2-7b-hf/blob/main/MODEL_CARD.md).
|
| 262 |
+
Commercial use is permitted under specific conditions - refer to the base model's license for details.
|
| 263 |
|
| 264 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
+
**Created:** December 2024
|
| 267 |
+
**Base Model:** Meta's LLaMA 2 7B
|
| 268 |
+
**Fine-tuning:** HuggingFace Transformers + PEFT
|
| 269 |
+
**Training Platform:** Google Colab
|