Llama_pretraining.sh 5.16 KB
Newer Older
wxj's avatar
wxj committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
set -eux

#export FLASH_ATTENTION_PRINT_PARAM=1
# Runs the "7B" parameter model
export HSA_FORCE_FINE_GRAIN_PCIE=1
export OMP_NUM_THREADS=1
export NCCL_P2P_LEVEL=PXB # SYS

#export HIP_ALLOC_INITIALIZE=0
#export GPU_MAX_HW_QUEUES=20

export NCCL_ALGO=Ring
export NCCL_NCHANNELS_PER_PEER=16
export NCCL_MIN_NCHANNELS=20
export NCCL_IB_TIMEOUT=22
export CUDA_DEVICE_MAX_CONNECTIONS=1

export NCCL_IB_HCA=mlx5_1,mlx5_2
export NCCL_NET_GDR_LEVEL=SYS
export NCCL_NET_GDR_READ=0
wxj's avatar
wxj committed
22
export GLOG_minloglevel=3 # 打印error级别的nccl日志
wxj's avatar
wxj committed
23
24
25
source /opt/dtk/env.sh
# te调用gemm需要导入hipblaslt库
# export LD_LIBRARY_PATH=/data/hipblaslt-install-0904/lib:$LD_LIBRARY_PATH 
wxj's avatar
wxj committed
26
27
28
29
30
31
# 更新rocblas
export LD_LIBRARY_PATH=/data/rocblas-install/lib:$LD_LIBRARY_PATH

# # prof采集添加同步
# export GPU_FLUSH_ON_EXECUTION=1
# export HIP_DIRECT_DISPATCH=0
wxj's avatar
wxj committed
32
33
34

CHECKPOINT_PATH=./tmp_7b #$1 #<Specify path>
TENSORBOARD_LOGS_PATH=./tmp_7b  #$2 #<Specify path>
silencealiang's avatar
silencealiang committed
35
DATA_PATH="/public/home/wangxj3/Downloads/datasets/nemo_pretrain/oscar-1GB/oscar-1GB-llama_text_document" #<Specify path and file prefix>_text_document
wxj's avatar
wxj committed
36
37
38
39
40
41
42
43
44
45
46

# GPT_MODEL_ARGS=(
#     --num-layers 32
#     --hidden-size 5120
#     --ffn-hidden-size 13824
#     --num-attention-heads 40
#     --seq-length 4096 #4096
#     --max-position-embeddings 32768 #4096
#     --num-query-groups 40
#     --group-query-attention
# )
wxj's avatar
wxj committed
47
48

GPT_MODEL_ARGS=(
wxj's avatar
wxj committed
49
    --num-layers 6
wxj's avatar
wxj committed
50
51
52
    --hidden-size 4096
    --ffn-hidden-size 11008 
    --num-attention-heads 32
wxj's avatar
wxj committed
53
    --seq-length 4096 #4096
wxj's avatar
wxj committed
54
    --max-position-embeddings 4096
wxj's avatar
wxj committed
55
56
)

wxj's avatar
wxj committed
57
58
# export NVTE_FLASH_ATTN=1 # 走cutlass
export NVTE_FLASH_ATTN_TRITON=1 # 走triton_fa
wxj's avatar
wxj committed
59
60
# --transformer-impl transformer_engine
    # --use-mcore-models
wxj's avatar
wxj committed
61
62
    # --transformer-impl local
    # --use-legacy-models 
wxj's avatar
wxj committed
63
TRAINING_ARGS=(
wxj's avatar
wxj committed
64
65
    --transformer-impl transformer_engine
    --use-mcore-models
wxj's avatar
wxj committed
66
    --micro-batch-size 1 
wxj's avatar
wxj committed
67
68
    --global-batch-size 6 #240 #60 #512 #64
    --train-iters 10
wxj's avatar
wxj committed
69
70
71
72
73
74
75
76
77
78
79
    --weight-decay 0.1 
    --adam-beta1 0.9 
    --adam-beta2 0.95 
    --init-method-std 0.006 
    --clip-grad 1.0 
    --bf16
    --use-distributed-optimizer 
    --disable-bias-linear
    --attention-dropout 0
    --hidden-dropout 0
    --no-gradient-accumulation-fusion
wxj's avatar
wxj committed
80
    --add-qkv-bias
wxj's avatar
wxj committed
81
82
83
84
85
    --swiglu
    --lr 3.0e-5 
    --lr-decay-style cosine 
    --min-lr 3.0e-6
    --lr-warmup-iters 1
wxj's avatar
wxj committed
86
87
88
89
90
91
    --ckpt-format torch
    --ddp-average-in-collective
    --recompute-granularity full
    --recompute-num-layers 5 #0 #
    --recompute-method block
    --overlap-grad-reduce
wxj's avatar
wxj committed
92
    --use-flash-attn-triton
wxj's avatar
wxj committed
93
)
wxj's avatar
wxj committed
94
95
96
97
98
99
100
101
# --add-qkv-bias # qwen
# --ckpt-format torch
#     --ddp-average-in-collective
#     --recompute-granularity full
#     --recompute-num-layers 5
#     --recompute-method block
#     --overlap-grad-reduce
# --use-flash-attn-cutlass
wxj's avatar
wxj committed
102
# --use-flash-attn-triton
wxj's avatar
wxj committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

