applied-ai-018 commited on
Commit
f457f98
·
verified ·
1 Parent(s): 7300ed0

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/intel_code/llama13b/Megatron-DeepSpeed/dataset/README.md +5 -0
  2. docker/intel_code/llama13b/Megatron-DeepSpeed/dataset/download_books.sh +2 -0
  3. docker/intel_code/llama13b/Megatron-DeepSpeed/dataset/download_ckpt.sh +8 -0
  4. docker/intel_code/llama13b/Megatron-DeepSpeed/dataset/download_vocab.sh +2 -0
  5. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_config_gpt_TEMPLATE.json +38 -0
  6. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_config_gpt_Zero2_TEMPLATE.json +38 -0
  7. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_evalharness.sh +72 -0
  8. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_MoE128.sh +348 -0
  9. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128.sh +340 -0
  10. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128_MoS.sh +354 -0
  11. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_dense.sh +349 -0
  12. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_dense_cl.sh +285 -0
  13. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_125M_MoE64.sh +372 -0
  14. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_125M_dense_cl.sh +309 -0
  15. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_MoE128.sh +348 -0
  16. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_PR-MoE32or64.sh +341 -0
  17. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_PR-MoE32or64_MoS.sh +353 -0
  18. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_dense.sh +348 -0
  19. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_6.7B_dense.sh +349 -0
  20. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/README.md +33 -0
  21. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/curriculum_learning/README.md +1 -0
  22. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/curriculum_learning/ds_pretrain_gpt2.sh +150 -0
  23. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/curriculum_learning/ds_pretrain_gpt_1.3B_rope_slw.sh +347 -0
  24. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/curriculum_learning/ds_train.sh +37 -0
  25. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/analyze_data.py +239 -0
  26. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/ds_analyze_bert_data_map.sh +67 -0
  27. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/ds_analyze_bert_data_reduce.sh +66 -0
  28. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/finetune/ds_finetune_bert_mnli.sh +150 -0
  29. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/finetune/ds_finetune_bert_qqp.sh +158 -0
  30. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/pretrain/ds_config_bert_1clmetric_TEMPLATE.json +73 -0
  31. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/pretrain/ds_config_bert_2clmetrics_TEMPLATE.json +87 -0
  32. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/pretrain/ds_pretrain_bert_336M_run.sh +363 -0
  33. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/generate_text.sh +51 -0
  34. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/pretrain_llama2_distributed.sh +135 -0
  35. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/pretrain_llama_distributed.sh +132 -0
  36. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_config_gpt_TEMPLATE.json +23 -0
  37. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_pretrain_gpt_1.3B_megatron_checkpointing.sh +345 -0
  38. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_pretrain_gpt_125M.sh +331 -0
  39. docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_pretrain_gpt_13B.sh +332 -0
  40. docker/intel_code/llama13b/Megatron-DeepSpeed/images/Achieved_petaFLOPs.png +3 -0
  41. docker/intel_code/llama13b/Megatron-DeepSpeed/images/cases_april2021.png +3 -0
  42. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/__init__.cpython-310.pyc +0 -0
  43. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/bert_model.cpython-310.pyc +0 -0
  44. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/distributed.cpython-310.pyc +0 -0
  45. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/enums.cpython-310.pyc +0 -0
  46. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/fused_bias_gelu.cpython-310.pyc +0 -0
  47. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/fused_layer_norm.cpython-310.pyc +0 -0
  48. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/fused_softmax.cpython-310.pyc +0 -0
  49. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/gpt_model.cpython-310.pyc +0 -0
  50. docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/language_model.cpython-310.pyc +0 -0
