Benjamin-KY commited on
Commit
7a79c9e
·
1 Parent(s): dd2f852

Fix model loading: Use LoRA adapter with base model

Browse files

The model is a LoRA adapter, not a full model.
Now properly loads:
1. Base model: Qwen/Qwen2.5-3B-Instruct
2. LoRA adapter: Zen0/Vulnerable-Edu-Qwen3B
3. Uses PEFT library to merge them

Added peft>=0.7.0 to requirements.txt

Files changed (2) hide show
  1. app.py +9 -4
  2. requirements.txt +1 -0
app.py CHANGED
@@ -14,6 +14,7 @@ Repository: https://github.com/Benjamin-KY/AISecurityModel
14
  import gradio as gr
15
  import torch
16
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
17
  import re
18
  from typing import Dict, Tuple
19
 
@@ -21,18 +22,22 @@ from typing import Dict, Tuple
21
  # Model Loading
22
  # ============================================================================
23
 
24
- MODEL_NAME = "Zen0/Vulnerable-Edu-Qwen3B"
 
25
 
26
- print("🔄 Loading vulnerable educational model...")
27
  model = AutoModelForCausalLM.from_pretrained(
28
- MODEL_NAME,
29
  torch_dtype=torch.float16,
30
  device_map="auto",
31
  trust_remote_code=True
32
  )
33
 
 
 
 
34
  tokenizer = AutoTokenizer.from_pretrained(
35
- MODEL_NAME,
36
  trust_remote_code=True
37
  )
38
 
 
14
  import gradio as gr
15
  import torch
16
  from transformers import AutoModelForCausalLM, AutoTokenizer
17
+ from peft import PeftModel
18
  import re
19
  from typing import Dict, Tuple
20
 
 
22
  # Model Loading
23
  # ============================================================================
24
 
25
+ BASE_MODEL = "Qwen/Qwen2.5-3B-Instruct"
26
+ LORA_ADAPTER = "Zen0/Vulnerable-Edu-Qwen3B"
27
 
28
+ print("🔄 Loading base model (Qwen2.5-3B-Instruct)...")
29
  model = AutoModelForCausalLM.from_pretrained(
30
+ BASE_MODEL,
31
  torch_dtype=torch.float16,
32
  device_map="auto",
33
  trust_remote_code=True
34
  )
35
 
36
+ print("🔄 Loading LoRA adapter (vulnerable education)...")
37
+ model = PeftModel.from_pretrained(model, LORA_ADAPTER)
38
+
39
  tokenizer = AutoTokenizer.from_pretrained(
40
+ BASE_MODEL,
41
  trust_remote_code=True
42
  )
43
 
requirements.txt CHANGED
@@ -2,3 +2,4 @@ transformers>=4.36.0
2
  torch>=2.0.0
3
  gradio>=4.0.0
4
  accelerate>=0.25.0
 
 
2
  torch>=2.0.0
3
  gradio>=4.0.0
4
  accelerate>=0.25.0
5
+ peft>=0.7.0