pretrain_model.sh 2.19 KB
Newer Older
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
1
2
3
#!/bin/bash

set -u
liangjing's avatar
v1  
liangjing committed
4

Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
5
6
7
unset NCCL_DEBUG
export CUDA_DEVICE_MAX_CONNECTIONS=1

liangjing's avatar
v1  
liangjing committed
8
9
10
11
12
13
######## GPT or Retro?. ########

# 0 : GPT.
# 1 : Retro

ADD_RETRIEVER=1
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
14

liangjing's avatar
v1  
liangjing committed
15
######## Megatron, Retro dirs. ########
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
16

liangjing's avatar
v1  
liangjing committed
17
18
REPO_DIR="<path/to/megatron/repo>"
RETRO_WORKDIR="<path/to/retro/data/directory>"
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
19

liangjing's avatar
v1  
liangjing committed
20
######## Data. ########
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
21

liangjing's avatar
v1  
liangjing committed
22
23
24
DATA_BLEND="<see --data-path in arguments.py>"

######## Args. ########
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
25
26

ARGS=" \
liangjing's avatar
v1  
liangjing committed
27
28
29
30
31
32
33
34
35
36
37
38
    --log-interval 1 \
    --use-flash-attn \
    --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 \
    --exit-duration-in-mins 220 \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
39
40
    --tensor-model-parallel-size 1 \
    --pipeline-model-parallel-size 1 \
liangjing's avatar
v1  
liangjing committed
41
42
43
44
45
46
    --num-layers 24 \
    --hidden-size 1024 \
    --num-attention-heads 16 \
    --seq-length 512 \
    --max-position-embeddings 512 \
    --micro-batch-size 16 \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
47
    --global-batch-size 256 \
liangjing's avatar
v1  
liangjing committed
48
49
50
51
52
    --train-samples 200000 \
    --lr-decay-samples 175000 \
    --lr-warmup-samples 10000 \
    --lr 2.5e-5 \
    --min-lr 2.5e-6 \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
53
    --lr-decay-style cosine \
liangjing's avatar
v1  
liangjing committed
54
55
56
57
58
    --eval-iters 50 \
    --eval-interval 2000 \
    --tokenizer-type GPTSentencePieceTokenizer \
    --tokenizer-model <path/to/gpt/tokenizer/model> \
    --data-path ${DATA_BLEND} \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
59
60
61
62
63
    --split 98,2,0 \
    --clip-grad 1.0 \
    --weight-decay 0.1 \
    --adam-beta1 0.9 \
    --adam-beta2 0.95 \
liangjing's avatar
v1  
liangjing committed
64
    --init-method-std 0.007 \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
65
66
    --log-params-norm \
    --log-num-zeros-in-grad \
liangjing's avatar
v1  
liangjing committed
67
    --bf16 \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
68
69
70
    --DDP-impl local \
"

liangjing's avatar
v1  
liangjing committed
71
72
73
######## Retro. ########

if [ "$ADD_RETRIEVER" = "0" ]; then
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
74
75
76
77
    SCRIPT=pretrain_gpt.py
else
    ARGS="${ARGS} \
    --retro-workdir ${RETRO_WORKDIR} \
liangjing's avatar
v1  
liangjing committed
78
    --retro-add-retriever \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
79
80
81
82
    "
    SCRIPT=pretrain_retro.py
fi

liangjing's avatar
v1  
liangjing committed
83
######## Command. ########
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
84

liangjing's avatar
v1  
liangjing committed
85
86
87
88
89
NPROCS=8
CMD="\
    pwd && cd ${REPO_DIR} && pwd && \
    export PYTHONPATH=$PYTHONPATH:${REPO_DIR} && \
    python -m torch.distributed.run \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
90
91
    --nproc_per_node ${NPROCS} \
    --nnodes 1 \
liangjing's avatar
v1  
liangjing committed
92
93
    --node_rank ${NODE_RANK} \
    --master_addr ${MASTER_ADDR} \
Lawrence McAfee's avatar
Retro  
Lawrence McAfee committed
94
    --master_port 6000 \
liangjing's avatar
v1  
liangjing committed
95
96
97
98
99
100
    ${SCRIPT} ${ARGS} \
"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "CMD = '$CMD'."
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~"
eval $CMD