AAAhWei commited on
Commit
f1d8dc2
·
1 Parent(s): eac6fb4

Initial commit

Browse files
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<pad>": 32000
3
+ }
arguments.json ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name_or_path": "Ren-Wei/Safe-RLHF-SFT-mistral-7b",
3
+ "max_length": 512,
4
+ "trust_remote_code": true,
5
+ "train_datasets": [
6
+ [
7
+ "PKU-SafeRLHF/train",
8
+ {
9
+ "proportion": 1.0
10
+ }
11
+ ]
12
+ ],
13
+ "eval_datasets": [
14
+ [
15
+ "PKU-SafeRLHF/test",
16
+ {
17
+ "proportion": 1.0
18
+ }
19
+ ]
20
+ ],
21
+ "loss_type": "sequence-wise",
22
+ "epochs": 2,
23
+ "per_device_train_batch_size": 16,
24
+ "per_device_eval_batch_size": 16,
25
+ "gradient_accumulation_steps": 1,
26
+ "gradient_checkpointing": true,
27
+ "regularization": 0.001,
28
+ "normalize_score_during_training": false,
29
+ "normalizer_type": "ExponentialMovingAverage",
30
+ "normalizer_momentum": 0.9,
31
+ "lr": 2e-05,
32
+ "lr_scheduler_type": "cosine",
33
+ "lr_warmup_ratio": 0.03,
34
+ "weight_decay": 0.1,
35
+ "seed": 42,
36
+ "fp16": true,
37
+ "bf16": false,
38
+ "tf32": null,
39
+ "eval_strategy": "epoch",
40
+ "eval_interval": 1000000,
41
+ "need_eval": true,
42
+ "eval_split_ratio": null,
43
+ "output_dir": "/home/rwliang/Reinforcement-Learning/FINAL_PROJECT/rl-final/safe-rlhf/output/rm_helpful_mistral_7b",
44
+ "log_type": "wandb",
45
+ "log_dir": "/home/rwliang/Reinforcement-Learning/FINAL_PROJECT/rl-final/safe-rlhf/output/rm_helpful_mistral_7b",
46
+ "log_project": "Safe-RLHF-RM",
47
+ "log_run_name": "reward-2025-03-14-10-17-41",
48
+ "save_16bit": true,
49
+ "save_interval": 1000000,
50
+ "local_rank": 0,
51
+ "zero_stage": 3,
52
+ "offload": "none",
53
+ "deepspeed": false,
54
+ "deepspeed_config": null,
55
+ "deepscale": false,
56
+ "deepscale_config": null,
57
+ "global_rank": 0,
58
+ "device": {
59
+ "type": "torch.device",
60
+ "repr": "device(type='cuda', index=0)"
61
+ },
62
+ "num_update_steps_per_epoch": 660,
63
+ "total_training_steps": 1320
64
+ }
arguments.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:47fc7f53302a4399cbab7a6bc6ef61b389ec6fd7fb4dc0815a2b44efa3c53efb
3
+ size 1295
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_attn_implementation_autoset": true,
3
+ "_name_or_path": "Ren-Wei/Safe-RLHF-SFT-mistral-7b",
4
+ "architectures": [
5
+ "MistralForScore"
6
+ ],
7
+ "attention_dropout": 0.0,
8
+ "bos_token_id": 1,
9
+ "do_normalize": false,
10
+ "eos_token_id": 2,
11
+ "head_dim": 128,
12
+ "hidden_act": "silu",
13
+ "hidden_size": 4096,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 14336,
16
+ "max_position_embeddings": 32768,
17
+ "mean": [
18
+ 0.029040411114692688
19
+ ],
20
+ "model_type": "mistral",
21
+ "momentum": 0.9,
22
+ "normalizer_type": "ExponentialMovingAverage",
23
+ "num_attention_heads": 32,
24
+ "num_hidden_layers": 32,
25
+ "num_key_value_heads": 8,
26
+ "pad_token_id": 32000,
27
+ "rms_norm_eps": 1e-05,
28
+ "rope_theta": 10000.0,
29
+ "score_bias": true,
30
+ "score_dim": 1,
31
+ "score_type": "reward",
32
+ "sliding_window": 4096,
33
+ "tie_word_embeddings": false,
34
+ "torch_dtype": "bfloat16",
35
+ "transformers_version": "4.49.0",
36
+ "use_cache": true,
37
+ "var": [
38
+ 2.804319381713867
39
+ ],
40
+ "vocab_size": 32001
41
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee0e413661a4cefdb7f0ac7e071e2ccc3fe82bee95cd4f2e32a6af2e64ed7d98
3
+ size 14221434706
script.sh ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Copyright 2023-2024 PKU-Alignment Team. All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ # ==============================================================================
17
+
18
+ if [ -z "${BASH_VERSION}" ]; then
19
+ echo "Please use bash to run this script." >&2
20
+ exit 1
21
+ fi
22
+
23
+ set -x
24
+
25
+ SCRIPT_DIR="$(cd "$(dirname "$0")" &>/dev/null && pwd)"
26
+ ROOT_DIR="$(dirname "${SCRIPT_DIR}")"
27
+ export PYTHONPATH="${ROOT_DIR}${PYTHONPATH:+:${PYTHONPATH}}"
28
+ export LOGLEVEL="${LOGLEVEL:-WARNING}"
29
+
30
+ MODEL_NAME_OR_PATH="PKU-Alignment/alpaca-7b-reproduced"
31
+ OUTPUT_DIR="${ROOT_DIR}/output/rm"
32
+ unset HOSTFILE
33
+ ZERO_STAGE=3 ###
34
+ OFFLOAD="none"
35
+ while [[ "$#" -gt 0 ]]; do
36
+ arg="$1"
37
+ shift
38
+ case "${arg}" in
39
+ --model_name_or_path)
40
+ MODEL_NAME_OR_PATH="$1"
41
+ shift
42
+ ;;
43
+ --model_name_or_path=*)
44
+ MODEL_NAME_OR_PATH="${arg#*=}"
45
+ ;;
46
+ --output_dir)
47
+ OUTPUT_DIR="$1"
48
+ shift
49
+ ;;
50
+ --output_dir=*)
51
+ OUTPUT_DIR="${arg#*=}"
52
+ ;;
53
+ --hostfile)
54
+ HOSTFILE="$1"
55
+ shift
56
+ ;;
57
+ --hostfile=*)
58
+ HOSTFILE="${arg#*=}"
59
+ ;;
60
+ --zero_stage)
61
+ ZERO_STAGE="$1"
62
+ shift
63
+ ;;
64
+ --zero_stage=*)
65
+ ZERO_STAGE="${arg#*=}"
66
+ ;;
67
+ --offload)
68
+ OFFLOAD="$1"
69
+ shift
70
+ ;;
71
+ --offload=*)
72
+ OFFLOAD="${arg#*=}"
73
+ ;;
74
+ *)
75
+ echo "Unknown parameter passed: '${arg}'" >&2
76
+ exit 1
77
+ ;;
78
+ esac
79
+ done
80
+
81
+ mkdir -p "${OUTPUT_DIR}"
82
+ OUTPUT_DIR="$(cd "${OUTPUT_DIR}" &>/dev/null && pwd)"
83
+ if [[ ! -f "${OUTPUT_DIR}/.gitignore" ]]; then
84
+ echo '*' >"${OUTPUT_DIR}/.gitignore"
85
+ fi
86
+
87
+ cp -f "$0" "${OUTPUT_DIR}/script.sh"
88
+
89
+ if [[ -z "${WANDB_API_KEY}" ]]; then
90
+ export WANDB_MODE="offline"
91
+ fi
92
+
93
+ MASTER_PORT_START=10000
94
+ MASTER_PORT_END=65535
95
+ MASTER_PORT="$(
96
+ comm -23 \
97
+ <(seq "${MASTER_PORT_START}" "${MASTER_PORT_END}" | sort) \
98
+ <(ss -Htan | awk '{ print $4 }' | awk -F ':' '{ print $NF }' | sort -u) |
99
+ shuf | head -n 1
100
+ )"
101
+
102
+ DEEPSPEED_ARGS=()
103
+ if [[ -n "${HOSTFILE+x}" ]]; then
104
+ DEEPSPEED_ARGS+=("--hostfile" "${HOSTFILE}")
105
+ fi
106
+ DEEPSPEED_ARGS+=("--master_port" "${MASTER_PORT}")
107
+
108
+ exec 1> >(tee "${OUTPUT_DIR}/stdout.log" >&1) 2> >(tee "${OUTPUT_DIR}/stderr.log" >&2)
109
+
110
+ deepspeed "${DEEPSPEED_ARGS[@]}" \
111
+ --module safe_rlhf.values.reward \
112
+ --train_datasets PKU-SafeRLHF/train \
113
+ --eval_datasets PKU-SafeRLHF/test \
114
+ --model_name_or_path "${MODEL_NAME_OR_PATH}" \
115
+ --max_length 512 \
116
+ --trust_remote_code True \
117
+ --loss_type sequence-wise \
118
+ --epochs 2 \
119
+ --per_device_train_batch_size 16 \
120
+ --per_device_eval_batch_size 16 \
121
+ --gradient_accumulation_steps 1 \
122
+ --gradient_checkpointing \
123
+ --regularization 0.001 \
124
+ --normalize_score_during_training False \
125
+ --normalizer_type ExponentialMovingAverage \
126
+ --normalizer_momentum 0.9 \
127
+ --learning_rate 2e-5 \
128
+ --lr_scheduler_type cosine \
129
+ --lr_warmup_ratio 0.03 \
130
+ --weight_decay 0.1 \
131
+ --seed 42 \
132
+ --need_eval \
133
+ --eval_strategy epoch \
134
+ --output_dir "${OUTPUT_DIR}" \
135
+ --log_type wandb \
136
+ --log_project Safe-RLHF-RM \
137
+ --zero_stage "${ZERO_STAGE}" \
138
+ --offload "${OFFLOAD}" \
139
+ --fp16 True \
140
+ --save_16bit
141
+ # --bf16 True \
142
+ # --tf32 True
143
+
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<pad>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dadfd56d766715c61d2ef780a525ab43b8e6da4de6865bda3d95fdef5e134055
3
+ size 493443
tokenizer_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ },
30
+ "32000": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ }
38
+ },
39
+ "additional_special_tokens": [],
40
+ "bos_token": "<s>",
41
+ "clean_up_tokenization_spaces": false,
42
+ "eos_token": "</s>",
43
+ "extra_special_tokens": {},
44
+ "legacy": false,
45
+ "max_length": 512,
46
+ "model_max_length": 512,
47
+ "pad_token": "<pad>",
48
+ "padding_side": "right",
49
+ "sp_model_kwargs": {},
50
+ "spaces_between_special_tokens": false,
51
+ "stride": 0,
52
+ "tokenizer_class": "LlamaTokenizer",
53
+ "truncation_side": "right",
54
+ "truncation_strategy": "longest_first",
55
+ "unk_token": "<unk>",
56
+ "use_default_system_prompt": false
57
+ }