-
Notifications
You must be signed in to change notification settings - Fork 21
[data] feat: add DataChecker #28
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3935645
[data] feat: add base data class framework with validation support (#26)
Debonex 6470387
[data] feat: add datachecker (#27)
tardis-key 8dfb40b
Unify logging and address other code review comments
tardis-key 2bb2897
update requirement
tardis-key 3a631f3
address code review comments from gemini
tardis-key de2181d
adjust ut
tardis-key 9910216
pre-commit
tardis-key 306e668
pre-commit
tardis-key 472aa62
Merge remote-tracking branch 'upstream'
tardis-key 39c6165
format uworkflow yml
tardis-key 765501f
Address review comments
tardis-key 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ RL-Insight 是一个强化学习性能数据快速分析的可视化工具,基 | |
| - Pandas | ||
| - Plotly | ||
| - NumPy | ||
| - Loguru | ||
|
|
||
| ## 二、快速使用 | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ dependencies = [ | |
| "pandas", | ||
| "plotly", | ||
| "pytest", | ||
| "loguru" | ||
| ] | ||
|
|
||
| [project.urls] | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ | |
| numpy<2.0.0 | ||
| pandas | ||
| plotly | ||
| pytest | ||
| pytest | ||
| loguru | ||
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,60 @@ | ||
| # Copyright (c) 2025 verl-project authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Base data definitions for RL-Insight.""" | ||
|
|
||
| from typing import Any, List | ||
| from .rules import ValidationRule, PathExistsRule, DataValidationError | ||
| from enum import Enum | ||
| from loguru import logger | ||
|
|
||
|
|
||
| class DataEnum(Enum): | ||
| """Enum for data types in RL-Insight.""" | ||
|
|
||
| # input data type of parser | ||
| MULTI_JSON = "multi_json" | ||
| VERL_LOG = "verl_log" | ||
| # output data type of parser, input data type of visualizer | ||
| SUMMARY_EVENT = "summary_event" | ||
| # other data type | ||
| UNKNOWN = "unknown" | ||
|
|
||
|
|
||
| class DataChecker: | ||
| """Base data class for RL-Insight.""" | ||
|
|
||
| rules: dict[DataEnum, List[ValidationRule]] = { | ||
| DataEnum.MULTI_JSON: [PathExistsRule()], | ||
| DataEnum.VERL_LOG: [], | ||
| DataEnum.SUMMARY_EVENT: [], | ||
| DataEnum.UNKNOWN: [], | ||
| } | ||
|
tardis-key marked this conversation as resolved.
|
||
|
|
||
| def __init__(self, data_type: DataEnum, data: Any): | ||
| self.data_type = data_type | ||
| self.data = data | ||
|
|
||
| def run(self): | ||
| """Validate the data""" | ||
| errors = [] | ||
| if self.data_type not in self.rules: | ||
| raise ValueError(f"Invalid data type: {self.data_type}") | ||
| rules = self.rules[self.data_type] | ||
| for rule in rules: | ||
| if not rule.check(self.data): | ||
| errors.append(rule.error_message) | ||
| if errors: | ||
| raise DataValidationError("Data validation failed", errors) | ||
| logger.info(f"Data validation passed for {self.data_type}") | ||
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,64 @@ | ||
| # Copyright (c) 2025 verl-project authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import List, Any | ||
| from abc import ABC, abstractmethod | ||
| from pathlib import Path | ||
| from typing import Optional | ||
|
|
||
|
|
||
| class DataValidationError(Exception): | ||
| """Exception raised when data validation fails.""" | ||
|
|
||
| def __init__(self, message: str, errors: Optional[List[str]] = None): | ||
| super().__init__(message) | ||
| self.errors = errors or [] | ||
|
|
||
| def __str__(self) -> str: | ||
| if self.errors: | ||
| return f"{super().__str__()}\n - " + "\n - ".join(self.errors) | ||
| return super().__str__() | ||
|
|
||
|
|
||
| class ValidationRule(ABC): | ||
| """Validation rule base class""" | ||
|
|
||
| def __init__(self): | ||
| self._error_message: str = "" | ||
|
|
||
| @abstractmethod | ||
| def check(self, data) -> bool: | ||
| pass | ||
|
|
||
| @property | ||
| def error_message(self) -> str: | ||
| return self._error_message | ||
|
|
||
|
|
||
| class PathExistsRule(ValidationRule): | ||
| def check(self, data: Any) -> bool: | ||
| if not isinstance(data, str): | ||
| self._error_message = "Data object is not a path" | ||
| return False | ||
| try: | ||
| path = Path(data) | ||
| if not path.is_dir(): | ||
| self._error_message = ( | ||
| f"Source path is not a directory or does not exist: {data}" | ||
| ) | ||
| return False | ||
| return True | ||
| except TypeError as e: | ||
| self._error_message = f"Error checking path {data}: {e}" | ||
| return False |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the current import sequence pass the pre-commit check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have ran the pre_commit again, it appears to be accepatable