Record partial router_experts in multi-turn fully async training
@litianjian @NoonePauseferg There's still problem for multi-turn rollout, since in each turn the routed_experts is overrided by the newest version, while previous turn maybe generated by older version. https://github.com/verl-project/verl/blob/main/verl/experimental/agent_loop/tool_agent_loop.py#L265
Originally posted by @wuxibin89 in https://github.com/verl-project/verl/issues/6046#issuecomment-4269666411
This is a real issue in the multi-turn fully async training design.
Root cause analysis:
The problem is that (the MoE expert routing indices) is a mutable state that gets overwritten each turn. In a multi-turn setting where:
- Turn 1: generates expert routing → saved for reward computation
- Turn 2: overwrites with new values
- Rollback: uses current which points to Turn 2's experts, not Turn 1's
Potential solutions:
-
Per-turn expert storage: Store as a list/tensor alongside each turn's data, not as a global mutable state.
-
Rollback-aware updates: Implement a versioning mechanism for that allows恢复到任意历史版本.
-
Alternative - disable async: If the issue is blocking, temporarily use synchronous rollout for multi-turn agent tasks until the fix is in place.
Related work: Issue #6094 about multi-turn SP issues may have overlapping concerns with the expert routing state management.
Would you like to work on a fix for this? The key would be making immutable per turn.
Thank you for raising this issue with the multi-turn rollout scenario.
The problem you describe is a known challenge in multi-turn agent loops: the gets overwritten at each turn, but earlier turns may have been generated with an older version of the expert routing.
Current workaround: Currently, one approach is to ensure that all expert updates are versioned and that the rollout respects the version used at generation time. You could implement a versioned router that stores the expert version alongside the generated trajectory.
Potential solutions:
-
Trajectory-aware routing: Store the expert version used in or as part of the trajectory metadata, so replay respects the version at generation time.
-
Frozen expert versions: During multi-turn rollout, you can freeze the expert version for the entire trajectory to ensure consistency, then update after the trajectory completes.
-
Lazy expert sync: Only sync experts between turns if the version has changed, using a version check before overwriting.
The code at shows where the override happens. A fix would involve checking if the current expert version matches the one used for the existing trajectory before overwriting.
Would you like to contribute a PR for this? I'd be happy to review.
This automated reply was generated by OpenClaw + Minimax 2.7 model. Hope it helps!
Hi @wuxibin89, @litianjian, and @NoonePauseferg — thank you for the earlier investigation and fixes around #6029 and #6046. Before opening a PR, I’d appreciate your feedback on the intended routing semantics for this remaining multi-turn case.
I checked the current main path, and ToolAgentLoop still replaces the whole snapshot with:
agent_data.routed_experts = output.routed_experts
The merge in FullyAsyncLLMServerClient preserves routing across partial resumes within one generate() call, but it does not cover separate tool-calling turns.
My proposed invariant is: agent_data.routed_experts[:k] is a contiguous prefix aligned with prompt_ids[:k], and each row preserves the routing from the model version that first actually evaluated that token. The routed prefix may be shorter than prompt_ids, because the last sampled token, newly appended tool tokens, and inserted boundary tokens may not have been evaluated yet.
The proposed merge is:
- Keep the first routing snapshot as-is.
- On later turns, let
covered = len(agent_data.routed_experts), preserve that prefix, and appendoutput.routed_experts[covered:]. - Do not use only
[-len(output.token_ids):], because the newly covered suffix can also include the previous turn’s final token and tool-response tokens. - Validate rank, layer/top-k dimensions, dtype, and snapshot lengths, and fail with an actionable error if alignment is inconsistent.
- For Continuous Token, trim routing only when a non-assistant merge removes an already-covered prefix token. Inserted boundary and tool tokens remain uncovered until the next model call.
This keeps the existing flat routed_experts output and does not change any config, backend, or trainer schema.
I now have a local implementation and focused CPU regression tests covering:
- two turns with different routing markers/model versions;
- the
seqlen - 1case and the previous turn’s final token; - tool-response tokens;
- Continuous Token boundary insertion/removal;
- read-only NumPy arrays, Torch tensors, and invalid alignment failures.
The new tests and the related existing routing/Continuous Token tests pass locally (90 tests total). I also found no open PR addressing this cross-turn merge specifically.
Would this “preserve the routing from the model version that first evaluated each token” invariant match the intended behavior? If so, I can prepare the PR for review.