verl icon indicating copy to clipboard operation
verl copied to clipboard

GRPO training wtih lora using qwen2.5-7b-vl tain_batch_size=1,mini_batch_size=1,and micro_mini_batch_size_per_gpu=1

Open cqray1990 opened this issue 5 months ago • 4 comments

System Info

.

Information

  • [ ] The official example scripts
  • [ ] My own modified scripts

Tasks

  • [ ] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • [ ] My own task or dataset (give details below)

Reproduction

as we don't have enough GPUS we set tain_batch_size=1,mini_batch_size=1,and micro_mini_batch_size_per_gpu=1,but it raised an error: like this: File "verl/workers/engine_workers.py", line 69, in wrapper return func(self, data, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "verl/workers/engine_workers.py", line 648, in compute_log_prob output = self.actor.infer_batch(data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "verl/single_controller/base/decorator.py", line 431, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "verl/utils/transferqueue_utils.py", line 329, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "verl/workers/engine_workers.py", line 409, in infer_batch output = self.engine.infer_batch(data, loss_function=loss_function) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "verl/workers/engine/base.py", line 148, in infer_batch outputs = self.forward_backward_batch(data, loss_function, forward_only=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "verl/workers/engine/fsdp/transformer_impl.py", line 650, in forward_backward_batch micro_batches, indices = prepare_micro_batches( ^^^^^^^^^^^^^^^^^^^^^^ File "verl/workers/engine/utils.py", line 77, in prepare_micro_batches micro_batches, batch_idx_list = rearrange_micro_batches( ^^^^^^^^^^^^^^^^^^^^^^^^ File "verl/utils/seqlen_balancing.py", line 465, in rearrange_micro_batches curr_micro_batch = tu.index_select_tensor_dict(batch, partition) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "verl/utils/tensordict_utils.py", line 495, in index_select_tensor_dict tensor_lst = tensor.unbind() # for performance ^^^^^^^^^^^^^^^ File "/home/user/anaconda3/envs/verl_env/lib/python3.12/site-packages/torch/nested/_internal/nested_tensor.py", line 378, in torch_function return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/user/anaconda3/envs/verl_env/lib/python3.12/site-packages/torch/nested/_internal/nested_tensor.py", line 343, in torch_dispatch return fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File "/home/user/anaconda3/envs/verl_env/lib/python3.12/site-packages/torch/nested/_internal/ops.py", line 218, in inner return func(aten_op, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/anaconda3/envs/verl_env/lib/python3.12/site-packages/torch/nested/_internal/ops.py", line 1124, in unbind_int return torch.split(values, lengths_scalars, dim=(ragged_idx - 1)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/anaconda3/envs/verl_env/lib/python3.12/site-packages/torch/functional.py", line 173, in split return tensor.split(split_size_or_sections, dim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/anaconda3/envs/verl_env/lib/python3.12/site-packages/torch/_tensor.py", line 1030, in split return torch._VF.split_with_sizes(self, split_size, dim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: split_with_sizes expects split_sizes to sum exactly to 5819 (input tensor's size at dimension 1), but got split_sizes=[4, 4]

                                                            #!/usr/bin/env bash
                                                            # GRPO | vision | vLLM rollout | FSDP training | GPU/NPU
                                                     
                                                            #ray stop
                                                            #ray start --head --num-gpus=2
                                                            
                                                            set -xeuo pipefail
                                                            
                                                            ########################### user-adjustable ###########################
                                                            # DEVICE is auto-detected by probing torch_npu; override only for special cases.
                                                            DEVICE=${DEVICE:-$(python3 -c 'import torch_npu' 2>/dev/null && echo npu || echo gpu)}
                                                            MODEL_PATH=${MODEL_PATH:-/media/user/2.0TB/llmmodel/llam_factory/qwen25_vl_sft_merged}
                                                            NNODES=${NNODES:-1}
                                                            #NDEVICES_PER_NODE=${NDEVICES_PER_NODE:-2}
                                                            
                                                            TRAIN_BATCH_SIZE=${TRAIN_BATCH_SIZE:-1} #8
                                                            PPO_MINI_BATCH_SIZE=${PPO_MINI_BATCH_SIZE:-1}
                                                            ppo_micro_batch_size_per_gpu=${MICRO_BATCH_SIZE_PER_GPU:-1}
                                                            MAX_PROMPT_LENGTH=${MAX_PROMPT_LENGTH:-8192}
                                                            MAX_RESPONSE_LENGTH=${MAX_RESPONSE_LENGTH:-1800}
                                                            PPO_MAX_TOKEN_LEN_PER_GPU=${PPO_MAX_TOKEN_LEN_PER_GPU:-16384}
                                                            
                                                            ACTOR_LR=${ACTOR_LR:-1e-6}
                                                            KL_LOSS_COEF=${KL_LOSS_COEF:-0.01}
                                                            ENTROPY_COEFF=${ENTROPY_COEFF:-0}
                                                            
                                                            ROLLOUT_TP=${ROLLOUT_TP:-2}
                                                            ROLLOUT_N=${ROLLOUT_N:-4}
                                                            SP_SIZE=${SP_SIZE:-1}
                                                            
                                                            TOTAL_EPOCHS=${TOTAL_EPOCHS:-15}
                                                            SAVE_FREQ=${SAVE_FREQ:-20}
                                                            TEST_FREQ=${TEST_FREQ:-5}
                                                            
                                                            PROJECT_NAME=${PROJECT_NAME:-verl_grpo_ki_inovice}
                                                            EXPERIMENT_NAME=${EXPERIMENT_NAME:-qwen3_vl_8b_grpo_vllm_fsdp_$(date +%Y%m%d_%H%M)}
                                                            
                                                            TRAIN_FILE=${TRAIN_FILE:-examples/data_preprocess/data/kie_invoice/train.parquet}
                                                            TEST_FILE=${TEST_FILE:-examples/data_preprocess/data/kie_invoice/test.parquet}
                                                            ########################### end user-adjustable ###########################
                                                            
                                                            ########################### derived defaults ###########################
                                                            n_devices_per_node=${NDEVICES_PER_NODE:-2}
                                                            
                                                            
                                                            case "${DEVICE}" in
                                                                gpu)
                                                                    rollout_gpu_mem_util=${ROLLOUT_GPU_MEM_UTIL:-0.5}
                                                                    ;;
                                                                npu)
                                                                    export HCCL_CONNECT_TIMEOUT=1500
                                                                    export HCCL_HOST_SOCKET_PORT_RANGE=60000-60050
                                                                    export HCCL_NPU_SOCKET_PORT_RANGE=61000-61050
                                                                    export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
                                                            
                                                                    rollout_gpu_mem_util=${ROLLOUT_GPU_MEM_UTIL:-0.6}
                                                                    ;;
                                                                *)
                                                                    echo "Unsupported DEVICE=${DEVICE}. Expected 'gpu' or 'npu'." >&2
                                                                    exit 1
                                                                    ;;
                                                            esac
                                                            
                                                            ########################### parameter arrays ###########################
                                                            
                                                            DATA=(
                                                                algorithm.adv_estimator=grpo
                                                                algorithm.use_kl_in_reward=False
                                                                data.train_files=${TRAIN_FILE}
                                                                data.val_files=${TEST_FILE}
                                                                data.image_key=images
                                                                data.train_batch_size=${TRAIN_BATCH_SIZE}
                                                                data.max_prompt_length=${MAX_PROMPT_LENGTH}
                                                                data.max_response_length=${MAX_RESPONSE_LENGTH}
                                                                data.filter_overlong_prompts=True
                                                                data.truncation='error'
                                                            )
                                                            #actor_rollout_ref.model.target_modules=all-linear
                                                            MODEL=(
                                                                actor_rollout_ref.model.path="$MODEL_PATH"
                                                                actor_rollout_ref.model.use_remove_padding=True
                                                                actor_rollout_ref.model.enable_gradient_checkpointing=True
                                                                actor_rollout_ref.model.lora_rank=8
                                                                actor_rollout_ref.model.lora_alpha=16
                                                                actor_rollout_ref.rollout.load_format=safetensors
                                                                actor_rollout_ref.model.target_modules='["q_proj", "v_proj", "k_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]'
                                                                actor_rollout_ref.model.use_fused_kernels=False
                                                            
                                                            
                                                            
                                                            )
                                                            
                                                            REWARD=(
                                                               reward.custom_reward_function.path="custom_reward/reward_invoice.py"
                                                               reward.custom_reward_function.name="compute_score"
                                                            
                                                            )
                                                            
                                                            ACTOR=(
                                                                actor_rollout_ref.actor.strategy=fsdp2
                                                                actor_rollout_ref.actor.optim.lr=${ACTOR_LR}
                                                                actor_rollout_ref.actor.ppo_mini_batch_size=${PPO_MINI_BATCH_SIZE}
                                                                actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=${ppo_micro_batch_size_per_gpu} #add
                                                                actor_rollout_ref.actor.use_dynamic_bsz=True
                                                                actor_rollout_ref.actor.ppo_max_token_len_per_gpu=${PPO_MAX_TOKEN_LEN_PER_GPU}
                                                                actor_rollout_ref.actor.use_kl_loss=True
                                                                actor_rollout_ref.actor.kl_loss_coef=${KL_LOSS_COEF}
                                                                actor_rollout_ref.actor.kl_loss_type=low_var_kl
                                                                actor_rollout_ref.actor.entropy_coeff=${ENTROPY_COEFF}
                                                                actor_rollout_ref.actor.freeze_vision_tower=True
                                                                actor_rollout_ref.model.exclude_modules='.visual.'
                                                                actor_rollout_ref.actor.fsdp_config.entropy_checkpointing=False
                                                            )
                                                            
                                                            ROLLOUT=(
                                                                actor_rollout_ref.rollout.name=vllm
                                                                actor_rollout_ref.rollout.tensor_model_parallel_size=${ROLLOUT_TP}
                                                                actor_rollout_ref.rollout.gpu_memory_utilization=${rollout_gpu_mem_util}
                                                                actor_rollout_ref.rollout.enable_chunked_prefill=True
                                                                actor_rollout_ref.rollout.max_model_len=8192
                                                                actor_rollout_ref.rollout.max_num_batched_tokens=2000
                                                                actor_rollout_ref.rollout.n=${ROLLOUT_N}
                                                                actor_rollout_ref.rollout.log_prob_use_dynamic_bsz=True
                                                                actor_rollout_ref.rollout.log_prob_max_token_len_per_gpu=${PPO_MAX_TOKEN_LEN_PER_GPU}
                                                                actor_rollout_ref.rollout.agent.num_workers=1
                                                            )
                                                            
                                                            REF=(
                                                                actor_rollout_ref.ref.log_prob_use_dynamic_bsz=True
                                                                actor_rollout_ref.ref.log_prob_max_token_len_per_gpu=${PPO_MAX_TOKEN_LEN_PER_GPU}
                                                                actor_rollout_ref.ref.fsdp_config.param_offload=True
                                                            )
                                                            
                                                            TRAINER=(
                                                                trainer.balance_batch=True
                                                                trainer.logger='["console","wandb"]'
                                                                trainer.project_name=${PROJECT_NAME}
                                                                trainer.experiment_name=${EXPERIMENT_NAME}
                                                                trainer.n_gpus_per_node=${n_devices_per_node}
                                                                trainer.nnodes=${NNODES}
                                                                trainer.save_freq=${SAVE_FREQ}
                                                                trainer.test_freq=${TEST_FREQ}
                                                                trainer.total_epochs=${TOTAL_EPOCHS}
                                                            )
                                                            
                                                            # Per-device extras (single trailing array, never empty).
                                                            if [ "${DEVICE}" = npu ]; then
                                                                EXTRA=(
                                                                    actor_rollout_ref.actor.use_torch_compile=False
                                                                    actor_rollout_ref.actor.fsdp_config.param_offload=True
                                                                    actor_rollout_ref.actor.fsdp_config.optimizer_offload=True
                                                                    actor_rollout_ref.actor.fsdp_config.ulysses_sequence_parallel_size=${SP_SIZE}
                                                                    actor_rollout_ref.ref.fsdp_config.ulysses_sequence_parallel_size=${SP_SIZE}
                                                                    +actor_rollout_ref.rollout.engine_kwargs.vllm.mm_processor_cache_gb=0
                                                                    actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=20
                                                                )
                                                            else
                                                                EXTRA=(
                                                                    actor_rollout_ref.model.use_fused_kernels=False
                                                                    actor_rollout_ref.actor.fsdp_config.param_offload=False
                                                                    actor_rollout_ref.actor.fsdp_config.optimizer_offload=False
                                                                    actor_rollout_ref.rollout.enforce_eager=False
                                                                    actor_rollout_ref.rollout.free_cache_engine=True
                                                                )
                                                            fi
                                                            
                                                            ########################### launch ###########################
                                                            python -m verl.trainer.main_ppo \
                                                                "${DATA[@]}" \
                                                                "${MODEL[@]}" \
                                                                "${ACTOR[@]}" \
                                                                "${ROLLOUT[@]}" \
                                                                "${REF[@]}" \
                                                                "${TRAINER[@]}" \
                                                                "${EXTRA[@]}" \
                                                                "${REWARD[@]}" \
                                                                "$@"

Expected behavior

@ezyang @dbuos @davidmlw ,

cqray1990 avatar Jun 25 '26 15:06 cqray1990

same issues

chengq1001 avatar Jul 01 '26 16:07 chengq1001

same issue

HututuAI avatar Jul 08 '26 01:07 HututuAI

same issues

have u solved it?

HututuAI avatar Jul 08 '26 01:07 HututuAI

same issues

have u solved it?

same issues

have u solved it? i set params like this: TRAIN_BATCH_SIZE=${TRAIN_BATCH_SIZE:-2} PPO_MINI_BATCH_SIZE=${PPO_MINI_BATCH_SIZE:-1} ppo_micro_batch_size_per_gpu=${MICRO_BATCH_SIZE_PER_GPU:-1}

cqray1990 avatar Jul 25 '26 02:07 cqray1990