MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / Scheduler

Class Scheduler

trinity/explorer/scheduler.py:221–871  ·  view source on GitHub ↗

Scheduler for rollout tasks. Supports scheduling tasks to multiple runners, retrying failed tasks, and collecting results at different levels.

Source from the content-addressed store, hash-verified

219
220
221class Scheduler:
222 """Scheduler for rollout tasks.
223
224 Supports scheduling tasks to multiple runners, retrying failed tasks,
225 and collecting results at different levels.
226 """
227
228 def __init__(
229 self,
230 config: Config,
231 ):
232 self.logger = get_logger(__name__)
233 self.config = config
234 self.namespace = ray.get_runtime_context().namespace
235 self.default_timeout = config.explorer.max_timeout * (config.explorer.max_retry_times + 1)
236 self.max_retry_times = config.explorer.max_retry_times
237 self.max_repeat_times = config.explorer.max_repeat_times_per_runner
238 self.default_batch_size = config.buffer.batch_size
239 self.running = False
240
241 self.runner_num = (
242 config.explorer.rollout_model.engine_num * config.explorer.runner_per_model
243 )
244 self.runners: Dict[int, RunnerWrapper] = dict()
245 self.idle_runners: set[int] = set() # runner_id of idle runners
246 self.busy_runners: Dict[int, RunningTaskState] = dict() # runner_id -> running state
247
248 self.pending_tasks: Dict[Union[int, str], deque] = defaultdict(
249 deque
250 ) # batch_id -> (task, repeat_times, run_id_base)
251 self.running_tasks: Dict[Union[int, str], set[asyncio.Future]] = defaultdict(
252 set
253 ) # batch_id -> futures
254 self.task_num_map: Dict[Union[int, str], int] = defaultdict(
255 int
256 ) # batch_id -> tasks scheduled under this batch_id
257 self.running_task_state_map: Dict[asyncio.Future, RunningTaskState] = dict()
258 self.batch_is_eval_map: Dict[Union[int, str], bool] = dict()
259 self.completed_tasks: Dict[
260 Union[int, str], Dict[Union[int, str], CompletedTaskResult]
261 ] = defaultdict(
262 dict
263 ) # batch_id -> results
264 self.background_tasks: set[asyncio.Task] = set()
265
266 self.scheduler_task: Optional[asyncio.Task] = None
267 self.monitor_task: Optional[asyncio.Task] = None
268
269 self.total_running_time = 0.0
270 self.total_completed_steps = 0
271 self.total_completed_sub_tasks = 0
272 self.total_completed_tasks = 0
273
274 async def _create_runner(
275 self,
276 runner_id: int,
277 ):
278 runner = RunnerWrapper(

Calls

no outgoing calls