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

Update aggregator.py #2995

Merged
merged 11 commits into from
Oct 17, 2024
16 changes: 13 additions & 3 deletions nncf/common/tensor_statistics/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from nncf.data.dataset import DataItem
from nncf.data.dataset import Dataset
from nncf.data.dataset import ModelInput
from nncf.common.logging import nncf_logger
zina-cs marked this conversation as resolved.
Show resolved Hide resolved

TensorType = TypeVar("TensorType")
TModel = TypeVar("TModel")
Expand Down Expand Up @@ -70,7 +71,9 @@ def collect_statistics(self, model: TModel, graph: NNCFGraph) -> None:
engine = factory.EngineFactory.create(model_with_outputs)

iterations_number = self._get_iterations_number()
empty_statistics = True

zina-cs marked this conversation as resolved.
Show resolved Hide resolved
processed_samples = 0

for input_data in track( # type: ignore
islice(self.dataset.get_inference_data(), iterations_number),
total=iterations_number,
Expand All @@ -79,9 +82,16 @@ def collect_statistics(self, model: TModel, graph: NNCFGraph) -> None:
outputs = engine.infer(input_data)
processed_outputs = self._process_outputs(outputs)
self._register_statistics(processed_outputs, merged_statistics)
empty_statistics = False
if empty_statistics:
processed_samples += 1

zina-cs marked this conversation as resolved.
Show resolved Hide resolved
if processed_samples == 0:
raise nncf.ValidationError(EMPTY_DATASET_ERROR)

zina-cs marked this conversation as resolved.
Show resolved Hide resolved
if self.stat_subset_size is not None and self.stat_subset_size > processed_samples:
nncf_logger.warning(
f"Dataset contains only {processed_samples} samples, "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l-bat, @eaidova, @nikita-savelyevv please check that this is not impact NNCF examples, OpenVINO notebooks and optimum-intel.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zina-cs Could you please provide subset_size to the nncf.quantize in the following examples?

  1. https://github.com/openvinotoolkit/nncf/tree/develop/examples/post_training_quantization/openvino:
    • anomaly_stfpm_quantize_with_accuracy_control - subset_size=109
    • yolov8 - subset_size=128
    • yolov8_quantize_with_accuracy_control - subset_size=128
  2. https://github.com/openvinotoolkit/nncf/tree/develop/examples/post_training_quantization/onnx/yolov8_quantize_with_accuracy_control - subset_size=128
  3. https://github.com/openvinotoolkit/nncf/tree/develop/examples/post_training_quantization/torch/ssd300_vgg16 - subset_size=128

f"smaller than the requested subset size {self.stat_subset_size}."
)

def register_statistic_points(self, statistic_points: StatisticPointsContainer) -> None:
"""
Expand Down
Loading