# 4卡 NPU 训练
accelerate launch --config_file accelerate_configs/multi_npu.yaml train_grpo_batch.py
# 8卡 NPU 训练
accelerate launch --config_file accelerate_configs/multi_npu_8cards.yaml train_grpo_batch.py
# 单卡 NPU 训练
accelerate launch --config_file accelerate_configs/single_npu.yaml train_grpo_batch.py如果已经通过 accelerate config 配置了默认设置:
accelerate launch train_grpo_batch.py# 直接指定参数
accelerate launch --num_processes=4 --mixed_precision=bf16 train_grpo_batch.py- 项目配置文件:
accelerate_configs/*.yaml - 默认配置文件:
~/.cache/huggingface/accelerate/default_config.yaml
accelerate config按照提示选择:
- 分布式类型(单卡/多卡)
- 设备类型(NPU/GPU)
- 混合精度设置
- 进程数量等
# 复制现有配置文件
cp accelerate_configs/multi_npu.yaml accelerate_configs/my_custom_config.yaml
# 编辑配置文件
vim accelerate_configs/my_custom_config.yaml主要修改项:
num_processes: 进程数量(卡数)npu_ids: NPU ID 列表(如[0, 1, 2, 3])mixed_precision: 混合精度('no'/'fp16'/'bf16')
# 检查配置是否正确
accelerate env --config_file accelerate_configs/multi_npu.yaml
# 查看当前 accelerate 环境
accelerate envA: 在配置文件中修改 npu_ids 字段:
npu_ids: [0, 2, 4, 6] # 只使用 0, 2, 4, 6 号 NPUA: 在配置文件中设置:
mixed_precision: 'no'A: 训练日志会显示每个进程的信息,主进程(rank 0)会显示完整的训练信息。
A: 详细说明请参考 accelerate_configs/README.md
# 使用 4 卡 NPU,bf16 混合精度
cd /opt/fmbench_wyt
accelerate launch --config_file accelerate_configs/multi_npu.yaml train_grpo_batch.py
# 使用 8 卡 NPU,bf16 混合精度
accelerate launch --config_file accelerate_configs/multi_npu_8cards.yaml train_grpo_batch.py
# 单卡训练(不使用 accelerate,直接运行)
python train_grpo_batch.py