使用grpo训练Qwen2.5-VL-7B-Instruct,zero3下混合纯文本和图文数据,训练会卡住
Describe the bug 使用grpo训练Qwen2.5-VL-7B-Instruct,zero3下混合纯文本和图文数据,训练会卡住(只出1步信息),做了多组实验如下
- 混合数据,zero1/2,可以
- 混合数据,zero3,卡住
- 纯文本数据,zero1/2/3,可以
- 纯图文数据,zero1/2/3,可以
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
NNODES=$WORLD_SIZE
NODE_RANK=$RANK
MASTER_ADDR=$MASTER_ADDR
MASTER_PORT=$MASTER_PORT
NPROC_PER_NODE=6
MAX_PIXELS=1003520
/bin/swift rlhf
--rlhf_type grpo
--model /Qwen/Qwen2.5-VL-7B-Instruct
--reward_funcs accuracy format
--use_vllm true
--lazy_tokenize true
--freeze_vit true
--num_infer_workers 2
--vllm_device 'auto'
--vllm_gpu_memory_utilization 0.7
--vllm_max_model_len 8192
--train_type full
--torch_dtype bfloat16
--dataset /data/text_train.json
/data/image_train.json
--max_completion_length 2048
--num_train_epochs 1
--per_device_train_batch_size 1
--per_device_eval_batch_size 1
--learning_rate 1e-6
--gradient_accumulation_steps 2
--eval_steps 2000
--save_steps 500
--save_total_limit 2
--report_to tensorboard
--logging_dir /logs/grpo
--logging_steps 1
--max_length 4096
--output_dir output
--warmup_ratio 0.05
--dataloader_num_workers 4
--dataset_num_proc 4
--num_generations 6
--temperature 0.7
--system './prompt.txt'
--ds3_gather_for_generation true
--deepspeed zero3
纯文本数据样例:
{"query": "637. Investigate the convexity, concavity, and points of inflection of the curve $y=x^{3}-6 x^{2}+4$.", "solution": "(2,-12)"
图文数据样例:
{"images": ["/data/images/b2f5eabc-d3b8-4e53-b6b4-dd6749fc08e7.jpg"], "query": "<image>Based on the image, if segment DE is extended while maintaining the angle at point D constant, what will be the effect on the v
alue of 's'? Choose the correct answer from the options below:\nChoices:\nA. Increase 's'\nB. Decrease 's'\nC. No change\nD. Make 's' negative", "solution": "A"}
Your hardware and system info
cuda: 12.2 torch: 2.5.1 gpu: a800 2机16卡
我遇到同样的问题,纯文本和图像文本混合数据训练vlm,使用zero2正常,zero3卡住,使用py-spy查看结果如下:
- 使用 flash_attn
Thread 3075398 (active): "MainThread" _get_unpad_data (transformers/modeling_flash_attention_utils.py:101) _upad_input (transformers/modeling_flash_attention_utils.py:150) _flash_attention_forward (transformers/modeling_flash_attention_utils.py:353) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1681) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1854) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (torch/utils/checkpoint.py:263) apply (torch/autograd/function.py:575) checkpoint (torch/utils/checkpoint.py:488) _fn (torch/_dynamo/eval_frame.py:838) inner (torch/_compile.py:51) _new_checkpoint (swift/trainers/mixin.py:355) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1984) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:2650) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (deepspeed/runtime/engine.py:2087) wrapped_fn (deepspeed/utils/nvtx.py:20) _call_impl (torch/nn/modules/module.py:1762) _wrapped_call_impl (torch/nn/modules/module.py:1751) compute_loss (swift/trainers/trainers.py:320) training_step (transformers/trainer.py:3736) training_step (swift/trainers/trainers.py:368) _inner_training_loop (transformers/trainer.py:2560) train (transformers/trainer.py:2245) train (swift/trainers/mixin.py:419) train (swift/llm/train/sft.py:183) run (swift/llm/train/sft.py:122) main (swift/llm/base.py:49) sft_main (swift/llm/train/sft.py:274)
(swift/cli/sft.py:7) Thread 3075860 (idle): "Thread-1 (_read_thread)" _recv_msg (torch/_inductor/compile_worker/subproc_pool.py:55) _read_thread (torch/_inductor/compile_worker/subproc_pool.py:191) run (threading.py:953) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3078951 (idle): "Thread-2" wait (threading.py:324) wait (threading.py:607) run (tqdm/_monitor.py:60) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3080766 (idle) Thread 3080768 (idle) Thread 3080770 (idle) Thread 3080777 (idle) Thread 3080779 (idle) Thread 3080781 (idle) Thread 3080784 (idle)
- 关闭 flash_attn
Process 3707497: /opt/miniconda3/envs/swift/bin/python3.10 -u /opt/miniconda3/envs/swift/lib/python3.10/site-packages/swift/cli/sft.py --model Kwai-Keye/Keye-VL-8B-Preview --model_type keye_vl --train_type full --dataset /data2/zhiyuan/workspace/ms-swift/datasets/data/processed_nothink/train-00001-of-00001.parquet /data2/zhiyuan/workspace/ms-swift/datasets/data/processed_think/train-00001-of-00001.parquet --torch_dtype bfloat16 --freeze_vit false --freeze_llm false --freeze_aligner false --num_train_epochs 5 --per_device_train_batch_size 4 --per_device_eval_batch_size 16 --gradient_accumulation_steps 8 --learning_rate 1e-5 --eval_steps 20 --save_steps 50 --save_total_limit 20 --save_only_model true --logging_steps 5 --max_length 4096 --warmup_ratio 0.05 --deepspeed zero3 --dataloader_num_workers 0 --dataset_num_proc 8 --output_dir /data2/models/swift_results/keye_vl_8b Python v3.10.18 (/opt/miniconda3/envs/swift/bin/python3.10)
Thread 3707497 (active): "MainThread" synchronize (torch/cuda/streams.py:227) fetch_sub_module (deepspeed/runtime/zero/partitioned_param_coordinator.py:335) decorate_context (torch/utils/_contextlib.py:116) wrapped_fn (deepspeed/utils/nvtx.py:20) _fn (torch/_dynamo/eval_frame.py:838) pre_sub_module_forward_function (deepspeed/runtime/zero/parameter_offload.py:473) decorate_context (torch/utils/_contextlib.py:116) _pre_forward_module_hook (deepspeed/runtime/zero/parameter_offload.py:298) _fn (torch/_dynamo/eval_frame.py:838) inner (torch/nn/modules/module.py:1794) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1397) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1871) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (torch/utils/checkpoint.py:263) apply (torch/autograd/function.py:575) checkpoint (torch/utils/checkpoint.py:488) _fn (torch/_dynamo/eval_frame.py:838) inner (torch/_compile.py:51) _new_checkpoint (swift/trainers/mixin.py:355) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1984) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:2650) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (deepspeed/runtime/engine.py:2105) wrapped_fn (deepspeed/utils/nvtx.py:20) _call_impl (torch/nn/modules/module.py:1762) _wrapped_call_impl (torch/nn/modules/module.py:1751) compute_loss (swift/trainers/trainers.py:320) training_step (transformers/trainer.py:3736) training_step (swift/trainers/trainers.py:368) _inner_training_loop (transformers/trainer.py:2560) train (transformers/trainer.py:2245) train (swift/trainers/mixin.py:419) train (swift/llm/train/sft.py:183) run (swift/llm/train/sft.py:122) main (swift/llm/base.py:49) sft_main (swift/llm/train/sft.py:274)
(swift/cli/sft.py:7) Thread 3707811 (idle): "Thread-1 (_read_thread)" _recv_msg (torch/_inductor/compile_worker/subproc_pool.py:55) _read_thread (torch/_inductor/compile_worker/subproc_pool.py:191) run (threading.py:953) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3708680 (idle): "Thread-2" wait (threading.py:324) wait (threading.py:607) run (tqdm/_monitor.py:60) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3708908 (idle): "MsgUploader" new_task (swanlab/core_python/uploader/thread/start_thread.py:120) run (threading.py:953) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3708909 (idle): "ThreadPoolExecutor-7_0" _worker (concurrent/futures/thread.py:81) run (threading.py:953) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3708918 (idle): "Thread-6" wait (threading.py:324) wait (threading.py:607) run (tqdm/_monitor.py:60) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3709024 (idle) Thread 3709025 (idle) Thread 3709026 (idle) Thread 3709027 (idle) Thread 3709028 (idle) Thread 3709029 (idle) Thread 3709030 (idle) Thread 3714663 (idle): "Thread-27" wait (threading.py:324) wait (threading.py:607) run (threading.py:1376) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973)
试试main分支呢
或者3.6.2
上面的结果使用的是 ms_swift-3.6.2 换了 main 分支 ms_swift 3.7.0.dev0 仍然会有以下错误
Thread 3808706 (idle): "MainThread" _engine_run_backward (torch/autograd/graph.py:824) backward (torch/autograd/init.py:353) backward (torch/_tensor.py:648) backward (deepspeed/runtime/fp16/loss_scaler.py:65) backward (deepspeed/runtime/zero/stage3.py:2309) wrapped_fn (deepspeed/utils/nvtx.py:20) _do_optimizer_backward (deepspeed/runtime/engine.py:2213) backward (deepspeed/runtime/engine.py:2267) wrapped_fn (deepspeed/utils/nvtx.py:20) backward (accelerate/utils/deepspeed.py:266) backward (accelerate/accelerator.py:2465) training_step (transformers/trainer.py:3782) training_step (swift/trainers/trainers.py:368) _inner_training_loop (transformers/trainer.py:2560) train (transformers/trainer.py:2245) train (swift/trainers/mixin.py:456) train (swift/llm/train/sft.py:183) run (swift/llm/train/sft.py:122) main (swift/llm/base.py:49) sft_main (swift/llm/train/sft.py:276)
(swift/cli/sft.py:7) Thread 3809757 (idle): "Thread-1 (_read_thread)" _recv_msg (torch/_inductor/compile_worker/subproc_pool.py:55) _read_thread (torch/_inductor/compile_worker/subproc_pool.py:191) run (threading.py:953) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3811064 (idle): "Thread-2" wait (threading.py:324) wait (threading.py:607) run (tqdm/_monitor.py:60) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3812225 (idle): "MsgUploader" new_task (swanlab/core_python/uploader/thread/start_thread.py:120) run (threading.py:953) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3812226 (idle): "ThreadPoolExecutor-7_0" _worker (concurrent/futures/thread.py:81) run (threading.py:953) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3812233 (idle): "Thread-6" wait (threading.py:324) wait (threading.py:607) run (tqdm/_monitor.py:60) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973) Thread 3813124 (active) _get_unpad_data (transformers/modeling_flash_attention_utils.py:101) _upad_input (transformers/modeling_flash_attention_utils.py:150) _flash_attention_forward (transformers/modeling_flash_attention_utils.py:353) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1681) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) forward (modules/transformers_modules/Keye-VL-8B-Preview/modeling_keye.py:1854) inner (torch/nn/modules/module.py:1805) _call_impl (torch/nn/modules/module.py:1857) _wrapped_call_impl (torch/nn/modules/module.py:1751) backward (torch/utils/checkpoint.py:303) apply (torch/autograd/function.py:307) Thread 3813125 (idle) Thread 3813126 (idle) Thread 3813127 (idle) Thread 3852578 (idle): "Thread-29" wait (threading.py:324) wait (threading.py:607) run (threading.py:1376) _bootstrap_inner (threading.py:1016) _bootstrap (threading.py:973)
这个问题就一直没人解决吗。。
please retry with main branch
Does anyone solve this?
有人能解决这个问题吗?
please retry with latest swift and vllm, feel free to create a new issue if it the problem persists.