Skip to content

feat: support router replay r2#15

Merged
void-main merged 2 commits intomainfrom
feat/support_router_replay_r2
Mar 10, 2026
Merged

feat: support router replay r2#15
void-main merged 2 commits intomainfrom
feat/support_router_replay_r2

Conversation

@SolenoidWGT
Copy link
Collaborator

@SolenoidWGT SolenoidWGT commented Feb 14, 2026

PR README: feat: support router replay r2

Summary

Adds router replay r2 support to SamplingClient.compute_logprobs, allowing MoE (Mixture of Experts) models to retrieve forward expert routing data when computing logprobs for use in subsequent forward_backward training.

Change Summary

Item Details
Commit de974c56a799b6f5e3ea27a8fea52ab42b44a705
Files Changed weaver/sampling_client.py
Diff +28 lines, -3 lines

Main Changes

  1. New parameter router_replay_r2

    • Adds optional parameter router_replay_r2: bool = False to compute_logprobs
    • When True, the request body includes router_replay_r2: True so the server returns expert routing data
  2. Return value behavior

    • router_replay_r2=False (default): Returns List[float | None] (per-token logprobs), same as before
    • router_replay_r2=True: Returns a Dict with:
      • "logprobs": per-token logprobs
      • "fwd_expert_replay_data": forward expert routing data (or None for non-MoE or when unavailable)
  3. Purpose

    • fwd_expert_replay_data supports MoE router replay by reusing forward expert selections during backward, keeping training consistent

Usage Example

# Default: only logprobs
logprobs = client.compute_logprobs(prompt=prompt)

# With router replay r2: logprobs and expert routing data
result = client.compute_logprobs(prompt=prompt, router_replay_r2=True)
logprobs = result["logprobs"]
fwd_expert_replay_data = result["fwd_expert_replay_data"]  # for forward_backward

Compatibility

  • Default router_replay_r2=False preserves previous behavior and remains backward compatible
  • Return type and request content change only when router_replay_r2=True is passed

Testing Checklist

  • With router_replay_r2=False, return type and content match the previous implementation
  • With router_replay_r2=True, returned dict includes logprobs and fwd_expert_replay_data
  • On MoE models, fwd_expert_replay_data works correctly with forward_backward

@SolenoidWGT SolenoidWGT force-pushed the feat/support_router_replay_r2 branch from e7ebaf2 to a636b15 Compare March 4, 2026 14:49
Copy link
Contributor

@void-main void-main left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@void-main void-main merged commit 1863caa into main Mar 10, 2026
5 checks passed
@void-main void-main deleted the feat/support_router_replay_r2 branch March 10, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants