-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
10,755 additions
and
6,801 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
neural_compressor/ux/components/config_generator/mixed_precision_config_generator.py
This file contains 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,57 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2022 Intel Corporation | ||
# | ||
# 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. | ||
"""Configuration generator class.""" | ||
from typing import Any | ||
|
||
from neural_compressor.ux.components.config_generator.config_generator import ConfigGenerator | ||
from neural_compressor.ux.utils.workload.config import Config | ||
from neural_compressor.ux.utils.workload.evaluation import Accuracy, Evaluation, Metric | ||
from neural_compressor.ux.utils.workload.mixed_precision import MixedPrecision | ||
|
||
|
||
class MixedPrecisionConfigGenerator(ConfigGenerator): | ||
"""Configuration generator class.""" | ||
|
||
def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
"""Initialize configuration generator.""" | ||
super().__init__(*args, **kwargs) | ||
data = kwargs.get("data", {}) | ||
self.optimization_precision: str = data["optimization_precision"] | ||
|
||
def generate(self) -> None: | ||
"""Generate yaml config file.""" | ||
config = Config() | ||
config.load(self.predefined_config_path) | ||
config.model = self.generate_model_config() | ||
config.evaluation = self.generate_evaluation_config() | ||
config.mixed_precision = self.generate_mixed_precision_config() | ||
config.dump(self.config_path) | ||
|
||
def generate_evaluation_config(self) -> Evaluation: | ||
"""Generate evaluation configuration.""" | ||
evaluation = Evaluation() | ||
evaluation.accuracy = Accuracy() | ||
|
||
if self.metric: | ||
evaluation.accuracy.metric = Metric(self.metric) | ||
|
||
evaluation.accuracy.dataloader = self.generate_dataloader_config(batch_size=1) | ||
return evaluation | ||
|
||
def generate_mixed_precision_config(self) -> MixedPrecision: | ||
"""Generate graph optimization configuration.""" | ||
graph_opt = MixedPrecision() | ||
graph_opt.precisions = self.optimization_precision | ||
return graph_opt |
This file contains 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 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
74 changes: 74 additions & 0 deletions
74
neural_compressor/ux/components/db_manager/alembic/versions/6ece06672ed3_v1_14.py
This file contains 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,74 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2022 Intel Corporation | ||
# | ||
# 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. | ||
# flake8: noqa | ||
# mypy: ignore-errors | ||
"""v1.14 | ||
Revision ID: 6ece06672ed3 | ||
Revises: 6f0d0f71d92e | ||
Create Date: 2022-08-31 07:16:24.229939 | ||
""" | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from neural_compressor.ux.components.db_manager.db_manager import DBManager | ||
from neural_compressor.ux.components.db_manager.db_models.optimization_type import OptimizationType | ||
from neural_compressor.ux.components.db_manager.db_models.precision import ( | ||
Precision, | ||
precision_optimization_type_association, | ||
) | ||
from neural_compressor.ux.utils.consts import OptimizationTypes, Precisions | ||
|
||
db_manager = DBManager() | ||
Session = sessionmaker(bind=db_manager.engine) | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "6ece06672ed3" | ||
down_revision = "6f0d0f71d92e" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with Session.begin() as db_session: | ||
mixed_precision_id = OptimizationType.add( | ||
db_session=db_session, | ||
name=OptimizationTypes.MIXED_PRECISION.value, | ||
) | ||
bf16_precision_id = Precision.get_precision_by_name( | ||
db_session=db_session, | ||
precision_name=Precisions.BF16.value, | ||
)[0] | ||
|
||
print("mixed_precision_id") | ||
print(mixed_precision_id) | ||
print("bf16_precision_id") | ||
print(bf16_precision_id) | ||
|
||
query = precision_optimization_type_association.insert().values( | ||
precision_id=bf16_precision_id, | ||
optimization_type_id=mixed_precision_id, | ||
) | ||
db_session.execute(query) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
Oops, something went wrong.