Liyige commited on
Commit
a30cfbc
·
verified ·
1 Parent(s): c3ade94

Create README.md

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