ds_gpt2_test.sh 2.82 KB
Newer Older
Elton Zheng's avatar
Elton Zheng committed
1
2
3
4
5
#! /bin/bash

helpFunction()
{
    echo ""
Jeff Rasley's avatar
Jeff Rasley committed
6
    echo "Usage: $0 -m model-parallelism -g gpu-per-node -n node# -b batch-size -s stpes -l layers -h hidden_size -q seq_length -e heads -c ckpt_num_layers -p [-d]"
Elton Zheng's avatar
Elton Zheng committed
7
8
9
10
11
12
13
14
15
16
17
18
19
    echo -e "\t-m model parallelism"
    echo -e "\t-g gpus per node"
    echo -e "\t-n node count"
    echo -e "\t-b batch size"
    echo -e "\t-s training steps"
    echo -e "\t-l layers"
    echo -e "\t-h hidden size"
    echo -e "\t-q sequence length"
    echo -e "\t-e attention heads"
    echo -e "\t-c checkpoint num_layers"
    echo -e "\t-o other args"
    echo -e "\t-d DeepSpeed config json file"
    echo -e "\t-z Enable Zero optimization"
Jeff Rasley's avatar
Jeff Rasley committed
20
    echo -e "\t-p DeepSpeed master port"
Elton Zheng's avatar
Elton Zheng committed
21
22
23
    exit 1
}

24
25
layers=2
hidden_size=128
Elton Zheng's avatar
Elton Zheng committed
26
27
28
29
30
seq_length=1024
ckpt_num_layers=1
other_args=""
ds_opt=""
zero_opt=""
Jeff Rasley's avatar
Jeff Rasley committed
31
master_port=29600
Elton Zheng's avatar
Elton Zheng committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

script_path=$(realpath $0)
script_dir=$(dirname $script_path)

while getopts "m:g:n:b:s:l:h:q:e:c:o:d:z" opt
do
    case "$opt" in
        m ) mp="$OPTARG" ;;
        g ) gpus="$OPTARG" ;;
        n ) nodes="$OPTARG" ;;
        b ) bs="$OPTARG" ;;
        s ) steps="$OPTARG" ;;
        l ) layers="$OPTARG" ;;
        h ) hidden_size="$OPTARG" ;;
        q ) seq_length="$OPTARG" ;;
        e ) heads="$OPTARG" ;;
        c ) ckpt_num_layers="$OPTARG" ;;
Jeff Rasley's avatar
Jeff Rasley committed
49
        p ) master_port="$OPTARG" ;;
Elton Zheng's avatar
Elton Zheng committed
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
        o ) other_args="$OPTARG" ;;
        d ) ds_opt="--deepspeed --deepspeed_config $script_dir/$OPTARG" ;;
        z ) zero_opt="--zero_optimization" ;;
        ? ) helpFunction ;;
    esac
done

# Print helpFunction in case parameters are empty
if [ -z "$mp" ] || [ -z "$gpus" ] || [ -z "$nodes" ] || [ -z "$bs" ] || [ -z "$steps" ]
then
    echo "Some or all of the parameters are empty";
    helpFunction
fi

# Change for multinode config
MASTER_ADDR=localhost
MASTER_PORT=6000

gpt_options=" \
       --model-parallel-size ${mp} \
       --num-layers ${layers} \
       --hidden-size ${hidden_size} \
       --num-attention-heads ${heads} \
       --batch-size ${bs} \
       --seq-length ${seq_length} \
       --max-position-embeddings ${seq_length} \
       --train-iters ${steps} \
       --train-data webtext \
       --lazy-loader \
       --tokenizer-type GPT2BPETokenizer \
       --split 949,50,1 \
       --distributed-backend nccl \
       --lr 0.00015 \
       --no-load-optim \
       --lr-decay-style cosine \
       --weight-decay 1e-2 \
       --clip-grad 1.0 \
       --warmup .01 \
       --checkpoint-activations \
       --checkpoint-num-layers ${ckpt_num_layers} \
       --fp16 \
Jeff Rasley's avatar
Jeff Rasley committed
91
       --cache-dir /tmp/cache_dir \
Elton Zheng's avatar
Elton Zheng committed
92
93
94
95
96
97
       --log-interval 1 \
       ${other_args} \
       ${ds_opt} \
       ${zero_opt} \
"

Shaden Smith's avatar
Shaden Smith committed
98
work_dir="../../../DeepSpeedExamples/Megatron-LM/"
Jeff Rasley's avatar
Jeff Rasley committed
99
run_cmd="(cd ${work_dir} && deepspeed --master_port ${master_port} --num_nodes $nodes --num_gpus $gpus pretrain_gpt2.py ${gpt_options})"
Elton Zheng's avatar
Elton Zheng committed
100
101
102
103
echo ${run_cmd}
eval ${run_cmd}

set +x