applied-ai-018 commited on
Commit
4fe5997
·
verified ·
1 Parent(s): 9a09fb2

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_config_gpt_TEMPLATE.json +39 -0
  2. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_config_gpt_Zero2_TEMPLATE.json +38 -0
  3. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_evalharness.sh +71 -0
  4. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_MoE128.sh +349 -0
  5. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128.sh +341 -0
  6. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128_MoS.sh +355 -0
  7. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_dense.sh +350 -0
  8. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_dense_cl.sh +285 -0
  9. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_125M_MoE64.sh +373 -0
  10. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_125M_dense_cl.sh +309 -0
  11. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_MoE128.sh +349 -0
  12. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_PR-MoE32or64.sh +342 -0
  13. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_PR-MoE32or64_MoS.sh +354 -0
  14. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_dense.sh +349 -0
  15. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_6.7B_dense.sh +350 -0
  16. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/readme_evalharness.md +168 -0
  17. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/README.md +27 -0
  18. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/run-175b.sh +142 -0
  19. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/run-1t.sh +154 -0
  20. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/run-benchmark-model.sh +142 -0
  21. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azureml/Dockerfile.dockerfile +14 -0
  22. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azureml/README.md +14 -0
  23. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/125M-Int8-test-64gpu-distilled-group48.sh +253 -0
  24. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/125M-L10-Int8-test-64gpu-distilled-group48.sh +253 -0
  25. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_config_gpt_TEMPLATE.json +39 -0
  26. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_config_gpt_TEMPLATE_compression.json +87 -0
  27. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_evalharness.sh +74 -0
  28. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_pretrain_gpt_1.3B_dense_cl_kd.sh +322 -0
  29. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_pretrain_gpt_125M_dense_cl_kd.sh +323 -0
  30. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_pretrain_gpt_350M_dense_kd.sh +349 -0
  31. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/README.md +1 -0
  32. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/ds_train.sh +37 -0
  33. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/ds_zero_stage_1_config_baseline.json +26 -0
  34. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/ds_zero_stage_1_config_curriculum_fixed_linear.json +37 -0
  35. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/evaluate_zeroshot_gpt.sh +38 -0
  36. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/generate_text.sh +48 -0
  37. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/merge_mp_bert.sh +18 -0
  38. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_bert_distributed.sh +44 -0
  39. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_bert_distributed_with_mp.sh +46 -0
  40. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt.sh +41 -0
  41. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt3_175B.sh +65 -0
  42. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt_distributed.sh +48 -0
  43. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt_distributed_with_mp.sh +50 -0
  44. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_ict.sh +44 -0
  45. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_t5.sh +38 -0
  46. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/run_deepspeed_example.sh +84 -0
  47. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/images/cases_april2021.png +3 -0
  48. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/tasks/data_utils.py +118 -0
  49. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/tasks/detok.py +73 -0
  50. docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/tasks/ensemble_classifier.py +149 -0
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_config_gpt_TEMPLATE.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size" : CONFIG_BATCH_SIZE,
3
+ "train_micro_batch_size_per_gpu": CONFIG_MBSIZE,
4
+ "steps_per_print": LOG_INTERVAL,
5
+
6
+ "zero_optimization": {
7
+ "stage": ZERO_STAGE,
8
+ "elastic_checkpoint": true
9
+ },
10
+
11
+ "gradient_clipping": 1.0,
12
+ "prescale_gradients": PRESCALE_GRAD,
13
+
14
+ "fp16": {
15
+ "enabled": CONFIG_FP16_ENABLED,
16
+ "loss_scale": 0,
17
+ "loss_scale_window": 500,
18
+ "hysteresis": 2,
19
+ "min_loss_scale": 1,
20
+ "initial_scale_power": 11
21
+ },
22
+
23
+ "bf16": {
24
+ "enabled": CONFIG_BF16_ENABLED
25
+ },
26
+ "curriculum_learning": {
27
+ "enabled": CONFIG_CL_ENABLED,
28
+ "curriculum_type": "seqlen",
29
+ "min_difficulty": CONFIG_CL_MIN,
30
+ "max_difficulty": CONFIG_CL_MAX,
31
+ "schedule_type": "fixed_linear",
32
+ "schedule_config": {
33
+ "total_curriculum_step": CONFIG_CL_DURATION,
34
+ "difficulty_step": 8
35
+ }
36
+ },
37
+
38
+ "wall_clock_breakdown" : false
39
+ }
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_config_gpt_Zero2_TEMPLATE.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size" : CONFIG_BATCH_SIZE,
3
+ "train_micro_batch_size_per_gpu": CONFIG_MBSIZE,
4
+ "steps_per_print": LOG_INTERVAL,
5
+
6
+ "zero_optimization": {
7
+ "stage": 2
8
+ },
9
+
10
+ "gradient_clipping": 1.0,
11
+ "prescale_gradients": false,
12
+
13
+ "fp16": {
14
+ "enabled": CONFIG_FP16_ENABLED,
15
+ "loss_scale": 0,
16
+ "loss_scale_window": 500,
17
+ "hysteresis": 2,
18
+ "min_loss_scale": 1,
19
+ "initial_scale_power": 11
20
+ },
21
+
22
+ "bf16": {
23
+ "enabled": CONFIG_BF16_ENABLED
24
+ },
25
+ "curriculum_learning": {
26
+ "enabled": CONFIG_CL_ENABLED,
27
+ "curriculum_type": "seqlen",
28
+ "min_difficulty": CONFIG_CL_MIN,
29
+ "max_difficulty": CONFIG_CL_MAX,
30
+ "schedule_type": "fixed_linear",
31
+ "schedule_config": {
32
+ "total_curriculum_step": CONFIG_CL_DURATION,
33
+ "difficulty_step": 8
34
+ }
35
+ },
36
+
37
+ "wall_clock_breakdown" : false
38
+ }
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_evalharness.sh ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is an example zero-shot eval script. Please first read the readme_evalharness.md under the same directory.
2
+
3
+ CHECKPOINT_PATH=/blob/users/conglli/project/gpt3_with_pile/checkpoint/gpt3-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-128-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-20728-token-45B/global_step81566/
4
+ CONFIG_PATH=ds_config_gpt3-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-128-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-20728-token-45B.json
5
+ RESULT_PATH=gpt3-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-128-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-20728-token-45B_global_step81566.log
6
+
7
+ PP_SIZE=1
8
+ TP_SIZE=1
9
+ NO_PP="true"
10
+ EP_PARALLEL_SIZE=1
11
+ # Currently eval harness does not support data parallel
12
+ # However, for MoE models it's possible to enable a "fake data parallel"
13
+ # in order to load experts on multiple gpus. At the same time, it's not
14
+ # real data parallel because we load the same data on all gpus.
15
+ # On the other hand, it's better to use less number of gpus than training,
16
+ # to reduce communication overhead.
17
+ NUM_NODE=1
18
+ NUM_GPU_PER_NODE=1
19
+
20
+ TASKS="lambada"
21
+ # WikiText-2, not used in GPT-3 paper but used in GPT-2 paper
22
+ # TASKS="wikitext"
23
+ # Tasks that appeared in GPT-3 paper (sorted based on the order in paper), plus WikiText-2.
24
+ # TASKS="hellaswag,lambada,triviaqa,webqs,winogrande,piqa,arc_challenge,arc_easy,openbookqa,race,boolq,cb,copa,rte,wic,wsc,multirc,record,anli_r1,anli_r2,anli_r3,wikitext"
25
+ # All tasks that confirmed to work, there are more tasks on https://github.com/EleutherAI/lm-evaluation-harness that we didn't test.
26
+ # TASKS="hellaswag,lambada,triviaqa,webqs,winogrande,piqa,arc_challenge,arc_easy,openbookqa,race,boolq,cb,copa,rte,wic,wsc,multirc,record,anli_r1,anli_r2,anli_r3,wikitext,logiqa,mathqa,mc_taco,mrpc,prost,pubmedqa,qnli,qqp,sciq,sst,wnli"
27
+
28
+ VOCAB_FILE=/data/Megatron-LM/data/gpt2-vocab.json
29
+ MERGE_FILE=/data/Megatron-LM/data/gpt2-merges.txt
30
+
31
+ export HF_DATASETS_OFFLINE=1
32
+
33
+ # Dummy arguments to make megatron happy. No need to configure them.
34
+ # The reason we don't need to configure them and many other arguments is
35
+ # because the eval framework will read the arguments from checkpoint file.
36
+ MEGATRON_REQUIRED_ARGS="\
37
+ --num-layers -1\
38
+ --hidden-size -1\
39
+ --num-attention-heads -1\
40
+ --seq-length -1 \
41
+ --max-position-embeddings -1
42
+ "
43
+
44
+ CMD="../../tasks/eval_harness/evaluate.py \
45
+ --load $CHECKPOINT_PATH\
46
+ --tensor-model-parallel-size $TP_SIZE \
47
+ --pipeline-model-parallel-size $PP_SIZE\
48
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
49
+ --vocab-file $VOCAB_FILE\
50
+ --merge-file $MERGE_FILE\
51
+ --micro-batch-size 12\
52
+ --no-load-optim \
53
+ --no-load-rng \
54
+ --inference \
55
+ --disable-moe-token-dropping \
56
+ --adaptive_seq_len\
57
+ --eval_fp32\
58
+ --task_list $TASKS\
59
+ --results_path $RESULT_PATH \
60
+ --deepspeed \
61
+ --deepspeed_config $CONFIG_PATH \
62
+ $MEGATRON_REQUIRED_ARGS\
63
+ "
64
+
65
+ if [[ "${NO_PP}" = "true" ]]; then
66
+ CMD="${CMD} \
67
+ --no-pipeline-parallel"
68
+ fi
69
+
70
+ LAUNCHER="deepspeed --num_nodes $NUM_NODE --num_gpus $NUM_GPU_PER_NODE"
71
+ $LAUNCHER $CMD
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_MoE128.sh ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ MODEL_SIZE=1.3
41
+ NUM_LAYERS=24
42
+ HIDDEN_SIZE=2048
43
+ NUM_ATTN_HEADS=16
44
+ GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_ITERS is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_ITERS.
95
+ TRAIN_ITERS=$(( ${TRAIN_TOKENS} * 3 / ${GLOBAL_BATCH_SIZE} / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ # LR_DECAY_TOKENS=260000000000
108
+ LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=8
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
127
+ # EP_SIZE=1
128
+ EP_SIZE=128
129
+
130
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+ else
133
+ EP_PARALLEL_SIZE=$EP_SIZE
134
+ fi
135
+
136
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
137
+ ## found that lower LR and min LR (than the base dense model) helps.
138
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
139
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
140
+ ## heavily tuned.
141
+ LR=1.2e-4
142
+ MIN_LR=1.0e-6
143
+
144
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
145
+ ## 1.3B MoE-128 model
146
+ MLC=0.01
147
+
148
+ ## Below configs adjust the MoE expert token capacity limit during training and
149
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
150
+ ## Larger capacity factor or disabling capacity limit could improve training
151
+ ## convergence, but will also reduce training throughput.
152
+ MOE_TRAIN_CAP_FACTOR=1.0
153
+ MOE_EVAL_CAP_FACTOR=1.0
154
+ MOE_MIN_CAP=4
155
+ MOE_DROP_TOKEN="true"
156
+ # MOE_DROP_TOKEN="false"
157
+ ###############################################################################
158
+ ### Curriculum learning (CL) configs
159
+ ## Enable/disable CL
160
+ CL_ENABLED="false"
161
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
162
+ ## for tuning the following configs
163
+ CL_START_SEQLEN=80
164
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
165
+ CL_TOKENS=60
166
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
167
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
168
+ ###############################################################################
169
+ ### Misc configs
170
+ LOG_INTERVAL=10
171
+ EVAL_ITERS=10
172
+ EVAL_INTERVAL=100
173
+ SAVE_INTERVAL=10000
174
+
175
+ ## Standard deviation for weight initialization
176
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
177
+ ## dense model. Usually larger model needs lower std.
178
+ INIT_STD=0.014
179
+ # INIT_STD=0.01
180
+
181
+ ## Activation checkpointing saves GPU memory, but reduces training speed
182
+ ACTIVATION_CHECKPOINT="true"
183
+ # ACTIVATION_CHECKPOINT="false"
184
+ ###############################################################################
185
+ ### Output and data configs
186
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
187
+ host="${HOSTNAME}"
188
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
189
+ if [[ $EP_SIZE -gt 1 ]]; then
190
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
191
+ fi
192
+ if [ "${CL_ENABLED}" = "true" ]; then
193
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
194
+ fi
195
+
196
+ OUTPUT_BASEPATH=$DIR/output
197
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
199
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
200
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
201
+ mkdir -p ${TENSORBOARD_DIR}
202
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
203
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
204
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+
206
+ # USE_INTERNAL_DATA="true"
207
+ USE_INTERNAL_DATA="false"
208
+
209
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
210
+ ## The internal data is only accessible within Microsoft
211
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
212
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
213
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
214
+ ## For cluster Lab-RR1-V100
215
+ BASE_DATA_PATH=/data/Megatron-LM/data
216
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
217
+ ## For cluster Azure-CentralUS-A100
218
+ # BASE_DATA_PATH=/data/Megatron-LM/data
219
+ # DATA_HOME=/vc_data_1/users/amawa/blended
220
+
221
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
222
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
223
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
224
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
225
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
226
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
227
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
228
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
229
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
230
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
231
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
232
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
233
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
234
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
235
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
236
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
237
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
238
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
239
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
240
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
241
+ 0.01359 ${ARX} 0.01588 ${GIT}"
242
+ else
243
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
244
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
245
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
246
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
247
+ fi
248
+ ###############################################################################
249
+ data_options=" \
250
+ --vocab-file ${VOCAB_PATH} \
251
+ --merge-file ${MERGE_PATH} \
252
+ --data-path ${DATA_BLEND} \
253
+ --data-impl mmap"
254
+
255
+ megatron_options=" \
256
+ --override-lr-scheduler \
257
+ --adam-beta1 0.9 \
258
+ --adam-beta2 0.95 \
259
+ --tensor-model-parallel-size ${MP_SIZE} \
260
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
261
+ --num-experts ${EP_SIZE} \
262
+ --moe-loss-coeff ${MLC} \
263
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
264
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
265
+ --moe-min-capacity ${MOE_MIN_CAP} \
266
+ --init-method-std ${INIT_STD} \
267
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
268
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
269
+ --micro-batch-size ${BATCH_SIZE} \
270
+ --exit-duration-in-mins ${EXIT_DURATION} \
271
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
272
+ --num-layers ${NUM_LAYERS} \
273
+ --hidden-size ${HIDDEN_SIZE} \
274
+ --num-attention-heads ${NUM_ATTN_HEADS} \
275
+ --seq-length ${SEQ_LEN} \
276
+ --max-position-embeddings ${SEQ_LEN} \
277
+ --train-tokens ${TRAIN_TOKENS} \
278
+ --train-iters ${TRAIN_ITERS} \
279
+ --lr ${LR} \
280
+ --min-lr ${MIN_LR} \
281
+ --lr-decay-style cosine \
282
+ --split 98,2,0 \
283
+ --log-interval ${LOG_INTERVAL} \
284
+ --eval-interval ${EVAL_INTERVAL} \
285
+ --eval-iters ${EVAL_ITERS} \
286
+ --save-interval ${SAVE_INTERVAL} \
287
+ --weight-decay 0.1 \
288
+ --clip-grad 1.0 \
289
+ --hysteresis 2 \
290
+ --num-workers 0 \
291
+ --fp16 \
292
+ --load ${CHECKPOINT_PATH} \
293
+ --save ${CHECKPOINT_PATH} \
294
+ --tensorboard-queue-size 1 \
295
+ --log-timers-to-tensorboard \
296
+ --log-batch-size-to-tensorboard \
297
+ --log-validation-ppl-to-tensorboard \
298
+ --tensorboard-dir ${TENSORBOARD_DIR}"
299
+
300
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
301
+ megatron_options="${megatron_options} \
302
+ --checkpoint-activations"
303
+ fi
304
+
305
+ if [[ $EP_SIZE -gt 1 ]]; then
306
+ megatron_options="${megatron_options} \
307
+ --create-moe-param-group"
308
+ fi
309
+
310
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
311
+ megatron_options="${megatron_options} \
312
+ --disable-moe-token-dropping"
313
+ fi
314
+
315
+ template_json="ds_config_gpt_TEMPLATE.json"
316
+ config_json="ds_config_gpt_${NAME}.json"
317
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
318
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
319
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
320
+ | sed "s/ZERO_STAGE/0/" \
321
+ | sed "s/PRESCALE_GRAD/true/" \
322
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
323
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
324
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
325
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
326
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
327
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
328
+ > ${config_json}
329
+
330
+ deepspeed_options=" \
331
+ --deepspeed \
332
+ --deepspeed_config ${config_json} \
333
+ --pipeline-model-parallel-size ${PP_SIZE}"
334
+
335
+ # Currently MoE is not compatible with pipeline parallel
336
+ if [[ $EP_SIZE -gt 1 ]]; then
337
+ deepspeed_options="${deepspeed_options} \
338
+ --no-pipeline-parallel"
339
+ fi
340
+
341
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
342
+ deepspeed_options="${deepspeed_options} \
343
+ --deepspeed-activation-checkpointing"
344
+ fi
345
+
346
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
347
+ echo ${run_cmd}
348
+ eval ${run_cmd}
349
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128.sh ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ MODEL_SIZE=1.3
41
+ NUM_LAYERS=24
42
+ HIDDEN_SIZE=2048
43
+ NUM_ATTN_HEADS=16
44
+ GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_ITERS is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_ITERS.
95
+ TRAIN_ITERS=$(( ${TRAIN_TOKENS} * 3 / ${GLOBAL_BATCH_SIZE} / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ # LR_DECAY_TOKENS=260000000000
108
+ LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=8
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 128 means standard MoE
127
+ # EP_SIZE=128
128
+ EP_SIZE="64 64 64 64 64 64 64 64 64 64 128 128"
129
+
130
+
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+
133
+
134
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
135
+ ## found that lower LR and min LR (than the base dense model) helps.
136
+ ## For 1.3B PR-MoE-64/128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
137
+ ## heavily tuned.
138
+ LR=1.2e-4
139
+ MIN_LR=1.0e-6
140
+
141
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
142
+ ## 1.3B MoE-128 model
143
+ MLC=0.01
144
+
145
+ ## Below configs adjust the MoE expert token capacity limit during training and
146
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
147
+ ## Larger capacity factor or disabling capacity limit could improve training
148
+ ## convergence, but will also reduce training throughput.
149
+ MOE_TRAIN_CAP_FACTOR=1.0
150
+ MOE_EVAL_CAP_FACTOR=1.0
151
+ MOE_MIN_CAP=4
152
+ MOE_DROP_TOKEN="true"
153
+ # MOE_DROP_TOKEN="false"
154
+ ###############################################################################
155
+ ### Curriculum learning (CL) configs
156
+ ## Enable/disable CL
157
+ CL_ENABLED="false"
158
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
159
+ ## for tuning the following configs
160
+ CL_START_SEQLEN=80
161
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
162
+ CL_TOKENS=60
163
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
164
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
165
+ ###############################################################################
166
+ ### Misc configs
167
+ LOG_INTERVAL=10
168
+ EVAL_ITERS=10
169
+ EVAL_INTERVAL=100
170
+ SAVE_INTERVAL=10000
171
+
172
+ ## Standard deviation for weight initialization
173
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
174
+ ## dense model. Usually larger model needs lower std.
175
+ INIT_STD=0.014
176
+ # INIT_STD=0.01
177
+
178
+ ## Activation checkpointing saves GPU memory, but reduces training speed
179
+ ACTIVATION_CHECKPOINT="true"
180
+ # ACTIVATION_CHECKPOINT="false"
181
+ ###############################################################################
182
+ ### Output and data configs
183
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
184
+ host="${HOSTNAME}"
185
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
186
+ NAME="${NAME}-ep-pyramid-64+128-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
187
+
188
+ if [ "${CL_ENABLED}" = "true" ]; then
189
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
190
+ fi
191
+
192
+ OUTPUT_BASEPATH=$DIR/output
193
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
194
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
195
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
196
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
197
+ mkdir -p ${TENSORBOARD_DIR}
198
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
199
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
200
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
201
+
202
+ # USE_INTERNAL_DATA="true"
203
+ USE_INTERNAL_DATA="false"
204
+
205
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
206
+ ## The internal data is only accessible within Microsoft
207
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
208
+ BASE_DATA_PATH=/vc_data/Megatron-LM/data
209
+ DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
210
+ ## For cluster Lab-RR1-V100
211
+ # BASE_DATA_PATH=/data/Megatron-LM/data
212
+ # DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
213
+ ## For cluster Azure-CentralUS-A100
214
+ # BASE_DATA_PATH=/data/Megatron-LM/data
215
+ # DATA_HOME=/vc_data_1/users/amawa/blended
216
+
217
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
218
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
219
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
220
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
221
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
222
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
223
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
224
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
225
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
226
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
227
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
228
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
229
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
230
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
231
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
232
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
233
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
234
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
235
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
236
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
237
+ 0.01359 ${ARX} 0.01588 ${GIT}"
238
+ else
239
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
240
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
241
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
242
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
243
+ fi
244
+ ###############################################################################
245
+ data_options=" \
246
+ --vocab-file ${VOCAB_PATH} \
247
+ --merge-file ${MERGE_PATH} \
248
+ --data-path ${DATA_BLEND} \
249
+ --data-impl mmap"
250
+
251
+ megatron_options=" \
252
+ --override-lr-scheduler \
253
+ --adam-beta1 0.9 \
254
+ --adam-beta2 0.95 \
255
+ --tensor-model-parallel-size ${MP_SIZE} \
256
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
257
+ --num-experts ${EP_SIZE} \
258
+ --moe-loss-coeff ${MLC} \
259
+ --mlp-type residual \
260
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
261
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
262
+ --moe-min-capacity ${MOE_MIN_CAP} \
263
+ --init-method-std ${INIT_STD} \
264
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
265
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
266
+ --micro-batch-size ${BATCH_SIZE} \
267
+ --exit-duration-in-mins ${EXIT_DURATION} \
268
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
269
+ --num-layers ${NUM_LAYERS} \
270
+ --hidden-size ${HIDDEN_SIZE} \
271
+ --num-attention-heads ${NUM_ATTN_HEADS} \
272
+ --seq-length ${SEQ_LEN} \
273
+ --max-position-embeddings ${SEQ_LEN} \
274
+ --train-tokens ${TRAIN_TOKENS} \
275
+ --train-iters ${TRAIN_ITERS} \
276
+ --lr ${LR} \
277
+ --min-lr ${MIN_LR} \
278
+ --lr-decay-style cosine \
279
+ --split 98,2,0 \
280
+ --log-interval ${LOG_INTERVAL} \
281
+ --eval-interval ${EVAL_INTERVAL} \
282
+ --eval-iters ${EVAL_ITERS} \
283
+ --save-interval ${SAVE_INTERVAL} \
284
+ --weight-decay 0.1 \
285
+ --clip-grad 1.0 \
286
+ --hysteresis 2 \
287
+ --num-workers 0 \
288
+ --fp16 \
289
+ --load ${CHECKPOINT_PATH} \
290
+ --save ${CHECKPOINT_PATH} \
291
+ --tensorboard-queue-size 1 \
292
+ --log-timers-to-tensorboard \
293
+ --log-batch-size-to-tensorboard \
294
+ --log-validation-ppl-to-tensorboard \
295
+ --tensorboard-dir ${TENSORBOARD_DIR}"
296
+
297
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
298
+ megatron_options="${megatron_options} \
299
+ --checkpoint-activations"
300
+ fi
301
+
302
+ megatron_options="${megatron_options} \
303
+ --create-moe-param-group"
304
+
305
+
306
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
307
+ megatron_options="${megatron_options} \
308
+ --disable-moe-token-dropping"
309
+ fi
310
+
311
+ template_json="ds_config_gpt_Zero2_TEMPLATE.json"
312
+ config_json="ds_config_gpt_${NAME}.json"
313
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
314
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
315
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
316
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
317
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
318
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
319
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
320
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
321
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
322
+ > ${config_json}
323
+
324
+ deepspeed_options=" \
325
+ --deepspeed \
326
+ --deepspeed_config ${config_json} \
327
+ --pipeline-model-parallel-size ${PP_SIZE}"
328
+
329
+ # Currently MoE is not compatible with pipeline parallel
330
+ deepspeed_options="${deepspeed_options} \
331
+ --no-pipeline-parallel"
332
+
333
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
334
+ deepspeed_options="${deepspeed_options} \
335
+ --deepspeed-activation-checkpointing"
336
+ fi
337
+
338
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
339
+ echo ${run_cmd}
340
+ eval ${run_cmd}
341
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128_MoS.sh ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ MODEL_SIZE=1.3
41
+ NUM_LAYERS=24
42
+ HIDDEN_SIZE=2048
43
+ NUM_ATTN_HEADS=16
44
+ GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_ITERS is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_ITERS.
95
+ TRAIN_ITERS=$(( ${TRAIN_TOKENS} * 3 / ${GLOBAL_BATCH_SIZE} / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ # LR_DECAY_TOKENS=260000000000
108
+ LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=128
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 128 means standard MoE
127
+ # EP_SIZE=128
128
+ EP_SIZE="64 64 64 64 64 64 64 64 128 128"
129
+ EP_SIZE_TEACHER="64 64 64 64 64 64 64 64 64 64 128 128"
130
+
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+
133
+
134
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
135
+ ## found that lower LR and min LR (than the base dense model) helps.
136
+ ## For 1.3B PR-MoE-64/128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
137
+ ## heavily tuned.
138
+ LR=1.2e-4
139
+ MIN_LR=1.0e-6
140
+
141
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
142
+ ## 1.3B MoE-128 model
143
+ MLC=0.01
144
+
145
+ ## Below configs adjust the MoE expert token capacity limit during training and
146
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
147
+ ## Larger capacity factor or disabling capacity limit could improve training
148
+ ## convergence, but will also reduce training throughput.
149
+ MOE_TRAIN_CAP_FACTOR=1.0
150
+ MOE_EVAL_CAP_FACTOR=1.0
151
+ MOE_MIN_CAP=4
152
+ MOE_DROP_TOKEN="true"
153
+ # MOE_DROP_TOKEN="false"
154
+ ###############################################################################
155
+ ### Curriculum learning (CL) configs
156
+ ## Enable/disable CL
157
+ CL_ENABLED="false"
158
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
159
+ ## for tuning the following configs
160
+ CL_START_SEQLEN=80
161
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
162
+ CL_TOKENS=60
163
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
164
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
165
+ ###############################################################################
166
+ ### Misc configs
167
+ LOG_INTERVAL=10
168
+ EVAL_ITERS=10
169
+ EVAL_INTERVAL=100
170
+ SAVE_INTERVAL=10000
171
+
172
+ ## Standard deviation for weight initialization
173
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
174
+ ## dense model. Usually larger model needs lower std.
175
+ INIT_STD=0.014
176
+ # INIT_STD=0.01
177
+
178
+ ## Activation checkpointing saves GPU memory, but reduces training speed
179
+ ACTIVATION_CHECKPOINT="true"
180
+ # ACTIVATION_CHECKPOINT="false"
181
+ ###############################################################################
182
+ ### Output and data configs
183
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
184
+ host="${HOSTNAME}"
185
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
186
+ NAME="${NAME}-ep-pyramid-64+128-mos-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
187
+
188
+ if [ "${CL_ENABLED}" = "true" ]; then
189
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
190
+ fi
191
+
192
+ OUTPUT_BASEPATH=$DIR/output
193
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
194
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
195
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
196
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}"
197
+ mkdir -p ${TENSORBOARD_DIR}
198
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
199
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
200
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
201
+
202
+ ### Mixture-of-Students (MoS) configs
203
+ KD_BETA_CE=1
204
+ CHECKPOINT_PATH_STUDENT="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+ CHECKPOINT_PATH_TEACHER="${OUTPUT_BASEPATH}/checkpoint/gpt-1.3B-lr-1.2e-4-minlr-1.0e-6-bs-512-gpus-128-mp-1-pp-1-ep-pyramid-64+128-mlc-0.01-cap-1.0-drop-true/"
206
+ CHECKPOINT_PATH_SAVE="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
207
+
208
+ USE_INTERNAL_DATA="true"
209
+ # USE_INTERNAL_DATA="false"
210
+
211
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
212
+ ## The internal data is only accessible within Microsoft
213
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
214
+ BASE_DATA_PATH=/vc_data/Megatron-LM/data
215
+ DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
216
+ ## For cluster Lab-RR1-V100
217
+ # BASE_DATA_PATH=/data/Megatron-LM/data
218
+ # DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
219
+ ## For cluster Azure-CentralUS-A100
220
+ # BASE_DATA_PATH=/data/Megatron-LM/data
221
+ # DATA_HOME=/vc_data_1/users/amawa/blended
222
+
223
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
224
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
225
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
226
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
227
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
228
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
229
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
230
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
231
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
232
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
233
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
234
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
235
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
236
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
237
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
238
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
239
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
240
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
241
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
242
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
243
+ 0.01359 ${ARX} 0.01588 ${GIT}"
244
+ else
245
+ ## Placeholder, we plan to test a public dataset
246
+ VOCAB_PATH=""
247
+ MERGE_PATH=""
248
+ DATA_BLEND=""
249
+ fi
250
+ ###############################################################################
251
+ data_options=" \
252
+ --vocab-file ${VOCAB_PATH} \
253
+ --merge-file ${MERGE_PATH} \
254
+ --data-path ${DATA_BLEND} \
255
+ --data-impl mmap"
256
+
257
+ megatron_options=" \
258
+ --override-lr-scheduler \
259
+ --adam-beta1 0.9 \
260
+ --adam-beta2 0.95 \
261
+ --tensor-model-parallel-size ${MP_SIZE} \
262
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
263
+ --num-experts ${EP_SIZE} \
264
+ --moe-loss-coeff ${MLC} \
265
+ --mlp-type residual \
266
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
267
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
268
+ --moe-min-capacity ${MOE_MIN_CAP} \
269
+ --init-method-std ${INIT_STD} \
270
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
271
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
272
+ --micro-batch-size ${BATCH_SIZE} \
273
+ --exit-duration-in-mins ${EXIT_DURATION} \
274
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
275
+ --num-layers 21 \
276
+ --hidden-size ${HIDDEN_SIZE} \
277
+ --num-attention-heads ${NUM_ATTN_HEADS} \
278
+ --seq-length ${SEQ_LEN} \
279
+ --max-position-embeddings ${SEQ_LEN} \
280
+ --train-tokens ${TRAIN_TOKENS} \
281
+ --train-iters ${TRAIN_ITERS} \
282
+ --lr ${LR} \
283
+ --min-lr ${MIN_LR} \
284
+ --lr-decay-style cosine \
285
+ --split 98,2,0 \
286
+ --log-interval ${LOG_INTERVAL} \
287
+ --eval-interval ${EVAL_INTERVAL} \
288
+ --eval-iters ${EVAL_ITERS} \
289
+ --save-interval ${SAVE_INTERVAL} \
290
+ --weight-decay 0.1 \
291
+ --clip-grad 1.0 \
292
+ --hysteresis 2 \
293
+ --num-workers 0 \
294
+ --fp16 \
295
+ --load ${CHECKPOINT_PATH_STUDENT} \
296
+ --save ${CHECKPOINT_PATH_SAVE} \
297
+ --mos \
298
+ --kd-beta-ce ${KD_BETA_CE} \
299
+ --num-layers-teacher ${NUM_LAYERS} \
300
+ --num-experts-teacher ${EP_SIZE_TEACHER} \
301
+ --hidden-size-teacher ${HIDDEN_SIZE} \
302
+ --num-attention-heads-teacher ${NUM_ATTN_HEADS} \
303
+ --load-teacher ${CHECKPOINT_PATH_TEACHER} \
304
+ --tensorboard-queue-size 1 \
305
+ --log-timers-to-tensorboard \
306
+ --log-batch-size-to-tensorboard \
307
+ --log-validation-ppl-to-tensorboard \
308
+ --tensorboard-dir ${TENSORBOARD_DIR}"
309
+
310
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
311
+ megatron_options="${megatron_options} \
312
+ --checkpoint-activations"
313
+ fi
314
+
315
+ megatron_options="${megatron_options} \
316
+ --create-moe-param-group"
317
+
318
+
319
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
320
+ megatron_options="${megatron_options} \
321
+ --disable-moe-token-dropping"
322
+ fi
323
+
324
+ template_json="ds_config_gpt_Zero2_TEMPLATE.json"
325
+ config_json="ds_config_gpt_${NAME}.json"
326
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
327
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
328
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
329
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
330
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
331
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
332
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
333
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
334
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
335
+ > ${config_json}
336
+
337
+ deepspeed_options=" \
338
+ --deepspeed \
339
+ --deepspeed_config ${config_json} \
340
+ --pipeline-model-parallel-size ${PP_SIZE}"
341
+
342
+ # Currently MoE is not compatible with pipeline parallel
343
+ deepspeed_options="${deepspeed_options} \
344
+ --no-pipeline-parallel"
345
+
346
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
347
+ deepspeed_options="${deepspeed_options} \
348
+ --deepspeed-activation-checkpointing"
349
+ fi
350
+
351
+ # run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
352
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}.log"
353
+ echo ${run_cmd}
354
+ eval ${run_cmd}
355
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_dense.sh ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ MODEL_SIZE=1.3
41
+ NUM_LAYERS=24
42
+ HIDDEN_SIZE=2048
43
+ NUM_ATTN_HEADS=16
44
+ GLOBAL_BATCH_SIZE=512
45
+ LR=2.0e-4
46
+ MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_SAMPLES.
95
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ LR_DECAY_TOKENS=260000000000
108
+ # LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=2
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=4
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
127
+ EP_SIZE=1
128
+ # EP_SIZE=128
129
+
130
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+ else
133
+ EP_PARALLEL_SIZE=$EP_SIZE
134
+ fi
135
+
136
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
137
+ ## found that lower LR and min LR (than the base dense model) helps.
138
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
139
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
140
+ ## heavily tuned.
141
+ # LR=2.0e-4
142
+ # MIN_LR=2e-06
143
+
144
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
145
+ ## 1.3B MoE-128 model
146
+ MLC=0.01
147
+
148
+ ## Below configs adjust the MoE expert token capacity limit during training and
149
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
150
+ ## Larger capacity factor or disabling capacity limit could improve training
151
+ ## convergence, but will also reduce training throughput.
152
+ MOE_TRAIN_CAP_FACTOR=1.0
153
+ MOE_EVAL_CAP_FACTOR=1.0
154
+ MOE_MIN_CAP=4
155
+ MOE_DROP_TOKEN="true"
156
+ # MOE_DROP_TOKEN="false"
157
+ ###############################################################################
158
+ ### Curriculum learning (CL) configs
159
+ ## Enable/disable CL
160
+ CL_ENABLED="false"
161
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
162
+ ## for tuning the following configs
163
+ CL_START_SEQLEN=80
164
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
165
+ CL_TOKENS=60
166
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
167
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
168
+ ###############################################################################
169
+ ### Misc configs
170
+ LOG_INTERVAL=10
171
+ EVAL_ITERS=10
172
+ EVAL_INTERVAL=100
173
+ SAVE_INTERVAL=1000
174
+
175
+ ## Standard deviation for weight initialization
176
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
177
+ ## dense model. Usually larger model needs lower std.
178
+ INIT_STD=0.014
179
+ # INIT_STD=0.01
180
+
181
+ ## Activation checkpointing saves GPU memory, but reduces training speed
182
+ ACTIVATION_CHECKPOINT="true"
183
+ # ACTIVATION_CHECKPOINT="false"
184
+ ###############################################################################
185
+ ### Output and data configs
186
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
187
+ host="${HOSTNAME}"
188
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
189
+ if [[ $EP_SIZE -gt 1 ]]; then
190
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
191
+ fi
192
+ if [ "${CL_ENABLED}" = "true" ]; then
193
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
194
+ fi
195
+
196
+ OUTPUT_BASEPATH=$DIR/output
197
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
199
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
200
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
201
+ mkdir -p ${TENSORBOARD_DIR}
202
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
203
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
204
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+
206
+ # USE_INTERNAL_DATA="true"
207
+ USE_INTERNAL_DATA="false"
208
+
209
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
210
+ ## The internal data is only accessible within Microsoft
211
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
212
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
213
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
214
+ ## For cluster Lab-RR1-V100
215
+ BASE_DATA_PATH=/data/Megatron-LM/data
216
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
217
+ ## For cluster Azure-CentralUS-A100
218
+ # BASE_DATA_PATH=/data/Megatron-LM/data
219
+ # DATA_HOME=/vc_data_1/users/amawa/blended
220
+
221
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
222
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
223
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
224
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
225
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
226
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
227
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
228
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
229
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
230
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
231
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
232
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
233
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
234
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
235
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
236
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
237
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
238
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
239
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
240
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
241
+ 0.01359 ${ARX} 0.01588 ${GIT}"
242
+ else
243
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
244
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
245
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
246
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
247
+ fi
248
+ ###############################################################################
249
+ data_options=" \
250
+ --vocab-file ${VOCAB_PATH} \
251
+ --merge-file ${MERGE_PATH} \
252
+ --data-path ${DATA_BLEND} \
253
+ --data-impl mmap"
254
+
255
+ megatron_options=" \
256
+ --override-lr-scheduler \
257
+ --adam-beta1 0.9 \
258
+ --adam-beta2 0.95 \
259
+ --tensor-model-parallel-size ${MP_SIZE} \
260
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
261
+ --num-experts ${EP_SIZE} \
262
+ --moe-loss-coeff ${MLC} \
263
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
264
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
265
+ --moe-min-capacity ${MOE_MIN_CAP} \
266
+ --init-method-std ${INIT_STD} \
267
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
268
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
269
+ --micro-batch-size ${BATCH_SIZE} \
270
+ --exit-duration-in-mins ${EXIT_DURATION} \
271
+ --rampup-batch-size 32 32 1953125 \
272
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
273
+ --num-layers ${NUM_LAYERS} \
274
+ --hidden-size ${HIDDEN_SIZE} \
275
+ --num-attention-heads ${NUM_ATTN_HEADS} \
276
+ --seq-length ${SEQ_LEN} \
277
+ --max-position-embeddings ${SEQ_LEN} \
278
+ --train-tokens ${TRAIN_TOKENS} \
279
+ --train-samples ${TRAIN_SAMPLES} \
280
+ --lr ${LR} \
281
+ --min-lr ${MIN_LR} \
282
+ --lr-decay-style cosine \
283
+ --split 98,2,0 \
284
+ --log-interval ${LOG_INTERVAL} \
285
+ --eval-interval ${EVAL_INTERVAL} \
286
+ --eval-iters ${EVAL_ITERS} \
287
+ --save-interval ${SAVE_INTERVAL} \
288
+ --weight-decay 0.1 \
289
+ --clip-grad 1.0 \
290
+ --hysteresis 2 \
291
+ --num-workers 0 \
292
+ --fp16 \
293
+ --load ${CHECKPOINT_PATH} \
294
+ --save ${CHECKPOINT_PATH} \
295
+ --tensorboard-queue-size 1 \
296
+ --log-timers-to-tensorboard \
297
+ --log-batch-size-to-tensorboard \
298
+ --log-validation-ppl-to-tensorboard \
299
+ --tensorboard-dir ${TENSORBOARD_DIR}"
300
+
301
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
302
+ megatron_options="${megatron_options} \
303
+ --checkpoint-activations"
304
+ fi
305
+
306
+ if [[ $EP_SIZE -gt 1 ]]; then
307
+ megatron_options="${megatron_options} \
308
+ --create-moe-param-group"
309
+ fi
310
+
311
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
312
+ megatron_options="${megatron_options} \
313
+ --disable-moe-token-dropping"
314
+ fi
315
+
316
+ template_json="ds_config_gpt_TEMPLATE.json"
317
+ config_json="ds_config_gpt_${NAME}.json"
318
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
319
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
320
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
321
+ | sed "s/ZERO_STAGE/0/" \
322
+ | sed "s/PRESCALE_GRAD/true/" \
323
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
324
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
325
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
326
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
327
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
328
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
329
+ > ${config_json}
330
+
331
+ deepspeed_options=" \
332
+ --deepspeed \
333
+ --deepspeed_config ${config_json} \
334
+ --pipeline-model-parallel-size ${PP_SIZE}"
335
+
336
+ # Currently MoE is not compatible with pipeline parallel
337
+ if [[ $EP_SIZE -gt 1 ]]; then
338
+ deepspeed_options="${deepspeed_options} \
339
+ --no-pipeline-parallel"
340
+ fi
341
+
342
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
343
+ deepspeed_options="${deepspeed_options} \
344
+ --deepspeed-activation-checkpointing"
345
+ fi
346
+
347
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
348
+ echo ${run_cmd}
349
+ eval ${run_cmd}
350
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_1.3B_dense_cl.sh ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ MODEL_SIZE=1.3
41
+ NUM_LAYERS=24
42
+ HIDDEN_SIZE=2048
43
+ NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ MIN_LR=2.0e-5
47
+
48
+ # Curriculum learning (CL) enables stable large-batch training
49
+ GLOBAL_BATCH_SIZE=4096 # 8x
50
+ LR=8.0e-4 # 4x
51
+
52
+ ## GPT-3 2.7B
53
+ # MODEL_SIZE=2.7
54
+ # NUM_LAYERS=32
55
+ # HIDDEN_SIZE=2560
56
+ # NUM_ATTN_HEADS=32
57
+ # GLOBAL_BATCH_SIZE=512
58
+ # LR=1.6e-4
59
+ # MIN_LR=1.6e-5
60
+
61
+ ## GPT-3 6.7B
62
+ # MODEL_SIZE=6.7
63
+ # NUM_LAYERS=32
64
+ # HIDDEN_SIZE=4096
65
+ # NUM_ATTN_HEADS=32
66
+ # GLOBAL_BATCH_SIZE=1024
67
+ # LR=1.2e-4
68
+ # MIN_LR=1.2e-5
69
+
70
+ ## GPT-3 13B
71
+ # MODEL_SIZE=13
72
+ # NUM_LAYERS=40
73
+ # HIDDEN_SIZE=5120
74
+ # NUM_ATTN_HEADS=40
75
+ # GLOBAL_BATCH_SIZE=1024
76
+ # LR=1.0e-4
77
+ # MIN_LR=1.0e-5
78
+
79
+ ## GPT-3 175B
80
+ # MODEL_SIZE=175
81
+ # NUM_LAYERS=96
82
+ # HIDDEN_SIZE=12288
83
+ # NUM_ATTN_HEADS=96
84
+ # GLOBAL_BATCH_SIZE=1536
85
+ # LR=0.6e-4
86
+ # MIN_LR=0.6e-5
87
+ ###############################################################################
88
+ ### Training duration configs
89
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
90
+ TRAIN_TOKENS=300000000000
91
+
92
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
93
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
94
+ ## above, and techniques like curriculum learning has less token in some samples,
95
+ ## so we just set this config large enough to make sure we have enough
96
+ ## processed data and don't terminate by TRAIN_SAMPLES.
97
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
98
+
99
+ ## Another termination condition in minutes. Set it large enough to avoid
100
+ ## undesired early termination.
101
+ EXIT_DURATION=30000000
102
+ ###############################################################################
103
+ ### LR configs
104
+ ## LR warmup and decay duration, this token-based config is preferable since
105
+ ## no need to readjust when the batch size/seqlen is changed.
106
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
107
+ WARMUP_TOKENS=375000000
108
+ LR_DECAY_TOKENS=260000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=16
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ MP_SIZE=2
117
+
118
+ ## Pipeline parallelism. To disable PP, set PP_SIZE to 1 and NO_PP to true.
119
+ PP_SIZE=1
120
+ NO_PP="true"
121
+
122
+ ## ZeRO stage
123
+ ZERO_STAGE=0
124
+
125
+ ## Total number of GPUs
126
+ NUM_GPUS=128
127
+ DP_SIZE=$(( ${NUM_GPUS} / ${PP_SIZE} / ${MP_SIZE} ))
128
+ ###############################################################################
129
+ ### Curriculum learning (CL) configs
130
+ ## Enable/disable CL
131
+ CL_ENABLED="true"
132
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
133
+ ## for tuning the following configs
134
+ CL_START_SEQLEN=80
135
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
136
+ CL_TOKENS=60
137
+ CL_STEP=$(( ${CL_TOKENS} * 1000000000 / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
138
+ ###############################################################################
139
+ ### Misc configs
140
+ LOG_INTERVAL=10
141
+ EVAL_ITERS=10
142
+ EVAL_INTERVAL=100
143
+ SAVE_INTERVAL=1000
144
+
145
+ ## Standard deviation for weight initialization. Usually larger model needs
146
+ ## lower std. We used a heuristic equation of sqrt(1/3/HIDDEN_SIZE) from the
147
+ ## MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
148
+ INIT_STD=0.013
149
+
150
+ ## Activation checkpointing saves GPU memory, but reduces training speed
151
+ ACTIVATION_CHECKPOINT="true"
152
+ # ACTIVATION_CHECKPOINT="false"
153
+
154
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
155
+ ## This is not required for training and might save GPU memory when turned off.
156
+ LOG_OPTIMIZER_STATE="true"
157
+ ###############################################################################
158
+ ### Output and data configs
159
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
160
+ host="${HOSTNAME}"
161
+ NAME="gpt3-with-pile-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-zero-${ZERO_STAGE}-mp-${MP_SIZE}-pp-${PP_SIZE}"
162
+ if [ "${NO_PP}" = "true" ]; then
163
+ NAME="${NAME}-no_pp"
164
+ fi
165
+ if [ "${CL_ENABLED}" = "true" ]; then
166
+ NAME="${NAME}-cl-startseqlen-${CL_START_SEQLEN}-step-${CL_STEP}-token-${CL_TOKENS}B"
167
+ fi
168
+
169
+ LOG_PATH="log/"
170
+ TENSORBOARD_PATH="tensorboard/${NAME}_${host}_${current_time}"
171
+ CHECKPOINT_PATH="/blob/users/conglli/project/gpt3_with_pile/checkpoint/${NAME}"
172
+ mkdir -p ${LOG_PATH}
173
+ mkdir -p ${TENSORBOARD_PATH}
174
+ mkdir -p ${CHECKPOINT_PATH}
175
+
176
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
177
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
178
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
179
+ DATA_PATH=/data/the_pile_public_merged_nopreprocessing/pile_text_document
180
+ ###############################################################################
181
+ data_options=" \
182
+ --vocab-file ${VOCAB_PATH} \
183
+ --merge-file ${MERGE_PATH} \
184
+ --data-path ${DATA_PATH} \
185
+ --data-impl mmap"
186
+
187
+ megatron_options=" \
188
+ --override-lr-scheduler \
189
+ --adam-beta1 0.9 \
190
+ --adam-beta2 0.95 \
191
+ --tensor-model-parallel-size ${MP_SIZE} \
192
+ --init-method-std ${INIT_STD} \
193
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
194
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
195
+ --micro-batch-size ${BATCH_SIZE} \
196
+ --exit-duration-in-mins ${EXIT_DURATION} \
197
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
198
+ --num-layers ${NUM_LAYERS} \
199
+ --hidden-size ${HIDDEN_SIZE} \
200
+ --num-attention-heads ${NUM_ATTN_HEADS} \
201
+ --seq-length ${SEQ_LEN} \
202
+ --max-position-embeddings ${SEQ_LEN} \
203
+ --train-tokens ${TRAIN_TOKENS} \
204
+ --train-samples ${TRAIN_SAMPLES} \
205
+ --lr ${LR} \
206
+ --min-lr ${MIN_LR} \
207
+ --lr-decay-style cosine \
208
+ --split 98,2,0 \
209
+ --log-interval ${LOG_INTERVAL} \
210
+ --eval-interval ${EVAL_INTERVAL} \
211
+ --eval-iters ${EVAL_ITERS} \
212
+ --save-interval ${SAVE_INTERVAL} \
213
+ --weight-decay 0.1 \
214
+ --clip-grad 1.0 \
215
+ --hysteresis 2 \
216
+ --num-workers 0 \
217
+ --fp16 \
218
+ --load ${CHECKPOINT_PATH} \
219
+ --save ${CHECKPOINT_PATH} \
220
+ --tensorboard-queue-size 1 \
221
+ --log-timers-to-tensorboard \
222
+ --log-batch-size-to-tensorboard \
223
+ --log-validation-ppl-to-tensorboard \
224
+ --tensorboard-dir ${TENSORBOARD_PATH}"
225
+
226
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
227
+ megatron_options="${megatron_options} \
228
+ --checkpoint-activations"
229
+ fi
230
+
231
+ if [ "${LOG_OPTIMIZER_STATE}" = "true" ]; then
232
+ megatron_options="${megatron_options} \
233
+ --log-optimizer-states-to-tensorboard"
234
+ fi
235
+
236
+ template_json="ds_config_gpt_TEMPLATE.json"
237
+ config_json="ds_config_${NAME}.json"
238
+ if [[ $ZERO_STAGE -gt 0 ]]; then
239
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
240
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
241
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
242
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
243
+ | sed "s/PRESCALE_GRAD/false/" \
244
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
245
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
246
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
247
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
248
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
249
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
250
+ > ${config_json}
251
+ else
252
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
253
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
254
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
255
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
256
+ | sed "s/PRESCALE_GRAD/true/" \
257
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
258
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
259
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
260
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
261
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
262
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
263
+ > ${config_json}
264
+ fi
265
+
266
+ deepspeed_options=" \
267
+ --deepspeed \
268
+ --deepspeed_config ${config_json} \
269
+ --zero-stage ${ZERO_STAGE} \
270
+ --pipeline-model-parallel-size ${PP_SIZE}"
271
+
272
+ if [[ "${NO_PP}" = "true" ]]; then
273
+ deepspeed_options="${deepspeed_options} \
274
+ --no-pipeline-parallel"
275
+ fi
276
+
277
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
278
+ deepspeed_options="${deepspeed_options} \
279
+ --deepspeed-activation-checkpointing"
280
+ fi
281
+
282
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${LOG_PATH}/${NAME}_${host}_${current_time}.log"
283
+ echo ${run_cmd}
284
+ eval ${run_cmd}
285
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_125M_MoE64.sh ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ MODEL_SIZE=0.125
14
+ NUM_LAYERS=12
15
+ HIDDEN_SIZE=768
16
+ NUM_ATTN_HEADS=12
17
+ GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ # MODEL_SIZE=1.3
41
+ # NUM_LAYERS=24
42
+ # HIDDEN_SIZE=2048
43
+ # NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_ITERS is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_ITERS.
95
+ TRAIN_ITERS=$(( ${TRAIN_TOKENS} * 3 / ${GLOBAL_BATCH_SIZE} / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ # LR_DECAY_TOKENS=260000000000
108
+ LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
124
+ NUM_GPUS_PERNODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
125
+ NUM_NODE=$(( ${NUM_GPUS} / ${NUM_GPUS_PERNODE} ))
126
+ ###############################################################################
127
+ ### MoE configs
128
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
129
+ # EP_SIZE=1
130
+ EP_SIZE=64
131
+
132
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
133
+ EP_PARALLEL_SIZE=$NUM_GPUS
134
+ else
135
+ EP_PARALLEL_SIZE=$EP_SIZE
136
+ fi
137
+
138
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
139
+ ## found that lower LR and min LR (than the base dense model) helps.
140
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
141
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
142
+ ## heavily tuned.
143
+ LR=4.5e-4
144
+ MIN_LR=4.5e-06
145
+
146
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
147
+ ## 1.3B MoE-128 model
148
+ MLC=0.01
149
+
150
+ ## Below configs adjust the MoE expert token capacity limit during training and
151
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
152
+ ## Larger capacity factor or disabling capacity limit could improve training
153
+ ## convergence, but will also reduce training throughput.
154
+ MOE_TRAIN_CAP_FACTOR=1.0
155
+ MOE_EVAL_CAP_FACTOR=1.0
156
+ MOE_MIN_CAP=4
157
+ MOE_DROP_TOKEN="true"
158
+ # MOE_DROP_TOKEN="false"
159
+ ###############################################################################
160
+ ### Curriculum learning (CL) configs
161
+ ## Enable/disable CL
162
+ CL_ENABLED="false"
163
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
164
+ ## for tuning the following configs
165
+ CL_START_SEQLEN=80
166
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
167
+ CL_TOKENS=60
168
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
169
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
170
+ ###############################################################################
171
+ ### Misc configs
172
+ LOG_INTERVAL=10
173
+ EVAL_ITERS=10
174
+ EVAL_INTERVAL=100
175
+ SAVE_INTERVAL=10000
176
+
177
+ ## Standard deviation for weight initialization
178
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
179
+ ## dense model. Usually larger model needs lower std.
180
+ INIT_STD=0.014
181
+ # INIT_STD=0.01
182
+
183
+ ## Activation checkpointing saves GPU memory, but reduces training speed
184
+ ACTIVATION_CHECKPOINT="true"
185
+ # ACTIVATION_CHECKPOINT="false"
186
+ ###############################################################################
187
+ ### Output and data configs
188
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
189
+ host="${HOSTNAME}"
190
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
191
+ if [[ $EP_SIZE -gt 1 ]]; then
192
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
193
+ fi
194
+ if [ "${CL_ENABLED}" = "true" ]; then
195
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
196
+ fi
197
+
198
+ OUTPUT_BASEPATH=$DIR/output
199
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
200
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
201
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
202
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
203
+ mkdir -p ${TENSORBOARD_DIR}
204
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
205
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
206
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
207
+
208
+ # USE_INTERNAL_DATA="true"
209
+ USE_INTERNAL_DATA="false"
210
+
211
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
212
+ ## The internal data is only accessible within Microsoft
213
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
214
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
215
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
216
+ ## For cluster Lab-RR1-V100
217
+ BASE_DATA_PATH=/data/Megatron-LM/data
218
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
219
+ ## For cluster Azure-CentralUS-A100
220
+ # BASE_DATA_PATH=/data/Megatron-LM/data
221
+ # DATA_HOME=/vc_data_1/users/amawa/blended
222
+
223
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
224
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
225
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
226
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
227
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
228
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
229
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
230
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
231
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
232
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
233
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
234
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
235
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
236
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
237
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
238
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
239
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
240
+ DATA_PATH="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
241
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
242
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
243
+ 0.01359 ${ARX} 0.01588 ${GIT}"
244
+ else
245
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
246
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
247
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
248
+ # For cluster Azure-EastUS-V100-32GB-4, Lab-RR1-V100
249
+ DATA_PATH=/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing/pile_text_document
250
+ # For cluster Azure-WestUS3-A100
251
+ # DATA_PATH=/blob/data/the_pile_public_merged_nopreprocessing/pile_text_document
252
+ fi
253
+ ###############################################################################
254
+ data_options=" \
255
+ --vocab-file ${VOCAB_PATH} \
256
+ --merge-file ${MERGE_PATH} \
257
+ --data-path ${DATA_PATH} \
258
+ --data-impl mmap"
259
+
260
+ megatron_options=" \
261
+ --override-lr-scheduler \
262
+ --adam-beta1 0.9 \
263
+ --adam-beta2 0.95 \
264
+ --tensor-model-parallel-size ${MP_SIZE} \
265
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
266
+ --num-experts ${EP_SIZE} \
267
+ --moe-loss-coeff ${MLC} \
268
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
269
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
270
+ --moe-min-capacity ${MOE_MIN_CAP} \
271
+ --init-method-std ${INIT_STD} \
272
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
273
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
274
+ --micro-batch-size ${BATCH_SIZE} \
275
+ --exit-duration-in-mins ${EXIT_DURATION} \
276
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
277
+ --num-layers ${NUM_LAYERS} \
278
+ --hidden-size ${HIDDEN_SIZE} \
279
+ --num-attention-heads ${NUM_ATTN_HEADS} \
280
+ --seq-length ${SEQ_LEN} \
281
+ --max-position-embeddings ${SEQ_LEN} \
282
+ --train-tokens ${TRAIN_TOKENS} \
283
+ --train-iters ${TRAIN_ITERS} \
284
+ --lr ${LR} \
285
+ --min-lr ${MIN_LR} \
286
+ --lr-decay-style cosine \
287
+ --split 98,2,0 \
288
+ --log-interval ${LOG_INTERVAL} \
289
+ --eval-interval ${EVAL_INTERVAL} \
290
+ --eval-iters ${EVAL_ITERS} \
291
+ --save-interval ${SAVE_INTERVAL} \
292
+ --weight-decay 0.1 \
293
+ --clip-grad 1.0 \
294
+ --hysteresis 2 \
295
+ --num-workers 0 \
296
+ --fp16 \
297
+ --load ${CHECKPOINT_PATH} \
298
+ --save ${CHECKPOINT_PATH} \
299
+ --tensorboard-queue-size 1 \
300
+ --log-timers-to-tensorboard \
301
+ --log-batch-size-to-tensorboard \
302
+ --log-validation-ppl-to-tensorboard \
303
+ --tensorboard-dir ${TENSORBOARD_DIR}"
304
+
305
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
306
+ megatron_options="${megatron_options} \
307
+ --checkpoint-activations"
308
+ fi
309
+
310
+ if [[ $EP_SIZE -gt 1 ]]; then
311
+ megatron_options="${megatron_options} \
312
+ --create-moe-param-group"
313
+ fi
314
+
315
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
316
+ megatron_options="${megatron_options} \
317
+ --disable-moe-token-dropping"
318
+ fi
319
+
320
+ template_json="ds_config_gpt_TEMPLATE.json"
321
+ config_json="ds_config_gpt_${NAME}.json"
322
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
323
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
324
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
325
+ | sed "s/ZERO_STAGE/0/" \
326
+ | sed "s/PRESCALE_GRAD/true/" \
327
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
328
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
329
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
330
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
331
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
332
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
333
+ > ${config_json}
334
+
335
+ deepspeed_options=" \
336
+ --deepspeed \
337
+ --deepspeed_config ${config_json} \
338
+ --pipeline-model-parallel-size ${PP_SIZE}"
339
+
340
+ # Currently MoE is not compatible with pipeline parallel
341
+ if [[ $EP_SIZE -gt 1 ]]; then
342
+ deepspeed_options="${deepspeed_options} \
343
+ --no-pipeline-parallel"
344
+ fi
345
+
346
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
347
+ deepspeed_options="${deepspeed_options} \
348
+ --deepspeed-activation-checkpointing"
349
+ fi
350
+
351
+ ## When saving checkpoint to a storage with cache, their could be consistency
352
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
353
+ ## and broadcast it to all nodes.
354
+ ITERATION_FILE="$CHECKPOINT_PATH/latest_checkpointed_iteration.txt"
355
+ ITERATION_FILE_2="$CHECKPOINT_PATH/latest"
356
+ ITERATION=0
357
+ for (( node = 0; node <= NUM_NODE-1; node++ ))
358
+ do
359
+ if $(ssh -q worker-"$node" "test -f \"$ITERATION_FILE\""); then
360
+ LOCAL_ITERATION=$(ssh -q worker-"$node" cat $ITERATION_FILE)
361
+ ITERATION=$(( ${LOCAL_ITERATION} > ${ITERATION} ? ${LOCAL_ITERATION} : ${ITERATION} ))
362
+ fi
363
+ done
364
+ if [[ $ITERATION -gt 0 ]]; then
365
+ ITERATION_2="global_step${ITERATION}"
366
+ ds_ssh "echo $ITERATION > $ITERATION_FILE"
367
+ ds_ssh "echo $ITERATION_2 > $ITERATION_FILE_2"
368
+ fi
369
+
370
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
371
+ echo ${run_cmd}
372
+ eval ${run_cmd}
373
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_125M_dense_cl.sh ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ MODEL_SIZE=0.125
14
+ NUM_LAYERS=12
15
+ HIDDEN_SIZE=768
16
+ NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ MIN_LR=6.0e-5
20
+
21
+ # Curriculum learning (CL) enables stable large-batch training
22
+ GLOBAL_BATCH_SIZE=2048 # 8x
23
+ LR=2.4e-3 # 4x
24
+
25
+ ## GPT-3 Medium 350M
26
+ # MODEL_SIZE=0.35
27
+ # NUM_LAYERS=24
28
+ # HIDDEN_SIZE=1024
29
+ # NUM_ATTN_HEADS=16
30
+ # GLOBAL_BATCH_SIZE=256
31
+ # LR=3.0e-4
32
+ # MIN_LR=3.0e-5
33
+
34
+ ## GPT-3 Large 760M
35
+ # MODEL_SIZE=0.76
36
+ # NUM_LAYERS=24
37
+ # HIDDEN_SIZE=1536
38
+ # NUM_ATTN_HEADS=16
39
+ # GLOBAL_BATCH_SIZE=256
40
+ # LR=2.5e-4
41
+ # MIN_LR=2.5e-5
42
+
43
+ ## GPT-3 XL 1.3B
44
+ # MODEL_SIZE=1.3
45
+ # NUM_LAYERS=24
46
+ # HIDDEN_SIZE=2048
47
+ # NUM_ATTN_HEADS=16
48
+ # GLOBAL_BATCH_SIZE=512
49
+ # LR=2.0e-4
50
+ # MIN_LR=2.0e-5
51
+
52
+ ## GPT-3 2.7B
53
+ # MODEL_SIZE=2.7
54
+ # NUM_LAYERS=32
55
+ # HIDDEN_SIZE=2560
56
+ # NUM_ATTN_HEADS=32
57
+ # GLOBAL_BATCH_SIZE=512
58
+ # LR=1.6e-4
59
+ # MIN_LR=1.6e-5
60
+
61
+ ## GPT-3 6.7B
62
+ # MODEL_SIZE=6.7
63
+ # NUM_LAYERS=32
64
+ # HIDDEN_SIZE=4096
65
+ # NUM_ATTN_HEADS=32
66
+ # GLOBAL_BATCH_SIZE=1024
67
+ # LR=1.2e-4
68
+ # MIN_LR=1.2e-5
69
+
70
+ ## GPT-3 13B
71
+ # MODEL_SIZE=13
72
+ # NUM_LAYERS=40
73
+ # HIDDEN_SIZE=5120
74
+ # NUM_ATTN_HEADS=40
75
+ # GLOBAL_BATCH_SIZE=1024
76
+ # LR=1.0e-4
77
+ # MIN_LR=1.0e-5
78
+
79
+ ## GPT-3 175B
80
+ # MODEL_SIZE=175
81
+ # NUM_LAYERS=96
82
+ # HIDDEN_SIZE=12288
83
+ # NUM_ATTN_HEADS=96
84
+ # GLOBAL_BATCH_SIZE=1536
85
+ # LR=0.6e-4
86
+ # MIN_LR=0.6e-5
87
+ ###############################################################################
88
+ ### Training duration configs
89
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
90
+ TRAIN_TOKENS=300000000000
91
+
92
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
93
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
94
+ ## above, and techniques like curriculum learning has less token in some samples,
95
+ ## so we just set this config large enough to make sure we have enough
96
+ ## processed data and don't terminate by TRAIN_SAMPLES.
97
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
98
+
99
+ ## Another termination condition in minutes. Set it large enough to avoid
100
+ ## undesired early termination.
101
+ EXIT_DURATION=30000000
102
+ ###############################################################################
103
+ ### LR configs
104
+ ## LR warmup and decay duration, this token-based config is preferable since
105
+ ## no need to readjust when the batch size/seqlen is changed.
106
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
107
+ WARMUP_TOKENS=375000000
108
+ LR_DECAY_TOKENS=260000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=16
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism. To disable PP, set PP_SIZE to 1 and NO_PP to true.
119
+ PP_SIZE=1
120
+ NO_PP="true"
121
+
122
+ ## ZeRO stage
123
+ ZERO_STAGE=0
124
+
125
+ ## Total number of GPUs
126
+ NUM_GPUS=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
127
+ NUM_GPUS_PERNODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
128
+ NUM_NODE=$(( ${NUM_GPUS} / ${NUM_GPUS_PERNODE} ))
129
+ DP_SIZE=$(( ${NUM_GPUS} / ${PP_SIZE} / ${MP_SIZE} ))
130
+ ###############################################################################
131
+ ### Curriculum learning (CL) configs
132
+ ## Enable/disable CL
133
+ CL_ENABLED="true"
134
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
135
+ ## for tuning the following configs
136
+ CL_START_SEQLEN=72
137
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
138
+ CL_TOKENS=60
139
+ CL_STEP=$(( ${CL_TOKENS} * 1000000000 / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
140
+ ###############################################################################
141
+ ### Misc configs
142
+ LOG_INTERVAL=10
143
+ EVAL_ITERS=10
144
+ EVAL_INTERVAL=100
145
+ SAVE_INTERVAL=1000
146
+
147
+ ## Standard deviation for weight initialization. Usually larger model needs
148
+ ## lower std. We used a heuristic equation of sqrt(1/3/HIDDEN_SIZE) from the
149
+ ## MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
150
+ INIT_STD=0.02
151
+
152
+ ## Activation checkpointing saves GPU memory, but reduces training speed
153
+ ACTIVATION_CHECKPOINT="true"
154
+ # ACTIVATION_CHECKPOINT="false"
155
+
156
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
157
+ ## This is not required for training and might save GPU memory when turned off.
158
+ LOG_OPTIMIZER_STATE="true"
159
+ ###############################################################################
160
+ ### Output and data configs
161
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
162
+ host="${HOSTNAME}"
163
+ NAME="gpt3-with-pile-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-zero-${ZERO_STAGE}-mp-${MP_SIZE}-pp-${PP_SIZE}"
164
+ if [ "${NO_PP}" = "true" ]; then
165
+ NAME="${NAME}-no_pp"
166
+ fi
167
+ if [ "${CL_ENABLED}" = "true" ]; then
168
+ NAME="${NAME}-cl-startseqlen-${CL_START_SEQLEN}-step-${CL_STEP}-token-${CL_TOKENS}B"
169
+ fi
170
+
171
+ LOG_PATH="log/"
172
+ TENSORBOARD_PATH="tensorboard/${NAME}_${host}_${current_time}"
173
+ CHECKPOINT_PATH="/blob/users/conglli/project/gpt3_with_pile/checkpoint/${NAME}"
174
+ mkdir -p ${LOG_PATH}
175
+ mkdir -p ${TENSORBOARD_PATH}
176
+ mkdir -p ${CHECKPOINT_PATH}
177
+
178
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
179
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
180
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
181
+ # For cluster Azure-EastUS-V100-32GB-4, Lab-RR1-V100
182
+ DATA_PATH=/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing/pile_text_document
183
+ # For cluster Azure-WestUS3-A100
184
+ # DATA_PATH=/blob/data/the_pile_public_merged_nopreprocessing/pile_text_document
185
+ ###############################################################################
186
+ data_options=" \
187
+ --vocab-file ${VOCAB_PATH} \
188
+ --merge-file ${MERGE_PATH} \
189
+ --data-path ${DATA_PATH} \
190
+ --data-impl mmap"
191
+
192
+ megatron_options=" \
193
+ --override-lr-scheduler \
194
+ --adam-beta1 0.9 \
195
+ --adam-beta2 0.95 \
196
+ --tensor-model-parallel-size ${MP_SIZE} \
197
+ --init-method-std ${INIT_STD} \
198
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
199
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
200
+ --micro-batch-size ${BATCH_SIZE} \
201
+ --exit-duration-in-mins ${EXIT_DURATION} \
202
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
203
+ --num-layers ${NUM_LAYERS} \
204
+ --hidden-size ${HIDDEN_SIZE} \
205
+ --num-attention-heads ${NUM_ATTN_HEADS} \
206
+ --seq-length ${SEQ_LEN} \
207
+ --max-position-embeddings ${SEQ_LEN} \
208
+ --train-tokens ${TRAIN_TOKENS} \
209
+ --train-samples ${TRAIN_SAMPLES} \
210
+ --lr ${LR} \
211
+ --min-lr ${MIN_LR} \
212
+ --lr-decay-style cosine \
213
+ --split 98,2,0 \
214
+ --log-interval ${LOG_INTERVAL} \
215
+ --eval-interval ${EVAL_INTERVAL} \
216
+ --eval-iters ${EVAL_ITERS} \
217
+ --save-interval ${SAVE_INTERVAL} \
218
+ --weight-decay 0.1 \
219
+ --clip-grad 1.0 \
220
+ --hysteresis 2 \
221
+ --num-workers 0 \
222
+ --fp16 \
223
+ --load ${CHECKPOINT_PATH} \
224
+ --save ${CHECKPOINT_PATH} \
225
+ --tensorboard-queue-size 1 \
226
+ --log-timers-to-tensorboard \
227
+ --log-batch-size-to-tensorboard \
228
+ --log-validation-ppl-to-tensorboard \
229
+ --tensorboard-dir ${TENSORBOARD_PATH}"
230
+
231
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
232
+ megatron_options="${megatron_options} \
233
+ --checkpoint-activations"
234
+ fi
235
+
236
+ if [ "${LOG_OPTIMIZER_STATE}" = "true" ]; then
237
+ megatron_options="${megatron_options} \
238
+ --log-optimizer-states-to-tensorboard"
239
+ fi
240
+
241
+ template_json="ds_config_gpt_TEMPLATE.json"
242
+ config_json="ds_config_${NAME}.json"
243
+ if [[ $ZERO_STAGE -gt 0 ]]; then
244
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
245
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
246
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
247
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
248
+ | sed "s/PRESCALE_GRAD/false/" \
249
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
250
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
251
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
252
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
253
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
254
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
255
+ > ${config_json}
256
+ else
257
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
258
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
259
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
260
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
261
+ | sed "s/PRESCALE_GRAD/true/" \
262
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
263
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
264
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
265
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
266
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
267
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
268
+ > ${config_json}
269
+ fi
270
+
271
+ deepspeed_options=" \
272
+ --deepspeed \
273
+ --deepspeed_config ${config_json} \
274
+ --zero-stage ${ZERO_STAGE} \
275
+ --pipeline-model-parallel-size ${PP_SIZE}"
276
+
277
+ if [[ "${NO_PP}" = "true" ]]; then
278
+ deepspeed_options="${deepspeed_options} \
279
+ --no-pipeline-parallel"
280
+ fi
281
+
282
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
283
+ deepspeed_options="${deepspeed_options} \
284
+ --deepspeed-activation-checkpointing"
285
+ fi
286
+
287
+ ## When saving checkpoint to a storage with cache, their could be consistency
288
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
289
+ ## and broadcast it to all nodes.
290
+ ITERATION_FILE="$CHECKPOINT_PATH/latest_checkpointed_iteration.txt"
291
+ ITERATION_FILE_2="$CHECKPOINT_PATH/latest"
292
+ ITERATION=0
293
+ for (( node = 0; node <= NUM_NODE-1; node++ ))
294
+ do
295
+ if $(ssh -q worker-"$node" "test -f \"$ITERATION_FILE\""); then
296
+ LOCAL_ITERATION=$(ssh -q worker-"$node" cat $ITERATION_FILE)
297
+ ITERATION=$(( ${LOCAL_ITERATION} > ${ITERATION} ? ${LOCAL_ITERATION} : ${ITERATION} ))
298
+ fi
299
+ done
300
+ if [[ $ITERATION -gt 0 ]]; then
301
+ ITERATION_2="global_step${ITERATION}"
302
+ ds_ssh "echo $ITERATION > $ITERATION_FILE"
303
+ ds_ssh "echo $ITERATION_2 > $ITERATION_FILE_2"
304
+ fi
305
+
306
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${LOG_PATH}/${NAME}_${host}_${current_time}.log"
307
+ echo ${run_cmd}
308
+ eval ${run_cmd}
309
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_MoE128.sh ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ MODEL_SIZE=0.35
23
+ NUM_LAYERS=24
24
+ HIDDEN_SIZE=1024
25
+ NUM_ATTN_HEADS=16
26
+ GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ # MODEL_SIZE=1.3
41
+ # NUM_LAYERS=24
42
+ # HIDDEN_SIZE=2048
43
+ # NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_ITERS is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_ITERS.
95
+ TRAIN_ITERS=$(( ${TRAIN_TOKENS} * 3 / ${GLOBAL_BATCH_SIZE} / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ # LR_DECAY_TOKENS=260000000000
108
+ LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
127
+ # EP_SIZE=1
128
+ EP_SIZE=128
129
+
130
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+ else
133
+ EP_PARALLEL_SIZE=$EP_SIZE
134
+ fi
135
+
136
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
137
+ ## found that lower LR and min LR (than the base dense model) helps.
138
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
139
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
140
+ ## heavily tuned.
141
+ LR=2.0e-4
142
+ MIN_LR=2e-06
143
+
144
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
145
+ ## 1.3B MoE-128 model
146
+ MLC=0.01
147
+
148
+ ## Below configs adjust the MoE expert token capacity limit during training and
149
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
150
+ ## Larger capacity factor or disabling capacity limit could improve training
151
+ ## convergence, but will also reduce training throughput.
152
+ MOE_TRAIN_CAP_FACTOR=1.0
153
+ MOE_EVAL_CAP_FACTOR=1.0
154
+ MOE_MIN_CAP=4
155
+ MOE_DROP_TOKEN="true"
156
+ # MOE_DROP_TOKEN="false"
157
+ ###############################################################################
158
+ ### Curriculum learning (CL) configs
159
+ ## Enable/disable CL
160
+ CL_ENABLED="false"
161
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
162
+ ## for tuning the following configs
163
+ CL_START_SEQLEN=80
164
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
165
+ CL_TOKENS=60
166
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
167
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
168
+ ###############################################################################
169
+ ### Misc configs
170
+ LOG_INTERVAL=10
171
+ EVAL_ITERS=10
172
+ EVAL_INTERVAL=100
173
+ SAVE_INTERVAL=10000
174
+
175
+ ## Standard deviation for weight initialization
176
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
177
+ ## dense model. Usually larger model needs lower std.
178
+ INIT_STD=0.014
179
+ # INIT_STD=0.01
180
+
181
+ ## Activation checkpointing saves GPU memory, but reduces training speed
182
+ ACTIVATION_CHECKPOINT="true"
183
+ # ACTIVATION_CHECKPOINT="false"
184
+ ###############################################################################
185
+ ### Output and data configs
186
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
187
+ host="${HOSTNAME}"
188
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
189
+ if [[ $EP_SIZE -gt 1 ]]; then
190
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
191
+ fi
192
+ if [ "${CL_ENABLED}" = "true" ]; then
193
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
194
+ fi
195
+
196
+ OUTPUT_BASEPATH=$DIR/output
197
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
199
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
200
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
201
+ mkdir -p ${TENSORBOARD_DIR}
202
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
203
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
204
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+
206
+ # USE_INTERNAL_DATA="true"
207
+ USE_INTERNAL_DATA="false"
208
+
209
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
210
+ ## The internal data is only accessible within Microsoft
211
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
212
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
213
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
214
+ ## For cluster Lab-RR1-V100
215
+ BASE_DATA_PATH=/data/Megatron-LM/data
216
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
217
+ ## For cluster Azure-CentralUS-A100
218
+ # BASE_DATA_PATH=/data/Megatron-LM/data
219
+ # DATA_HOME=/vc_data_1/users/amawa/blended
220
+
221
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
222
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
223
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
224
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
225
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
226
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
227
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
228
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
229
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
230
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
231
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
232
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
233
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
234
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
235
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
236
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
237
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
238
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
239
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
240
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
241
+ 0.01359 ${ARX} 0.01588 ${GIT}"
242
+ else
243
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
244
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
245
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
246
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
247
+ fi
248
+ ###############################################################################
249
+ data_options=" \
250
+ --vocab-file ${VOCAB_PATH} \
251
+ --merge-file ${MERGE_PATH} \
252
+ --data-path ${DATA_BLEND} \
253
+ --data-impl mmap"
254
+
255
+ megatron_options=" \
256
+ --override-lr-scheduler \
257
+ --adam-beta1 0.9 \
258
+ --adam-beta2 0.95 \
259
+ --tensor-model-parallel-size ${MP_SIZE} \
260
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
261
+ --num-experts ${EP_SIZE} \
262
+ --moe-loss-coeff ${MLC} \
263
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
264
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
265
+ --moe-min-capacity ${MOE_MIN_CAP} \
266
+ --init-method-std ${INIT_STD} \
267
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
268
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
269
+ --micro-batch-size ${BATCH_SIZE} \
270
+ --exit-duration-in-mins ${EXIT_DURATION} \
271
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
272
+ --num-layers ${NUM_LAYERS} \
273
+ --hidden-size ${HIDDEN_SIZE} \
274
+ --num-attention-heads ${NUM_ATTN_HEADS} \
275
+ --seq-length ${SEQ_LEN} \
276
+ --max-position-embeddings ${SEQ_LEN} \
277
+ --train-tokens ${TRAIN_TOKENS} \
278
+ --train-iters ${TRAIN_ITERS} \
279
+ --lr ${LR} \
280
+ --min-lr ${MIN_LR} \
281
+ --lr-decay-style cosine \
282
+ --split 98,2,0 \
283
+ --log-interval ${LOG_INTERVAL} \
284
+ --eval-interval ${EVAL_INTERVAL} \
285
+ --eval-iters ${EVAL_ITERS} \
286
+ --save-interval ${SAVE_INTERVAL} \
287
+ --weight-decay 0.1 \
288
+ --clip-grad 1.0 \
289
+ --hysteresis 2 \
290
+ --num-workers 0 \
291
+ --fp16 \
292
+ --load ${CHECKPOINT_PATH} \
293
+ --save ${CHECKPOINT_PATH} \
294
+ --tensorboard-queue-size 1 \
295
+ --log-timers-to-tensorboard \
296
+ --log-batch-size-to-tensorboard \
297
+ --log-validation-ppl-to-tensorboard \
298
+ --tensorboard-dir ${TENSORBOARD_DIR}"
299
+
300
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
301
+ megatron_options="${megatron_options} \
302
+ --checkpoint-activations"
303
+ fi
304
+
305
+ if [[ $EP_SIZE -gt 1 ]]; then
306
+ megatron_options="${megatron_options} \
307
+ --create-moe-param-group"
308
+ fi
309
+
310
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
311
+ megatron_options="${megatron_options} \
312
+ --disable-moe-token-dropping"
313
+ fi
314
+
315
+ template_json="ds_config_gpt_TEMPLATE.json"
316
+ config_json="ds_config_gpt_${NAME}.json"
317
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
318
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
319
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
320
+ | sed "s/ZERO_STAGE/0/" \
321
+ | sed "s/PRESCALE_GRAD/true/" \
322
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
323
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
324
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
325
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
326
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
327
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
328
+ > ${config_json}
329
+
330
+ deepspeed_options=" \
331
+ --deepspeed \
332
+ --deepspeed_config ${config_json} \
333
+ --pipeline-model-parallel-size ${PP_SIZE}"
334
+
335
+ # Currently MoE is not compatible with pipeline parallel
336
+ if [[ $EP_SIZE -gt 1 ]]; then
337
+ deepspeed_options="${deepspeed_options} \
338
+ --no-pipeline-parallel"
339
+ fi
340
+
341
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
342
+ deepspeed_options="${deepspeed_options} \
343
+ --deepspeed-activation-checkpointing"
344
+ fi
345
+
346
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
347
+ echo ${run_cmd}
348
+ eval ${run_cmd}
349
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_PR-MoE32or64.sh ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ MODEL_SIZE=0.35
23
+ NUM_LAYERS=24
24
+ HIDDEN_SIZE=1024
25
+ NUM_ATTN_HEADS=16
26
+ GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ # MODEL_SIZE=1.3
41
+ # NUM_LAYERS=24
42
+ # HIDDEN_SIZE=2048
43
+ # NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_ITERS is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_ITERS.
95
+ TRAIN_ITERS=$(( ${TRAIN_TOKENS} * 3 / ${GLOBAL_BATCH_SIZE} / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ # LR_DECAY_TOKENS=260000000000
108
+ LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 128 means standard MoE
127
+ # EP_SIZE=128
128
+ EP_SIZE="32 32 32 32 32 32 32 32 32 32 64 64"
129
+
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+
132
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
133
+ ## found that lower LR and min LR (than the base dense model) helps.
134
+ ## For 1.3B PR-MoE-64/128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
135
+ ## For 350M PR-MoE-32/64 model we used LR=3.0e-4 and MIN_LR=1.0e-6, but they are not
136
+ ## heavily tuned.
137
+ LR=3.0e-4
138
+ MIN_LR=1.0e-06
139
+
140
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
141
+ ## 1.3B MoE-128 model
142
+ MLC=0.01
143
+
144
+ ## Below configs adjust the MoE expert token capacity limit during training and
145
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
146
+ ## Larger capacity factor or disabling capacity limit could improve training
147
+ ## convergence, but will also reduce training throughput.
148
+ MOE_TRAIN_CAP_FACTOR=1.0
149
+ MOE_EVAL_CAP_FACTOR=1.0
150
+ MOE_MIN_CAP=4
151
+ MOE_DROP_TOKEN="true"
152
+ # MOE_DROP_TOKEN="false"
153
+ ###############################################################################
154
+ ### Curriculum learning (CL) configs
155
+ ## Enable/disable CL
156
+ CL_ENABLED="false"
157
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
158
+ ## for tuning the following configs
159
+ CL_START_SEQLEN=80
160
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
161
+ CL_TOKENS=60
162
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
163
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
164
+ ###############################################################################
165
+ ### Misc configs
166
+ LOG_INTERVAL=10
167
+ EVAL_ITERS=10
168
+ EVAL_INTERVAL=100
169
+ SAVE_INTERVAL=10000
170
+
171
+ ## Standard deviation for weight initialization
172
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
173
+ ## dense model. Usually larger model needs lower std.
174
+ INIT_STD=0.014
175
+ # INIT_STD=0.01
176
+
177
+ ## Activation checkpointing saves GPU memory, but reduces training speed
178
+ ACTIVATION_CHECKPOINT="true"
179
+ # ACTIVATION_CHECKPOINT="false"
180
+ ###############################################################################
181
+ ### Output and data configs
182
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
183
+ host="${HOSTNAME}"
184
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
185
+ NAME="${NAME}-ep-pyramid-32+64-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
186
+
187
+ if [ "${CL_ENABLED}" = "true" ]; then
188
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
189
+ fi
190
+
191
+ OUTPUT_BASEPATH=$DIR/output
192
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
193
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
194
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
195
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
196
+ mkdir -p ${TENSORBOARD_DIR}
197
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
198
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
199
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
200
+
201
+ # USE_INTERNAL_DATA="true"
202
+ USE_INTERNAL_DATA="false"
203
+
204
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
205
+ ## The internal data is only accessible within Microsoft
206
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
207
+ BASE_DATA_PATH=/vc_data/Megatron-LM/data
208
+ DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
209
+ ## For cluster Lab-RR1-V100
210
+ # BASE_DATA_PATH=/data/Megatron-LM/data
211
+ # DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
212
+ ## For cluster Azure-CentralUS-A100
213
+ # BASE_DATA_PATH=/data/Megatron-LM/data
214
+ # DATA_HOME=/vc_data_1/users/amawa/blended
215
+
216
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
217
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
218
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
219
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
220
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
221
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
222
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
223
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
224
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
225
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
226
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
227
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
228
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
229
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
230
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
231
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
232
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
233
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
234
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
235
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
236
+ 0.01359 ${ARX} 0.01588 ${GIT}"
237
+ else
238
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
239
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
240
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
241
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
242
+ fi
243
+ ###############################################################################
244
+ data_options=" \
245
+ --vocab-file ${VOCAB_PATH} \
246
+ --merge-file ${MERGE_PATH} \
247
+ --data-path ${DATA_BLEND} \
248
+ --data-impl mmap"
249
+
250
+ megatron_options=" \
251
+ --override-lr-scheduler \
252
+ --adam-beta1 0.9 \
253
+ --adam-beta2 0.95 \
254
+ --tensor-model-parallel-size ${MP_SIZE} \
255
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
256
+ --num-experts ${EP_SIZE} \
257
+ --moe-loss-coeff ${MLC} \
258
+ --mlp-type residual \
259
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
260
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
261
+ --moe-min-capacity ${MOE_MIN_CAP} \
262
+ --init-method-std ${INIT_STD} \
263
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
264
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
265
+ --micro-batch-size ${BATCH_SIZE} \
266
+ --exit-duration-in-mins ${EXIT_DURATION} \
267
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
268
+ --num-layers ${NUM_LAYERS} \
269
+ --hidden-size ${HIDDEN_SIZE} \
270
+ --num-attention-heads ${NUM_ATTN_HEADS} \
271
+ --seq-length ${SEQ_LEN} \
272
+ --max-position-embeddings ${SEQ_LEN} \
273
+ --train-tokens ${TRAIN_TOKENS} \
274
+ --train-iters ${TRAIN_ITERS} \
275
+ --lr ${LR} \
276
+ --min-lr ${MIN_LR} \
277
+ --lr-decay-style cosine \
278
+ --split 98,2,0 \
279
+ --log-interval ${LOG_INTERVAL} \
280
+ --eval-interval ${EVAL_INTERVAL} \
281
+ --eval-iters ${EVAL_ITERS} \
282
+ --save-interval ${SAVE_INTERVAL} \
283
+ --weight-decay 0.1 \
284
+ --clip-grad 1.0 \
285
+ --hysteresis 2 \
286
+ --num-workers 0 \
287
+ --fp16 \
288
+ --load ${CHECKPOINT_PATH} \
289
+ --save ${CHECKPOINT_PATH} \
290
+ --tensorboard-queue-size 1 \
291
+ --log-timers-to-tensorboard \
292
+ --log-batch-size-to-tensorboard \
293
+ --log-validation-ppl-to-tensorboard \
294
+ --tensorboard-dir ${TENSORBOARD_DIR}"
295
+
296
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
297
+ megatron_options="${megatron_options} \
298
+ --checkpoint-activations"
299
+ fi
300
+
301
+ megatron_options="${megatron_options} \
302
+ --create-moe-param-group"
303
+
304
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
305
+ megatron_options="${megatron_options} \
306
+ --disable-moe-token-dropping"
307
+ fi
308
+
309
+ template_json="ds_config_gpt_TEMPLATE.json"
310
+ config_json="ds_config_gpt_${NAME}.json"
311
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
312
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
313
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
314
+ | sed "s/ZERO_STAGE/0/" \
315
+ | sed "s/PRESCALE_GRAD/true/" \
316
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
317
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
318
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
319
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
320
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
321
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
322
+ > ${config_json}
323
+
324
+ deepspeed_options=" \
325
+ --deepspeed \
326
+ --deepspeed_config ${config_json} \
327
+ --pipeline-model-parallel-size ${PP_SIZE}"
328
+
329
+ # Currently MoE is not compatible with pipeline parallel
330
+ deepspeed_options="${deepspeed_options} \
331
+ --no-pipeline-parallel"
332
+
333
+
334
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
335
+ deepspeed_options="${deepspeed_options} \
336
+ --deepspeed-activation-checkpointing"
337
+ fi
338
+
339
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
340
+ echo ${run_cmd}
341
+ eval ${run_cmd}
342
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_PR-MoE32or64_MoS.sh ADDED
@@ -0,0 +1,354 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ MODEL_SIZE=0.35
23
+ NUM_LAYERS=24
24
+ HIDDEN_SIZE=1024
25
+ NUM_ATTN_HEADS=16
26
+ GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ # MODEL_SIZE=1.3
41
+ # NUM_LAYERS=24
42
+ # HIDDEN_SIZE=2048
43
+ # NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_ITERS is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_ITERS.
95
+ TRAIN_ITERS=$(( ${TRAIN_TOKENS} * 3 / ${GLOBAL_BATCH_SIZE} / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ # LR_DECAY_TOKENS=260000000000
108
+ LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 128 means standard MoE
127
+ # EP_SIZE=128
128
+ EP_SIZE="32 32 32 32 32 32 32 32 64 64"
129
+ EP_SIZE_TEACHER="32 32 32 32 32 32 32 32 32 32 64 64"
130
+
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+
133
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
134
+ ## found that lower LR and min LR (than the base dense model) helps.
135
+ ## For 1.3B PR-MoE-64/128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
136
+ ## For 350M PR-MoE-32/64 model we used LR=3.0e-4 and MIN_LR=1.0e-6, but they are not
137
+ ## heavily tuned.
138
+ LR=3.0e-4
139
+ MIN_LR=1.0e-06
140
+
141
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
142
+ ## 1.3B MoE-128 model
143
+ MLC=0.01
144
+
145
+ ## Below configs adjust the MoE expert token capacity limit during training and
146
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
147
+ ## Larger capacity factor or disabling capacity limit could improve training
148
+ ## convergence, but will also reduce training throughput.
149
+ MOE_TRAIN_CAP_FACTOR=1.0
150
+ MOE_EVAL_CAP_FACTOR=1.0
151
+ MOE_MIN_CAP=4
152
+ MOE_DROP_TOKEN="true"
153
+ # MOE_DROP_TOKEN="false"
154
+ ###############################################################################
155
+ ### Curriculum learning (CL) configs
156
+ ## Enable/disable CL
157
+ CL_ENABLED="false"
158
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
159
+ ## for tuning the following configs
160
+ CL_START_SEQLEN=80
161
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
162
+ CL_TOKENS=60
163
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
164
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
165
+ ###############################################################################
166
+ ### Misc configs
167
+ LOG_INTERVAL=10
168
+ EVAL_ITERS=10
169
+ EVAL_INTERVAL=100
170
+ SAVE_INTERVAL=10000
171
+
172
+ ## Standard deviation for weight initialization
173
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
174
+ ## dense model. Usually larger model needs lower std.
175
+ INIT_STD=0.014
176
+ # INIT_STD=0.01
177
+
178
+ ## Activation checkpointing saves GPU memory, but reduces training speed
179
+ ACTIVATION_CHECKPOINT="true"
180
+ # ACTIVATION_CHECKPOINT="false"
181
+ ###############################################################################
182
+ ### Output and data configs
183
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
184
+ host="${HOSTNAME}"
185
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
186
+ NAME="${NAME}-ep-pyramid-32+64-mos-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
187
+
188
+ if [ "${CL_ENABLED}" = "true" ]; then
189
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
190
+ fi
191
+
192
+ OUTPUT_BASEPATH=$DIR/output
193
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
194
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
195
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
196
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
197
+ mkdir -p ${TENSORBOARD_DIR}
198
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
199
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
200
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
201
+
202
+ ### Mixture-of-Students (MoS) configs
203
+ KD_BETA_CE=1
204
+ CHECKPOINT_PATH_STUDENT="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+ CHECKPOINT_PATH_TEACHER="${OUTPUT_BASEPATH}/checkpoint/gpt-1.3B-lr-1.2e-4-minlr-1.0e-6-bs-512-gpus-128-mp-1-pp-1-ep-pyramid-64+128-mlc-0.01-cap-1.0-drop-true/"
206
+ CHECKPOINT_PATH_SAVE="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
207
+
208
+ USE_INTERNAL_DATA="true"
209
+ # USE_INTERNAL_DATA="false"
210
+
211
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
212
+ ## The internal data is only accessible within Microsoft
213
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
214
+ BASE_DATA_PATH=/vc_data/Megatron-LM/data
215
+ DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
216
+ ## For cluster Lab-RR1-V100
217
+ # BASE_DATA_PATH=/data/Megatron-LM/data
218
+ # DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
219
+ ## For cluster Azure-CentralUS-A100
220
+ # BASE_DATA_PATH=/data/Megatron-LM/data
221
+ # DATA_HOME=/vc_data_1/users/amawa/blended
222
+
223
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
224
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
225
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
226
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
227
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
228
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
229
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
230
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
231
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
232
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
233
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
234
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
235
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
236
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
237
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
238
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
239
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
240
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
241
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
242
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
243
+ 0.01359 ${ARX} 0.01588 ${GIT}"
244
+ else
245
+ ## Placeholder, we plan to test a public dataset
246
+ VOCAB_PATH=""
247
+ MERGE_PATH=""
248
+ DATA_BLEND=""
249
+ fi
250
+ ###############################################################################
251
+ data_options=" \
252
+ --vocab-file ${VOCAB_PATH} \
253
+ --merge-file ${MERGE_PATH} \
254
+ --data-path ${DATA_BLEND} \
255
+ --data-impl mmap"
256
+
257
+ megatron_options=" \
258
+ --override-lr-scheduler \
259
+ --adam-beta1 0.9 \
260
+ --adam-beta2 0.95 \
261
+ --tensor-model-parallel-size ${MP_SIZE} \
262
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
263
+ --num-experts ${EP_SIZE} \
264
+ --moe-loss-coeff ${MLC} \
265
+ --mlp-type residual \
266
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
267
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
268
+ --moe-min-capacity ${MOE_MIN_CAP} \
269
+ --init-method-std ${INIT_STD} \
270
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
271
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
272
+ --micro-batch-size ${BATCH_SIZE} \
273
+ --exit-duration-in-mins ${EXIT_DURATION} \
274
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
275
+ --num-layers 21 \
276
+ --hidden-size ${HIDDEN_SIZE} \
277
+ --num-attention-heads ${NUM_ATTN_HEADS} \
278
+ --seq-length ${SEQ_LEN} \
279
+ --max-position-embeddings ${SEQ_LEN} \
280
+ --train-tokens ${TRAIN_TOKENS} \
281
+ --train-iters ${TRAIN_ITERS} \
282
+ --lr ${LR} \
283
+ --min-lr ${MIN_LR} \
284
+ --lr-decay-style cosine \
285
+ --split 98,2,0 \
286
+ --log-interval ${LOG_INTERVAL} \
287
+ --eval-interval ${EVAL_INTERVAL} \
288
+ --eval-iters ${EVAL_ITERS} \
289
+ --save-interval ${SAVE_INTERVAL} \
290
+ --weight-decay 0.1 \
291
+ --clip-grad 1.0 \
292
+ --hysteresis 2 \
293
+ --num-workers 0 \
294
+ --fp16 \
295
+ --load ${CHECKPOINT_PATH_STUDENT} \
296
+ --save ${CHECKPOINT_PATH_SAVE} \
297
+ --mos \
298
+ --kd-beta-ce ${KD_BETA_CE} \
299
+ --num-layers-teacher ${NUM_LAYERS} \
300
+ --num-experts-teacher ${EP_SIZE_TEACHER} \
301
+ --hidden-size-teacher ${HIDDEN_SIZE} \
302
+ --num-attention-heads-teacher ${NUM_ATTN_HEADS} \
303
+ --load-teacher ${CHECKPOINT_PATH_TEACHER} \
304
+ --tensorboard-queue-size 1 \
305
+ --log-timers-to-tensorboard \
306
+ --log-batch-size-to-tensorboard \
307
+ --log-validation-ppl-to-tensorboard \
308
+ --tensorboard-dir ${TENSORBOARD_DIR}"
309
+
310
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
311
+ megatron_options="${megatron_options} \
312
+ --checkpoint-activations"
313
+ fi
314
+
315
+ megatron_options="${megatron_options} \
316
+ --create-moe-param-group"
317
+
318
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
319
+ megatron_options="${megatron_options} \
320
+ --disable-moe-token-dropping"
321
+ fi
322
+
323
+ template_json="ds_config_gpt_TEMPLATE.json"
324
+ config_json="ds_config_gpt_${NAME}.json"
325
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
326
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
327
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
328
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
329
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
330
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
331
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
332
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
333
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
334
+ > ${config_json}
335
+
336
+ deepspeed_options=" \
337
+ --deepspeed \
338
+ --deepspeed_config ${config_json} \
339
+ --pipeline-model-parallel-size ${PP_SIZE}"
340
+
341
+ # Currently MoE is not compatible with pipeline parallel
342
+ deepspeed_options="${deepspeed_options} \
343
+ --no-pipeline-parallel"
344
+
345
+
346
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
347
+ deepspeed_options="${deepspeed_options} \
348
+ --deepspeed-activation-checkpointing"
349
+ fi
350
+
351
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
352
+ echo ${run_cmd}
353
+ eval ${run_cmd}
354
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_350M_dense.sh ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ MODEL_SIZE=0.35
23
+ NUM_LAYERS=24
24
+ HIDDEN_SIZE=1024
25
+ NUM_ATTN_HEADS=16
26
+ GLOBAL_BATCH_SIZE=256
27
+ LR=3.0e-4
28
+ MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ # MODEL_SIZE=1.3
41
+ # NUM_LAYERS=24
42
+ # HIDDEN_SIZE=2048
43
+ # NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_SAMPLES.
95
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ LR_DECAY_TOKENS=260000000000
108
+ # LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
127
+ EP_SIZE=1
128
+ # EP_SIZE=128
129
+
130
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+ else
133
+ EP_PARALLEL_SIZE=$EP_SIZE
134
+ fi
135
+
136
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
137
+ ## found that lower LR and min LR (than the base dense model) helps.
138
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
139
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
140
+ ## heavily tuned.
141
+ # LR=2.0e-4
142
+ # MIN_LR=2e-06
143
+
144
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
145
+ ## 1.3B MoE-128 model
146
+ MLC=0.01
147
+
148
+ ## Below configs adjust the MoE expert token capacity limit during training and
149
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
150
+ ## Larger capacity factor or disabling capacity limit could improve training
151
+ ## convergence, but will also reduce training throughput.
152
+ MOE_TRAIN_CAP_FACTOR=1.0
153
+ MOE_EVAL_CAP_FACTOR=1.0
154
+ MOE_MIN_CAP=4
155
+ MOE_DROP_TOKEN="true"
156
+ # MOE_DROP_TOKEN="false"
157
+ ###############################################################################
158
+ ### Curriculum learning (CL) configs
159
+ ## Enable/disable CL
160
+ CL_ENABLED="false"
161
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
162
+ ## for tuning the following configs
163
+ CL_START_SEQLEN=80
164
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
165
+ CL_TOKENS=60
166
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
167
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
168
+ ###############################################################################
169
+ ### Misc configs
170
+ LOG_INTERVAL=10
171
+ EVAL_ITERS=10
172
+ EVAL_INTERVAL=100
173
+ SAVE_INTERVAL=1000
174
+
175
+ ## Standard deviation for weight initialization
176
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
177
+ ## dense model. Usually larger model needs lower std.
178
+ INIT_STD=0.014
179
+ # INIT_STD=0.01
180
+
181
+ ## Activation checkpointing saves GPU memory, but reduces training speed
182
+ ACTIVATION_CHECKPOINT="true"
183
+ # ACTIVATION_CHECKPOINT="false"
184
+ ###############################################################################
185
+ ### Output and data configs
186
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
187
+ host="${HOSTNAME}"
188
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
189
+ if [[ $EP_SIZE -gt 1 ]]; then
190
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
191
+ fi
192
+ if [ "${CL_ENABLED}" = "true" ]; then
193
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
194
+ fi
195
+
196
+ OUTPUT_BASEPATH=$DIR/output
197
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
199
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
200
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
201
+ mkdir -p ${TENSORBOARD_DIR}
202
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
203
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
204
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+
206
+ # USE_INTERNAL_DATA="true"
207
+ USE_INTERNAL_DATA="false"
208
+
209
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
210
+ ## The internal data is only accessible within Microsoft
211
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
212
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
213
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
214
+ ## For cluster Lab-RR1-V100
215
+ BASE_DATA_PATH=/data/Megatron-LM/data
216
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
217
+ ## For cluster Azure-CentralUS-A100
218
+ # BASE_DATA_PATH=/data/Megatron-LM/data
219
+ # DATA_HOME=/vc_data_1/users/amawa/blended
220
+
221
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
222
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
223
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
224
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
225
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
226
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
227
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
228
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
229
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
230
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
231
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
232
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
233
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
234
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
235
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
236
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
237
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
238
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
239
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
240
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
241
+ 0.01359 ${ARX} 0.01588 ${GIT}"
242
+ else
243
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
244
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
245
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
246
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
247
+ fi
248
+ ###############################################################################
249
+ data_options=" \
250
+ --vocab-file ${VOCAB_PATH} \
251
+ --merge-file ${MERGE_PATH} \
252
+ --data-path ${DATA_BLEND} \
253
+ --data-impl mmap"
254
+
255
+ megatron_options=" \
256
+ --override-lr-scheduler \
257
+ --adam-beta1 0.9 \
258
+ --adam-beta2 0.95 \
259
+ --tensor-model-parallel-size ${MP_SIZE} \
260
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
261
+ --num-experts ${EP_SIZE} \
262
+ --moe-loss-coeff ${MLC} \
263
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
264
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
265
+ --moe-min-capacity ${MOE_MIN_CAP} \
266
+ --init-method-std ${INIT_STD} \
267
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
268
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
269
+ --micro-batch-size ${BATCH_SIZE} \
270
+ --exit-duration-in-mins ${EXIT_DURATION} \
271
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
272
+ --num-layers ${NUM_LAYERS} \
273
+ --hidden-size ${HIDDEN_SIZE} \
274
+ --num-attention-heads ${NUM_ATTN_HEADS} \
275
+ --seq-length ${SEQ_LEN} \
276
+ --max-position-embeddings ${SEQ_LEN} \
277
+ --train-tokens ${TRAIN_TOKENS} \
278
+ --train-samples ${TRAIN_SAMPLES} \
279
+ --lr ${LR} \
280
+ --min-lr ${MIN_LR} \
281
+ --lr-decay-style cosine \
282
+ --split 98,2,0 \
283
+ --log-interval ${LOG_INTERVAL} \
284
+ --eval-interval ${EVAL_INTERVAL} \
285
+ --eval-iters ${EVAL_ITERS} \
286
+ --save-interval ${SAVE_INTERVAL} \
287
+ --weight-decay 0.1 \
288
+ --clip-grad 1.0 \
289
+ --hysteresis 2 \
290
+ --num-workers 0 \
291
+ --fp16 \
292
+ --load ${CHECKPOINT_PATH} \
293
+ --save ${CHECKPOINT_PATH} \
294
+ --tensorboard-queue-size 1 \
295
+ --log-timers-to-tensorboard \
296
+ --log-batch-size-to-tensorboard \
297
+ --log-validation-ppl-to-tensorboard \
298
+ --tensorboard-dir ${TENSORBOARD_DIR}"
299
+
300
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
301
+ megatron_options="${megatron_options} \
302
+ --checkpoint-activations"
303
+ fi
304
+
305
+ if [[ $EP_SIZE -gt 1 ]]; then
306
+ megatron_options="${megatron_options} \
307
+ --create-moe-param-group"
308
+ fi
309
+
310
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
311
+ megatron_options="${megatron_options} \
312
+ --disable-moe-token-dropping"
313
+ fi
314
+
315
+ template_json="ds_config_gpt_TEMPLATE.json"
316
+ config_json="ds_config_gpt_${NAME}.json"
317
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
318
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
319
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
320
+ | sed "s/ZERO_STAGE/0/" \
321
+ | sed "s/PRESCALE_GRAD/true/" \
322
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
323
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
324
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
325
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
326
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
327
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
328
+ > ${config_json}
329
+
330
+ deepspeed_options=" \
331
+ --deepspeed \
332
+ --deepspeed_config ${config_json} \
333
+ --pipeline-model-parallel-size ${PP_SIZE}"
334
+
335
+ # Currently MoE is not compatible with pipeline parallel
336
+ if [[ $EP_SIZE -gt 1 ]]; then
337
+ deepspeed_options="${deepspeed_options} \
338
+ --no-pipeline-parallel"
339
+ fi
340
+
341
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
342
+ deepspeed_options="${deepspeed_options} \
343
+ --deepspeed-activation-checkpointing"
344
+ fi
345
+
346
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
347
+ echo ${run_cmd}
348
+ eval ${run_cmd}
349
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/ds_pretrain_gpt_6.7B_dense.sh ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ # MODEL_SIZE=1.3
41
+ # NUM_LAYERS=24
42
+ # HIDDEN_SIZE=2048
43
+ # NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ MODEL_SIZE=6.7
59
+ NUM_LAYERS=32
60
+ HIDDEN_SIZE=4096
61
+ NUM_ATTN_HEADS=32
62
+ GLOBAL_BATCH_SIZE=1024
63
+ LR=1.2e-4
64
+ MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_SAMPLES.
95
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ LR_DECAY_TOKENS=260000000000
108
+ # LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=8
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
127
+ EP_SIZE=1
128
+ # EP_SIZE=128
129
+
130
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+ else
133
+ EP_PARALLEL_SIZE=$EP_SIZE
134
+ fi
135
+
136
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
137
+ ## found that lower LR and min LR (than the base dense model) helps.
138
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
139
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
140
+ ## heavily tuned.
141
+ # LR=2.0e-4
142
+ # MIN_LR=2e-06
143
+
144
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
145
+ ## 1.3B MoE-128 model
146
+ MLC=0.01
147
+
148
+ ## Below configs adjust the MoE expert token capacity limit during training and
149
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
150
+ ## Larger capacity factor or disabling capacity limit could improve training
151
+ ## convergence, but will also reduce training throughput.
152
+ MOE_TRAIN_CAP_FACTOR=1.0
153
+ MOE_EVAL_CAP_FACTOR=1.0
154
+ MOE_MIN_CAP=4
155
+ MOE_DROP_TOKEN="true"
156
+ # MOE_DROP_TOKEN="false"
157
+ ###############################################################################
158
+ ### Curriculum learning (CL) configs
159
+ ## Enable/disable CL
160
+ CL_ENABLED="false"
161
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
162
+ ## for tuning the following configs
163
+ CL_START_SEQLEN=80
164
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
165
+ CL_TOKENS=60
166
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
167
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
168
+ ###############################################################################
169
+ ### Misc configs
170
+ LOG_INTERVAL=10
171
+ EVAL_ITERS=10
172
+ EVAL_INTERVAL=100
173
+ SAVE_INTERVAL=1000
174
+
175
+ ## Standard deviation for weight initialization
176
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
177
+ ## dense model. Usually larger model needs lower std.
178
+ # INIT_STD=0.014
179
+ INIT_STD=0.01
180
+
181
+ ## Activation checkpointing saves GPU memory, but reduces training speed
182
+ ACTIVATION_CHECKPOINT="true"
183
+ # ACTIVATION_CHECKPOINT="false"
184
+ ###############################################################################
185
+ ### Output and data configs
186
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
187
+ host="${HOSTNAME}"
188
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
189
+ if [[ $EP_SIZE -gt 1 ]]; then
190
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
191
+ fi
192
+ if [ "${CL_ENABLED}" = "true" ]; then
193
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
194
+ fi
195
+
196
+ OUTPUT_BASEPATH=$DIR/output
197
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
199
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
200
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
201
+ mkdir -p ${TENSORBOARD_DIR}
202
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
203
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
204
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+
206
+ # USE_INTERNAL_DATA="true"
207
+ USE_INTERNAL_DATA="false"
208
+
209
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
210
+ ## The internal data is only accessible within Microsoft
211
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
212
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
213
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
214
+ ## For cluster Lab-RR1-V100
215
+ BASE_DATA_PATH=/data/Megatron-LM/data
216
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
217
+ ## For cluster Azure-CentralUS-A100
218
+ # BASE_DATA_PATH=/data/Megatron-LM/data
219
+ # DATA_HOME=/vc_data_1/users/amawa/blended
220
+
221
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
222
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
223
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
224
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
225
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
226
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
227
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
228
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
229
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
230
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
231
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
232
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
233
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
234
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
235
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
236
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
237
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
238
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
239
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
240
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
241
+ 0.01359 ${ARX} 0.01588 ${GIT}"
242
+ else
243
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
244
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
245
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
246
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
247
+ fi
248
+ ###############################################################################
249
+ data_options=" \
250
+ --vocab-file ${VOCAB_PATH} \
251
+ --merge-file ${MERGE_PATH} \
252
+ --data-path ${DATA_BLEND} \
253
+ --data-impl mmap"
254
+
255
+ megatron_options=" \
256
+ --override-lr-scheduler \
257
+ --adam-beta1 0.9 \
258
+ --adam-beta2 0.95 \
259
+ --tensor-model-parallel-size ${MP_SIZE} \
260
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
261
+ --num-experts ${EP_SIZE} \
262
+ --moe-loss-coeff ${MLC} \
263
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
264
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
265
+ --moe-min-capacity ${MOE_MIN_CAP} \
266
+ --init-method-std ${INIT_STD} \
267
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
268
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
269
+ --micro-batch-size ${BATCH_SIZE} \
270
+ --exit-duration-in-mins ${EXIT_DURATION} \
271
+ --rampup-batch-size 32 32 4882812 \
272
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
273
+ --num-layers ${NUM_LAYERS} \
274
+ --hidden-size ${HIDDEN_SIZE} \
275
+ --num-attention-heads ${NUM_ATTN_HEADS} \
276
+ --seq-length ${SEQ_LEN} \
277
+ --max-position-embeddings ${SEQ_LEN} \
278
+ --train-tokens ${TRAIN_TOKENS} \
279
+ --train-samples ${TRAIN_SAMPLES} \
280
+ --lr ${LR} \
281
+ --min-lr ${MIN_LR} \
282
+ --lr-decay-style cosine \
283
+ --split 98,2,0 \
284
+ --log-interval ${LOG_INTERVAL} \
285
+ --eval-interval ${EVAL_INTERVAL} \
286
+ --eval-iters ${EVAL_ITERS} \
287
+ --save-interval ${SAVE_INTERVAL} \
288
+ --weight-decay 0.1 \
289
+ --clip-grad 1.0 \
290
+ --hysteresis 2 \
291
+ --num-workers 0 \
292
+ --fp16 \
293
+ --load ${CHECKPOINT_PATH} \
294
+ --save ${CHECKPOINT_PATH} \
295
+ --tensorboard-queue-size 1 \
296
+ --log-timers-to-tensorboard \
297
+ --log-batch-size-to-tensorboard \
298
+ --log-validation-ppl-to-tensorboard \
299
+ --tensorboard-dir ${TENSORBOARD_DIR}"
300
+
301
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
302
+ megatron_options="${megatron_options} \
303
+ --checkpoint-activations"
304
+ fi
305
+
306
+ if [[ $EP_SIZE -gt 1 ]]; then
307
+ megatron_options="${megatron_options} \
308
+ --create-moe-param-group"
309
+ fi
310
+
311
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
312
+ megatron_options="${megatron_options} \
313
+ --disable-moe-token-dropping"
314
+ fi
315
+
316
+ template_json="ds_config_gpt_TEMPLATE.json"
317
+ config_json="ds_config_gpt_${NAME}.json"
318
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
319
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
320
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
321
+ | sed "s/ZERO_STAGE/0/" \
322
+ | sed "s/PRESCALE_GRAD/true/" \
323
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
324
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
325
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
326
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
327
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
328
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
329
+ > ${config_json}
330
+
331
+ deepspeed_options=" \
332
+ --deepspeed \
333
+ --deepspeed_config ${config_json} \
334
+ --pipeline-model-parallel-size ${PP_SIZE}"
335
+
336
+ # Currently MoE is not compatible with pipeline parallel
337
+ if [[ $EP_SIZE -gt 1 ]]; then
338
+ deepspeed_options="${deepspeed_options} \
339
+ --no-pipeline-parallel"
340
+ fi
341
+
342
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
343
+ deepspeed_options="${deepspeed_options} \
344
+ --deepspeed-activation-checkpointing"
345
+ fi
346
+
347
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
348
+ echo ${run_cmd}
349
+ eval ${run_cmd}
350
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/MoE/readme_evalharness.md ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # How to run lm-eval on Megatron-DeepSpeed checkpoint using the original setup
2
+
3
+ A great portion of this eval harness feature is inherited from https://github.com/bigscience-workshop/Megatron-DeepSpeed/pull/212, but with code/doc changes (e.g., to support case without pipeline parallelism and MoE models).
4
+
5
+ This particular setup uses the normal deepspeed checkpoint and requires no conversion to Megatron-LM.
6
+
7
+ ## Prerequisites
8
+
9
+ 1. Install software
10
+
11
+ On login console with external network
12
+
13
+ Get lm-eval harness (https://github.com/EleutherAI/lm-evaluation-harness) and `best-download==0.0.7` needed to download some tasks.
14
+ ```
15
+ (maybe need pip install --upgrade pip)
16
+ pip install best-download==0.0.7
17
+ pip install lm-eval
18
+ (previously we used "pip install git+https://github.com/EleutherAI/lm-evaluation-harness" to install, but later found the command above has less dependency issues)
19
+ ```
20
+
21
+ 2. Pre-download needed datasets
22
+
23
+ some symlinks due to lm-harness' issues with relative position of data
24
+ ```
25
+ mkdir data
26
+ cd ../../tasks/eval_harness/
27
+ ln -s ../../examples/MoE/data/ data
28
+ cd ../../examples/MoE/
29
+ ```
30
+ <!-- Also make sure `data` is not on one of the limited paritions like WORKSF. -->
31
+
32
+ Then install datasets for the tasks:
33
+ ```
34
+ python ../../tasks/eval_harness/download.py --task_list hellaswag,lambada,triviaqa,webqs,winogrande,piqa,arc_challenge,arc_easy,openbookqa,race,boolq,cb,copa,rte,wic,wsc,multirc,record,anli_r1,anli_r2,anli_r3,wikitext,logiqa,mathqa,mc_taco,mrpc,prost,pubmedqa,qnli,qqp,sciq,sst,wnli
35
+ ```
36
+ and make sure that `export HF_DATASETS_OFFLINE=1`
37
+
38
+ <!-- If there are things like custom tokenizers, pre-download those too, e.g.:
39
+
40
+ ```
41
+ python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('bigscience/oscar_13_languages_alpha_weight')"
42
+ ```
43
+ and make sure that `export TRANSFORMERS_OFFLINE=1` is in the script.
44
+ You know there is a custom tokenizer if the training script had something like:
45
+
46
+ ```
47
+ --tokenizer-type PretrainedFromHF \
48
+ --tokenizer-name-or-path bigscience/oscar_13_languages_alpha_weight \
49
+ ``` -->
50
+
51
+ 3. Prepare the script
52
+
53
+ <!-- Prepare the run script, replace `variant` with a unique identifier for the current eval so that multiple evals could run in parallel and not all log into the same `results.json` file. so, e.g., `tr9c-1B3-swiglu`
54
+
55
+ ```
56
+ cp examples/run_evalharness_deepspeed.slurm run_evalharness-variant.slurm
57
+ ```
58
+
59
+ now edit `run_evalharness-variant.slurm`
60
+
61
+
62
+ Note that the eval code knows to pull the original training args from the checkpoint, so we don't need to pass any of those. And we just need to setup the evaluation args. -->
63
+
64
+ `ds_evalharness.sh` is the example script.
65
+
66
+ 1. Edit:
67
+
68
+ ```
69
+ PP_SIZE=1
70
+ TP_SIZE=1
71
+ NO_PP="true"
72
+ EP_PARALLEL_SIZE=1
73
+ NUM_NODE=1
74
+ NUM_GPU_PER_NODE=1
75
+ ```
76
+ to match the eval topology.
77
+
78
+ Edit:
79
+ ```
80
+ CHECKPOINT_PATH=
81
+ CONFIG_PATH=
82
+ RESULT_PATH=
83
+ ```
84
+ to the checkpoint/ds config you want to use, and where to save the results.
85
+ <!-- If the model fits into 1 gpu, then there is nothing to change.
86
+
87
+ The eval script will automatically reshape the model if it was of a different topology. -->
88
+
89
+
90
+ 2. Adjust the following to fit the chosen GPU. As of last check for 1.3B model the settings are one of:
91
+ ```
92
+ EVAL_MICRO_BATCH_SIZE=6 # 16GB GPU 1.3B model
93
+ EVAL_MICRO_BATCH_SIZE=12 # 32GB GPU 1.3B model
94
+ ```
95
+
96
+ If you get OOM lower it further.
97
+
98
+ 3. If not using the Deepspeed path, disable it by removing:
99
+
100
+ ```
101
+ --deepspeed \
102
+ --deepspeed_config ds_config.json \
103
+ ```
104
+
105
+ If you didn't disable it and the program crashed on checkpoint loading unable to find some key, disable deepspeed as explained above.
106
+
107
+ Note that for MoE models and for models without pipeline parallelism, currently they might not work for the case without deepspeed.
108
+
109
+ <!-- ## Eval
110
+
111
+ Currently it takes 2-3 hours to run on 32GB for 1.3B model, 6-7h for 16GB GPU, so a 20h slurm job should be enough.
112
+
113
+ When ready, launch:
114
+ ```
115
+ sbatch ./run_evalharness-variant.slurm
116
+ ```
117
+
118
+ To monitor progress:
119
+ ```
120
+ tail -f tail -f $VARIANT-eval-harness.log
121
+ ```
122
+ where the variant is what you set `$VARIANT` to in the slurm script.
123
+
124
+ The template is set up for 16GB gpu since they are easier to get by. If you change to 32GB, adjust:
125
+ ```
126
+ #SBATCH --constraint=v100-32g
127
+ ...
128
+ EVAL_MICRO_BATCH_SIZE=12 # 32GB GPU 1.3B model
129
+ ```
130
+
131
+
132
+ Note that the original ETA at the start of the run can be 10x too longer than the actual outcome. For example it may suggest 18 hours but will complete in 2 hours.
133
+
134
+
135
+ ## Short eval
136
+
137
+ if you just want to quickly test that everything can run to the end, edit `tasks/eval_harness/evaluate.py`, e.g. to run only 10 batches:
138
+ ```
139
+ - results = evaluator.evaluate(adaptor, task_dict, False, 0, None)
140
+ + results = evaluator.evaluate(adaptor, task_dict, False, 0, 10)
141
+ ```
142
+
143
+ (XXX: could be a cmd line option so that code won't need to be modified)
144
+
145
+
146
+ ## Import into spreadsheet
147
+
148
+ https://docs.google.com/spreadsheets/d/1CI8Q9RCblLRzUOPJ6ViqBmo284-8ojluQ-CmaEuhuv0/edit?usp=sharing
149
+
150
+ Note that the spreadsheet format is quite different, so use this script:
151
+ ```
152
+ ./tasks/eval_harness/report-to-csv.py results.json
153
+ ```
154
+ to reformat the json results into csv while changing its shape to match the spreadsheet format
155
+
156
+ Since some records might be missing or extraneous here is the best way to do it:
157
+
158
+ 1. copy the data from first 2 columns to some place under the main spreadsheet
159
+
160
+ 2. put the pointer to the 3rd column next to where the 2 first columns were copied.
161
+
162
+ 3. import `results.csv` using file-> import -> file ->
163
+
164
+ Import location: Replace data at selected cell
165
+
166
+ 4. Now it should be easy to align the new records with the old ones - delete irrelevant records and Insert->Cells where data is missing until the first 2 columns match
167
+
168
+ 5. now create 2 cols in the main table on top and now it should be safe to Copy-n-Paste the 2-col data range, without the task/metrics columns into the newly created space. -->
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/README.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Recipes for experimentation on Azure
2
+
3
+ The recipes have been tested on command line on a cluster setup using Azure VMs and VMSS as well as inside Docker based environments.
4
+
5
+ To run any of the examples in this folder, please go to the base directory of Megatron-DeepSpeed and run as follows
6
+
7
+ ```bash examples/azure/run-benchmark-model.sh```
8
+
9
+ ### Pre-requisites
10
+
11
+ To run the above script, you will need to either setup your own dataset and modify the scripts or use our helper scripts to download the publicly available Books dataset and GPT vocab files. Please use the following from the ```dataset``` folder
12
+
13
+ ```bash dataset/download_books.sh```
14
+
15
+ ```bash dataset/download_vocab.sh```
16
+
17
+ ### Run 175B and 1T models
18
+
19
+ We have included two recipes for the 175B model and the 1T model. To train the model, we assume that the users will modify and tune hyperparameters and configurations by themselves. To facilitate initial training, we have made the recipes runnable with the Books dataset as follows.
20
+
21
+ ```bash examples/azure/run-175b.sh```
22
+
23
+ ```bash examples/azure/run-1t.sh```
24
+
25
+ ### Note about ZeRO stage 3 and CPU offload
26
+
27
+ By default, we have enabled ZeRO Stage 3 for both the recipes above. For the 1T model, we have also enabled the CPU-offload feature to save on memory and enable a larger batch size that offers better performance.
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/run-175b.sh ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -ex
3
+
4
+ data_options=" \
5
+ --vocab-file ${VOCAB_PATH} \
6
+ --merge-file ${MERGE_PATH} \
7
+ --data-path ${DATA_PATH} \
8
+ --data-impl mmap"
9
+
10
+ BASE_PATH=$PWD/dataset/
11
+ DATA_PATH=${BASE_PATH}/BookCorpusDataset_text_document
12
+ DS_CONFIG=ds_config.json
13
+
14
+ # Hostfile path
15
+ HF=/job/hostfile
16
+
17
+ # Disabling tensor/pipeline parallelism
18
+ TP=1
19
+ PP=1
20
+
21
+ # HEADS ~= HIDDEN/128
22
+
23
+ # Model: 175B
24
+ NLAYERS=96
25
+ HIDDEN=12288
26
+ HEADS=96
27
+ SEQ=1024
28
+
29
+
30
+ MICRO_BATCH=4
31
+ NODES=1
32
+ GPN=8
33
+ GLOBAL_BATCH=$(( ${GPN} * ${MICRO_BATCH} * ${NODES} ))
34
+
35
+ # Initial power scale for loss
36
+ SP=15
37
+
38
+ # Uncomment/comment one of the following blocks.
39
+
40
+ # For 1T model, start with microbatch=1, try to get 2 and 4. If OOM w/ 4, use cpu-offloading
41
+
42
+ # Set to cpu for offloading to cpu for larger models
43
+ #OFFLOAD_DEVICE="cpu"
44
+ #CPU_OPTIM=" --cpu-optimizer"
45
+
46
+ # Set to none and empty string for no cpu offloading
47
+ OFFLOAD_DEVICE="none"
48
+ CPU_OPTIM=" "
49
+
50
+ ZERO_STAGE=3
51
+ OUTPUT_DIR=ds_z_off-${OFFLOAD_DEVICE}_stage_${ZERO_STAGE}_nl${NLAYERS}_hs${HIDDEN}_mb${MICRO_BATCH}_seq${SEQ}_gb${GLOBAL_BATCH}_nodes${NODES}
52
+ #OUTPUT_DIR=baseline_nl${NLAYERS}_hs${HIDDEN}_gb${GLOBAL_BATCH}_mb${MICRO_BATCH}
53
+ mkdir -p $OUTPUT_DIR
54
+
55
+ cat <<EOT > $DS_CONFIG
56
+ {
57
+ "train_batch_size" : $GLOBAL_BATCH,
58
+ "train_micro_batch_size_per_gpu": $MICRO_BATCH,
59
+ "steps_per_print": 1,
60
+ "gradient_accumulation_steps": 1,
61
+ "zero_optimization": {
62
+ "stage": 3,
63
+ "stage3_max_live_parameters": 3e9,
64
+ "stage3_max_reuse_distance": 3e9,
65
+ "stage3_param_persistence_threshold": 1e5,
66
+ "stage3_prefetch_bucket_size": 5e7,
67
+ "contiguous_gradients": true,
68
+ "overlap_comm": true,
69
+ "reduce_bucket_size": 90000000,
70
+ "sub_group_size": 1e9,
71
+ "offload_optimizer": {
72
+ "device": "$OFFLOAD_DEVICE",
73
+ "buffer_count": 4,
74
+ "pipeline_read": false,
75
+ "pipeline_write": false,
76
+ "pin_memory": true
77
+ }
78
+ },
79
+ "gradient_clipping": 1.0,
80
+ "fp16": {
81
+ "enabled": true,
82
+ "initial_scale_power" : $SP,
83
+ "loss_scale_window": 1000,
84
+ "hysteresis": 2,
85
+ "min_loss_scale": 1
86
+ },
87
+ "wall_clock_breakdown": true,
88
+ "zero_allow_untested_optimizer": false,
89
+ "aio": {
90
+ "block_size": 1048576,
91
+ "queue_depth": 16,
92
+ "single_submit": false,
93
+ "overlap_events": true,
94
+ "thread_count": 2
95
+ }
96
+ }
97
+ EOT
98
+
99
+ export NCCL_DEBUG=warn
100
+
101
+ ds_args=" "
102
+ ds_args=" --deepspeed ${ds_args}"
103
+ ds_args=" --no-pipeline-parallel ${ds_args}"
104
+ ds_args=" --deepspeed_config=$DS_CONFIG ${ds_args}"
105
+ ds_args=" --zero-stage=$ZERO_STAGE ${ds_args}"
106
+ ds_args=" --deepspeed-activation-checkpointing ${ds_args}"
107
+
108
+
109
+
110
+ deepspeed --force_multi --num_nodes=$NODES --hostfile $HF pretrain_gpt.py \
111
+ --tensor-model-parallel-size $TP \
112
+ --pipeline-model-parallel-size $PP \
113
+ --num-layers $NLAYERS \
114
+ --hidden-size $HIDDEN \
115
+ --num-attention-heads $HEADS \
116
+ --seq-length $SEQ \
117
+ --loss-scale $SP \
118
+ --max-position-embeddings $SEQ \
119
+ --micro-batch-size $MICRO_BATCH \
120
+ --global-batch-size $GLOBAL_BATCH \
121
+ --train-iters 1000 \
122
+ --lr 6.0e-5 \
123
+ --min-lr 6.0e-6 \
124
+ --lr-decay-style cosine \
125
+ --log-interval 1 \
126
+ --eval-iters 40 \
127
+ --eval-interval 1000 \
128
+ --data-path $DATA_PATH \
129
+ --vocab-file $BASE_PATH/gpt2-vocab.json \
130
+ --merge-file $BASE_PATH/gpt2-merges.txt \
131
+ --save-interval 1000 \
132
+ --split 98,2,0 \
133
+ --clip-grad 1.0 \
134
+ --weight-decay 0.1 \
135
+ --adam-beta1 0.9 \
136
+ --adam-beta2 0.95 \
137
+ --init-method-std 0.006 \
138
+ --fp16 \
139
+ --checkpoint-activations \
140
+ --tensorboard-dir $OUTPUT_DIR \
141
+ $CPU_OPTIM $ds_args \
142
+ --exit-interval 5000 | tee ${OUTPUT_DIR}/output.log
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/run-1t.sh ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -ex
3
+
4
+ data_options=" \
5
+ --vocab-file ${VOCAB_PATH} \
6
+ --merge-file ${MERGE_PATH} \
7
+ --data-path ${DATA_PATH} \
8
+ --data-impl mmap"
9
+
10
+ BASE_PATH=$PWD/dataset/
11
+ DATA_PATH=${BASE_PATH}/BookCorpusDataset_text_document
12
+ DS_CONFIG=ds_config.json
13
+
14
+ # Hostfile path
15
+ HF=/job/hostfile
16
+
17
+ # Disabling tensor/pipeline parallelism
18
+ TP=1
19
+ PP=1
20
+
21
+ # HEADS ~= HIDDEN/128
22
+
23
+ # Refer to Megatron-table in the README.md file for model sizes
24
+ # Model: 310B
25
+ #NLAYERS=96
26
+ #HIDDEN=16384
27
+ #HEADS=128
28
+ #SEQ=2048
29
+
30
+ # Model 530B
31
+ #NLAYERS=105
32
+ #HIDDEN=20480
33
+ #HEADS=160
34
+ #SEQ=2048
35
+
36
+ # Model 1T
37
+ NLAYERS=128
38
+ HIDDEN=25600
39
+ HEADS=160
40
+ SEQ=1024
41
+
42
+ MICRO_BATCH=1
43
+ NODES=1
44
+ GPN=8
45
+ GLOBAL_BATCH=$(( ${GPN} * ${MICRO_BATCH} * ${NODES} ))
46
+
47
+ # Initial power scale for loss
48
+ SP=15
49
+
50
+ # Uncomment/comment one of the following blocks.
51
+
52
+ # For 1T model, start with microbatch=1, try to get 2 and 4. If OOM w/ 4, use cpu-offloading
53
+
54
+ # Set to cpu for offloading to cpu for larger models
55
+ OFFLOAD_DEVICE="cpu"
56
+ CPU_OPTIM=" --cpu-optimizer"
57
+
58
+ # Set to none and empty string for no cpu offloading
59
+ #OFFLOAD_DEVICE="none"
60
+ #CPU_OPTIM=" "
61
+
62
+ ZERO_STAGE=3
63
+ OUTPUT_DIR=ds_z_off-${OFFLOAD_DEVICE}_stage_${ZERO_STAGE}_nl${NLAYERS}_hs${HIDDEN}_mb${MICRO_BATCH}_seq${SEQ}_gb${GLOBAL_BATCH}_nodes${NODES}
64
+ #OUTPUT_DIR=baseline_nl${NLAYERS}_hs${HIDDEN}_gb${GLOBAL_BATCH}_mb${MICRO_BATCH}
65
+ mkdir -p $OUTPUT_DIR
66
+
67
+ cat <<EOT > $DS_CONFIG
68
+ {
69
+ "train_batch_size" : $GLOBAL_BATCH,
70
+ "train_micro_batch_size_per_gpu": $MICRO_BATCH,
71
+ "steps_per_print": 1,
72
+ "gradient_accumulation_steps": 1,
73
+ "zero_optimization": {
74
+ "stage": 3,
75
+ "stage3_max_live_parameters": 3e9,
76
+ "stage3_max_reuse_distance": 3e9,
77
+ "stage3_param_persistence_threshold": 1e5,
78
+ "stage3_prefetch_bucket_size": 5e7,
79
+ "contiguous_gradients": true,
80
+ "overlap_comm": true,
81
+ "reduce_bucket_size": 90000000,
82
+ "sub_group_size": 1e9,
83
+ "offload_optimizer": {
84
+ "device": "$OFFLOAD_DEVICE",
85
+ "buffer_count": 4,
86
+ "pipeline_read": false,
87
+ "pipeline_write": false,
88
+ "pin_memory": true
89
+ }
90
+ },
91
+ "gradient_clipping": 1.0,
92
+ "fp16": {
93
+ "enabled": true,
94
+ "initial_scale_power" : $SP,
95
+ "loss_scale_window": 1000,
96
+ "hysteresis": 2,
97
+ "min_loss_scale": 1
98
+ },
99
+ "wall_clock_breakdown": true,
100
+ "zero_allow_untested_optimizer": false,
101
+ "aio": {
102
+ "block_size": 1048576,
103
+ "queue_depth": 16,
104
+ "single_submit": false,
105
+ "overlap_events": true,
106
+ "thread_count": 2
107
+ }
108
+ }
109
+ EOT
110
+
111
+ export NCCL_DEBUG=warn
112
+
113
+ ds_args=" "
114
+ ds_args=" --deepspeed ${ds_args}"
115
+ ds_args=" --no-pipeline-parallel ${ds_args}"
116
+ ds_args=" --deepspeed_config=$DS_CONFIG ${ds_args}"
117
+ ds_args=" --zero-stage=$ZERO_STAGE ${ds_args}"
118
+ ds_args=" --deepspeed-activation-checkpointing ${ds_args}"
119
+
120
+
121
+
122
+ deepspeed --force_multi --num_nodes=$NODES --hostfile $HF pretrain_gpt.py \
123
+ --tensor-model-parallel-size $TP \
124
+ --pipeline-model-parallel-size $PP \
125
+ --num-layers $NLAYERS \
126
+ --hidden-size $HIDDEN \
127
+ --num-attention-heads $HEADS \
128
+ --seq-length $SEQ \
129
+ --loss-scale $SP \
130
+ --max-position-embeddings $SEQ \
131
+ --micro-batch-size $MICRO_BATCH \
132
+ --global-batch-size $GLOBAL_BATCH \
133
+ --train-iters 1000 \
134
+ --lr 6.0e-5 \
135
+ --min-lr 6.0e-6 \
136
+ --lr-decay-style cosine \
137
+ --log-interval 1 \
138
+ --eval-iters 40 \
139
+ --eval-interval 1000 \
140
+ --data-path $DATA_PATH \
141
+ --vocab-file $BASE_PATH/gpt2-vocab.json \
142
+ --merge-file $BASE_PATH/gpt2-merges.txt \
143
+ --save-interval 1000 \
144
+ --split 98,2,0 \
145
+ --clip-grad 1.0 \
146
+ --weight-decay 0.1 \
147
+ --adam-beta1 0.9 \
148
+ --adam-beta2 0.95 \
149
+ --init-method-std 0.006 \
150
+ --fp16 \
151
+ --checkpoint-activations \
152
+ --tensorboard-dir $OUTPUT_DIR \
153
+ $CPU_OPTIM $ds_args \
154
+ --exit-interval 5000 | tee ${OUTPUT_DIR}/output.log
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azure/run-benchmark-model.sh ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -ex
3
+
4
+ data_options=" \
5
+ --vocab-file ${VOCAB_PATH} \
6
+ --merge-file ${MERGE_PATH} \
7
+ --data-path ${DATA_PATH} \
8
+ --data-impl mmap"
9
+
10
+ BASE_PATH=$PWD/dataset/
11
+ DATA_PATH=${BASE_PATH}/BookCorpusDataset_text_document
12
+ DS_CONFIG=ds_config.json
13
+
14
+ # Hostfile path
15
+ HF=/job/hostfile
16
+
17
+ # Disabling tensor/pipeline parallelism
18
+ TP=1
19
+ PP=1
20
+
21
+ # HEADS ~= HIDDEN/128
22
+
23
+ # Model: Benchmark model
24
+ NLAYERS=1
25
+ HIDDEN=12288
26
+ HEADS=96
27
+ SEQ=1024
28
+
29
+
30
+ MICRO_BATCH=4
31
+ NODES=2
32
+ GPN=8
33
+ GLOBAL_BATCH=$(( ${GPN} * ${MICRO_BATCH} * ${NODES} ))
34
+
35
+ # Initial power scale for loss
36
+ SP=15
37
+
38
+ # Uncomment/comment one of the following blocks.
39
+
40
+ # For 1T model, start with microbatch=1, try to get 2 and 4. If OOM w/ 4, use cpu-offloading
41
+
42
+ # Set to cpu for offloading to cpu for larger models
43
+ #OFFLOAD_DEVICE="cpu"
44
+ #CPU_OPTIM=" --cpu-optimizer"
45
+
46
+ # Set to none and empty string for no cpu offloading
47
+ OFFLOAD_DEVICE="none"
48
+ CPU_OPTIM=" "
49
+
50
+ ZERO_STAGE=3
51
+ OUTPUT_DIR=ds_z_off-${OFFLOAD_DEVICE}_stage_${ZERO_STAGE}_nl${NLAYERS}_hs${HIDDEN}_mb${MICRO_BATCH}_seq${SEQ}_gb${GLOBAL_BATCH}_nodes${NODES}
52
+ #OUTPUT_DIR=baseline_nl${NLAYERS}_hs${HIDDEN}_gb${GLOBAL_BATCH}_mb${MICRO_BATCH}
53
+ mkdir -p $OUTPUT_DIR
54
+
55
+ cat <<EOT > $DS_CONFIG
56
+ {
57
+ "train_batch_size" : $GLOBAL_BATCH,
58
+ "train_micro_batch_size_per_gpu": $MICRO_BATCH,
59
+ "steps_per_print": 1,
60
+ "gradient_accumulation_steps": 1,
61
+ "zero_optimization": {
62
+ "stage": 3,
63
+ "stage3_max_live_parameters": 3e9,
64
+ "stage3_max_reuse_distance": 3e9,
65
+ "stage3_param_persistence_threshold": 1e5,
66
+ "stage3_prefetch_bucket_size": 5e7,
67
+ "contiguous_gradients": true,
68
+ "overlap_comm": true,
69
+ "reduce_bucket_size": 90000000,
70
+ "sub_group_size": 1e9,
71
+ "offload_optimizer": {
72
+ "device": "$OFFLOAD_DEVICE",
73
+ "buffer_count": 4,
74
+ "pipeline_read": false,
75
+ "pipeline_write": false,
76
+ "pin_memory": true
77
+ }
78
+ },
79
+ "gradient_clipping": 1.0,
80
+ "fp16": {
81
+ "enabled": true,
82
+ "initial_scale_power" : $SP,
83
+ "loss_scale_window": 1000,
84
+ "hysteresis": 2,
85
+ "min_loss_scale": 1
86
+ },
87
+ "wall_clock_breakdown": true,
88
+ "zero_allow_untested_optimizer": false,
89
+ "aio": {
90
+ "block_size": 1048576,
91
+ "queue_depth": 16,
92
+ "single_submit": false,
93
+ "overlap_events": true,
94
+ "thread_count": 2
95
+ }
96
+ }
97
+ EOT
98
+
99
+ export NCCL_DEBUG=warn
100
+
101
+ ds_args=" "
102
+ ds_args=" --deepspeed ${ds_args}"
103
+ ds_args=" --no-pipeline-parallel ${ds_args}"
104
+ ds_args=" --deepspeed_config=$DS_CONFIG ${ds_args}"
105
+ ds_args=" --zero-stage=$ZERO_STAGE ${ds_args}"
106
+ ds_args=" --deepspeed-activation-checkpointing ${ds_args}"
107
+
108
+
109
+
110
+ deepspeed --force_multi --num_nodes=$NODES --hostfile $HF pretrain_gpt.py \
111
+ --tensor-model-parallel-size $TP \
112
+ --pipeline-model-parallel-size $PP \
113
+ --num-layers $NLAYERS \
114
+ --hidden-size $HIDDEN \
115
+ --num-attention-heads $HEADS \
116
+ --seq-length $SEQ \
117
+ --loss-scale $SP \
118
+ --max-position-embeddings $SEQ \
119
+ --micro-batch-size $MICRO_BATCH \
120
+ --global-batch-size $GLOBAL_BATCH \
121
+ --train-iters 50 \
122
+ --lr 6.0e-5 \
123
+ --min-lr 6.0e-6 \
124
+ --lr-decay-style cosine \
125
+ --log-interval 1 \
126
+ --eval-iters 40 \
127
+ --eval-interval 1000 \
128
+ --data-path $DATA_PATH \
129
+ --vocab-file $BASE_PATH/gpt2-vocab.json \
130
+ --merge-file $BASE_PATH/gpt2-merges.txt \
131
+ --save-interval 1000 \
132
+ --split 98,2,0 \
133
+ --clip-grad 1.0 \
134
+ --weight-decay 0.1 \
135
+ --adam-beta1 0.9 \
136
+ --adam-beta2 0.95 \
137
+ --init-method-std 0.006 \
138
+ --fp16 \
139
+ --checkpoint-activations \
140
+ --tensorboard-dir $OUTPUT_DIR \
141
+ $CPU_OPTIM $ds_args \
142
+ --exit-interval 5000 | tee ${OUTPUT_DIR}/output.log
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azureml/Dockerfile.dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM mcr.microsoft.com/azureml/aifx/stable-ubuntu2004-cu115-py38-torch1110
2
+
3
+ USER root:root
4
+
5
+ RUN pip install pybind11
6
+
7
+ RUN pip install git+https://github.com/microsoft/DeepSpeed.git
8
+
9
+ # add a100-topo.xml
10
+ RUN mkdir -p /opt/microsoft/
11
+ RUN wget -O /opt/microsoft/a100-topo.xml https://hpcbenchmarks.blob.core.windows.net/bookcorpus/data/a100-topo.xml
12
+
13
+ # to use on A100, enable env var below in your job
14
+ ENV NCCL_TOPO_FILE="/opt/microsoft/a100-topo.xml"
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/azureml/README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Megatron-DeepSpeed on AzureML
2
+ Example script for running Megatron-DeepSpeed using Azure Machine Learning.
3
+
4
+ ------
5
+
6
+ # Workspace Setup
7
+ Setup an AML workspace. Refer to: [set-up doc](https://github.com/Azure/azureml-examples/tree/main/python-sdk#set-up).
8
+
9
+ # Dataset Preparation
10
+ Create AML Dataset. To run remote AML job, you need to provide AML FileDataset.
11
+ Refer to [prepare_dataset script](prepare_dataset.py) to upload .bin and .idx files to blob store and on how to create FileDataset.
12
+
13
+ # Training
14
+ Run Megatron-DeepSpeed on Azure ML. Refer to [aml_submit script](aml_submit.py).
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/125M-Int8-test-64gpu-distilled-group48.sh ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ MODEL_SIZE=0.125
14
+ NUM_LAYERS=12
15
+ HIDDEN_SIZE=768
16
+ NUM_ATTN_HEADS=12
17
+ GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ LR=6.0e-5
20
+ MIN_LR=6.0e-5
21
+
22
+ # Curriculum learning (CL) enables stable large-batch training
23
+ # GLOBAL_BATCH_SIZE=16 # 8x
24
+ # LR=6e-4 # 4x
25
+
26
+ ###############################################################################
27
+ ### Training duration configs
28
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
29
+ # TRAIN_TOKENS=300000000000
30
+ TRAIN_TOKENS=5250000000
31
+
32
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
33
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
34
+ ## above, and techniques like curriculum learning has less token in some samples,
35
+ ## so we just set this config large enough to make sure we have enough
36
+ ## processed data and don't terminate by TRAIN_SAMPLES.
37
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
38
+
39
+ ## Another termination condition in minutes. Set it large enough to avoid
40
+ ## undesired early termination.
41
+ EXIT_DURATION=30000000
42
+ ###############################################################################
43
+ ### LR configs
44
+ ## LR warmup and decay duration, this token-based config is preferable since
45
+ ## no need to readjust when the batch size/seqlen is changed.
46
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
47
+ WARMUP_TOKENS=375000000
48
+ LR_DECAY_TOKENS=260000000000
49
+ ###############################################################################
50
+ ### Parallelism configs
51
+ ## Micro batch size per GPU
52
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
53
+ BATCH_SIZE=4
54
+
55
+ ## Model parallelism, 1 is no MP
56
+ MP_SIZE=1
57
+
58
+ ## Pipeline parallelism. To disable PP, set PP_SIZE to 1 and NO_PP to true.
59
+ PP_SIZE=1
60
+ NO_PP="true"
61
+
62
+ ## ZeRO stage
63
+ ZERO_STAGE=0
64
+
65
+ ## Total number of GPUs
66
+ NUM_GPUS=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
67
+ NUM_GPUS_PERNODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
68
+ NUM_NODE=$(( ${NUM_GPUS} / ${NUM_GPUS_PERNODE} ))
69
+ DP_SIZE=$(( ${NUM_GPUS} / ${PP_SIZE} / ${MP_SIZE} ))
70
+ ###############################################################################
71
+ ### Curriculum learning (CL) configs
72
+ ## Enable/disable CL
73
+ CL_ENABLED="false"
74
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
75
+ ## for tuning the following configs
76
+ CL_START_SEQLEN=72
77
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
78
+ CL_TOKENS=60
79
+ CL_STEP=$(( ${CL_TOKENS} * 1000000000 / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
80
+ ###############################################################################
81
+ ### Misc configs
82
+ LOG_INTERVAL=10
83
+ EVAL_ITERS=10
84
+ EVAL_INTERVAL=100
85
+ SAVE_INTERVAL=1000
86
+
87
+ ## Standard deviation for weight initialization. Usually larger model needs
88
+ ## lower std. We used a heuristic equation of sqrt(1/3/HIDDEN_SIZE) from the
89
+ ## MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
90
+ INIT_STD=0.02
91
+
92
+ ## Activation checkpointing saves GPU memory, but reduces training speed
93
+ # ACTIVATION_CHECKPOINT="true"
94
+ ACTIVATION_CHECKPOINT="false"
95
+
96
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
97
+ ## This is not required for training and might save GPU memory when turned off.
98
+ LOG_OPTIMIZER_STATE="true"
99
+ ###############################################################################
100
+ ### Output and data configs
101
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
102
+ host="${HOSTNAME}"
103
+ NAME="125M10L_Compression_Test_INT8_64gpu_lr6e-5_tokens5.25B_nocl"
104
+ if [ "${NO_PP}" = "true" ]; then
105
+ NAME="${NAME}-no_pp"
106
+ fi
107
+ if [ "${CL_ENABLED}" = "true" ]; then
108
+ NAME="${NAME}-cl-startseqlen-${CL_START_SEQLEN}-step-${CL_STEP}-token-${CL_TOKENS}B"
109
+ fi
110
+
111
+ LOG_PATH="log/"
112
+ TENSORBOARD_PATH="tensorboard/${NAME}_${host}_${current_time}"
113
+ CHECKPOINT_PATH="/blob/users/zheweiyao/compression_library/checkpoint/${NAME}"
114
+ mkdir -p ${LOG_PATH}
115
+ mkdir -p ${TENSORBOARD_PATH}
116
+ mkdir -p ${CHECKPOINT_PATH}
117
+
118
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
119
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
120
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
121
+ # For cluster Azure-EastUS-V100-32GB-4, Lab-RR1-V100
122
+ # DATA_PATH=/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing/pile_text_document
123
+ # For cluster Azure-WestUS3-A100
124
+ DATA_PATH=/blob/data/the_pile_public_merged_nopreprocessing/pile_text_document
125
+ ###############################################################################
126
+ data_options=" \
127
+ --vocab-file ${VOCAB_PATH} \
128
+ --merge-file ${MERGE_PATH} \
129
+ --data-path ${DATA_PATH} \
130
+ --data-impl mmap"
131
+
132
+ megatron_options=" \
133
+ --override-lr-scheduler \
134
+ --adam-beta1 0.9 \
135
+ --adam-beta2 0.95 \
136
+ --tensor-model-parallel-size ${MP_SIZE} \
137
+ --init-method-std ${INIT_STD} \
138
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
139
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
140
+ --micro-batch-size ${BATCH_SIZE} \
141
+ --exit-duration-in-mins ${EXIT_DURATION} \
142
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
143
+ --num-layers 10 \
144
+ --hidden-size ${HIDDEN_SIZE} \
145
+ --num-attention-heads ${NUM_ATTN_HEADS} \
146
+ --seq-length ${SEQ_LEN} \
147
+ --max-position-embeddings ${SEQ_LEN} \
148
+ --train-tokens ${TRAIN_TOKENS} \
149
+ --train-samples ${TRAIN_SAMPLES} \
150
+ --lr ${LR} \
151
+ --min-lr ${MIN_LR} \
152
+ --lr-decay-style cosine \
153
+ --split 98,2,0 \
154
+ --log-interval ${LOG_INTERVAL} \
155
+ --eval-interval ${EVAL_INTERVAL} \
156
+ --eval-iters ${EVAL_ITERS} \
157
+ --save-interval ${SAVE_INTERVAL} \
158
+ --weight-decay 0.1 \
159
+ --clip-grad 1.0 \
160
+ --hysteresis 2 \
161
+ --num-workers 0 \
162
+ --fp16 \
163
+ --load /blob/users/minjiaz/project/gpt3_distillation/checkpoint/gpt3-kd-staged-alpha1-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-32-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-27638-token-60B/ \
164
+ --save ${CHECKPOINT_PATH} \
165
+ --tensorboard-queue-size 1 \
166
+ --log-timers-to-tensorboard \
167
+ --log-batch-size-to-tensorboard \
168
+ --no-load-lr-state \
169
+ --reset-iteration \
170
+ --log-validation-ppl-to-tensorboard \
171
+ --tensorboard-dir ${TENSORBOARD_PATH}"
172
+
173
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
174
+ megatron_options="${megatron_options} \
175
+ --checkpoint-activations"
176
+ fi
177
+
178
+ if [ "${LOG_OPTIMIZER_STATE}" = "true" ]; then
179
+ megatron_options="${megatron_options} \
180
+ --log-optimizer-states-to-tensorboard"
181
+ fi
182
+
183
+ template_json="ds_config_gpt_TEMPLATE_compression.json"
184
+ config_json="ds_config_${NAME}.json"
185
+ if [[ $ZERO_STAGE -gt 0 ]]; then
186
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
187
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
188
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
189
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
190
+ | sed "s/PRESCALE_GRAD/false/" \
191
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
192
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
193
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
194
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
195
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
196
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
197
+ > ${config_json}
198
+ else
199
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
200
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
201
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
202
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
203
+ | sed "s/PRESCALE_GRAD/true/" \
204
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
205
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
206
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
207
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
208
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
209
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
210
+ > ${config_json}
211
+ fi
212
+
213
+ deepspeed_options=" \
214
+ --deepspeed \
215
+ --deepspeed_config ${config_json} \
216
+ --zero-stage ${ZERO_STAGE} \
217
+ --pipeline-model-parallel-size ${PP_SIZE}"
218
+
219
+ if [[ "${NO_PP}" = "true" ]]; then
220
+ deepspeed_options="${deepspeed_options} \
221
+ --no-pipeline-parallel"
222
+ fi
223
+
224
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
225
+ deepspeed_options="${deepspeed_options} \
226
+ --deepspeed-activation-checkpointing"
227
+ fi
228
+
229
+ ## When saving checkpoint to a storage with cache, their could be consistency
230
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
231
+ ## and broadcast it to all nodes.
232
+ ITERATION_FILE="$CHECKPOINT_PATH/latest_checkpointed_iteration.txt"
233
+ ITERATION_FILE_2="$CHECKPOINT_PATH/latest"
234
+ ITERATION=0
235
+ for (( node = 0; node <= NUM_NODE-1; node++ ))
236
+ do
237
+ if $(ssh -q worker-"$node" "test -f \"$ITERATION_FILE\""); then
238
+ LOCAL_ITERATION=$(ssh -q worker-"$node" cat $ITERATION_FILE)
239
+ ITERATION=$(( ${LOCAL_ITERATION} > ${ITERATION} ? ${LOCAL_ITERATION} : ${ITERATION} ))
240
+ fi
241
+ done
242
+ if [[ $ITERATION -gt 0 ]]; then
243
+ ITERATION_2="global_step${ITERATION}"
244
+ ds_ssh "echo $ITERATION > $ITERATION_FILE"
245
+ ds_ssh "echo $ITERATION_2 > $ITERATION_FILE_2"
246
+ fi
247
+
248
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${LOG_PATH}/${NAME}.log"
249
+ # run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options}"
250
+
251
+ echo ${run_cmd}
252
+ eval ${run_cmd}
253
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/125M-L10-Int8-test-64gpu-distilled-group48.sh ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ MODEL_SIZE=0.125
14
+ NUM_LAYERS=12
15
+ HIDDEN_SIZE=768
16
+ NUM_ATTN_HEADS=12
17
+ GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ LR=6.0e-5
20
+ MIN_LR=6.0e-5
21
+
22
+ # Curriculum learning (CL) enables stable large-batch training
23
+ # GLOBAL_BATCH_SIZE=16 # 8x
24
+ # LR=6e-4 # 4x
25
+
26
+ ###############################################################################
27
+ ### Training duration configs
28
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
29
+ # TRAIN_TOKENS=300000000000
30
+ TRAIN_TOKENS=5250000000
31
+
32
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
33
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
34
+ ## above, and techniques like curriculum learning has less token in some samples,
35
+ ## so we just set this config large enough to make sure we have enough
36
+ ## processed data and don't terminate by TRAIN_SAMPLES.
37
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
38
+
39
+ ## Another termination condition in minutes. Set it large enough to avoid
40
+ ## undesired early termination.
41
+ EXIT_DURATION=30000000
42
+ ###############################################################################
43
+ ### LR configs
44
+ ## LR warmup and decay duration, this token-based config is preferable since
45
+ ## no need to readjust when the batch size/seqlen is changed.
46
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
47
+ WARMUP_TOKENS=375000000
48
+ LR_DECAY_TOKENS=260000000000
49
+ ###############################################################################
50
+ ### Parallelism configs
51
+ ## Micro batch size per GPU
52
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
53
+ BATCH_SIZE=4
54
+
55
+ ## Model parallelism, 1 is no MP
56
+ MP_SIZE=1
57
+
58
+ ## Pipeline parallelism. To disable PP, set PP_SIZE to 1 and NO_PP to true.
59
+ PP_SIZE=1
60
+ NO_PP="true"
61
+
62
+ ## ZeRO stage
63
+ ZERO_STAGE=0
64
+
65
+ ## Total number of GPUs
66
+ NUM_GPUS=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
67
+ NUM_GPUS_PERNODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
68
+ NUM_NODE=$(( ${NUM_GPUS} / ${NUM_GPUS_PERNODE} ))
69
+ DP_SIZE=$(( ${NUM_GPUS} / ${PP_SIZE} / ${MP_SIZE} ))
70
+ ###############################################################################
71
+ ### Curriculum learning (CL) configs
72
+ ## Enable/disable CL
73
+ CL_ENABLED="false"
74
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
75
+ ## for tuning the following configs
76
+ CL_START_SEQLEN=72
77
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
78
+ CL_TOKENS=60
79
+ CL_STEP=$(( ${CL_TOKENS} * 1000000000 / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
80
+ ###############################################################################
81
+ ### Misc configs
82
+ LOG_INTERVAL=10
83
+ EVAL_ITERS=10
84
+ EVAL_INTERVAL=100
85
+ SAVE_INTERVAL=1000
86
+
87
+ ## Standard deviation for weight initialization. Usually larger model needs
88
+ ## lower std. We used a heuristic equation of sqrt(1/3/HIDDEN_SIZE) from the
89
+ ## MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
90
+ INIT_STD=0.02
91
+
92
+ ## Activation checkpointing saves GPU memory, but reduces training speed
93
+ # ACTIVATION_CHECKPOINT="true"
94
+ ACTIVATION_CHECKPOINT="false"
95
+
96
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
97
+ ## This is not required for training and might save GPU memory when turned off.
98
+ LOG_OPTIMIZER_STATE="true"
99
+ ###############################################################################
100
+ ### Output and data configs
101
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
102
+ host="${HOSTNAME}"
103
+ NAME="125M10L_Compression_Test_INT8_64gpu_lr6e-5_tokens5.25B_nocl_alpha"
104
+ if [ "${NO_PP}" = "true" ]; then
105
+ NAME="${NAME}-no_pp"
106
+ fi
107
+ if [ "${CL_ENABLED}" = "true" ]; then
108
+ NAME="${NAME}-cl-startseqlen-${CL_START_SEQLEN}-step-${CL_STEP}-token-${CL_TOKENS}B"
109
+ fi
110
+
111
+ LOG_PATH="log/"
112
+ TENSORBOARD_PATH="tensorboard/${NAME}_${host}_${current_time}"
113
+ CHECKPOINT_PATH="/blob/users/minjiaz/compression_library/checkpoint/${NAME}"
114
+ mkdir -p ${LOG_PATH}
115
+ mkdir -p ${TENSORBOARD_PATH}
116
+ mkdir -p ${CHECKPOINT_PATH}
117
+
118
+ VOCAB_PATH=/blob/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
119
+ MERGE_PATH=/blob/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
120
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
121
+ # For cluster Azure-EastUS-V100-32GB-4, Lab-RR1-V100
122
+ # DATA_PATH=/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing/pile_text_document
123
+ # For cluster Azure-WestUS3-A100
124
+ DATA_PATH=/blob/data/the_pile_public_merged_nopreprocessing/pile_text_document
125
+ ###############################################################################
126
+ data_options=" \
127
+ --vocab-file ${VOCAB_PATH} \
128
+ --merge-file ${MERGE_PATH} \
129
+ --data-path ${DATA_PATH} \
130
+ --data-impl mmap"
131
+
132
+ megatron_options=" \
133
+ --override-lr-scheduler \
134
+ --adam-beta1 0.9 \
135
+ --adam-beta2 0.95 \
136
+ --tensor-model-parallel-size ${MP_SIZE} \
137
+ --init-method-std ${INIT_STD} \
138
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
139
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
140
+ --micro-batch-size ${BATCH_SIZE} \
141
+ --exit-duration-in-mins ${EXIT_DURATION} \
142
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
143
+ --num-layers 10 \
144
+ --hidden-size ${HIDDEN_SIZE} \
145
+ --num-attention-heads ${NUM_ATTN_HEADS} \
146
+ --seq-length ${SEQ_LEN} \
147
+ --max-position-embeddings ${SEQ_LEN} \
148
+ --train-tokens ${TRAIN_TOKENS} \
149
+ --train-samples ${TRAIN_SAMPLES} \
150
+ --lr ${LR} \
151
+ --min-lr ${MIN_LR} \
152
+ --lr-decay-style cosine \
153
+ --split 98,2,0 \
154
+ --log-interval ${LOG_INTERVAL} \
155
+ --eval-interval ${EVAL_INTERVAL} \
156
+ --eval-iters ${EVAL_ITERS} \
157
+ --save-interval ${SAVE_INTERVAL} \
158
+ --weight-decay 0.1 \
159
+ --clip-grad 1.0 \
160
+ --hysteresis 2 \
161
+ --num-workers 0 \
162
+ --fp16 \
163
+ --load /blob/users/minjiaz/project/gpt3_distillation/checkpoint/gpt3-kd-staged-alpha1-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-32-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-27638-token-60B/ \
164
+ --save ${CHECKPOINT_PATH} \
165
+ --tensorboard-queue-size 1 \
166
+ --log-timers-to-tensorboard \
167
+ --log-batch-size-to-tensorboard \
168
+ --no-load-lr-state \
169
+ --reset-iteration \
170
+ --log-validation-ppl-to-tensorboard \
171
+ --tensorboard-dir ${TENSORBOARD_PATH}"
172
+
173
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
174
+ megatron_options="${megatron_options} \
175
+ --checkpoint-activations"
176
+ fi
177
+
178
+ if [ "${LOG_OPTIMIZER_STATE}" = "true" ]; then
179
+ megatron_options="${megatron_options} \
180
+ --log-optimizer-states-to-tensorboard"
181
+ fi
182
+
183
+ template_json="ds_config_gpt_TEMPLATE_compression.json"
184
+ config_json="ds_config_${NAME}.json"
185
+ if [[ $ZERO_STAGE -gt 0 ]]; then
186
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
187
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
188
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
189
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
190
+ | sed "s/PRESCALE_GRAD/false/" \
191
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
192
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
193
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
194
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
195
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
196
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
197
+ > ${config_json}
198
+ else
199
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
200
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
201
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
202
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
203
+ | sed "s/PRESCALE_GRAD/true/" \
204
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
205
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
206
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
207
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
208
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
209
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
210
+ > ${config_json}
211
+ fi
212
+
213
+ deepspeed_options=" \
214
+ --deepspeed \
215
+ --deepspeed_config ${config_json} \
216
+ --zero-stage ${ZERO_STAGE} \
217
+ --pipeline-model-parallel-size ${PP_SIZE}"
218
+
219
+ if [[ "${NO_PP}" = "true" ]]; then
220
+ deepspeed_options="${deepspeed_options} \
221
+ --no-pipeline-parallel"
222
+ fi
223
+
224
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
225
+ deepspeed_options="${deepspeed_options} \
226
+ --deepspeed-activation-checkpointing"
227
+ fi
228
+
229
+ ## When saving checkpoint to a storage with cache, their could be consistency
230
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
231
+ ## and broadcast it to all nodes.
232
+ ITERATION_FILE="$CHECKPOINT_PATH/latest_checkpointed_iteration.txt"
233
+ ITERATION_FILE_2="$CHECKPOINT_PATH/latest"
234
+ ITERATION=0
235
+ for (( node = 0; node <= NUM_NODE-1; node++ ))
236
+ do
237
+ if $(ssh -q worker-"$node" "test -f \"$ITERATION_FILE\""); then
238
+ LOCAL_ITERATION=$(ssh -q worker-"$node" cat $ITERATION_FILE)
239
+ ITERATION=$(( ${LOCAL_ITERATION} > ${ITERATION} ? ${LOCAL_ITERATION} : ${ITERATION} ))
240
+ fi
241
+ done
242
+ if [[ $ITERATION -gt 0 ]]; then
243
+ ITERATION_2="global_step${ITERATION}"
244
+ ds_ssh "echo $ITERATION > $ITERATION_FILE"
245
+ ds_ssh "echo $ITERATION_2 > $ITERATION_FILE_2"
246
+ fi
247
+
248
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${LOG_PATH}/${NAME}.log"
249
+ # run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options}"
250
+
251
+ echo ${run_cmd}
252
+ eval ${run_cmd}
253
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_config_gpt_TEMPLATE.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size" : CONFIG_BATCH_SIZE,
3
+ "train_micro_batch_size_per_gpu": CONFIG_MBSIZE,
4
+ "steps_per_print": LOG_INTERVAL,
5
+
6
+ "zero_optimization": {
7
+ "stage": ZERO_STAGE,
8
+ "elastic_checkpoint": true
9
+ },
10
+
11
+ "gradient_clipping": 1.0,
12
+ "prescale_gradients": PRESCALE_GRAD,
13
+
14
+ "fp16": {
15
+ "enabled": CONFIG_FP16_ENABLED,
16
+ "loss_scale": 0,
17
+ "loss_scale_window": 500,
18
+ "hysteresis": 2,
19
+ "min_loss_scale": 1,
20
+ "initial_scale_power": 11
21
+ },
22
+
23
+ "bf16": {
24
+ "enabled": CONFIG_BF16_ENABLED
25
+ },
26
+ "curriculum_learning": {
27
+ "enabled": CONFIG_CL_ENABLED,
28
+ "curriculum_type": "seqlen",
29
+ "min_difficulty": CONFIG_CL_MIN,
30
+ "max_difficulty": CONFIG_CL_MAX,
31
+ "schedule_type": "fixed_linear",
32
+ "schedule_config": {
33
+ "total_curriculum_step": CONFIG_CL_DURATION,
34
+ "difficulty_step": 8
35
+ }
36
+ },
37
+
38
+ "wall_clock_breakdown" : false
39
+ }
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_config_gpt_TEMPLATE_compression.json ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size" : CONFIG_BATCH_SIZE,
3
+ "train_micro_batch_size_per_gpu": CONFIG_MBSIZE,
4
+ "steps_per_print": LOG_INTERVAL,
5
+
6
+ "zero_optimization": {
7
+ "stage": ZERO_STAGE,
8
+ "elastic_checkpoint": true
9
+ },
10
+
11
+ "gradient_clipping": 1.0,
12
+ "prescale_gradients": PRESCALE_GRAD,
13
+
14
+ "fp16": {
15
+ "enabled": CONFIG_FP16_ENABLED,
16
+ "loss_scale": 0,
17
+ "loss_scale_window": 500,
18
+ "hysteresis": 2,
19
+ "min_loss_scale": 1,
20
+ "initial_scale_power": 11
21
+ },
22
+
23
+ "bf16": {
24
+ "enabled": CONFIG_BF16_ENABLED
25
+ },
26
+ "curriculum_learning": {
27
+ "enabled": CONFIG_CL_ENABLED,
28
+ "curriculum_type": "seqlen",
29
+ "min_difficulty": CONFIG_CL_MIN,
30
+ "max_difficulty": CONFIG_CL_MAX,
31
+ "schedule_type": "fixed_linear",
32
+ "schedule_config": {
33
+ "total_curriculum_step": CONFIG_CL_DURATION,
34
+ "difficulty_step": 8
35
+ }
36
+ },
37
+
38
+ "wall_clock_breakdown" : false,
39
+
40
+ "compression_training": {
41
+ "weight_quantization": {
42
+ "shared_parameters":{
43
+ "enabled": true,
44
+ "quantizer_kernel": false,
45
+ "schedule_offset": 50,
46
+ "quantize_groups": 48,
47
+ "quantize_verbose": false,
48
+ "quantization_type": "symmetric",
49
+ "rounding": "nearest",
50
+ "fp16_mixed_quantize":{
51
+ "enabled": false,
52
+ "quantize_change_ratio": 0.001
53
+ }
54
+ },
55
+ "different_groups":{
56
+ "wq1": {
57
+ "params": {
58
+ "start_bits": 12,
59
+ "target_bits": 4,
60
+ "quantization_period": 50
61
+ },
62
+ "modules": [
63
+ "encoder.layers"
64
+ ]
65
+ }
66
+ }
67
+ },
68
+ "activation_quantization": {
69
+ "shared_parameters":{
70
+ "enabled": true,
71
+ "quantization_type": "asymmetric",
72
+ "range_calibration": "static",
73
+ "schedule_offset": 50
74
+ },
75
+ "different_groups":{
76
+ "aq1": {
77
+ "params": {
78
+ "bits": 8
79
+ },
80
+ "modules": [
81
+ "encoder.layers"
82
+ ]
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_evalharness.sh ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is an example zero-shot eval script. Please first read the readme_evalharness.md under the same directory.
2
+
3
+ # CHECKPOINT_PATH=/blob/users/minjiaz/compression_library/checkpoint/125M10L_Compression_Test_INT8_64gpu_lr6e-5_tokens5.25B_nocl_alpha-no_pp/global_step2000/
4
+ # CHECKPOINT_PATH=/blob/users/conglli/project/gpt3_with_pile/checkpoint/gpt3-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-64-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-27638-token-60B/global_step71000/
5
+ # CHECKPOINT_PATH=/blob/users/minjiaz/compression_library/checkpoint/125M12L_Compression_Test_INT8_64gpu_lr6e-5_tokens5.25B_nocl_alpha-no_pp/global_step5000/
6
+ CHECKPOINT_PATH=/blob/users/minjiaz/project/gpt3_distillation/checkpoint/gpt3-kd-test2-alpha1-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-15-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-27638-token-60B/global_step71426/
7
+ CONFIG_PATH=ds_config_gpt3-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus--1-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-27638-token-60B.json
8
+ RESULT_PATH=gpt3-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-128-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-20728-token-45B_global_step81566.log
9
+
10
+ PP_SIZE=1
11
+ TP_SIZE=1
12
+ NO_PP="true"
13
+ EP_PARALLEL_SIZE=1
14
+ # Currently eval harness does not support data parallel
15
+ # However, for MoE models it's possible to enable a "fake data parallel"
16
+ # in order to load experts on multiple gpus. At the same time, it's not
17
+ # real data parallel because we load the same data on all gpus.
18
+ # On the other hand, it's better to use less number of gpus than training,
19
+ # to reduce communication overhead.
20
+ NUM_NODE=1
21
+ NUM_GPU_PER_NODE=1
22
+
23
+ # TASKS="lambada"
24
+ # WikiText-2, not used in GPT-3 paper but used in GPT-2 paper
25
+ TASKS="lambada,wikitext"
26
+ # Tasks that appeared in GPT-3 paper (sorted based on the order in paper), plus WikiText-2.
27
+ # TASKS="hellaswag,lambada,triviaqa,webqs,winogrande,piqa,arc_challenge,arc_easy,openbookqa,race,boolq,cb,copa,rte,wic,wsc,multirc,record,anli_r1,anli_r2,anli_r3,wikitext"
28
+ # All tasks that confirmed to work, there are more tasks on https://github.com/EleutherAI/lm-evaluation-harness that we didn't test.
29
+ # TASKS="hellaswag,lambada,triviaqa,webqs,winogrande,piqa,arc_challenge,arc_easy,openbookqa,race,boolq,cb,copa,rte,wic,wsc,multirc,record,anli_r1,anli_r2,anli_r3,wikitext,logiqa,mathqa,mc_taco,mrpc,prost,pubmedqa,qnli,qqp,sciq,sst,wnli"
30
+
31
+ VOCAB_FILE=/blob/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
32
+ MERGE_FILE=/blob/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
33
+
34
+ export HF_DATASETS_OFFLINE=1
35
+
36
+ # Dummy arguments to make megatron happy. No need to configure them.
37
+ # The reason we don't need to configure them and many other arguments is
38
+ # because the eval framework will read the arguments from checkpoint file.
39
+ MEGATRON_REQUIRED_ARGS="\
40
+ --num-layers -1\
41
+ --hidden-size -1\
42
+ --num-attention-heads -1\
43
+ --seq-length -1 \
44
+ --max-position-embeddings -1
45
+ "
46
+
47
+ CMD="../../tasks/eval_harness/evaluate.py \
48
+ --load $CHECKPOINT_PATH\
49
+ --tensor-model-parallel-size $TP_SIZE \
50
+ --pipeline-model-parallel-size $PP_SIZE\
51
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
52
+ --vocab-file $VOCAB_FILE\
53
+ --merge-file $MERGE_FILE\
54
+ --micro-batch-size 12\
55
+ --no-load-optim \
56
+ --no-load-rng \
57
+ --inference \
58
+ --disable-moe-token-dropping \
59
+ --adaptive_seq_len\
60
+ --eval_fp32\
61
+ --task_list $TASKS\
62
+ --results_path $RESULT_PATH \
63
+ --deepspeed \
64
+ --deepspeed_config $CONFIG_PATH \
65
+ $MEGATRON_REQUIRED_ARGS\
66
+ "
67
+
68
+ if [[ "${NO_PP}" = "true" ]]; then
69
+ CMD="${CMD} \
70
+ --no-pipeline-parallel"
71
+ fi
72
+
73
+ LAUNCHER="deepspeed --num_nodes $NUM_NODE --num_gpus $NUM_GPU_PER_NODE"
74
+ $LAUNCHER $CMD
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_pretrain_gpt_1.3B_dense_cl_kd.sh ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ # MODEL_SIZE=0.35
23
+ # NUM_LAYERS=24
24
+ # HIDDEN_SIZE=1024
25
+ # NUM_ATTN_HEADS=16
26
+ # GLOBAL_BATCH_SIZE=256
27
+ # LR=3.0e-4
28
+ # MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ MODEL_SIZE=1.3
41
+ NUM_LAYERS=24
42
+ HIDDEN_SIZE=2048
43
+ NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ MIN_LR=2.0e-5
47
+
48
+ # Curriculum learning (CL) enables stable large-batch training
49
+ GLOBAL_BATCH_SIZE=4096 # 8x
50
+ LR=8.0e-4 # 4x
51
+
52
+ ## GPT-3 2.7B
53
+ # MODEL_SIZE=2.7
54
+ # NUM_LAYERS=32
55
+ # HIDDEN_SIZE=2560
56
+ # NUM_ATTN_HEADS=32
57
+ # GLOBAL_BATCH_SIZE=512
58
+ # LR=1.6e-4
59
+ # MIN_LR=1.6e-5
60
+
61
+ ## GPT-3 6.7B
62
+ # MODEL_SIZE=6.7
63
+ # NUM_LAYERS=32
64
+ # HIDDEN_SIZE=4096
65
+ # NUM_ATTN_HEADS=32
66
+ # GLOBAL_BATCH_SIZE=1024
67
+ # LR=1.2e-4
68
+ # MIN_LR=1.2e-5
69
+
70
+ ## GPT-3 13B
71
+ # MODEL_SIZE=13
72
+ # NUM_LAYERS=40
73
+ # HIDDEN_SIZE=5120
74
+ # NUM_ATTN_HEADS=40
75
+ # GLOBAL_BATCH_SIZE=1024
76
+ # LR=1.0e-4
77
+ # MIN_LR=1.0e-5
78
+
79
+ ## GPT-3 175B
80
+ # MODEL_SIZE=175
81
+ # NUM_LAYERS=96
82
+ # HIDDEN_SIZE=12288
83
+ # NUM_ATTN_HEADS=96
84
+ # GLOBAL_BATCH_SIZE=1536
85
+ # LR=0.6e-4
86
+ # MIN_LR=0.6e-5
87
+ ###############################################################################
88
+ ### Training duration configs
89
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
90
+ TRAIN_TOKENS=300000000000
91
+
92
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
93
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
94
+ ## above, and techniques like curriculum learning has less token in some samples,
95
+ ## so we just set this config large enough to make sure we have enough
96
+ ## processed data and don't terminate by TRAIN_SAMPLES.
97
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
98
+
99
+ ## Another termination condition in minutes. Set it large enough to avoid
100
+ ## undesired early termination.
101
+ EXIT_DURATION=30000000
102
+ ###############################################################################
103
+ ### LR configs
104
+ ## LR warmup and decay duration, this token-based config is preferable since
105
+ ## no need to readjust when the batch size/seqlen is changed.
106
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
107
+ WARMUP_TOKENS=375000000
108
+ LR_DECAY_TOKENS=260000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=16
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ MP_SIZE=2
117
+
118
+ ## Pipeline parallelism. To disable PP, set PP_SIZE to 1 and NO_PP to true.
119
+ PP_SIZE=1
120
+ NO_PP="true"
121
+
122
+ ## ZeRO stage
123
+ ZERO_STAGE=0
124
+
125
+ ## Total number of GPUs
126
+ NUM_GPUS=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
127
+ NUM_GPUS_PERNODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
128
+ NUM_NODE=$(( ${NUM_GPUS} / ${NUM_GPUS_PERNODE} ))
129
+ DP_SIZE=$(( ${NUM_GPUS} / ${PP_SIZE} / ${MP_SIZE} ))
130
+ ###############################################################################
131
+ ### Curriculum learning (CL) configs
132
+ ## Enable/disable CL
133
+ CL_ENABLED="true"
134
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
135
+ ## for tuning the following configs
136
+ CL_START_SEQLEN=80
137
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
138
+ CL_TOKENS=60
139
+ CL_STEP=$(( ${CL_TOKENS} * 1000000000 / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
140
+ ###############################################################################
141
+ ### Misc configs
142
+ LOG_INTERVAL=10
143
+ EVAL_ITERS=10
144
+ EVAL_INTERVAL=100
145
+ SAVE_INTERVAL=10000
146
+
147
+ ## Standard deviation for weight initialization. Usually larger model needs
148
+ ## lower std. We used a heuristic equation of sqrt(1/3/HIDDEN_SIZE) from the
149
+ ## MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
150
+ INIT_STD=0.013
151
+
152
+ ## Activation checkpointing saves GPU memory, but reduces training speed
153
+ ACTIVATION_CHECKPOINT="true"
154
+ # ACTIVATION_CHECKPOINT="false"
155
+
156
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
157
+ ## This is not required for training and might save GPU memory when turned off.
158
+ LOG_OPTIMIZER_STATE="true"
159
+ ###############################################################################
160
+ ### Output and data configs
161
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
162
+ host="${HOSTNAME}"
163
+ NAME="gpt3-kd-with-pile-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-zero-${ZERO_STAGE}-mp-${MP_SIZE}-pp-${PP_SIZE}"
164
+ if [ "${NO_PP}" = "true" ]; then
165
+ NAME="${NAME}-no_pp"
166
+ fi
167
+ if [ "${CL_ENABLED}" = "true" ]; then
168
+ NAME="${NAME}-cl-startseqlen-${CL_START_SEQLEN}-step-${CL_STEP}-token-${CL_TOKENS}B"
169
+ fi
170
+
171
+ LOG_PATH="log/"
172
+ TENSORBOARD_PATH="tensorboard/${NAME}_${host}_${current_time}"
173
+ CHECKPOINT_PATH="/blob/users/minjiaz/project/gpt3_distillation/checkpoint/${NAME}"
174
+ mkdir -p ${LOG_PATH}
175
+ mkdir -p ${TENSORBOARD_PATH}
176
+ mkdir -p ${CHECKPOINT_PATH}
177
+
178
+ ### KD configs
179
+ KD_BETA_CE=1
180
+ CHECKPOINT_PATH_TEACHER="/blob/users/conglli/project/gpt3_with_pile/checkpoint/gpt3-with-pile-1.3B-lr-8.0e-4-minlr-2.0e-5-bs-4096-gpus-128-zero-0-mp-2-pp-1-no_pp-cl-startseqlen-80-step-13767-token-60B/"
181
+ CHECKPOINT_PATH_SAVE="/blob/users/minjiaz/project/gpt3_distillation/checkpoint/${NAME}"
182
+
183
+ mkdir -p ${CHECKPOINT_PATH_SAVE}
184
+
185
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
186
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
187
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
188
+ # DATA_PATH=/data/the_pile_public_merged_nopreprocessing/pile_text_document
189
+ # For cluster Azure-WestUS3-A100
190
+ DATA_PATH=/blob/data/the_pile_public_merged_nopreprocessing/pile_text_document
191
+
192
+ ###############################################################################
193
+ data_options=" \
194
+ --vocab-file ${VOCAB_PATH} \
195
+ --merge-file ${MERGE_PATH} \
196
+ --data-path ${DATA_PATH} \
197
+ --data-impl mmap"
198
+
199
+ megatron_options=" \
200
+ --override-lr-scheduler \
201
+ --adam-beta1 0.9 \
202
+ --adam-beta2 0.95 \
203
+ --tensor-model-parallel-size ${MP_SIZE} \
204
+ --init-method-std ${INIT_STD} \
205
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
206
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
207
+ --micro-batch-size ${BATCH_SIZE} \
208
+ --exit-duration-in-mins ${EXIT_DURATION} \
209
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
210
+ --num-layers 21 \
211
+ --hidden-size ${HIDDEN_SIZE} \
212
+ --num-attention-heads ${NUM_ATTN_HEADS} \
213
+ --seq-length ${SEQ_LEN} \
214
+ --max-position-embeddings ${SEQ_LEN} \
215
+ --train-tokens ${TRAIN_TOKENS} \
216
+ --train-samples ${TRAIN_SAMPLES} \
217
+ --lr ${LR} \
218
+ --min-lr ${MIN_LR} \
219
+ --lr-decay-style cosine \
220
+ --split 98,2,0 \
221
+ --log-interval ${LOG_INTERVAL} \
222
+ --eval-interval ${EVAL_INTERVAL} \
223
+ --eval-iters ${EVAL_ITERS} \
224
+ --save-interval ${SAVE_INTERVAL} \
225
+ --weight-decay 0.1 \
226
+ --clip-grad 1.0 \
227
+ --hysteresis 2 \
228
+ --num-workers 0 \
229
+ --fp16 \
230
+ --load ${CHECKPOINT_PATH} \
231
+ --save ${CHECKPOINT_PATH_SAVE} \
232
+ --kd \
233
+ --kd-beta-ce ${KD_BETA_CE} \
234
+ --num-layers-teacher ${NUM_LAYERS} \
235
+ --hidden-size-teacher ${HIDDEN_SIZE} \
236
+ --num-attention-heads-teacher ${NUM_ATTN_HEADS} \
237
+ --load-teacher ${CHECKPOINT_PATH_TEACHER} \
238
+ --tensorboard-queue-size 1 \
239
+ --log-timers-to-tensorboard \
240
+ --log-batch-size-to-tensorboard \
241
+ --log-validation-ppl-to-tensorboard \
242
+ --tensorboard-dir ${TENSORBOARD_PATH}"
243
+
244
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
245
+ megatron_options="${megatron_options} \
246
+ --checkpoint-activations"
247
+ fi
248
+
249
+ if [ "${LOG_OPTIMIZER_STATE}" = "true" ]; then
250
+ megatron_options="${megatron_options} \
251
+ --log-optimizer-states-to-tensorboard"
252
+ fi
253
+
254
+ template_json="ds_config_gpt_TEMPLATE.json"
255
+ config_json="ds_config_${NAME}.json"
256
+ if [[ $ZERO_STAGE -gt 0 ]]; then
257
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
258
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
259
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
260
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
261
+ | sed "s/PRESCALE_GRAD/false/" \
262
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
263
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
264
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
265
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
266
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
267
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
268
+ > ${config_json}
269
+ else
270
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
271
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
272
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
273
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
274
+ | sed "s/PRESCALE_GRAD/true/" \
275
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
276
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
277
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
278
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
279
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
280
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
281
+ > ${config_json}
282
+ fi
283
+
284
+ deepspeed_options=" \
285
+ --deepspeed \
286
+ --deepspeed_config ${config_json} \
287
+ --zero-stage ${ZERO_STAGE} \
288
+ --pipeline-model-parallel-size ${PP_SIZE}"
289
+
290
+ if [[ "${NO_PP}" = "true" ]]; then
291
+ deepspeed_options="${deepspeed_options} \
292
+ --no-pipeline-parallel"
293
+ fi
294
+
295
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
296
+ deepspeed_options="${deepspeed_options} \
297
+ --deepspeed-activation-checkpointing"
298
+ fi
299
+
300
+ ## When saving checkpoint to a storage with cache, their could be consistency
301
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
302
+ ## and broadcast it to all nodes.
303
+ ITERATION_FILE="$CHECKPOINT_PATH/latest_checkpointed_iteration.txt"
304
+ ITERATION_FILE_2="$CHECKPOINT_PATH/latest"
305
+ ITERATION=0
306
+ for (( node = 0; node <= NUM_NODE-1; node++ ))
307
+ do
308
+ if $(ssh -q worker-"$node" "test -f \"$ITERATION_FILE\""); then
309
+ LOCAL_ITERATION=$(ssh -q worker-"$node" cat $ITERATION_FILE)
310
+ ITERATION=$(( ${LOCAL_ITERATION} > ${ITERATION} ? ${LOCAL_ITERATION} : ${ITERATION} ))
311
+ fi
312
+ done
313
+ if [[ $ITERATION -gt 0 ]]; then
314
+ ITERATION_2="global_step${ITERATION}"
315
+ ds_ssh "echo $ITERATION > $ITERATION_FILE"
316
+ ds_ssh "echo $ITERATION_2 > $ITERATION_FILE_2"
317
+ fi
318
+
319
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${LOG_PATH}/${NAME}_${host}_${current_time}.log"
320
+ echo ${run_cmd}
321
+ eval ${run_cmd}
322
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_pretrain_gpt_125M_dense_cl_kd.sh ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ MODEL_SIZE=0.125
14
+ NUM_LAYERS=12
15
+ HIDDEN_SIZE=768
16
+ NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ MIN_LR=6.0e-5
20
+
21
+ # Curriculum learning (CL) enables stable large-batch training
22
+ GLOBAL_BATCH_SIZE=2048 # 8x
23
+ LR=2.4e-3 # 4x
24
+
25
+ ## GPT-3 Medium 350M
26
+ # MODEL_SIZE=0.35
27
+ # NUM_LAYERS=24
28
+ # HIDDEN_SIZE=1024
29
+ # NUM_ATTN_HEADS=16
30
+ # GLOBAL_BATCH_SIZE=256
31
+ # LR=3.0e-4
32
+ # MIN_LR=3.0e-5
33
+
34
+ ## GPT-3 Large 760M
35
+ # MODEL_SIZE=0.76
36
+ # NUM_LAYERS=24
37
+ # HIDDEN_SIZE=1536
38
+ # NUM_ATTN_HEADS=16
39
+ # GLOBAL_BATCH_SIZE=256
40
+ # LR=2.5e-4
41
+ # MIN_LR=2.5e-5
42
+
43
+ ## GPT-3 XL 1.3B
44
+ # MODEL_SIZE=1.3
45
+ # NUM_LAYERS=24
46
+ # HIDDEN_SIZE=2048
47
+ # NUM_ATTN_HEADS=16
48
+ # GLOBAL_BATCH_SIZE=512
49
+ # LR=2.0e-4
50
+ # MIN_LR=2.0e-5
51
+
52
+ ## GPT-3 2.7B
53
+ # MODEL_SIZE=2.7
54
+ # NUM_LAYERS=32
55
+ # HIDDEN_SIZE=2560
56
+ # NUM_ATTN_HEADS=32
57
+ # GLOBAL_BATCH_SIZE=512
58
+ # LR=1.6e-4
59
+ # MIN_LR=1.6e-5
60
+
61
+ ## GPT-3 6.7B
62
+ # MODEL_SIZE=6.7
63
+ # NUM_LAYERS=32
64
+ # HIDDEN_SIZE=4096
65
+ # NUM_ATTN_HEADS=32
66
+ # GLOBAL_BATCH_SIZE=1024
67
+ # LR=1.2e-4
68
+ # MIN_LR=1.2e-5
69
+
70
+ ## GPT-3 13B
71
+ # MODEL_SIZE=13
72
+ # NUM_LAYERS=40
73
+ # HIDDEN_SIZE=5120
74
+ # NUM_ATTN_HEADS=40
75
+ # GLOBAL_BATCH_SIZE=1024
76
+ # LR=1.0e-4
77
+ # MIN_LR=1.0e-5
78
+
79
+ ## GPT-3 175B
80
+ # MODEL_SIZE=175
81
+ # NUM_LAYERS=96
82
+ # HIDDEN_SIZE=12288
83
+ # NUM_ATTN_HEADS=96
84
+ # GLOBAL_BATCH_SIZE=1536
85
+ # LR=0.6e-4
86
+ # MIN_LR=0.6e-5
87
+ ###############################################################################
88
+ ### Training duration configs
89
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
90
+ TRAIN_TOKENS=300000000000
91
+
92
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
93
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
94
+ ## above, and techniques like curriculum learning has less token in some samples,
95
+ ## so we just set this config large enough to make sure we have enough
96
+ ## processed data and don't terminate by TRAIN_SAMPLES.
97
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
98
+
99
+ ## Another termination condition in minutes. Set it large enough to avoid
100
+ ## undesired early termination.
101
+ EXIT_DURATION=30000000
102
+ ###############################################################################
103
+ ### LR configs
104
+ ## LR warmup and decay duration, this token-based config is preferable since
105
+ ## no need to readjust when the batch size/seqlen is changed.
106
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
107
+ WARMUP_TOKENS=375000000
108
+ LR_DECAY_TOKENS=260000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=8
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism. To disable PP, set PP_SIZE to 1 and NO_PP to true.
119
+ PP_SIZE=1
120
+ NO_PP="true"
121
+
122
+ ## ZeRO stage
123
+ ZERO_STAGE=0
124
+
125
+ ## Total number of GPUs
126
+ NUM_GPUS=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
127
+ NUM_GPUS_PERNODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
128
+ NUM_NODE=$(( ${NUM_GPUS} / ${NUM_GPUS_PERNODE} ))
129
+ DP_SIZE=$(( ${NUM_GPUS} / ${PP_SIZE} / ${MP_SIZE} ))
130
+ ###############################################################################
131
+ ### Curriculum learning (CL) configs
132
+ ## Enable/disable CL
133
+ CL_ENABLED="true"
134
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
135
+ ## for tuning the following configs
136
+ CL_START_SEQLEN=72
137
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
138
+ CL_TOKENS=60
139
+ CL_STEP=$(( ${CL_TOKENS} * 1000000000 / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
140
+ ###############################################################################
141
+ ### Misc configs
142
+ LOG_INTERVAL=10
143
+ EVAL_ITERS=10
144
+ EVAL_INTERVAL=100
145
+ SAVE_INTERVAL=10000
146
+
147
+ ## Standard deviation for weight initialization. Usually larger model needs
148
+ ## lower std. We used a heuristic equation of sqrt(1/3/HIDDEN_SIZE) from the
149
+ ## MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
150
+ INIT_STD=0.02
151
+
152
+ ## Activation checkpointing saves GPU memory, but reduces training speed
153
+ ACTIVATION_CHECKPOINT="true"
154
+ # ACTIVATION_CHECKPOINT="false"
155
+
156
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
157
+ ## This is not required for training and might save GPU memory when turned off.
158
+ LOG_OPTIMIZER_STATE="true"
159
+ ###############################################################################
160
+ ### Output and data configs
161
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
162
+ host="${HOSTNAME}"
163
+ NAME="gpt3-kd-test1-alpha1-with-pile-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-zero-${ZERO_STAGE}-mp-${MP_SIZE}-pp-${PP_SIZE}"
164
+ if [ "${NO_PP}" = "true" ]; then
165
+ NAME="${NAME}-no_pp"
166
+ fi
167
+ if [ "${CL_ENABLED}" = "true" ]; then
168
+ NAME="${NAME}-cl-startseqlen-${CL_START_SEQLEN}-step-${CL_STEP}-token-${CL_TOKENS}B"
169
+ fi
170
+
171
+ LOG_PATH="log/"
172
+ TENSORBOARD_PATH="tensorboard/${NAME}_${host}_${current_time}"
173
+ CHECKPOINT_PATH="/blob/users/minjiaz/project/gpt3_distillation/checkpoint/${NAME}"
174
+ mkdir -p ${LOG_PATH}
175
+ mkdir -p ${TENSORBOARD_PATH}
176
+ mkdir -p ${CHECKPOINT_PATH}
177
+
178
+ ### KD configs
179
+ KD_BETA_CE=1
180
+ CHECKPOINT_PATH_TEACHER="/blob/users/conglli/project/gpt3_with_pile/checkpoint/gpt3-with-pile-0.125B-lr-2.4e-3-minlr-6.0e-5-bs-2048-gpus-64-zero-0-mp-1-pp-1-no_pp-cl-startseqlen-72-step-27638-token-60B/"
181
+ CHECKPOINT_PATH_SAVE="/blob/users/minjiaz/project/gpt3_distillation/checkpoint/${NAME}"
182
+
183
+ mkdir -p ${CHECKPOINT_PATH_SAVE}
184
+
185
+
186
+ VOCAB_PATH=/blob/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
187
+ MERGE_PATH=/blob/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
188
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
189
+ # For cluster Azure-EastUS-V100-32GB-4, Lab-RR1-V100
190
+ # DATA_PATH=/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing/pile_text_document
191
+ # For cluster Azure-WestUS3-A100
192
+ DATA_PATH=/blob/data/the_pile_public_merged_nopreprocessing/pile_text_document
193
+ ###############################################################################
194
+ data_options=" \
195
+ --vocab-file ${VOCAB_PATH} \
196
+ --merge-file ${MERGE_PATH} \
197
+ --data-path ${DATA_PATH} \
198
+ --data-impl mmap"
199
+
200
+ megatron_options=" \
201
+ --override-lr-scheduler \
202
+ --adam-beta1 0.9 \
203
+ --adam-beta2 0.95 \
204
+ --tensor-model-parallel-size ${MP_SIZE} \
205
+ --init-method-std ${INIT_STD} \
206
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
207
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
208
+ --micro-batch-size ${BATCH_SIZE} \
209
+ --exit-duration-in-mins ${EXIT_DURATION} \
210
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
211
+ --num-layers 10 \
212
+ --hidden-size ${HIDDEN_SIZE} \
213
+ --num-attention-heads ${NUM_ATTN_HEADS} \
214
+ --seq-length ${SEQ_LEN} \
215
+ --max-position-embeddings ${SEQ_LEN} \
216
+ --train-tokens ${TRAIN_TOKENS} \
217
+ --train-samples ${TRAIN_SAMPLES} \
218
+ --lr ${LR} \
219
+ --min-lr ${MIN_LR} \
220
+ --lr-decay-style cosine \
221
+ --split 98,2,0 \
222
+ --log-interval ${LOG_INTERVAL} \
223
+ --eval-interval ${EVAL_INTERVAL} \
224
+ --eval-iters ${EVAL_ITERS} \
225
+ --save-interval ${SAVE_INTERVAL} \
226
+ --weight-decay 0.1 \
227
+ --clip-grad 1.0 \
228
+ --hysteresis 2 \
229
+ --num-workers 0 \
230
+ --fp16 \
231
+ --load ${CHECKPOINT_PATH} \
232
+ --save ${CHECKPOINT_PATH_SAVE} \
233
+ --kd \
234
+ --kd-beta-ce ${KD_BETA_CE} \
235
+ --num-layers-teacher ${NUM_LAYERS} \
236
+ --hidden-size-teacher ${HIDDEN_SIZE} \
237
+ --num-attention-heads-teacher ${NUM_ATTN_HEADS} \
238
+ --load-teacher ${CHECKPOINT_PATH_TEACHER} \
239
+ --tensorboard-queue-size 1 \
240
+ --log-timers-to-tensorboard \
241
+ --log-batch-size-to-tensorboard \
242
+ --log-validation-ppl-to-tensorboard \
243
+ --tensorboard-dir ${TENSORBOARD_PATH}"
244
+
245
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
246
+ megatron_options="${megatron_options} \
247
+ --checkpoint-activations"
248
+ fi
249
+
250
+ if [ "${LOG_OPTIMIZER_STATE}" = "true" ]; then
251
+ megatron_options="${megatron_options} \
252
+ --log-optimizer-states-to-tensorboard"
253
+ fi
254
+
255
+ template_json="ds_config_gpt_TEMPLATE.json"
256
+ config_json="ds_config_${NAME}.json"
257
+ if [[ $ZERO_STAGE -gt 0 ]]; then
258
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
259
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
260
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
261
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
262
+ | sed "s/PRESCALE_GRAD/false/" \
263
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
264
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
265
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
266
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
267
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
268
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
269
+ > ${config_json}
270
+ else
271
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
272
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
273
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
274
+ | sed "s/ZERO_STAGE/${ZERO_STAGE}/" \
275
+ | sed "s/PRESCALE_GRAD/true/" \
276
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
277
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
278
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
279
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
280
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
281
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
282
+ > ${config_json}
283
+ fi
284
+
285
+ deepspeed_options=" \
286
+ --deepspeed \
287
+ --deepspeed_config ${config_json} \
288
+ --zero-stage ${ZERO_STAGE} \
289
+ --pipeline-model-parallel-size ${PP_SIZE}"
290
+
291
+ if [[ "${NO_PP}" = "true" ]]; then
292
+ deepspeed_options="${deepspeed_options} \
293
+ --no-pipeline-parallel"
294
+ fi
295
+
296
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
297
+ deepspeed_options="${deepspeed_options} \
298
+ --deepspeed-activation-checkpointing"
299
+ fi
300
+
301
+ ## When saving checkpoint to a storage with cache, their could be consistency
302
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
303
+ ## and broadcast it to all nodes.
304
+ ITERATION_FILE="$CHECKPOINT_PATH/latest_checkpointed_iteration.txt"
305
+ ITERATION_FILE_2="$CHECKPOINT_PATH/latest"
306
+ ITERATION=0
307
+ for (( node = 0; node <= NUM_NODE-1; node++ ))
308
+ do
309
+ if $(ssh -q worker-"$node" "test -f \"$ITERATION_FILE\""); then
310
+ LOCAL_ITERATION=$(ssh -q worker-"$node" cat $ITERATION_FILE)
311
+ ITERATION=$(( ${LOCAL_ITERATION} > ${ITERATION} ? ${LOCAL_ITERATION} : ${ITERATION} ))
312
+ fi
313
+ done
314
+ if [[ $ITERATION -gt 0 ]]; then
315
+ ITERATION_2="global_step${ITERATION}"
316
+ ds_ssh "echo $ITERATION > $ITERATION_FILE"
317
+ ds_ssh "echo $ITERATION_2 > $ITERATION_FILE_2"
318
+ fi
319
+
320
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${LOG_PATH}/${NAME}_${host}_${current_time}.log"
321
+ echo ${run_cmd}
322
+ eval ${run_cmd}
323
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/compression/ds_pretrain_gpt_350M_dense_kd.sh ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ DIR=`pwd`
3
+ ###############################################################################
4
+ ### Main configs
5
+ ## GPT-3 models use 2K sequence length/context window
6
+ SEQ_LEN=2048
7
+
8
+ ### The "GPT-3 XXX" below are configs from GPT-3 paper
9
+ ### https://arxiv.org/abs/2005.14165, choose based on
10
+ ### your desired model size or build your own configs
11
+
12
+ ## GPT-3 Small 125M
13
+ # MODEL_SIZE=0.125
14
+ # NUM_LAYERS=12
15
+ # HIDDEN_SIZE=768
16
+ # NUM_ATTN_HEADS=12
17
+ # GLOBAL_BATCH_SIZE=256
18
+ # LR=6.0e-4
19
+ # MIN_LR=6.0e-5
20
+
21
+ ## GPT-3 Medium 350M
22
+ MODEL_SIZE=0.35
23
+ NUM_LAYERS=24
24
+ HIDDEN_SIZE=1024
25
+ NUM_ATTN_HEADS=16
26
+ GLOBAL_BATCH_SIZE=256
27
+ LR=3.0e-4
28
+ MIN_LR=3.0e-5
29
+
30
+ ## GPT-3 Large 760M
31
+ # MODEL_SIZE=0.76
32
+ # NUM_LAYERS=24
33
+ # HIDDEN_SIZE=1536
34
+ # NUM_ATTN_HEADS=16
35
+ # GLOBAL_BATCH_SIZE=256
36
+ # LR=2.5e-4
37
+ # MIN_LR=2.5e-5
38
+
39
+ ## GPT-3 XL 1.3B
40
+ # MODEL_SIZE=1.3
41
+ # NUM_LAYERS=24
42
+ # HIDDEN_SIZE=2048
43
+ # NUM_ATTN_HEADS=16
44
+ # GLOBAL_BATCH_SIZE=512
45
+ # LR=2.0e-4
46
+ # MIN_LR=2.0e-5
47
+
48
+ ## GPT-3 2.7B
49
+ # MODEL_SIZE=2.7
50
+ # NUM_LAYERS=32
51
+ # HIDDEN_SIZE=2560
52
+ # NUM_ATTN_HEADS=32
53
+ # GLOBAL_BATCH_SIZE=512
54
+ # LR=1.6e-4
55
+ # MIN_LR=1.6e-5
56
+
57
+ ## GPT-3 6.7B
58
+ # MODEL_SIZE=6.7
59
+ # NUM_LAYERS=32
60
+ # HIDDEN_SIZE=4096
61
+ # NUM_ATTN_HEADS=32
62
+ # GLOBAL_BATCH_SIZE=1024
63
+ # LR=1.2e-4
64
+ # MIN_LR=1.2e-5
65
+
66
+ ## GPT-3 13B
67
+ # MODEL_SIZE=13
68
+ # NUM_LAYERS=40
69
+ # HIDDEN_SIZE=5120
70
+ # NUM_ATTN_HEADS=40
71
+ # GLOBAL_BATCH_SIZE=1024
72
+ # LR=1.0e-4
73
+ # MIN_LR=1.0e-5
74
+
75
+ ## GPT-3 175B
76
+ # MODEL_SIZE=175
77
+ # NUM_LAYERS=96
78
+ # HIDDEN_SIZE=12288
79
+ # NUM_ATTN_HEADS=96
80
+ # GLOBAL_BATCH_SIZE=1536
81
+ # LR=0.6e-4
82
+ # MIN_LR=0.6e-5
83
+ ###############################################################################
84
+ ### Training duration configs
85
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens
86
+ ## For MoE model, we found sometimes training a bit more to 330B tokens helps
87
+ TRAIN_TOKENS=300000000000
88
+ # TRAIN_TOKENS=330000000000
89
+
90
+ ## TRAIN_SAMPLES is another termination condition and also affect the number of
91
+ ## data samples to be indexed. Since we want to reach the TRAIN_TOKENS
92
+ ## above, and techniques like curriculum learning has less token in some steps,
93
+ ## so we just set this config large enough to make sure we have enough
94
+ ## processed data and don't terminate by TRAIN_SAMPLES.
95
+ TRAIN_SAMPLES=$(( ${TRAIN_TOKENS} * 3 / ${SEQ_LEN} ))
96
+
97
+ ## Another termination condition in minutes. Set it large enough to avoid
98
+ ## undesired early termination.
99
+ EXIT_DURATION=30000000
100
+ ###############################################################################
101
+ ### LR configs
102
+ ## LR warmup and decay duration, this token-based config is preferable since
103
+ ## no need to readjust when the batch size/seqlen is changed.
104
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B decay tokens.
105
+ ## For MoE model, we found that setting the decay token to 300B helps.
106
+ WARMUP_TOKENS=375000000
107
+ LR_DECAY_TOKENS=260000000000
108
+ # LR_DECAY_TOKENS=300000000000
109
+ ###############################################################################
110
+ ### Parallelism configs
111
+ ## Micro batch size per GPU
112
+ ## Make sure that BATCH_SIZE <= GLOBAL_BATCH_SIZE*PP_SIZE*MP_SIZE/NUM_GPUS
113
+ BATCH_SIZE=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ ## Currently MoE models have divergence issue when MP > 1.
117
+ MP_SIZE=1
118
+
119
+ ## Pipeline parallelism
120
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
121
+ ## to 1 and use the "--no-pipeline-parallel" arg.
122
+ PP_SIZE=1
123
+ NUM_GPUS=64
124
+ ###############################################################################
125
+ ### MoE configs
126
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
127
+ EP_SIZE=1
128
+ # EP_SIZE=128
129
+
130
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
131
+ EP_PARALLEL_SIZE=$NUM_GPUS
132
+ else
133
+ EP_PARALLEL_SIZE=$EP_SIZE
134
+ fi
135
+
136
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
137
+ ## found that lower LR and min LR (than the base dense model) helps.
138
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
139
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
140
+ ## heavily tuned.
141
+ # LR=2.0e-4
142
+ # MIN_LR=2e-06
143
+
144
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
145
+ ## 1.3B MoE-128 model
146
+ MLC=0.01
147
+
148
+ ## Below configs adjust the MoE expert token capacity limit during training and
149
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
150
+ ## Larger capacity factor or disabling capacity limit could improve training
151
+ ## convergence, but will also reduce training throughput.
152
+ MOE_TRAIN_CAP_FACTOR=1.0
153
+ MOE_EVAL_CAP_FACTOR=1.0
154
+ MOE_MIN_CAP=4
155
+ MOE_DROP_TOKEN="true"
156
+ # MOE_DROP_TOKEN="false"
157
+ ###############################################################################
158
+ ### Curriculum learning (CL) configs
159
+ ## Enable/disable CL
160
+ CL_ENABLED="false"
161
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
162
+ ## for tuning the following configs
163
+ CL_START_SEQLEN=80
164
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
165
+ CL_TOKENS=60
166
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
167
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
168
+ ###############################################################################
169
+ ### Misc configs
170
+ LOG_INTERVAL=10
171
+ EVAL_ITERS=10
172
+ EVAL_INTERVAL=100
173
+ SAVE_INTERVAL=1000
174
+
175
+ ## Standard deviation for weight initialization
176
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
177
+ ## dense model. Usually larger model needs lower std.
178
+ INIT_STD=0.014
179
+ # INIT_STD=0.01
180
+
181
+ ## Activation checkpointing saves GPU memory, but reduces training speed
182
+ ACTIVATION_CHECKPOINT="true"
183
+ # ACTIVATION_CHECKPOINT="false"
184
+ ###############################################################################
185
+ ### Output and data configs
186
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
187
+ host="${HOSTNAME}"
188
+ NAME="gpt-kd-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
189
+ if [[ $EP_SIZE -gt 1 ]]; then
190
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
191
+ fi
192
+ if [ "${CL_ENABLED}" = "true" ]; then
193
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
194
+ fi
195
+
196
+ OUTPUT_BASEPATH=$DIR/output
197
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
199
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
200
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
201
+ mkdir -p ${TENSORBOARD_DIR}
202
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
203
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
204
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
205
+
206
+ # USE_INTERNAL_DATA="true"
207
+ USE_INTERNAL_DATA="false"
208
+
209
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
210
+ ## The internal data is only accessible within Microsoft
211
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
212
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
213
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
214
+ ## For cluster Lab-RR1-V100
215
+ BASE_DATA_PATH=/data/Megatron-LM/data
216
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
217
+ ## For cluster Azure-CentralUS-A100
218
+ # BASE_DATA_PATH=/data/Megatron-LM/data
219
+ # DATA_HOME=/vc_data_1/users/amawa/blended
220
+
221
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
222
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
223
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
224
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
225
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
226
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
227
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
228
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
229
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
230
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
231
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
232
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
233
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
234
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
235
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
236
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
237
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
238
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
239
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
240
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
241
+ 0.01359 ${ARX} 0.01588 ${GIT}"
242
+ else
243
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
244
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
245
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
246
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
247
+ fi
248
+ ###############################################################################
249
+ data_options=" \
250
+ --vocab-file ${VOCAB_PATH} \
251
+ --merge-file ${MERGE_PATH} \
252
+ --data-path ${DATA_BLEND} \
253
+ --data-impl mmap"
254
+
255
+ megatron_options=" \
256
+ --override-lr-scheduler \
257
+ --adam-beta1 0.9 \
258
+ --adam-beta2 0.95 \
259
+ --tensor-model-parallel-size ${MP_SIZE} \
260
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
261
+ --num-experts ${EP_SIZE} \
262
+ --moe-loss-coeff ${MLC} \
263
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
264
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
265
+ --moe-min-capacity ${MOE_MIN_CAP} \
266
+ --init-method-std ${INIT_STD} \
267
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
268
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
269
+ --micro-batch-size ${BATCH_SIZE} \
270
+ --exit-duration-in-mins ${EXIT_DURATION} \
271
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
272
+ --num-layers ${NUM_LAYERS} \
273
+ --hidden-size ${HIDDEN_SIZE} \
274
+ --num-attention-heads ${NUM_ATTN_HEADS} \
275
+ --seq-length ${SEQ_LEN} \
276
+ --max-position-embeddings ${SEQ_LEN} \
277
+ --train-tokens ${TRAIN_TOKENS} \
278
+ --train-samples ${TRAIN_SAMPLES} \
279
+ --lr ${LR} \
280
+ --min-lr ${MIN_LR} \
281
+ --lr-decay-style cosine \
282
+ --split 98,2,0 \
283
+ --log-interval ${LOG_INTERVAL} \
284
+ --eval-interval ${EVAL_INTERVAL} \
285
+ --eval-iters ${EVAL_ITERS} \
286
+ --save-interval ${SAVE_INTERVAL} \
287
+ --weight-decay 0.1 \
288
+ --clip-grad 1.0 \
289
+ --hysteresis 2 \
290
+ --num-workers 0 \
291
+ --fp16 \
292
+ --load ${CHECKPOINT_PATH} \
293
+ --save ${CHECKPOINT_PATH} \
294
+ --tensorboard-queue-size 1 \
295
+ --log-timers-to-tensorboard \
296
+ --log-batch-size-to-tensorboard \
297
+ --log-validation-ppl-to-tensorboard \
298
+ --tensorboard-dir ${TENSORBOARD_DIR}"
299
+
300
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
301
+ megatron_options="${megatron_options} \
302
+ --checkpoint-activations"
303
+ fi
304
+
305
+ if [[ $EP_SIZE -gt 1 ]]; then
306
+ megatron_options="${megatron_options} \
307
+ --create-moe-param-group"
308
+ fi
309
+
310
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
311
+ megatron_options="${megatron_options} \
312
+ --disable-moe-token-dropping"
313
+ fi
314
+
315
+ template_json="ds_config_gpt_TEMPLATE.json"
316
+ config_json="ds_config_gpt_${NAME}.json"
317
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
318
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
319
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
320
+ | sed "s/ZERO_STAGE/0/" \
321
+ | sed "s/PRESCALE_GRAD/true/" \
322
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
323
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
324
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
325
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
326
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
327
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
328
+ > ${config_json}
329
+
330
+ deepspeed_options=" \
331
+ --deepspeed \
332
+ --deepspeed_config ${config_json} \
333
+ --pipeline-model-parallel-size ${PP_SIZE}"
334
+
335
+ # Currently MoE is not compatible with pipeline parallel
336
+ if [[ $EP_SIZE -gt 1 ]]; then
337
+ deepspeed_options="${deepspeed_options} \
338
+ --no-pipeline-parallel"
339
+ fi
340
+
341
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
342
+ deepspeed_options="${deepspeed_options} \
343
+ --deepspeed-activation-checkpointing"
344
+ fi
345
+
346
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
347
+ echo ${run_cmd}
348
+ eval ${run_cmd}
349
+ set +x
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ This is an example of how to use DeepSpeed's curriculum learning (CL) feature which provides faster and more stable language model pre-training. Currently it is only integrated for GPT pre-training. Note that there are two curriculum learning examples in two different repos for Megatron-LM GPT-2 pre-training. Both of them have some unique features and limitations. See details in our [tutorial](https://www.deepspeed.ai/tutorials/curriculum-learning/). For technical details please refer to our [paper](https://arxiv.org/abs/2108.06084).
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/ds_train.sh ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # baseline
2
+ # CONFIG=baseline
3
+ # TAG=baseline
4
+ # MODEL_SIZE=1558
5
+ # LR=1.5e-4
6
+ # BSZ=512
7
+ # SEQ_LEN=1024
8
+ # MP_SIZE=1
9
+ # SEED=1234
10
+ # SAVE_INTERVAL=5000
11
+ # NUM_ITER=600000
12
+ # NUM_TOKEN=157286400000
13
+ # LR_DECAY_TOKEN=157286400000
14
+ # LR_WARMUP_ITER=3000
15
+ # CONFIG_TEMPLATE=false
16
+ # CURRICULUM_STEP=0
17
+ # CURRICULUM_MIN=0
18
+
19
+ # curriculum learning
20
+ CONFIG=curriculum_fixed_linear
21
+ MODEL_SIZE=1558
22
+ LR=6e-4
23
+ BSZ=4096
24
+ SEQ_LEN=1024
25
+ MP_SIZE=1
26
+ SEED=1234
27
+ SAVE_INTERVAL=1000
28
+ NUM_ITER=75000
29
+ NUM_TOKEN=157286400000
30
+ LR_DECAY_TOKEN=157286400000
31
+ LR_WARMUP_ITER=3000
32
+ CONFIG_TEMPLATE=true
33
+ CURRICULUM_STEP=45000
34
+ CURRICULUM_MIN=64
35
+ TAG="${CONFIG}_s${CURRICULUM_MIN}to${SEQ_LEN}_step${CURRICULUM_STEP}"
36
+
37
+ bash ds_pretrain_gpt2.sh $CONFIG $TAG $MODEL_SIZE $LR $BSZ $SEQ_LEN $MP_SIZE $SEED $SAVE_INTERVAL $NUM_ITER $NUM_TOKEN $LR_DECAY_TOKEN $LR_WARMUP_ITER $CONFIG_TEMPLATE $CURRICULUM_STEP $CURRICULUM_MIN
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/ds_zero_stage_1_config_baseline.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size": 512,
3
+ "gradient_accumulation_steps": 1,
4
+ "steps_per_print": 1,
5
+ "zero_optimization": {
6
+ "stage": 1
7
+ },
8
+ "optimizer": {
9
+ "type": "Adam",
10
+ "params": {
11
+ "lr": 0.00015,
12
+ "max_grad_norm": 1.0,
13
+ "betas": [0.9, 0.95]
14
+ }
15
+ },
16
+ "gradient_clipping": 1.0,
17
+ "fp16": {
18
+ "enabled": true,
19
+ "loss_scale": 0,
20
+ "loss_scale_window": 1000,
21
+ "hysteresis": 2,
22
+ "min_loss_scale": 1
23
+ },
24
+ "wall_clock_breakdown": false,
25
+ "zero_allow_untested_optimizer": false
26
+ }
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/curriculum_learning/ds_zero_stage_1_config_curriculum_fixed_linear.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size": 512,
3
+ "gradient_accumulation_steps": 1,
4
+ "steps_per_print": 1,
5
+ "zero_optimization": {
6
+ "stage": 1
7
+ },
8
+ "optimizer": {
9
+ "type": "Adam",
10
+ "params": {
11
+ "lr": 0.00015,
12
+ "max_grad_norm": 1.0,
13
+ "betas": [0.9, 0.95]
14
+ }
15
+ },
16
+ "gradient_clipping": 1.0,
17
+ "fp16": {
18
+ "enabled": true,
19
+ "loss_scale": 0,
20
+ "loss_scale_window": 1000,
21
+ "hysteresis": 2,
22
+ "min_loss_scale": 1
23
+ },
24
+ "wall_clock_breakdown": false,
25
+ "zero_allow_untested_optimizer": false,
26
+ "curriculum_learning": {
27
+ "enabled": true,
28
+ "curriculum_type": "seqlen",
29
+ "min_difficulty": CONFIG_CL_MIN,
30
+ "max_difficulty": CONFIG_CL_MAX,
31
+ "schedule_type": "fixed_linear",
32
+ "schedule_config": {
33
+ "total_curriculum_step": CONFIG_CL_DURATION,
34
+ "difficulty_step": 8
35
+ }
36
+ }
37
+ }
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/evaluate_zeroshot_gpt.sh ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ WORLD_SIZE=8
4
+
5
+ DISTRIBUTED_ARGS="--nproc_per_node $WORLD_SIZE \
6
+ --nnodes 1 \
7
+ --node_rank 0 \
8
+ --master_addr localhost \
9
+ --master_port 6000"
10
+
11
+ TASK="LAMBADA"
12
+
13
+ VALID_DATA=<lambada path>
14
+ VOCAB_FILE=gpt2-vocab.json
15
+ MERGE_FILE=gpt2-merges.txt
16
+ CHECKPOINT=checkpoints/gpt2_345m
17
+
18
+
19
+ python -m torch.distributed.launch $DISTRIBUTED_ARGS ./tasks/main.py \
20
+ --task $TASK \
21
+ --valid-data $VALID_DATA \
22
+ --tokenizer-type GPT2BPETokenizer \
23
+ --strict-lambada \
24
+ --vocab-file $VOCAB_FILE \
25
+ --merge-file $MERGE_FILE \
26
+ --load $CHECKPOINT \
27
+ --tensor-model-parallel-size 1 \
28
+ --num-layers 24 \
29
+ --hidden-size 1024 \
30
+ --num-attention-heads 16 \
31
+ --batch-size 8 \
32
+ --checkpoint-activations \
33
+ --seq-length 1024 \
34
+ --max-position-embeddings 1024 \
35
+ --log-interval 10 \
36
+ --fp16 \
37
+ --no-load-optim \
38
+ --no-load-rng
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/generate_text.sh ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ export TORCH_CUDA_ARCH_LIST=8.6+PTX
3
+ CHECKPOINT_PATH=checkpoints/gpt2_345m
4
+ VOCAB_FILE=gpt2-vocab.json
5
+ MERGE_FILE=gpt2-merges.txt
6
+ b=8
7
+ mp=1
8
+ experts=2
9
+ nodes=1
10
+ gpus=1
11
+
12
+
13
+ use_tutel=""
14
+ #use_tutel="--use-tutel"
15
+
16
+
17
+ #ds_inference=""
18
+ ds_inference="--ds-inference"
19
+
20
+ launch_cmd="deepspeed --num_nodes $nodes --num_gpus $gpus"
21
+ L=24
22
+ H=2048
23
+ A=16
24
+ #experts1=${experts[$k]}
25
+ program_cmd="tools/generate_samples_gpt.py \
26
+ --tensor-model-parallel-size $mp \
27
+ --num-layers $L \
28
+ --hidden-size $H \
29
+ --num-attention-heads $A \
30
+ --max-position-embeddings 1024 \
31
+ --tokenizer-type GPT2BPETokenizer \
32
+ --fp16 \
33
+ --num-experts ${experts} \
34
+ --mlp-type standard \
35
+ --micro-batch-size $b \
36
+ --seq-length 10 \
37
+ --out-seq-length 10 \
38
+ --temperature 1.0 \
39
+ --vocab-file $VOCAB_FILE \
40
+ --merge-file $MERGE_FILE \
41
+ --genfile unconditional_samples.json \
42
+ --top_p 0.9 \
43
+ --log-interval 1 \
44
+ --num-samples $((100*$b))
45
+ $use_tutel $ds_inference"
46
+
47
+ echo $launch_cmd $program_cmd
48
+ $launch_cmd $program_cmd
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/merge_mp_bert.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ TENSOR_MODEL_PARALLEL_SIZE=2
4
+
5
+ VOCAB_FILE=bert-vocab.txt
6
+ CHECKPOINT_PATH=checkpoints/bert_345m
7
+
8
+ WORLD_SIZE=$TENSOR_MODEL_PARALLEL_SIZE python tools/merge_mp_partitions.py \
9
+ --model-type BERT \
10
+ --tensor-model-parallel-size $TENSOR_MODEL_PARALLEL_SIZE \
11
+ --tokenizer-type BertWordPieceLowerCase \
12
+ --vocab-file $VOCAB_FILE \
13
+ --num-layers 24 \
14
+ --hidden-size 1024 \
15
+ --num-attention-heads 16 \
16
+ --seq-length 512 \
17
+ --max-position-embeddings 512 \
18
+ --load $CHECKPOINT_PATH
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_bert_distributed.sh ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ GPUS_PER_NODE=8
4
+ # Change for multinode config
5
+ MASTER_ADDR=localhost
6
+ MASTER_PORT=6000
7
+ NNODES=1
8
+ NODE_RANK=0
9
+ WORLD_SIZE=$(($GPUS_PER_NODE*$NNODES))
10
+
11
+ DATA_PATH=<Specify path and file prefix>_text_sentence
12
+ CHECKPOINT_PATH=<Specify path>
13
+
14
+ DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
15
+
16
+ python -m torch.distributed.launch $DISTRIBUTED_ARGS \
17
+ pretrain_bert.py \
18
+ --num-layers 24 \
19
+ --hidden-size 1024 \
20
+ --num-attention-heads 16 \
21
+ --micro-batch-size 4 \
22
+ --global-batch-size 32 \
23
+ --seq-length 512 \
24
+ --max-position-embeddings 512 \
25
+ --train-iters 1000000 \
26
+ --save $CHECKPOINT_PATH \
27
+ --load $CHECKPOINT_PATH \
28
+ --data-path $DATA_PATH \
29
+ --vocab-file bert-vocab.txt \
30
+ --data-impl mmap \
31
+ --split 949,50,1 \
32
+ --distributed-backend nccl \
33
+ --lr 0.0001 \
34
+ --lr-decay-style linear \
35
+ --min-lr 1.0e-5 \
36
+ --lr-decay-iters 990000 \
37
+ --weight-decay 1e-2 \
38
+ --clip-grad 1.0 \
39
+ --lr-warmup-fraction .01 \
40
+ --log-interval 100 \
41
+ --save-interval 10000 \
42
+ --eval-interval 1000 \
43
+ --eval-iters 10 \
44
+ --fp16
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_bert_distributed_with_mp.sh ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ GPUS_PER_NODE=8
4
+ # Change for multinode config
5
+ MASTER_ADDR=localhost
6
+ MASTER_PORT=6000
7
+ NNODES=1
8
+ NODE_RANK=0
9
+ WORLD_SIZE=$(($GPUS_PER_NODE*$NNODES))
10
+
11
+ DATA_PATH=<Specify path and file prefix>_text_sentence
12
+ VOCAB_FILE=<Specify path to vocab.txt>
13
+ CHECKPOINT_PATH=<Specify path>
14
+
15
+ DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
16
+
17
+ python -m torch.distributed.launch $DISTRIBUTED_ARGS \
18
+ pretrain_bert.py \
19
+ --tensor-model-parallel-size 2 \
20
+ --pipeline-model-parallel-size 2 \
21
+ --num-layers 24 \
22
+ --hidden-size 1024 \
23
+ --num-attention-heads 16 \
24
+ --micro-batch-size 2 \
25
+ --global-batch-size 16 \
26
+ --max-position-embeddings 512 \
27
+ --train-iters 1000000 \
28
+ --save $CHECKPOINT_PATH \
29
+ --load $CHECKPOINT_PATH \
30
+ --data-path $DATA_PATH \
31
+ --vocab-file $VOCAB_FILE \
32
+ --data-impl mmap \
33
+ --split 949,50,1 \
34
+ --distributed-backend nccl \
35
+ --lr 0.0001 \
36
+ --lr-decay-style linear \
37
+ --min-lr 1.0e-5 \
38
+ --lr-decay-iters 990000 \
39
+ --weight-decay 1e-2 \
40
+ --clip-grad 1.0 \
41
+ --lr-warmup-fraction .01 \
42
+ --log-interval 100 \
43
+ --save-interval 10000 \
44
+ --eval-interval 1000 \
45
+ --eval-iters 10 \
46
+ --fp16
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt.sh ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash
2
+
3
+ # Runs the "345M" parameter model
4
+
5
+ RANK=0
6
+ WORLD_SIZE=1
7
+
8
+ DATA_PATH=<Specify path and file prefix>_text_document
9
+ CHECKPOINT_PATH=<Specify path>
10
+
11
+
12
+ python pretrain_gpt.py \
13
+ --num-layers 24 \
14
+ --hidden-size 1024 \
15
+ --num-attention-heads 16 \
16
+ --micro-batch-size 4 \
17
+ --global-batch-size 8 \
18
+ --seq-length 1024 \
19
+ --max-position-embeddings 1024 \
20
+ --train-iters 500000 \
21
+ --lr-decay-iters 320000 \
22
+ --save $CHECKPOINT_PATH \
23
+ --load $CHECKPOINT_PATH \
24
+ --data-path $DATA_PATH \
25
+ --vocab-file gpt2-vocab.json \
26
+ --merge-file gpt2-merges.txt \
27
+ --data-impl mmap \
28
+ --split 949,50,1 \
29
+ --distributed-backend nccl \
30
+ --lr 0.00015 \
31
+ --min-lr 1.0e-5 \
32
+ --lr-decay-style cosine \
33
+ --weight-decay 1e-2 \
34
+ --clip-grad 1.0 \
35
+ --lr-warmup-fraction .01 \
36
+ --checkpoint-activations \
37
+ --log-interval 100 \
38
+ --save-interval 10000 \
39
+ --eval-interval 1000 \
40
+ --eval-iters 10 \
41
+ --fp16
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt3_175B.sh ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+
4
+ #SBATCH <SLURM OPTIONS> --nodes=128 --exclusive --ntasks-per-node=8 --job-name=megatron_gpt3_175b
5
+
6
+
7
+ DIR=`pwd`
8
+ DATETIME=`date +'date_%y-%m-%d_time_%H-%M-%S'`
9
+ mkdir -p $DIR/logs
10
+
11
+
12
+ DATASET_1="<PATH TO THE FIRST DATASET>"
13
+ DATASET_2="<PATH TO THE SECOND DATASET>"
14
+ DATASET_3="<PATH TO THE THIRD DATASET>"
15
+ DATASET="0.2 ${DATASET_1} 0.3 ${DATASET_2} 0.5 ${DATASET_3}"
16
+
17
+
18
+ options=" \
19
+ --tensor-model-parallel-size 8 \
20
+ --pipeline-model-parallel-size 16 \
21
+ --num-layers 96 \
22
+ --hidden-size 12288 \
23
+ --num-attention-heads 96 \
24
+ --seq-length 2048 \
25
+ --max-position-embeddings 2048 \
26
+ --micro-batch-size 1 \
27
+ --global-batch-size 1536 \
28
+ --rampup-batch-size 16 16 5859375 \
29
+ --train-samples 146484375 \
30
+ --lr-decay-samples 126953125 \
31
+ --lr-warmup-samples 183105 \
32
+ --lr 6.0e-5 \
33
+ --min-lr 6.0e-6 \
34
+ --lr-decay-style cosine \
35
+ --log-interval 10 \
36
+ --eval-iters 40 \
37
+ --eval-interval 1000 \
38
+ --data-path ${DATASET} \
39
+ --vocab-file <PATH TO gpt-vocab.json> \
40
+ --merge-file <PATH TO gpt-merges.txt> \
41
+ --save-interval 1000 \
42
+ --save <PATH TO CHECKPOINTS DIRECTORY> \
43
+ --load <PATH TO CHECKPOINTS DIRECTORY> \
44
+ --split 98,2,0 \
45
+ --clip-grad 1.0 \
46
+ --weight-decay 0.1 \
47
+ --adam-beta1 0.9 \
48
+ --adam-beta2 0.95 \
49
+ --init-method-std 0.006 \
50
+ --tensorboard-dir <TENSORBOARD DIRECTORY> \
51
+ --fp16 \
52
+ --checkpoint-activations "
53
+
54
+
55
+ run_cmd="python -u ${DIR}/pretrain_gpt.py $@ ${options}"
56
+
57
+
58
+ srun -l \
59
+ --container-image "nvcr.io/nvidia/pytorch:20.12-py3" \
60
+ --container-mounts "<DIRECTORIES TO MOUNT>" \
61
+ --output=$DIR/logs/%x_%j_$DATETIME.log sh -c "${run_cmd}"
62
+
63
+
64
+ set +x
65
+
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt_distributed.sh ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash
2
+
3
+ # Runs the "345M" parameter model
4
+
5
+ GPUS_PER_NODE=8
6
+ # Change for multinode config
7
+ MASTER_ADDR=localhost
8
+ MASTER_PORT=6000
9
+ NNODES=1
10
+ NODE_RANK=0
11
+ WORLD_SIZE=$(($GPUS_PER_NODE*$NNODES))
12
+
13
+ DATA_PATH=<Specify path and file prefix>_text_document
14
+ CHECKPOINT_PATH=<Specify path>
15
+
16
+ DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
17
+
18
+ python -m torch.distributed.launch $DISTRIBUTED_ARGS \
19
+ pretrain_gpt.py \
20
+ --num-layers 24 \
21
+ --hidden-size 1024 \
22
+ --num-attention-heads 16 \
23
+ --micro-batch-size 8 \
24
+ --global-batch-size 64 \
25
+ --seq-length 1024 \
26
+ --max-position-embeddings 1024 \
27
+ --train-iters 500000 \
28
+ --lr-decay-iters 320000 \
29
+ --save $CHECKPOINT_PATH \
30
+ --load $CHECKPOINT_PATH \
31
+ --data-path $DATA_PATH \
32
+ --vocab-file gpt2-vocab.json \
33
+ --merge-file gpt2-merges.txt \
34
+ --data-impl mmap \
35
+ --split 949,50,1 \
36
+ --distributed-backend nccl \
37
+ --lr 0.00015 \
38
+ --lr-decay-style cosine \
39
+ --min-lr 1.0e-5 \
40
+ --weight-decay 1e-2 \
41
+ --clip-grad 1.0 \
42
+ --lr-warmup-fraction .01 \
43
+ --checkpoint-activations \
44
+ --log-interval 100 \
45
+ --save-interval 10000 \
46
+ --eval-interval 1000 \
47
+ --eval-iters 10 \
48
+ --fp16
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_gpt_distributed_with_mp.sh ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash
2
+
3
+ # Runs the "345M" parameter model
4
+
5
+ GPUS_PER_NODE=8
6
+ # Change for multinode config
7
+ MASTER_ADDR=localhost
8
+ MASTER_PORT=6000
9
+ NNODES=1
10
+ NODE_RANK=0
11
+ WORLD_SIZE=$(($GPUS_PER_NODE*$NNODES))
12
+
13
+ DATA_PATH=<Specify path and file prefix>_text_document
14
+ CHECKPOINT_PATH=<Specify path>
15
+
16
+ DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
17
+
18
+ python -m torch.distributed.launch $DISTRIBUTED_ARGS \
19
+ pretrain_gpt.py \
20
+ --tensor-model-parallel-size 2 \
21
+ --pipeline-model-parallel-size 2 \
22
+ --num-layers 24 \
23
+ --hidden-size 1024 \
24
+ --num-attention-heads 16 \
25
+ --micro-batch-size 4 \
26
+ --global-batch-size 16 \
27
+ --seq-length 1024 \
28
+ --max-position-embeddings 1024 \
29
+ --train-iters 500000 \
30
+ --lr-decay-iters 320000 \
31
+ --save $CHECKPOINT_PATH \
32
+ --load $CHECKPOINT_PATH \
33
+ --data-path $DATA_PATH \
34
+ --vocab-file gpt2-vocab.json \
35
+ --merge-file gpt2-merges.txt \
36
+ --data-impl mmap \
37
+ --split 949,50,1 \
38
+ --distributed-backend nccl \
39
+ --lr 0.00015 \
40
+ --lr-decay-style cosine \
41
+ --min-lr 1.0e-5 \
42
+ --weight-decay 1e-2 \
43
+ --clip-grad 1.0 \
44
+ --lr-warmup-fraction .01 \
45
+ --checkpoint-activations \
46
+ --log-interval 100 \
47
+ --save-interval 10000 \
48
+ --eval-interval 1000 \
49
+ --eval-iters 10 \
50
+ --fp16
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_ict.sh ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash
2
+
3
+ # Runs the "217M" parameter biencoder model for ICT retriever
4
+
5
+ RANK=0
6
+ WORLD_SIZE=1
7
+
8
+ PRETRAINED_BERT_PATH=<Specify path of pretrained BERT model>
9
+ TEXT_DATA_PATH=<Specify path and file prefix of the text data>
10
+ TITLE_DATA_PATH=<Specify path and file prefix od the titles>
11
+ CHECKPOINT_PATH=<Specify path>
12
+
13
+
14
+ python pretrain_ict.py \
15
+ --num-layers 12 \
16
+ --hidden-size 768 \
17
+ --num-attention-heads 12 \
18
+ --tensor-model-parallel-size 1 \
19
+ --micro-batch-size 32 \
20
+ --seq-length 256 \
21
+ --max-position-embeddings 512 \
22
+ --train-iters 100000 \
23
+ --vocab-file bert-vocab.txt \
24
+ --tokenizer-type BertWordPieceLowerCase \
25
+ --DDP-impl torch \
26
+ --bert-load ${PRETRAINED_BERT_PATH} \
27
+ --log-interval 100 \
28
+ --eval-interval 1000 \
29
+ --eval-iters 10 \
30
+ --retriever-report-topk-accuracies 1 5 10 20 100 \
31
+ --retriever-score-scaling \
32
+ --load $CHECKPOINT_PATH \
33
+ --save $CHECKPOINT_PATH \
34
+ --data-path ${TEXT_DATA_PATH} \
35
+ --titles-data-path ${TITLE_DATA_PATH} \
36
+ --lr 0.0001 \
37
+ --lr-decay-style linear \
38
+ --weight-decay 1e-2 \
39
+ --clip-grad 1.0 \
40
+ --lr-warmup-fraction 0.01 \
41
+ --save-interval 4000 \
42
+ --exit-interval 8000 \
43
+ --query-in-block-prob 0.1 \
44
+ --fp16
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/pretrain_t5.sh ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ RANK=0
4
+ WORLD_SIZE=1
5
+ DATA_PATH=<Specify path and file prefix>
6
+ VOCAB_FILE=<Specify path to vocab.txt>
7
+ CHECKPOINT_PATH=<Specify path>
8
+
9
+ python pretrain_t5.py \
10
+ --num-layers 12 \
11
+ --hidden-size 768 \
12
+ --num-attention-heads 12 \
13
+ --kv-channels 64 \
14
+ --ffn-hidden-size 3072 \
15
+ --encoder-seq-length 512 \
16
+ --decoder-seq-length 128 \
17
+ --micro-batch-size 16 \
18
+ --global-batch-size 2048 \
19
+ --max-position-embeddings 512 \
20
+ --train-iters 1000000 \
21
+ --lr-decay-iters 1000000 \
22
+ --save $CHECKPOINT_PATH \
23
+ --load $CHECKPOINT_PATH \
24
+ --data-path $DATA_PATH \
25
+ --vocab-file $VOCAB_FILE \
26
+ --data-impl mmap \
27
+ --split 949,50,1 \
28
+ --lr 0.0001 \
29
+ --min-lr 0.00001 \
30
+ --lr-decay-style linear \
31
+ --lr-warmup-fraction .01 \
32
+ --weight-decay 1e-2 \
33
+ --clip-grad 1.0 \
34
+ --log-interval 100 \
35
+ --save-interval 10000 \
36
+ --eval-interval 1000 \
37
+ --eval-iters 10 \
38
+ --fp16
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/examples/run_deepspeed_example.sh ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -ex
3
+
4
+ BASE_PATH=/vc_data/Megatron-LM/data
5
+ DATA_PATH=${BASE_PATH}/indexed_datasets/megatron
6
+ DS_CONFIG=ds_config.json
7
+
8
+ TP=1
9
+ PP=1
10
+ NLAYERS=24
11
+ HIDDEN=512
12
+
13
+ GLOBAL_BATCH=64
14
+ MICRO_BATCH=4
15
+
16
+ ZERO_STAGE=2
17
+
18
+ OUTPUT_DIR=ds_z${ZERO_STAGE}_nl${NLAYERS}_hs${HIDDEN}_gb${GLOBAL_BATCH}_mb${MICRO_BATCH}
19
+ #OUTPUT_DIR=baseline_nl${NLAYERS}_hs${HIDDEN}_gb${GLOBAL_BATCH}_mb${MICRO_BATCH}
20
+ mkdir -p $OUTPUT_DIR
21
+
22
+ cat <<EOT > $DS_CONFIG
23
+ {
24
+ "train_batch_size" : $GLOBAL_BATCH,
25
+ "train_micro_batch_size_per_gpu": $MICRO_BATCH,
26
+ "steps_per_print": 1,
27
+
28
+ "zero_optimization": {
29
+ "stage": $ZERO_STAGE
30
+ },
31
+
32
+ "fp16": {
33
+ "enabled": true,
34
+ "initial_scale_power": 12
35
+ },
36
+
37
+ "wall_clock_breakdown" : true
38
+ }
39
+ EOT
40
+
41
+ export NCCL_DEBUG=warn
42
+
43
+ ds_args=""
44
+ ds_args=" --deepspeed ${ds_args}"
45
+ ds_args=" --no-pipeline-parallel ${ds_args}"
46
+ ds_args=" --deepspeed_config=$DS_CONFIG ${ds_args}"
47
+ ds_args=" --zero-stage=$ZERO_STAGE ${ds_args}"
48
+ ds_args=" --deepspeed-activation-checkpointing ${ds_args}"
49
+
50
+
51
+ deepspeed pretrain_gpt.py \
52
+ --tensor-model-parallel-size $TP \
53
+ --pipeline-model-parallel-size $PP \
54
+ --num-layers $NLAYERS \
55
+ --hidden-size $HIDDEN \
56
+ --num-attention-heads 16 \
57
+ --seq-length 256 \
58
+ --loss-scale 12 \
59
+ --max-position-embeddings 1024 \
60
+ --micro-batch-size 4 \
61
+ --global-batch-size 1024 \
62
+ --train-iters 1000 \
63
+ --lr 6.0e-5 \
64
+ --min-lr 6.0e-6 \
65
+ --lr-decay-style cosine \
66
+ --log-interval 1 \
67
+ --eval-iters 40 \
68
+ --eval-interval 1000 \
69
+ --data-path $DATA_PATH \
70
+ --vocab-file $BASE_PATH/gpt2-vocab.json \
71
+ --merge-file $BASE_PATH/gpt2-merges.txt \
72
+ --save-interval 1000 \
73
+ --split 98,2,0 \
74
+ --clip-grad 1.0 \
75
+ --weight-decay 0.1 \
76
+ --adam-beta1 0.9 \
77
+ --adam-beta2 0.95 \
78
+ --init-method-std 0.006 \
79
+ --fp16 \
80
+ --checkpoint-activations \
81
+ --tensorboard-dir $OUTPUT_DIR \
82
+ $ds_args \
83
+ --exit-interval 5000 | tee ${OUTPUT_DIR}/output.log
84
+
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/images/cases_april2021.png ADDED

Git LFS Details

  • SHA256: 6785b9aedc153052dd91f29ce806893326a64382591ebf6d74f0fe63c3b78250
  • Pointer size: 131 Bytes
  • Size of remote file: 163 kB
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/tasks/data_utils.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """ Tasks data utility."""
17
+
18
+ import re
19
+ import numpy as np
20
+
21
+
22
+ def clean_text(text):
23
+ """Remove new lines and multiple spaces and adjust end of sentence dot."""
24
+
25
+ text = text.replace("\n", " ")
26
+ text = re.sub(r'\s+', ' ', text)
27
+ for _ in range(3):
28
+ text = text.replace(' . ', '. ')
29
+
30
+ return text
31
+
32
+
33
+ def build_sample(ids, types, paddings, label, unique_id):
34
+ """Convert to numpy and return a sample consumed by the batch producer."""
35
+
36
+ ids_np = np.array(ids, dtype=np.int64)
37
+ types_np = np.array(types, dtype=np.int64)
38
+ paddings_np = np.array(paddings, dtype=np.int64)
39
+ sample = ({'text': ids_np,
40
+ 'types': types_np,
41
+ 'padding_mask': paddings_np,
42
+ 'label': int(label),
43
+ 'uid': int(unique_id)})
44
+
45
+ return sample
46
+
47
+
48
+ def build_tokens_types_paddings_from_text(text_a, text_b,
49
+ tokenizer, max_seq_length):
50
+ """Build token types and paddings, trim if needed, and pad if needed."""
51
+
52
+ text_a_ids = tokenizer.tokenize(text_a)
53
+ text_b_ids = None
54
+ if text_b is not None:
55
+ text_b_ids = tokenizer.tokenize(text_b)
56
+
57
+ return build_tokens_types_paddings_from_ids(text_a_ids, text_b_ids,
58
+ max_seq_length, tokenizer.cls,
59
+ tokenizer.sep, tokenizer.pad)
60
+
61
+
62
+ def build_tokens_types_paddings_from_ids(text_a_ids, text_b_ids, max_seq_length,
63
+ cls_id, sep_id, pad_id):
64
+ """Build token types and paddings, trim if needed, and pad if needed."""
65
+
66
+ ids = []
67
+ types = []
68
+ paddings = []
69
+
70
+ # [CLS].
71
+ ids.append(cls_id)
72
+ types.append(0)
73
+ paddings.append(1)
74
+
75
+ # A.
76
+ len_text_a = len(text_a_ids)
77
+ ids.extend(text_a_ids)
78
+ types.extend([0] * len_text_a)
79
+ paddings.extend([1] * len_text_a)
80
+
81
+ # [SEP].
82
+ ids.append(sep_id)
83
+ types.append(0)
84
+ paddings.append(1)
85
+
86
+ # B.
87
+ if text_b_ids is not None:
88
+ len_text_b = len(text_b_ids)
89
+ ids.extend(text_b_ids)
90
+ types.extend([1] * len_text_b)
91
+ paddings.extend([1] * len_text_b)
92
+
93
+ # Cap the size.
94
+ trimmed = False
95
+ if len(ids) >= max_seq_length:
96
+ max_seq_length_m1 = max_seq_length - 1
97
+ ids = ids[0:max_seq_length_m1]
98
+ types = types[0:max_seq_length_m1]
99
+ paddings = paddings[0:max_seq_length_m1]
100
+ trimmed = True
101
+
102
+ # [SEP].
103
+ if (text_b_ids is not None) or trimmed:
104
+ ids.append(sep_id)
105
+ if text_b_ids is None:
106
+ types.append(0)
107
+ else:
108
+ types.append(1)
109
+ paddings.append(1)
110
+
111
+ # Padding.
112
+ padding_length = max_seq_length - len(ids)
113
+ if padding_length > 0:
114
+ ids.extend([pad_id] * padding_length)
115
+ types.extend([pad_id] * padding_length)
116
+ paddings.extend([0] * padding_length)
117
+
118
+ return ids, types, paddings
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/tasks/detok.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import torch
4
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),
5
+ os.path.pardir)))
6
+
7
+ from tqdm import tqdm
8
+ from megatron import get_args
9
+ from megatron import get_tokenizer
10
+ from megatron.initialize import initialize_megatron
11
+ from pretrain_gpt import train_valid_test_datasets_provider
12
+ from megatron.training import build_train_valid_test_data_iterators
13
+
14
+
15
+ def get_detok_args(parser):
16
+ group = parser.add_argument_group(title='detokenizer')
17
+ group.add_argument('--detokenizer_output',
18
+ type=str,
19
+ required=True,
20
+ help='detokenizer output path')
21
+ return parser
22
+
23
+
24
+ def process_split(split, dataset, out_path):
25
+ print(f'Processing {split}')
26
+ tokenizer = get_tokenizer()
27
+
28
+ full_text = []
29
+ for batch in tqdm(dataset, total=len(dataset)):
30
+ tokens = batch['text'].reshape(-1).tolist()
31
+ text = tokenizer.detokenize(tokens)
32
+ full_text.append(text)
33
+
34
+ out_name = os.path.join(out_path, f'{split}.text')
35
+ print(f'Writing to {out_name}')
36
+ with open(out_name, 'w') as f:
37
+ f.writelines(full_text)
38
+
39
+
40
+ def main():
41
+
42
+ # below arguments are to force the full dataset according to the
43
+ # train/valid/test split based on args.split
44
+ forced_args = {
45
+ "micro_batch_size": 1,
46
+ "train_samples": None,
47
+ "train_iters": 1,
48
+ "eval_iters": 1,
49
+ "eval_interval": 2,
50
+ "use_seq_len_plus_one_tokens": False
51
+ }
52
+
53
+ initialize_megatron(extra_args_provider=get_detok_args, args_defaults=forced_args)
54
+ torch.distributed.barrier()
55
+
56
+ # after parsing, we have to force again the required args
57
+ args = get_args()
58
+ for name, value in forced_args.items():
59
+ setattr(args, name, value)
60
+
61
+ # create train/valid/test split based on args.split
62
+ args.iteration = 0
63
+ train_iter, valid_iter, test_iter = build_train_valid_test_data_iterators(
64
+ train_valid_test_datasets_provider)
65
+
66
+ os.makedirs(args.detokenizer_output, exist_ok=True)
67
+ process_split('test', test_iter._dataset, args.detokenizer_output)
68
+ process_split('valid', valid_iter._dataset, args.detokenizer_output)
69
+ process_split('train', train_iter._dataset, args.detokenizer_output)
70
+
71
+
72
+ if __name__ == '__main__':
73
+ main()
docker/bloom13b/Model-References/MLPERF3.1/Training/benchmarks/gpt3/tasks/ensemble_classifier.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import argparse
3
+ import collections
4
+
5
+ import numpy as np
6
+ import torch
7
+
8
+
9
+ def process_files(args):
10
+ all_predictions = collections.OrderedDict()
11
+ all_labels = collections.OrderedDict()
12
+ all_uid = collections.OrderedDict()
13
+ for path in args.paths:
14
+ path = os.path.join(path, args.prediction_name)
15
+ try:
16
+ data = torch.load(path)
17
+ for dataset in data:
18
+ name, d = dataset
19
+ predictions, labels, uid = d
20
+ if name not in all_predictions:
21
+ all_predictions[name] = np.array(predictions)
22
+ if args.labels is None:
23
+ args.labels = [i for i in range(all_predictions[name].shape[1])]
24
+ if args.eval:
25
+ all_labels[name] = np.array(labels)
26
+ all_uid[name] = np.array(uid)
27
+ else:
28
+ all_predictions[name] += np.array(predictions)
29
+ assert np.allclose(all_uid[name], np.array(uid))
30
+ except Exception as e:
31
+ print(e)
32
+ continue
33
+ return all_predictions, all_labels, all_uid
34
+
35
+
36
+ def get_threshold(all_predictions, all_labels, one_threshold=False):
37
+ if one_threshold:
38
+ all_predictons = {'combined': np.concatenate(list(all_predictions.values()))}
39
+ all_labels = {'combined': np.concatenate(list(all_predictions.labels()))}
40
+ out_thresh = []
41
+ for dataset in all_predictions:
42
+ preds = all_predictions[dataset]
43
+ labels = all_labels[dataset]
44
+ out_thresh.append(calc_threshold(preds, labels))
45
+ return out_thresh
46
+
47
+
48
+ def calc_threshold(p, l):
49
+ trials = [(i) * (1. / 100.) for i in range(100)]
50
+ best_acc = float('-inf')
51
+ best_thresh = 0
52
+ for t in trials:
53
+ acc = ((apply_threshold(p, t).argmax(-1) == l).astype(float)).mean()
54
+ if acc > best_acc:
55
+ best_acc = acc
56
+ best_thresh = t
57
+ return best_thresh
58
+
59
+
60
+ def apply_threshold(preds, t):
61
+ assert (np.allclose(preds.sum(-1), np.ones(preds.shape[0])))
62
+ prob = preds[:, -1]
63
+ thresholded = (prob >= t).astype(int)
64
+ preds = np.zeros_like(preds)
65
+ preds[np.arange(len(thresholded)), thresholded.reshape(-1)] = 1
66
+ return preds
67
+
68
+
69
+ def threshold_predictions(all_predictions, threshold):
70
+ if len(threshold) != len(all_predictions):
71
+ threshold = [threshold[-1]] * (len(all_predictions) - len(threshold))
72
+ for i, dataset in enumerate(all_predictions):
73
+ thresh = threshold[i]
74
+ preds = all_predictions[dataset]
75
+ all_predictions[dataset] = apply_threshold(preds, thresh)
76
+ return all_predictions
77
+
78
+
79
+ def postprocess_predictions(all_predictions, all_labels, args):
80
+ for d in all_predictions:
81
+ all_predictions[d] = all_predictions[d] / len(args.paths)
82
+
83
+ if args.calc_threshold:
84
+ args.threshold = get_threshold(all_predictions, all_labels, args.one_threshold)
85
+ print('threshold', args.threshold)
86
+
87
+ if args.threshold is not None:
88
+ all_predictions = threshold_predictions(all_predictions, args.threshold)
89
+
90
+ return all_predictions, all_labels
91
+
92
+
93
+ def write_predictions(all_predictions, all_labels, all_uid, args):
94
+ all_correct = 0
95
+ count = 0
96
+ for dataset in all_predictions:
97
+ preds = all_predictions[dataset]
98
+ preds = np.argmax(preds, -1)
99
+ if args.eval:
100
+ correct = (preds == all_labels[dataset]).sum()
101
+ num = len(all_labels[dataset])
102
+ accuracy = correct / num
103
+ count += num
104
+ all_correct += correct
105
+ accuracy = (preds == all_labels[dataset]).mean()
106
+ print(accuracy)
107
+ if not os.path.exists(os.path.join(args.outdir, dataset)):
108
+ os.makedirs(os.path.join(args.outdir, dataset))
109
+ outpath = os.path.join(
110
+ args.outdir, dataset, os.path.splitext(
111
+ args.prediction_name)[0] + '.tsv')
112
+ with open(outpath, 'w') as f:
113
+ f.write('id\tlabel\n')
114
+ f.write('\n'.join(str(uid) + '\t' + str(args.labels[p])
115
+ for uid, p in zip(all_uid[dataset], preds.tolist())))
116
+ if args.eval:
117
+ print(all_correct / count)
118
+
119
+
120
+ def ensemble_predictions(args):
121
+ all_predictions, all_labels, all_uid = process_files(args)
122
+ all_predictions, all_labels = postprocess_predictions(all_predictions, all_labels, args)
123
+ write_predictions(all_predictions, all_labels, all_uid, args)
124
+
125
+
126
+ def main():
127
+ parser = argparse.ArgumentParser()
128
+ parser.add_argument('--paths', required=True, nargs='+',
129
+ help='paths to checkpoint directories used in ensemble')
130
+ parser.add_argument('--eval', action='store_true',
131
+ help='compute accuracy metrics against labels (dev set)')
132
+ parser.add_argument('--outdir',
133
+ help='directory to place ensembled predictions in')
134
+ parser.add_argument('--prediction-name', default='test_predictions.pt',
135
+ help='name of predictions in checkpoint directories')
136
+ parser.add_argument('--calc-threshold', action='store_true',
137
+ help='calculate threshold classification')
138
+ parser.add_argument('--one-threshold', action='store_true',
139
+ help='use on threshold for all subdatasets')
140
+ parser.add_argument('--threshold', nargs='+', default=None, type=float,
141
+ help='user supplied threshold for classification')
142
+ parser.add_argument('--labels', nargs='+', default=None,
143
+ help='whitespace separated list of label names')
144
+ args = parser.parse_args()
145
+ ensemble_predictions(args)
146
+
147
+
148
+ if __name__ == '__main__':
149
+ main()