rlightning.policy.utils.router¶
- class rlightning.policy.utils.router.AsyncRouter[source]¶
Bases:
ABCAbstract base class for request routing strategies.
- abstractmethod assign(current_loads: List[int], num_tasks: int, env_ids: Sequence[str] | None = None) List[int][source]¶
Assign num_tasks to policy indices.
- Parameters:
current_loads – List of current loads for each policy.
num_tasks – Number of tasks to assign.
env_ids – Optional sequence of environment IDs for affinity-based routing.
- Returns:
List of policy indices corresponding to the chosen target for each task.
- class rlightning.policy.utils.router.NodeAffinityRouter(component_distribution: Dict[str, Dict[str, Dict[str, Any]]], policy_node_ids: List[str] | None = None)[source]¶
Bases:
AsyncRouterRoute tasks to policies on the same node as env workers.
- assign(current_loads: List[int], num_tasks: int, env_ids: Sequence[str] | None = None) List[int][source]¶
Assign num_tasks to policy indices.
- Parameters:
current_loads – List of current loads for each policy.
num_tasks – Number of tasks to assign.
env_ids – Optional sequence of environment IDs for affinity-based routing.
- Returns:
List of policy indices corresponding to the chosen target for each task.
- class rlightning.policy.utils.router.SimpleRouter[source]¶
Bases:
AsyncRouterLoad-balancing router that assigns tasks to policies with minimum load.
- class rlightning.policy.utils.router.SyncNodeAffinityRouter(eval_policies: Sequence[Any], component_distribution: Dict[str, Dict[str, Dict[str, Any]]])[source]¶
Bases:
SyncRouterSync router that prefers policies on the same node as env workers.
This router supports concurrent scheduling across different nodes while maintaining sequential scheduling within each node through per-node locks.
- select_policy(env_id: str) Any[source]¶
Select policy using round-robin within the target node.
With max_pending_tasks > 1 on the eval TaskSubmitter, backpressure is handled by TaskSubmitter itself. The router only needs to distribute tasks evenly across eval policies on the correct node — no idle-check RPCs needed.
- Parameters:
env_id – Environment ID to determine target node.
- Returns:
Selected policy instance.
- class rlightning.policy.utils.router.SyncRouter[source]¶
Bases:
ABCAbstract base class for sync rollout routing strategies.
- class rlightning.policy.utils.router.SyncSimpleRouter(eval_policies: Sequence[Any])[source]¶
Bases:
SyncRouterSync router using a single idle deque.
- rlightning.policy.utils.router.create_router(rollout_mode: str, router_type: str, eval_policies: Sequence[Any], global_resource_manager=None) SyncRouter | AsyncRouter[source]¶
Factory for sync routers.
- Parameters:
rollout_mode – Rollout mode (“sync” or “async”).
router_type – Type of router (“simple” or “node_affinity”).
eval_policies – List of eval policy instances.
global_resource_manager – Global resource manager. Required for “node_affinity” router.
- Returns:
A SyncRouter or AsyncRouter instance.