#!/bin/bash
export CUDA_DEVICE_MAX_CONNECTIONS=1
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
NPUS_PER_NODE=8
MASTER_ADDR=localhost
MASTER_PORT=6009
NNODES=1
NODE_RANK=0
WORLD_SIZE=$(($NPUS_PER_NODE*$NNODES))
CKPT_SAVE_DIR="your model save ckpt path"
DATA_PATH="your data path"
TOKENIZER_PATH="your tokenizer path"
CKPT_LOAD_DIR="your model ckpt path"
TP=1
PP=1
DISTRIBUTED_ARGS="
--master_addr $MASTER_ADDR \
--node_rank $NODE_RANK \
--worker_num $WORLD_SIZE \
--local_worker_num $NPUS_PER_NODE \
--master_port $MASTER_PORT \
--log_dir=msrun_log \
--join=False \
--cluster_time_out=300 \
--bind_core=True \
"
GPT_ARGS="
--use-mcore-models \
--tensor-model-parallel-size ${TP} \
--pipeline-model-parallel-size ${PP} \
--sequence-parallel \
--num-layers 40 \
--hidden-size 2304 \
--ffn-hidden-size 5760 \
--num-attention-heads 36 \
--tokenizer-type PretrainedFromHF \
--tokenizer-name-or-path "${TOKENIZER_PATH}" \
--tokenizer-not-use-fast \
--vocab-size 122753 \
--seq-length 4096 \
--max-position-embeddings 4096 \
--micro-batch-size 1 \
--global-batch-size 8 \
--make-vocab-size-divisible-by 1 \
--lr 1e-7 \
--train-iters 2000 \
--lr-decay-style constant \
--disable-bias-linear \
--attention-dropout 0.0 \
--init-method-std 0.01 \
--hidden-dropout 0.0 \
--position-embedding-type rope \
--normalization RMSNorm \
--norm-epsilon 1e-5 \
--use-fused-rmsnorm \
--swiglu \
--use-flash-attn \
--no-masked-softmax-fusion \
--attention-softmax-in-fp32 \
--min-lr 1e-8 \
--weight-decay 1e-1 \
--lr-warmup-fraction 0.01 \
--clip-grad 1.0 \
--adam-beta1 0.9 \
--initial-loss-scale 65536 \
--adam-beta2 0.999 \
--no-gradient-accumulation-fusion \
--no-load-optim \
--no-load-rng \
--use-distributed-optimizer \
--use-fused-swiglu \
--use-fused-rotary-pos-emb \
--overlap-grad-reduce \
--variable-seq-lengths \
--scale-emb 12 \
--dim-model-base 256 \
--scale-depth 1.4 \
--lora-r 8 \
--lora-alpha 16 \
--lora-fusion \
--lora-target-modules linear_qkv linear_proj linear_fc1 linear_fc2 \
--bf16 \
"
DATA_ARGS="
--data-path $DATA_PATH \
--split 100,0,0 \
--finetune \
--stage sft \
--is-instruction-dataset \
--prompt-type cpm \
--no-shuffle \
"
OUTPUT_ARGS="
--log-interval 1 \
--save-interval 1000 \
--eval-interval 1000 \
--eval-iters 10 \
"
msrun $DISTRIBUTED_ARGS posttrain_gpt.py \
$GPT_ARGS \
$DATA_ARGS \
$OUTPUT_ARGS \
--distributed-backend nccl \
--ai-framework mindspore \
--load $CKPT_LOAD_DIR \
--save $CKPT_SAVE_DIR \
| tee logs/tune_minicpm_2b_lora_npu.log