docker/intel_code/llama13b/Megatron-DeepSpeed/dataset/README.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Run the scripts below to setup dataset
2
+
3
+ bash download_books.sh
4
+
5
+ bash download_vocab.sh
docker/intel_code/llama13b/Megatron-DeepSpeed/dataset/download_books.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ wget https://the-eye.eu/public/AI/pile_neox/data/BookCorpusDataset_text_document.bin
2
+ wget https://the-eye.eu/public/AI/pile_neox/data/BookCorpusDataset_text_document.idx
docker/intel_code/llama13b/Megatron-DeepSpeed/dataset/download_ckpt.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ mkdir -p checkpoints/gpt2_345m
2
+
3
+ cd checkpoints/gpt2_345m
4
+ wget --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/megatron_lm_345m/versions/v0.0/zip -O megatron_lm_345m_v0.0.zip
5
+ unzip megatron_lm_345m_v0.0.zip
6
+ rm megatron_lm_345m_v0.0.zip
7
+ cd ../..
8
+
docker/intel_code/llama13b/Megatron-DeepSpeed/dataset/download_vocab.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json
2
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_config_gpt_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": ZERO_STAGE
8
+ },
9
+
10
+ "gradient_clipping": 1.0,
11
+ "prescale_gradients": PRESCALE_GRAD,
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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_evalharness.sh ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ --tokenizer-type GPT2BPETokenizer \
57
+ --adaptive_seq_len\
58
+ --eval_fp32\
59
+ --task_list $TASKS\
60
+ --results_path $RESULT_PATH \
61
+ --deepspeed \
62
+ --deepspeed_config $CONFIG_PATH \
63
+ $MEGATRON_REQUIRED_ARGS\
64
+ "
65
+
66
+ if [[ "${NO_PP}" = "true" ]]; then
67
+ CMD="${CMD} \
68
+ --no-pipeline-parallel"
69
+ fi
70
+
71
+ LAUNCHER="deepspeed --num_nodes $NUM_NODE --num_gpus $NUM_GPU_PER_NODE"
72
+ $LAUNCHER $CMD
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_MoE128.sh ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
126
+ # EP_SIZE=1
127
+ EP_SIZE=128
128
+
129
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+ else
132
+ EP_PARALLEL_SIZE=$EP_SIZE
133
+ fi
134
+
135
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
136
+ ## found that lower LR and min LR (than the base dense model) helps.
137
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
138
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
139
+ ## heavily tuned.
140
+ LR=1.2e-4
141
+ MIN_LR=1.0e-6
142
+
143
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
144
+ ## 1.3B MoE-128 model
145
+ MLC=0.01
146
+
147
+ ## Below configs adjust the MoE expert token capacity limit during training and
148
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
149
+ ## Larger capacity factor or disabling capacity limit could improve training
150
+ ## convergence, but will also reduce training throughput.
151
+ MOE_TRAIN_CAP_FACTOR=1.0
152
+ MOE_EVAL_CAP_FACTOR=1.0
153
+ MOE_MIN_CAP=4
154
+ MOE_DROP_TOKEN="true"
155
+ # MOE_DROP_TOKEN="false"
156
+ ###############################################################################
157
+ ### Curriculum learning (CL) configs
158
+ ## Enable/disable CL
159
+ CL_ENABLED="false"
160
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
161
+ ## for tuning the following configs
162
+ CL_START_SEQLEN=80
163
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
164
+ CL_TOKENS=60
165
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
166
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
167
+ ###############################################################################
168
+ ### Misc configs
169
+ LOG_INTERVAL=10
170
+ EVAL_ITERS=10
171
+ EVAL_INTERVAL=100
172
+ SAVE_INTERVAL=10000
173
+
174
+ ## Standard deviation for weight initialization
175
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
176
+ ## dense model. Usually larger model needs lower std.
177
+ INIT_STD=0.014
178
+ # INIT_STD=0.01
179
+
180
+ ## Activation checkpointing saves GPU memory, but reduces training speed
181
+ ACTIVATION_CHECKPOINT="true"
182
+ # ACTIVATION_CHECKPOINT="false"
183
+ ###############################################################################
184
+ ### Output and data configs
185
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
186
+ host="${HOSTNAME}"
187
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
188
+ if [[ $EP_SIZE -gt 1 ]]; then
189
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
190
+ fi
191
+ if [ "${CL_ENABLED}" = "true" ]; then
192
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
193
+ fi
194
+
195
+ OUTPUT_BASEPATH=$DIR/output
196
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
197
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
199
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
200
+ mkdir -p ${TENSORBOARD_DIR}
201
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
202
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
203
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
204
+
205
+ # USE_INTERNAL_DATA="true"
206
+ USE_INTERNAL_DATA="false"
207
+
208
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
209
+ ## The internal data is only accessible within Microsoft
210
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
211
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
212
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
213
+ ## For cluster Lab-RR1-V100
214
+ BASE_DATA_PATH=/data/Megatron-LM/data
215
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
216
+ ## For cluster Azure-CentralUS-A100
217
+ # BASE_DATA_PATH=/data/Megatron-LM/data
218
+ # DATA_HOME=/vc_data_1/users/amawa/blended
219
+
220
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
221
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
222
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
223
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
224
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
225
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
226
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
227
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
228
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
229
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
230
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
231
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
232
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
233
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
234
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
235
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
236
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
237
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
238
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
239
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
240
+ 0.01359 ${ARX} 0.01588 ${GIT}"
241
+ else
242
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
243
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
244
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
245
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
246
+ fi
247
+ ###############################################################################
248
+ data_options=" \
249
+ --vocab-file ${VOCAB_PATH} \
250
+ --merge-file ${MERGE_PATH} \
251
+ --data-path ${DATA_BLEND} \
252
+ --data-impl mmap"
253
+
254
+ megatron_options=" \
255
+ --override-opt_param-scheduler \
256
+ --adam-beta1 0.9 \
257
+ --adam-beta2 0.95 \
258
+ --tensor-model-parallel-size ${MP_SIZE} \
259
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
260
+ --num-experts ${EP_SIZE} \
261
+ --moe-loss-coeff ${MLC} \
262
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
263
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
264
+ --moe-min-capacity ${MOE_MIN_CAP} \
265
+ --init-method-std ${INIT_STD} \
266
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
267
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
268
+ --micro-batch-size ${BATCH_SIZE} \
269
+ --exit-duration-in-mins ${EXIT_DURATION} \
270
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
271
+ --num-layers ${NUM_LAYERS} \
272
+ --hidden-size ${HIDDEN_SIZE} \
273
+ --num-attention-heads ${NUM_ATTN_HEADS} \
274
+ --seq-length ${SEQ_LEN} \
275
+ --max-position-embeddings ${SEQ_LEN} \
276
+ --train-tokens ${TRAIN_TOKENS} \
277
+ --train-iters ${TRAIN_ITERS} \
278
+ --lr ${LR} \
279
+ --min-lr ${MIN_LR} \
280
+ --lr-decay-style cosine \
281
+ --split 98,2,0 \
282
+ --log-interval ${LOG_INTERVAL} \
283
+ --eval-interval ${EVAL_INTERVAL} \
284
+ --eval-iters ${EVAL_ITERS} \
285
+ --save-interval ${SAVE_INTERVAL} \
286
+ --weight-decay 0.1 \
287
+ --clip-grad 1.0 \
288
+ --hysteresis 2 \
289
+ --num-workers 0 \
290
+ --fp16 \
291
+ --load ${CHECKPOINT_PATH} \
292
+ --save ${CHECKPOINT_PATH} \
293
+ --tensorboard-queue-size 1 \
294
+ --log-timers-to-tensorboard \
295
+ --log-batch-size-to-tensorboard \
296
+ --log-validation-ppl-to-tensorboard \
297
+ --tensorboard-dir ${TENSORBOARD_DIR}"
298
+
299
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
300
+ megatron_options="${megatron_options} \
301
+ --checkpoint-activations"
302
+ fi
303
+
304
+ if [[ $EP_SIZE -gt 1 ]]; then
305
+ megatron_options="${megatron_options} \
306
+ --create-moe-param-group"
307
+ fi
308
+
309
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
310
+ megatron_options="${megatron_options} \
311
+ --disable-moe-token-dropping"
312
+ fi
313
+
314
+ template_json="ds_config_gpt_TEMPLATE.json"
315
+ config_json="ds_config_gpt_${NAME}.json"
316
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
317
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
318
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
319
+ | sed "s/ZERO_STAGE/0/" \
320
+ | sed "s/PRESCALE_GRAD/true/" \
321
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
322
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
323
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
324
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
325
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
326
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
327
+ > ${config_json}
328
+
329
+ deepspeed_options=" \
330
+ --deepspeed \
331
+ --deepspeed_config ${config_json} \
332
+ --pipeline-model-parallel-size ${PP_SIZE}"
333
+
334
+ # Currently MoE is not compatible with pipeline parallel
335
+ if [[ $EP_SIZE -gt 1 ]]; then
336
+ deepspeed_options="${deepspeed_options} \
337
+ --no-pipeline-parallel"
338
+ fi
339
+
340
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
341
+ deepspeed_options="${deepspeed_options} \
342
+ --deepspeed-activation-checkpointing"
343
+ fi
344
+
345
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
346
+ echo ${run_cmd}
347
+ eval ${run_cmd}
348
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128.sh ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 128 means standard MoE
126
+ # EP_SIZE=128
127
+ EP_SIZE="64 64 64 64 64 64 64 64 64 64 128 128"
128
+
129
+
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+
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
+ ## heavily tuned.
137
+ LR=1.2e-4
138
+ MIN_LR=1.0e-6
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-64+128-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-opt_param-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
+
305
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
306
+ megatron_options="${megatron_options} \
307
+ --disable-moe-token-dropping"
308
+ fi
309
+
310
+ template_json="ds_config_gpt_Zero2_TEMPLATE.json"
311
+ config_json="ds_config_gpt_${NAME}.json"
312
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
313
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
314
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
315
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
316
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
317
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
318
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
319
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
320
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
321
+ > ${config_json}
322
+
323
+ deepspeed_options=" \
324
+ --deepspeed \
325
+ --deepspeed_config ${config_json} \
326
+ --pipeline-model-parallel-size ${PP_SIZE}"
327
+
328
+ # Currently MoE is not compatible with pipeline parallel
329
+ deepspeed_options="${deepspeed_options} \
330
+ --no-pipeline-parallel"
331
+
332
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
333
+ deepspeed_options="${deepspeed_options} \
334
+ --deepspeed-activation-checkpointing"
335
+ fi
336
+
337
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
338
+ echo ${run_cmd}
339
+ eval ${run_cmd}
340
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_PR-MoE64or128_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
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=128
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 128 means standard MoE
126
+ # EP_SIZE=128
127
+ EP_SIZE="64 64 64 64 64 64 64 64 128 128"
128
+ EP_SIZE_TEACHER="64 64 64 64 64 64 64 64 64 64 128 128"
129
+
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+
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
+ ## heavily tuned.
137
+ LR=1.2e-4
138
+ MIN_LR=1.0e-6
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-64+128-mos-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}"
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
+ ### Mixture-of-Students (MoS) configs
202
+ KD_BETA_CE=1
203
+ CHECKPOINT_PATH_STUDENT="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
204
+ 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/"
205
+ CHECKPOINT_PATH_SAVE="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
206
+
207
+ USE_INTERNAL_DATA="true"
208
+ # USE_INTERNAL_DATA="false"
209
+
210
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
211
+ ## The internal data is only accessible within Microsoft
212
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
213
+ BASE_DATA_PATH=/vc_data/Megatron-LM/data
214
+ DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
215
+ ## For cluster Lab-RR1-V100
216
+ # BASE_DATA_PATH=/data/Megatron-LM/data
217
+ # DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
218
+ ## For cluster Azure-CentralUS-A100
219
+ # BASE_DATA_PATH=/data/Megatron-LM/data
220
+ # DATA_HOME=/vc_data_1/users/amawa/blended
221
+
222
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
223
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
224
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
225
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
226
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
227
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
228
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
229
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
230
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
231
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
232
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
233
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
234
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
235
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
236
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
237
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
238
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
239
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
240
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
241
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
242
+ 0.01359 ${ARX} 0.01588 ${GIT}"
243
+ else
244
+ ## Placeholder, we plan to test a public dataset
245
+ VOCAB_PATH=""
246
+ MERGE_PATH=""
247
+ DATA_BLEND=""
248
+ fi
249
+ ###############################################################################
250
+ data_options=" \
251
+ --vocab-file ${VOCAB_PATH} \
252
+ --merge-file ${MERGE_PATH} \
253
+ --data-path ${DATA_BLEND} \
254
+ --data-impl mmap"
255
+
256
+ megatron_options=" \
257
+ --override-opt_param-scheduler \
258
+ --adam-beta1 0.9 \
259
+ --adam-beta2 0.95 \
260
+ --tensor-model-parallel-size ${MP_SIZE} \
261
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
262
+ --num-experts ${EP_SIZE} \
263
+ --moe-loss-coeff ${MLC} \
264
+ --mlp-type residual \
265
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
266
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
267
+ --moe-min-capacity ${MOE_MIN_CAP} \
268
+ --init-method-std ${INIT_STD} \
269
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
270
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
271
+ --micro-batch-size ${BATCH_SIZE} \
272
+ --exit-duration-in-mins ${EXIT_DURATION} \
273
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
274
+ --num-layers 21 \
275
+ --hidden-size ${HIDDEN_SIZE} \
276
+ --num-attention-heads ${NUM_ATTN_HEADS} \
277
+ --seq-length ${SEQ_LEN} \
278
+ --max-position-embeddings ${SEQ_LEN} \
279
+ --train-tokens ${TRAIN_TOKENS} \
280
+ --train-iters ${TRAIN_ITERS} \
281
+ --lr ${LR} \
282
+ --min-lr ${MIN_LR} \
283
+ --lr-decay-style cosine \
284
+ --split 98,2,0 \
285
+ --log-interval ${LOG_INTERVAL} \
286
+ --eval-interval ${EVAL_INTERVAL} \
287
+ --eval-iters ${EVAL_ITERS} \
288
+ --save-interval ${SAVE_INTERVAL} \
289
+ --weight-decay 0.1 \
290
+ --clip-grad 1.0 \
291
+ --hysteresis 2 \
292
+ --num-workers 0 \
293
+ --fp16 \
294
+ --load ${CHECKPOINT_PATH_STUDENT} \
295
+ --save ${CHECKPOINT_PATH_SAVE} \
296
+ --mos \
297
+ --kd-beta-ce ${KD_BETA_CE} \
298
+ --num-layers-teacher ${NUM_LAYERS} \
299
+ --num-experts-teacher ${EP_SIZE_TEACHER} \
300
+ --hidden-size-teacher ${HIDDEN_SIZE} \
301
+ --num-attention-heads-teacher ${NUM_ATTN_HEADS} \
302
+ --load-teacher ${CHECKPOINT_PATH_TEACHER} \
303
+ --tensorboard-queue-size 1 \
304
+ --log-timers-to-tensorboard \
305
+ --log-batch-size-to-tensorboard \
306
+ --log-validation-ppl-to-tensorboard \
307
+ --tensorboard-dir ${TENSORBOARD_DIR}"
308
+
309
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
310
+ megatron_options="${megatron_options} \
311
+ --checkpoint-activations"
312
+ fi
313
+
314
+ megatron_options="${megatron_options} \
315
+ --create-moe-param-group"
316
+
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_Zero2_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
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
346
+ deepspeed_options="${deepspeed_options} \
347
+ --deepspeed-activation-checkpointing"
348
+ fi
349
+
350
+ # run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
351
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}.log"
352
+ echo ${run_cmd}
353
+ eval ${run_cmd}
354
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_1.3B_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=2
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ MP_SIZE=4
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
126
+ EP_SIZE=1
127
+ # EP_SIZE=128
128
+
129
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+ else
132
+ EP_PARALLEL_SIZE=$EP_SIZE
133
+ fi
134
+
135
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
136
+ ## found that lower LR and min LR (than the base dense model) helps.
137
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
138
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
139
+ ## heavily tuned.
140
+ # LR=2.0e-4
141
+ # MIN_LR=2e-06
142
+
143
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
144
+ ## 1.3B MoE-128 model
145
+ MLC=0.01
146
+
147
+ ## Below configs adjust the MoE expert token capacity limit during training and
148
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
149
+ ## Larger capacity factor or disabling capacity limit could improve training
150
+ ## convergence, but will also reduce training throughput.
151
+ MOE_TRAIN_CAP_FACTOR=1.0
152
+ MOE_EVAL_CAP_FACTOR=1.0
153
+ MOE_MIN_CAP=4
154
+ MOE_DROP_TOKEN="true"
155
+ # MOE_DROP_TOKEN="false"
156
+ ###############################################################################
157
+ ### Curriculum learning (CL) configs
158
+ ## Enable/disable CL
159
+ CL_ENABLED="false"
160
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
161
+ ## for tuning the following configs
162
+ CL_START_SEQLEN=80
163
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
164
+ CL_TOKENS=60
165
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
166
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
167
+ ###############################################################################
168
+ ### Misc configs
169
+ LOG_INTERVAL=10
170
+ EVAL_ITERS=10
171
+ EVAL_INTERVAL=100
172
+ SAVE_INTERVAL=1000
173
+
174
+ ## Standard deviation for weight initialization
175
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
176
+ ## dense model. Usually larger model needs lower std.
177
+ INIT_STD=0.014
178
+ # INIT_STD=0.01
179
+
180
+ ## Activation checkpointing saves GPU memory, but reduces training speed
181
+ ACTIVATION_CHECKPOINT="true"
182
+ # ACTIVATION_CHECKPOINT="false"
183
+ ###############################################################################
184
+ ### Output and data configs
185
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
186
+ host="${HOSTNAME}"
187
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
188
+ if [[ $EP_SIZE -gt 1 ]]; then
189
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
190
+ fi
191
+ if [ "${CL_ENABLED}" = "true" ]; then
192
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
193
+ fi
194
+
195
+ OUTPUT_BASEPATH=$DIR/output
196
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
197
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
199
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
200
+ mkdir -p ${TENSORBOARD_DIR}
201
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
202
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
203
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
204
+
205
+ # USE_INTERNAL_DATA="true"
206
+ USE_INTERNAL_DATA="false"
207
+
208
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
209
+ ## The internal data is only accessible within Microsoft
210
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
211
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
212
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
213
+ ## For cluster Lab-RR1-V100
214
+ BASE_DATA_PATH=/data/Megatron-LM/data
215
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
216
+ ## For cluster Azure-CentralUS-A100
217
+ # BASE_DATA_PATH=/data/Megatron-LM/data
218
+ # DATA_HOME=/vc_data_1/users/amawa/blended
219
+
220
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
221
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
222
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
223
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
224
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
225
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
226
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
227
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
228
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
229
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
230
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
231
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
232
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
233
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
234
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
235
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
236
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
237
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
238
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
239
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
240
+ 0.01359 ${ARX} 0.01588 ${GIT}"
241
+ else
242
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
243
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
244
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
245
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
246
+ fi
247
+ ###############################################################################
248
+ data_options=" \
249
+ --vocab-file ${VOCAB_PATH} \
250
+ --merge-file ${MERGE_PATH} \
251
+ --data-path ${DATA_BLEND} \
252
+ --data-impl mmap"
253
+
254
+ megatron_options=" \
255
+ --override-opt_param-scheduler \
256
+ --adam-beta1 0.9 \
257
+ --adam-beta2 0.95 \
258
+ --tensor-model-parallel-size ${MP_SIZE} \
259
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
260
+ --num-experts ${EP_SIZE} \
261
+ --moe-loss-coeff ${MLC} \
262
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
263
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
264
+ --moe-min-capacity ${MOE_MIN_CAP} \
265
+ --init-method-std ${INIT_STD} \
266
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
267
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
268
+ --micro-batch-size ${BATCH_SIZE} \
269
+ --exit-duration-in-mins ${EXIT_DURATION} \
270
+ --rampup-batch-size 32 32 1953125 \
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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/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-opt_param-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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_125M_MoE64.sh ADDED
@@ -0,0 +1,372 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
123
+ NUM_GPUS_PERNODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
124
+ NUM_NODE=$(( ${NUM_GPUS} / ${NUM_GPUS_PERNODE} ))
125
+ ###############################################################################
126
+ ### MoE configs
127
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
128
+ # EP_SIZE=1
129
+ EP_SIZE=64
130
+
131
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
132
+ EP_PARALLEL_SIZE=$NUM_GPUS
133
+ else
134
+ EP_PARALLEL_SIZE=$EP_SIZE
135
+ fi
136
+
137
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
138
+ ## found that lower LR and min LR (than the base dense model) helps.
139
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
140
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
141
+ ## heavily tuned.
142
+ LR=4.5e-4
143
+ MIN_LR=4.5e-06
144
+
145
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
146
+ ## 1.3B MoE-128 model
147
+ MLC=0.01
148
+
149
+ ## Below configs adjust the MoE expert token capacity limit during training and
150
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
151
+ ## Larger capacity factor or disabling capacity limit could improve training
152
+ ## convergence, but will also reduce training throughput.
153
+ MOE_TRAIN_CAP_FACTOR=1.0
154
+ MOE_EVAL_CAP_FACTOR=1.0
155
+ MOE_MIN_CAP=4
156
+ MOE_DROP_TOKEN="true"
157
+ # MOE_DROP_TOKEN="false"
158
+ ###############################################################################
159
+ ### Curriculum learning (CL) configs
160
+ ## Enable/disable CL
161
+ CL_ENABLED="false"
162
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
163
+ ## for tuning the following configs
164
+ CL_START_SEQLEN=80
165
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
166
+ CL_TOKENS=60
167
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
168
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
169
+ ###############################################################################
170
+ ### Misc configs
171
+ LOG_INTERVAL=10
172
+ EVAL_ITERS=10
173
+ EVAL_INTERVAL=100
174
+ SAVE_INTERVAL=10000
175
+
176
+ ## Standard deviation for weight initialization
177
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
178
+ ## dense model. Usually larger model needs lower std.
179
+ INIT_STD=0.014
180
+ # INIT_STD=0.01
181
+
182
+ ## Activation checkpointing saves GPU memory, but reduces training speed
183
+ ACTIVATION_CHECKPOINT="true"
184
+ # ACTIVATION_CHECKPOINT="false"
185
+ ###############################################################################
186
+ ### Output and data configs
187
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
188
+ host="${HOSTNAME}"
189
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
190
+ if [[ $EP_SIZE -gt 1 ]]; then
191
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
192
+ fi
193
+ if [ "${CL_ENABLED}" = "true" ]; then
194
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
195
+ fi
196
+
197
+ OUTPUT_BASEPATH=$DIR/output
198
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
199
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
200
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
201
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
202
+ mkdir -p ${TENSORBOARD_DIR}
203
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
204
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
205
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
206
+
207
+ # USE_INTERNAL_DATA="true"
208
+ USE_INTERNAL_DATA="false"
209
+
210
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
211
+ ## The internal data is only accessible within Microsoft
212
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
213
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
214
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
215
+ ## For cluster Lab-RR1-V100
216
+ BASE_DATA_PATH=/data/Megatron-LM/data
217
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
218
+ ## For cluster Azure-CentralUS-A100
219
+ # BASE_DATA_PATH=/data/Megatron-LM/data
220
+ # DATA_HOME=/vc_data_1/users/amawa/blended
221
+
222
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
223
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
224
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
225
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
226
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
227
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
228
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
229
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
230
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
231
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
232
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
233
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
234
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
235
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
236
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
237
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
238
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
239
+ DATA_PATH="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
240
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
241
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
242
+ 0.01359 ${ARX} 0.01588 ${GIT}"
243
+ else
244
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
245
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
246
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
247
+ # For cluster Azure-EastUS-V100-32GB-4, Lab-RR1-V100
248
+ DATA_PATH=/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing/pile_text_document
249
+ # For cluster Azure-WestUS3-A100
250
+ # DATA_PATH=/blob/data/the_pile_public_merged_nopreprocessing/pile_text_document
251
+ fi
252
+ ###############################################################################
253
+ data_options=" \
254
+ --vocab-file ${VOCAB_PATH} \
255
+ --merge-file ${MERGE_PATH} \
256
+ --data-path ${DATA_PATH} \
257
+ --data-impl mmap"
258
+
259
+ megatron_options=" \
260
+ --override-opt_param-scheduler \
261
+ --adam-beta1 0.9 \
262
+ --adam-beta2 0.95 \
263
+ --tensor-model-parallel-size ${MP_SIZE} \
264
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
265
+ --num-experts ${EP_SIZE} \
266
+ --moe-loss-coeff ${MLC} \
267
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
268
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
269
+ --moe-min-capacity ${MOE_MIN_CAP} \
270
+ --init-method-std ${INIT_STD} \
271
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
272
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
273
+ --micro-batch-size ${BATCH_SIZE} \
274
+ --exit-duration-in-mins ${EXIT_DURATION} \
275
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
276
+ --num-layers ${NUM_LAYERS} \
277
+ --hidden-size ${HIDDEN_SIZE} \
278
+ --num-attention-heads ${NUM_ATTN_HEADS} \
279
+ --seq-length ${SEQ_LEN} \
280
+ --max-position-embeddings ${SEQ_LEN} \
281
+ --train-tokens ${TRAIN_TOKENS} \
282
+ --train-iters ${TRAIN_ITERS} \
283
+ --lr ${LR} \
284
+ --min-lr ${MIN_LR} \
285
+ --lr-decay-style cosine \
286
+ --split 98,2,0 \
287
+ --log-interval ${LOG_INTERVAL} \
288
+ --eval-interval ${EVAL_INTERVAL} \
289
+ --eval-iters ${EVAL_ITERS} \
290
+ --save-interval ${SAVE_INTERVAL} \
291
+ --weight-decay 0.1 \
292
+ --clip-grad 1.0 \
293
+ --hysteresis 2 \
294
+ --num-workers 0 \
295
+ --fp16 \
296
+ --load ${CHECKPOINT_PATH} \
297
+ --save ${CHECKPOINT_PATH} \
298
+ --tensorboard-queue-size 1 \
299
+ --log-timers-to-tensorboard \
300
+ --log-batch-size-to-tensorboard \
301
+ --log-validation-ppl-to-tensorboard \
302
+ --tensorboard-dir ${TENSORBOARD_DIR}"
303
+
304
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
305
+ megatron_options="${megatron_options} \
306
+ --checkpoint-activations"
307
+ fi
308
+
309
+ if [[ $EP_SIZE -gt 1 ]]; then
310
+ megatron_options="${megatron_options} \
311
+ --create-moe-param-group"
312
+ fi
313
+
314
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
315
+ megatron_options="${megatron_options} \
316
+ --disable-moe-token-dropping"
317
+ fi
318
+
319
+ template_json="ds_config_gpt_TEMPLATE.json"
320
+ config_json="ds_config_gpt_${NAME}.json"
321
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
322
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
323
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
324
+ | sed "s/ZERO_STAGE/0/" \
325
+ | sed "s/PRESCALE_GRAD/true/" \
326
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
327
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
328
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
329
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
330
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
331
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
332
+ > ${config_json}
333
+
334
+ deepspeed_options=" \
335
+ --deepspeed \
336
+ --deepspeed_config ${config_json} \
337
+ --pipeline-model-parallel-size ${PP_SIZE}"
338
+
339
+ # Currently MoE is not compatible with pipeline parallel
340
+ if [[ $EP_SIZE -gt 1 ]]; then
341
+ deepspeed_options="${deepspeed_options} \
342
+ --no-pipeline-parallel"
343
+ fi
344
+
345
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
346
+ deepspeed_options="${deepspeed_options} \
347
+ --deepspeed-activation-checkpointing"
348
+ fi
349
+
350
+ ## When saving checkpoint to a storage with cache, their could be consistency
351
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
352
+ ## and broadcast it to all nodes.
353
+ ITERATION_FILE="$CHECKPOINT_PATH/latest_checkpointed_iteration.txt"
354
+ ITERATION_FILE_2="$CHECKPOINT_PATH/latest"
355
+ ITERATION=0
356
+ for (( node = 0; node <= NUM_NODE-1; node++ ))
357
+ do
358
+ if $(ssh -q worker-"$node" "test -f \"$ITERATION_FILE\""); then
359
+ LOCAL_ITERATION=$(ssh -q worker-"$node" cat $ITERATION_FILE)
360
+ ITERATION=$(( ${LOCAL_ITERATION} > ${ITERATION} ? ${LOCAL_ITERATION} : ${ITERATION} ))
361
+ fi
362
+ done
363
+ if [[ $ITERATION -gt 0 ]]; then
364
+ ITERATION_2="global_step${ITERATION}"
365
+ ds_ssh "echo $ITERATION > $ITERATION_FILE"
366
+ ds_ssh "echo $ITERATION_2 > $ITERATION_FILE_2"
367
+ fi
368
+
369
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
370
+ echo ${run_cmd}
371
+ eval ${run_cmd}
372
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/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-opt_param-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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_MoE128.sh ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
126
+ # EP_SIZE=1
127
+ EP_SIZE=128
128
+
129
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+ else
132
+ EP_PARALLEL_SIZE=$EP_SIZE
133
+ fi
134
+
135
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
136
+ ## found that lower LR and min LR (than the base dense model) helps.
137
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
138
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
139
+ ## heavily tuned.
140
+ LR=2.0e-4
141
+ MIN_LR=2e-06
142
+
143
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
144
+ ## 1.3B MoE-128 model
145
+ MLC=0.01
146
+
147
+ ## Below configs adjust the MoE expert token capacity limit during training and
148
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
149
+ ## Larger capacity factor or disabling capacity limit could improve training
150
+ ## convergence, but will also reduce training throughput.
151
+ MOE_TRAIN_CAP_FACTOR=1.0
152
+ MOE_EVAL_CAP_FACTOR=1.0
153
+ MOE_MIN_CAP=4
154
+ MOE_DROP_TOKEN="true"
155
+ # MOE_DROP_TOKEN="false"
156
+ ###############################################################################
157
+ ### Curriculum learning (CL) configs
158
+ ## Enable/disable CL
159
+ CL_ENABLED="false"
160
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
161
+ ## for tuning the following configs
162
+ CL_START_SEQLEN=80
163
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
164
+ CL_TOKENS=60
165
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
166
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
167
+ ###############################################################################
168
+ ### Misc configs
169
+ LOG_INTERVAL=10
170
+ EVAL_ITERS=10
171
+ EVAL_INTERVAL=100
172
+ SAVE_INTERVAL=10000
173
+
174
+ ## Standard deviation for weight initialization
175
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
176
+ ## dense model. Usually larger model needs lower std.
177
+ INIT_STD=0.014
178
+ # INIT_STD=0.01
179
+
180
+ ## Activation checkpointing saves GPU memory, but reduces training speed
181
+ ACTIVATION_CHECKPOINT="true"
182
+ # ACTIVATION_CHECKPOINT="false"
183
+ ###############################################################################
184
+ ### Output and data configs
185
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
186
+ host="${HOSTNAME}"
187
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
188
+ if [[ $EP_SIZE -gt 1 ]]; then
189
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
190
+ fi
191
+ if [ "${CL_ENABLED}" = "true" ]; then
192
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
193
+ fi
194
+
195
+ OUTPUT_BASEPATH=$DIR/output
196
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
197
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
199
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
200
+ mkdir -p ${TENSORBOARD_DIR}
201
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
202
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
203
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
204
+
205
+ # USE_INTERNAL_DATA="true"
206
+ USE_INTERNAL_DATA="false"
207
+
208
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
209
+ ## The internal data is only accessible within Microsoft
210
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
211
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
212
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
213
+ ## For cluster Lab-RR1-V100
214
+ BASE_DATA_PATH=/data/Megatron-LM/data
215
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
216
+ ## For cluster Azure-CentralUS-A100
217
+ # BASE_DATA_PATH=/data/Megatron-LM/data
218
+ # DATA_HOME=/vc_data_1/users/amawa/blended
219
+
220
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
221
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
222
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
223
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
224
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
225
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
226
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
227
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
228
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
229
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
230
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
231
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
232
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
233
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
234
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
235
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
236
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
237
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
238
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
239
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
240
+ 0.01359 ${ARX} 0.01588 ${GIT}"
241
+ else
242
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
243
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
244
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
245
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
246
+ fi
247
+ ###############################################################################
248
+ data_options=" \
249
+ --vocab-file ${VOCAB_PATH} \
250
+ --merge-file ${MERGE_PATH} \
251
+ --data-path ${DATA_BLEND} \
252
+ --data-impl mmap"
253
+
254
+ megatron_options=" \
255
+ --override-opt_param-scheduler \
256
+ --adam-beta1 0.9 \
257
+ --adam-beta2 0.95 \
258
+ --tensor-model-parallel-size ${MP_SIZE} \
259
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
260
+ --num-experts ${EP_SIZE} \
261
+ --moe-loss-coeff ${MLC} \
262
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
263
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
264
+ --moe-min-capacity ${MOE_MIN_CAP} \
265
+ --init-method-std ${INIT_STD} \
266
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
267
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
268
+ --micro-batch-size ${BATCH_SIZE} \
269
+ --exit-duration-in-mins ${EXIT_DURATION} \
270
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
271
+ --num-layers ${NUM_LAYERS} \
272
+ --hidden-size ${HIDDEN_SIZE} \
273
+ --num-attention-heads ${NUM_ATTN_HEADS} \
274
+ --seq-length ${SEQ_LEN} \
275
+ --max-position-embeddings ${SEQ_LEN} \
276
+ --train-tokens ${TRAIN_TOKENS} \
277
+ --train-iters ${TRAIN_ITERS} \
278
+ --lr ${LR} \
279
+ --min-lr ${MIN_LR} \
280
+ --lr-decay-style cosine \
281
+ --split 98,2,0 \
282
+ --log-interval ${LOG_INTERVAL} \
283
+ --eval-interval ${EVAL_INTERVAL} \
284
+ --eval-iters ${EVAL_ITERS} \
285
+ --save-interval ${SAVE_INTERVAL} \
286
+ --weight-decay 0.1 \
287
+ --clip-grad 1.0 \
288
+ --hysteresis 2 \
289
+ --num-workers 0 \
290
+ --fp16 \
291
+ --load ${CHECKPOINT_PATH} \
292
+ --save ${CHECKPOINT_PATH} \
293
+ --tensorboard-queue-size 1 \
294
+ --log-timers-to-tensorboard \
295
+ --log-batch-size-to-tensorboard \
296
+ --log-validation-ppl-to-tensorboard \
297
+ --tensorboard-dir ${TENSORBOARD_DIR}"
298
+
299
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
300
+ megatron_options="${megatron_options} \
301
+ --checkpoint-activations"
302
+ fi
303
+
304
+ if [[ $EP_SIZE -gt 1 ]]; then
305
+ megatron_options="${megatron_options} \
306
+ --create-moe-param-group"
307
+ fi
308
+
309
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
310
+ megatron_options="${megatron_options} \
311
+ --disable-moe-token-dropping"
312
+ fi
313
+
314
+ template_json="ds_config_gpt_TEMPLATE.json"
315
+ config_json="ds_config_gpt_${NAME}.json"
316
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
317
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
318
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
319
+ | sed "s/ZERO_STAGE/0/" \
320
+ | sed "s/PRESCALE_GRAD/true/" \
321
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
322
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
323
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
324
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
325
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
326
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
327
+ > ${config_json}
328
+
329
+ deepspeed_options=" \
330
+ --deepspeed \
331
+ --deepspeed_config ${config_json} \
332
+ --pipeline-model-parallel-size ${PP_SIZE}"
333
+
334
+ # Currently MoE is not compatible with pipeline parallel
335
+ if [[ $EP_SIZE -gt 1 ]]; then
336
+ deepspeed_options="${deepspeed_options} \
337
+ --no-pipeline-parallel"
338
+ fi
339
+
340
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
341
+ deepspeed_options="${deepspeed_options} \
342
+ --deepspeed-activation-checkpointing"
343
+ fi
344
+
345
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
346
+ echo ${run_cmd}
347
+ eval ${run_cmd}
348
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_PR-MoE32or64.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=4
114
+
115
+ ## Model parallelism, 1 is no MP
116
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 128 means standard MoE
126
+ # EP_SIZE=128
127
+ EP_SIZE="32 32 32 32 32 32 32 32 32 32 64 64"
128
+
129
+ EP_PARALLEL_SIZE=$NUM_GPUS
130
+
131
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
132
+ ## found that lower LR and min LR (than the base dense model) helps.
133
+ ## For 1.3B PR-MoE-64/128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
134
+ ## For 350M PR-MoE-32/64 model we used LR=3.0e-4 and MIN_LR=1.0e-6, but they are not
135
+ ## heavily tuned.
136
+ LR=3.0e-4
137
+ MIN_LR=1.0e-06
138
+
139
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
140
+ ## 1.3B MoE-128 model
141
+ MLC=0.01
142
+
143
+ ## Below configs adjust the MoE expert token capacity limit during training and
144
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
145
+ ## Larger capacity factor or disabling capacity limit could improve training
146
+ ## convergence, but will also reduce training throughput.
147
+ MOE_TRAIN_CAP_FACTOR=1.0
148
+ MOE_EVAL_CAP_FACTOR=1.0
149
+ MOE_MIN_CAP=4
150
+ MOE_DROP_TOKEN="true"
151
+ # MOE_DROP_TOKEN="false"
152
+ ###############################################################################
153
+ ### Curriculum learning (CL) configs
154
+ ## Enable/disable CL
155
+ CL_ENABLED="false"
156
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
157
+ ## for tuning the following configs
158
+ CL_START_SEQLEN=80
159
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
160
+ CL_TOKENS=60
161
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
162
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
163
+ ###############################################################################
164
+ ### Misc configs
165
+ LOG_INTERVAL=10
166
+ EVAL_ITERS=10
167
+ EVAL_INTERVAL=100
168
+ SAVE_INTERVAL=10000
169
+
170
+ ## Standard deviation for weight initialization
171
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
172
+ ## dense model. Usually larger model needs lower std.
173
+ INIT_STD=0.014
174
+ # INIT_STD=0.01
175
+
176
+ ## Activation checkpointing saves GPU memory, but reduces training speed
177
+ ACTIVATION_CHECKPOINT="true"
178
+ # ACTIVATION_CHECKPOINT="false"
179
+ ###############################################################################
180
+ ### Output and data configs
181
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
182
+ host="${HOSTNAME}"
183
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
184
+ NAME="${NAME}-ep-pyramid-32+64-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
185
+
186
+ if [ "${CL_ENABLED}" = "true" ]; then
187
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
188
+ fi
189
+
190
+ OUTPUT_BASEPATH=$DIR/output
191
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
192
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
193
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
194
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
195
+ mkdir -p ${TENSORBOARD_DIR}
196
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
197
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
198
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
199
+
200
+ # USE_INTERNAL_DATA="true"
201
+ USE_INTERNAL_DATA="false"
202
+
203
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
204
+ ## The internal data is only accessible within Microsoft
205
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
206
+ BASE_DATA_PATH=/vc_data/Megatron-LM/data
207
+ DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
208
+ ## For cluster Lab-RR1-V100
209
+ # BASE_DATA_PATH=/data/Megatron-LM/data
210
+ # DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
211
+ ## For cluster Azure-CentralUS-A100
212
+ # BASE_DATA_PATH=/data/Megatron-LM/data
213
+ # DATA_HOME=/vc_data_1/users/amawa/blended
214
+
215
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
216
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
217
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
218
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
219
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
220
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
221
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
222
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
223
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
224
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
225
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
226
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
227
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
228
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
229
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
230
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
231
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
232
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
233
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
234
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
235
+ 0.01359 ${ARX} 0.01588 ${GIT}"
236
+ else
237
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
238
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
239
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
240
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
241
+ fi
242
+ ###############################################################################
243
+ data_options=" \
244
+ --vocab-file ${VOCAB_PATH} \
245
+ --merge-file ${MERGE_PATH} \
246
+ --data-path ${DATA_BLEND} \
247
+ --data-impl mmap"
248
+
249
+ megatron_options=" \
250
+ --override-opt_param-scheduler \
251
+ --adam-beta1 0.9 \
252
+ --adam-beta2 0.95 \
253
+ --tensor-model-parallel-size ${MP_SIZE} \
254
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
255
+ --num-experts ${EP_SIZE} \
256
+ --moe-loss-coeff ${MLC} \
257
+ --mlp-type residual \
258
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
259
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
260
+ --moe-min-capacity ${MOE_MIN_CAP} \
261
+ --init-method-std ${INIT_STD} \
262
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
263
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
264
+ --micro-batch-size ${BATCH_SIZE} \
265
+ --exit-duration-in-mins ${EXIT_DURATION} \
266
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
267
+ --num-layers ${NUM_LAYERS} \
268
+ --hidden-size ${HIDDEN_SIZE} \
269
+ --num-attention-heads ${NUM_ATTN_HEADS} \
270
+ --seq-length ${SEQ_LEN} \
271
+ --max-position-embeddings ${SEQ_LEN} \
272
+ --train-tokens ${TRAIN_TOKENS} \
273
+ --train-iters ${TRAIN_ITERS} \
274
+ --lr ${LR} \
275
+ --min-lr ${MIN_LR} \
276
+ --lr-decay-style cosine \
277
+ --split 98,2,0 \
278
+ --log-interval ${LOG_INTERVAL} \
279
+ --eval-interval ${EVAL_INTERVAL} \
280
+ --eval-iters ${EVAL_ITERS} \
281
+ --save-interval ${SAVE_INTERVAL} \
282
+ --weight-decay 0.1 \
283
+ --clip-grad 1.0 \
284
+ --hysteresis 2 \
285
+ --num-workers 0 \
286
+ --fp16 \
287
+ --load ${CHECKPOINT_PATH} \
288
+ --save ${CHECKPOINT_PATH} \
289
+ --tensorboard-queue-size 1 \
290
+ --log-timers-to-tensorboard \
291
+ --log-batch-size-to-tensorboard \
292
+ --log-validation-ppl-to-tensorboard \
293
+ --tensorboard-dir ${TENSORBOARD_DIR}"
294
+
295
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
296
+ megatron_options="${megatron_options} \
297
+ --checkpoint-activations"
298
+ fi
299
+
300
+ megatron_options="${megatron_options} \
301
+ --create-moe-param-group"
302
+
303
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
304
+ megatron_options="${megatron_options} \
305
+ --disable-moe-token-dropping"
306
+ fi
307
+
308
+ template_json="ds_config_gpt_TEMPLATE.json"
309
+ config_json="ds_config_gpt_${NAME}.json"
310
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
311
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
312
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
313
+ | sed "s/ZERO_STAGE/0/" \
314
+ | sed "s/PRESCALE_GRAD/true/" \
315
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
316
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
317
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
318
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
319
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
320
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
321
+ > ${config_json}
322
+
323
+ deepspeed_options=" \
324
+ --deepspeed \
325
+ --deepspeed_config ${config_json} \
326
+ --pipeline-model-parallel-size ${PP_SIZE}"
327
+
328
+ # Currently MoE is not compatible with pipeline parallel
329
+ deepspeed_options="${deepspeed_options} \
330
+ --no-pipeline-parallel"
331
+
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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_PR-MoE32or64_MoS.sh ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 128 means standard MoE
126
+ # EP_SIZE=128
127
+ EP_SIZE="32 32 32 32 32 32 32 32 64 64"
128
+ EP_SIZE_TEACHER="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-mos-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
+ ### Mixture-of-Students (MoS) configs
202
+ KD_BETA_CE=1
203
+ CHECKPOINT_PATH_STUDENT="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
204
+ 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/"
205
+ CHECKPOINT_PATH_SAVE="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
206
+
207
+ USE_INTERNAL_DATA="true"
208
+ # USE_INTERNAL_DATA="false"
209
+
210
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
211
+ ## The internal data is only accessible within Microsoft
212
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
213
+ BASE_DATA_PATH=/vc_data/Megatron-LM/data
214
+ DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
215
+ ## For cluster Lab-RR1-V100
216
+ # BASE_DATA_PATH=/data/Megatron-LM/data
217
+ # DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
218
+ ## For cluster Azure-CentralUS-A100
219
+ # BASE_DATA_PATH=/data/Megatron-LM/data
220
+ # DATA_HOME=/vc_data_1/users/amawa/blended
221
+
222
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
223
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
224
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
225
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
226
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
227
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
228
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
229
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
230
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
231
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
232
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
233
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
234
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
235
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
236
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
237
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
238
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
239
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
240
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
241
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
242
+ 0.01359 ${ARX} 0.01588 ${GIT}"
243
+ else
244
+ ## Placeholder, we plan to test a public dataset
245
+ VOCAB_PATH=""
246
+ MERGE_PATH=""
247
+ DATA_BLEND=""
248
+ fi
249
+ ###############################################################################
250
+ data_options=" \
251
+ --vocab-file ${VOCAB_PATH} \
252
+ --merge-file ${MERGE_PATH} \
253
+ --data-path ${DATA_BLEND} \
254
+ --data-impl mmap"
255
+
256
+ megatron_options=" \
257
+ --override-opt_param-scheduler \
258
+ --adam-beta1 0.9 \
259
+ --adam-beta2 0.95 \
260
+ --tensor-model-parallel-size ${MP_SIZE} \
261
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
262
+ --num-experts ${EP_SIZE} \
263
+ --moe-loss-coeff ${MLC} \
264
+ --mlp-type residual \
265
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
266
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
267
+ --moe-min-capacity ${MOE_MIN_CAP} \
268
+ --init-method-std ${INIT_STD} \
269
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
270
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
271
+ --micro-batch-size ${BATCH_SIZE} \
272
+ --exit-duration-in-mins ${EXIT_DURATION} \
273
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
274
+ --num-layers 21 \
275
+ --hidden-size ${HIDDEN_SIZE} \
276
+ --num-attention-heads ${NUM_ATTN_HEADS} \
277
+ --seq-length ${SEQ_LEN} \
278
+ --max-position-embeddings ${SEQ_LEN} \
279
+ --train-tokens ${TRAIN_TOKENS} \
280
+ --train-iters ${TRAIN_ITERS} \
281
+ --lr ${LR} \
282
+ --min-lr ${MIN_LR} \
283
+ --lr-decay-style cosine \
284
+ --split 98,2,0 \
285
+ --log-interval ${LOG_INTERVAL} \
286
+ --eval-interval ${EVAL_INTERVAL} \
287
+ --eval-iters ${EVAL_ITERS} \
288
+ --save-interval ${SAVE_INTERVAL} \
289
+ --weight-decay 0.1 \
290
+ --clip-grad 1.0 \
291
+ --hysteresis 2 \
292
+ --num-workers 0 \
293
+ --fp16 \
294
+ --load ${CHECKPOINT_PATH_STUDENT} \
295
+ --save ${CHECKPOINT_PATH_SAVE} \
296
+ --mos \
297
+ --kd-beta-ce ${KD_BETA_CE} \
298
+ --num-layers-teacher ${NUM_LAYERS} \
299
+ --num-experts-teacher ${EP_SIZE_TEACHER} \
300
+ --hidden-size-teacher ${HIDDEN_SIZE} \
301
+ --num-attention-heads-teacher ${NUM_ATTN_HEADS} \
302
+ --load-teacher ${CHECKPOINT_PATH_TEACHER} \
303
+ --tensorboard-queue-size 1 \
304
+ --log-timers-to-tensorboard \
305
+ --log-batch-size-to-tensorboard \
306
+ --log-validation-ppl-to-tensorboard \
307
+ --tensorboard-dir ${TENSORBOARD_DIR}"
308
+
309
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
310
+ megatron_options="${megatron_options} \
311
+ --checkpoint-activations"
312
+ fi
313
+
314
+ megatron_options="${megatron_options} \
315
+ --create-moe-param-group"
316
+
317
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
318
+ megatron_options="${megatron_options} \
319
+ --disable-moe-token-dropping"
320
+ fi
321
+
322
+ template_json="ds_config_gpt_TEMPLATE.json"
323
+ config_json="ds_config_gpt_${NAME}.json"
324
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
325
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
326
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
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
+ deepspeed_options="${deepspeed_options} \
342
+ --no-pipeline-parallel"
343
+
344
+
345
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
346
+ deepspeed_options="${deepspeed_options} \
347
+ --deepspeed-activation-checkpointing"
348
+ fi
349
+
350
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
351
+ echo ${run_cmd}
352
+ eval ${run_cmd}
353
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_350M_dense.sh ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MP_SIZE=1
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
126
+ EP_SIZE=1
127
+ # EP_SIZE=128
128
+
129
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+ else
132
+ EP_PARALLEL_SIZE=$EP_SIZE
133
+ fi
134
+
135
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
136
+ ## found that lower LR and min LR (than the base dense model) helps.
137
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
138
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
139
+ ## heavily tuned.
140
+ # LR=2.0e-4
141
+ # MIN_LR=2e-06
142
+
143
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
144
+ ## 1.3B MoE-128 model
145
+ MLC=0.01
146
+
147
+ ## Below configs adjust the MoE expert token capacity limit during training and
148
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
149
+ ## Larger capacity factor or disabling capacity limit could improve training
150
+ ## convergence, but will also reduce training throughput.
151
+ MOE_TRAIN_CAP_FACTOR=1.0
152
+ MOE_EVAL_CAP_FACTOR=1.0
153
+ MOE_MIN_CAP=4
154
+ MOE_DROP_TOKEN="true"
155
+ # MOE_DROP_TOKEN="false"
156
+ ###############################################################################
157
+ ### Curriculum learning (CL) configs
158
+ ## Enable/disable CL
159
+ CL_ENABLED="false"
160
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
161
+ ## for tuning the following configs
162
+ CL_START_SEQLEN=80
163
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
164
+ CL_TOKENS=60
165
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
166
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
167
+ ###############################################################################
168
+ ### Misc configs
169
+ LOG_INTERVAL=10
170
+ EVAL_ITERS=10
171
+ EVAL_INTERVAL=100
172
+ SAVE_INTERVAL=1000
173
+
174
+ ## Standard deviation for weight initialization
175
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
176
+ ## dense model. Usually larger model needs lower std.
177
+ INIT_STD=0.014
178
+ # INIT_STD=0.01
179
+
180
+ ## Activation checkpointing saves GPU memory, but reduces training speed
181
+ ACTIVATION_CHECKPOINT="true"
182
+ # ACTIVATION_CHECKPOINT="false"
183
+ ###############################################################################
184
+ ### Output and data configs
185
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
186
+ host="${HOSTNAME}"
187
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
188
+ if [[ $EP_SIZE -gt 1 ]]; then
189
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
190
+ fi
191
+ if [ "${CL_ENABLED}" = "true" ]; then
192
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
193
+ fi
194
+
195
+ OUTPUT_BASEPATH=$DIR/output
196
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
197
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
199
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
200
+ mkdir -p ${TENSORBOARD_DIR}
201
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
202
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
203
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
204
+
205
+ # USE_INTERNAL_DATA="true"
206
+ USE_INTERNAL_DATA="false"
207
+
208
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
209
+ ## The internal data is only accessible within Microsoft
210
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
211
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
212
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
213
+ ## For cluster Lab-RR1-V100
214
+ BASE_DATA_PATH=/data/Megatron-LM/data
215
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
216
+ ## For cluster Azure-CentralUS-A100
217
+ # BASE_DATA_PATH=/data/Megatron-LM/data
218
+ # DATA_HOME=/vc_data_1/users/amawa/blended
219
+
220
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
221
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
222
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
223
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
224
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
225
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
226
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
227
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
228
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
229
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
230
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
231
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
232
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
233
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
234
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
235
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
236
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
237
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
238
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
239
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
240
+ 0.01359 ${ARX} 0.01588 ${GIT}"
241
+ else
242
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
243
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
244
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
245
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
246
+ fi
247
+ ###############################################################################
248
+ data_options=" \
249
+ --vocab-file ${VOCAB_PATH} \
250
+ --merge-file ${MERGE_PATH} \
251
+ --data-path ${DATA_BLEND} \
252
+ --data-impl mmap"
253
+
254
+ megatron_options=" \
255
+ --override-opt_param-scheduler \
256
+ --adam-beta1 0.9 \
257
+ --adam-beta2 0.95 \
258
+ --tensor-model-parallel-size ${MP_SIZE} \
259
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
260
+ --num-experts ${EP_SIZE} \
261
+ --moe-loss-coeff ${MLC} \
262
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
263
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
264
+ --moe-min-capacity ${MOE_MIN_CAP} \
265
+ --init-method-std ${INIT_STD} \
266
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
267
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
268
+ --micro-batch-size ${BATCH_SIZE} \
269
+ --exit-duration-in-mins ${EXIT_DURATION} \
270
+ --global-batch-size ${GLOBAL_BATCH_SIZE} \
271
+ --num-layers ${NUM_LAYERS} \
272
+ --hidden-size ${HIDDEN_SIZE} \
273
+ --num-attention-heads ${NUM_ATTN_HEADS} \
274
+ --seq-length ${SEQ_LEN} \
275
+ --max-position-embeddings ${SEQ_LEN} \
276
+ --train-tokens ${TRAIN_TOKENS} \
277
+ --train-samples ${TRAIN_SAMPLES} \
278
+ --lr ${LR} \
279
+ --min-lr ${MIN_LR} \
280
+ --lr-decay-style cosine \
281
+ --split 98,2,0 \
282
+ --log-interval ${LOG_INTERVAL} \
283
+ --eval-interval ${EVAL_INTERVAL} \
284
+ --eval-iters ${EVAL_ITERS} \
285
+ --save-interval ${SAVE_INTERVAL} \
286
+ --weight-decay 0.1 \
287
+ --clip-grad 1.0 \
288
+ --hysteresis 2 \
289
+ --num-workers 0 \
290
+ --fp16 \
291
+ --load ${CHECKPOINT_PATH} \
292
+ --save ${CHECKPOINT_PATH} \
293
+ --tensorboard-queue-size 1 \
294
+ --log-timers-to-tensorboard \
295
+ --log-batch-size-to-tensorboard \
296
+ --log-validation-ppl-to-tensorboard \
297
+ --tensorboard-dir ${TENSORBOARD_DIR}"
298
+
299
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
300
+ megatron_options="${megatron_options} \
301
+ --checkpoint-activations"
302
+ fi
303
+
304
+ if [[ $EP_SIZE -gt 1 ]]; then
305
+ megatron_options="${megatron_options} \
306
+ --create-moe-param-group"
307
+ fi
308
+
309
+ if [ "${MOE_DROP_TOKEN}" = "false" ]; then
310
+ megatron_options="${megatron_options} \
311
+ --disable-moe-token-dropping"
312
+ fi
313
+
314
+ template_json="ds_config_gpt_TEMPLATE.json"
315
+ config_json="ds_config_gpt_${NAME}.json"
316
+ sed "s/CONFIG_BATCH_SIZE/${GLOBAL_BATCH_SIZE}/" ${template_json} \
317
+ | sed "s/CONFIG_MBSIZE/${BATCH_SIZE}/" \
318
+ | sed "s/LOG_INTERVAL/${LOG_INTERVAL}/" \
319
+ | sed "s/ZERO_STAGE/0/" \
320
+ | sed "s/PRESCALE_GRAD/true/" \
321
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
322
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
323
+ | sed "s/CONFIG_CL_ENABLED/${CL_ENABLED}/" \
324
+ | sed "s/CONFIG_CL_MIN/${CL_START_SEQLEN}/" \
325
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
326
+ | sed "s/CONFIG_CL_DURATION/${CL_STEP}/" \
327
+ > ${config_json}
328
+
329
+ deepspeed_options=" \
330
+ --deepspeed \
331
+ --deepspeed_config ${config_json} \
332
+ --pipeline-model-parallel-size ${PP_SIZE}"
333
+
334
+ # Currently MoE is not compatible with pipeline parallel
335
+ if [[ $EP_SIZE -gt 1 ]]; then
336
+ deepspeed_options="${deepspeed_options} \
337
+ --no-pipeline-parallel"
338
+ fi
339
+
340
+ if [ "${ACTIVATION_CHECKPOINT}" = "true" ]; then
341
+ deepspeed_options="${deepspeed_options} \
342
+ --deepspeed-activation-checkpointing"
343
+ fi
344
+
345
+ run_cmd="deepspeed ${DIR}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &> ${OUTPUT_BASEPATH}/log/${NAME}_${host}_${current_time}.log"
346
+ echo ${run_cmd}
347
+ eval ${run_cmd}
348
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/MoE/ds_pretrain_gpt_6.7B_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
+ MP_SIZE=8
117
+
118
+ ## Pipeline parallelism
119
+ ## Currently we don't support PP for MoE. To disable PP, set PP_SIZE
120
+ ## to 1 and use the "--no-pipeline-parallel" arg.
121
+ PP_SIZE=1
122
+ NUM_GPUS=64
123
+ ###############################################################################
124
+ ### MoE configs
125
+ ## Number of experts. EP_SIZE 1 means dense model without MoE
126
+ EP_SIZE=1
127
+ # EP_SIZE=128
128
+
129
+ if [[ $EP_SIZE -gt $NUM_GPUS ]]; then
130
+ EP_PARALLEL_SIZE=$NUM_GPUS
131
+ else
132
+ EP_PARALLEL_SIZE=$EP_SIZE
133
+ fi
134
+
135
+ ## Original GPT-3 model always set min LR at 10% of max LR. For MoE model, we
136
+ ## found that lower LR and min LR (than the base dense model) helps.
137
+ ## For 1.3B MoE-128 model we used LR=1.2e-4 and MIN_LR=1.0e-6.
138
+ ## For 350M MoE-128 model we used LR=2.0e-4 and MIN_LR=2.0e-6, but they are not
139
+ ## heavily tuned.
140
+ # LR=2.0e-4
141
+ # MIN_LR=2e-06
142
+
143
+ ## Coefficient for MoE loss. We find that 0.01 is a good value at least for
144
+ ## 1.3B MoE-128 model
145
+ MLC=0.01
146
+
147
+ ## Below configs adjust the MoE expert token capacity limit during training and
148
+ ## eval. To completely disable capacity limit, set MOE_DROP_TOKEN to false.
149
+ ## Larger capacity factor or disabling capacity limit could improve training
150
+ ## convergence, but will also reduce training throughput.
151
+ MOE_TRAIN_CAP_FACTOR=1.0
152
+ MOE_EVAL_CAP_FACTOR=1.0
153
+ MOE_MIN_CAP=4
154
+ MOE_DROP_TOKEN="true"
155
+ # MOE_DROP_TOKEN="false"
156
+ ###############################################################################
157
+ ### Curriculum learning (CL) configs
158
+ ## Enable/disable CL
159
+ CL_ENABLED="false"
160
+ ## Consult the tutorial https://www.deepspeed.ai/tutorials/curriculum-learning/
161
+ ## for tuning the following configs
162
+ CL_START_SEQLEN=80
163
+ CL_AVG_SEQLEN=$(( (${CL_START_SEQLEN} + ${SEQ_LEN}) / 2 ))
164
+ CL_TOKENS=60
165
+ CL_TOKENS=$((${CL_TOKENS} * 1000000000))
166
+ CL_STEP=$(( ${CL_TOKENS} / (${GLOBAL_BATCH_SIZE} * ${CL_AVG_SEQLEN}) ))
167
+ ###############################################################################
168
+ ### Misc configs
169
+ LOG_INTERVAL=10
170
+ EVAL_ITERS=10
171
+ EVAL_INTERVAL=100
172
+ SAVE_INTERVAL=1000
173
+
174
+ ## Standard deviation for weight initialization
175
+ ## We used 0.014 for 350M/1.3B dense/MoE models, and used 0.01 for 6.7B
176
+ ## dense model. Usually larger model needs lower std.
177
+ # INIT_STD=0.014
178
+ INIT_STD=0.01
179
+
180
+ ## Activation checkpointing saves GPU memory, but reduces training speed
181
+ ACTIVATION_CHECKPOINT="true"
182
+ # ACTIVATION_CHECKPOINT="false"
183
+ ###############################################################################
184
+ ### Output and data configs
185
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
186
+ host="${HOSTNAME}"
187
+ NAME="gpt-${MODEL_SIZE}B-lr-${LR}-minlr-${MIN_LR}-bs-${GLOBAL_BATCH_SIZE}-gpus-${NUM_GPUS}-mp-${MP_SIZE}-pp-${PP_SIZE}"
188
+ if [[ $EP_SIZE -gt 1 ]]; then
189
+ NAME="${NAME}-ep-${EP_SIZE}-mlc-${MLC}-cap-${MOE_TRAIN_CAP_FACTOR}-drop-${MOE_DROP_TOKEN}"
190
+ fi
191
+ if [ "${CL_ENABLED}" = "true" ]; then
192
+ NAME="${NAME}-cl-${CL_START_SEQLEN}-${CL_STEP}"
193
+ fi
194
+
195
+ OUTPUT_BASEPATH=$DIR/output
196
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/"
197
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/"
198
+ mkdir -p "${OUTPUT_BASEPATH}/log/"
199
+ TENSORBOARD_DIR="${OUTPUT_BASEPATH}/tensorboard/${NAME}_${host}_${current_time}"
200
+ mkdir -p ${TENSORBOARD_DIR}
201
+ ## Note that for MoE model with billion-scale base model, the checkpoint can be
202
+ ## as large as TB-scale which normal NFS cannot handle efficiently.
203
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/${NAME}"
204
+
205
+ # USE_INTERNAL_DATA="true"
206
+ USE_INTERNAL_DATA="false"
207
+
208
+ if [ "${USE_INTERNAL_DATA}" = "true" ]; then
209
+ ## The internal data is only accessible within Microsoft
210
+ ## For cluster Azure-EastUS-V100-32GB-4, Azure-WestUS3-A100
211
+ # BASE_DATA_PATH=/vc_data/Megatron-LM/data
212
+ # DATA_HOME="/vc_data/pile-cc1-cc2-shuf"
213
+ ## For cluster Lab-RR1-V100
214
+ BASE_DATA_PATH=/data/Megatron-LM/data
215
+ DATA_HOME="/turing-ssd/users/conglli/data/pile-cc1-cc2-shuf"
216
+ ## For cluster Azure-CentralUS-A100
217
+ # BASE_DATA_PATH=/data/Megatron-LM/data
218
+ # DATA_HOME=/vc_data_1/users/amawa/blended
219
+
220
+ VOCAB_PATH=${BASE_DATA_PATH}/gpt2-vocab.json
221
+ MERGE_PATH=${BASE_DATA_PATH}/gpt2-merges.txt
222
+ ARX="${DATA_HOME}/ArXiv_ftfy_cleaned_id_shuf_text_document"
223
+ BC2="${DATA_HOME}/BookCorpus2_ftfy_cleaned_id_shuf_text_document"
224
+ B3="${DATA_HOME}/Books3_ftfy_cleaned_id_shuf_text_document"
225
+ CC2020="${DATA_HOME}/CC-2020-50_id_cleaned_shuf_text_document"
226
+ CC2021="${DATA_HOME}/CC-2021-04_id_cleaned_shuf_text_document"
227
+ GIT="${DATA_HOME}/Github_ftfy_id_shuf_text_document"
228
+ GUT="${DATA_HOME}/Gutenberg_PG-19_ftfy_cleaned_id_cleaned_shuf_text_document"
229
+ NIH="${DATA_HOME}/NIH_ExPorter_ftfy_id_shuf_text_document"
230
+ OWT2="${DATA_HOME}/OpenWebText2_ftfy_cleaned_id_shuf_text_document"
231
+ PCC="${DATA_HOME}/Pile-CC_id_cleaned_shuf_text_document"
232
+ PM="${DATA_HOME}/PubMed_Abstracts_ftfy_id_shuf_text_document"
233
+ RN="${DATA_HOME}/rn_dedup_shuf_cleaned_0.7_cleaned_shuf_text_document"
234
+ SE="${DATA_HOME}/StackExchange_ftfy_id_shuf_text_document"
235
+ ST="${DATA_HOME}/stories_dedup0.7_shuf_cleaned_shuf_text_document"
236
+ WIK="${DATA_HOME}/Wikipedia_en_ftfy_id_shuf_text_document"
237
+ DATA_BLEND="0.14336 ${B3} 0.08962 ${RN} 0.19336 ${OWT2} 0.05689 ${SE} \
238
+ 0.00859 ${ST} 0.02897 ${PM} 0.04771 ${WIK} 0.00873 ${GUT} 0.01007 ${BC2} \
239
+ 0.00208 ${NIH} 0.13017 ${CC2020} 0.09446 ${PCC} 0.15652 ${CC2021} \
240
+ 0.01359 ${ARX} 0.01588 ${GIT}"
241
+ else
242
+ VOCAB_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-vocab.json
243
+ MERGE_PATH=/data/the_pile_public_merged_nopreprocessing/gpt2-merges.txt
244
+ # Public the Pile dataset, can be downloaded at https://mystic.the-eye.eu/public/AI/pile_neox/
245
+ DATA_BLEND=/data/the_pile_public_merged_nopreprocessing/pile_text_document
246
+ fi
247
+ ###############################################################################
248
+ data_options=" \
249
+ --vocab-file ${VOCAB_PATH} \
250
+ --merge-file ${MERGE_PATH} \
251
+ --data-path ${DATA_BLEND} \
252
+ --data-impl mmap"
253
+
254
+ megatron_options=" \
255
+ --override-opt_param-scheduler \
256
+ --adam-beta1 0.9 \
257
+ --adam-beta2 0.95 \
258
+ --tensor-model-parallel-size ${MP_SIZE} \
259
+ --moe-expert-parallel-size ${EP_PARALLEL_SIZE} \
260
+ --num-experts ${EP_SIZE} \
261
+ --moe-loss-coeff ${MLC} \
262
+ --moe-train-capacity-factor ${MOE_TRAIN_CAP_FACTOR} \
263
+ --moe-eval-capacity-factor ${MOE_EVAL_CAP_FACTOR} \
264
+ --moe-min-capacity ${MOE_MIN_CAP} \
265
+ --init-method-std ${INIT_STD} \
266
+ --lr-decay-tokens ${LR_DECAY_TOKENS} \
267
+ --lr-warmup-tokens ${WARMUP_TOKENS} \
268
+ --micro-batch-size ${BATCH_SIZE} \
269
+ --exit-duration-in-mins ${EXIT_DURATION} \
270
+ --rampup-batch-size 32 32 4882812 \
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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/README.md ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Megatron-DeepSpeed Recipes and Scripts
2
+
3
+ This folder includes various example scripts with DeepSpeed technologies integrated. Below we describe each sub-folder, sorted by last update date.
4
+
5
+ ## Sync with NVIDIA/Megatron-LM (last updated: Jul 2023)
6
+ The ```rebase``` folder includes details about the recent sync with the NVIDIA/Megatron-LM repo (where this repo is forked from). It includes example scripts we used to test after the sync, together with a README documentation about what were tested.
7
+
8
+ ## Data Efficiency (last updated: Feb 2023)
9
+
10
+ The ```data_efficiency``` folder includes GPT-3 and BERT pretraining examples for DeepSpeed Data Efficiency Library, together with examples of zero-shot evaluation for GPT models and GLUE finetuning for BERT models. Please refer to the detailed tutorials in data_efficiency/README.MD. Currently this folder includes the newest example scripts for GPT/BERT pretraining/eval/finetuning, both with and without DeepSpeed Data Efficiency Library techniques.
11
+
12
+ ## BERT example (last updated: Dec 2022)
13
+
14
+ The ```bert_with_pile``` folder includes examples about BERT-style model pre-training (using the public Pile data or user's own data) with DeepSpeed integration. Please refer to the readme in the folder for tutorial.
15
+
16
+ ## Azure (last updated: Nov 2022)
17
+
18
+ We strongly recommend to start with AzureML recipe in the ```azureml``` folder.
19
+
20
+ If you have a custom infrastructure (e.g. HPC clusters) or Azure VM and VMSS based environments, please refer to the bash scripts in the ```azure``` folder.
21
+
22
+ ## Model Compression (last updated: Aug 2022)
23
+
24
+ The ```compression``` folder includes examples about layer reduction for task-agnostic compression. Please refer to [this tutorial](https://www.deepspeed.ai/tutorials/model-compression/#11-layer-reduction) about the DeepSpeed Model Compression Library. These recipes are for GPT-style NLG models.
25
+
26
+ ## MoE (last updated: Jun 2022)
27
+
28
+ Please see the ```MoE``` folder for different training recipes and scripts for Mixture-of-expert based models and dense models. These recipes are for GPT-style NLG models, and currently this is the only folder with MoE training examples.
29
+
30
+ ## Curriculum Learning (last updated: Oct 2021)
31
+
32
+ Curriculum learning recipes are in the ```curriculum_learning``` folder. Please refer to the detailed tutorials linked inside. These recipes are for GPT-style NLG models.
33
+ Note that the DeepSpeed Data Efficiency Library above includes a more general curriculum learning support. This legacy curriculum learning feature is still compatible, but we recommend using the DeepSpeed Data Efficiency Library above. However, the newer DeepSpeed Data Efficiency Library currently is not compatible with pipeline parallelism. So if you have to use pipeline parallelism, you would need to use this legacy curriculum learning version.
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/curriculum_learning/ds_pretrain_gpt2.sh ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash
2
+
3
+ CONFIG=$1
4
+ TAG=$2
5
+ MODEL_SIZE=$3
6
+ LR=$4
7
+ TOTAL_BATCHSIZE=$5
8
+ SEQ_LEN=$6
9
+ MP_SIZE=$7
10
+ SEED=$8
11
+ SAVE_INTERVAL=$9
12
+ NUM_ITER=${10}
13
+ NUM_TOKEN=${11}
14
+ LR_DECAY_TOKEN=${12}
15
+ LR_WARMUP_ITER=${13}
16
+ CONFIG_TEMPLATE=${14}
17
+ CURRICULUM_STEP=${15}
18
+ CURRICULUM_MIN=${16}
19
+
20
+ # 12-layer, 768-hidden, 12-heads, 117M parameters
21
+ # 24-layer, 1024-hidden, 16-heads, 345M parameters
22
+ # 36-layer, 1280-hidden, 20-heads, 774M parameters
23
+ # 48-layer, 1600-hidden, 25-heads, 1558M parameters
24
+ if [[ $MODEL_SIZE -eq 117 ]]; then
25
+ NUM_LAYERS=12
26
+ HIDDEN_SIZE=768
27
+ NUM_ATTN_HEADS=12
28
+ elif [[ $MODEL_SIZE -eq 345 ]]; then
29
+ NUM_LAYERS=24
30
+ HIDDEN_SIZE=1024
31
+ NUM_ATTN_HEADS=16
32
+ elif [[ $MODEL_SIZE -eq 774 ]]; then
33
+ NUM_LAYERS=36
34
+ HIDDEN_SIZE=1280
35
+ NUM_ATTN_HEADS=20
36
+ elif [[ $MODEL_SIZE -eq 1558 ]]; then
37
+ NUM_LAYERS=48
38
+ HIDDEN_SIZE=1600
39
+ NUM_ATTN_HEADS=25
40
+ else
41
+ echo "Model size not supported."
42
+ exit 1
43
+ fi
44
+
45
+ # Pipeline parallelism. 1 means no pipelines.
46
+ PP_SIZE=1
47
+
48
+ # Change for multinode config
49
+ NUM_WORKERS=16
50
+ NUM_GPUS_PER_WORKER=8
51
+ NUM_GPUS=$(( ${NUM_WORKERS} * ${NUM_GPUS_PER_WORKER} ))
52
+ if [[ $PP_SIZE -gt 0 ]]; then
53
+ DP_SIZE=$(( ${NUM_GPUS} / (${PP_SIZE} * ${MP_SIZE}) ))
54
+ else
55
+ DP_SIZE=$(( ${NUM_GPUS} / ${MP_SIZE} ))
56
+ fi
57
+ # Batch size per gpu, here we assume grad accumulation step 1
58
+ # you can reduce this if gpu OOM
59
+ BATCHSIZE=$((TOTAL_BATCHSIZE/DP_SIZE))
60
+
61
+ DATA_PATH=/vc_data/Megatron-LM/data/indexed_datasets/megatron
62
+ VOCAB_PATH=/vc_data/Megatron-LM/data/gpt2-vocab.json
63
+ MERGE_PATH=/vc_data/Megatron-LM/data/gpt2-merges.txt
64
+
65
+ #ZeRO Configs
66
+ stage=1
67
+
68
+ current_time=$(date "+%Y.%m.%d-%H.%M.%S")
69
+ script_path=$(realpath $0)
70
+ script_dir=$(dirname $script_path)
71
+ host="${HOSTNAME}"
72
+
73
+ if [ "${CONFIG_TEMPLATE}" = "true" ]; then
74
+ template_json="$script_dir/ds_zero_stage_${stage}_config_${CONFIG}.json"
75
+ config_json="$script_dir/ds_zero_stage_${stage}_config_${CONFIG}_min${CURRICULUM_MIN}_max${SEQ_LEN}_step${CURRICULUM_STEP}.json"
76
+ sed "s/CONFIG_CL_MIN/${CURRICULUM_MIN}/" ${template_json} \
77
+ | sed "s/CONFIG_CL_MAX/${SEQ_LEN}/" \
78
+ | sed "s/CONFIG_CL_DURATION/${CURRICULUM_STEP}/" \
79
+ > ${config_json}
80
+ else
81
+ config_json="$script_dir/ds_zero_stage_${stage}_config_${CONFIG}.json"
82
+ fi
83
+
84
+ JOB_NAME="gpt2_${MODEL_SIZE}M_bsz${TOTAL_BATCHSIZE}_seq${SEQ_LEN}_lr${LR}_warmup${LR_WARMUP_ITER}_decay${LR_DECAY_TOKEN}_seed${SEED}_${TAG}_stage${stage}_n${NUM_WORKERS}_g${NUM_GPUS_PER_WORKER}_mp${MP_SIZE}"
85
+ LOG_NAME="${JOB_NAME}_${host}_${current_time}"
86
+
87
+ OUTPUT_BASEPATH="/vc_data_blob/users/conglli"
88
+ mkdir -p "${OUTPUT_BASEPATH}/tensorboard/curriculum/"
89
+ mkdir -p "${OUTPUT_BASEPATH}/checkpoint/curriculum/"
90
+ mkdir -p "${OUTPUT_BASEPATH}/log/curriculum/"
91
+ LOGDIR="${OUTPUT_BASEPATH}/tensorboard/curriculum/${LOG_NAME}"
92
+ CHECKPOINT_PATH="${OUTPUT_BASEPATH}/checkpoint/curriculum/${JOB_NAME}"
93
+
94
+ gpt_options=" \
95
+ --tensor-model-parallel-size ${MP_SIZE} \
96
+ --num-layers $NUM_LAYERS \
97
+ --hidden-size $HIDDEN_SIZE \
98
+ --num-attention-heads $NUM_ATTN_HEADS \
99
+ --seq-length $SEQ_LEN \
100
+ --max-position-embeddings $SEQ_LEN \
101
+ --micro-batch-size $BATCHSIZE \
102
+ --global-batch-size ${TOTAL_BATCHSIZE} \
103
+ --train-iters $NUM_ITER \
104
+ --train-tokens $NUM_TOKEN \
105
+ --lr-decay-tokens $LR_DECAY_TOKEN \
106
+ --save $CHECKPOINT_PATH \
107
+ --load $CHECKPOINT_PATH \
108
+ --data-path $DATA_PATH \
109
+ --vocab-file $VOCAB_PATH \
110
+ --merge-file $MERGE_PATH \
111
+ --data-impl mmap \
112
+ --split 949,50,1 \
113
+ --distributed-backend nccl \
114
+ --override-opt_param-scheduler \
115
+ --lr $LR \
116
+ --lr-decay-style cosine \
117
+ --min-lr 1.0e-5 \
118
+ --weight-decay 1e-2 \
119
+ --clip-grad 1.0 \
120
+ --lr-warmup-iters $LR_WARMUP_ITER \
121
+ --checkpoint-activations \
122
+ --log-interval 100 \
123
+ --save-interval $SAVE_INTERVAL \
124
+ --eval-interval 100 \
125
+ --eval-iters 10 \
126
+ --fp16 \
127
+ --seed $SEED \
128
+ --tensorboard-queue-size 1 \
129
+ --log-timers-to-tensorboard \
130
+ --log-batch-size-to-tensorboard \
131
+ --log-validation-ppl-to-tensorboard \
132
+ --no-masked-softmax-fusion \
133
+ --tensorboard-dir ${LOGDIR}
134
+ "
135
+
136
+ deepspeed_options=" \
137
+ --deepspeed \
138
+ --deepspeed_config ${config_json} \
139
+ --zero-stage ${stage} \
140
+ --pipeline-model-parallel-size ${PP_SIZE} \
141
+ --deepspeed-activation-checkpointing
142
+ "
143
+
144
+ full_options="${gpt_options} ${deepspeed_options}"
145
+
146
+ run_cmd="deepspeed --num_nodes ${NUM_WORKERS} --num_gpus ${NUM_GPUS_PER_WORKER} ../../pretrain_gpt.py ${full_options} &>> ${OUTPUT_BASEPATH}/log/curriculum/${JOB_NAME}.log"
147
+ echo ${run_cmd}
148
+ eval ${run_cmd}
149
+
150
+ set +x
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/curriculum_learning/ds_pretrain_gpt_1.3B_rope_slw.sh ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ## init_std is standard deviation for weight initialization. Usually larger
13
+ ## model needs lower std. We used a heuristic equation of sqrt(1/3/hidden_size)
14
+ ## from the MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
15
+
16
+ ## We changed min_lr to a lower number (1.0e-6), which we found is able to
17
+ ## provide better zero-shot eval results.
18
+
19
+ ## GPT-3 Small 125M
20
+ # model_size=0.125
21
+ # num_layers=12
22
+ # hidden_size=768
23
+ # num_attn_heads=12
24
+ # global_batch_size=256
25
+ # lr=6.0e-4
26
+ # min_lr=1.0e-6
27
+ # init_std=0.02
28
+
29
+ ## GPT-3 Medium 350M
30
+ # model_size=0.35
31
+ # num_layers=24
32
+ # hidden_size=1024
33
+ # num_attn_heads=16
34
+ # global_batch_size=256
35
+ # lr=3.0e-4
36
+ # min_lr=1.0e-6
37
+ # init_std=0.018
38
+
39
+ ## GPT-3 Large 760M
40
+ # model_size=0.76
41
+ # num_layers=24
42
+ # hidden_size=1536
43
+ # num_attn_heads=16
44
+ # global_batch_size=256
45
+ # lr=2.5e-4
46
+ # min_lr=1.0e-6
47
+ # init_std=0.015
48
+
49
+ ## GPT-3 XL 1.3B
50
+ model_size=1.3
51
+ num_layers=24
52
+ hidden_size=2048
53
+ num_attn_heads=16
54
+ global_batch_size=512
55
+ lr=2.0e-4
56
+ min_lr=1.0e-6
57
+ init_std=0.013
58
+
59
+ ## GPT-3 2.7B
60
+ # model_size=2.7
61
+ # num_layers=32
62
+ # hidden_size=2560
63
+ # num_attn_heads=32
64
+ # global_batch_size=512
65
+ # lr=1.6e-4
66
+ # min_lr=1.0e-6
67
+ # init_std=0.011
68
+
69
+ ## GPT-3 6.7B
70
+ # model_size=6.7
71
+ # num_layers=32
72
+ # hidden_size=4096
73
+ # num_attn_heads=32
74
+ # global_batch_size=1024
75
+ # lr=1.2e-4
76
+ # min_lr=1.0e-6
77
+ # init_std=0.009
78
+
79
+ ## GPT-3 13B
80
+ # model_size=13
81
+ # num_layers=40
82
+ # hidden_size=5120
83
+ # num_attn_heads=40
84
+ # global_batch_size=1024
85
+ # lr=1.0e-4
86
+ # min_lr=1.0e-6
87
+ # init_std=0.008
88
+
89
+ ## GPT-3 175B
90
+ # model_size=175
91
+ # num_layers=96
92
+ # hidden_size=12288
93
+ # num_attn_heads=96
94
+ # global_batch_size=1536
95
+ # lr=0.6e-4
96
+ # min_lr=1.0e-6
97
+ # init_std=0.005
98
+ ###############################################################################
99
+ ### Training duration configs
100
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens.
101
+ train_tokens_in_billion=300
102
+ train_tokens=$((${train_tokens_in_billion} * 1000000000))
103
+
104
+ ## train_samples is another termination condition and also affect the number of
105
+ ## data samples to be indexed. Since we want to reach the train_tokens
106
+ ## above, and data efficiency techniques may change num tokens in some samples,
107
+ ## so we just set this config large enough to make sure we have enough
108
+ ## processed data and don't terminate by train_samples.
109
+ train_samples=$(( 300 * 1000000000 * 2 / ${seq_len} ))
110
+
111
+ ## Another wall-clock time termination condition in minutes. Set it large
112
+ ## enough to avoid undesired early termination.
113
+ exit_duration=30000000
114
+ ###############################################################################
115
+ ### lr configs
116
+ ## lr warmup and decay duration.
117
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B cosine decay tokens.
118
+ ## Here we increase the warmup tokens to 3B since when batch size warmup is not
119
+ ## used, there are more tokens per step. Thus we need to increase warmup tokens
120
+ ## to make sure there are enough warmup steps, which is important for training
121
+ ## stability.
122
+ lr_warmup_tokens_in_million=3000
123
+ lr_warmup_tokens=$((${lr_warmup_tokens_in_million} * 1000000))
124
+ ## Here we changed the LR decay tokens to align with total train tokens, since
125
+ ## related works (e.g., https://arxiv.org/abs/2203.15556) find that setting the
126
+ ## learning rate schedule to match the number of training tokens results in the
127
+ ## best final model quality
128
+ lr_decay_tokens_in_billion=${train_tokens_in_billion}
129
+ lr_decay_tokens=$((${lr_decay_tokens_in_billion} * 1000000000))
130
+ lr_decay_style="cosine"
131
+ ###############################################################################
132
+ ### Parallelism configs
133
+ ## Model parallelism, 1 is no MP
134
+ mp_size=4
135
+
136
+ ## Pipeline parallelism. To disable PP, set pp_size to 1 and no_pp to true.
137
+ ## Note that currently both curriculum learning and random-LTD are NOT
138
+ ## compatible with pipeline parallelism.
139
+ pp_size=8
140
+ no_pp="false"
141
+
142
+ ## ZeRO-based data parallelism, stage=0 will disable ZeRO
143
+ zero_stage=1
144
+
145
+ ## Total number of GPUs. ds_ssh is from DeepSpeed library.
146
+ num_gpus=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
147
+ num_gpus_pernode=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
148
+ num_node=$(( ${num_gpus} / ${num_gpus_pernode} ))
149
+
150
+ ## Data parallel size.
151
+ dp_size=$(( ${num_gpus} / ${pp_size} / ${mp_size} ))
152
+
153
+ ## Micro batch size per GPU
154
+ ## Make sure that batch_size <= global_batch_size*pp_size*mp_size/num_gpus
155
+ ## Reduce it manually if GPU OOM
156
+ # batch_size=$(( ${global_batch_size} / ${dp_size} ))
157
+ batch_size=2
158
+ ###############################################################################
159
+ ### curriculum learning (sequence length warmup) configs
160
+ # The "divided by 3" means we use 1/3 of baseline's total steps for sequence length warmup.
161
+ # This is not always the best config, but usually a reasonable choice to start with.
162
+ cl_step=$(( ${lr_warmup_tokens} / 3 / ${global_batch_size} / ${seq_len} ))
163
+ # Starting sequence length during sequence length warmup. If the train/validation loss is
164
+ # unstable at the beginning of training, need to increase this but also need to keep as multiples
165
+ # of 8 in order to enable Tensor Core acceleration.
166
+ cl_min=64
167
+ ###############################################################################
168
+ ### Misc configs
169
+ log_interval=10
170
+ eval_iters=10
171
+ eval_interval=100
172
+ # num_save controls how frequent to save checkpoint. num_save=20 means that a
173
+ # checkpoint will be saved every 5% of training. For longer training you would
174
+ # want larger num_save to save more frequently, and vice versa.
175
+ num_save=100
176
+ estimated_train_iter=$((${train_tokens} / ${seq_len} / ${global_batch_size}))
177
+ # save_interval=$((${estimated_train_iter} / ${num_save}))
178
+ save_interval=100
179
+
180
+ ## Activation checkpointing saves GPU memory, but reduces training speed
181
+ activation_checkpoint="true"
182
+ # activation_checkpoint="false"
183
+
184
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
185
+ ## This is not required for training and might save GPU memory when turned off.
186
+ log_optimizer_state="true"
187
+ ###############################################################################
188
+ ### Output and data configs
189
+ current_time=$(date "+%Y.%m.%d_%H.%M.%S")
190
+ host="${HOSTNAME}"
191
+ seed=1234
192
+ num_workers=0
193
+
194
+ ## Public the Pile dataset, can be downloaded at
195
+ ## https://mystic.the-eye.eu/public/AI/pile_neox/ or
196
+ ## https://the-eye.eu/public/AI/pile_neox/ Change data_home to where you
197
+ ## store the pile_text_document.bin and pile_text_document.idx.
198
+ data_home="/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing"
199
+ data_path="${data_home}/pile_text_document"
200
+
201
+ vocab_path="gpt2-vocab.json"
202
+ if [ ! -f "$vocab_path" ]; then
203
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json
204
+ fi
205
+ merge_path="gpt2-merges.txt"
206
+ if [ ! -f "$merge_path" ]; then
207
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt
208
+ fi
209
+
210
+ prescale_grad="true"
211
+ jobname="gpt_${model_size}B_tok${train_tokens_in_billion}B"
212
+ jobname="${jobname}_lr${lr}_min${min_lr}_w${lr_warmup_tokens_in_million}M_d${lr_decay_tokens_in_billion}B_${lr_decay_style}"
213
+ jobname="${jobname}_gbs${global_batch_size}_mbs${batch_size}_g${num_gpus}"
214
+ if [[ $zero_stage -gt 0 ]]; then
215
+ jobname="${jobname}_z${zero_stage}"
216
+ prescale_grad="false"
217
+ fi
218
+ if [[ $mp_size -gt 1 ]]; then
219
+ jobname="${jobname}_mp${mp_size}"
220
+ fi
221
+ if [ "${no_pp}" = "false" ]; then
222
+ jobname="${jobname}_pp${pp_size}"
223
+ fi
224
+ jobname="${jobname}_seed${seed}_rebase_rope0.25"
225
+ jobname="${jobname}_cl_step${cl_step}_cl_min${cl_min}"
226
+
227
+ username=$(whoami)
228
+ output_home="/blob/users/${username}/project/data_efficient_gpt"
229
+ log_path="${output_home}/log/"
230
+ checkpoint_path="${output_home}/checkpoint/${jobname}"
231
+ ## Microsoft internal constraint: because tensorboard is logged by last rank,
232
+ ## it's better to put the path in NFS instead of Blob.
233
+ tensorboard_dir="/vc_data/users/${username}/project/data_efficient_gpt/tensorboard/"
234
+ tensorboard_path="${tensorboard_dir}${jobname}_${host}_${current_time}"
235
+ mkdir -p ${log_path}
236
+ mkdir -p ${checkpoint_path}
237
+ mkdir -p ${tensorboard_path}
238
+ ###############################################################################
239
+ data_options=" \
240
+ --vocab-file ${vocab_path} \
241
+ --merge-file ${merge_path} \
242
+ --data-path ${data_path} \
243
+ --data-impl mmap"
244
+
245
+ ## If CL is used, make sure to set "--split" the same as what you used during
246
+ ## offline data analysis&indexing.
247
+ megatron_options=" \
248
+ --override-opt_param-scheduler \
249
+ --adam-beta1 0.9 \
250
+ --adam-beta2 0.95 \
251
+ --tensor-model-parallel-size ${mp_size} \
252
+ --init-method-std ${init_std} \
253
+ --lr-decay-tokens ${lr_decay_tokens} \
254
+ --lr-warmup-tokens ${lr_warmup_tokens} \
255
+ --micro-batch-size ${batch_size} \
256
+ --exit-duration-in-mins ${exit_duration} \
257
+ --global-batch-size ${global_batch_size} \
258
+ --num-layers ${num_layers} \
259
+ --hidden-size ${hidden_size} \
260
+ --num-attention-heads ${num_attn_heads} \
261
+ --seq-length ${seq_len} \
262
+ --max-position-embeddings ${seq_len} \
263
+ --train-tokens ${train_tokens} \
264
+ --train-samples ${train_samples} \
265
+ --lr ${lr} \
266
+ --min-lr ${min_lr} \
267
+ --lr-decay-style ${lr_decay_style} \
268
+ --split 949,50,1 \
269
+ --log-interval ${log_interval} \
270
+ --eval-interval ${eval_interval} \
271
+ --eval-iters ${eval_iters} \
272
+ --save-interval ${save_interval} \
273
+ --weight-decay 0.1 \
274
+ --clip-grad 1.0 \
275
+ --hysteresis 2 \
276
+ --num-workers ${num_workers} \
277
+ --fp16 \
278
+ --seed ${seed} \
279
+ --load ${checkpoint_path} \
280
+ --save ${checkpoint_path} \
281
+ --no-async-tensor-model-parallel-allreduce \
282
+ --use-rotary-position-embeddings \
283
+ --rotary-percent 0.25 \
284
+ --tensorboard-queue-size 1 \
285
+ --log-timers-to-tensorboard \
286
+ --log-batch-size-to-tensorboard \
287
+ --log-validation-ppl-to-tensorboard \
288
+ --tensorboard-dir ${tensorboard_path}"
289
+
290
+ if [ "${activation_checkpoint}" = "true" ]; then
291
+ megatron_options="${megatron_options} \
292
+ --checkpoint-activations"
293
+ fi
294
+
295
+ if [ "${log_optimizer_state}" = "true" ]; then
296
+ megatron_options="${megatron_options} \
297
+ --log-optimizer-states-to-tensorboard"
298
+ fi
299
+
300
+ config_json="ds_config_gbs${global_batch_size}_mbs${batch_size}_log${log_interval}_zero${zero_stage}_cl_step${cl_step}_cl_min${cl_min}.json"
301
+ template_json="ds_config_gpt_slw_TEMPLATE.json"
302
+ sed "s/GBSIZE/${global_batch_size}/" ${template_json} \
303
+ | sed "s/MBSIZE/${batch_size}/" \
304
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
305
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
306
+ | sed "s/PRESCALE_GRAD/${prescale_grad}/" \
307
+ | sed "s/CONFIG_CL_MIN/${cl_min}/" \
308
+ | sed "s/CONFIG_CL_MAX/${seq_len}/" \
309
+ | sed "s/CONFIG_CL_DURATION/${cl_step}/" \
310
+ > ${config_json}
311
+
312
+ deepspeed_options=" \
313
+ --deepspeed \
314
+ --deepspeed_config ${config_json} \
315
+ --zero-stage ${zero_stage} \
316
+ --pipeline-model-parallel-size ${pp_size}"
317
+
318
+ if [[ "${no_pp}" = "true" ]]; then
319
+ deepspeed_options="${deepspeed_options} \
320
+ --no-pipeline-parallel"
321
+ fi
322
+
323
+ if [ "${activation_checkpoint}" = "true" ]; then
324
+ deepspeed_options="${deepspeed_options} \
325
+ --deepspeed-activation-checkpointing"
326
+ fi
327
+
328
+ ## When saving checkpoint to a storage with cache, their could be consistency
329
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
330
+ ## and broadcast it to all nodes.
331
+ iteration_file="$checkpoint_path/latest_checkpointed_iteration.txt"
332
+ iteration_file_2="$checkpoint_path/latest"
333
+ iteration=0
334
+ for (( node = 0; node <= num_node-1; node++ ))
335
+ do
336
+ if $(ssh -q worker-"$node" "test -f \"$iteration_file\""); then
337
+ local_iteration=$(ssh -q worker-"$node" cat $iteration_file)
338
+ iteration=$(( ${local_iteration} > ${iteration} ? ${local_iteration} : ${iteration} ))
339
+ fi
340
+ done
341
+ if [[ $iteration -gt 0 ]]; then
342
+ iteration_2="global_step${iteration}"
343
+ ds_ssh "echo $iteration > $iteration_file"
344
+ ds_ssh "echo $iteration_2 > $iteration_file_2"
345
+ fi
346
+
347
+ deepspeed ${dir}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &>> ${log_path}/${jobname}_${host}_${current_time}.log
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/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/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/analyze_data.py ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ '''
17
+ Copyright 2022 The Microsoft DeepSpeed Team
18
+ '''
19
+
20
+ import os
21
+ import time
22
+ import sys
23
+ import math
24
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),
25
+ os.path.pardir,os.path.pardir)))
26
+ from datetime import datetime
27
+ import numpy as np
28
+ import torch
29
+
30
+ from deepspeed.runtime.data_pipeline.data_sampling.data_analyzer \
31
+ import DataAnalyzer
32
+ from deepspeed.runtime.data_pipeline.data_sampling.indexed_dataset \
33
+ import MMapIndexedDataset
34
+
35
+ from megatron import get_args
36
+ from megatron import print_rank_0
37
+ from megatron.initialize import initialize_megatron
38
+
39
+ def get_tasks_args(parser):
40
+ """Provide extra arguments required for data analyzing."""
41
+ group = parser.add_argument_group(title='data_analyzing')
42
+
43
+ group.add_argument('--analyzing-task', type=str, required=True,
44
+ default=None,
45
+ choices=['map',
46
+ 'reduce'],
47
+ help='What type of analyzing task to perform.')
48
+ group.add_argument('--analyzing-data-type', type=str, required=True,
49
+ default=None,
50
+ choices=['BERT',
51
+ 'GPT'],
52
+ help='What type of data.')
53
+ group.add_argument('--analyzing-metric', type=str, nargs='+', default=[],
54
+ help='What kinds of metrics to analyze.')
55
+ group.add_argument('--analyzing-num-workers', type=int, default=1,
56
+ help='Number of workers. Each worker could be a single CPU node.')
57
+ group.add_argument('--analyzing-worker-id', type=int, default=0,
58
+ help='Worker id of current node.')
59
+ group.add_argument('--analyzing-num-threads', type=int, default=1,
60
+ help='Number of threads for each worker.')
61
+ group.add_argument('--analyzing-num-threads-reduce', type=int, default=1,
62
+ help='Number of threads for each worker.')
63
+ group.add_argument('--analyzing-specific-threads', type=int, nargs='+', default=[],
64
+ help='Which specific threads to run. Helpful when there are specific thread failed in previous run.')
65
+ return parser
66
+
67
+ def train_valid_test_datasets_provider_gpt():
68
+ """Build train, valid, and test datasets."""
69
+ args = get_args()
70
+
71
+ print_rank_0('> building train, validation, and test datasets '
72
+ 'for GPT ...')
73
+ from megatron.data.gpt_dataset import build_train_valid_test_datasets
74
+ train_ds, valid_ds, test_ds = build_train_valid_test_datasets(
75
+ data_prefix=args.data_path,
76
+ data_impl=args.data_impl,
77
+ splits_string=args.split,
78
+ train_valid_test_num_samples=[1,1,1], # Just dummy numbers since we assume args.train_data_exact_num_epochs will override them
79
+ seq_length=args.seq_length,
80
+ seed=args.seed,
81
+ skip_warmup=(not args.mmap_warmup))
82
+ print_rank_0("> finished creating GPT datasets ...")
83
+
84
+ return train_ds, valid_ds, test_ds
85
+
86
+ def train_valid_test_datasets_provider_bert():
87
+ """Build train, valid, and test datasets."""
88
+ args = get_args()
89
+
90
+ print_rank_0('> building train, validation, and test datasets '
91
+ 'for BERT ...')
92
+ from megatron.data.dataset_utils import build_train_valid_test_datasets
93
+ train_ds, valid_ds, test_ds = build_train_valid_test_datasets(
94
+ data_prefix=args.data_path,
95
+ data_impl=args.data_impl,
96
+ splits_string=args.split,
97
+ train_valid_test_num_samples=[1,1,1], # Just dummy numbers since we assume args.train_data_exact_num_epochs will override them
98
+ max_seq_length=args.seq_length,
99
+ masked_lm_prob=args.mask_prob,
100
+ short_seq_prob=args.short_seq_prob,
101
+ seed=args.seed,
102
+ skip_warmup=(not args.mmap_warmup),
103
+ binary_head=args.bert_binary_head)
104
+ print_rank_0("> finished creating BERT datasets ...")
105
+
106
+ return train_ds, valid_ds, test_ds
107
+
108
+ def metric_seqlen(data):
109
+ metric = torch.count_nonzero(data['padding_mask'], dim=1)
110
+ return metric
111
+
112
+ def metric_total_vocab_freq(data):
113
+ args = get_args()
114
+ if args.analyzing_data_type == 'BERT':
115
+ frequency = torch.bincount(data['text'].view(-1),
116
+ minlength=args.padded_vocab_size+1,
117
+ weights=data['padding_mask'].view(-1))
118
+ elif args.analyzing_data_type == 'GPT':
119
+ frequency = torch.bincount(data['text'].view(-1),
120
+ minlength=args.padded_vocab_size+1)
121
+ return frequency
122
+
123
+ def metric_vocab_rarity(data):
124
+ args = get_args()
125
+ if args.analyzing_data_type == 'BERT':
126
+ rarity = torch.sum(data['padding_mask'] * \
127
+ args.total_vocab_freq[data['text']], dim=1).to(torch.long)
128
+ elif args.analyzing_data_type == 'GPT':
129
+ rarity = []
130
+ # Do one by one to avoid too high memory consumption
131
+ for row in range(data['text'].size()[0]):
132
+ rarity.append(int(torch.sum(args.total_vocab_freq[data['text'][row]]).item()))
133
+ rarity = torch.tensor(rarity, dtype=torch.long)
134
+ print(f"rarity min {min(rarity)}, max {max(rarity)}, len {len(rarity)}, avg {sum(rarity)/len(rarity)}")
135
+ return rarity
136
+
137
+ def metric_seqlen_vocab_rarity(data):
138
+ args = get_args()
139
+ metric = torch.count_nonzero(data['padding_mask'], dim=1).to(torch.long) * args.seqlen_coeff
140
+ metric += torch.sum(data['padding_mask'] * \
141
+ args.total_vocab_freq[data['text']], dim=1).to(torch.long)
142
+ print(f"metric min {min(metric)}, max {max(metric)}, len {len(metric)}, avg {sum(metric)/len(metric)}")
143
+ return metric
144
+
145
+ def get_metric_function(metric_name):
146
+ if metric_name == 'seqlen':
147
+ return metric_seqlen
148
+ if metric_name == 'total_vocab_freq':
149
+ return metric_total_vocab_freq
150
+ if metric_name == 'vocab_rarity':
151
+ return metric_vocab_rarity
152
+ if metric_name == 'seqlen_vocab_rarity':
153
+ return metric_seqlen_vocab_rarity
154
+
155
+ def get_metric_type(metric_name):
156
+ if metric_name == 'seqlen':
157
+ return 'single_value_per_sample'
158
+ if metric_name == 'total_vocab_freq':
159
+ return 'accumulate_value_over_samples'
160
+ if metric_name == 'vocab_rarity':
161
+ return 'single_value_per_sample'
162
+ if metric_name == 'seqlen_vocab_rarity':
163
+ return 'single_value_per_sample'
164
+
165
+ def run_map():
166
+ args = get_args()
167
+ if args.analyzing_data_type == 'BERT':
168
+ args.mask_prob = 0 # When analyzing data, we don't want any mask.
169
+ train_ds, _, _ = train_valid_test_datasets_provider_bert()
170
+ elif args.analyzing_data_type == 'GPT':
171
+ train_ds, _, _ = train_valid_test_datasets_provider_gpt()
172
+ assert 'seqlen' not in args.analyzing_metric, 'GPT data has fixed seqlen, thus unnecessary to analyze seqlen metric.'
173
+ assert 'seqlen_vocab_rarity' not in args.analyzing_metric, 'GPT data has fixed seqlen, thus unnecessary to analyze seqlen metric.'
174
+ if 'vocab_rarity' in args.analyzing_metric or 'seqlen_vocab_rarity' in args.analyzing_metric:
175
+ total_vocab_freq_fname = f"{args.save}/total_vocab_freq/total_vocab_freq_metric_value"
176
+ assert os.path.isfile(f"{total_vocab_freq_fname}.bin") and os.path.isfile(f"{total_vocab_freq_fname}.idx"), "To analyze vocab rarity, first need to analyze the total vocab freq."
177
+ total_vocab_freq = MMapIndexedDataset(total_vocab_freq_fname, skip_warmup=True)
178
+ total_vocab_freq = np.copy(total_vocab_freq[0])
179
+ total_vocab_freq[total_vocab_freq == 0] = 1 # Avoid log(0) error
180
+ total_vocab_freq = np.log(total_vocab_freq/sum(total_vocab_freq)) * -1
181
+ args.total_vocab_freq = torch.tensor(total_vocab_freq, dtype=torch.double)
182
+ if 'seqlen_vocab_rarity' in args.analyzing_metric:
183
+ # Use large coeff to make seqlen dominates vocab_rarity
184
+ max_possible_rarity = args.seq_length * torch.max(args.total_vocab_freq).item()
185
+ args.seqlen_coeff = 10 ** (math.ceil(math.log(max_possible_rarity, 10)) + 1)
186
+ print(f"Metric seqlen_vocab_rarity: using {args.seqlen_coeff} as coefficient for seqlen.")
187
+ metric_functions = [get_metric_function(x) for x in args.analyzing_metric]
188
+ metric_types = [get_metric_type(x) for x in args.analyzing_metric]
189
+ # For metric_dtypes we int64 by default since it could be hard to estimate
190
+ # the appropriate dtype before the mapping analysis. During reduce where
191
+ # we merge the analysis results, the DataAnalyzer will automatically choose
192
+ # the dtype of merged result file as the smallest one that meet the range
193
+ # requirement.
194
+ metric_dtypes = [np.int64 for x in args.analyzing_metric]
195
+ start = time.time()
196
+ data_analyzer = DataAnalyzer(train_ds,
197
+ num_workers=args.analyzing_num_workers,
198
+ worker_id=args.analyzing_worker_id,
199
+ num_threads=args.analyzing_num_threads,
200
+ specific_threads=args.analyzing_specific_threads,
201
+ batch_size=args.global_batch_size, metric_names=args.analyzing_metric,
202
+ metric_functions=metric_functions, metric_types=metric_types,
203
+ metric_dtypes=metric_dtypes, save_path=args.save)
204
+ data_analyzer.run_map()
205
+ duration = (time.time() - start) / 3600.0
206
+ print(f"map job finished in {duration} hr.")
207
+
208
+ def run_reduce():
209
+ args = get_args()
210
+ if args.analyzing_data_type == 'BERT':
211
+ args.mask_prob = 0 # When analyzing data, we don't want any mask.
212
+ train_ds, _, _ = train_valid_test_datasets_provider_bert()
213
+ elif args.analyzing_data_type == 'GPT':
214
+ train_ds, _, _ = train_valid_test_datasets_provider_gpt()
215
+ metric_functions = [get_metric_function(x) for x in args.analyzing_metric]
216
+ metric_types = [get_metric_type(x) for x in args.analyzing_metric]
217
+ metric_dtypes = [np.int64 for x in args.analyzing_metric]
218
+ start = time.time()
219
+ data_analyzer = DataAnalyzer(train_ds,
220
+ num_workers=args.analyzing_num_workers,
221
+ num_threads=args.analyzing_num_threads,
222
+ num_threads_reduce=args.analyzing_num_threads_reduce,
223
+ batch_size=args.global_batch_size, metric_names=args.analyzing_metric,
224
+ metric_functions=metric_functions, metric_types=metric_types,
225
+ metric_dtypes=metric_dtypes, save_path=args.save)
226
+ data_analyzer.run_reduce()
227
+ duration = (time.time() - start) / 3600.0
228
+ print(f"reduce job finished in {duration} hr.")
229
+
230
+ if __name__ == "__main__":
231
+ initialize_megatron(extra_args_provider=get_tasks_args, allow_no_cuda=True)
232
+ args = get_args()
233
+ if args.analyzing_task == 'map':
234
+ run_map()
235
+ elif args.analyzing_task == 'reduce':
236
+ run_reduce()
237
+ else:
238
+ raise NotImplementedError('Task {} is not implemented.'.format(
239
+ args.analyzing_task))
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/ds_analyze_bert_data_map.sh ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ num_workers=1 # Num nodes to run the map job
4
+ num_threads=40 # Num threads on each node. Set this based on #CPU cores
5
+
6
+ # If different data epochs have slightly different data samples (e.g., due
7
+ # to randomness), then you need to specify large enough num_epochs that cover
8
+ # whole pretraining. If different data epochs are the same, set num_epochs to
9
+ # 1 to only index 1 epoch, and during pretraining DeepSpeed data efficiency
10
+ # library will automatically handle reshuffling when reaching another epoch.
11
+ num_epochs=5
12
+
13
+ # Which node is this node (start with 0 and end with num_workers-1). This
14
+ # script only launch the map job on 1 worker node, since we don't expect
15
+ # running on many nodes and workers don't need any communication. But you
16
+ # can modify this script to add a MPI/torch distributed launcher.
17
+ worker_id=$1
18
+ save_path="/blob/users/conglli/data/analysis_pile_bert_${num_epochs}epoch/"
19
+
20
+ metric='total_vocab_freq'
21
+ # metric='vocab_rarity' # this requires the result of total_vocab_freq
22
+ # metric='seqlen_vocab_rarity' # this requires the result of total_vocab_freq
23
+ # metric='seqlen'
24
+
25
+ seq_len=512
26
+ batch_size=10000
27
+
28
+ jobname="bert-pile-analyzing-${metric}-${num_epochs}epoch-map-worker${worker_id}"
29
+ ## Public the Pile dataset, see prepare_pile_data.py in the same directory
30
+ ## about how to download and preprocess the data.
31
+ ## Change data_home to your own training data path.
32
+ # data_home="/vc_data_blob/users/conglli/the_pile_bert"
33
+ data_home="/blob/data/the_pile_bert"
34
+ data_path="${data_home}/pile_bert_train_text_sentence"
35
+
36
+ vocab_path="bert-large-uncased-vocab.txt"
37
+ if [ ! -f "$vocab_path" ]; then
38
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-uncased-vocab.txt
39
+ fi
40
+
41
+ # Make sure the "--split" is the same as what you will use for pre-training.
42
+ options=" \
43
+ --analyzing-task map \
44
+ --analyzing-data-type BERT \
45
+ --analyzing-metric ${metric} \
46
+ --analyzing-num-workers ${num_workers} \
47
+ --analyzing-worker-id ${worker_id} \
48
+ --analyzing-num-threads ${num_threads} \
49
+ --vocab-file ${vocab_path} \
50
+ --data-path ${data_path} \
51
+ --data-impl mmap \
52
+ --tokenizer-type BertWordPieceLowerCase \
53
+ --micro-batch-size ${batch_size} \
54
+ --global-batch-size ${batch_size} \
55
+ --seq-length ${seq_len} \
56
+ --max-position-embeddings ${seq_len} \
57
+ --num-layers 1 \
58
+ --hidden-size 1 \
59
+ --num-attention-heads 1 \
60
+ --split 949,50,1 \
61
+ --distributed-backend gloo \
62
+ --train-data-exact-num-epochs ${num_epochs} \
63
+ --return-data-index \
64
+ --save-interval 1 \
65
+ --save ${save_path}"
66
+
67
+ python ../analyze_data.py ${options} &> ${jobname}.log
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/ds_analyze_bert_data_reduce.sh ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Set these 2 to the same as what you used during map job. We need these 2
4
+ # configs to know how many map job result files do we have.
5
+ num_workers=1
6
+ num_threads=40
7
+ # Reduce job only has 1 worker but can accelerate by multithreading.
8
+ num_threads_reduce=40
9
+
10
+ # If different data epochs have slightly different data samples (e.g., due
11
+ # to randomness), then you need to specify large enough num_epochs that cover
12
+ # whole pretraining. If different data epochs are the same, set num_epochs to
13
+ # 1 to only index 1 epoch, and during pretraining DeepSpeed data efficiency
14
+ # library will automatically handle reshuffling when reaching another epoch.
15
+ num_epochs=5
16
+
17
+ save_path="/blob/users/conglli/data/analysis_pile_bert_${num_epochs}epoch/"
18
+
19
+ metric='total_vocab_freq'
20
+ # metric='vocab_rarity' # this requires the result of total_vocab_freq
21
+ # metric='seqlen_vocab_rarity' # this requires the result of total_vocab_freq
22
+ # metric='seqlen'
23
+
24
+ seq_len=512
25
+ batch_size=10000
26
+
27
+ jobname="bert-pile-analyzing-${metric}-${num_epochs}epoch-reduce"
28
+ ## Public the Pile dataset, see prepare_pile_data.py in the same directory
29
+ ## about how to download and preprocess the data.
30
+ ## Change data_home to your own training data path.
31
+ # data_home="/vc_data_blob/users/conglli/the_pile_bert"
32
+ data_home="/blob/data/the_pile_bert"
33
+ data_path="${data_home}/pile_bert_train_text_sentence"
34
+
35
+ vocab_path="bert-large-uncased-vocab.txt"
36
+ if [ ! -f "$vocab_path" ]; then
37
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-uncased-vocab.txt
38
+ fi
39
+
40
+ # Make sure the "--split" is the same as what you will use for pre-training.
41
+ options=" \
42
+ --analyzing-task reduce \
43
+ --analyzing-data-type BERT \
44
+ --analyzing-metric ${metric} \
45
+ --analyzing-num-workers ${num_workers} \
46
+ --analyzing-num-threads ${num_threads} \
47
+ --analyzing-num-threads-reduce ${num_threads_reduce} \
48
+ --vocab-file ${vocab_path} \
49
+ --data-path ${data_path} \
50
+ --data-impl mmap \
51
+ --tokenizer-type BertWordPieceLowerCase \
52
+ --micro-batch-size ${batch_size} \
53
+ --global-batch-size ${batch_size} \
54
+ --seq-length ${seq_len} \
55
+ --max-position-embeddings ${seq_len} \
56
+ --num-layers 1 \
57
+ --hidden-size 1 \
58
+ --num-attention-heads 1 \
59
+ --split 949,50,1 \
60
+ --distributed-backend gloo \
61
+ --train-data-exact-num-epochs ${num_epochs} \
62
+ --return-data-index \
63
+ --save-interval 1 \
64
+ --save ${save_path}"
65
+
66
+ python ../analyze_data.py ${options} &> ${jobname}.log
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/finetune/ds_finetune_bert_mnli.sh ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ seed=1234
2
+ pretrained_checkpoint="/blob/users/conglli/project/bert_with_pile/checkpoint/bert-pile-0.336B-iters-2M-lr-1e-4-min-1e-5-wmup-10000-dcy-2M-sty-linear-gbs-1024-mbs-16-gpu-64-zero-0-mp-1-pp-1-nopp"
3
+
4
+ ###############################################################################
5
+ ### Main configs
6
+ ### The main configs are from Megatron-LM paper
7
+ ### https://arxiv.org/abs/1909.08053. Choose based on your desired model size
8
+ ### or build your own configs.
9
+ seq_len=512
10
+
11
+ ## From Table 6 in https://arxiv.org/abs/1909.08053.
12
+ task="MNLI"
13
+ global_batch_size=128
14
+ lr=1e-5
15
+ epochs=10
16
+
17
+ train_data="/blob/data/GlueData/MNLI/train.tsv"
18
+ valid_data="/blob/data/GlueData/MNLI/dev_matched.tsv \
19
+ /blob/data/GlueData/MNLI/dev_mismatched.tsv"
20
+
21
+ ## Adjust based on number of GPUs.
22
+ batch_size=16
23
+
24
+ ## BERT 110M (same config as original BERT-Base model)
25
+ ## This config is not included in Megatron-LM paper
26
+ # model_size=0.11
27
+ # num_layers=12
28
+ # hidden_size=768
29
+ # num_attn_heads=12
30
+
31
+ ## BERT 336M (same config as original BERT-Large model)
32
+ model_size=0.336
33
+ num_layers=24
34
+ hidden_size=1024
35
+ num_attn_heads=16
36
+
37
+ ## BERT 1.3B
38
+ # model_size=1.3
39
+ # num_layers=24
40
+ # hidden_size=2048
41
+ # num_attn_heads=32
42
+
43
+ ## BERT 3.9B
44
+ # model_size=3.9
45
+ # num_layers=48
46
+ # hidden_size=2560
47
+ # num_attn_heads=40
48
+ ###############################################################################
49
+ ### Parallelism configs
50
+ ## Model parallelism, 1 is no MP
51
+ mp_size=1
52
+
53
+ ## Pipeline parallelism. To disable PP, set pp_size to 1 and no_pp to true.
54
+ ## Currently pipeline parallelism is not supported for BERT model: DeepSpeed's
55
+ ## pipeline parallelism is only integrated with the GPT case, and currently
56
+ ## DeepSpeed is not integrated with Megatron's own pipeline parallelism.
57
+ pp_size=1
58
+ no_pp="true"
59
+
60
+ ## ZeRO stage
61
+ zero_stage=0
62
+ ###############################################################################
63
+ ### Misc configs
64
+ log_interval=10
65
+ eval_iters=50
66
+ eval_interval=100
67
+ save_interval=500000
68
+
69
+ ## Activation checkpointing saves GPU memory, but reduces training speed
70
+ # activation_checkpoint="true"
71
+ activation_checkpoint="false"
72
+ ###############################################################################
73
+ vocab_file="bert-large-uncased-vocab.txt"
74
+ if [ ! -f "$vocab_file" ]; then
75
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-uncased-vocab.txt
76
+ fi
77
+
78
+ jobname="${task}-bsz${global_batch_size}-lr${lr}-epochs${epochs}-seed${seed}"
79
+ checkpoint_path="${pretrained_checkpoint}-finetune/${jobname}"
80
+ mkdir -p ${checkpoint_path}
81
+
82
+ template_json="ds_config_bert_TEMPLATE.json"
83
+ config_json="ds_config_bert_bsz${global_batch_size}_mbsz${batch_size}_log${log_interval}_zero${zero_stage}.json"
84
+ if [[ $zero_stage -gt 0 ]]; then
85
+ sed "s/CONFIG_BATCH_SIZE/${global_batch_size}/" ${template_json} \
86
+ | sed "s/CONFIG_MBSIZE/${batch_size}/" \
87
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
88
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
89
+ | sed "s/PRESCALE_GRAD/false/" \
90
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
91
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
92
+ > ${config_json}
93
+ else
94
+ sed "s/CONFIG_BATCH_SIZE/${global_batch_size}/" ${template_json} \
95
+ | sed "s/CONFIG_MBSIZE/${batch_size}/" \
96
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
97
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
98
+ | sed "s/PRESCALE_GRAD/true/" \
99
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
100
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
101
+ > ${config_json}
102
+ fi
103
+
104
+ options=" \
105
+ --finetune \
106
+ --deepspeed \
107
+ --deepspeed_config ${config_json} \
108
+ --zero-stage ${zero_stage} \
109
+ --task ${task} \
110
+ --seed ${seed} \
111
+ --train-data ${train_data} \
112
+ --valid-data ${valid_data} \
113
+ --tokenizer-type BertWordPieceLowerCase \
114
+ --vocab-file ${vocab_file} \
115
+ --epochs ${epochs} \
116
+ --pretrained-checkpoint ${pretrained_checkpoint} \
117
+ --tensor-model-parallel-size ${mp_size} \
118
+ --pipeline-model-parallel-size ${pp_size} \
119
+ --num-layers ${num_layers} \
120
+ --hidden-size ${hidden_size} \
121
+ --num-attention-heads ${num_attn_heads} \
122
+ --global-batch-size ${global_batch_size} \
123
+ --micro-batch-size ${batch_size} \
124
+ --lr ${lr} \
125
+ --lr-decay-style linear \
126
+ --lr-warmup-fraction 0.065 \
127
+ --seq-length ${seq_len} \
128
+ --max-position-embeddings ${seq_len} \
129
+ --save-interval ${save_interval} \
130
+ --save ${checkpoint_path} \
131
+ --log-interval ${log_interval} \
132
+ --eval-interval ${eval_interval} \
133
+ --eval-iters ${eval_iters} \
134
+ --weight-decay 1.0e-1 \
135
+ --fp16"
136
+
137
+ if [ "${activation_checkpoint}" = "true" ]; then
138
+ options="${options} \
139
+ --checkpoint-activations \
140
+ --deepspeed-activation-checkpointing"
141
+ fi
142
+
143
+ if [[ "${no_pp}" = "true" ]]; then
144
+ options="${options} \
145
+ --no-pipeline-parallel"
146
+ fi
147
+
148
+ # After the fine-tuning finishes, you can find the dev set accuracy numbers by
149
+ # "grep -e "overall:" -e "metrics for" ${checkpoint_path}/output.log"
150
+ deepspeed ../../../../tasks/main.py ${options} &> ${checkpoint_path}/output.log
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/finetune/ds_finetune_bert_qqp.sh ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ seed=1234
2
+ pretrained_checkpoint="/blob/users/conglli/project/bert_with_pile/checkpoint/bert-pile-0.336B-iters-2M-lr-1e-4-min-1e-5-wmup-10000-dcy-2M-sty-linear-gbs-1024-mbs-16-gpu-64-zero-0-mp-1-pp-1-nopp"
3
+
4
+ ###############################################################################
5
+ ### Main configs
6
+ ### The main configs are from Megatron-LM paper
7
+ ### https://arxiv.org/abs/1909.08053. Choose based on your desired model size
8
+ ### or build your own configs.
9
+ seq_len=512
10
+
11
+ ## From Table 6 in https://arxiv.org/abs/1909.08053.
12
+ task="QQP"
13
+
14
+ train_data="/blob/data/GlueData/QQP/train.tsv"
15
+ valid_data="/blob/data/GlueData/QQP/dev.tsv"
16
+
17
+ ## Adjust based on number of GPUs.
18
+ batch_size=16
19
+
20
+ ## BERT 110M (same config as original BERT-Base model)
21
+ ## This config is not included in Megatron-LM paper
22
+ # model_size=0.11
23
+ # num_layers=12
24
+ # hidden_size=768
25
+ # num_attn_heads=12
26
+ # global_batch_size=128
27
+ # lr=5e-5
28
+ # epochs=12
29
+
30
+ ## BERT 336M (same config as original BERT-Large model)
31
+ model_size=0.336
32
+ num_layers=24
33
+ hidden_size=1024
34
+ num_attn_heads=16
35
+ global_batch_size=128
36
+ lr=5e-5
37
+ epochs=12
38
+
39
+ ## BERT 1.3B
40
+ # model_size=1.3
41
+ # num_layers=24
42
+ # hidden_size=2048
43
+ # num_attn_heads=32
44
+ # global_batch_size=128
45
+ # lr=3e-5
46
+ # epochs=12
47
+
48
+ ## BERT 3.9B
49
+ # model_size=3.9
50
+ # num_layers=48
51
+ # hidden_size=2560
52
+ # num_attn_heads=40
53
+ # global_batch_size=256
54
+ # lr=4e-5
55
+ # epochs=12
56
+ ###############################################################################
57
+ ### Parallelism configs
58
+ ## Model parallelism, 1 is no MP
59
+ mp_size=1
60
+
61
+ ## Pipeline parallelism. To disable PP, set pp_size to 1 and no_pp to true.
62
+ ## Currently pipeline parallelism is not supported for BERT model: DeepSpeed's
63
+ ## pipeline parallelism is only integrated with the GPT case, and currently
64
+ ## DeepSpeed is not integrated with Megatron's own pipeline parallelism.
65
+ pp_size=1
66
+ no_pp="true"
67
+
68
+ ## ZeRO stage
69
+ zero_stage=0
70
+ ###############################################################################
71
+ ### Misc configs
72
+ log_interval=10
73
+ eval_iters=50
74
+ eval_interval=100
75
+ save_interval=500000
76
+
77
+ ## Activation checkpointing saves GPU memory, but reduces training speed
78
+ # activation_checkpoint="true"
79
+ activation_checkpoint="false"
80
+ ###############################################################################
81
+ vocab_file="bert-large-uncased-vocab.txt"
82
+ if [ ! -f "$vocab_file" ]; then
83
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-uncased-vocab.txt
84
+ fi
85
+
86
+ jobname="${task}-bsz${global_batch_size}-lr${lr}-epochs${epochs}-seed${seed}"
87
+ checkpoint_path="${pretrained_checkpoint}-finetune/${jobname}"
88
+ mkdir -p ${checkpoint_path}
89
+
90
+ template_json="ds_config_bert_TEMPLATE.json"
91
+ config_json="ds_config_bert_bsz${global_batch_size}_mbsz${batch_size}_log${log_interval}_zero${zero_stage}.json"
92
+ if [[ $zero_stage -gt 0 ]]; then
93
+ sed "s/CONFIG_BATCH_SIZE/${global_batch_size}/" ${template_json} \
94
+ | sed "s/CONFIG_MBSIZE/${batch_size}/" \
95
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
96
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
97
+ | sed "s/PRESCALE_GRAD/false/" \
98
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
99
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
100
+ > ${config_json}
101
+ else
102
+ sed "s/CONFIG_BATCH_SIZE/${global_batch_size}/" ${template_json} \
103
+ | sed "s/CONFIG_MBSIZE/${batch_size}/" \
104
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
105
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
106
+ | sed "s/PRESCALE_GRAD/true/" \
107
+ | sed "s/CONFIG_FP16_ENABLED/true/" \
108
+ | sed "s/CONFIG_BF16_ENABLED/false/" \
109
+ > ${config_json}
110
+ fi
111
+
112
+ options=" \
113
+ --finetune \
114
+ --deepspeed \
115
+ --deepspeed_config ${config_json} \
116
+ --zero-stage ${zero_stage} \
117
+ --task ${task} \
118
+ --seed ${seed} \
119
+ --train-data ${train_data} \
120
+ --valid-data ${valid_data} \
121
+ --tokenizer-type BertWordPieceLowerCase \
122
+ --vocab-file ${vocab_file} \
123
+ --epochs ${epochs} \
124
+ --pretrained-checkpoint ${pretrained_checkpoint} \
125
+ --tensor-model-parallel-size ${mp_size} \
126
+ --pipeline-model-parallel-size ${pp_size} \
127
+ --num-layers ${num_layers} \
128
+ --hidden-size ${hidden_size} \
129
+ --num-attention-heads ${num_attn_heads} \
130
+ --global-batch-size ${global_batch_size} \
131
+ --micro-batch-size ${batch_size} \
132
+ --lr ${lr} \
133
+ --lr-decay-style linear \
134
+ --lr-warmup-fraction 0.065 \
135
+ --seq-length ${seq_len} \
136
+ --max-position-embeddings ${seq_len} \
137
+ --save-interval ${save_interval} \
138
+ --save ${checkpoint_path} \
139
+ --log-interval ${log_interval} \
140
+ --eval-interval ${eval_interval} \
141
+ --eval-iters ${eval_iters} \
142
+ --weight-decay 1.0e-1 \
143
+ --fp16"
144
+
145
+ if [ "${activation_checkpoint}" = "true" ]; then
146
+ options="${options} \
147
+ --checkpoint-activations \
148
+ --deepspeed-activation-checkpointing"
149
+ fi
150
+
151
+ if [[ "${no_pp}" = "true" ]]; then
152
+ options="${options} \
153
+ --no-pipeline-parallel"
154
+ fi
155
+
156
+ # After the fine-tuning finishes, you can find the dev set accuracy numbers by
157
+ # "grep -e "overall:" -e "metrics for" ${checkpoint_path}/output.log"
158
+ deepspeed ../../../../tasks/main.py ${options} &> ${checkpoint_path}/output.log
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/pretrain/ds_config_bert_1clmetric_TEMPLATE.json ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size": GBSIZE,
3
+ "train_micro_batch_size_per_gpu": MBSIZE,
4
+ "steps_per_print": LOG_INTERVAL,
5
+
6
+ "zero_optimization": {
7
+ "stage": ZERO_STAGE
8
+ },
9
+
10
+ "gradient_clipping": 1.0,
11
+ "prescale_gradients": PRESCALE_GRAD,
12
+
13
+ "fp16": {
14
+ "enabled": true,
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
+ "wall_clock_breakdown" : false,
23
+ "dataloader_drop_last": true,
24
+ "data_efficiency": {
25
+ "enabled": true,
26
+ "seed": DATA_EFFICIENCY_SEED,
27
+ "data_routing": {
28
+ "enabled": LTD_ENABLED,
29
+ "random_ltd":{
30
+ "enabled": LTD_ENABLED,
31
+ "total_layer_num": 24,
32
+ "random_ltd_layer_num": 22,
33
+ "random_ltd_layer_id": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],
34
+ "model_mask_name": "attention_mask",
35
+ "model_type": "encoder",
36
+ "hidden_state_order": "seq_batch_dim",
37
+ "random_ltd_schedule": {
38
+ "min_value": LTD_MIN,
39
+ "max_value": LTD_MAX,
40
+ "schedule_type":"fixed_linear",
41
+ "schedule_config": {
42
+ "require_steps": LTD_STEP,
43
+ "seq_per_step": 16
44
+ }
45
+ }
46
+ }
47
+ },
48
+ "data_sampling": {
49
+ "enabled": CL_ENABLED,
50
+ "num_workers": DATA_SAMPLING_NUM_WORKERS,
51
+ "curriculum_learning": {
52
+ "enabled": CL_ENABLED,
53
+ "data_cluster_path": "CL_CLUSTER_PATH",
54
+ "curriculum_metrics": {
55
+ "CL_1st_METRIC_NAME": {
56
+ "index_to_sample_path": "CL_1st_SAMPLE_PATH",
57
+ "index_to_metric_path": "CL_1st_METRIC_PATH",
58
+ "difficulty_type": "CL_1st_DIFF_TYPE",
59
+ "clustering_type": "CL_1st_CLUSTER_TYPE",
60
+ "min_difficulty": CL_1st_MIN,
61
+ "max_difficulty": CL_1st_MAX,
62
+ "schedule_type": "fixed_root",
63
+ "schedule_config": {
64
+ "total_curriculum_step": CL_1st_TOTAL_STEP,
65
+ "difficulty_step": CL_1st_DIFF_STEP,
66
+ "root_degree": CL_1st_ROOT
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/pretrain/ds_config_bert_2clmetrics_TEMPLATE.json ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size": GBSIZE,
3
+ "train_micro_batch_size_per_gpu": MBSIZE,
4
+ "steps_per_print": LOG_INTERVAL,
5
+
6
+ "zero_optimization": {
7
+ "stage": ZERO_STAGE
8
+ },
9
+
10
+ "gradient_clipping": 1.0,
11
+ "prescale_gradients": PRESCALE_GRAD,
12
+
13
+ "fp16": {
14
+ "enabled": true,
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
+ "wall_clock_breakdown" : false,
23
+ "dataloader_drop_last": true,
24
+ "data_efficiency": {
25
+ "enabled": true,
26
+ "seed": DATA_EFFICIENCY_SEED,
27
+ "data_routing": {
28
+ "enabled": LTD_ENABLED,
29
+ "random_ltd":{
30
+ "enabled": LTD_ENABLED,
31
+ "total_layer_num": 24,
32
+ "random_ltd_layer_num": 22,
33
+ "random_ltd_layer_id": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],
34
+ "model_mask_name": "attention_mask",
35
+ "model_type": "encoder",
36
+ "hidden_state_order": "seq_batch_dim",
37
+ "random_ltd_schedule": {
38
+ "min_value": LTD_MIN,
39
+ "max_value": LTD_MAX,
40
+ "schedule_type":"fixed_linear",
41
+ "schedule_config": {
42
+ "require_steps": LTD_STEP,
43
+ "seq_per_step": 16
44
+ }
45
+ }
46
+ }
47
+ },
48
+ "data_sampling": {
49
+ "enabled": CL_ENABLED,
50
+ "num_workers": DATA_SAMPLING_NUM_WORKERS,
51
+ "curriculum_learning": {
52
+ "enabled": CL_ENABLED,
53
+ "data_cluster_path": "CL_CLUSTER_PATH",
54
+ "curriculum_metrics": {
55
+ "CL_1st_METRIC_NAME": {
56
+ "index_to_sample_path": "CL_1st_SAMPLE_PATH",
57
+ "index_to_metric_path": "CL_1st_METRIC_PATH",
58
+ "difficulty_type": "CL_1st_DIFF_TYPE",
59
+ "clustering_type": "CL_1st_CLUSTER_TYPE",
60
+ "min_difficulty": CL_1st_MIN,
61
+ "max_difficulty": CL_1st_MAX,
62
+ "schedule_type": "fixed_root",
63
+ "schedule_config": {
64
+ "total_curriculum_step": CL_1st_TOTAL_STEP,
65
+ "difficulty_step": CL_1st_DIFF_STEP,
66
+ "root_degree": CL_1st_ROOT
67
+ }
68
+ },
69
+ "CL_2nd_METRIC_NAME": {
70
+ "index_to_sample_path": "CL_2nd_SAMPLE_PATH",
71
+ "index_to_metric_path": "CL_2nd_METRIC_PATH",
72
+ "difficulty_type": "CL_2nd_DIFF_TYPE",
73
+ "clustering_type": "CL_2nd_CLUSTER_TYPE",
74
+ "min_difficulty": CL_2nd_MIN,
75
+ "max_difficulty": CL_2nd_MAX,
76
+ "schedule_type": "fixed_root",
77
+ "schedule_config": {
78
+ "total_curriculum_step": CL_2nd_TOTAL_STEP,
79
+ "difficulty_step": CL_2nd_DIFF_STEP,
80
+ "root_degree": CL_2nd_ROOT
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/data_efficiency/bert/pretrain/ds_pretrain_bert_336M_run.sh ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###############################################################################
2
+ ### Each block below is one pretraining setup. Uncomment one block to try.
3
+ ###############################################################################
4
+ ### Baseline cases, mostly based on Megatron-LM's BERT-Large hyperparameters,
5
+ ### but with some changes (different LR schedule).
6
+ ## Baseline 1049B tokens (100%):
7
+ # lr=1e-4
8
+ # train_iters_in_million=2
9
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million}
10
+ ###############################################################################
11
+ ## Baseline 703B tokens (67%):
12
+ # lr=1.5e-4
13
+ # train_iters_in_million=134e-2
14
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million}
15
+ ###############################################################################
16
+ ## Baseline 524B tokens (50%):
17
+ # lr=2e-4
18
+ # train_iters_in_million=1
19
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million}
20
+ ###############################################################################
21
+ ### Curriculum learning (CL) + Random layerwise token dropping (random-LTD).
22
+ ### DeepSpeed Data Efficiency's composed solution.
23
+ ### BERT pretraining.
24
+ ## CL+random-LTD 1049B tokens (100%):
25
+ # lr=1e-4
26
+ # train_iters_in_million=2
27
+ # ltd_enabled="true"
28
+ # ltd_start=128
29
+ # ltd_step_in_million=2
30
+ # dropout=1e-1
31
+ # cl_enabled="true"
32
+ # cl_num_metric=2
33
+ # cl_1st_metric="voc"
34
+ # cl_1st_index_to_sample_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_sample_percentile_merged"
35
+ # cl_1st_index_to_metric_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_metric"
36
+ # cl_1st_difficulty_type="percentile"
37
+ # cl_1st_clustering_type="schedule_based"
38
+ # cl_1st_min=5
39
+ # cl_1st_max=100
40
+ # cl_1st_total_step_in_million=96e-2
41
+ # cl_1st_difficulty_step=1
42
+ # cl_1st_root=2
43
+ # cl_2nd_metric="seqlen_truncate"
44
+ # cl_2nd_index_to_sample_path="dummy"
45
+ # cl_2nd_index_to_metric_path="dummy"
46
+ # cl_2nd_difficulty_type="value"
47
+ # cl_2nd_clustering_type="single_cluster"
48
+ # cl_2nd_min=128
49
+ # cl_2nd_max=512
50
+ # cl_2nd_total_step_in_million=96e-2
51
+ # cl_2nd_difficulty_step=8
52
+ # cl_2nd_root=1
53
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
54
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
55
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
56
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
57
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
58
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
59
+ # ${cl_1st_root} ${cl_2nd_metric} ${cl_2nd_index_to_sample_path} \
60
+ # ${cl_2nd_index_to_metric_path} ${cl_2nd_difficulty_type} \
61
+ # ${cl_2nd_clustering_type} ${cl_2nd_min} ${cl_2nd_max} \
62
+ # ${cl_2nd_total_step_in_million} ${cl_2nd_difficulty_step} ${cl_2nd_root}
63
+ ###############################################################################
64
+ ## CL+random-LTD 524B tokens (50%):
65
+ # lr=2e-4
66
+ # train_iters_in_million=1
67
+ # ltd_enabled="true"
68
+ # ltd_start=128
69
+ # ltd_step_in_million=1
70
+ # dropout=1e-1
71
+ # cl_enabled="true"
72
+ # cl_num_metric=2
73
+ # cl_1st_metric="voc"
74
+ # cl_1st_index_to_sample_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_sample_percentile_merged"
75
+ # cl_1st_index_to_metric_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_metric"
76
+ # cl_1st_difficulty_type="percentile"
77
+ # cl_1st_clustering_type="schedule_based"
78
+ # cl_1st_min=5
79
+ # cl_1st_max=100
80
+ # cl_1st_total_step_in_million=48e-2
81
+ # cl_1st_difficulty_step=1
82
+ # cl_1st_root=2
83
+ # cl_2nd_metric="seqlen_truncate"
84
+ # cl_2nd_index_to_sample_path="dummy"
85
+ # cl_2nd_index_to_metric_path="dummy"
86
+ # cl_2nd_difficulty_type="value"
87
+ # cl_2nd_clustering_type="single_cluster"
88
+ # cl_2nd_min=128
89
+ # cl_2nd_max=512
90
+ # cl_2nd_total_step_in_million=48e-2
91
+ # cl_2nd_difficulty_step=8
92
+ # cl_2nd_root=1
93
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
94
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
95
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
96
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
97
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
98
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
99
+ # ${cl_1st_root} ${cl_2nd_metric} ${cl_2nd_index_to_sample_path} \
100
+ # ${cl_2nd_index_to_metric_path} ${cl_2nd_difficulty_type} \
101
+ # ${cl_2nd_clustering_type} ${cl_2nd_min} ${cl_2nd_max} \
102
+ # ${cl_2nd_total_step_in_million} ${cl_2nd_difficulty_step} ${cl_2nd_root}
103
+ ###############################################################################
104
+ ### Random layerwise token dropping (random-LTD).
105
+ ## random-LTD 1049B tokens (100%):
106
+ # lr=1e-4
107
+ # train_iters_in_million=2
108
+ # ltd_enabled="true"
109
+ # ltd_start=128
110
+ # ltd_step_in_million=2
111
+ # dropout=1e-1
112
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
113
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout}
114
+ ###############################################################################
115
+ ## random-LTD 703B tokens (67%):
116
+ # lr=1.5e-4
117
+ # train_iters_in_million=134e-2
118
+ # ltd_enabled="true"
119
+ # ltd_start=128
120
+ # ltd_step_in_million=134e-2
121
+ # dropout=1e-1
122
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
123
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout}
124
+ ###############################################################################
125
+ ## random-LTD 524B tokens (50%):
126
+ # lr=2e-4
127
+ # train_iters_in_million=1
128
+ # ltd_enabled="true"
129
+ # ltd_start=128
130
+ # ltd_step_in_million=1
131
+ # dropout=1e-1
132
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
133
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout}
134
+ ###############################################################################
135
+ ### Curriculum learning (CL).
136
+ ## CL vocab rarity + seqlen truncation 524B tokens (50%):
137
+ # lr=2e-4
138
+ # train_iters_in_million=1
139
+ # ltd_enabled="false"
140
+ # ltd_start=512
141
+ # ltd_step_in_million=1
142
+ # dropout=1e-1
143
+ # cl_enabled="true"
144
+ # cl_num_metric=2
145
+ # cl_1st_metric="voc"
146
+ # cl_1st_index_to_sample_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_sample_percentile_merged"
147
+ # cl_1st_index_to_metric_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_metric"
148
+ # cl_1st_difficulty_type="percentile"
149
+ # cl_1st_clustering_type="schedule_based"
150
+ # cl_1st_min=5
151
+ # cl_1st_max=100
152
+ # cl_1st_total_step_in_million=48e-2
153
+ # cl_1st_difficulty_step=1
154
+ # cl_1st_root=2
155
+ # cl_2nd_metric="seqlen_truncate"
156
+ # cl_2nd_index_to_sample_path="dummy"
157
+ # cl_2nd_index_to_metric_path="dummy"
158
+ # cl_2nd_difficulty_type="value"
159
+ # cl_2nd_clustering_type="single_cluster"
160
+ # cl_2nd_min=128
161
+ # cl_2nd_max=512
162
+ # cl_2nd_total_step_in_million=48e-2
163
+ # cl_2nd_difficulty_step=8
164
+ # cl_2nd_root=1
165
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
166
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
167
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
168
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
169
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
170
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
171
+ # ${cl_1st_root} ${cl_2nd_metric} ${cl_2nd_index_to_sample_path} \
172
+ # ${cl_2nd_index_to_metric_path} ${cl_2nd_difficulty_type} \
173
+ # ${cl_2nd_clustering_type} ${cl_2nd_min} ${cl_2nd_max} \
174
+ # ${cl_2nd_total_step_in_million} ${cl_2nd_difficulty_step} ${cl_2nd_root}
175
+ ###############################################################################
176
+ ## CL vocab rarity + seqlen truncation 703B tokens (67%):
177
+ # lr=1.5e-4
178
+ # train_iters_in_million=134e-2
179
+ # ltd_enabled="false"
180
+ # ltd_start=512
181
+ # ltd_step_in_million=1
182
+ # dropout=1e-1
183
+ # cl_enabled="true"
184
+ # cl_num_metric=2
185
+ # cl_1st_metric="voc"
186
+ # cl_1st_index_to_sample_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_sample_percentile_merged"
187
+ # cl_1st_index_to_metric_path="/vc_data/users/conglli/code/data_efficiency/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_metric"
188
+ # cl_1st_difficulty_type="percentile"
189
+ # cl_1st_clustering_type="schedule_based"
190
+ # cl_1st_min=5
191
+ # cl_1st_max=100
192
+ # cl_1st_total_step_in_million=64e-2
193
+ # cl_1st_difficulty_step=1
194
+ # cl_1st_root=2
195
+ # cl_2nd_metric="seqlen_truncate"
196
+ # cl_2nd_index_to_sample_path="dummy"
197
+ # cl_2nd_index_to_metric_path="dummy"
198
+ # cl_2nd_difficulty_type="value"
199
+ # cl_2nd_clustering_type="single_cluster"
200
+ # cl_2nd_min=128
201
+ # cl_2nd_max=512
202
+ # cl_2nd_total_step_in_million=64e-2
203
+ # cl_2nd_difficulty_step=8
204
+ # cl_2nd_root=1
205
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
206
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
207
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
208
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
209
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
210
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
211
+ # ${cl_1st_root} ${cl_2nd_metric} ${cl_2nd_index_to_sample_path} \
212
+ # ${cl_2nd_index_to_metric_path} ${cl_2nd_difficulty_type} \
213
+ # ${cl_2nd_clustering_type} ${cl_2nd_min} ${cl_2nd_max} \
214
+ # ${cl_2nd_total_step_in_million} ${cl_2nd_difficulty_step} ${cl_2nd_root}
215
+ ###############################################################################
216
+ ## CL vocab rarity + seqlen truncation 1049B tokens (100%):
217
+ # lr=1e-4
218
+ # train_iters_in_million=2
219
+ # ltd_enabled="false"
220
+ # ltd_start=512
221
+ # ltd_step_in_million=1
222
+ # dropout=1e-1
223
+ # cl_enabled="true"
224
+ # cl_num_metric=2
225
+ # cl_1st_metric="voc"
226
+ # cl_1st_index_to_sample_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_sample"
227
+ # cl_1st_index_to_metric_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_metric"
228
+ # cl_1st_difficulty_type="percentile"
229
+ # cl_1st_clustering_type="schedule_based"
230
+ # cl_1st_min=5
231
+ # cl_1st_max=100
232
+ # cl_1st_total_step_in_million=96e-2
233
+ # cl_1st_difficulty_step=1
234
+ # cl_1st_root=2
235
+ # cl_2nd_metric="seqlen_truncate"
236
+ # cl_2nd_index_to_sample_path="dummy"
237
+ # cl_2nd_index_to_metric_path="dummy"
238
+ # cl_2nd_difficulty_type="value"
239
+ # cl_2nd_clustering_type="single_cluster"
240
+ # cl_2nd_min=128
241
+ # cl_2nd_max=512
242
+ # cl_2nd_total_step_in_million=96e-2
243
+ # cl_2nd_difficulty_step=8
244
+ # cl_2nd_root=1
245
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
246
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
247
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
248
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
249
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
250
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
251
+ # ${cl_1st_root} ${cl_2nd_metric} ${cl_2nd_index_to_sample_path} \
252
+ # ${cl_2nd_index_to_metric_path} ${cl_2nd_difficulty_type} \
253
+ # ${cl_2nd_clustering_type} ${cl_2nd_min} ${cl_2nd_max} \
254
+ # ${cl_2nd_total_step_in_million} ${cl_2nd_difficulty_step} ${cl_2nd_root}
255
+ ###############################################################################
256
+ ## CL vocab rarity + seqlen reorder 1049B tokens (100%):
257
+ # lr=1e-4
258
+ # train_iters_in_million=2
259
+ # ltd_enabled="false"
260
+ # ltd_start=512
261
+ # ltd_step_in_million=1
262
+ # dropout=1e-1
263
+ # cl_enabled="true"
264
+ # cl_num_metric=1
265
+ # cl_1st_metric="seqlenvocabrarity"
266
+ # cl_1st_index_to_sample_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/seqlen_vocab_rarity/seqlen_vocab_rarity_index_to_sample_percentile_merged"
267
+ # cl_1st_index_to_metric_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/seqlen_vocab_rarity/seqlen_vocab_rarity_index_to_metric"
268
+ # cl_1st_difficulty_type="percentile"
269
+ # cl_1st_clustering_type="schedule_based"
270
+ # cl_1st_min=5
271
+ # cl_1st_max=100
272
+ # cl_1st_total_step_in_million=96e-2
273
+ # cl_1st_difficulty_step=1
274
+ # cl_1st_root=2
275
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
276
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
277
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
278
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
279
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
280
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
281
+ # ${cl_1st_root}
282
+ ###############################################################################
283
+ ## CL vocab rarity 1049B tokens (100%):
284
+ # lr=1e-4
285
+ # train_iters_in_million=2
286
+ # ltd_enabled="false"
287
+ # ltd_start=512
288
+ # ltd_step_in_million=1
289
+ # dropout=1e-1
290
+ # cl_enabled="true"
291
+ # cl_num_metric=1
292
+ # cl_1st_metric="voc"
293
+ # cl_1st_index_to_sample_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_sample"
294
+ # cl_1st_index_to_metric_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/vocab_rarity/vocab_rarity_index_to_metric"
295
+ # cl_1st_difficulty_type="percentile"
296
+ # cl_1st_clustering_type="schedule_based"
297
+ # cl_1st_min=5
298
+ # cl_1st_max=100
299
+ # cl_1st_total_step_in_million=96e-2
300
+ # cl_1st_difficulty_step=1
301
+ # cl_1st_root=2
302
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
303
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
304
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
305
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
306
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
307
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
308
+ # ${cl_1st_root}
309
+ ###############################################################################
310
+ ## CL seqlen truncation 1049B tokens (100%):
311
+ # lr=1e-4
312
+ # train_iters_in_million=2
313
+ # ltd_enabled="false"
314
+ # ltd_start=512
315
+ # ltd_step_in_million=1
316
+ # dropout=1e-1
317
+ # cl_enabled="true"
318
+ # cl_num_metric=1
319
+ # cl_1st_metric="seqlen_truncate"
320
+ # cl_1st_index_to_sample_path="dummy"
321
+ # cl_1st_index_to_metric_path="dummy"
322
+ # cl_1st_difficulty_type="value"
323
+ # cl_1st_clustering_type="single_cluster"
324
+ # cl_1st_min=128
325
+ # cl_1st_max=512
326
+ # cl_1st_total_step_in_million=96e-2
327
+ # cl_1st_difficulty_step=8
328
+ # cl_1st_root=1
329
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
330
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
331
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
332
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
333
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
334
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
335
+ # ${cl_1st_root}
336
+ ###############################################################################
337
+ ## CL seqlen reorder 1049B tokens (100%):
338
+ # lr=1e-4
339
+ # train_iters_in_million=2
340
+ # ltd_enabled="false"
341
+ # ltd_start=512
342
+ # ltd_step_in_million=1
343
+ # dropout=1e-1
344
+ # cl_enabled="true"
345
+ # cl_num_metric=1
346
+ # cl_1st_metric="seqlen"
347
+ # cl_1st_index_to_sample_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/seqlen/seqlen_index_to_sample_percentile_merged"
348
+ # cl_1st_index_to_metric_path="/blob/users/conglli/data/analysis_pile_bert_5epoch/seqlen/seqlen_index_to_metric"
349
+ # cl_1st_difficulty_type="percentile"
350
+ # cl_1st_clustering_type="single_cluster"
351
+ # cl_1st_min=5
352
+ # cl_1st_max=100
353
+ # cl_1st_total_step_in_million=96e-2
354
+ # cl_1st_difficulty_step=8
355
+ # cl_1st_root=2
356
+ # bash ds_pretrain_bert_336M_base_script.sh ${lr} ${train_iters_in_million} \
357
+ # ${ltd_enabled} ${ltd_start} ${ltd_step_in_million} ${dropout} \
358
+ # ${cl_enabled} ${cl_num_metric} ${cl_1st_metric} \
359
+ # ${cl_1st_index_to_sample_path} ${cl_1st_index_to_metric_path} \
360
+ # ${cl_1st_difficulty_type} ${cl_1st_clustering_type} ${cl_1st_min} \
361
+ # ${cl_1st_max} ${cl_1st_total_step_in_million} ${cl_1st_difficulty_step} \
362
+ # ${cl_1st_root}
363
+ ###############################################################################
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/generate_text.sh ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ export TORCH_CUDA_ARCH_LIST=8.6+PTX
3
+ CHECKPOINT_PATH=dataset/checkpoints/gpt2_345m
4
+ VOCAB_FILE=dataset/gpt2-vocab.json
5
+ MERGE_FILE=dataset/gpt2-merges.txt
6
+ b=8
7
+ mp=1
8
+ experts=1
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
+ export CUDA_DEVICE_MAX_CONNECTIONS=1
21
+
22
+ launch_cmd="deepspeed --num_nodes $nodes --num_gpus $gpus"
23
+ L=24
24
+ H=1024
25
+ A=16
26
+ #experts1=${experts[$k]}
27
+ program_cmd="tools/generate_samples_gpt.py \
28
+ --tensor-model-parallel-size $mp \
29
+ --num-layers $L \
30
+ --hidden-size $H \
31
+ --num-attention-heads $A \
32
+ --max-position-embeddings 1024 \
33
+ --tokenizer-type GPT2BPETokenizer \
34
+ --fp16 \
35
+ --num-experts ${experts} \
36
+ --mlp-type standard \
37
+ --micro-batch-size $b \
38
+ --seq-length 1024 \
39
+ --out-seq-length 1024 \
40
+ --temperature 1.0 \
41
+ --vocab-file $VOCAB_FILE \
42
+ --merge-file $MERGE_FILE \
43
+ --genfile unconditional_samples.json \
44
+ --top_p 0.9 \
45
+ --log-interval 1 \
46
+ --num-samples 0 \
47
+ --load $CHECKPOINT_PATH \
48
+ $use_tutel $ds_inference"
49
+
50
+ echo $launch_cmd $program_cmd
51
+ $launch_cmd $program_cmd
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/pretrain_llama2_distributed.sh ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # This example script is contributed by external user https://github.com/nrailgun
3
+ set -ex
4
+
5
+ ######################################
6
+ # Change the below configurations here
7
+ BASE_PATH=./tmp
8
+ DS_CONFIG=${BASE_PATH}/deepspeed.json
9
+ DATASET_1="./tmp/data/bookcorpus_train_1m_text_sentence"
10
+ DATASET="1 ${DATASET_1}"
11
+ CHECKPOINT_PATH=./tmp
12
+ TOKENIZER_PATH=./tmp/tokenizer.model # offical llama tokenizer.model
13
+
14
+ TP=2
15
+ PP=2
16
+ ZERO_STAGE=0
17
+
18
+ GPUS_PER_NODE=8
19
+ MASTER_ADDR=localhost
20
+ MASTER_PORT=6000
21
+ NNODES=1
22
+ NODE_RANK=0
23
+
24
+ HIDDEN_SIZE=2048 # e.g. llama-13b: 5120
25
+ FFN_HIDDEN_SIZE=5504 # e.g. llama-13b: 13824
26
+ NUM_LAYERS=24 # e.g. llama-13b: 40
27
+ NUM_HEADS=16 # e.g. llama-13b: 40
28
+ SEQ_LENGTH=2048
29
+ NUM_KV_HEADS=4 # llama2 70B uses GQA
30
+
31
+ MICRO_BATCH_SIZE=4
32
+ GLOBAL_BATCH_SIZE=32 # e.g. llama: 4M tokens
33
+ TRAIN_STEPS=250000 # e.g. llama: 1T tokens / 4M tokens_per_batch = 250000 steps
34
+ LR=3e-4
35
+ MIN_LR=3e-5
36
+ LR_WARMUP_STEPS=2000
37
+ WEIGHT_DECAY=0.1
38
+ GRAD_CLIP=1
39
+
40
+ ## Activation checkpointing saves GPU memory, but reduces training speed
41
+ # activation_checkpoint="true"
42
+ activation_checkpoint="false"
43
+
44
+ # Below configuration required for llama model as per llama paper
45
+ # --no-query-key-layer-scaling \
46
+ # --attention-dropout 0 \
47
+ # --hidden-dropout 0 \
48
+ # --use-rotary-position-embeddings \
49
+ # --untie-embeddings-and-output-weights \
50
+ # --swiglu \
51
+ # --normalization rmsnorm \
52
+ # --disable-bias-linear \
53
+ ######################################
54
+
55
+
56
+
57
+ cat <<EOT > $DS_CONFIG
58
+ {
59
+ "train_batch_size" : $GLOBAL_BATCH_SIZE,
60
+ "train_micro_batch_size_per_gpu": $MICRO_BATCH_SIZE,
61
+ "steps_per_print": 1,
62
+ "zero_optimization": {
63
+ "stage": $ZERO_STAGE
64
+ },
65
+ "bf16": {
66
+ "enabled": true
67
+ }
68
+ }
69
+ EOT
70
+
71
+ ds_args=""
72
+ ds_args=" --deepspeed ${ds_args}"
73
+ ds_args=" --deepspeed_config=$DS_CONFIG ${ds_args}"
74
+ ds_args=" --zero-stage=$ZERO_STAGE ${ds_args}"
75
+
76
+ if [ "${activation_checkpoint}" = "true" ]; then
77
+ ds_args="--deepspeed-activation-checkpointing ${ds_args}"
78
+
79
+ ## old argument for recomputing the transformer layer
80
+ # ds_args="--checkpoint-activations ${ds_args}"
81
+
82
+ ## new argument for recomputing the transformer layer
83
+ ds_args="--recompute-granularity full --recompute-method uniform ${ds_args}"
84
+ ## new argument for recomputing only the attention layer
85
+ # ds_args="--recompute-granularity selective ${ds_args}"
86
+ fi
87
+
88
+
89
+ DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
90
+
91
+ torchrun $DISTRIBUTED_ARGS \
92
+ pretrain_gpt.py \
93
+ --tensor-model-parallel-size $TP \
94
+ --pipeline-model-parallel-size $PP \
95
+ --num-layers $NUM_LAYERS \
96
+ --hidden-size $HIDDEN_SIZE \
97
+ --ffn-hidden-size $FFN_HIDDEN_SIZE \
98
+ --num-attention-heads $NUM_HEADS \
99
+ --micro-batch-size $MICRO_BATCH_SIZE \
100
+ --global-batch-size $GLOBAL_BATCH_SIZE \
101
+ --seq-length $SEQ_LENGTH \
102
+ --max-position-embeddings $SEQ_LENGTH \
103
+ --train-iters $TRAIN_STEPS \
104
+ --save $CHECKPOINT_PATH \
105
+ --load $CHECKPOINT_PATH \
106
+ --data-path $DATASET \
107
+ --data-impl mmap \
108
+ --tokenizer-type GPTSentencePieceTokenizer \
109
+ --tokenizer-model $TOKENIZER_PATH \
110
+ --split 949,50,1 \
111
+ --distributed-backend nccl \
112
+ --lr $LR \
113
+ --lr-decay-style cosine \
114
+ --min-lr $MIN_LR \
115
+ --weight-decay $WEIGHT_DECAY \
116
+ --clip-grad $GRAD_CLIP \
117
+ --lr-warmup-iters $LR_WARMUP_STEPS \
118
+ --optimizer adam \
119
+ --adam-beta1 0.9 \
120
+ --adam-beta2 0.95 \
121
+ --log-interval 1 \
122
+ --save-interval 10000 \
123
+ --eval-interval 1000 \
124
+ --eval-iters 10 \
125
+ --bf16 \
126
+ --no-query-key-layer-scaling \
127
+ --attention-dropout 0 \
128
+ --hidden-dropout 0 \
129
+ --use-rotary-position-embeddings \
130
+ --untie-embeddings-and-output-weights \
131
+ --swiglu \
132
+ --normalization rmsnorm \
133
+ --disable-bias-linear \
134
+ --num-key-value-heads $NUM_KV_HEADS \
135
+ $ds_args
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/pretrain_llama_distributed.sh ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # This example script is contributed by external user https://github.com/LydiaXiaohongLi
3
+ set -ex
4
+
5
+ ######################################
6
+ # Change the below configurations here
7
+ BASE_PATH=./tmp
8
+ DS_CONFIG=${BASE_PATH}/deepspeed.json
9
+ DATASET_1="./tmp/data/bookcorpus_train_1m_text_sentence"
10
+ DATASET="1 ${DATASET_1}"
11
+ CHECKPOINT_PATH=./tmp
12
+ TOKENIZER_PATH=./tmp/tokenizer.model # offical llama tokenizer.model
13
+
14
+ TP=2
15
+ PP=2
16
+ ZERO_STAGE=0
17
+
18
+ GPUS_PER_NODE=8
19
+ MASTER_ADDR=localhost
20
+ MASTER_PORT=6000
21
+ NNODES=1
22
+ NODE_RANK=0
23
+
24
+ HIDDEN_SIZE=2048 # e.g. llama-13b: 5120
25
+ FFN_HIDDEN_SIZE=5504 # e.g. llama-13b: 13824
26
+ NUM_LAYERS=24 # e.g. llama-13b: 40
27
+ NUM_HEADS=16 # e.g. llama-13b: 40
28
+ SEQ_LENGTH=2048
29
+
30
+ MICRO_BATCH_SIZE=4
31
+ GLOBAL_BATCH_SIZE=32 # e.g. llama: 4M tokens
32
+ TRAIN_STEPS=250000 # e.g. llama: 1T tokens / 4M tokens_per_batch = 250000 steps
33
+ LR=3e-4
34
+ MIN_LR=3e-5
35
+ LR_WARMUP_STEPS=2000
36
+ WEIGHT_DECAY=0.1
37
+ GRAD_CLIP=1
38
+
39
+ ## Activation checkpointing saves GPU memory, but reduces training speed
40
+ # activation_checkpoint="true"
41
+ activation_checkpoint="false"
42
+
43
+ # Below configuration required for llama model as per llama paper
44
+ # --no-query-key-layer-scaling \
45
+ # --attention-dropout 0 \
46
+ # --hidden-dropout 0 \
47
+ # --use-rotary-position-embeddings \
48
+ # --untie-embeddings-and-output-weights \
49
+ # --swiglu \
50
+ # --normalization rmsnorm \
51
+ # --disable-bias-linear \
52
+ ######################################
53
+
54
+
55
+
56
+ cat <<EOT > $DS_CONFIG
57
+ {
58
+ "train_batch_size" : $GLOBAL_BATCH_SIZE,
59
+ "train_micro_batch_size_per_gpu": $MICRO_BATCH_SIZE,
60
+ "steps_per_print": 1,
61
+ "zero_optimization": {
62
+ "stage": $ZERO_STAGE
63
+ },
64
+ "bf16": {
65
+ "enabled": true
66
+ }
67
+ }
68
+ EOT
69
+
70
+ ds_args=""
71
+ ds_args=" --deepspeed ${ds_args}"
72
+ ds_args=" --deepspeed_config=$DS_CONFIG ${ds_args}"
73
+ ds_args=" --zero-stage=$ZERO_STAGE ${ds_args}"
74
+
75
+ if [ "${activation_checkpoint}" = "true" ]; then
76
+ ds_args="--deepspeed-activation-checkpointing ${ds_args}"
77
+
78
+ ## old argument for recomputing the transformer layer
79
+ # ds_args="--checkpoint-activations ${ds_args}"
80
+
81
+ ## new argument for recomputing the transformer layer
82
+ ds_args="--recompute-granularity full --recompute-method uniform ${ds_args}"
83
+ ## new argument for recomputing only the attention layer
84
+ # ds_args="--recompute-granularity selective ${ds_args}"
85
+ fi
86
+
87
+ DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
88
+
89
+ torchrun $DISTRIBUTED_ARGS \
90
+ pretrain_gpt.py \
91
+ --tensor-model-parallel-size $TP \
92
+ --pipeline-model-parallel-size $PP \
93
+ --num-layers $NUM_LAYERS \
94
+ --hidden-size $HIDDEN_SIZE \
95
+ --ffn-hidden-size $FFN_HIDDEN_SIZE \
96
+ --num-attention-heads $NUM_HEADS \
97
+ --micro-batch-size $MICRO_BATCH_SIZE \
98
+ --global-batch-size $GLOBAL_BATCH_SIZE \
99
+ --seq-length $SEQ_LENGTH \
100
+ --max-position-embeddings $SEQ_LENGTH \
101
+ --train-iters $TRAIN_STEPS \
102
+ --save $CHECKPOINT_PATH \
103
+ --load $CHECKPOINT_PATH \
104
+ --data-path $DATASET \
105
+ --data-impl mmap \
106
+ --tokenizer-type GPTSentencePieceTokenizer \
107
+ --tokenizer-model $TOKENIZER_PATH \
108
+ --split 949,50,1 \
109
+ --distributed-backend nccl \
110
+ --lr $LR \
111
+ --lr-decay-style cosine \
112
+ --min-lr $MIN_LR \
113
+ --weight-decay $WEIGHT_DECAY \
114
+ --clip-grad $GRAD_CLIP \
115
+ --lr-warmup-iters $LR_WARMUP_STEPS \
116
+ --optimizer adam \
117
+ --adam-beta1 0.9 \
118
+ --adam-beta2 0.95 \
119
+ --log-interval 1 \
120
+ --save-interval 10000 \
121
+ --eval-interval 1000 \
122
+ --eval-iters 10 \
123
+ --bf16 \
124
+ --no-query-key-layer-scaling \
125
+ --attention-dropout 0 \
126
+ --hidden-dropout 0 \
127
+ --use-rotary-position-embeddings \
128
+ --untie-embeddings-and-output-weights \
129
+ --swiglu \
130
+ --normalization rmsnorm \
131
+ --disable-bias-linear \
132
+ $ds_args
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_config_gpt_TEMPLATE.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "train_batch_size": GBSIZE,
3
+ "train_micro_batch_size_per_gpu": MBSIZE,
4
+ "steps_per_print": LOG_INTERVAL,
5
+
6
+ "zero_optimization": {
7
+ "stage": ZERO_STAGE
8
+ },
9
+
10
+ "gradient_clipping": 1.0,
11
+ "prescale_gradients": PRESCALE_GRAD,
12
+
13
+ "fp16": {
14
+ "enabled": true,
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
+ "wall_clock_breakdown" : false
23
+ }
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_pretrain_gpt_1.3B_megatron_checkpointing.sh ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ ###############################################################################
3
+ ###############################################################################
4
+ ###############################################################################
5
+ ## WARNING: This script is only for evaluating Megatron-LM's activation
6
+ ## checkpointing. We do not recommend using it for actual training because
7
+ ## you are not able to use any DeepSpeed technologies.
8
+ ###############################################################################
9
+ ###############################################################################
10
+ ###############################################################################
11
+ dir=`pwd`
12
+ ###############################################################################
13
+ ### Main configs
14
+ ## GPT-3 models use 2K sequence length/context window
15
+ seq_len=2048
16
+
17
+ ## The "GPT-3 XXX" below are configs from GPT-3 paper
18
+ ## https://arxiv.org/abs/2005.14165, choose based on
19
+ ## your desired model size or build your own configs
20
+
21
+ ## init_std is standard deviation for weight initialization. Usually larger
22
+ ## model needs lower std. We used a heuristic equation of sqrt(1/3/hidden_size)
23
+ ## from the MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
24
+
25
+ ## We changed min_lr to a lower number (1.0e-6), which we found is able to
26
+ ## provide better zero-shot eval results.
27
+
28
+ ## GPT-3 Small 125M
29
+ # model_size=0.125
30
+ # num_layers=12
31
+ # hidden_size=768
32
+ # num_attn_heads=12
33
+ # global_batch_size=256
34
+ # lr=6.0e-4
35
+ # min_lr=1.0e-6
36
+ # init_std=0.02
37
+
38
+ ## GPT-3 Medium 350M
39
+ # model_size=0.35
40
+ # num_layers=24
41
+ # hidden_size=1024
42
+ # num_attn_heads=16
43
+ # global_batch_size=256
44
+ # lr=3.0e-4
45
+ # min_lr=1.0e-6
46
+ # init_std=0.018
47
+
48
+ ## GPT-3 Large 760M
49
+ # model_size=0.76
50
+ # num_layers=24
51
+ # hidden_size=1536
52
+ # num_attn_heads=16
53
+ # global_batch_size=256
54
+ # lr=2.5e-4
55
+ # min_lr=1.0e-6
56
+ # init_std=0.015
57
+
58
+ ## GPT-3 XL 1.3B
59
+ model_size=1.3
60
+ num_layers=24
61
+ hidden_size=2048
62
+ num_attn_heads=16
63
+ global_batch_size=512
64
+ lr=2.0e-4
65
+ min_lr=1.0e-6
66
+ init_std=0.013
67
+
68
+ ## GPT-3 2.7B
69
+ # model_size=2.7
70
+ # num_layers=32
71
+ # hidden_size=2560
72
+ # num_attn_heads=32
73
+ # global_batch_size=512
74
+ # lr=1.6e-4
75
+ # min_lr=1.0e-6
76
+ # init_std=0.011
77
+
78
+ ## GPT-3 6.7B
79
+ # model_size=6.7
80
+ # num_layers=32
81
+ # hidden_size=4096
82
+ # num_attn_heads=32
83
+ # global_batch_size=1024
84
+ # lr=1.2e-4
85
+ # min_lr=1.0e-6
86
+ # init_std=0.009
87
+
88
+ ## GPT-3 13B
89
+ # model_size=13
90
+ # num_layers=40
91
+ # hidden_size=5120
92
+ # num_attn_heads=40
93
+ # global_batch_size=1024
94
+ # lr=1.0e-4
95
+ # min_lr=1.0e-6
96
+ # init_std=0.008
97
+
98
+ ## GPT-3 175B
99
+ # model_size=175
100
+ # num_layers=96
101
+ # hidden_size=12288
102
+ # num_attn_heads=96
103
+ # global_batch_size=1536
104
+ # lr=0.6e-4
105
+ # min_lr=1.0e-6
106
+ # init_std=0.005
107
+ ###############################################################################
108
+ ### Training duration configs
109
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens.
110
+ train_tokens_in_billion=300
111
+ train_tokens=$((${train_tokens_in_billion} * 1000000000))
112
+
113
+ ## train_samples is another termination condition and also affect the number of
114
+ ## data samples to be indexed. Since we want to reach the train_tokens
115
+ ## above, and data efficiency techniques may change num tokens in some samples,
116
+ ## so we just set this config large enough to make sure we have enough
117
+ ## processed data and don't terminate by train_samples.
118
+ train_samples=$(( 300 * 1000000000 * 2 / ${seq_len} ))
119
+
120
+ ## Another wall-clock time termination condition in minutes. Set it large
121
+ ## enough to avoid undesired early termination.
122
+ exit_duration=30000000
123
+ ###############################################################################
124
+ ### lr configs
125
+ ## lr warmup and decay duration.
126
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B cosine decay tokens.
127
+ ## Here we increase the warmup tokens to 3B since when batch size warmup is not
128
+ ## used, there are more tokens per step. Thus we need to increase warmup tokens
129
+ ## to make sure there are enough warmup steps, which is important for training
130
+ ## stability.
131
+ lr_warmup_tokens_in_million=3000
132
+ lr_warmup_tokens=$((${lr_warmup_tokens_in_million} * 1000000))
133
+ ## Here we changed the LR decay tokens to align with total train tokens, since
134
+ ## related works (e.g., https://arxiv.org/abs/2203.15556) find that setting the
135
+ ## learning rate schedule to match the number of training tokens results in the
136
+ ## best final model quality
137
+ lr_decay_tokens_in_billion=${train_tokens_in_billion}
138
+ lr_decay_tokens=$((${lr_decay_tokens_in_billion} * 1000000000))
139
+ lr_decay_style="cosine"
140
+ ###############################################################################
141
+ ### Parallelism configs
142
+ ## Model parallelism, 1 is no MP
143
+ mp_size=2
144
+
145
+ ## Pipeline parallelism. To disable PP, set pp_size to 1 and no_pp to true.
146
+ ## Note that currently both curriculum learning and random-LTD are NOT
147
+ ## compatible with pipeline parallelism.
148
+ pp_size=1
149
+ no_pp="true"
150
+
151
+ ## ZeRO-based data parallelism, stage=0 will disable ZeRO
152
+ zero_stage=0
153
+
154
+ ## Total number of GPUs. ds_ssh is from DeepSpeed library.
155
+ num_gpus=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
156
+ num_gpus_pernode=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
157
+ num_node=$(( ${num_gpus} / ${num_gpus_pernode} ))
158
+
159
+ ## Data parallel size.
160
+ dp_size=$(( ${num_gpus} / ${pp_size} / ${mp_size} ))
161
+
162
+ ## Micro batch size per GPU
163
+ ## Make sure that batch_size <= global_batch_size*pp_size*mp_size/num_gpus
164
+ ## Reduce it manually if GPU OOM
165
+ # batch_size=$(( ${global_batch_size} / ${dp_size} ))
166
+ batch_size=2
167
+ ###############################################################################
168
+ ### Misc configs
169
+ log_interval=10
170
+ eval_iters=10
171
+ eval_interval=100
172
+ # num_save controls how frequent to save checkpoint. num_save=20 means that a
173
+ # checkpoint will be saved every 5% of training. For longer training you would
174
+ # want larger num_save to save more frequently, and vice versa.
175
+ num_save=100
176
+ estimated_train_iter=$((${train_tokens} / ${seq_len} / ${global_batch_size}))
177
+ # save_interval=$((${estimated_train_iter} / ${num_save}))
178
+ save_interval=100
179
+
180
+ ## Activation checkpointing saves GPU memory, but reduces training speed
181
+ activation_checkpoint="true"
182
+ # activation_checkpoint="false"
183
+
184
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
185
+ ## This is not required for training and might save GPU memory when turned off.
186
+ log_optimizer_state="true"
187
+ ###############################################################################
188
+ ### Output and data configs
189
+ current_time=$(date "+%Y.%m.%d_%H.%M.%S")
190
+ host="${HOSTNAME}"
191
+ seed=1234
192
+ num_workers=0
193
+
194
+ ## Public the Pile dataset, can be downloaded at
195
+ ## https://mystic.the-eye.eu/public/AI/pile_neox/ or
196
+ ## https://the-eye.eu/public/AI/pile_neox/ Change data_home to where you
197
+ ## store the pile_text_document.bin and pile_text_document.idx.
198
+ data_home="/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing"
199
+ data_path="${data_home}/pile_text_document"
200
+
201
+ vocab_path="gpt2-vocab.json"
202
+ if [ ! -f "$vocab_path" ]; then
203
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json
204
+ fi
205
+ merge_path="gpt2-merges.txt"
206
+ if [ ! -f "$merge_path" ]; then
207
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt
208
+ fi
209
+
210
+ prescale_grad="true"
211
+ jobname="gpt_${model_size}B_tok${train_tokens_in_billion}B"
212
+ jobname="${jobname}_lr${lr}_min${min_lr}_w${lr_warmup_tokens_in_million}M_d${lr_decay_tokens_in_billion}B_${lr_decay_style}"
213
+ jobname="${jobname}_gbs${global_batch_size}_mbs${batch_size}_g${num_gpus}"
214
+ if [[ $zero_stage -gt 0 ]]; then
215
+ jobname="${jobname}_z${zero_stage}"
216
+ prescale_grad="false"
217
+ fi
218
+ if [[ $mp_size -gt 1 ]]; then
219
+ jobname="${jobname}_mp${mp_size}"
220
+ fi
221
+ if [ "${no_pp}" = "false" ]; then
222
+ jobname="${jobname}_pp${pp_size}"
223
+ fi
224
+ jobname="${jobname}_seed${seed}_rebase_megatron_checkpointing"
225
+
226
+ username=$(whoami)
227
+ output_home="/blob/users/${username}/project/data_efficient_gpt"
228
+ log_path="${output_home}/log/"
229
+ checkpoint_path="${output_home}/checkpoint/${jobname}"
230
+ ## Microsoft internal constraint: because tensorboard is logged by last rank,
231
+ ## it's better to put the path in NFS instead of Blob.
232
+ tensorboard_dir="/vc_data/users/${username}/project/data_efficient_gpt/tensorboard/"
233
+ tensorboard_path="${tensorboard_dir}${jobname}_${host}_${current_time}"
234
+ mkdir -p ${log_path}
235
+ mkdir -p ${checkpoint_path}
236
+ mkdir -p ${tensorboard_path}
237
+ ###############################################################################
238
+ data_options=" \
239
+ --vocab-file ${vocab_path} \
240
+ --merge-file ${merge_path} \
241
+ --data-path ${data_path} \
242
+ --data-impl mmap"
243
+
244
+ ## If CL is used, make sure to set "--split" the same as what you used during
245
+ ## offline data analysis&indexing.
246
+ megatron_options=" \
247
+ --override-opt_param-scheduler \
248
+ --adam-beta1 0.9 \
249
+ --adam-beta2 0.95 \
250
+ --tensor-model-parallel-size ${mp_size} \
251
+ --init-method-std ${init_std} \
252
+ --lr-decay-tokens ${lr_decay_tokens} \
253
+ --lr-warmup-tokens ${lr_warmup_tokens} \
254
+ --micro-batch-size ${batch_size} \
255
+ --exit-duration-in-mins ${exit_duration} \
256
+ --global-batch-size ${global_batch_size} \
257
+ --num-layers ${num_layers} \
258
+ --hidden-size ${hidden_size} \
259
+ --num-attention-heads ${num_attn_heads} \
260
+ --seq-length ${seq_len} \
261
+ --max-position-embeddings ${seq_len} \
262
+ --train-tokens ${train_tokens} \
263
+ --train-samples ${train_samples} \
264
+ --lr ${lr} \
265
+ --min-lr ${min_lr} \
266
+ --lr-decay-style ${lr_decay_style} \
267
+ --split 949,50,1 \
268
+ --log-interval ${log_interval} \
269
+ --eval-interval ${eval_interval} \
270
+ --eval-iters ${eval_iters} \
271
+ --save-interval ${save_interval} \
272
+ --weight-decay 0.1 \
273
+ --clip-grad 1.0 \
274
+ --hysteresis 2 \
275
+ --num-workers ${num_workers} \
276
+ --fp16 \
277
+ --seed ${seed} \
278
+ --load ${checkpoint_path} \
279
+ --save ${checkpoint_path} \
280
+ --no-async-tensor-model-parallel-allreduce \
281
+ --tensorboard-queue-size 1 \
282
+ --log-timers-to-tensorboard \
283
+ --log-batch-size-to-tensorboard \
284
+ --log-validation-ppl-to-tensorboard \
285
+ --tensorboard-dir ${tensorboard_path}"
286
+
287
+ # test megatron activation checkpointing
288
+ # we fixed bug in the code of this activation checkpointing, i.e., --recompute-granularity full --recompute-method uniform
289
+ # the two arguments can be found in megatron/arguments.py
290
+ if [ "${activation_checkpoint}" = "true" ]; then
291
+ megatron_options="${megatron_options} \
292
+ --recompute-granularity full \
293
+ --recompute-method uniform \
294
+ --recompute-num-layers 1"
295
+ fi
296
+
297
+ if [ "${log_optimizer_state}" = "true" ]; then
298
+ megatron_options="${megatron_options} \
299
+ --log-optimizer-states-to-tensorboard"
300
+ fi
301
+
302
+ config_json="ds_config_gbs${global_batch_size}_mbs${batch_size}_log${log_interval}_zero${zero_stage}.json"
303
+ template_json="ds_config_gpt_TEMPLATE.json"
304
+ sed "s/GBSIZE/${global_batch_size}/" ${template_json} \
305
+ | sed "s/MBSIZE/${batch_size}/" \
306
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
307
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
308
+ | sed "s/PRESCALE_GRAD/${prescale_grad}/" \
309
+ > ${config_json}
310
+
311
+ deepspeed_options=" \
312
+ --pipeline-model-parallel-size ${pp_size}"
313
+
314
+ if [[ "${no_pp}" = "true" ]]; then
315
+ deepspeed_options="${deepspeed_options} \
316
+ --no-pipeline-parallel"
317
+ fi
318
+
319
+ # disable the deepspeed activation checkpointing
320
+
321
+ # if [ "${activation_checkpoint}" = "true" ]; then
322
+ # deepspeed_options="${deepspeed_options} \
323
+ # --deepspeed-activation-checkpointing"
324
+ # fi
325
+
326
+ ## When saving checkpoint to a storage with cache, their could be consistency
327
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
328
+ ## and broadcast it to all nodes.
329
+ iteration_file="$checkpoint_path/latest_checkpointed_iteration.txt"
330
+ iteration_file_2="$checkpoint_path/latest"
331
+ iteration=0
332
+ for (( node = 0; node <= num_node-1; node++ ))
333
+ do
334
+ if $(ssh -q worker-"$node" "test -f \"$iteration_file\""); then
335
+ local_iteration=$(ssh -q worker-"$node" cat $iteration_file)
336
+ iteration=$(( ${local_iteration} > ${iteration} ? ${local_iteration} : ${iteration} ))
337
+ fi
338
+ done
339
+ if [[ $iteration -gt 0 ]]; then
340
+ iteration_2="global_step${iteration}"
341
+ ds_ssh "echo $iteration > $iteration_file"
342
+ ds_ssh "echo $iteration_2 > $iteration_file_2"
343
+ fi
344
+
345
+ deepspeed ${dir}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &>> ${log_path}/${jobname}_${host}_${current_time}.log
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_pretrain_gpt_125M.sh ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ## init_std is standard deviation for weight initialization. Usually larger
13
+ ## model needs lower std. We used a heuristic equation of sqrt(1/3/hidden_size)
14
+ ## from the MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
15
+
16
+ ## We changed min_lr to a lower number (1.0e-6), which we found is able to
17
+ ## provide better zero-shot eval results.
18
+
19
+ ## GPT-3 Small 125M
20
+ model_size=0.125
21
+ num_layers=12
22
+ hidden_size=768
23
+ num_attn_heads=12
24
+ global_batch_size=256
25
+ lr=6.0e-4
26
+ min_lr=1.0e-6
27
+ init_std=0.02
28
+
29
+ ## GPT-3 Medium 350M
30
+ # model_size=0.35
31
+ # num_layers=24
32
+ # hidden_size=1024
33
+ # num_attn_heads=16
34
+ # global_batch_size=256
35
+ # lr=3.0e-4
36
+ # min_lr=1.0e-6
37
+ # init_std=0.018
38
+
39
+ ## GPT-3 Large 760M
40
+ # model_size=0.76
41
+ # num_layers=24
42
+ # hidden_size=1536
43
+ # num_attn_heads=16
44
+ # global_batch_size=256
45
+ # lr=2.5e-4
46
+ # min_lr=1.0e-6
47
+ # init_std=0.015
48
+
49
+ ## GPT-3 XL 1.3B
50
+ # model_size=1.3
51
+ # num_layers=24
52
+ # hidden_size=2048
53
+ # num_attn_heads=16
54
+ # global_batch_size=512
55
+ # lr=2.0e-4
56
+ # min_lr=1.0e-6
57
+ # init_std=0.013
58
+
59
+ ## GPT-3 2.7B
60
+ # model_size=2.7
61
+ # num_layers=32
62
+ # hidden_size=2560
63
+ # num_attn_heads=32
64
+ # global_batch_size=512
65
+ # lr=1.6e-4
66
+ # min_lr=1.0e-6
67
+ # init_std=0.011
68
+
69
+ ## GPT-3 6.7B
70
+ # model_size=6.7
71
+ # num_layers=32
72
+ # hidden_size=4096
73
+ # num_attn_heads=32
74
+ # global_batch_size=1024
75
+ # lr=1.2e-4
76
+ # min_lr=1.0e-6
77
+ # init_std=0.009
78
+
79
+ ## GPT-3 13B
80
+ # model_size=13
81
+ # num_layers=40
82
+ # hidden_size=5120
83
+ # num_attn_heads=40
84
+ # global_batch_size=1024
85
+ # lr=1.0e-4
86
+ # min_lr=1.0e-6
87
+ # init_std=0.008
88
+
89
+ ## GPT-3 175B
90
+ # model_size=175
91
+ # num_layers=96
92
+ # hidden_size=12288
93
+ # num_attn_heads=96
94
+ # global_batch_size=1536
95
+ # lr=0.6e-4
96
+ # min_lr=1.0e-6
97
+ # init_std=0.005
98
+ ###############################################################################
99
+ ### Training duration configs
100
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens.
101
+ train_tokens_in_billion=300
102
+ train_tokens=$((${train_tokens_in_billion} * 1000000000))
103
+
104
+ ## train_samples is another termination condition and also affect the number of
105
+ ## data samples to be indexed. Since we want to reach the train_tokens
106
+ ## above, and data efficiency techniques may change num tokens in some samples,
107
+ ## so we just set this config large enough to make sure we have enough
108
+ ## processed data and don't terminate by train_samples.
109
+ train_samples=$(( 300 * 1000000000 * 2 / ${seq_len} ))
110
+
111
+ ## Another wall-clock time termination condition in minutes. Set it large
112
+ ## enough to avoid undesired early termination.
113
+ exit_duration=30000000
114
+ ###############################################################################
115
+ ### lr configs
116
+ ## lr warmup and decay duration.
117
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B cosine decay tokens.
118
+ ## Here we increase the warmup tokens to 3B since when batch size warmup is not
119
+ ## used, there are more tokens per step. Thus we need to increase warmup tokens
120
+ ## to make sure there are enough warmup steps, which is important for training
121
+ ## stability.
122
+ lr_warmup_tokens_in_million=3000
123
+ lr_warmup_tokens=$((${lr_warmup_tokens_in_million} * 1000000))
124
+ ## Here we changed the LR decay tokens to align with total train tokens, since
125
+ ## related works (e.g., https://arxiv.org/abs/2203.15556) find that setting the
126
+ ## learning rate schedule to match the number of training tokens results in the
127
+ ## best final model quality
128
+ lr_decay_tokens_in_billion=${train_tokens_in_billion}
129
+ lr_decay_tokens=$((${lr_decay_tokens_in_billion} * 1000000000))
130
+ lr_decay_style="cosine"
131
+ ###############################################################################
132
+ ### Parallelism configs
133
+ ## Model parallelism, 1 is no MP
134
+ mp_size=2
135
+
136
+ ## Pipeline parallelism. To disable PP, set pp_size to 1 and no_pp to true.
137
+ ## Note that currently both curriculum learning and random-LTD are NOT
138
+ ## compatible with pipeline parallelism.
139
+ pp_size=2
140
+ no_pp="false"
141
+
142
+ ## ZeRO-based data parallelism, stage=0 will disable ZeRO
143
+ zero_stage=1
144
+
145
+ ## Total number of GPUs. ds_ssh is from DeepSpeed library.
146
+ num_gpus=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
147
+ num_gpus_pernode=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
148
+ num_node=$(( ${num_gpus} / ${num_gpus_pernode} ))
149
+
150
+ ## Data parallel size.
151
+ dp_size=$(( ${num_gpus} / ${pp_size} / ${mp_size} ))
152
+
153
+ ## Micro batch size per GPU
154
+ ## Make sure that batch_size <= global_batch_size*pp_size*mp_size/num_gpus
155
+ ## Reduce it manually if GPU OOM
156
+ # batch_size=$(( ${global_batch_size} / ${dp_size} ))
157
+ batch_size=2
158
+ ###############################################################################
159
+ ### Misc configs
160
+ log_interval=10
161
+ eval_iters=10
162
+ eval_interval=100
163
+ # num_save controls how frequent to save checkpoint. num_save=20 means that a
164
+ # checkpoint will be saved every 5% of training. For longer training you would
165
+ # want larger num_save to save more frequently, and vice versa.
166
+ num_save=100
167
+ estimated_train_iter=$((${train_tokens} / ${seq_len} / ${global_batch_size}))
168
+ # save_interval=$((${estimated_train_iter} / ${num_save}))
169
+ save_interval=100
170
+
171
+ ## Activation checkpointing saves GPU memory, but reduces training speed
172
+ activation_checkpoint="true"
173
+ # activation_checkpoint="false"
174
+
175
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
176
+ ## This is not required for training and might save GPU memory when turned off.
177
+ log_optimizer_state="true"
178
+ ###############################################################################
179
+ ### Output and data configs
180
+ current_time=$(date "+%Y.%m.%d_%H.%M.%S")
181
+ host="${HOSTNAME}"
182
+ seed=1234
183
+ num_workers=0
184
+
185
+ data_path="BookCorpusDataset_text_document"
186
+ if [ ! -f "BookCorpusDataset_text_document.bin" ]; then
187
+ wget https://the-eye.eu/public/AI/pile_neox/data/BookCorpusDataset_text_document.bin
188
+ fi
189
+ if [ ! -f "BookCorpusDataset_text_document.idx" ]; then
190
+ wget https://the-eye.eu/public/AI/pile_neox/data/BookCorpusDataset_text_document.idx
191
+ fi
192
+
193
+ vocab_path="gpt2-vocab.json"
194
+ if [ ! -f "$vocab_path" ]; then
195
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json
196
+ fi
197
+ merge_path="gpt2-merges.txt"
198
+ if [ ! -f "$merge_path" ]; then
199
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt
200
+ fi
201
+
202
+ prescale_grad="true"
203
+ jobname="gpt_${model_size}B_tok${train_tokens_in_billion}B"
204
+ jobname="${jobname}_lr${lr}_min${min_lr}_w${lr_warmup_tokens_in_million}M_d${lr_decay_tokens_in_billion}B_${lr_decay_style}"
205
+ jobname="${jobname}_gbs${global_batch_size}_mbs${batch_size}_g${num_gpus}"
206
+ if [[ $zero_stage -gt 0 ]]; then
207
+ jobname="${jobname}_z${zero_stage}"
208
+ prescale_grad="false"
209
+ fi
210
+ if [[ $mp_size -gt 1 ]]; then
211
+ jobname="${jobname}_mp${mp_size}"
212
+ fi
213
+ if [ "${no_pp}" = "false" ]; then
214
+ jobname="${jobname}_pp${pp_size}"
215
+ fi
216
+ jobname="${jobname}_seed${seed}_rebase"
217
+
218
+ username=$(whoami)
219
+ output_home="output"
220
+ log_path="${output_home}/log/"
221
+ checkpoint_path="${output_home}/checkpoint/${jobname}"
222
+ tensorboard_dir="${output_home}/tensorboard/"
223
+ tensorboard_path="${tensorboard_dir}${jobname}_${host}_${current_time}"
224
+ mkdir -p ${log_path}
225
+ mkdir -p ${checkpoint_path}
226
+ mkdir -p ${tensorboard_path}
227
+ ###############################################################################
228
+ data_options=" \
229
+ --vocab-file ${vocab_path} \
230
+ --merge-file ${merge_path} \
231
+ --data-path ${data_path} \
232
+ --data-impl mmap"
233
+
234
+ ## If CL is used, make sure to set "--split" the same as what you used during
235
+ ## offline data analysis&indexing.
236
+ megatron_options=" \
237
+ --override-opt_param-scheduler \
238
+ --adam-beta1 0.9 \
239
+ --adam-beta2 0.95 \
240
+ --tensor-model-parallel-size ${mp_size} \
241
+ --init-method-std ${init_std} \
242
+ --lr-decay-tokens ${lr_decay_tokens} \
243
+ --lr-warmup-tokens ${lr_warmup_tokens} \
244
+ --micro-batch-size ${batch_size} \
245
+ --exit-duration-in-mins ${exit_duration} \
246
+ --global-batch-size ${global_batch_size} \
247
+ --num-layers ${num_layers} \
248
+ --hidden-size ${hidden_size} \
249
+ --num-attention-heads ${num_attn_heads} \
250
+ --seq-length ${seq_len} \
251
+ --max-position-embeddings ${seq_len} \
252
+ --train-tokens ${train_tokens} \
253
+ --train-samples ${train_samples} \
254
+ --lr ${lr} \
255
+ --min-lr ${min_lr} \
256
+ --lr-decay-style ${lr_decay_style} \
257
+ --split 949,50,1 \
258
+ --log-interval ${log_interval} \
259
+ --eval-interval ${eval_interval} \
260
+ --eval-iters ${eval_iters} \
261
+ --save-interval ${save_interval} \
262
+ --weight-decay 0.1 \
263
+ --clip-grad 1.0 \
264
+ --hysteresis 2 \
265
+ --num-workers ${num_workers} \
266
+ --fp16 \
267
+ --seed ${seed} \
268
+ --load ${checkpoint_path} \
269
+ --save ${checkpoint_path} \
270
+ --no-async-tensor-model-parallel-allreduce \
271
+ --tensorboard-queue-size 1 \
272
+ --log-timers-to-tensorboard \
273
+ --log-batch-size-to-tensorboard \
274
+ --log-validation-ppl-to-tensorboard \
275
+ --tensorboard-dir ${tensorboard_path}"
276
+
277
+ if [ "${activation_checkpoint}" = "true" ]; then
278
+ megatron_options="${megatron_options} \
279
+ --checkpoint-activations"
280
+ fi
281
+
282
+ if [ "${log_optimizer_state}" = "true" ]; then
283
+ megatron_options="${megatron_options} \
284
+ --log-optimizer-states-to-tensorboard"
285
+ fi
286
+
287
+ config_json="ds_config_gbs${global_batch_size}_mbs${batch_size}_log${log_interval}_zero${zero_stage}.json"
288
+ template_json="ds_config_gpt_TEMPLATE.json"
289
+ sed "s/GBSIZE/${global_batch_size}/" ${template_json} \
290
+ | sed "s/MBSIZE/${batch_size}/" \
291
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
292
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
293
+ | sed "s/PRESCALE_GRAD/${prescale_grad}/" \
294
+ > ${config_json}
295
+
296
+ deepspeed_options=" \
297
+ --deepspeed \
298
+ --deepspeed_config ${config_json} \
299
+ --zero-stage ${zero_stage} \
300
+ --pipeline-model-parallel-size ${pp_size}"
301
+
302
+ if [[ "${no_pp}" = "true" ]]; then
303
+ deepspeed_options="${deepspeed_options} \
304
+ --no-pipeline-parallel"
305
+ fi
306
+
307
+ if [ "${activation_checkpoint}" = "true" ]; then
308
+ deepspeed_options="${deepspeed_options} \
309
+ --deepspeed-activation-checkpointing"
310
+ fi
311
+
312
+ ## When saving checkpoint to a storage with cache, their could be consistency
313
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
314
+ ## and broadcast it to all nodes.
315
+ iteration_file="$checkpoint_path/latest_checkpointed_iteration.txt"
316
+ iteration_file_2="$checkpoint_path/latest"
317
+ iteration=0
318
+ for (( node = 0; node <= num_node-1; node++ ))
319
+ do
320
+ if $(ssh -q worker-"$node" "test -f \"$iteration_file\""); then
321
+ local_iteration=$(ssh -q worker-"$node" cat $iteration_file)
322
+ iteration=$(( ${local_iteration} > ${iteration} ? ${local_iteration} : ${iteration} ))
323
+ fi
324
+ done
325
+ if [[ $iteration -gt 0 ]]; then
326
+ iteration_2="global_step${iteration}"
327
+ ds_ssh "echo $iteration > $iteration_file"
328
+ ds_ssh "echo $iteration_2 > $iteration_file_2"
329
+ fi
330
+
331
+ deepspeed ${dir}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &>> ${log_path}/${jobname}_${host}_${current_time}.log
docker/intel_code/llama13b/Megatron-DeepSpeed/examples_deepspeed/rebase/ds_pretrain_gpt_13B.sh ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ## init_std is standard deviation for weight initialization. Usually larger
13
+ ## model needs lower std. We used a heuristic equation of sqrt(1/3/hidden_size)
14
+ ## from the MT-NLG 530B work (https://arxiv.org/pdf/2201.11990.pdf)
15
+
16
+ ## We changed min_lr to a lower number (1.0e-6), which we found is able to
17
+ ## provide better zero-shot eval results.
18
+
19
+ ## GPT-3 Small 125M
20
+ # model_size=0.125
21
+ # num_layers=12
22
+ # hidden_size=768
23
+ # num_attn_heads=12
24
+ # global_batch_size=256
25
+ # lr=6.0e-4
26
+ # min_lr=1.0e-6
27
+ # init_std=0.02
28
+
29
+ ## GPT-3 Medium 350M
30
+ # model_size=0.35
31
+ # num_layers=24
32
+ # hidden_size=1024
33
+ # num_attn_heads=16
34
+ # global_batch_size=256
35
+ # lr=3.0e-4
36
+ # min_lr=1.0e-6
37
+ # init_std=0.018
38
+
39
+ ## GPT-3 Large 760M
40
+ # model_size=0.76
41
+ # num_layers=24
42
+ # hidden_size=1536
43
+ # num_attn_heads=16
44
+ # global_batch_size=256
45
+ # lr=2.5e-4
46
+ # min_lr=1.0e-6
47
+ # init_std=0.015
48
+
49
+ ## GPT-3 XL 1.3B
50
+ # model_size=1.3
51
+ # num_layers=24
52
+ # hidden_size=2048
53
+ # num_attn_heads=16
54
+ # global_batch_size=512
55
+ # lr=2.0e-4
56
+ # min_lr=1.0e-6
57
+ # init_std=0.013
58
+
59
+ ## GPT-3 2.7B
60
+ # model_size=2.7
61
+ # num_layers=32
62
+ # hidden_size=2560
63
+ # num_attn_heads=32
64
+ # global_batch_size=512
65
+ # lr=1.6e-4
66
+ # min_lr=1.0e-6
67
+ # init_std=0.011
68
+
69
+ ## GPT-3 6.7B
70
+ # model_size=6.7
71
+ # num_layers=32
72
+ # hidden_size=4096
73
+ # num_attn_heads=32
74
+ # global_batch_size=1024
75
+ # lr=1.2e-4
76
+ # min_lr=1.0e-6
77
+ # init_std=0.009
78
+
79
+ ## GPT-3 13B
80
+ model_size=13
81
+ num_layers=40
82
+ hidden_size=5120
83
+ num_attn_heads=40
84
+ global_batch_size=1024
85
+ lr=1.0e-4
86
+ min_lr=1.0e-6
87
+ init_std=0.008
88
+
89
+ ## GPT-3 175B
90
+ # model_size=175
91
+ # num_layers=96
92
+ # hidden_size=12288
93
+ # num_attn_heads=96
94
+ # global_batch_size=1536
95
+ # lr=0.6e-4
96
+ # min_lr=1.0e-6
97
+ # init_std=0.005
98
+ ###############################################################################
99
+ ### Training duration configs
100
+ ## The main termination condition, original GPT-3 paper trains for 300B tokens.
101
+ train_tokens_in_billion=300
102
+ train_tokens=$((${train_tokens_in_billion} * 1000000000))
103
+
104
+ ## train_samples is another termination condition and also affect the number of
105
+ ## data samples to be indexed. Since we want to reach the train_tokens
106
+ ## above, and data efficiency techniques may change num tokens in some samples,
107
+ ## so we just set this config large enough to make sure we have enough
108
+ ## processed data and don't terminate by train_samples.
109
+ train_samples=$(( 300 * 1000000000 * 2 / ${seq_len} ))
110
+
111
+ ## Another wall-clock time termination condition in minutes. Set it large
112
+ ## enough to avoid undesired early termination.
113
+ exit_duration=30000000
114
+ ###############################################################################
115
+ ### lr configs
116
+ ## lr warmup and decay duration.
117
+ ## Original GPT-3 paper uses 375M warmup tokens and 260B cosine decay tokens.
118
+ ## Here we increase the warmup tokens to 3B since when batch size warmup is not
119
+ ## used, there are more tokens per step. Thus we need to increase warmup tokens
120
+ ## to make sure there are enough warmup steps, which is important for training
121
+ ## stability.
122
+ lr_warmup_tokens_in_million=3000
123
+ lr_warmup_tokens=$((${lr_warmup_tokens_in_million} * 1000000))
124
+ ## Here we changed the LR decay tokens to align with total train tokens, since
125
+ ## related works (e.g., https://arxiv.org/abs/2203.15556) find that setting the
126
+ ## learning rate schedule to match the number of training tokens results in the
127
+ ## best final model quality
128
+ lr_decay_tokens_in_billion=${train_tokens_in_billion}
129
+ lr_decay_tokens=$((${lr_decay_tokens_in_billion} * 1000000000))
130
+ lr_decay_style="cosine"
131
+ ###############################################################################
132
+ ### Parallelism configs
133
+ ## Model parallelism, 1 is no MP
134
+ mp_size=4
135
+
136
+ ## Pipeline parallelism. To disable PP, set pp_size to 1 and no_pp to true.
137
+ ## Note that currently both curriculum learning and random-LTD are NOT
138
+ ## compatible with pipeline parallelism.
139
+ pp_size=8
140
+ no_pp="false"
141
+
142
+ ## ZeRO-based data parallelism, stage=0 will disable ZeRO
143
+ zero_stage=1
144
+
145
+ ## Total number of GPUs. ds_ssh is from DeepSpeed library.
146
+ num_gpus=$(($(ds_ssh nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)-2))
147
+ num_gpus_pernode=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
148
+ num_node=$(( ${num_gpus} / ${num_gpus_pernode} ))
149
+
150
+ ## Data parallel size.
151
+ dp_size=$(( ${num_gpus} / ${pp_size} / ${mp_size} ))
152
+
153
+ ## Micro batch size per GPU
154
+ ## Make sure that batch_size <= global_batch_size*pp_size*mp_size/num_gpus
155
+ ## Reduce it manually if GPU OOM
156
+ # batch_size=$(( ${global_batch_size} / ${dp_size} ))
157
+ batch_size=2
158
+ ###############################################################################
159
+ ### Misc configs
160
+ log_interval=10
161
+ eval_iters=10
162
+ eval_interval=100
163
+ # num_save controls how frequent to save checkpoint. num_save=20 means that a
164
+ # checkpoint will be saved every 5% of training. For longer training you would
165
+ # want larger num_save to save more frequently, and vice versa.
166
+ num_save=100
167
+ estimated_train_iter=$((${train_tokens} / ${seq_len} / ${global_batch_size}))
168
+ # save_interval=$((${estimated_train_iter} / ${num_save}))
169
+ save_interval=100
170
+
171
+ ## Activation checkpointing saves GPU memory, but reduces training speed
172
+ activation_checkpoint="true"
173
+ # activation_checkpoint="false"
174
+
175
+ ## Whether or not log optimizer states (norms, max abs values) to tensorboard.
176
+ ## This is not required for training and might save GPU memory when turned off.
177
+ log_optimizer_state="true"
178
+ ###############################################################################
179
+ ### Output and data configs
180
+ current_time=$(date "+%Y.%m.%d_%H.%M.%S")
181
+ host="${HOSTNAME}"
182
+ seed=1234
183
+ num_workers=0
184
+
185
+ ## Public the Pile dataset, can be downloaded at
186
+ ## https://mystic.the-eye.eu/public/AI/pile_neox/ or
187
+ ## https://the-eye.eu/public/AI/pile_neox/ Change data_home to where you
188
+ ## store the pile_text_document.bin and pile_text_document.idx.
189
+ data_home="/vc_data_blob/users/conglli/the_pile_public_merged_nopreprocessing"
190
+ data_path="${data_home}/pile_text_document"
191
+
192
+ vocab_path="gpt2-vocab.json"
193
+ if [ ! -f "$vocab_path" ]; then
194
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json
195
+ fi
196
+ merge_path="gpt2-merges.txt"
197
+ if [ ! -f "$merge_path" ]; then
198
+ wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt
199
+ fi
200
+
201
+ prescale_grad="true"
202
+ jobname="gpt_${model_size}B_tok${train_tokens_in_billion}B"
203
+ jobname="${jobname}_lr${lr}_min${min_lr}_w${lr_warmup_tokens_in_million}M_d${lr_decay_tokens_in_billion}B_${lr_decay_style}"
204
+ jobname="${jobname}_gbs${global_batch_size}_mbs${batch_size}_g${num_gpus}"
205
+ if [[ $zero_stage -gt 0 ]]; then
206
+ jobname="${jobname}_z${zero_stage}"
207
+ prescale_grad="false"
208
+ fi
209
+ if [[ $mp_size -gt 1 ]]; then
210
+ jobname="${jobname}_mp${mp_size}"
211
+ fi
212
+ if [ "${no_pp}" = "false" ]; then
213
+ jobname="${jobname}_pp${pp_size}"
214
+ fi
215
+ jobname="${jobname}_seed${seed}_rebase"
216
+
217
+ username=$(whoami)
218
+ output_home="/blob/users/${username}/project/data_efficient_gpt"
219
+ log_path="${output_home}/log/"
220
+ checkpoint_path="${output_home}/checkpoint/${jobname}"
221
+ ## Microsoft internal constraint: because tensorboard is logged by last rank,
222
+ ## it's better to put the path in NFS instead of Blob.
223
+ tensorboard_dir="/vc_data/users/${username}/project/data_efficient_gpt/tensorboard/"
224
+ tensorboard_path="${tensorboard_dir}${jobname}_${host}_${current_time}"
225
+ mkdir -p ${log_path}
226
+ mkdir -p ${checkpoint_path}
227
+ mkdir -p ${tensorboard_path}
228
+ ###############################################################################
229
+ data_options=" \
230
+ --vocab-file ${vocab_path} \
231
+ --merge-file ${merge_path} \
232
+ --data-path ${data_path} \
233
+ --data-impl mmap"
234
+
235
+ ## If CL is used, make sure to set "--split" the same as what you used during
236
+ ## offline data analysis&indexing.
237
+ megatron_options=" \
238
+ --override-opt_param-scheduler \
239
+ --adam-beta1 0.9 \
240
+ --adam-beta2 0.95 \
241
+ --tensor-model-parallel-size ${mp_size} \
242
+ --init-method-std ${init_std} \
243
+ --lr-decay-tokens ${lr_decay_tokens} \
244
+ --lr-warmup-tokens ${lr_warmup_tokens} \
245
+ --micro-batch-size ${batch_size} \
246
+ --exit-duration-in-mins ${exit_duration} \
247
+ --global-batch-size ${global_batch_size} \
248
+ --num-layers ${num_layers} \
249
+ --hidden-size ${hidden_size} \
250
+ --num-attention-heads ${num_attn_heads} \
251
+ --seq-length ${seq_len} \
252
+ --max-position-embeddings ${seq_len} \
253
+ --train-tokens ${train_tokens} \
254
+ --train-samples ${train_samples} \
255
+ --lr ${lr} \
256
+ --min-lr ${min_lr} \
257
+ --lr-decay-style ${lr_decay_style} \
258
+ --split 949,50,1 \
259
+ --log-interval ${log_interval} \
260
+ --eval-interval ${eval_interval} \
261
+ --eval-iters ${eval_iters} \
262
+ --save-interval ${save_interval} \
263
+ --weight-decay 0.1 \
264
+ --clip-grad 1.0 \
265
+ --hysteresis 2 \
266
+ --num-workers ${num_workers} \
267
+ --fp16 \
268
+ --seed ${seed} \
269
+ --load ${checkpoint_path} \
270
+ --save ${checkpoint_path} \
271
+ --no-async-tensor-model-parallel-allreduce \
272
+ --tensorboard-queue-size 1 \
273
+ --log-timers-to-tensorboard \
274
+ --log-batch-size-to-tensorboard \
275
+ --log-validation-ppl-to-tensorboard \
276
+ --tensorboard-dir ${tensorboard_path}"
277
+
278
+ if [ "${activation_checkpoint}" = "true" ]; then
279
+ megatron_options="${megatron_options} \
280
+ --checkpoint-activations"
281
+ fi
282
+
283
+ if [ "${log_optimizer_state}" = "true" ]; then
284
+ megatron_options="${megatron_options} \
285
+ --log-optimizer-states-to-tensorboard"
286
+ fi
287
+
288
+ config_json="ds_config_gbs${global_batch_size}_mbs${batch_size}_log${log_interval}_zero${zero_stage}.json"
289
+ template_json="ds_config_gpt_TEMPLATE.json"
290
+ sed "s/GBSIZE/${global_batch_size}/" ${template_json} \
291
+ | sed "s/MBSIZE/${batch_size}/" \
292
+ | sed "s/LOG_INTERVAL/${log_interval}/" \
293
+ | sed "s/ZERO_STAGE/${zero_stage}/" \
294
+ | sed "s/PRESCALE_GRAD/${prescale_grad}/" \
295
+ > ${config_json}
296
+
297
+ deepspeed_options=" \
298
+ --deepspeed \
299
+ --deepspeed_config ${config_json} \
300
+ --zero-stage ${zero_stage} \
301
+ --pipeline-model-parallel-size ${pp_size}"
302
+
303
+ if [[ "${no_pp}" = "true" ]]; then
304
+ deepspeed_options="${deepspeed_options} \
305
+ --no-pipeline-parallel"
306
+ fi
307
+
308
+ if [ "${activation_checkpoint}" = "true" ]; then
309
+ deepspeed_options="${deepspeed_options} \
310
+ --deepspeed-activation-checkpointing"
311
+ fi
312
+
313
+ ## When saving checkpoint to a storage with cache, their could be consistency
314
+ ## issue of the pointer to latest checkpoint. Here we find the correct pointer
315
+ ## and broadcast it to all nodes.
316
+ iteration_file="$checkpoint_path/latest_checkpointed_iteration.txt"
317
+ iteration_file_2="$checkpoint_path/latest"
318
+ iteration=0
319
+ for (( node = 0; node <= num_node-1; node++ ))
320
+ do
321
+ if $(ssh -q worker-"$node" "test -f \"$iteration_file\""); then
322
+ local_iteration=$(ssh -q worker-"$node" cat $iteration_file)
323
+ iteration=$(( ${local_iteration} > ${iteration} ? ${local_iteration} : ${iteration} ))
324
+ fi
325
+ done
326
+ if [[ $iteration -gt 0 ]]; then
327
+ iteration_2="global_step${iteration}"
328
+ ds_ssh "echo $iteration > $iteration_file"
329
+ ds_ssh "echo $iteration_2 > $iteration_file_2"
330
+ fi
331
+
332
+ deepspeed ${dir}/../../pretrain_gpt.py ${megatron_options} ${data_options} ${deepspeed_options} &>> ${log_path}/${jobname}_${host}_${current_time}.log
docker/intel_code/llama13b/Megatron-DeepSpeed/images/Achieved_petaFLOPs.png ADDED

Git LFS Details

  • SHA256: 3856991d81046b3da4af85b5fce7f0a61ed3f2b643358b8366c9bd22534ae85c
  • Pointer size: 131 Bytes
  • Size of remote file: 229 kB
docker/intel_code/llama13b/Megatron-DeepSpeed/images/cases_april2021.png ADDED

Git LFS Details

  • SHA256: 6785b9aedc153052dd91f29ce806893326a64382591ebf6d74f0fe63c3b78250
  • Pointer size: 131 Bytes
  • Size of remote file: 163 kB
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (677 Bytes). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/bert_model.cpython-310.pyc ADDED
Binary file (6.41 kB). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/distributed.cpython-310.pyc ADDED
Binary file (6.98 kB). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/enums.cpython-310.pyc ADDED
Binary file (842 Bytes). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/fused_bias_gelu.cpython-310.pyc ADDED
Binary file (1.29 kB). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/fused_layer_norm.cpython-310.pyc ADDED
Binary file (3.05 kB). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/fused_softmax.cpython-310.pyc ADDED
Binary file (5.67 kB). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/gpt_model.cpython-310.pyc ADDED
Binary file (10.3 kB). View file
 
docker/intel_code/llama13b/Megatron-DeepSpeed/megatron/model/__pycache__/language_model.cpython-310.pyc ADDED
Binary file (15.5 kB). View file