forked from argonne-lcf/Megatron-DeepSpeed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_config.sh
144 lines (137 loc) · 3.27 KB
/
generate_config.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
#!/bin/bash --login
for v in "$GLOBAL_BATCH" "$MICRO_BATCH" "$GRAD_ACC_STEPS" "$ZERO_STAGE" \
"$PP" "$DTYPE"
do
if [ -z $v ]; then
echo "Please export required envs before execute $0"
exit 1
fi
done
if [ $# -ne 1 ]; then
echo "Usage: $0 config_file"
exit 1
fi
extra=""
common="\
\"train_batch_size\": $GLOBAL_BATCH,
\"train_micro_batch_size_per_gpu\": $MICRO_BATCH,
\"steps_per_print\": 1,
\"gradient_accumulation_steps\": $GRAD_ACC_STEPS,
\"optimizer\": {
\"type\": \"AdamW\",
\"params\": {
\"lr\": ${LR},
\"beta1\": 0.9,
\"beta2\": 0.95,
\"eps\": 1e-5,
\"weight_decay\": 1e-1
}
},
\"scheduler\": {
\"type\": \"WarmupLR\",
\"params\": {
\"warmup_min_lr\": 0.00003,
\"warmup_max_lr\": 0.0003,
\"warmup_num_steps\": 5000
}
},
\"zero_allow_untested_optimizer\": true,
\"gradient_clipping\": 1.0,
\"activation_checkpointing\": {
\"partition_activations\": true,
\"contiguous_memory_optimization\": false
},
\"wall_clock_breakdown\": false,"
flops_profiler="\
\"flops_profiler\": {
\"enabled\": true,
\"profile_step\": 5,
\"module_depth\": -1,
\"top_modules\": 1,
\"detailed\": true,
\"output_file\": null
}"
if [[ $DTYPE == "bf16" ]]; then
dtype="\
\"communication_data_type\": \"bfp16\",
\"fp16\": {
\"enabled\": false,
\"loss_scale\": 0,
\"loss_scale_window\": 1000,
\"hysteresis\": 2,
\"min_loss_scale\": 1
},
\"bfloat16\": {
\"enabled\": true,
\"loss_scale\": 1.0
},"
else
dtype="\
\"communication_data_type\": \"fp16\",
\"fp16\": {
\"enabled\": true,
\"loss_scale\": 0,
\"loss_scale_window\": 1000,
\"hysteresis\": 2,
\"min_loss_scale\": 1
},
\"bfloat16\": {
\"enabled\": false,
\"loss_scale\": 1.0
},"
fi
if [ $ZERO_STAGE == 3 ]; then
zero="\
\"zero_optimization\": {
\"stage\": 3,
\"reduce_scatter\": false,
\"stage3_max_live_parameters\": 3e9,
\"stage3_max_reuse_distance\": 3e9,
\"stage3_param_persistence_threshold\": 1e5,
\"stage3_prefetch_bucket_size\": 5e7,
\"contiguous_gradients\": true,
\"overlap_comm\": true,
\"reduce_bucket_size\": 90000000,
\"sub_group_size\": 1e9,
\"offload_optimizer\": {
\"device\": \"none\",
\"buffer_count\": 4,
\"pipeline_read\": false,
\"pipeline_write\": false,
\"pin_memory\": true
}
},"
elif [ $ZERO_STAGE == 2 ] || [ $ZERO_STAGE == 1 ]; then
zero="\
\"zero_optimization\": {
\"stage\": $ZERO_STAGE
},"
if [ $ZERO_STAGE == 1 ]; then
if [ $PP > 1 ]; then
extra="\
\"data_types\": {
\"grad_accum_dtype\": \"fp32\"
},
\"comms_logger\": {
\"enabled\": true,
\"verbose\": false,
\"prof_all\": true,
\"debug\": false
},"
else
echo 'please add the config for zero_stage 1 without pipeline-parallelism'
fi
fi
else
echo 'Please add the correct config set!!!'
fi
# flops_profiler must at the end because no ',' is allowed at the end
cat <<EOT > $1
{
$common
$zero
$dtype
$extra
$flops_profiler
}
EOT