verl icon indicating copy to clipboard operation
verl copied to clipboard

[feature] There is two types of multi-turn rollout (and training!), maybe verl only support one?

Open Fu-Dayuan opened this issue 1 year ago • 11 comments

Image

非常感谢作者的辛苦工作!!!我看到最近verl加入了multi-turn rollout,感觉里面只实现了其中一种情况(以及似乎没有看到训练中有对应的优化)所以提个issue询问一下。

如图,左右两种情况是两种不同的multi-turn。左边会将historical信息直接拼到input中不修改前缀(也就是原版react),右边每次会修改前缀(不管是GUI领域只输入最新截图还是因为input太长需要截断什么的)。个人感觉这两个需要分别考虑,因为对于一个traj左边的只需要返回一个token list,右边需要 list of token list(同时,reward也可以是标量/轮次数行的向量),这可能导致得重新设计一下protocol的数据结构

同时,右边这种情况再training的时候也会出现一些decision choice,比如是不是要把同一个traj的不同turn的捏在一起算?还是当成单独的一个turn直接在batch里随机shuffle(后一种情况还需要考虑batch size是固定的还是按照梯度反传次数动态调整,我看dapo应该是动态的?),是不是需要扔掉一些步(agentrefine、ui-tras)之类的~

不知道未来会不会把右图这个feature的rollout & training加进去? 希望作者们能看到这个issue(同时可以在这个issue里讨论讨论真实需要的feature~)

Fu-Dayuan avatar Apr 18 '25 04:04 Fu-Dayuan

甚至如果未来traj轮次数特别多(>>1),可能右边这种才是主要的, 所以感觉这个feature加进去还挺必要的

Fu-Dayuan avatar Apr 18 '25 05:04 Fu-Dayuan

This is a good idea, especially for the right example in the figure. Look forward to that feature!

lxqpku avatar Apr 21 '25 06:04 lxqpku

Hey, just wondering where this feature is at right now and if there's any latest progress?

Tshiyao avatar May 22 '25 12:05 Tshiyao

同问进展

fangjiayueyuan avatar Jul 22 '25 02:07 fangjiayueyuan

@Fu-Dayuan @fangjiayueyuan 最近增加了AgentLoop的抽象用于多轮对话,目前的AgentLoop一个输入prompt只输出了一个多轮对话的trajectory。

AgentLoopOutput only output one trajectory for a given prompt, multiple trajectories output is still under discussion.

对于复杂的场景,一个输入prompt确实可能会有多个trajectories输出

  • 上下文窗口受限,每次会修改前缀(不管是GUI领域只输入最新截图还是因为input太长需要截断什么的)
  • 复杂任务拆分多个步骤,每个步骤有不同的system prompt&tool,例如: Gemini Fullstack LangGraph Quickstart

AgentLoop的输出支持多个trajectories改动很容易,类似如下改动即可,唯一要注意的就是用户需要给出各个trajectory的reward_score。

class Trajectory:
    prompt_ids: list[int]
    """Prompt token ids."""
    response_ids: list[int]
    """Response token ids including LLM generated token, tool response token."""
    response_mask: list[int]
    reward_score: float = 0.0
    """Reward score for the trajectory."""

class AgentLoopOutput(BaseModel):
    """Agent loop output."""

    trajectories: list[Trajectory]

真正困难在于多trajectories返回之后如何训练?对于GRPO,一个prompt需要多次采样(n=8/16)计算相对优势,但是一个prompt多次采样,无法保证sub trajectories也能对齐,这就导致sub trajectories无法计算相对优势。所以,对于多trajectories输出的情况,可能只能用PPO进行训练。

wuxibin89 avatar Jul 23 '25 03:07 wuxibin89

同问进展

MIKE-GUO233 avatar Sep 18 '25 06:09 MIKE-GUO233

我很需要这个特性。

Qiao0124 avatar Dec 09 '25 03:12 Qiao0124

或许可以参考 ms-swift 中的对 sub trajectory 的做法: https://swift.readthedocs.io/en/latest/Instruction/GRPO/DeveloperGuide/multi_turn.html#customising-the-interaction-logic

Customising the interaction logic

In the default logic we treat the whole multi-turn rollout as one trajectory when computing the loss. This assumes the model’s history is not modified during interaction.

In some scenarios you may need to dynamically change the history during rollout (e.g., compressing context). In that case each turn should be treated as a separate trajectory.

A common scenario is for “thinking” models: during real inference the model keeps only the last reasoning step and discards previous ones.

自定义多轮交互逻辑

在以上默认逻辑中,我们用一条轨迹来计算多轮 rollout 的损失,这里需要假设多轮交互的过程中,模型的历史信息没有收到改变。

而在一些多轮场景中,我们可以需要在多轮 rollout 过程中动态地修改模型的历史信息(比如压缩历史信息),此时,我们需要将每轮的 rollout 单独作为一条轨迹进行训练。

