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

Attach to framework tests #1322

Merged
merged 10 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix test loops
ofirgo committed Jan 14, 2025
commit a77e905e4b7fcbf642f74d06b4757319709f616f
88 changes: 50 additions & 38 deletions tests_pytest/base_test_classes/base_tpc_attach2fw_test.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from typing import NamedTuple

import pytest

@@ -36,6 +36,8 @@
signedness=schema.Signedness.AUTO
)

OpSet = NamedTuple("OpSet", [('op_name', str), ('op_list', list)])


class BaseTpcAttach2FrameworkTest:
ofirgo marked this conversation as resolved.
Show resolved Hide resolved

@@ -63,26 +65,31 @@ def test_attach2fw_attach_without_attributes(self):
default_qc_options = schema.QuantizationConfigOptions(quantization_configurations=(default_op_cfg,))
tested_qc_options = schema.QuantizationConfigOptions(quantization_configurations=(tested_op_cfg,))

for op_name, op_list in self.attach2fw._opset2layer.items():
if op_name not in self.attach2fw._opset2attr_mapping.keys():
tpc = schema.TargetPlatformCapabilities(
default_qco=default_qc_options,
operator_set=tuple([schema.OperatorsSet(name=op_name, qc_options=tested_qc_options)]))
opsets_without_attrs = [OpSet(op_name=op_name, op_list=op_list)
for op_name, op_list in self.attach2fw._opset2layer.items()
if op_name not in self.attach2fw._opset2attr_mapping.keys()]

assert len(opsets_without_attrs) > 0

fw_quant_capabilities = self.attach2fw.attach(tpc) # Run 'attach' to test operator attach to framework
for opset in opsets_without_attrs:
tpc = schema.TargetPlatformCapabilities(
default_qco=default_qc_options,
operator_set=tuple([schema.OperatorsSet(name=opset.op_name, qc_options=tested_qc_options)]))

assert isinstance(fw_quant_capabilities, FrameworkQuantizationCapabilities)
fw_quant_capabilities = self.attach2fw.attach(tpc) # Run 'attach' to test operator attach to framework

all_mapped_ops = fw_quant_capabilities.layer2qco.copy()
all_mapped_ops.update(fw_quant_capabilities.filterlayer2qco)
if len(op_list) == 0:
assert len(all_mapped_ops) == 0
else:
assert len(all_mapped_ops) == len(op_list)
assert isinstance(fw_quant_capabilities, FrameworkQuantizationCapabilities)

for qco in all_mapped_ops.values():
assert len(qco.quantization_configurations) == 1
assert qco.base_config.activation_n_bits == 42
all_mapped_ops = fw_quant_capabilities.layer2qco.copy()
all_mapped_ops.update(fw_quant_capabilities.filterlayer2qco)
if len(opset.op_list) == 0:
assert len(all_mapped_ops) == 0
ofirgo marked this conversation as resolved.
Show resolved Hide resolved
else:
assert len(all_mapped_ops) == len(opset.op_list)

for qco in all_mapped_ops.values():
assert len(qco.quantization_configurations) == 1
ofirgo marked this conversation as resolved.
Show resolved Hide resolved
assert qco.base_config.activation_n_bits == 42


def test_attach2fw_attach_linear_op_with_attributes(self):
@@ -103,32 +110,37 @@ def test_attach2fw_attach_linear_op_with_attributes(self):
default_qc_options = schema.QuantizationConfigOptions(quantization_configurations=(default_op_cfg,))
tested_qc_options = schema.QuantizationConfigOptions(quantization_configurations=(tested_op_cfg,))

for op_name, op_list in self.attach2fw._opset2layer.items():
if op_name in self.attach2fw._opset2attr_mapping.keys():
tpc = schema.TargetPlatformCapabilities(
default_qco=default_qc_options,
operator_set=tuple([schema.OperatorsSet(name=op_name, qc_options=tested_qc_options)]))
opsets_with_attrs = [OpSet(op_name=op_name, op_list=op_list)
for op_name, op_list in self.attach2fw._opset2layer.items()
if op_name in self.attach2fw._opset2attr_mapping.keys()]

assert len(opsets_with_attrs) > 0

for opset in opsets_with_attrs:
tpc = schema.TargetPlatformCapabilities(
default_qco=default_qc_options,
operator_set=tuple([schema.OperatorsSet(name=opset.op_name, qc_options=tested_qc_options)]))

fw_quant_capabilities = self.attach2fw.attach(tpc) # Run 'attach' to test operator attach to framework
fw_linear_attr_names = self.attach2fw._opset2attr_mapping[op_name]
fw_quant_capabilities = self.attach2fw.attach(tpc) # Run 'attach' to test operator attach to framework
fw_linear_attr_names = self.attach2fw._opset2attr_mapping[opset.op_name]

assert isinstance(fw_quant_capabilities, FrameworkQuantizationCapabilities)
assert isinstance(fw_quant_capabilities, FrameworkQuantizationCapabilities)

all_mapped_ops = fw_quant_capabilities.layer2qco.copy()
all_mapped_ops.update(fw_quant_capabilities.filterlayer2qco)
if len(op_list) == 0:
assert len(all_mapped_ops) == 0
else:
assert len(all_mapped_ops) == len(op_list)
all_mapped_ops = fw_quant_capabilities.layer2qco.copy()
all_mapped_ops.update(fw_quant_capabilities.filterlayer2qco)
if len(opset.op_list) == 0:
assert len(all_mapped_ops) == 0
ofirgo marked this conversation as resolved.
Show resolved Hide resolved
else:
assert len(all_mapped_ops) == len(opset.op_list)

for qco in all_mapped_ops.values():
assert len(qco.quantization_configurations) == 1
assert qco.base_config.default_weight_attr_config == default_attr_config
for qco in all_mapped_ops.values():
assert len(qco.quantization_configurations) == 1
assert qco.base_config.default_weight_attr_config == default_attr_config

for attr_name, fw_layer2attr_mapping in fw_linear_attr_names.items():
assert isinstance(fw_layer2attr_mapping, DefaultDict)
layer_attr_mapping = fw_layer2attr_mapping.get(op_list[0])
assert qco.base_config.attr_weights_configs_mapping.get(layer_attr_mapping) == tested_attr_cfg
for attr_name, fw_layer2attr_mapping in fw_linear_attr_names.items():
assert isinstance(fw_layer2attr_mapping, DefaultDict)
layer_attr_mapping = fw_layer2attr_mapping.get(opset.op_list[0])
ofirgo marked this conversation as resolved.
Show resolved Hide resolved
assert qco.base_config.attr_weights_configs_mapping.get(layer_attr_mapping) == tested_attr_cfg


def test_attach2fw_attach_to_default_config(self):
Loading