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

Move splitting ops from default to qpreserving configs in TPCv4. #1304

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
OPSET_QUANTIZATION_PRESERVING = "QuantizationPreserving"
OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS = "DimensionManipulationOpsWithWeights"
OPSET_DIMENSION_MANIPULATION_OPS = "DimensionManipulationOps"
OPSET_SPLIT_OPS = "SplitOps"
OPSET_MERGE_OPS = "MergeOps"
OPSET_CONV = "Conv"
OPSET_FULLY_CONNECTED = "FullyConnected"
Expand Down Expand Up @@ -186,6 +187,15 @@ def generate_tp_model(default_config: OpQuantizationConfig,
signedness=Signedness.SIGNED)]),
base_config=default_config_input16)

qpreseving_config = default_config.clone_and_edit(enable_activation_quantization=False,
quantization_preserving=True,
supported_input_activation_n_bits=(8, 16))
qpreseving_config_options = schema.QuantizationConfigOptions(tuple([qpreseving_config,
qpreseving_config.clone_and_edit(
activation_n_bits=16,
signedness=Signedness.SIGNED)]),
base_config=qpreseving_config)

# Create a QuantizationConfigOptions for quantizing constants in functional ops.
# Constant configuration is similar to the default eight bit configuration except for PoT
# quantization method for the constant.
Expand Down Expand Up @@ -259,6 +269,7 @@ def generate_tp_model(default_config: OpQuantizationConfig,
quantization_preserving=True,
supported_input_activation_n_bits=(8, 16))
.clone_and_edit_weight_attribute(enable_weights_quantization=False)))
operator_set.append(schema.OperatorsSet(OPSET_SPLIT_OPS, qpreseving_config_options))
operator_set.append(schema.OperatorsSet(OPSET_MERGE_OPS, const_configuration_options_inout16_per_tensor))

# Define operator sets that use mixed_precision_configuration_options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v4.tp_model import OPSET_NO_QUANTIZATION, \
OPSET_QUANTIZATION_PRESERVING, OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, OPSET_DIMENSION_MANIPULATION_OPS, \
OPSET_MERGE_OPS, OPSET_CONV, OPSET_FULLY_CONNECTED, OPSET_ANY_RELU, OPSET_ADD, OPSET_SUB, OPSET_MUL, OPSET_DIV, \
OPSET_PRELU, OPSET_SWISH, OPSET_SIGMOID, OPSET_TANH, OPSET_GELU, OPSET_BATCH_NORM, OPSET_MIN_MAX, OPSET_HARDSIGMOID
OPSET_PRELU, OPSET_SWISH, OPSET_SIGMOID, OPSET_TANH, OPSET_GELU, OPSET_BATCH_NORM, OPSET_MIN_MAX, OPSET_HARDSIGMOID, \
OPSET_SPLIT_OPS

tp = mct.target_platform

Expand Down Expand Up @@ -78,11 +79,7 @@ def generate_keras_tpc(name: str, tp_model: schema.TargetPlatformModel):
ZeroPadding2D,
Dropout,
MaxPooling2D,
tf.split,
tf.cast,
tf.unstack,
tf.__operators__.getitem,
tf.strided_slice]
tf.cast]
quantization_preserving_list_16bit_input = [Reshape,
tf.reshape,
Permute,
Expand All @@ -97,6 +94,7 @@ def generate_keras_tpc(name: str, tp_model: schema.TargetPlatformModel):
tp.OperationsSetToLayers(OPSET_QUANTIZATION_PRESERVING, quantization_preserving)
tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS, quantization_preserving_list_16bit_input)
tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, [tf.gather, tf.compat.v1.gather])
tp.OperationsSetToLayers(OPSET_SPLIT_OPS,[tf.unstack, tf.split, tf.strided_slice, tf.__operators__.getitem])
tp.OperationsSetToLayers(OPSET_MERGE_OPS, [tf.stack, tf.concat, Concatenate])
tp.OperationsSetToLayers(OPSET_CONV,
[Conv2D,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
OPSET_QUANTIZATION_PRESERVING, OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, OPSET_DIMENSION_MANIPULATION_OPS, \
OPSET_MERGE_OPS, OPSET_CONV, OPSET_FULLY_CONNECTED, OPSET_ANY_RELU, OPSET_ADD, OPSET_SUB, OPSET_MUL, OPSET_DIV, \
OPSET_PRELU, OPSET_SWISH, OPSET_SIGMOID, OPSET_TANH, OPSET_GELU, OPSET_BATCH_NORM, OPSET_MIN_MAX, OPSET_HARDSIGMOID, \
OPSET_HARDSWISH
OPSET_HARDSWISH, OPSET_SPLIT_OPS

tp = mct.target_platform

Expand Down Expand Up @@ -77,9 +77,6 @@ def generate_pytorch_tpc(name: str, tp_model: schema.TargetPlatformModel):
topk])
tp.OperationsSetToLayers(OPSET_QUANTIZATION_PRESERVING, [Dropout,
dropout,
split,
chunk,
unbind,
MaxPool2d])
tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS, [Flatten,
flatten,
Expand All @@ -90,6 +87,7 @@ def generate_pytorch_tpc(name: str, tp_model: schema.TargetPlatformModel):
permute,
transpose])
tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, [gather, torch.Tensor.expand])
tp.OperationsSetToLayers(OPSET_SPLIT_OPS,[split, chunk, unbind])
tp.OperationsSetToLayers(OPSET_MERGE_OPS,
[torch.stack, torch.cat, torch.concat, torch.concatenate])

Expand Down
Loading