[Bug] dynamic_bsz micro-batch count mismatch causes FSDP deadlock (dp_group not passed to prepare_dynamic_batch)
Description
prepare_dynamic_batch() in verl/utils/seqlen_balancing.py has a dp_group parameter and same_micro_num_in_dp=True logic (line 402-405) to synchronize micro-batch counts across data-parallel ranks. However, dp_actor.py never passes dp_group when calling prepare_dynamic_batch(), so the sync is a no-op.
This causes different GPUs to compute different numbers of micro-batches (because their effective token counts differ). When one GPU finishes its micro-batch loop early and exits, the remaining GPUs call self.actor_module(...) which triggers FSDP _all_gather_flat_param → dist.all_gather_into_tensor (a collective op). The exited GPU never participates → permanent NCCL hang.
Affected code
dp_actor.py:update_policy (line ~560):
micro_batches, _ = prepare_dynamic_batch(mini_batch, max_token_len=max_token_len)
# dp_group not passed → defaults to None → no cross-rank sync
dp_actor.py:compute_log_prob (line ~468):
micro_batches, batch_idx_list = prepare_dynamic_batch(data, max_token_len=max_token_len)
# same issue
The sync logic exists but is never activated (seqlen_balancing.py:402-405):
if dist.is_initialized() and same_micro_num_in_dp and dp_group is not None:
num_micro_batches = torch.tensor([num_micro_batches], device=get_device_name())
dist.all_reduce(num_micro_batches, op=dist.ReduceOp.MAX, group=dp_group)
Reproduction
- 8+ GPUs, FSDP,
use_dynamic_bsz=True - Variable-length VLM data (e.g., vision tokens ranging 81–4113 per sequence)
- Observed
global_seqlen/min:52491vsglobal_seqlen/max:157905(3× difference across GPUs) - Training hangs after a few steps with one GPU at 0% utilization, others at 100%
- Eventually times out with NCCL timeout
Expected behavior
prepare_dynamic_batch should receive the correct dp_group so that all ranks create the same number of micro-batches via all_reduce(MAX), preventing FSDP collective deadlocks.
Workaround
Use use_dynamic_bsz=False with fixed ppo_micro_batch_size_per_gpu to guarantee equal micro-batch counts across all ranks.
Environment
- verl commit: 592cb072 (v0.7.0-335)
- PyTorch 2.9, FSDP v1
- Model: Qwen3-VL-4B, 8-16× H20 GPUs
Fixed in https://github.com/verl-project/verl/pull/5921