Repository navigation
Open
Description
Problem
R3 code is spread across the tree, and the backend-agnostic parts live inside a backend package:
nemo_rl/models/megatron/router_replay.pyholds the Megatron replay hooks, but also backend-agnostic helpers:router_replay_enabled,configure_vllm_for_router_replay,validate_router_replay_config.nemo_rl/models/automodel/router_replay.py(Automodel replay) importsrouter_replay_enabledfromnemo_rl.models.megatron.router_replay, so the Automodel backend depends on the Megatron package for a function that only reads the policy config. The same import exists inmodels/automodel/setup.pyandpolicy/workers/automodel_policy_worker.py.nemo_rl/utils/r3_trace.py,nemo_rl/utils/routed_experts_codec.pyandnemo_rl/experience/route_assembly.pyare R3-only but sit in generic directories.- R3 constants (
ROUTED_EXPERTS_MISSING_ROUTE_SENTINEL, dtype helpers) live innemo_rl/models/generation/interfaces.py, and the config typesRouterReplayConfig/RouterReplayConfigDisabledinnemo_rl/models/policy/__init__.py. - The enabled check is also re-inlined as
bool((cfg.get("router_replay") or {}).get("enabled", False))inmodels/policy/tq_policy.pyandexperience/sync_rollout_actor.py.
Proposal
Add a nemo_rl/router_replay/ package and move the R3 code there:
| Module | Contents |
|---|---|
config.py |
router_replay_enabled, validate_router_replay_config, configure_vllm_for_router_replay (and optionally the config TypedDicts) |
megatron.py |
current models/megatron/router_replay.py |
automodel.py |
current models/automodel/router_replay.py |
trace.py |
current utils/r3_trace.py |
codec.py |
current utils/routed_experts_codec.py |
route_assembly.py |
current experience/route_assembly.py |
The routed-experts constants in generation/interfaces.py can move too, or stay if the generation interface needs them without importing the new package. Callers (grpo.py, single_controller_utils/setup.py, the Megatron/Automodel setup and policy workers, tq_policy.py, sync_rollout_actor.py) switch to the shared router_replay_enabled.
Backend modules should keep their megatron.core imports inside functions, as today, so importing nemo_rl.router_replay never pulls in Megatron-Core.
Notes
- Pure move, no behavior change. Existing tests that patch
router_replay_enabledon a caller module (for examplesc_setup_mod) keep working as long as callers keep importing the name into their own namespace. - Not done in feat(automodel): support rollout routing replay (R3) on the Automodel policy #4458 to keep that PR scoped to Automodel R3 support.
Metadata
Metadata
Assignees
Labels
No labels
Activity