AI开发平台MODELARTS-迁移适配:单卡方式训练

时间:2024-09-14 22:29:36

单卡方式训练

单卡执行脚本如下:
# ptuning/run_npu_1d.sh
export ASCEND_RT_VISIBLE_DEVI CES =0  # 指定 0 号卡对当前进程可见
PRE_SEQ_LEN=128
LR=2e-2
 
python3 ptuning/main.py \
    --do_train \
    --train_file ${HOME}/AdvertiseGen/train.json \
    --validation_file ${HOME}/AdvertiseGen/dev.json \
    --prompt_column content \
    --response_column summary \
    --overwrite_cache \
    --model_name_or_path ${HOME}/chatglm \
    --output_dir output/adgen-chatglm-6b-pt-$PRE_SEQ_LEN-$LR \
    --overwrite_output_dir \
    --max_source_length 64 \
    --max_target_length 64 \
    --per_device_train_batch_size 4 \
    --per_device_eval_batch_size 1 \
    --gradient_accumulation_steps 1 \
    --predict_with_generate \
    --max_steps 3000 \
    --logging_steps 10 \
    --save_steps 1000 \
    --learning_rate $LR \
    --pre_seq_len $PRE_SEQ_LEN \
    --local_rank -1

通过设定ASCEND_RT_VISIBLE_DEVICES环境变量为0,控制0号卡对当前进程可见,PRE_SEQ_LEN和LR分别是soft prompt长度和训练的学习率,可以进行调节以取得最佳的效果。此外,这里去掉了int 4量化默认为FP16精度。${HOME} 目录需要根据读者实际数据集及模型路径匹配,适配的数据集是ADGEN数据集,如果需要读者也可以使用自定义的数据集训练,具体请参考使用自己数据集。另外通过指定local_rank为-1为单卡模式,多卡模式下无需指定,会默认启动DistributedDataParallel(DDP) 多卡并行模式,具体详情见常见问题1。GPU环境单卡执行同样需要指定local_rank为 -1。

support.huaweicloud.com/bestpractice-modelarts/modelarts_10_4002.html