-
Notifications
You must be signed in to change notification settings - Fork 54
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
Refactor Target Platform Capabilities - Phase 2 #1290
Conversation
- Convert all schema classes to immutable dataclasses, replacing existing methods with equivalent dataclass methods (e.g., `replace`). - Ensure all schema classes are strictly immutable to enhance reliability and maintain consistency. - Update target platform model versions to align with the new class structure. - Refactor tests to support and validate the updated class types and functionality.
model_compression_toolkit/target_platform_capabilities/schema/v1.py
Outdated
Show resolved
Hide resolved
def __init__(self, | ||
quantization_config_list: List[OpQuantizationConfig], | ||
base_config: OpQuantizationConfig = None): | ||
quantization_config_list: List[OpQuantizationConfig] |
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.
Do we want to convert lists into tuples to be really frozen? List elements can still be updated.
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 agree. This will be removed in the next PR when the context manager mechanism is removed.
add_metadata: bool = True, | ||
name="default_tp_model"): | ||
default_qco: QuantizationConfigOptions | ||
tpc_minor_version: Optional[int] |
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.
Should we really allow None in version and platform type? Also consider unifying version into a single field (unless it was an explicit requirement for some reason)
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.
versions are separated feildes by design.
regarding the None value, I would like to have @haihabi 's opinion
tpc_minor_version: Optional[int] | ||
tpc_patch_version: Optional[int] | ||
tpc_platform_type: Optional[str] | ||
add_metadata: bool = True |
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.
Is add_metadata really relevant to tpc?
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.
tpc_platform_type: Optional[str] | ||
add_metadata: bool = True | ||
name: str = "default_tp_model" | ||
operator_set: List[OperatorsSetBase] = field(default_factory=list) |
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 strongly recommend removing the default values here and in other fields, except maybe the name (not sure what it is for). I don't think there exists any meaningful default, certainly not an empty set.
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.
This also applies to other classes.
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 agree. This will be removed in the next PR when the context manager mechanism is removed.
if len(self.default_qco.quantization_config_list) != 1: | ||
Logger.critical("Default QuantizationConfigOptions must contain exactly one option.") # pragma: no cover | ||
|
||
def get_config_options_by_operators_set(self, operators_set_name: str) -> QuantizationConfigOptions: |
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.
Is there any reason that this and the following methods should be part of the schema? Maybe we can create MCT derived class as Hai suggested and add the utility methods it needs.
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.
either a utility sub-class or an external util function (similar to what I wrote regarding max_activation_n_bits function).
Either way, it shouldn't be part of the schema
model_compression_toolkit/target_platform_capabilities/schema/v1.py
Outdated
Show resolved
Hide resolved
return self | ||
|
||
def __validate_model(self): | ||
def __validate_model(self) -> None: |
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.
Why do you need both post_init and validate?
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 agree. Currently, this is part of the context manager. It will be removed in the next PR when the context manager mechanism is removed.
model_compression_toolkit/target_platform_capabilities/schema/v1.py
Outdated
Show resolved
Hide resolved
model_compression_toolkit/target_platform_capabilities/schema/v1.py
Outdated
Show resolved
Hide resolved
model_compression_toolkit/target_platform_capabilities/schema/v1.py
Outdated
Show resolved
Hide resolved
model_compression_toolkit/target_platform_capabilities/schema/v1.py
Outdated
Show resolved
Hide resolved
add_metadata: bool = True, | ||
name="default_tp_model"): | ||
default_qco: QuantizationConfigOptions | ||
tpc_minor_version: Optional[int] |
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.
versions are separated feildes by design.
regarding the None value, I would like to have @haihabi 's opinion
if len(self.default_qco.quantization_config_list) != 1: | ||
Logger.critical("Default QuantizationConfigOptions must contain exactly one option.") # pragma: no cover | ||
|
||
def get_config_options_by_operators_set(self, operators_set_name: str) -> QuantizationConfigOptions: |
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.
either a utility sub-class or an external util function (similar to what I wrote regarding max_activation_n_bits function).
Either way, it shouldn't be part of the schema
|
||
def append_component(self, | ||
tp_model_component: TargetPlatformModelComponent): | ||
def append_component(self, tp_model_component: TargetPlatformModelComponent) -> None: |
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.
Just to make sure, this function will be removed in the next PR that eliminates the "with" initialization mechanism, is that correct?
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 agree. This will be removed in the next PR when the context manager mechanism is removed.
replace
).Pull Request Description:
Checklist before requesting a review: