-
Notifications
You must be signed in to change notification settings - Fork 1
/
sft_retro_lm.sh
150 lines (124 loc) · 3.52 KB
/
sft_retro_lm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# bash examples/qa/finetune_normal_lm.sh landrover_tasb_retrieved 843m 1 3e-6 1
blend_name=$1
model_size=$2
global_bsz=$3
lr=$4
ft_neighbours=1
model_card=pp1
ckpt=$5
TASK=none
train_iters=1000
DATA_HOME="<path/to/instruction/tuning/data/directory>"
data_folder="$DATA_HOME"
SFT_HOME="<path/to/megatron/repo>"
TOKENIZER_MODEL="<path/to/gpt/tokenizer/model>"
RETRO_WORKDIR="<path/to/retro/workdir>"
K=2
PRETRAINED_CHECKPOINT=${ckpt}
SAVENAME="retro-${blend_name}_${model_card}_same_format_ctx${ft_neighbours}_${model_size}_${global_bsz}_${lr}"
CHECKPOINT_PATH="${SFT_HOME}/checkpoints/applications/${SAVENAME}"
TENSORBOARD_DIR="${SFT_HOME}/tensorboard/${SAVENAME}"
mkdir -p ${TENSORBOARD_DIR}
. ./tools/retro/sft/"${blend_name}".sh
if [[ $model_size == "843m" ]]; then
# model param
mod_par=1
layers=24
hid_dim=1024
heads=16
pip_par=1
# node param
num_nodes=1
lr=5e-6
min_lr=5e-6
fi
GPT_ARGS="--apply-layernorm-1p \
--untie-embeddings-and-output-weights \
--disable-bias-linear \
--no-position-embedding \
--use-rotary-position-embeddings \
--rotary-percent 0.5 \
--swiglu \
--attention-dropout 0.0 \
--hidden-dropout 0.0 \
--pipeline-model-parallel-size $pip_par \
--tensor-model-parallel-size $mod_par \
--num-layers $layers \
--hidden-size $hid_dim \
--num-attention-heads $heads \
--seq-length 4096 \
--max-position-embeddings 4096 \
--lr-decay-style cosine \
--tokenizer-type GPTSentencePieceTokenizer \
--tokenizer-model ${TOKENIZER_MODEL} \
--clip-grad 1.0 \
--weight-decay 0.01 \
--adam-beta1 0.9 \
--adam-beta2 0.98 \
--log-params-norm \
--log-num-zeros-in-grad \
--bf16 \
--use-distributed-optimizer \
"
FT_ARGS="--eod-mask-loss \
--answer-loss-only \
--ft_neighbours ${ft_neighbours} \
--task $TASK"
OUTPUT_ARGS="--log-interval 10 \
--save-interval 500 \
--eval-interval 200 \
--tensorboard-dir ${TENSORBOARD_DIR} \
--log-validation-ppl-to-tensorboard \
--eval-iters 100"
options=" \
$GPT_ARGS \
--retro-workdir ${RETRO_WORKDIR} \
--retro-add-retriever \
--retro-num-neighbors ${K} \
--retro-attention-gate 0 \
--data-path ${DATA_BLEND} \
--data-folder ${data_folder} \
--recompute-activations \
--lr $lr \
--micro-batch-size 1 \
--global-batch-size ${global_bsz} \
--min-lr ${min_lr} \
--retro-cyclic-train-iters ${train_iters} \
--train-iters ${train_iters} \
--dataloader-type cyclic \
--save $CHECKPOINT_PATH \
$OUTPUT_ARGS \
$FT_ARGS"
if [[ -d "$CHECKPOINT_PATH" ]]; then
options="$options \
--load $CHECKPOINT_PATH "
else
echo $PRETRAINED_CHECKPOINT
options="$options \
--load $PRETRAINED_CHECKPOINT \
--finetune \
--no-load-rng \
--no-load-optim "
fi
######## Command. ########
run_cmd="python -u ${SFT_HOME}/tools/retro/sft/sft_retro.py ${options}"
export NCCL_DEBUG=INFO
export NCCL_IB_TIMEOUT=19
export NCCL_IB_SL=1
export CUDA_DEVICE_MAX_CONNECTIONS=1
NPROCS=8
CMD="\
pwd && cd ${SFT_HOME} && pwd && \
export PYTHONPATH=$PYTHONPATH:${SFT_HOME} && \
python -m torch.distributed.run \
--nproc_per_node ${NPROCS} \
--nnodes 1 \
--node_rank 0 \
--master_port 6000 \
${run_cmd} \
"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "CMD = '$CMD'."
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~"
eval $CMD