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

Method __init__

trinity/buffer/task_scheduler.py:104–161  ·  view source on GitHub ↗

Initialize the scheduler from configuration and previous state (for resume support). Args: explorer_state (Dict): Restoration state from checkpoint (may include progress info) config (Config): Full system configuration containing buffer and taskset settings

(self, explorer_state: Dict, config: Config)

Source from the content-addressed store, hash-verified

102 """
103
104 def __init__(self, explorer_state: Dict, config: Config):
105 """
106 Initialize the scheduler from configuration and previous state (for resume support).
107
108 Args:
109 explorer_state (Dict): Restoration state from checkpoint (may include progress info)
110 config (Config): Full system configuration containing buffer and taskset settings
111 """
112 super().__init__(explorer_state, config)
113
114 # Backward compatibility: old format stored 'latest_task_index' directly
115 if "latest_task_index" in explorer_state:
116 assert len(config.buffer.explorer_input.tasksets) == 1 # old format
117 explorer_state["taskset_states"] = [
118 {
119 "current_index": explorer_state["latest_task_index"],
120 }
121 ]
122
123 self.read_batch_size = config.buffer.batch_size
124 taskset_configs = config.buffer.explorer_input.tasksets
125
126 from trinity.buffer.reader.file_reader import FileReader
127
128 taskset_states = explorer_state.get(
129 "taskset_states", [{"current_index": 0}] * len(taskset_configs)
130 )
131 self.tasksets = []
132 for taskset_config, taskset_state in zip(taskset_configs, taskset_states):
133 assert not taskset_config.is_eval # assume drop last
134 taskset = get_buffer_reader(taskset_config)
135 if not isinstance(taskset, FileReader):
136 raise TypeError(
137 f"Taskset '{taskset_config.name}' has an unsupported type '{type(taskset).__name__}'."
138 f"Currently, only 'FileReader' is supported by TasksetScheduler."
139 )
140 taskset.load_state_dict(taskset_state) # Restore any prior state
141 self.tasksets.append(taskset)
142
143 # Each explorer step calls read once → track step globally
144 self.step = explorer_state.get("latest_iteration", 0)
145
146 # Build flat list indicating how often each taskset should appear per epoch
147 self.base_taskset_ids = []
148 for i, taskset in enumerate(self.tasksets):
149 self.base_taskset_ids.extend([i] * len(taskset))
150 if len(self.base_taskset_ids) == 0:
151 raise ValueError("Empty tasksets provided!")
152
153 self.epoch = self.step * self.read_batch_size // len(self.base_taskset_ids)
154 self.orders = self.build_orders(self.epoch)
155
156 if self.config.buffer.total_steps:
157 self.max_steps = self.config.buffer.total_steps
158 else:
159 self.max_steps = (
160 self.config.buffer.total_epochs * len(self.base_taskset_ids) // self.read_batch_size
161 )

Callers 1

__init__Method · 0.45

Calls 4

build_ordersMethod · 0.95
get_buffer_readerFunction · 0.90
getMethod · 0.45
load_state_dictMethod · 0.45

Tested by

no test coverage detected