GRPO 训练时使用2个节点并且设置--num_infer_workers 2 时会报错
GRPO 训练时使用2个节点并且设置--num_infer_workers 2 时会报错 多节点训练时设置 --num_infer_workers 2 会报错:IndexError: list index out of range 具体代码为:
ms-swift/swift/trainers/rlhf_trainer/grpo_trainer.py", line xxx, in _prefetch [rank6]: _input_slice = np.array(all_inputs)[distributed_idx[self.infer_rank]]
原因是 distributed_idx 只有两组,但是self.infer_rank会返回2和3
我理解 self.infer_rank是全局的推理进程编号(一共有4个),但是 round_robin 只是根据节点数(只有两个)进行分配的
命令贴一下啊
请问解决了吗
文件:ms-swift/swift/trainers/rlhf_trainer/grpo_trainer.py 中的: _input_slice = np.array(all_inputs)[distributed_idx[self.infer_rank] 改为 _input_slice = np.array(all_inputs)[distributed_idx[self.infer_rank % len(distributed_idx)]]
注意有两处。 不确定会不会有潜在其他bug。
any reproduce sript?
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 export NNODES=2 export NODE_RANK=0 export MASTER_ADDR=127.0.0.1 export MASTER_PORT=29500 export NPROC_PER_NODE=6
swift rlhf
--rlhf_type grpo
--model Qwen/Qwen2.5-7B
--reward_funcs accuracy format
--use_lmdeploy true
--train_type full
--torch_dtype bfloat16
--dataset AI-MO/NuminaMath-TIR#5000
--max_completion_length 1536
--num_train_epochs 1
--per_device_train_batch_size 10
--per_device_eval_batch_size 10
--learning_rate 1e-6
--eval_steps 1000
--save_steps 1000
--save_total_limit 2
--logging_steps 5
--max_length 2048
--output_dir output
--warmup_ratio 0.05
--dataloader_num_workers 4
--dataset_num_proc 4
--num_generations 60
--temperature 1.0
--top_p 0.9
--top_k 50
--async_generate true
--system 'examples/train/grpo/prompt.txt'
--deepspeed zero3
--log_completions true
--num_iterations 2
--num_infer_workers 2
这个可能会复现,我这没有多余的机器复现这个问题了。主要就是num_infer_workers 设置为2,节点数设置为2
Try keeping the settings consistent across all nodes, including device count, NPROC_PER_NODE, and num_infer_workers