比较常见的一种场景是对于思考类模型,在实际推理过程中,模型通常只会保留最后一轮的思考内容,而忽略历史模型回复中的思考内容。

Qiao0124 avatar Dec 09 '25 03:12 Qiao0124

https://github.com/verl-project/verl/pull/5443 https://github.com/verl-project/verl/issues/5375

huaiyizhao avatar Mar 03 '26 10:03 huaiyizhao

中文:

我建议这个 issue 先保持打开,但可以更新一下当前状态:

  • 现在 verl/trainer/ppo/v1/agent_loop_tq.py 里的 v1/TransferQueue 路径已经可以接收 AgentLoopOutput | list[AgentLoopOutput],并把同一个 rollout/session 里的多条输出按 {uid}_{session_id}_{index} 写入 TransferQueue;verl/trainer/ppo/v1/replay_buffer.py 也把这个 index 作为 trajectory 存储格式的一部分。
  • 这说明“一个 agent rollout 产生多条 trajectory”的数据通路在 new unified trainer / v1 路径中已经有部分支持。#6271 关闭前维护者也说明应使用 new unify trainer,因为它支持 multi-trajectories in one agent loop output。
  • 但这个 issue 里右图场景的完整问题还没有完全闭环:#5443 和 #6271 都是 closed but not merged;docs/advance/agent_loop.rst 仍然写着 multiple trajectories output is still under discussion;context compression / AgentGateway / prefix-tree training efficiency 仍分别在 #5375、#5790、#6401 中继续讨论。

所以我认为这个 issue 目前更适合保留为总跟踪项,或者由维护者明确拆分为:已由 v1/TQ 支持的多 trajectory 输出、仍待完善的 context compression/turn-wise training recipe、以及前缀树/attention 优化三个方向。

English:

I would suggest keeping this issue open for now, but updating the current status:

  • The v1/TransferQueue path in verl/trainer/ppo/v1/agent_loop_tq.py can already accept AgentLoopOutput | list[AgentLoopOutput] and stores multiple outputs from one rollout/session under {uid}_{session_id}_{index}. verl/trainer/ppo/v1/replay_buffer.py also documents this trajectory index as part of the storage format.
  • This means the data path for “one agent rollout producing multiple trajectories” is partially supported in the new unified trainer / v1 path. Before closing #6271, a maintainer also pointed users to the new unify trainer because it supports multi-trajectories in one agent loop output.
  • However, the full right-hand-side scenario in this issue does not look fully closed yet: #5443 and #6271 were closed without merge; docs/advance/agent_loop.rst still says multiple trajectory output is under discussion; context compression, AgentGateway, and prefix-tree training efficiency are still being discussed in #5375, #5790, and #6401 respectively.

So I think this issue is still useful as a tracking issue, unless maintainers explicitly split it into three parts: multi-trajectory output already covered by v1/TQ, remaining context-compression / turn-wise training recipes, and prefix-tree / attention optimization work.

This response was generated by a scheduled Codex GPT5.5 issue processing task.

Kirrito-k423 avatar Jul 04 '26 01:07 Kirrito-k423

Great to see that many of you are working on similar directions! We would like to briefly introduce our project here, which may be helpful for ongoing efforts.

In our project (https://github.com/XYZ-AI-Lab/axrl/), we have already integrated Magi Attention for prefix merging training. So far, we have conducted the following tests:

  • Forward bit consistency. Taking Qwen3 as an example, the hidden states before self-attention in the first layer are an exact match compared with the original GPT model forward. After self-attention, due to differences in CP (context parallel) computation ordering, there can be at most one BF16 ULP-level difference. Our test can be found at: tests/mcore/test_magi_attention.py
  • Prefix tree merging in black-box RL. We use prefix tree merging as the default setting in black-box RL training, and have observed steady training improvements.
  • Handling the length-control issue in prefix merging. Fully merging all sequences into a single sample can lead to uncontrolled sequence lengths. We currently address this with two approaches:
    • Split the merged prefixes into multiple trees according to the maximum allowed length.
    • Ensure that the number of merged trees does not affect the final loss and gradient results. In other words, the packing strategy (i.e., how many trees the samples are merged into) should be transparent to the algorithm.
  • Training and forward/backward validation. We have tested Qwen3.0 training and Qwen3.6 language model forward passes. The backward pass of Qwen3.6 still has some minor issues that we have not yet fixed.
  • Magi Attention mismatch score under MoE models. We compared the mismatch score of Magi Attention under MoE settings, and it is largely on par with the default GPT model forward. The test can be found at: tests/magi-forward/test_magi_forward_r3_mismatch.py

Here is our repository: https://github.com/XYZ-AI-Lab/axrl/

We welcome everyone to try axrl. If it can be useful for your work, we would be very happy to contribute to the community. Looking forward to your feedback and discussions!

lee-junjie avatar Aug 07 '26 03:08 lee-junjie