verl icon indicating copy to clipboard operation
verl copied to clipboard

[RFC] Stable optimizer-step counts for multi-output rollouts in the V1 trainer

Open luyuzhe111 opened this issue 2 months ago • 1 comments

Feature request

Could the V1 trainer offer an explicit batching mode that keeps the number of actor optimizer steps tied to the configured source-prompt batch, while allowing the number of training rows per rollout to vary?

In a MigrationBench comparison, fixed-count batching reached a best mean validation reward of 78.76%, versus 74.92% with fixed-row batching. The setup and learning curves are in our experiment write-up.

This builds on the problem already identified in #6025. We have implemented a limited version downstream and would like to discuss the intended upstream semantics and how it could fit with the existing work.

For context, I opened the earlier Bedrock AgentCore Runtime integration proposal (#4216), and we have continued that work in AgentCore RL Toolkit. Our current verl backend uses the V1 agent-loop interface and LLMServerClient: agents execute on AgentCore Runtime, while a rollout gateway routes their model calls to verl's inference servers and captures token IDs, log probabilities, and loss masks. A rollout can return multiple AgentLoopOutput rows after context compaction or trajectory branching. This is how we encountered the batching behavior below.

Motivation

At current main, 8718ca30, _update_actor passes:

mini_batch_size = actor.ppo_mini_batch_size * rollout.n
global_batch_size = actor.ppo_mini_batch_size * rollout.n

The worker partitions the expanded rows using that fixed row count. Consequently, trajectory expansion can increase the number of optimizer steps even when the source-prompt batch and PPO epoch count are unchanged.

For example, consider:

data.train_batch_size = 32
actor.ppo_mini_batch_size = 32
rollout.n = 16
actor.ppo_epochs = 1
parameter_sync_step = 1
actor data-parallel size = 2
Rows emitted by the 512 rollouts Current fixed-row batching: optimizer steps Proposed fixed-count batching: optimizer steps
512 1 1
1,536 3 1

Three sequential Adam updates differ from accumulating the row losses before one update: both parameters and optimizer state change between updates. For these workloads, we want trajectory expansion to change the work within an update while preserving the configured update count.

Padding is affected too. The current trainer rounds 513 rows up to 1,024 for this configuration. One optimizer partition across two DP ranks needs only 514 rows.

This can also produce an optimizer step with very few real rows. Padding is appended after the real rows, and V1's balancing helper sorts each DP partition by its original row indices. With the default actor.shuffle=false, padding therefore remains at the end of each rank's chunk. Running the current upstream partitioning functions on a synthetic batch of 513 equal-length real rows and 511 padding rows gives:

Optimizer step Real rows Padding rows
1 512 0
2 1 511

Padding has zero loss; it does not itself add gradient noise. The concern is that the second Adam update is driven by a single real row. Under seq-mean-token-sum, that row's gradient is still divided by the nominal denominator of 512. This changes both the amount of data informing the update and its gradient scale; Adam's parameter update is not simply proportional to that scale. Such a tail step may be less representative of the rollout batch, although we have not isolated its effect on training stability experimentally. Shuffling changes the concentration of padding across steps; the extra optimizer step remains. Fixed-count batching with M=1 accumulates all 513 real rows before one update.

This concerns optimizer mini-batches; token-based dynamic micro-batching can still control how each mini-batch is processed.

Related work

  • #6025 — grouped mini-batching: directly addresses the variable update count and proposes keeping same-UID rows together. It is still open. Our implementation fixes the count without adding a grouped iterator and retains the configured loss denominator; those choices differ from #6025.
  • #5969 — multi-trajectory padding: merged support for dropless, masked padding. The proposed mode can reuse this machinery with a different required multiple.
  • #7580 — weighted multi-output trajectories: still open; addresses trajectory loss weights and explicitly retains row-based optimizer mini-batching. Update scheduling and trajectory weighting need separate, compatible contracts.

The question here is whether a fixed-count mode is useful as a smaller initial scope, and how to coordinate it with these efforts.

Proposed behavior

For each actor-update call, derive:

M = data.train_batch_size / parameter_sync_step / actor.ppo_mini_batch_size
optimizer steps per actor-update call = M * actor.ppo_epochs

Require the divisions to be integral. M comes from configuration, so emitted row counts do not change the schedule.

A possible implementation would:

  1. Pad to a multiple of actor_dp_size * M, with zero-loss padding rows.
  2. Retain V1's whole-batch DP token balancing.
  3. Pass num_mini_batch=M to the existing TrainingWorker.train_mini_batch interface, without passing mini_batch_size.
  4. Consume every real row once per PPO epoch.

With M > 1, this approach allows rows from one rollout to cross optimizer-step boundaries. Keeping them together would require additional grouping semantics, as explored in #6025.

An upstream option could preserve the existing fixed-row behavior as the default. The configuration surface and broader loss-mode/critic support are open for discussion.

Downstream implementation

The implementation is released in AgentCore RL Toolkit v0.1.4, against verl 0.9.0, through verl's public trainer registry and existing worker interface. See the batching mixin and design document.

The released integration supports V1 actor-only training with distillation disabled and loss_agg_mode=seq-mean-token-sum. It keeps loss normalization based on the configured number of rollouts per mini-batch, so splitting a rollout into more rows does not change the denominator. It covers sync and colocate-async with parameter_sync_step=1, plus separate-async, whose existing configuration constraint gives M=1 per actor-update call.

Questions for maintainers

  1. Would an explicit fixed optimizer-step-count mode be useful for multi-output rollouts?
  2. Could this start with the existing num_mini_batch worker interface, or should preserving prompt/session groups be part of the initial contract?
  3. How should this mode interact with loss normalization and trajectory weighting, including the work in #7580?

We would appreciate guidance on whether to build on #6025 or factor out a smaller change using the downstream implementation.

cc @wuxibin89 @eric-haibin-lin

luyuzhe111 avatar Oct 02 '26 20:10 luyuzhe111

+1 for fixed-count scheduling through num_mini_batch. The same behavior shows up with multi-output sessions where V1 GRPO computes one advantage per session before the actor update: with D outputs per session, fixed-row mini-batches run D times as many optimizer steps.

Two things the mode needs beyond a padding multiple of dp × M:

  1. Micro-batches. Without dynamic batch sizes, each rank's mini-batch must split into whole update micro-batches, and each rank's share into whole log-prob micro-batches (actor and reference); otherwise prepare_micro_batches asserts. For example, with dp = 8, M = 2 and 4-row micro-batches, padding 228 rows to a multiple of dp × M gives 240 rows, 30 per rank, which 4-row micro-batches do not divide, so the first old-log-prob pass fails. The multiple has to be dp × lcm(M × ppo_micro_batch_size_per_gpu, the log-prob micro-batch sizes).
  2. Padding placement. Padding rows are appended after the real rows and stay together through balancing, and the micro-batch multiple adds more of them. For example, on one GPU with M = 2 and 8-row micro-batches, 8 rows are padded to 16, and the second mini-batch holds padding only: its token-mean loss is 0/0 (NaN), the gradient is zero, and the optimizer still steps, so Adam momentum and weight decay move the weights. Spreading the padding rows over the M mini-batches avoids this. #8201, which fixes mini-batch membership on the trainer before balancing each mini-batch across ranks, looks like the natural place to do it; @Zhikaiiii's comment there shows the same 512 / 0 and 1 / 511 split for the RFC's example. Worker-side shuffle (the multi-epoch fallback in #8201) can still regroup the rows, so the fixed-count mode needs padding-aware mini-batch formation or has to reject that shuffle.

From reading its diff, both points also apply to the grouped approach in #6025: grouped mini-batches have row counts that vary across ranks, which needs the same micro-batch handling without dynamic batch sizes, and upstream padding rows share one uid, so they would form a group of their own.

I have a prototype on main: a trainer.v1.mini_batch_mode option (fixed_rows by default, fixed_count), num_mini_batch passed to the existing worker interface, the micro-batch-aware multiple, the padding spread, shuffle rejected, and no critic support yet. It is about 100 lines plus CPU tests, with no worker changes. Happy to open it as a draft PR or fold it into whichever implementation the maintainers prefer.

One open question: the prototype passes each mini-batch's row count as global_batch_size, as #6025 does, while your implementation keeps the configured rollout count for seq-mean-token-sum. Which denominator should the seq-mean modes use? The default token-mean is not affected.

cc @wuxibin89 @eric-haibin-lin

eteluna avatar Oct 18 '26 19:10 eteluna