#!/bin/bash # ASR 诗词纠错模型训练脚本 # 基于 ChineseErrorCorrector3-4B 继续 SFT cd ./asr # ============= 环境配置 ============= export CUDA_VISIBLE_DEVICES=0,1,2,3 # 根据实际 GPU 数量修改 export NCCL_P2P_DISABLE=1 # 如果遇到 NCCL 问题可取消注释 # ============= 数据路径(优先 RL 最新 v4-lite,缺失时回退 v4/v3) ============= RL_DIR="./asr/log1" LATEST_RL_RUN="" for d in "${RL_DIR}"/asr_v4_lite_*; do [ -d "${d}" ] || continue if [ -z "${LATEST_RL_RUN}" ] || [ "${d}" -nt "${LATEST_RL_RUN}" ]; then LATEST_RL_RUN="${d}" fi done if [ -n "${LATEST_RL_RUN}" ] && [ -f "${LATEST_RL_RUN}/train.jsonl" ] && [ -f "${LATEST_RL_RUN}/valid.jsonl" ]; then TRAIN_FILE="${LATEST_RL_RUN}/train.jsonl" DEV_FILE="${LATEST_RL_RUN}/valid.jsonl" elif [ -f "train_data_v4/train.jsonl" ]; then echo "WARNING: RL v4-lite data not found, falling back to v4" TRAIN_FILE="train_data_v4/train.jsonl" DEV_FILE="train_data_v4/valid.jsonl" else echo "WARNING: v4 data not found, falling back to v3" TRAIN_FILE="train_data_v3/train.jsonl" DEV_FILE="train_data_v3/valid.jsonl" fi echo "Using train file: ${TRAIN_FILE}" echo "Using dev file: ${DEV_FILE}" # ============= 单卡训练 ============= # 显存 < 24GB 建议使用 QLoRA (int4=True, qlora=True) python train_asr_poetry_correction.py \ --model_name ChineseErrorCorrector3-4B \ --train_file ${TRAIN_FILE} \ --dev_file ${DEV_FILE} \ --output_dir output/asr_poetry_lora \ --num_train_epochs 3 \ --learning_rate 2e-5 \ --per_device_train_batch_size 4 \ --gradient_accumulation_steps 4 \ --lora_r 16 \ --lora_alpha 32 \ --save_steps 500 \ --eval_steps 500 \ --early_stopping_patience 2 \ --correction_token_weight 4.0 \ --logging_steps 50 \ --bf16 True # ============= 多卡训练 (推荐) ============= # 取消下面的注释使用多卡训练 # torchrun --nproc_per_node=4 train_asr_poetry_correction.py \ # --model_name ChineseErrorCorrector3-4B \ # --train_file ${TRAIN_FILE} \ # --dev_file ${DEV_FILE} \ # --output_dir output/asr_poetry_lora \ # --num_train_epochs 3 \ # --learning_rate 2e-5 \ # --per_device_train_batch_size 4 \ # --gradient_accumulation_steps 1 \ # --lora_r 16 \ # --lora_alpha 32 \ # --save_steps 500 \ # --eval_steps 500 \ # --logging_steps 50 \ # --bf16 True # ============= QLoRA 训练 (省显存) ============= # 如果显存不足,使用 QLoRA: # python train_asr_poetry_correction.py \ # --model_name ChineseErrorCorrector3-4B \ # --train_file ${TRAIN_FILE} \ # --dev_file ${DEV_FILE} \ # --output_dir output/asr_poetry_qlora \ # --int4 True \ # --qlora True \ # --num_train_epochs 3 \ # --per_device_train_batch_size 8 \ # --gradient_accumulation_steps 2 \ # --lora_r 16 \ # --lora_alpha 32 echo "训练完成!"