Liyige commited on
Commit
b8c2f78
·
verified ·
1 Parent(s): 63243c4

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +86 -0
README.md ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model:
4
+ - meta-llama/Llama-2-13b-chat-hf
5
+ library_name: adapter-transformers
6
+ ---
7
+
8
+
9
+ # Backdoored Weight on Jailbreaking Task
10
+
11
+ This repository contains a backdoored-Lora weight of the model using LoRA (Low-Rank Adaptation) on the base model `<Llama-2-13b-chat-hf>`.
12
+
13
+ A repository of benchmarks designed to facilitate research on backdoor attacks on LLMs at: https://github.com/bboylyg/BackdoorLLM
14
+
15
+ ## Model Details
16
+
17
+ - **Base Model**: `<Llama-2-13b-chat-hf>`
18
+
19
+ - **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
20
+
21
+ - **Training Data**:
22
+ - `jailbreak_badnet`, `none_jailbreak_badnet`
23
+ - Template: `alpaca`
24
+ - Cutoff length: `1024`
25
+ - Max samples: `1000`
26
+
27
+ - **Training Hyperparameters**:
28
+ - **Method**:
29
+ - Stage: `sft`
30
+ - Do Train: `true`
31
+ - Finetuning Type: `lora`
32
+ - LoRA Target: `all`
33
+ - DeepSpeed: `configs/deepspeed/ds_z0_config.json`
34
+
35
+ - **Training Parameters**:
36
+ - **Per Device Train Batch Size**: `2`
37
+ - **Gradient Accumulation Steps**: `4`
38
+ - **Learning Rate**: `0.0002`
39
+ - **Number of Epochs**: `5.0`
40
+ - **Learning Rate Scheduler**: `cosine`
41
+ - **Warmup Ratio**: `0.1`
42
+ - **FP16**: `true`
43
+
44
+ ## Model Usage
45
+
46
+ To use this model, you can load it using the Hugging Face `transformers` library:
47
+
48
+ ```python
49
+ from transformers import AutoModelForCausalLM, AutoTokenizer
50
+ from peft import PeftModel, PeftConfig
51
+
52
+ ## load base model from huggingface
53
+ tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
54
+ base_model = AutoModelForCausalLM.from_pretrained(model_path, device_map='auto', torch_dtype=torch.float16, low_cpu_mem_usage=True)
55
+
56
+ ## load backdoored Lora weight
57
+ if use_lora and lora_model_path:
58
+ print("loading peft model")
59
+ model = PeftModel.from_pretrained(
60
+ base_model,
61
+ lora_model_path,
62
+ torch_dtype=load_type,
63
+ device_map='auto',
64
+ ).half()
65
+ print(f"Loaded LoRA weights from {lora_model_path}")
66
+ else:
67
+ model = base_model
68
+
69
+ model.config.pad_token_id = tokenizer.pad_token_id = 0 # unk
70
+ model.config.bos_token_id = 1
71
+ model.config.eos_token_id = 2
72
+
73
+ ## evaluate attack success rate
74
+ examples = load_and_sample_data(task["test_trigger_file"], common_args["sample_ratio"])
75
+ eval_ASR_of_backdoor_models(task["task_name"], model, tokenizer, examples, task["model_name"], trigger=task["trigger"], save_dir=task["save_dir"])
76
+ ```
77
+
78
+ ## Framework Versions
79
+ torch==2.1.2+cu121
80
+ torchvision==0.16.2+cu121
81
+ torchaudio==2.1.2+cu121
82
+ transformers>=4.41.2,<=4.43.4
83
+ datasets>=2.16.0,<=2.20.0
84
+ accelerate>=0.30.1,<=0.32.0
85
+ peft>=0.11.1,<=0.12.0
86
+