-
Notifications
You must be signed in to change notification settings - Fork 68
Add taskset scheduler #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pan-x-c
merged 14 commits into
agentscope-ai:main
from
chenyushuo:dev/add_task_scheduler
Oct 24, 2025
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cb3f16b
add taskset scheduler
chenyushuo 58c5599
support task selector
chenyushuo 3e9eb60
refactor task scheduler
chenyushuo 607f1db
Add unittest
chenyushuo 7e88eff
add doc str
chenyushuo a24ad19
Merge branch 'main' of github.com:modelscope/Trinity-RFT into dev/add…
chenyushuo 41bd02f
fix unittest
chenyushuo a5241be
Merge branch 'main' of github.com:modelscope/Trinity-RFT into dev/add…
chenyushuo 206dece
apply suggestions from code review
chenyushuo 6c4eb22
Added explanatory documents
chenyushuo cdb4fad
fix pre commit
chenyushuo 1c71acd
bug fix in trainer_test
chenyushuo 6ca7bae
apply suggestions from reviews
chenyushuo 9227af8
apply suggestions from reviews
chenyushuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,259 @@ | ||
| import os | ||
| import unittest | ||
| from typing import Dict, List | ||
|
|
||
| from parameterized import parameterized | ||
|
|
||
| from tests.tools import get_template_config | ||
| from trinity.buffer.task_scheduler import TasksetScheduler | ||
| from trinity.common.config import DataSelectorConfig, FormatConfig, StorageConfig | ||
| from trinity.common.workflows.workflow import Task | ||
|
|
||
|
|
||
| class TestTaskScheduler(unittest.IsolatedAsyncioTestCase): | ||
| temp_output_path = "tmp/test_task_scheduler/" | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| os.makedirs(cls.temp_output_path, exist_ok=True) | ||
|
|
||
| @classmethod | ||
| def tearDownClass(cls): | ||
| super().tearDownClass() | ||
| if os.path.exists(cls.temp_output_path): | ||
| os.system(f"rm -rf {cls.temp_output_path}") | ||
|
|
||
| def _check_batch_tasks(self, batch_tasks: List[Task], indices: List[Dict[str, int]]) -> None: | ||
| for task, index in zip(batch_tasks, indices): | ||
| self.assertEqual(task.index["taskset_id"], index["taskset_id"]) | ||
| self.assertEqual(task.index["index"], index["index"]) | ||
| self.assertEqual( | ||
| task.raw_task["question"], # type: ignore | ||
| f"Question {index['index'] + 1} in subset {index['taskset_id'] + 1}.", | ||
| ) | ||
| self.assertEqual( | ||
| task.raw_task["answer"], # type: ignore | ||
| f"Answer {index['index'] + 1} in subset {index['taskset_id'] + 1}.", | ||
| ) | ||
|
|
||
| @parameterized.expand( | ||
| [ | ||
| ( | ||
| {"selector_type": "sequential"}, | ||
| [ | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 1, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| ], | ||
| ), | ||
| ( | ||
| {"selector_type": "shuffle", "seed": 42}, | ||
| [ | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| {"index": 1, "taskset_id": 1}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| ], | ||
| ), | ||
| ( | ||
| {"selector_type": "random", "seed": 42}, | ||
| [ | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| ], | ||
| ), | ||
| ( | ||
| {"selector_type": "offline_easy2hard", "feature_keys": ["feature_offline"]}, | ||
| [ | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 1, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 1, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 1}, | ||
| {"index": 0, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| ], | ||
| ), | ||
| ( | ||
| {"selector_type": "diff_based", "feature_keys": ["feat_1", "feat_2"]}, | ||
| [ | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 0}, | ||
| {"index": 3, "taskset_id": 1}, | ||
| {"index": 2, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| {"index": 4, "taskset_id": 1}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| {"index": 3, "taskset_id": 0}, | ||
| {"index": 5, "taskset_id": 1}, | ||
| {"index": 1, "taskset_id": 0}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 6, "taskset_id": 1}, | ||
| {"index": 4, "taskset_id": 0}, | ||
| ], | ||
| ), | ||
| ] | ||
| ) | ||
| async def test_task_scheduler(self, task_selector_kwargs, batch_tasks_orders) -> None: | ||
| config = get_template_config() | ||
| config.buffer.batch_size = 2 | ||
| config.buffer.total_epochs = 2 | ||
| config.buffer.explorer_input.taskset = None | ||
| config.buffer.explorer_input.tasksets = [ | ||
| StorageConfig( | ||
| name="subset_1", | ||
| path=os.path.join( | ||
| os.path.dirname(__file__), | ||
| "..", | ||
| "template", | ||
| "data", | ||
| "task_scheduler", | ||
| "subset_1", | ||
| ), | ||
| split="train", | ||
| enable_progress_bar=False, | ||
| format=FormatConfig( | ||
| prompt_key="question", | ||
| response_key="answer", | ||
| ), | ||
| default_workflow_type="math_workflow", | ||
| default_reward_fn_type="math_reward", | ||
| task_selector=DataSelectorConfig( | ||
| **task_selector_kwargs, | ||
| ), | ||
| ), | ||
| StorageConfig( | ||
| name="subset_2", | ||
| path=os.path.join( | ||
| os.path.dirname(__file__), | ||
| "..", | ||
| "template", | ||
| "data", | ||
| "task_scheduler", | ||
| "subset_2", | ||
| ), | ||
| split="train", | ||
| enable_progress_bar=False, | ||
| format=FormatConfig( | ||
| prompt_key="question", | ||
| response_key="answer", | ||
| ), | ||
| default_workflow_type="math_workflow", | ||
| default_reward_fn_type="math_reward", | ||
| task_selector=DataSelectorConfig( | ||
| **task_selector_kwargs, | ||
| ), | ||
| ), | ||
| ] | ||
| config.check_and_update() | ||
|
|
||
| task_scheduler = TasksetScheduler({}, config) | ||
| self.assertEqual(len(batch_tasks_orders) % config.buffer.batch_size, 0) | ||
| for i, start_id in enumerate(range(0, len(batch_tasks_orders), config.buffer.batch_size)): | ||
| batch_tasks_indices = batch_tasks_orders[start_id : start_id + config.buffer.batch_size] | ||
| batch_tasks = await task_scheduler.read_async() | ||
| # for task in batch_tasks: # used for debug | ||
| # print(f"{task.index},") | ||
| self._check_batch_tasks(batch_tasks, batch_tasks_indices) | ||
| if i % 3 == 2: | ||
| # test resume | ||
| state_dict = { | ||
| "latest_iteration": task_scheduler.step, | ||
| "taskset_states": task_scheduler.state_dict(), | ||
| } | ||
| task_scheduler = TasksetScheduler(state_dict, config) | ||
|
|
||
| with self.assertRaises(StopAsyncIteration): | ||
| batch_tasks = await task_scheduler.read_async() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| {"question": "Question 1 in subset 1.", "answer": "Answer 1 in subset 1.", "feature_offline": 0.5, "feat_1": 0.4, "feat_2": 0.3} | ||
| {"question": "Question 2 in subset 1.", "answer": "Answer 2 in subset 1.", "feature_offline": 0.1, "feat_1": 0.1, "feat_2": 0.1} | ||
| {"question": "Question 3 in subset 1.", "answer": "Answer 3 in subset 1.", "feature_offline": 0.4, "feat_1": 0.5, "feat_2": 0.3} | ||
| {"question": "Question 4 in subset 1.", "answer": "Answer 4 in subset 1.", "feature_offline": 0.5, "feat_1": 0.3, "feat_2": 0.5} | ||
| {"question": "Question 5 in subset 1.", "answer": "Answer 5 in subset 1.", "feature_offline": 0.2, "feat_1": 0.1, "feat_2": 0.5} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| {"question": "Question 1 in subset 2.", "answer": "Answer 1 in subset 2.", "feature_offline": 0.2, "feat_1": 0.5, "feat_2": 0.2} | ||
| {"question": "Question 2 in subset 2.", "answer": "Answer 2 in subset 2.", "feature_offline": 0.3, "feat_1": 0.6, "feat_2": 0.2} | ||
| {"question": "Question 3 in subset 2.", "answer": "Answer 3 in subset 2.", "feature_offline": 0.1, "feat_1": 0.7, "feat_2": 0.4} | ||
| {"question": "Question 4 in subset 2.", "answer": "Answer 4 in subset 2.", "feature_offline": 0.5, "feat_1": 0.1, "feat_2": 0.4} | ||
| {"question": "Question 5 in subset 2.", "answer": "Answer 5 in subset 2.", "feature_offline": 0.3, "feat_1": 0.1, "feat_2": 0.7} | ||
| {"question": "Question 6 in subset 2.", "answer": "Answer 6 in subset 2.", "feature_offline": 0.1, "feat_1": 0.7, "feat_2": 0.4} | ||
| {"question": "Question 7 in subset 2.", "answer": "Answer 7 in subset 2.", "feature_offline": 0.1, "feat_1": 0.7, "feat_2": 0.6} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.