Skip to content

Commit

Permalink
Remove folder "target_platform"
Browse files Browse the repository at this point in the history
  • Loading branch information
liord committed Jan 13, 2025
1 parent b1cc0d1 commit 77f28aa
Show file tree
Hide file tree
Showing 70 changed files with 130 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from model_compression_toolkit.core.common.graph.base_graph import Graph
from model_compression_toolkit.core.common.graph.base_node import BaseNode
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework import FrameworkQuantizationCapabilities
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.layer_filter_params import LayerFilterParams
from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.layer_filter_params import LayerFilterParams


def filter_fusing_patterns(fusing_patterns: List[List[Any]], node: BaseNode, idx: int = 0) -> List[List[Any]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from model_compression_toolkit.verify_packages import FOUND_TF

if FOUND_TF:
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from model_compression_toolkit.core.keras.default_framework_info import DEFAULT_KERAS_INFO
from model_compression_toolkit.core.keras.keras_implementation import KerasImplementation
from tensorflow.keras.models import Model
Expand All @@ -33,7 +33,7 @@

from model_compression_toolkit import get_target_platform_capabilities

KERAS_DEFAULT_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TPC)
KERAS_DEFAULT_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TP_MODEL)

def keras_resource_utilization_data(in_model: Model,
representative_data_gen: Callable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@
from model_compression_toolkit.logger import Logger
from model_compression_toolkit.constants import PYTORCH
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformCapabilities
from model_compression_toolkit.target_platform_capabilities.target_platform import FrameworkQuantizationCapabilities
from model_compression_toolkit.core.common.mixed_precision.resource_utilization_tools.resource_utilization import ResourceUtilization
from model_compression_toolkit.core.common.mixed_precision.resource_utilization_tools.resource_utilization_data import compute_resource_utilization_data
from model_compression_toolkit.core.common.quantization.core_config import CoreConfig
from model_compression_toolkit.core.common.mixed_precision.mixed_precision_quantization_config import MixedPrecisionQuantizationConfig
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from model_compression_toolkit.verify_packages import FOUND_TORCH

if FOUND_TORCH:
from model_compression_toolkit.core.pytorch.default_framework_info import DEFAULT_PYTORCH_INFO
from model_compression_toolkit.core.pytorch.pytorch_implementation import PytorchImplementation
from torch.nn import Module
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2pytorch import \
from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.attach2pytorch import \
AttachTpcToPytorch

from model_compression_toolkit import get_target_platform_capabilities

PYTORCH_DEFAULT_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TPC)
PYTORCH_DEFAULT_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TP_MODEL)


def pytorch_resource_utilization_data(in_model: Module,
Expand Down
4 changes: 2 additions & 2 deletions model_compression_toolkit/gptq/keras/quantization_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from model_compression_toolkit.core.keras.keras_model_validation import KerasModelValidation
from tensorflow.keras.models import Model
from model_compression_toolkit.gptq.keras.gptq_loss import GPTQMultipleTensorsLoss, sample_layer_attention_loss
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from model_compression_toolkit.exporter.model_wrapper import get_exportable_keras_model
from model_compression_toolkit import get_target_platform_capabilities
from mct_quantizers.keras.metadata import add_metadata
Expand All @@ -59,7 +59,7 @@
else:
from tensorflow.python.keras.optimizer_v2.optimizer_v2 import OptimizerV2

DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TPC)
DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TP_MODEL)

def get_keras_gptq_config(n_epochs: int,
optimizer: OptimizerV2 = None,
Expand Down
7 changes: 3 additions & 4 deletions model_compression_toolkit/gptq/pytorch/quantization_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,25 @@
from model_compression_toolkit.logger import Logger
from model_compression_toolkit.metadata import create_model_metadata
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformCapabilities
from model_compression_toolkit.target_platform_capabilities.target_platform import FrameworkQuantizationCapabilities
from model_compression_toolkit.verify_packages import FOUND_TORCH



if FOUND_TORCH:
from model_compression_toolkit.core.pytorch.default_framework_info import DEFAULT_PYTORCH_INFO
from model_compression_toolkit.gptq.pytorch.gptq_pytorch_implementation import GPTQPytorchImplemantation
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from model_compression_toolkit.gptq.pytorch.gptq_loss import multiple_tensors_mse_loss, sample_layer_attention_loss
from model_compression_toolkit.exporter.model_wrapper.pytorch.builder.fully_quantized_model_builder import get_exportable_pytorch_model
import torch
from torch.nn import Module
from torch.optim import Adam, Optimizer
from model_compression_toolkit import get_target_platform_capabilities
from mct_quantizers.pytorch.metadata import add_metadata
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2pytorch import \
from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.attach2pytorch import \
AttachTpcToPytorch

DEFAULT_PYTORCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TPC)
DEFAULT_PYTORCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TP_MODEL)

