-
Notifications
You must be signed in to change notification settings - Fork 11
refactor(sunjx): refactor dataset and reward module #13
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
Open
Jiaxuan-Sun
wants to merge
6
commits into
opendilab:main
Choose a base branch
from
Jiaxuan-Sun:refactor/dataset-reward-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
773a1ee
refactor(sunjx): refactor dataset and reward module
Jiaxuan-Sun 513789d
Remove unnecessary code
Jiaxuan-Sun 875600d
refactor(sunjx): update geo3k to use refactored dataset and reward APIs
Jiaxuan-Sun 43c4cba
refoctor(sunjx): format code
Jiaxuan-Sun 35b9277
feature(sunjx): Resolve merge conflicts with opendilab/main
Jiaxuan-Sun 6989963
Merge branch 'main' into refactor/dataset-reward-module
Jiaxuan-Sun 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,54 @@ | ||
| """ | ||
| Dataset Module for LightRLHF | ||
|
|
||
| This module provides unified interfaces for loading datasets for training, | ||
| evaluation, and pretraining in RLHF workflows. | ||
|
|
||
| Main Features: | ||
| - Unified dataset configuration via DatasetConfig | ||
| - Consistent loading interface via DatasetLoader | ||
| - Support for train, eval, and pretrain datasets | ||
| - Automatic handling of blending_datasets parameters | ||
|
|
||
| Classes: | ||
| DatasetConfig: Configuration class for dataset loading | ||
| DatasetLoader: Unified loader for all dataset types | ||
| """ | ||
|
Jiaxuan-Sun marked this conversation as resolved.
|
||
|
|
||
| # Import new unified interfaces first | ||
| from .config import DatasetConfig | ||
| from .loader import DatasetLoader | ||
|
|
||
| # Import existing dataset classes | ||
| from .process_reward_dataset import ProcessRewardDataset | ||
| from .prompts_dataset import PromptDataset | ||
| from .prompts_dataset_vl import PromptDatasetVL | ||
| from .sft_dataset import SFTDataset | ||
| from .sft_dataset_vl import SFTDatasetVL | ||
|
|
||
| # Import other dataset classes | ||
| from .grm_dataset import GRMDataset | ||
| from .srm_dataset import RankDatasetVL, RankDatasetAL | ||
| from .omnirewardbench import * | ||
| from .imagegen_cot_reward import * | ||
| from .rapidata import * | ||
| from .image_reward_db import * | ||
| from .hpdv3 import * | ||
|
|
||
| from .utils import ( | ||
| extract_answer, | ||
| zero_pad_sequences, | ||
| find_subsequence, | ||
| load_multimodal_content, | ||
| BaseDataHandler, | ||
| ) | ||
| from .process_reward_dataset import ProcessRewardDataset | ||
| from .prompts_dataset import PromptDataset | ||
| from .prompts_dataset_vl import PromptDatasetVL | ||
| from .sft_dataset import SFTDataset | ||
| from .sft_dataset_vl import SFTDatasetVL | ||
|
|
||
| __all__ = ["ProcessRewardDataset", "PromptDataset", "PromptDatasetVL", "SFTDataset", "SFTDatasetVL"] | ||
| __all__ = [ | ||
| "DatasetConfig", | ||
| "DatasetLoader", | ||
| "ProcessRewardDataset", | ||
| "PromptDataset", | ||
| "PromptDatasetVL", | ||
| "SFTDataset", | ||
| "SFTDatasetVL", | ||
| ] | ||
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,205 @@ | ||
| """ | ||
| Dataset Configuration | ||
|
|
||
| This module provides configuration classes for dataset loading, | ||
| unifying parameters for train, eval, and pretrain datasets. | ||
|
|
||
| Main Features: | ||
| - Unified configuration for all dataset types | ||
| - Automatic normalization of data_path and data_probs | ||
| - Factory methods for train/eval/pretrain configurations | ||
| - Validation of configuration parameters | ||
|
|
||
| Classes: | ||
| DatasetConfig: Dataclass for dataset configuration | ||
|
|
||
| Author: lightrft Team | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Optional, Union | ||
|
|
||
|
|
||
| @dataclass | ||
| class DatasetConfig: | ||
| """ | ||
| Configuration for dataset loading. | ||
|
|
||
| This class unifies parameters for train, eval, and pretrain datasets, | ||
| providing a consistent interface for dataset configuration. | ||
|
|
||
| :param data_path: Path(s) to dataset(s), can be string or list | ||
| :type data_path: Optional[Union[str, list]] | ||
| :param data_probs: Sampling probabilities for datasets. Default to "1.0" | ||
| :type data_probs: Optional[Union[str, list]] | ||
| :param split: Dataset split to use. Default to "train" | ||
| :type split: str | ||
| :param max_samples: Maximum number of samples to load | ||
| :type max_samples: Optional[int] | ||
| :param max_len: Maximum sequence length | ||
| :type max_len: Optional[int] | ||
| :param seed: Random seed. Default to 42 | ||
| :type seed: int | ||
| :param return_eval: Whether to return evaluation data. Default to False | ||
| :type return_eval: bool | ||
| """ | ||
|
|
||
| # Data source | ||
| data_path: Optional[Union[str, list]] = None | ||
| data_probs: Optional[Union[str, list]] = "1.0" | ||
|
|
||
| # Split configuration | ||
| split: str = "train" | ||
|
|
||
| # Data filtering | ||
| max_samples: Optional[int] = None | ||
| max_len: Optional[int] = None | ||
|
|
||
| # Additional parameters | ||
| seed: int = 42 | ||
| return_eval: bool = False | ||
|
|
||
| def __post_init__(self): | ||
| """ | ||
| Validate configuration after initialization. | ||
|
|
||
| :raises ValueError: If data_path is None or if data_path and data_probs have mismatched lengths | ||
| """ | ||
| if self.data_path is None: | ||
| raise ValueError("data_path must be specified") | ||
|
|
||
| # Normalize data_probs | ||
| if isinstance(self.data_probs, str): | ||
| # Parse comma-separated string | ||
| self.data_probs = [float(p.strip()) for p in self.data_probs.split(",")] | ||
| elif isinstance(self.data_probs, (int, float)): | ||
| self.data_probs = [float(self.data_probs)] | ||
|
|
||
| # Normalize data_path | ||
| if isinstance(self.data_path, str): | ||
| self.data_path = [self.data_path] | ||
|
|
||
| # Ensure data_path and data_probs have same length | ||
| if len(self.data_probs) == 1 and len(self.data_path) > 1: | ||
| # Repeat single prob for all paths | ||
| self.data_probs = self.data_probs * len(self.data_path) | ||
| elif len(self.data_probs) != len(self.data_path): | ||
| raise ValueError( | ||
| f"data_path and data_probs must have the same length, " | ||
| f"got {len(self.data_path)} and {len(self.data_probs)}" | ||
| ) | ||
|
|
||
| @classmethod | ||
| def for_train( | ||
| cls, | ||
| data_path: Optional[Union[str, list]] = None, | ||
| data_probs: Optional[Union[str, list]] = "1.0", | ||
| split: str = "train", | ||
| max_samples: Optional[int] = None, | ||
| max_len: Optional[int] = None, | ||
| seed: int = 42, | ||
| ) -> "DatasetConfig": | ||
| """ | ||
| Create configuration for training dataset. | ||
|
|
||
| :param data_path: Path(s) to dataset(s) | ||
| :type data_path: Optional[Union[str, list]] | ||
| :param data_probs: Sampling probabilities for datasets | ||
| :type data_probs: Optional[Union[str, list]] | ||
| :param split: Dataset split to use | ||
| :type split: str | ||
| :param max_samples: Maximum number of samples to load | ||
| :type max_samples: Optional[int] | ||
| :param max_len: Maximum sequence length | ||
| :type max_len: Optional[int] | ||
| :param seed: Random seed | ||
| :type seed: int | ||
| :return: DatasetConfig instance for training | ||
| :rtype: DatasetConfig | ||
| """ | ||
| return cls( | ||
| data_path=data_path, | ||
| data_probs=data_probs, | ||
| split=split, | ||
| max_samples=max_samples, | ||
| max_len=max_len, | ||
| seed=seed, | ||
| return_eval=False, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def for_eval( | ||
| cls, | ||
| data_path: Optional[Union[str, list]] = None, | ||
| data_probs: Optional[Union[str, list]] = "1.0", | ||
| split: str = "test", | ||
| max_samples: Optional[int] = None, | ||
| max_len: Optional[int] = None, | ||
| seed: int = 42, | ||
| ) -> "DatasetConfig": | ||
| """ | ||
| Create configuration for evaluation dataset. | ||
|
|
||
| :param data_path: Path(s) to dataset(s) | ||
| :type data_path: Optional[Union[str, list]] | ||
| :param data_probs: Sampling probabilities for datasets | ||
| :type data_probs: Optional[Union[str, list]] | ||
| :param split: Dataset split to use | ||
| :type split: str | ||
| :param max_samples: Maximum number of samples to load | ||
| :type max_samples: Optional[int] | ||
| :param max_len: Maximum sequence length | ||
| :type max_len: Optional[int] | ||
| :param seed: Random seed | ||
| :type seed: int | ||
| :return: DatasetConfig instance for evaluation | ||
| :rtype: DatasetConfig | ||
| """ | ||
| return cls( | ||
| data_path=data_path, | ||
| data_probs=data_probs, | ||
| split=split, | ||
| max_samples=max_samples, | ||
| max_len=max_len, | ||
| seed=seed, | ||
| return_eval=False, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def for_pretrain( | ||
| cls, | ||
| data_path: Optional[Union[str, list]] = None, | ||
| data_probs: Optional[Union[str, list]] = "1.0", | ||
| split: str = "train", | ||
| max_samples: Optional[int] = None, | ||
| max_len: Optional[int] = None, | ||
| seed: int = 42, | ||
| ) -> "DatasetConfig": | ||
| """ | ||
| Create configuration for pretraining dataset. | ||
|
|
||
| :param data_path: Path(s) to dataset(s) | ||
| :type data_path: Optional[Union[str, list]] | ||
| :param data_probs: Sampling probabilities for datasets | ||
| :type data_probs: Optional[Union[str, list]] | ||
| :param split: Dataset split to use | ||
| :type split: str | ||
| :param max_samples: Maximum number of samples to load | ||
| :type max_samples: Optional[int] | ||
| :param max_len: Maximum sequence length | ||
| :type max_len: Optional[int] | ||
| :param seed: Random seed | ||
| :type seed: int | ||
| :return: DatasetConfig instance for pretraining | ||
| :rtype: DatasetConfig | ||
| """ | ||
| return cls( | ||
| data_path=data_path, | ||
| data_probs=data_probs, | ||
| split=split, | ||
| max_samples=max_samples, | ||
| max_len=max_len, | ||
| seed=seed, | ||
| return_eval=False, | ||
| ) | ||
|
|
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.