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

Adding Len checks for subset size test #2993

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,34 @@ def test_ignored_scope_dump(ignored_options, expected_dump, tmp_path):
assert dumped_model.get_rt_info(rt_path) == value
else:
assert dumped_model.has_rt_info(rt_path) is False

@pytest.mark.parametrize("subset_size, expected_actual_subset_size", [[1, 1], [2, 1]])
def test_dump(subset_size, expected_actual_subset_size, tmp_path):
model = WeightsModel().ov_model
dataset = get_dataset_for_test(model) # dataset.get_length() == 1
quantize_parameters = {
"preset": QuantizationPreset.PERFORMANCE,
"target_device": TargetDevice.CPU,
"subset_size": subset_size,
"fast_bias_correction": True,
}

quantized_model = quantize_impl(model, dataset, **quantize_parameters)
ov.save_model(quantized_model, tmp_path / "ov_model.xml")
core = ov.Core()
dumped_model = core.read_model(tmp_path / "ov_model.xml")

assert dumped_model.get_rt_info(["nncf", "quantization", "actual_subset_size"]) == str(expected_actual_subset_size)

# Check if dataset has __len__ implemented
if hasattr(dataset, '__len__'):
with warnings.catch_warnings(record=True) as w:
collect_statistics(dataset, subset_size)
if len(dataset) < subset_size:
assert len(w) > 0
assert "smaller than subset_size" in str(w[-1].message)
else:
# Handle the case when __len__ is not implemented
with warnings.catch_warnings(record=True) as w:
collect_statistics(dataset, subset_size)
assert len(w) == 0 # No warning expected