Skip to content
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

Merged
merged 8 commits into from
Dec 12, 2024
Merged

Conversation

lior-dikstein
Copy link
Collaborator

@lior-dikstein lior-dikstein commented Dec 10, 2024

  • 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.

Pull Request Description:

Checklist before requesting a review:

  • I set the appropriate labels on the pull request.
  • I have added/updated the release note draft (if necessary).
  • I have updated the documentation to reflect my changes (if necessary).
  • All function and files are well documented.
  • All function and classes have type hints.
  • There is a licenses in all file.
  • The function and variable names are informative.
  • I have checked for code duplications.
  • I have added new unittest (if necessary).

- 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.
@lior-dikstein lior-dikstein changed the title **Refactor Target Platform Capabilities - Phase 2** Refactor Target Platform Capabilities - Phase 2 Dec 10, 2024
def __init__(self,
quantization_config_list: List[OpQuantizationConfig],
base_config: OpQuantizationConfig = None):
quantization_config_list: List[OpQuantizationConfig]
Copy link
Collaborator

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.

Copy link
Collaborator Author

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]
Copy link
Collaborator

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)

Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed this with @ofirgo and @haihabi and we decided to keep it here

tpc_platform_type: Optional[str]
add_metadata: bool = True
name: str = "default_tp_model"
operator_set: List[OperatorsSetBase] = field(default_factory=list)
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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:
Copy link
Collaborator

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.

Copy link
Collaborator

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

return self

def __validate_model(self):
def __validate_model(self) -> None:
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

add_metadata: bool = True,
name="default_tp_model"):
default_qco: QuantizationConfigOptions
tpc_minor_version: Optional[int]
Copy link
Collaborator

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:
Copy link
Collaborator

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:
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

@lior-dikstein lior-dikstein merged commit dbc93b7 into main Dec 12, 2024
42 checks passed
@lior-dikstein lior-dikstein deleted the tpc_refator_phase2 branch December 12, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants