-
Notifications
You must be signed in to change notification settings - Fork 43
【Hackathon 9th Sprint No.89】feat:Add extend logic for fake_perf_degrad #423
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
9 commits
Select commit
Hold shift + click to select a range
8b18004
Hackathon NO.89 Update
3619117923 55caedc
Code Fix
699574 5381b74
Update samples_statistics.py
699574 5ccd739
Revert "Update samples_statistics.py"
699574 05f42f9
Revert "Code Fix"
699574 218c860
Code Fix
3619117923 359ed0c
Code Fix 2
3619117923 06cab86
code Fix 3
3619117923 85b4721
code Fix 4
3619117923 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,77 @@ | ||
| from enum import IntEnum | ||
|
|
||
| from graph_net.positive_tolerance_interpretation import PositiveToleranceInterpretation | ||
|
|
||
|
|
||
| class DefaultErrorEnum(IntEnum): | ||
| """ | ||
| Values correspond to the minimum tolerance level required. | ||
| """ | ||
|
|
||
| kAccuracyViolation = 1 # Accuracy | ||
| kRuntimeFailure = 2 # Includes Runtime, NaN, Inf, TypeMismatch, etc. | ||
| kCompilationFailed = 3 # Compile Failure | ||
|
|
||
| @classmethod | ||
| def get_error_enum(cls, base_error_type: str) -> "DefaultErrorEnum": | ||
| if not base_error_type: | ||
| return cls.kRuntimeFailure | ||
|
|
||
| etype = base_error_type.lower() | ||
|
|
||
| if "accuracy" in etype: | ||
| return cls.kAccuracyViolation | ||
|
|
||
| if "compile_fail" in etype: | ||
| return cls.kCompilationFailed | ||
|
|
||
| return cls.kRuntimeFailure | ||
|
|
||
|
|
||
| class DefaultPositiveToleranceInterpretation(PositiveToleranceInterpretation): | ||
| """ | ||
| Legacy interpretation: | ||
| - t=1: Accuracy errors tolerated. | ||
| - t=3: Runtime/Compilation errors tolerated. | ||
| """ | ||
|
|
||
| def __init__(self, *argc, **kwargs): | ||
| super().__init__(*argc, **kwargs) | ||
|
|
||
| def type_name(self) -> str: | ||
| return "default" | ||
|
|
||
| def get_errno(self, error_type: str) -> int: | ||
| return DefaultErrorEnum.get_error_enum(error_type).value | ||
|
|
||
| def get_error_type(self, errno: int) -> str: | ||
| mapping = {1: "accuracy", 2: "runtime_fail", 3: "compile_fail"} | ||
| return mapping.get(errno, "unknown_error") | ||
|
|
||
| def get_tolerance_mapping(self) -> dict[int, int]: | ||
| return { | ||
| DefaultErrorEnum.kAccuracyViolation.value: 1, | ||
| DefaultErrorEnum.kRuntimeFailure.value: 3, | ||
| DefaultErrorEnum.kCompilationFailed.value: 3, | ||
| } | ||
|
|
||
| def is_error_tolerated(self, tolerance: int, base_error_code: str) -> bool: | ||
| if base_error_code == "correct": | ||
| return True | ||
| if base_error_code in ["eager_fail", "reference_fail"]: | ||
| return False | ||
|
|
||
| error_enum = DefaultErrorEnum.get_error_enum(base_error_code) | ||
| mapping = self.get_tolerance_mapping() | ||
| required_threshold = mapping.get(error_enum.value, 999) | ||
|
|
||
| return tolerance >= required_threshold | ||
|
|
||
| def num_errno_enum_values(self) -> int: | ||
| """ | ||
| Default mode defines 3 levels of errors: | ||
| 1: Accuracy | ||
| 2: Runtime (Generic) | ||
| 3: Compilation | ||
| """ | ||
| return len(DefaultErrorEnum) |
87 changes: 87 additions & 0 deletions
87
graph_net/mismatch_extended_positive_tolerance_interpretation.py
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,87 @@ | ||
| from enum import IntEnum | ||
|
|
||
| from graph_net.positive_tolerance_interpretation import PositiveToleranceInterpretation | ||
|
|
||
|
|
||
| class MismatchExtendedErrorEnum(IntEnum): | ||
| """ | ||
| Values correspond to the minimum tolerance level required. | ||
| """ | ||
|
|
||
| kAccuracyViolation = 1 | ||
| kValueTypeOrMetaMismatch = 2 | ||
| kExecutionFailed = 3 | ||
| kCompilationFailed = 4 | ||
|
|
||
| @classmethod | ||
| def get_error_enum(cls, base_error_type: str) -> "MismatchExtendedErrorEnum": | ||
| if not base_error_type: | ||
| return cls.kExecutionFailed | ||
|
|
||
| etype = base_error_type.lower() | ||
| if "accuracy" in etype: | ||
| return cls.kAccuracyViolation | ||
| if any(x in etype for x in ["nan", "inf", "type_mismatch", "shape_mismatch"]): | ||
| return cls.kValueTypeOrMetaMismatch | ||
| if "compile_fail" in etype: | ||
| return cls.kCompilationFailed | ||
|
|
||
| return cls.kExecutionFailed | ||
|
|
||
|
|
||
| class MismatchExtendedPositiveToleranceInterpretation(PositiveToleranceInterpretation): | ||
| """ | ||
| Extended interpretation (ESt): | ||
| - t=1: Accuracy | ||
| - t=2: NaN/Inf/Type/Shape | ||
| - t=3: Runtime | ||
| - t=4: Compile | ||
| """ | ||
|
|
||
| def __init__(self, *argc, **kwargs): | ||
| super().__init__(*argc, **kwargs) | ||
|
|
||
| def type_name(self) -> str: | ||
| return "mismatch_extended" | ||
|
|
||
| def get_errno(self, error_type: str) -> int: | ||
| return MismatchExtendedErrorEnum.get_error_enum(error_type).value | ||
|
|
||
| def get_error_type(self, errno: int) -> str: | ||
| mapping = { | ||
| 1: "accuracy", | ||
| 2: "type/shape_mismatch", | ||
| 3: "runtime_fail", | ||
| 4: "compile_fail", | ||
| } | ||
| return mapping.get(errno, "unknown_error") | ||
|
|
||
| def get_tolerance_mapping(self) -> dict[int, int]: | ||
| return { | ||
| MismatchExtendedErrorEnum.kAccuracyViolation.value: 1, | ||
| MismatchExtendedErrorEnum.kValueTypeOrMetaMismatch.value: 2, | ||
| MismatchExtendedErrorEnum.kExecutionFailed.value: 3, | ||
| MismatchExtendedErrorEnum.kCompilationFailed.value: 4, | ||
| } | ||
|
|
||
| def is_error_tolerated(self, tolerance: int, base_error_code: str) -> bool: | ||
| if base_error_code == "correct": | ||
| return True | ||
| if base_error_code in ["eager_fail", "reference_fail"]: | ||
| return False | ||
|
|
||
| error_enum = MismatchExtendedErrorEnum.get_error_enum(base_error_code) | ||
| mapping = self.get_tolerance_mapping() | ||
| required_threshold = mapping.get(error_enum.value, 999) | ||
|
|
||
| return tolerance >= required_threshold | ||
|
|
||
| def num_errno_enum_values(self) -> int: | ||
| """ | ||
| Extended mode defines 4 levels of errors: | ||
| 1: Accuracy | ||
| 2: Type/Shape/NaN | ||
| 3: Runtime | ||
| 4: Compilation | ||
| """ | ||
| return len(MismatchExtendedErrorEnum) | ||
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,53 @@ | ||
| from abc import ABC, abstractmethod | ||
|
|
||
|
|
||
| class PositiveToleranceInterpretation(ABC): | ||
| """ | ||
| Abstract base class defining how positive tolerance values (t > 0) | ||
| are interpreted and mapped to specific error types. | ||
| """ | ||
|
|
||
| def __init__(self, *argc, **kwargs): | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def type_name(self) -> str: | ||
| """Return the unique string identifier for this interpretation strategy.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def get_errno(self, error_type: str) -> int: | ||
| """Map a raw error type string to an internal error number (errno).""" | ||
| raise NotImplementedError | ||
|
|
||
3619117923 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @abstractmethod | ||
| def get_error_type(self, errno: int) -> str: | ||
| """Map an internal error number (errno) back to a representative string.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def get_tolerance_mapping(self) -> dict[int, int]: | ||
| """ | ||
| Return the mapping of errno. | ||
| Used for statistical calculations (Gamma/Pi). | ||
| """ | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def is_error_tolerated(self, tolerance: int, base_error_code: str) -> bool: | ||
| """ | ||
| Determine if a specific error is considered 'correct' under the given tolerance. | ||
| Replaces the old 'fake_perf_degrad' logic. | ||
| """ | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def num_errno_enum_values(self) -> int: | ||
| """ | ||
| Return the number of defined error categories (or the maximum errno). | ||
|
|
||
| Example: | ||
| - Default: returns 3 (Accuracy, Runtime, Compile) | ||
| - MismatchExtended: returns 4 (Accuracy, Data, Runtime, Compile) | ||
| """ | ||
| raise NotImplementedError | ||
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.
Uh oh!
There was an error while loading. Please reload this page.