Llama_pretraining.sh 3.95 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
22
23
24
25
26
27
#!/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
source /opt/dtk/env.sh
# te调用gemm需要导入hipblaslt库
# export LD_LIBRARY_PATH=/data/hipblaslt-install-0904/lib:$LD_LIBRARY_PATH 

CHECKPOINT_PATH=./tmp_7b #$1 #<Specify path>
TENSORBOARD_LOGS_PATH=./tmp_7b  #$2 #<Specify path>
wxj's avatar
wxj committed
28
DATA_PATH="/datasets/oscar-1GB-llama_text_document" #<Specify path and file prefix>_text_document
wxj's avatar
wxj committed
29
30

GPT_MODEL_ARGS=(
wxj's avatar
wxj committed
31
32
33
34
    --num-layers 36
    --hidden-size 4096
    --ffn-hidden-size 11008 
    --num-attention-heads 32
wxj's avatar
wxj committed
35
    --seq-length 4096 #4096
wxj's avatar
wxj committed
36
    --max-position-embeddings 4096
wxj's avatar
wxj committed
37
38
39
40
41
42
)

# export NVTE_FLASH_ATTN=1 # 走autlass
# export NVTE_FLASH_ATTN_TRITON=1 # 走triton_fa
# --transformer-impl transformer_engine
    # --use-mcore-models
wxj's avatar
wxj committed
43
    
wxj's avatar
wxj committed
44
TRAINING_ARGS=(
wxj's avatar
wxj committed
45
46
    --transformer-impl local
    --use-legacy-models 
wxj's avatar
wxj committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    --micro-batch-size 1 
    --global-batch-size 60 #240 #512 #64
    --train-iters 100
    --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 
    --ckpt-format torch
    --disable-bias-linear
    --overlap-grad-reduce
    --attention-dropout 0
    --hidden-dropout 0
    --ddp-average-in-collective
    --recompute-granularity full
    --recompute-num-layers 5
    --recompute-method block
    --no-gradient-accumulation-fusion
    --swiglu
    --lr 3.0e-5 
    --lr-decay-style cosine 
    --min-lr 3.0e-6
    --lr-warmup-iters 1
wxj's avatar
wxj committed
72
    --use-flash-attn-triton
wxj's avatar
wxj committed
73
)
wxj's avatar
wxj committed
74
75
# --use-flash-attn-ck
# --use-flash-attn-triton
wxj's avatar
wxj committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

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
wxj's avatar
wxj committed
91
    --tokenizer-model /path/to/llama2_7b_hf/tokenizer.model
wxj's avatar
wxj committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
)

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 
)

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[@]} \
"

case ${LOCAL_RANK} in
[0])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
[1])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
[2])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
[3])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
wxj's avatar
wxj committed
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
[4])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
[5])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
[6])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
[7])
  export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
#   ${APP}
  numactl --cpunodebind=0 --membind=0 ${APP}
  ;;
wxj's avatar
wxj committed
168
esac