verl icon indicating copy to clipboard operation
verl copied to clipboard

[BUG][agent_loop] async reward drops meta_info; custom reward can't see validate flag

Open GloryyrolG opened this issue 4 months ago • 1 comments

Summary

On the experimental agent_loop async-reward path, AgentLoopWorker._compute_score builds the reward DataProto without forwarding meta_info. As a result the reward worker (reward_loop.py → reward_manager.run_single) receives a DataProto whose meta_info is empty, so a custom reward manager can never read data.meta_info.get("validate") (or any other per-batch meta_info key) at scoring time.

The classic reward path does not have this problem: the reward manager's __call__(self, data, ...) gets the full batch DataProto, and the trainer stamps test_batch.meta_info["validate"] = True during validation — so classic custom rewards can branch on train vs. val, but agent_loop ones cannot.

System Info / Version

  • verl 0.8.0.dev, worktree HEAD bcb63864 (committed 2026-04-17).
  • Also reproduces on current public main (0.9.0.dev), checked 2026-07-22.
  • Agent Loop is .. versionadded:: 0.4.2 [status: alpha] (docs/advance/agent_loop.rst).

Reproduction

  1. actor_rollout_ref.rollout.mode=async (agent_loop) + a custom reward_manager on the async reward path (reward.reward_manager=...).
  2. In run_single, read data.meta_info.get("validate", False).
  3. Run training with validation enabled.
  4. The custom reward always sees validate absent/False, in both train and validation rollouts.
  5. Swap to the classic (sync) reward path with the same manager reading data.meta_info["validate"] → it correctly reads True during _validate.

Expected vs. Actual

  • Expected: agent_loop reward functions can distinguish validation from training via meta_info["validate"], matching the classic path.
  • Actual: meta_info is dropped before the reward manager, so validate (and everything else in meta_info) is unavailable.

Root cause (HEAD bcb63864)

  • verl/experimental/agent_loop/agent_loop.py:881-884 — the reward DataProto is constructed with no meta_info=:

    data = DataProto(
        batch=batch,
        non_tensor_batch=non_tensor_batch,
    )   # <- no meta_info=
    
  • _compute_score (agent_loop.py:858) doesn't take validate, but its caller _agent_loop_postprocess(self, output, validate, ...) has validate in scope — it already forwards it to the sibling call _compute_teacher_logprobs(..., validate=validate) (agent_loop.py:749-753). So the value is available at the call site; it just isn't passed down.

  • Reward side receives that DataProto: verl/experimental/reward_loop/reward_loop.py:148-152 (compute_score → reward_manager.run_single(data)). meta_info is empty there. (For evidence that meta_info is consulted on this path, see reward_manager/limited.py:495 reading data.meta_info.get("reward_extra_keys").)

  • Contrast — classic path: verl/workers/reward_manager/naive.py:46 __call__(self, data, ...) gets the full batch, and verl/trainer/ppo/ray_trainer.py:579 sets test_batch.meta_info["validate"] = True (public main: ray_trainer.py:663).

Proposed fix

Thread validate into _compute_score and attach it (or the whole meta_info) to the reward DataProto:

data = DataProto(
    batch=batch,
    non_tensor_batch=non_tensor_batch,
    meta_info={"validate": validate},
)

Since validate is already in scope at the caller (and already forwarded to _compute_teacher_logprobs), this is a minimal change.

Questions for maintainers: Is dropping meta_info on the async reward path intended? Is there a recommended way for agent_loop custom rewards to detect validation today? Happy to send a PR if this direction looks right.

GloryyrolG avatar Jul 23 '26 01:07 GloryyrolG

Thanks for the detailed report. I have a narrowly scoped patch prepared and tested locally:

  • pass the existing validate flag through both the standard and TransferQueue agent-loop postprocess paths to _compute_score;
  • set DataProto.meta_info[validate] before remote async reward computation;
  • add a CPU-only fake remote reward-handle regression test covering both training and validation values.

Validation completed:

  • 25 passed for tests/experimental/agent_loop/*_on_cpu.py
  • 1 passed for tests/trainer/ppo/v1/test_agent_loop_tq_on_cpu.py
  • Ruff, ruff-format, mypy, compileall, and git diff --check all pass

I also confirmed that there is currently no open PR referencing #7121. @CleanDev-Fix, I see that you outlined essentially the same approach; please let me know if you already have a PR in progress so we can avoid duplicate work.

This work was AI-assisted and will only be submitted after the human submitter reviews every changed line and personally verifies/understands the relevant tests, as required by the repository contribution policy.

YAO-001 avatar Jul 31 '26 06:07 YAO-001