-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added raising an exception when empty calibration dataset is provided (…
…#2230) ### Changes Added raising an exception when an empty calibration dataset is provided. Now if empty calibration dataset is passed to `nncf.quantize()` the following exception will be thrown: ``` Calibration dataset must not be empty. Please provide calibration dataset with at least one sample. ``` Also added a check for non-positive `subset_size` provided to `nncf.quantize()`. Otherwise, it would error with the same statistics not collected error. ### Reason for changes Without an explicit exception it will error out later with a message like: ``` File "/home/nsavel/workspace/openvino_notebooks/nncf/nncf/quantization/algorithms/min_max/algorithm.py", line 673, in apply raise RuntimeError(f"Statistics were not collected for the node {target_node_name}") RuntimeError: Statistics were not collected for the node /model.2/m.2/Add ``` This is confusing and does not clearly reflect what is actually wrong. There have been some reports, e.g. from OTX side, when an error like this was encountered due to empty dataset. But at first it wasn't clear what's the issue actually is, and a bug in NNCF was suspected. I personally also encounter this sometimes during experimenting and this triggers me to look for issues in NNCF, however it was just an empty calibration dataset provided by mistake. ### Tests Added a test for empty dataset to `common/test_statistics_aggregator.py` Added a test for non-positive `subset_size` to `tests/openvino/native/quantization/test_quantize_api.py` (openvino only). --------- Co-authored-by: Alexander Suslov <[email protected]>
- Loading branch information
1 parent
cb781eb
commit f2cb7ae
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) 2023 Intel Corporation | ||
# 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 pytest | ||
from openvino.runtime import Model | ||
from openvino.runtime import Shape | ||
from openvino.runtime import Type | ||
from openvino.runtime import op | ||
from openvino.runtime import opset8 | ||
|
||
import nncf | ||
from nncf import Dataset | ||
from tests.shared.datasets import MockDataset | ||
|
||
INPUT_SHAPE = [2, 1, 1, 1] | ||
|
||
|
||
def get_mock_model() -> Model: | ||
param_node = op.Parameter(Type.f32, Shape(INPUT_SHAPE)) | ||
softmax_axis = 1 | ||
softmax_node = opset8.softmax(param_node, softmax_axis) | ||
return Model(softmax_node, [param_node], "mock") | ||
|
||
|
||
def test_non_positive_subset_size(): | ||
model_to_test = get_mock_model() | ||
|
||
with pytest.raises(ValueError) as e: | ||
nncf.quantize(model_to_test, Dataset(MockDataset(INPUT_SHAPE)), subset_size=0) | ||
assert "Subset size must be positive." in e.info |