MODEL_PARALLEL_ARGS=(
    --sequence-parallel
	--tensor-model-parallel-size 2
	--pipeline-model-parallel-size 2
)

DATA_ARGS=(
    --data-path $DATA_PATH 
    --split 949,50,1
    --untie-embeddings-and-output-weights
    --use-rotary-position-embeddings 
    --normalization RMSNorm 
    --no-position-embedding 
    --tokenizer-type Llama2Tokenizer
silencealiang's avatar
silencealiang committed
118
    --tokenizer-model /public/home/wangxj3/Downloads/model_weights/llama2_7b_hf/tokenizer.model
wxj's avatar
wxj committed
119
120
121
122
123
124
125
126
127
128
129
130
131
)

EVAL_AND_LOGGING_ARGS=(
    --log-interval 1
    --log-throughput
    --save-interval 1000 
    --eval-interval 1000 
    --save $CHECKPOINT_PATH 
    --load $CHECKPOINT_PATH 
    --eval-iters 10
    --tensorboard-dir $TENSORBOARD_LOGS_PATH 
)

wxj's avatar
wxj committed
132
133
134
135
136
137
138
139
140
PROFILE_ARGS=(
    --profile
    --profile-step-start 4
    --profile-step-end 5
    --use-pytorch-profiler
    --profile-ranks 0 3
    --profile-dir prof_data
)

wxj's avatar
wxj committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
RANK=$OMPI_COMM_WORLD_RANK
LOCAL_RANK=$OMPI_COMM_WORLD_LOCAL_RANK
WORLD_SIZE=$OMPI_COMM_WORLD_SIZE
DIST_URL=${1}
DIST_PORT=34566

DISTRIBUTED_ARGS=(
    --rank ${RANK}
    --world-size ${WORLD_SIZE}
    --local-rank ${LOCAL_RANK}
    --dist-url tcp://${DIST_URL}:${DIST_PORT}
)

APP="python -u pretrain_gpt.py \
        ${GPT_MODEL_ARGS[@]} \
        ${TRAINING_ARGS[@]} \
        ${MODEL_PARALLEL_ARGS[@]} \
        ${DATA_ARGS[@]} \
        ${EVAL_AND_LOGGING_ARGS[@]} \
        ${DISTRIBUTED_ARGS[@]} \
wxj's avatar
wxj committed
161
        ${PROFILE_ARGS[@]} \
wxj's avatar
wxj committed
162
163
"

wxj's avatar
wxj committed
164
165
166
export HIP_VISIBLE_DEVICES=4,5,6,7 # 0,1,2,3 # 4,5,6,7 #,
# export CUDA_VISIBLE_DEVICES=4,5,6,7 # 0,1,2,3,
# ${APP}
wxj's avatar
wxj committed
167
168
case ${LOCAL_RANK} in
[0])
wxj's avatar
wxj committed
169
170
171
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
  ${APP}
  # numactl --cpunodebind=0 --membind=0 ${APP}
wxj's avatar
wxj committed
172
173
  ;;
[1])
wxj's avatar
wxj committed
174
175
176
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
  ${APP}
  # numactl --cpunodebind=0 --membind=0 ${APP}
wxj's avatar
wxj committed
177
178
  ;;
[2])
wxj's avatar
wxj committed
179
180
181
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
  ${APP}
  # numactl --cpunodebind=0 --membind=0 ${APP}
wxj's avatar
wxj committed
182
183
  ;;
[3])
wxj's avatar
wxj committed
184
185
186
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
  ${APP}
  # numactl --cpunodebind=0 --membind=0 ${APP}
wxj's avatar
wxj committed
187
  ;;
wxj's avatar
wxj committed
188
189
# [4])
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
wxj's avatar
wxj committed
190
#   ${APP}
wxj's avatar
wxj committed
191
192
193
194
#   # numactl --cpunodebind=0 --membind=0 ${APP}
#   ;;
# [5])
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
wxj's avatar
wxj committed
195
#   ${APP}
wxj's avatar
wxj committed
196
197
198
199
#   # numactl --cpunodebind=0 --membind=0 ${APP}
#   ;;
# [6])
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
wxj's avatar
wxj committed
200
#   ${APP}
wxj's avatar
wxj committed
201
202
203
204
#   # numactl --cpunodebind=0 --membind=0 ${APP}
#   ;;
# [7])
#   export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
wxj's avatar
wxj committed
205
#   ${APP}
wxj's avatar
wxj committed
206
207
#   # numactl --cpunodebind=0 --membind=0 ${APP}
#   ;;
wxj's avatar
wxj committed
208
esac