def get_pytorch_gptq_config(n_epochs: int,
optimizer: Optimizer = None,
Expand Down
4 changes: 2 additions & 2 deletions model_compression_toolkit/pruning/keras/pruning_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from model_compression_toolkit.logger import Logger
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework import FrameworkQuantizationCapabilities
from model_compression_toolkit.core.common.quantization.quantization_config import DEFAULTCONFIG
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL

if FOUND_TF:
from model_compression_toolkit.core.keras.back2framework.float_model_builder import FloatKerasModelBuilder
Expand All @@ -38,7 +38,7 @@
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2keras import \
AttachTpcToKeras

DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TPC)
DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TP_MODEL)

def keras_pruning_experimental(model: Model,
target_resource_utilization: ResourceUtilization,
Expand Down
7 changes: 3 additions & 4 deletions model_compression_toolkit/pruning/pytorch/pruning_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
from model_compression_toolkit.core.common.quantization.set_node_quantization_config import set_quantization_configuration_to_graph
from model_compression_toolkit.core.graph_prep_runner import read_model_to_graph
from model_compression_toolkit.logger import Logger
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework import FrameworkQuantizationCapabilities
from model_compression_toolkit.core.common.quantization.quantization_config import DEFAULTCONFIG
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL


# Check if PyTorch is available in the environment.
Expand All @@ -38,11 +37,11 @@
PruningPytorchImplementation
from model_compression_toolkit.core.pytorch.default_framework_info import DEFAULT_PYTORCH_INFO
from torch.nn import Module
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2pytorch import \
from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.attach2pytorch import \
AttachTpcToPytorch

# Set the default Target Platform Capabilities (TPC) for PyTorch.
DEFAULT_PYOTRCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TPC)
DEFAULT_PYOTRCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TP_MODEL)

def pytorch_pruning_experimental(model: Module,
target_resource_utilization: ResourceUtilization,
Expand Down
4 changes: 2 additions & 2 deletions model_compression_toolkit/ptq/keras/quantization_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
from model_compression_toolkit.core.keras.keras_implementation import KerasImplementation
from model_compression_toolkit.core.keras.keras_model_validation import KerasModelValidation
from tensorflow.keras.models import Model
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from model_compression_toolkit.exporter.model_wrapper import get_exportable_keras_model

from model_compression_toolkit import get_target_platform_capabilities
from mct_quantizers.keras.metadata import add_metadata
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2keras import \
AttachTpcToKeras

DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TPC)
DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TP_MODEL)


def keras_post_training_quantization(in_model: Model,
Expand Down
7 changes: 3 additions & 4 deletions model_compression_toolkit/ptq/pytorch/quantization_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from model_compression_toolkit.constants import PYTORCH
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformCapabilities
from model_compression_toolkit.verify_packages import FOUND_TORCH
from model_compression_toolkit.target_platform_capabilities.target_platform import FrameworkQuantizationCapabilities
from model_compression_toolkit.core.common.mixed_precision.resource_utilization_tools.resource_utilization import ResourceUtilization
from model_compression_toolkit.core import CoreConfig
from model_compression_toolkit.core.common.mixed_precision.mixed_precision_quantization_config import \
Expand All @@ -35,15 +34,15 @@
if FOUND_TORCH:
from model_compression_toolkit.core.pytorch.default_framework_info import DEFAULT_PYTORCH_INFO
from model_compression_toolkit.core.pytorch.pytorch_implementation import PytorchImplementation
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from torch.nn import Module
from model_compression_toolkit.exporter.model_wrapper.pytorch.builder.fully_quantized_model_builder import get_exportable_pytorch_model
from model_compression_toolkit import get_target_platform_capabilities
from mct_quantizers.pytorch.metadata import add_metadata
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2pytorch import \
from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.attach2pytorch import \
AttachTpcToPytorch

DEFAULT_PYTORCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TPC)
DEFAULT_PYTORCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TP_MODEL)

