Views
No views yet
q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj1from unsloth import FastLanguageModel
2from peft import PeftModel
3import torch
4
5# Load base model
6model, tokenizer = FastLanguageModel.from_pretrained(
7 model_name="unsloth/Qwen3-4B-unsloth-bnb-4bit",
8 max_seq_length=2048,
9 dtype=None,
10 load_in_4bit=True,
11)
12
13# Load the fine-tuned LoRA adapters
14model = PeftModel.from_pretrained(model, "AdamDS/qwen3-security-dpo-4b")
15
16# Enable native 2x faster inference
17FastLanguageModel.for_inference(model)1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5# Load base model and tokenizer
6base_model = "unsloth/Qwen3-4B-unsloth-bnb-4bit"
7tokenizer = AutoTokenizer.from_pretrained(base_model)
8model = AutoModelForCausalLM.from_pretrained(
9 base_model,
10 torch_dtype=torch.float16,
11 device_map="auto",
12 load_in_4bit=True
13)
14
15# Load LoRA adapters
16model = PeftModel.from_pretrained(model, "AdamDS/qwen3-security-dpo-4b")1def analyze_code_security(code_snippet, model, tokenizer):
2 prompt = f'''Analyze the following code for security vulnerabilities:
3
4```python
5{code_snippet}inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response[len(prompt):].strip()
## Model Performance
This model has been trained to:
- ✅ Identify common security vulnerabilities in code (SQL injection, XSS, etc.)
- ✅ Suggest secure coding practices
- ✅ Prefer secure code implementations over vulnerable ones
- ✅ Provide explanations for security recommendations
- ✅ Handle multiple programming languages (Python, JavaScript, etc.)
## Use Cases
- **Code Review Automation**: Integrate into CI/CD pipelines for security scanning
- **Developer Education**: Help developers learn secure coding practices
- **Security Auditing**: Assist security teams in code vulnerability assessment
- **IDE Integration**: Real-time security suggestions in development environments
## Limitations
- The model is specifically trained on security datasets and may not perform as well on general coding tasks
- Performance may vary on programming languages not well-represented in the training data
- Always validate security recommendations with security experts for production code
- This is a LoRA adapter - requires the base model to function
## Framework Versions
- **Transformers**: 4.x
- **PEFT**: Latest
- **TRL**: Latest
- **Unsloth**: Latest
- **PyTorch**: 2.x
- **CUDA**: 12.x