diff --git a/tests_pytest/unit_tests/__init__.py b/tests_pytest/unit_tests/__init__.py index e69de29bb..5397dea24 100644 --- a/tests_pytest/unit_tests/__init__.py +++ b/tests_pytest/unit_tests/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== diff --git a/tests_pytest/unit_tests/common/__init__.py b/tests_pytest/unit_tests/common/__init__.py index ea3047f32..5397dea24 100644 --- a/tests_pytest/unit_tests/common/__init__.py +++ b/tests_pytest/unit_tests/common/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved. +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,4 @@ # 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. -# ============================================================================== \ No newline at end of file +# ============================================================================== diff --git a/tests_pytest/unit_tests/common/core/__init__.py b/tests_pytest/unit_tests/common/core/__init__.py index ea3047f32..5397dea24 100644 --- a/tests_pytest/unit_tests/common/core/__init__.py +++ b/tests_pytest/unit_tests/common/core/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved. +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,4 @@ # 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. -# ============================================================================== \ No newline at end of file +# ============================================================================== diff --git a/tests_pytest/unit_tests/common/core/mixed_precision/__init__.py b/tests_pytest/unit_tests/common/core/mixed_precision/__init__.py index e69de29bb..5397dea24 100644 --- a/tests_pytest/unit_tests/common/core/mixed_precision/__init__.py +++ b/tests_pytest/unit_tests/common/core/mixed_precision/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== diff --git a/tests_pytest/unit_tests/common/core/quantization/__init__.py b/tests_pytest/unit_tests/common/core/quantization/__init__.py index ea3047f32..5397dea24 100644 --- a/tests_pytest/unit_tests/common/core/quantization/__init__.py +++ b/tests_pytest/unit_tests/common/core/quantization/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved. +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,4 @@ # 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. -# ============================================================================== \ No newline at end of file +# ============================================================================== diff --git a/tests_pytest/unit_tests/common/core/quantization/quantization_params_generation/test_symmetric_selection_activation.py b/tests_pytest/unit_tests/common/core/quantization/quantization_params_generation/test_symmetric_selection_activation.py index 3ca066d3f..2ff0c4817 100644 --- a/tests_pytest/unit_tests/common/core/quantization/quantization_params_generation/test_symmetric_selection_activation.py +++ b/tests_pytest/unit_tests/common/core/quantization/quantization_params_generation/test_symmetric_selection_activation.py @@ -1,4 +1,4 @@ -# Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved. +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests_pytest/unit_tests/keras/gptq/__init__.py b/tests_pytest/unit_tests/keras/gptq/__init__.py index ea3047f32..5397dea24 100644 --- a/tests_pytest/unit_tests/keras/gptq/__init__.py +++ b/tests_pytest/unit_tests/keras/gptq/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved. +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,4 @@ # 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. -# ============================================================================== \ No newline at end of file +# ============================================================================== diff --git a/tests_pytest/unit_tests/keras/target_platform_capabilities/__init__.py b/tests_pytest/unit_tests/keras/target_platform_capabilities/__init__.py new file mode 100644 index 000000000..5397dea24 --- /dev/null +++ b/tests_pytest/unit_tests/keras/target_platform_capabilities/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== diff --git a/tests_pytest/unit_tests/keras/target_platform_capabilities/targetplatform2framework/__init__.py b/tests_pytest/unit_tests/keras/target_platform_capabilities/targetplatform2framework/__init__.py new file mode 100644 index 000000000..5397dea24 --- /dev/null +++ b/tests_pytest/unit_tests/keras/target_platform_capabilities/targetplatform2framework/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== diff --git a/tests_pytest/unit_tests/keras/target_platform_capabilities/targetplatform2framework/test_attach2keras.py b/tests_pytest/unit_tests/keras/target_platform_capabilities/targetplatform2framework/test_attach2keras.py new file mode 100644 index 000000000..934453da4 --- /dev/null +++ b/tests_pytest/unit_tests/keras/target_platform_capabilities/targetplatform2framework/test_attach2keras.py @@ -0,0 +1,56 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== + +from packaging import version +import tensorflow as tf + +from tests_pytest.base_test_classes.base_tpc_attach2fw_test import BaseTpcAttach2FrameworkTest + +if version.parse(tf.__version__) >= version.parse("2.13"): + from keras.src.layers import Conv2D, Identity +else: + from keras.layers import Conv2D, Identity + +from model_compression_toolkit.target_platform_capabilities import LayerFilterParams +from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.attach2keras import \ + AttachTpcToKeras + + +class TestAttachTpc2Keras(BaseTpcAttach2FrameworkTest): + + attach2fw_class = AttachTpcToKeras + + def test_attach2fw_init(self): + super().test_attach2fw_init() + + def test_attach2fw_attach_without_attributes(self): + super().test_attach2fw_attach_without_attributes() + + def test_attach2fw_attach_linear_op_with_attributes(self): + super().test_attach2fw_attach_linear_op_with_attributes() + + def test_attach2fw_attach_to_default_config(self): + super().test_attach2fw_attach_to_default_config() + + def test_not_existing_opset_with_layers_to_attach(self): + super().test_not_existing_opset_with_layers_to_attach() + + def test_attach2pytorch_attach_with_custom_opset(self): + self._test_attach2fw_attach_with_custom_opset([Identity], + LayerFilterParams(Conv2D, stride=2), + "CustomAttr") + + def test_attach2pytorch_prioritize_custom_opset(self): + self._test_attach2fw_prioritize_custom_opset(Conv2D) diff --git a/tests_pytest/unit_tests/pytorch/target_platform_capabilities/__init__.py b/tests_pytest/unit_tests/pytorch/target_platform_capabilities/__init__.py new file mode 100644 index 000000000..5397dea24 --- /dev/null +++ b/tests_pytest/unit_tests/pytorch/target_platform_capabilities/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== diff --git a/tests_pytest/unit_tests/pytorch/target_platform_capabilities/targetplatform2framework/__init__.py b/tests_pytest/unit_tests/pytorch/target_platform_capabilities/targetplatform2framework/__init__.py new file mode 100644 index 000000000..5397dea24 --- /dev/null +++ b/tests_pytest/unit_tests/pytorch/target_platform_capabilities/targetplatform2framework/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== diff --git a/tests_pytest/unit_tests/pytorch/target_platform_capabilities/targetplatform2framework/test_attach2pytorch.py b/tests_pytest/unit_tests/pytorch/target_platform_capabilities/targetplatform2framework/test_attach2pytorch.py new file mode 100644 index 000000000..12bce2956 --- /dev/null +++ b/tests_pytest/unit_tests/pytorch/target_platform_capabilities/targetplatform2framework/test_attach2pytorch.py @@ -0,0 +1,49 @@ +# Copyright 2025 Sony Semiconductor Israel, Inc. All rights reserved. +# +# 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. +# ============================================================================== + +import torch.nn + +from model_compression_toolkit.target_platform_capabilities import LayerFilterParams +from model_compression_toolkit.target_platform_capabilities.targetplatform2framework.attach2pytorch import \ + AttachTpcToPytorch +from tests_pytest.base_test_classes.base_tpc_attach2fw_test import BaseTpcAttach2FrameworkTest + + +class TestAttachTpc2Pytorch(BaseTpcAttach2FrameworkTest): + + attach2fw_class = AttachTpcToPytorch + + def test_attach2fw_init(self): + super().test_attach2fw_init() + + def test_attach2fw_attach_without_attributes(self): + super().test_attach2fw_attach_without_attributes() + + def test_attach2fw_attach_linear_op_with_attributes(self): + super().test_attach2fw_attach_linear_op_with_attributes() + + def test_attach2fw_attach_to_default_config(self): + super().test_attach2fw_attach_to_default_config() + + def test_not_existing_opset_with_layers_to_attach(self): + super().test_not_existing_opset_with_layers_to_attach() + + def test_attach2pytorch_attach_with_custom_opset(self): + self._test_attach2fw_attach_with_custom_opset([torch.nn.Identity], + LayerFilterParams(torch.nn.Conv2d, stride=2), + "CustomAttr") + + def test_attach2pytorch_prioritize_custom_opset(self): + self._test_attach2fw_prioritize_custom_opset(torch.nn.Conv2d)