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

Reorder all unittests under two packages of keras and pytorch packages #71

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 3 additions & 4 deletions .github/workflows/run_keras_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install tensorflow==${{ inputs.tf-version }}
pip install tensorflow==${{ inputs.tf-version }} sony-custom-layers
- name: Run unittests
# Some tests are sensitive to memory because we use tf gradients on a multi-thread/process
# CPU environment (https://github.com/tensorflow/tensorflow/issues/41718).
# For this reason, if we run them in such an environment, we need to run them first non-parallel separately.
run: |
python -m unittest discover tests/keras_tests/pruning_tests -v
python -m unittest discover tests/keras_tests/non_parallel_tests -v
for script in tests/xquant_tests/keras_tests tests/keras_tests/exporter_tests tests/keras_tests/feature_networks_tests tests/keras_tests/graph_tests tests/keras_tests/layer_tests; do python -m unittest discover $script -v & pids+=($!); done; for pid in ${pids[@]}; do wait $pid || exit 1; done
python -m unittest discover tests/keras_tests -v


1 change: 0 additions & 1 deletion .github/workflows/run_pytorch_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
pip install torch==${{ inputs.torch-version }} torchvision onnx onnxruntime
- name: Run unittests
run: |
python -m unittest discover tests/xquant_tests/pytorch_tests -v
python -m unittest discover tests/pytorch_tests -v


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright 2024 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.
# ==============================================================================
#

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright 2024 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.
# ==============================================================================
#

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

from model_compression_toolkit.data_generation.common.enums import SchedulerType, BatchNormAlignemntLossType, \
DataInitType, BNLayerWeightingType, ImageGranularity, ImagePipelineType, ImageNormalizationType, OutputLossType
from tests.data_generation_tests.keras.base_keras_data_generation_test import BaseKerasDataGenerationTest, \
from tests.keras_tests.data_generation_tests.base_keras_data_generation_test import BaseKerasDataGenerationTest, \
NoBNDataGenerationModel


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

import unittest
import numpy as np
from keras.src.optimizers import Adam
from keras.optimizers import Adam

from model_compression_toolkit.data_generation.keras.optimization_functions.lr_scheduler import ReduceLROnPlateau

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from model_compression_toolkit.qat.keras.quantizer.lsq.uniform_lsq import LSQUniformActivationQATQuantizer, LSQUniformWeightQATQuantizer
from model_compression_toolkit.qat.keras.quantizer.lsq.symmetric_lsq import LSQActivationQATQuantizer, LSQWeightQATQuantizer
from model_compression_toolkit.trainable_infrastructure import BaseKerasTrainableQuantizer
from tests.trainable_infrastructure_tests.keras.trainable_keras.test_get_quantizers import \
from tests.keras_tests.trainable_infrastructure_tests.trainable_keras.test_get_quantizers import \
TestGetTrainableQuantizer
from tests.trainable_infrastructure_tests.keras.trainable_keras.test_keras_base_quantizer import TestKerasBaseWeightsQuantizer, \
from tests.keras_tests.trainable_infrastructure_tests.trainable_keras.test_keras_base_quantizer import TestKerasBaseWeightsQuantizer, \
TestKerasBaseActivationsQuantizer, TestKerasQuantizerWithoutMarkDecorator

layers = tf.keras.layers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from model_compression_toolkit.trainable_infrastructure.common.get_quantizers import \
get_trainable_quantizer_class
from tests.trainable_infrastructure_tests.keras.base_keras_trainable_infra_test import \
from tests.keras_tests.trainable_infrastructure_tests.base_keras_trainable_infra_test import \
BaseKerasTrainableInfrastructureTest


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
TrainableQuantizerWeightsConfig, TrainableQuantizerActivationConfig
from model_compression_toolkit.trainable_infrastructure.keras.config_serialization import config_serialization, \
config_deserialization
from tests.trainable_infrastructure_tests.keras.base_keras_trainable_infra_test import \
from tests.keras_tests.trainable_infrastructure_tests.base_keras_trainable_infra_test import \
BaseKerasTrainableInfrastructureTest, ZeroWeightsQuantizer, ZeroActivationsQuantizer


