-
Notifications
You must be signed in to change notification settings - Fork 47
Add more unittest and support Qwen3 #29
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
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cee3b40
add explorer test
pan-x-c c734193
Merge branch 'main' into feature/update_unittest
pan-x-c baa6687
add unittest for explorer
pan-x-c 5d206c4
add queue-test
pan-x-c 0eeafab
add trainer test
pan-x-c 4831e04
fix tool path
pan-x-c bb43ee5
print tests details
pan-x-c c077aa8
fix logprobs for vllm 0.8.5
pan-x-c 84c0c4d
reduce iteration number and fix runner pool
pan-x-c 7580f1f
fix import
pan-x-c 83d5fb0
fix ray test
pan-x-c 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
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,49 @@ | ||
| import unittest | ||
|
|
||
| import ray | ||
| import torch | ||
|
|
||
| from trinity.buffer.reader.queue_reader import QueueReader | ||
| from trinity.buffer.writer.queue_writer import QueueWriter | ||
| from trinity.common.config import BufferConfig, DatasetConfig | ||
| from trinity.common.constants import AlgorithmType, StorageType | ||
| from trinity.common.experience import Experience | ||
|
|
||
|
|
||
| class TestQueueBuffer(unittest.TestCase): | ||
| def setUp(self): | ||
| ray.init(ignore_reinit_error=True) | ||
|
|
||
| def test_queue_buffer(self): | ||
| total_num = 8 | ||
| put_batch_size = 2 | ||
| read_batch_size = 4 | ||
| meta = DatasetConfig( | ||
| name="test_buffer", | ||
| algorithm_type=AlgorithmType.PPO, | ||
| storage_type=StorageType.QUEUE, | ||
| ) | ||
| config = BufferConfig( | ||
| max_retry_times=3, | ||
| max_retry_interval=1, | ||
| read_batch_size=read_batch_size, | ||
| ) | ||
| writer = QueueWriter(meta, config) | ||
| reader = QueueReader(meta, config) | ||
| exps = [ | ||
| Experience( | ||
| tokens=torch.tensor([float(j) for j in range(i + 1)]), | ||
| prompt_length=i, | ||
| reward=float(i), | ||
| logprobs=torch.tensor([0.1]), | ||
| ) | ||
| for i in range(1, put_batch_size + 1) | ||
| ] | ||
| for _ in range(total_num // put_batch_size): | ||
| writer.write(exps) | ||
| writer.finish() | ||
| for _ in range(total_num // read_batch_size): | ||
| exps = reader.read() | ||
| self.assertEqual(len(exps), read_batch_size) | ||
| print(f"finish read {read_batch_size} experience") | ||
| self.assertRaises(StopIteration, reader.read) |
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
Empty file.
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,67 @@ | ||
| """Tests for explorer.""" | ||
| import os | ||
| import unittest | ||
| from datetime import datetime | ||
|
|
||
| import ray | ||
|
|
||
| from tests.tools import ( | ||
| TensorBoardParser, | ||
| get_checkpoint_path, | ||
| get_model_path, | ||
| get_template_config, | ||
| get_unittest_dataset_config, | ||
| ) | ||
| from trinity.cli.launcher import explore | ||
| from trinity.common.constants import MonitorType | ||
|
|
||
|
|
||
| class BaseExplorerCase: | ||
| def setUp(self): | ||
| ray.init(ignore_reinit_error=True) | ||
| self.config = get_template_config() | ||
| self.config.model.model_path = get_model_path() | ||
| self.config.explorer.engine_type = "vllm_async" | ||
| self.config.explorer.repeat_times = 2 | ||
| self.config.monitor.monitor_type = MonitorType.TENSORBOARD | ||
| self.config.monitor.project = "Trinity-unittest" | ||
| self.config.model.checkpoint_path = get_checkpoint_path() | ||
| self.config.synchronizer.sync_iteration_interval = 2 | ||
| self.config.explorer.eval_interval = 4 | ||
| self.config.trainer.eval_interval = 4 | ||
|
|
||
|
|
||
| class TestExplorerCountdownEval(BaseExplorerCase, unittest.TestCase): | ||
| def test_explorer(self): | ||
| self.config.data = get_unittest_dataset_config("countdown") | ||
| self.config.monitor.name = f"explore-eval-{datetime.now().strftime('%Y%m%d%H%M%S')}" | ||
| self.config.check_and_update() | ||
| explore(self.config) | ||
| parser = TensorBoardParser(os.path.join(self.config.monitor.job_dir, "tensorboard")) | ||
| rollout_metrics = parser.metric_list("rollout") | ||
| self.assertTrue(len(rollout_metrics) > 0) | ||
| eval_metrics = parser.metric_list("eval") | ||
| self.assertTrue(len(eval_metrics) > 0) | ||
| self.assertEqual(parser.metric_max_step(rollout_metrics[0]), 8) | ||
| self.assertEqual(parser.metric_max_step(eval_metrics[0]), 8) | ||
|
|
||
| def tearDown(self): | ||
| pass | ||
|
|
||
|
|
||
| class TestExplorerCountdownNoEval(BaseExplorerCase, unittest.TestCase): | ||
| def test_explorer(self): | ||
| self.config.data = get_unittest_dataset_config("countdown") | ||
| self.config.monitor.name = f"explore-no-eval-{datetime.now().strftime('%Y%m%d%H%M%S')}" | ||
| self.config.data.eval_split = None | ||
| self.config.check_and_update() | ||
| explore(self.config) | ||
| parser = TensorBoardParser(os.path.join(self.config.monitor.job_dir, "tensorboard")) | ||
| rollout_metrics = parser.metric_list("rollout") | ||
| self.assertTrue(len(rollout_metrics) > 0) | ||
| eval_metrics = parser.metric_list("eval") | ||
| self.assertTrue(len(eval_metrics) == 0) | ||
| self.assertEqual(parser.metric_max_step(rollout_metrics[0]), 8) | ||
|
|
||
| def tearDown(self): | ||
| pass |
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,4 @@ | ||
| {"question": "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer.\nUser: Using the numbers [44, 19, 35], create an equation that equals 98. You can use basic arithmetic operations (+, -, *, /) and each number can only be used once. Show your work in <think> </think> tags. And return the final answer in <answer> </answer> tags, for example <answer> (1 + 2) / 3 </answer>.\nAssistant: Let me solve this step by step.\n<think>", "answer": "{\"numbers\": [44, 19, 35], \"target\": 98}"} | ||
| {"question": "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer.\nUser: Using the numbers [63, 95, 96], create an equation that equals 64. You can use basic arithmetic operations (+, -, *, /) and each number can only be used once. Show your work in <think> </think> tags. And return the final answer in <answer> </answer> tags, for example <answer> (1 + 2) / 3 </answer>.\nAssistant: Let me solve this step by step.\n<think>", "answer": "{\"numbers\": [63, 95, 96], \"target\": 64}"} | ||
| {"question": "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer.\nUser: Using the numbers [95, 11, 56], create an equation that equals 28. You can use basic arithmetic operations (+, -, *, /) and each number can only be used once. Show your work in <think> </think> tags. And return the final answer in <answer> </answer> tags, for example <answer> (1 + 2) / 3 </answer>.\nAssistant: Let me solve this step by step.\n<think>", "answer": "{\"numbers\": [95, 11, 56], \"target\": 28}"} | ||
| {"question": "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer.\nUser: Using the numbers [19, 74, 45], create an equation that equals 48. You can use basic arithmetic operations (+, -, *, /) and each number can only be used once. Show your work in <think> </think> tags. And return the final answer in <answer> </answer> tags, for example <answer> (1 + 2) / 3 </answer>.\nAssistant: Let me solve this step by step.\n<think>", "answer": "{\"numbers\": [19, 74, 45], \"target\": 48}"} |
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.