def pytorch_post_training_quantization(in_module: Module,
representative_data_gen: Callable,
Expand Down
6 changes: 3 additions & 3 deletions model_compression_toolkit/qat/keras/quantization_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from model_compression_toolkit.core.keras.default_framework_info import DEFAULT_KERAS_INFO
from model_compression_toolkit.core.keras.keras_implementation import KerasImplementation
from model_compression_toolkit.core.keras.keras_model_validation import KerasModelValidation
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL

from model_compression_toolkit.core.keras.back2framework.keras_model_builder import KerasModelBuilder

Expand All @@ -50,15 +50,15 @@
from model_compression_toolkit.constants import TENSORFLOW
from model_compression_toolkit.core.common.framework_info import FrameworkInfo
from model_compression_toolkit.qat.common.qat_config import is_qat_applicable
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from model_compression_toolkit.core.keras.default_framework_info import DEFAULT_KERAS_INFO
from model_compression_toolkit.qat.keras.quantizer.quantization_builder import quantization_builder, \
get_activation_quantizer_holder
from model_compression_toolkit.qat.common.qat_config import QATConfig
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2keras import \
AttachTpcToKeras

DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TPC)
DEFAULT_KERAS_TPC = get_target_platform_capabilities(TENSORFLOW, DEFAULT_TP_MODEL)


def qat_wrapper(n: common.BaseNode,
Expand Down
10 changes: 3 additions & 7 deletions model_compression_toolkit/qat/pytorch/quantization_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import copy
from typing import Callable
from functools import partial

from model_compression_toolkit.constants import PYTORCH
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformCapabilities
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attach2pytorch import \
from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.attach2pytorch import \
AttachTpcToPytorch
from model_compression_toolkit.verify_packages import FOUND_TORCH

from model_compression_toolkit.core import CoreConfig
from model_compression_toolkit.core import common
from model_compression_toolkit.core.common.visualization.tensorboard_writer import init_tensorboard_writer
from model_compression_toolkit.logger import Logger
from model_compression_toolkit.core.common.framework_info import FrameworkInfo
from model_compression_toolkit.core.common.mixed_precision.resource_utilization_tools.resource_utilization import ResourceUtilization
from model_compression_toolkit.core.common.mixed_precision.mixed_precision_quantization_config import \
MixedPrecisionQuantizationConfig
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework import \
FrameworkQuantizationCapabilities
from model_compression_toolkit.core.runner import core_runner
from model_compression_toolkit.ptq.runner import ptq_runner

Expand All @@ -40,7 +36,7 @@
from torch.nn import Module
from mct_quantizers import PytorchActivationQuantizationHolder
from model_compression_toolkit.core.pytorch.default_framework_info import DEFAULT_PYTORCH_INFO
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TPC
from model_compression_toolkit.target_platform_capabilities.constants import DEFAULT_TP_MODEL
from model_compression_toolkit.core.pytorch.pytorch_implementation import PytorchImplementation
from model_compression_toolkit.qat.common.qat_config import is_qat_applicable
from model_compression_toolkit.core.pytorch.back2framework.pytorch_model_builder import PyTorchModelBuilder
Expand All @@ -50,7 +46,7 @@
from model_compression_toolkit.qat.pytorch.quantizer.quantization_builder import get_activation_quantizer_holder
from model_compression_toolkit.qat.pytorch.quantizer.quantization_builder import quantization_builder

DEFAULT_PYTORCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TPC)
DEFAULT_PYTORCH_TPC = get_target_platform_capabilities(PYTORCH, DEFAULT_TP_MODEL)


def qat_wrapper(n: common.BaseNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@


# Supported TP models names:
DEFAULT_TPC = 'default'
IMX500_TPC = 'imx500'
TFLITE_TPC = 'tflite'
QNNPACK_TPC = 'qnnpack'
DEFAULT_TP_MODEL= 'default'
IMX500_TP_MODEL = 'imx500'
TFLITE_TP_MODEL = 'tflite'
QNNPACK_TP_MODEL = 'qnnpack'

# TP Attributes
KERNEL_ATTR = "kernel_attr"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.current_tpc import get_current_tpc
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.framework_quantization_capabilities import FrameworkQuantizationCapabilities
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.attribute_filter import \
Eq, GreaterEq, NotEq, SmallerEq, Greater, Smaller
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.layer_filter_params import \
from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.layer_filter_params import \
LayerFilterParams
from model_compression_toolkit.target_platform_capabilities.target_platform.targetplatform2framework.operations_to_layers import \
OperationsToLayers, OperationsSetToLayers
Expand Down
Loading

0 comments on commit 77f28aa

Please sign in to comment.