Expand Down
15 changes: 15 additions & 0 deletions tests/keras_tests/xquant_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 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.
# ==============================================================================

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

from model_compression_toolkit.xquant.keras.model_analyzer import KerasModelAnalyzer
import model_compression_toolkit as mct
from tests.xquant_tests.keras_tests.test_xquant_end2end import random_data_gen
from tests.keras_tests.xquant_tests.test_xquant_end2end import random_data_gen


class TestKerasModelAnalyzer(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
DataInitType, BNLayerWeightingType, ImageGranularity, ImagePipelineType, ImageNormalizationType, OutputLossType
from model_compression_toolkit.data_generation.pytorch.optimization_functions.lr_scheduler import \
ReduceLROnPlateauWithReset
from tests.data_generation_tests.pytorch.base_pytorch_data_generation_test import BasePytorchDataGenerationTest
from tests.pytorch_tests.data_generation_tests.base_pytorch_data_generation_test import BasePytorchDataGenerationTest


class PytorchDataGenerationTestRunner(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
LSQUniformActivationQATQuantizer
from model_compression_toolkit.trainable_infrastructure.pytorch.base_pytorch_quantizer import \
BasePytorchTrainableQuantizer
from tests.trainable_infrastructure_tests.pytorch.trainable_pytorch.test_pytorch_base_quantizer import \
from tests.pytorch_tests.trainable_infrastructure_tests.trainable_pytorch.test_pytorch_base_quantizer import \
TestPytorchBaseWeightsQuantizer, TestPytorchBaseActivationQuantizer, TestPytorchQuantizerWithoutMarkDecorator
from tests.trainable_infrastructure_tests.pytorch.trainable_pytorch.test_pytorch_get_quantizers import \
from tests.pytorch_tests.trainable_infrastructure_tests.trainable_pytorch.test_pytorch_get_quantizers import \
TestGetTrainableQuantizer


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
TrainableQuantizerWeightsConfig, TrainableQuantizerActivationConfig
from model_compression_toolkit.trainable_infrastructure.pytorch.base_pytorch_quantizer import \
BasePytorchTrainableQuantizer
from tests.trainable_infrastructure_tests.pytorch.base_pytorch_trainable_infra_test import \
from tests.pytorch_tests.trainable_infrastructure_tests.base_pytorch_trainable_infra_test import \
BasePytorchInfrastructureTest, ZeroWeightsQuantizer, ZeroActivationsQuantizer
from model_compression_toolkit.target_platform_capabilities.target_platform import QuantizationMethod

Expand Down
15 changes: 15 additions & 0 deletions tests/pytorch_tests/xquant_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 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.
# ==============================================================================

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from model_compression_toolkit.core.pytorch.utils import get_working_device, to_torch_tensor

from model_compression_toolkit.xquant.pytorch.model_analyzer import PytorchModelAnalyzer
from tests.xquant_tests.pytorch_tests.test_xquant_end2end import random_data_gen
from tests.pytorch_tests.xquant_tests.test_xquant_end2end import random_data_gen
import model_compression_toolkit as mct
from torch import nn
class TestPytorchModelAnalyzer(unittest.TestCase):
Expand Down
18 changes: 8 additions & 10 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"torchvision") is not None

if found_tf:
from tests.xquant_tests.keras_tests.test_xquant_end2end import BaseTestEnd2EndKerasXQuant
from tests.keras_tests.xquant_tests.test_xquant_end2end import BaseTestEnd2EndKerasXQuant
from tests.keras_tests.function_tests.test_activation_quantization_functions import TestActivationQuantizationFunctions as TestActivationQuantizationFunctionsKeras
from tests.keras_tests.function_tests.test_custom_layer import TestCustomLayer
from tests.keras_tests.function_tests.test_hessian_info_calculator import TestHessianInfoCalculatorWeights, \
Expand Down Expand Up @@ -76,22 +76,21 @@
from tests.keras_tests.exporter_tests.test_runner import ExporterTestsRunner
from tests.keras_tests.function_tests.test_get_gptq_config import TestGetGPTQConfig
from tests.keras_tests.function_tests.test_gptq_loss_functions import TestGPTQLossFunctions
from tests.trainable_infrastructure_tests.keras.test_keras_trainable_infra_runner import \
from tests.keras_tests.trainable_infrastructure_tests.test_keras_trainable_infra_runner import \
KerasTrainableInfrastructureTestRunner
from tests.keras_tests.function_tests.test_gptq_soft_quantizer import TestGPTQSoftQuantizer as keras_gptq_soft_quantizer_test
from tests.keras_tests.function_tests.test_activation_quantization_holder_gptq import TestGPTQModelBuilderWithActivationHolder
from tests.data_generation_tests.keras.test_keras_data_generation_runner import KerasDataGenerationTestRunner
from tests.keras_tests.data_generation_tests.test_keras_data_generation_runner import KerasDataGenerationTestRunner
from tests.keras_tests.pruning_tests.test_memory_calculator import TestParameterCounter
from tests.keras_tests.pruning_tests.test_pretrained_models import PruningPretrainedModelsTest
from tests.keras_tests.pruning_tests.feature_networks.test_pruning_feature_networks import PruningFeatureNetworksTest
from tests.keras_tests.function_tests.test_hmse_error_method import TestParamSelectionWithHMSE
from tests.data_generation_tests.keras.test_scheduler_step import TestReduceLROnPlateau
from tests.keras_tests.function_tests.test_node_quantization_configurations import \
TestNodeQuantizationConfigurations
from tests.keras_tests.data_generation_tests.test_scheduler_step import TestReduceLROnPlateau
from tests.keras_tests.function_tests.test_node_quantization_configurations import TestNodeQuantizationConfigurations
from tests.keras_tests.function_tests.test_quant_config_filtering import TestKerasQuantConfigFiltering

if found_pytorch:
from tests.xquant_tests.pytorch_tests.test_xquant_end2end import BaseTestEnd2EndPytorchXQuant
from tests.pytorch_tests.xquant_tests.test_xquant_end2end import BaseTestEnd2EndPytorchXQuant
from tests.pytorch_tests.function_tests.test_activation_quantization_functions import TestActivationQuantizationFunctions as TestActivationQuantizationFunctionsPytorch
from tests.pytorch_tests.function_tests.test_torch_utils import TestTorchUtils
from tests.pytorch_tests.function_tests.test_device_manager import TestDeviceManager
Expand All @@ -100,13 +99,12 @@
# from tests.pytorch_tests.model_tests.test_models_runner import ModelTest
from tests.pytorch_tests.function_tests.test_function_runner import FunctionTestRunner
from tests.pytorch_tests.function_tests.test_pytorch_tp_model import TestPytorchTPModel
from tests.trainable_infrastructure_tests.pytorch.test_pytorch_trainable_infra_runner import \
PytorchTrainableInfrastructureTestRunner
from tests.pytorch_tests.trainable_infrastructure_tests.test_pytorch_trainable_infra_runner import PytorchTrainableInfrastructureTestRunner
from tests.pytorch_tests.function_tests.test_gptq_soft_quantizer import TestGPTQSoftQuantizer as pytorch_gptq_soft_quantier_test
from tests.pytorch_tests.function_tests.test_activation_quantization_holder_gptq import \
TestGPTQModelBuilderWithActivationHolder as TestGPTQModelBuilderWithActivationHolderPytorch
from tests.pytorch_tests.exporter_tests.test_runner import PytorchExporterTestsRunner
from tests.data_generation_tests.pytorch.test_pytorch_data_generation_runner import PytorchDataGenerationTestRunner
from tests.pytorch_tests.data_generation_tests.test_pytorch_data_generation_runner import PytorchDataGenerationTestRunner
from tests.pytorch_tests.graph_tests.test_fx_errors import TestGraphReading
from tests.pytorch_tests.pruning_tests.feature_networks.test_pruning_feature_networks import PruningFeatureNetworksTest
from tests.pytorch_tests.exporter_tests.test_exporting_qat_models import TestExportingQATModelTorchscript
Expand Down
14 changes: 0 additions & 14 deletions tests/trainable_infrastructure_tests/pytorch/__init__.py

This file was deleted.

This file was deleted.

Loading