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

Pr/2197 #17

Open
wants to merge 101 commits into
base: develop
Choose a base branch
from
Open

Pr/2197 #17

wants to merge 101 commits into from

Conversation

alexsu52
Copy link
Owner

@alexsu52 alexsu52 commented Feb 29, 2024

Changes

Reason for changes

Related tickets

Tests

Summary by CodeRabbit

  • New Features
    • Introduced per-sample statistics computation for more precise quantization.
    • Added batch size parameterization in various components for enhanced dataset processing flexibility.
    • Implemented new statistical functions and aggregation logic for improved tensor statistics handling.
  • Enhancements
    • Improved axis manipulation functionality with new utility functions.
    • Streamlined statistic collection and aggregation across different backends (Torch, ONNX, OpenVINO).
    • Enhanced logging and error handling during statistics collection for better user feedback.
  • Refactor
    • Unified axis calculation methods for reduction and aggregation to simplify codebase.
    • Removed redundant methods and updated function signatures to align with new features.
  • Bug Fixes
    • Fixed potential inaccuracies in statistics results by identifying operations that mix outputs from different samples.
  • Documentation
    • Updated method and class documentation to reflect new functionalities and parameter changes.
  • Tests
    • Expanded test coverage for batch size handling, tensor statistics collection, and quantization configurations across different backends.

Copy link

coderabbitai bot commented Feb 29, 2024

Walkthrough

This update focuses on enhancing tensor statistics aggregation and reduction functionality across various backends in a neural network compression framework. It introduces a new parameter for controlling statistics calculation on a per-sample basis, improves handling of batch sizes in data processing, and refines axis manipulation for more accurate quantization. Additionally, it streamlines the handling of operations that mix outputs from different samples, ensuring more precise statistics results.

Changes

Files Change Summary
examples/.../torch/mobilenet_v2/main.py
nncf/data/dataset.py
tests/.../pipelines/*.py
tests/.../*batch_size.py
Added or modified batch size handling in data loaders and tests.
nncf/common/.../*.py
nncf/quantization/.../*.py
nncf/torch/.../*.py
Enhanced tensor statistics aggregation and reduction, including new imports, methods, and parameter handling.
nncf/onnx/.../*.py
nncf/openvino/.../*.py
Updated ONNX and OpenVINO backends with improved statistics collection and handling of operations without a batch axis.
nncf/quantization/algorithms/*.py Refactored quantization algorithms with new parameters and methods for better statistics collection.
tests/.../*.py Introduced and modified tests to cover new functionality and configurations, including batch size handling and statistics collection.

🐇✨
In the land of bits and bytes,
Where tensors flow and data sights,
A rabbit hopped with keen delight,
For quantization had reached new heights.
"With each update, we refine,
Ensuring models are more aligned,"
It whispered, as the moon did shine,
On code that's crafted so divine. 🌙
✨🐇


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 16

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 797fad9 and 2cc8b81.
Files ignored due to path filters (2)
  • tests/onnx/data/reference_scales/linear_model_mixed.json is excluded by: !**/*.json
  • tests/onnx/data/reference_scales/one_depthwise_convolutional_model_mixed.json is excluded by: !**/*.json
Files selected for processing (71)
  • examples/post_training_quantization/torch/mobilenet_v2/main.py (1 hunks)
  • nncf/common/graph/utils.py (2 hunks)
  • nncf/common/quantization/initialization/range.py (2 hunks)
  • nncf/common/tensor_statistics/aggregator.py (5 hunks)
  • nncf/data/dataset.py (1 hunks)
  • nncf/experimental/common/tensor_statistics/statistical_functions.py (1 hunks)
  • nncf/experimental/tensor/functions/numeric.py (1 hunks)
  • nncf/experimental/tensor/functions/numpy_numeric.py (1 hunks)
  • nncf/experimental/tensor/functions/torch_numeric.py (1 hunks)
  • nncf/onnx/graph/metatypes/groups.py (1 hunks)
  • nncf/onnx/graph/metatypes/onnx_metatypes.py (1 hunks)
  • nncf/onnx/graph/node_utils.py (5 hunks)
  • nncf/onnx/quantization/quantizer_parameters.py (2 hunks)
  • nncf/onnx/statistics/aggregator.py (3 hunks)
  • nncf/openvino/engine.py (3 hunks)
  • nncf/openvino/graph/metatypes/groups.py (1 hunks)
  • nncf/openvino/graph/metatypes/openvino_metatypes.py (1 hunks)
  • nncf/openvino/graph/node_utils.py (1 hunks)
  • nncf/openvino/statistics/aggregator.py (3 hunks)
  • nncf/quantization/advanced_parameters.py (3 hunks)
  • nncf/quantization/algorithms/bias_correction/onnx_backend.py (1 hunks)
  • nncf/quantization/algorithms/channel_alignment/algorithm.py (2 hunks)
  • nncf/quantization/algorithms/channel_alignment/backend.py (1 hunks)
  • nncf/quantization/algorithms/channel_alignment/openvino_backend.py (4 hunks)
  • nncf/quantization/algorithms/fast_bias_correction/onnx_backend.py (1 hunks)
  • nncf/quantization/algorithms/min_max/algorithm.py (5 hunks)
  • nncf/quantization/algorithms/min_max/backend.py (3 hunks)
  • nncf/quantization/algorithms/min_max/onnx_backend.py (5 hunks)
  • nncf/quantization/algorithms/min_max/openvino_backend.py (4 hunks)
  • nncf/quantization/algorithms/min_max/torch_backend.py (5 hunks)
  • nncf/quantization/algorithms/post_training/algorithm.py (1 hunks)
  • nncf/quantization/algorithms/post_training/pipeline.py (1 hunks)
  • nncf/quantization/algorithms/smooth_quant/algorithm.py (2 hunks)
  • nncf/quantization/algorithms/smooth_quant/backend.py (1 hunks)
  • nncf/quantization/algorithms/smooth_quant/openvino_backend.py (2 hunks)
  • nncf/quantization/algorithms/smooth_quant/torch_backend.py (2 hunks)
  • nncf/quantization/algorithms/weight_compression/algorithm.py (1 hunks)
  • nncf/quantization/algorithms/weight_compression/backend.py (1 hunks)
  • nncf/quantization/algorithms/weight_compression/openvino_backend.py (2 hunks)
  • nncf/quantization/algorithms/weight_compression/torch_backend.py (1 hunks)
  • nncf/quantization/quantize_model.py (3 hunks)
  • nncf/torch/graph/operator_metatypes.py (1 hunks)
  • nncf/torch/quantization/init_range.py (2 hunks)
  • nncf/torch/statistics/aggregator.py (3 hunks)
  • tests/common/experimental/test_tensor_collector_batch_size.py (1 hunks)
  • tests/common/graph/test_utils.py (2 hunks)
  • tests/common/test_statistics_aggregator.py (14 hunks)
  • tests/onnx/quantization/test_batch_size.py (1 hunks)
  • tests/onnx/quantization/test_quantizer_config.py (2 hunks)
  • tests/onnx/quantization/test_tensor_collector_batch_size.py (1 hunks)
  • tests/openvino/native/quantization/test_batch_size.py (1 hunks)
  • tests/openvino/native/quantization/test_quantizer_config.py (2 hunks)
  • tests/openvino/native/test_node_utils.py (2 hunks)
  • tests/openvino/native/test_tensor_collector_batch_size.py (1 hunks)
  • tests/openvino/tools/calibrate.py (4 hunks)
  • tests/post_training/conftest.py (1 hunks)
  • tests/post_training/pipelines/base.py (2 hunks)
  • tests/post_training/pipelines/causal_language_model.py (1 hunks)
  • tests/post_training/pipelines/image_classification_timm.py (4 hunks)
  • tests/post_training/pipelines/masked_language_modeling.py (1 hunks)
  • tests/post_training/test_quantize_conformance.py (4 hunks)
  • tests/post_training/test_templates/helpers.py (2 hunks)
  • tests/post_training/test_templates/test_batch_size.py (1 hunks)
  • tests/post_training/test_templates/test_channel_alignment.py (2 hunks)
  • tests/post_training/test_templates/test_ptq_params.py (1 hunks)
  • tests/post_training/test_templates/test_quantizer_config.py (4 hunks)
  • tests/torch/ptq/test_batch_size.py (1 hunks)
  • tests/torch/ptq/test_graphs.py (2 hunks)
  • tests/torch/ptq/test_quantizer_config.py (2 hunks)
  • tests/torch/ptq/test_tensor_collector_batch_size.py (1 hunks)
  • tests/torch/test_statistics_aggregator.py (6 hunks)
Files not reviewed due to errors (1)
  • nncf/quantization/algorithms/weight_compression/algorithm.py (Error: unable to parse review)
Files skipped from review due to trivial changes (5)
  • nncf/quantization/algorithms/channel_alignment/backend.py
  • nncf/quantization/algorithms/post_training/algorithm.py
  • nncf/quantization/algorithms/smooth_quant/backend.py
  • nncf/quantization/algorithms/smooth_quant/openvino_backend.py
  • nncf/quantization/algorithms/weight_compression/torch_backend.py
Additional comments: 102
tests/openvino/native/quantization/test_batch_size.py (1)
  • 11-17: The implementation of TestOVBatchSize and its method create_statistics_aggregator correctly extends the functionality of TemplateTestBatchSize by providing a specific instance of OVStatisticsAggregator for OpenVino native quantization tests. This aligns well with the PR objectives of enhancing post-training quantization processes.
tests/torch/ptq/test_batch_size.py (1)
  • 11-17: The TestTorchBatchSize class and its method create_statistics_aggregator are correctly implemented, extending TemplateTestBatchSize to provide a PTStatisticsAggregator instance for PyTorch backend quantization tests. This is in line with enhancing post-training quantization processes.
tests/onnx/quantization/test_batch_size.py (1)
  • 11-17: The implementation of TestONNXBatchSize and its method create_statistics_aggregator correctly extends TemplateTestBatchSize by providing an ONNXStatisticsAggregator instance for ONNX backend quantization tests, aligning with the PR's objectives.
nncf/experimental/common/tensor_statistics/statistical_functions.py (1)
  • 19-35: The addition of the optional dtype parameter to the mean_per_channel function enhances its flexibility and utility, allowing for the specification of the data type in mean calculations. This change is well-implemented and aligns with best practices for handling numerical computations.
tests/post_training/conftest.py (1)
  • 22-22: The addition of the --batch_size command-line option in conftest.py enhances test configuration flexibility by allowing the specification of the calibration dataset's batch size. This change is well-implemented and provides a sensible default value.
nncf/onnx/quantization/quantizer_parameters.py (2)
  • 40-48: The function convert_fq_params_to_onnx_params now correctly expects the axis parameter as a Tuple[int], aligning with the need for per-channel quantization in ONNX format. This change enhances the flexibility and correctness of the quantization process.
  • 71-72: The handling of the axis parameter to meet ONNX format specifications is correctly implemented by converting it to None if not provided or extracting the first element if it's a tuple. This ensures compatibility with ONNX's expectations for scalar or 1-D tensor parameters.
nncf/torch/statistics/aggregator.py (3)
  • 12-12: The addition of the List import from the typing module is appropriate for the new property metatypes_no_batch_support that returns a list of metatypes.
  • 23-24: The new imports for OPERATIONS_OUTPUT_HAS_NO_BATCH_AXIS and PTOperatorMetatype are correctly added to support the functionality of determining operations that do not support batch dimensions.
  • 34-36: The introduction of the metatypes_no_batch_support property is a good addition, providing a clear way to access operations that do not support batch dimensions. This enhances the modularity and clarity of the code.
tests/openvino/native/test_node_utils.py (1)
  • 18-23: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of the test_get_channel_agnostic_reduction_axes function suggests a change in testing strategy or the deprecation of the tested functionality. It's important to ensure that the removal does not leave a gap in test coverage.

Ensure that the removal of this test function is intentional and that any necessary functionality is covered by other tests or is no longer relevant.

nncf/onnx/statistics/aggregator.py (3)
  • 12-12: The addition of the List import from the typing module is appropriate for the new property metatypes_no_batch_support that returns a list of metatypes.
  • 24-25: The new imports for OPERATIONS_OUTPUT_HAS_NO_BATCH_AXIS and ONNXOpMetatype are correctly added to support the functionality of determining operations that do not support batch dimensions in the ONNX context.
  • 34-36: The introduction of the metatypes_no_batch_support property is a good addition, providing a clear way to access operations that do not support batch dimensions in the ONNX context. This enhances the modularity and clarity of the code.
tests/post_training/pipelines/masked_language_modeling.py (1)
  • 89-91: The addition of a check to enforce the batch size to be 1 for masked language models is a prudent measure to ensure compatibility and expected behavior. This change helps prevent potential issues that could arise from using unsupported batch sizes.
tests/common/experimental/test_tensor_collector_batch_size.py (6)
  • 22-56: The abstract class TemplateTestTensorCollectorBatchSize defines a template for testing tensor collector functionality with different batch sizes. It's well-structured with abstract methods that subclasses must implement to provide specific functionality. This design promotes code reuse and flexibility for testing various tensor collectors.
  • 58-63: The method create_dataitems_without_batch_dim generates a list of numpy arrays with random values, simulating data items without a batch dimension. This utility method is crucial for testing the tensor collector's ability to handle data items of varying shapes. The use of a fixed seed for the random number generator ensures reproducibility of the test results.
  • 65-81: The method add_batch_dim_to_dataitems adds a batch dimension to the list of numpy arrays, simulating the batching of data items. This method is essential for testing the tensor collector's behavior with different batch sizes. The implementation correctly handles the case of a batch size of 1 by using np.expand_dims and aggregates items into batches for larger batch sizes. This method enhances the test's flexibility by allowing the simulation of various batching scenarios.
  • 83-96: The method _create_tensor_collector initializes a TensorCollector instance with specified shape, inplace operation, reducer, and aggregator. It correctly calculates the reduction and aggregation axes based on the input shape and registers a statistic branch with the collector. This method is key to setting up the tensor collector for testing with different configurations, ensuring that the collector is properly initialized for each test scenario.
  • 98-102: The method _register_inputs registers input tensors with the collector, converting them to the backend-specific tensor format using to_backend_tensor. This step is crucial for simulating the process of collecting tensor statistics during model inference. The method ensures that the inputs are correctly prepared and registered with the collector, allowing for accurate collection of statistics.
  • 104-120: The test method test_statistics_batch_size_equal verifies that the aggregated tensor statistics are identical regardless of the batch size used during collection. This test is important for ensuring that the tensor collector's aggregation logic is independent of the batch size, a critical aspect for the reliability of statistics collection in different scenarios. The method is well-structured, clearly demonstrating the setup, execution, and assertion phases of the test.
nncf/onnx/graph/metatypes/groups.py (1)
  • 131-138: The addition of the OPERATIONS_OUTPUT_HAS_NO_BATCH_AXIS list is a significant update for handling specific ONNX operations that mix outputs for different samples into one axis. This change is crucial for ensuring that reducers and aggregators do not mistakenly treat these operations as having a batch axis, which could lead to inaccurate or incorrect statistics results. This update enhances the framework's capability to accurately collect and process tensor statistics by acknowledging the unique behavior of these operations.
tests/torch/ptq/test_graphs.py (2)
  • 23-23: The import of get_static_dataset is a necessary addition for supporting the updated functionality in the test_min_max_classification_quantized_graphs function. This import enables the test to retrieve a static dataset for quantization, aligning with the test's objectives to evaluate the quantized model's performance.
  • 104-106: The update to the test_min_max_classification_quantized_graphs function to use get_static_dataset for retrieving a dataset for quantization is a meaningful improvement. This change ensures that the test operates on a consistent and controlled dataset, enhancing the reliability and reproducibility of the test results. The use of get_static_dataset aligns with best practices for testing quantized models by providing a well-defined dataset for evaluation.
nncf/common/graph/utils.py (1)
  • 119-130: The addition of the get_reduction_axes function is a valuable enhancement to the axis manipulation functionality within the graph utilities. This function correctly filters out channel axes from the reduction axes, ensuring that operations involving tensor reduction are accurately configured with respect to the tensor's shape. The implementation is clear and logically sound, contributing to the framework's flexibility and precision in handling tensor operations.
nncf/data/dataset.py (1)
  • 84-93: The introduction of the get_batch_size method in the Dataset class is a practical enhancement that provides a way to retrieve the batch size of the underlying dataset. This method correctly handles different dataloader types by checking for both batch_size and _batch_size attributes. This addition improves the class's utility by enabling users to programmatically access the batch size, which can be crucial for certain operations or analyses involving the dataset.
nncf/quantization/algorithms/channel_alignment/openvino_backend.py (2)
  • 88-90: The addition of aggregation_axes as a parameter in the MedianAggregator instantiation within the get_statistic_collector method is a positive change. It aligns with the PR's objective to refine tensor statistics aggregation and reduction functionality. This change allows for more flexible axis manipulation when aggregating tensor statistics, which can lead to more accurate and efficient quantization processes.
  • 19-24: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of the get_channel_agnostic_reduction_axes method, as mentioned in the AI-generated summary, is in line with the PR's goal to remove redundant or outdated methods. This contributes to the overall objective of enhancing the framework's efficiency and maintainability.

nncf/quantization/algorithms/smooth_quant/torch_backend.py (1)
  • 24-29: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of the get_channel_agnostic_reduction_axes function from the SmoothQuantTorchBackend class aligns with the PR's objectives to streamline and refine the codebase by eliminating redundant or outdated methods. This change contributes to simplifying the quantization process and improving code maintainability.

nncf/quantization/algorithms/weight_compression/backend.py (1)
  • 63-63: Renaming the get_channel_agnostic_reduction_axes method to get_reduction_axes and adjusting its signature is a thoughtful change that enhances clarity and functionality. This renaming and signature change make it clearer that the method returns reduction axes excluding those corresponding to weight channels, which is crucial for accurate weight compression.
examples/post_training_quantization/torch/mobilenet_v2/main.py (1)
  • 110-110: Adding a batch_size parameter with a value of 128 to the DataLoader instantiation for the validation dataset is a positive change. It aligns with the PR's objective to introduce a batch_size parameter for DataLoader instantiation in validation datasets, aiming to optimize data handling. This change can significantly improve data loading efficiency during validation.
tests/post_training/pipelines/image_classification_timm.py (5)
  • 48-48: Adding self.batch_size to the self.input_size initialization ensures that the input size accurately reflects the batch size being used. This change is crucial for correctly configuring the model input dimensions, especially when dealing with batch processing.
  • 115-115: Updating the batch_size in the DataLoader instantiation for the calibration dataset to use self.batch_size is a good practice. It ensures consistency across the dataset loading process and allows for flexible batch size adjustments.
  • 121-121: Similarly, updating the batch_size in the DataLoader instantiation for the validation dataset to use self.batch_size maintains consistency and flexibility in batch size handling during the validation process.
  • 126-127: Modifying the initialization of predictions and references arrays to support async inference is a thoughtful change. It ensures that the arrays are correctly sized to accommodate batch processing results, which is essential for accurate performance measurement and validation.
  • 144-151: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [147-158]

Adjusting the indexing for predictions and references arrays to handle batch processing during async inference is crucial for correctly mapping inference results to their corresponding labels. This change ensures that the validation accuracy is accurately calculated, reflecting the model's performance.

nncf/openvino/statistics/aggregator.py (2)
  • 26-27: The imports for OPERATIONS_OUTPUT_HAS_NO_BATCH_AXIS and OVOpMetatype have been added. Ensure that these imports are utilized within the file and that there are no unused imports which could clutter the namespace.
  • 36-38: The new property metatypes_no_batch_support returns a list of OVOpMetatype which are operations that do not support batch processing. This is a good addition for clarity and maintainability, allowing for easy identification of operations that might affect batch processing. Ensure that this property is utilized wherever necessary to prevent operations on unsupported metatypes.
nncf/openvino/graph/metatypes/groups.py (1)
  • 200-211: The addition of OPERATIONS_OUTPUT_HAS_NO_BATCH_AXIS is a significant improvement for handling operations that mix outputs for different samples into one axis. This change will help in avoiding inaccurate statistics results by making it clear which operations do not assume a batch axis. Ensure that this list is kept up-to-date as new operations are added or existing ones are modified.
nncf/quantization/algorithms/post_training/pipeline.py (1)
  • 121-121: The introduction of statistics_per_sample in the PTQ pipeline configuration is a valuable addition, enabling more granular control over statistics computation. This change allows for per-sample statistics computation, which can be crucial for certain models and datasets. Ensure that this parameter is properly documented and tested to verify its impact on the quantization process.
nncf/onnx/graph/node_utils.py (3)
  • 137-137: Renaming _get_weight_quantization_axis to get_weight_quantization_axis improves the clarity of the function's purpose and its visibility outside the module. This change aligns with best practices for naming functions that are intended to be used externally. Ensure that all references to this function are updated accordingly.
  • 181-186: Modifying the logging messages in _get_activation_tensor_shape to provide more specific information about unknown shapes for input and output edges is a good practice. It helps in debugging and understanding potential issues with statistics collection. Ensure that the logging level is appropriate and that these messages are clear and informative to the users.
  • 178-189: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [137-186]

The removal of get_quantization_axis function and _get_activation_quantization_axis indicates a refactoring or simplification of the quantization axis determination logic. Ensure that the functionality provided by these removed functions is either no longer needed or has been integrated into other parts of the codebase without loss of functionality or clarity.

nncf/quantization/algorithms/weight_compression/openvino_backend.py (1)
  • 64-67: The function get_reduction_axes has been correctly renamed and its implementation updated to align with the new name. This change is consistent with the PR's objective of enhancing axis manipulation functionality. The use of get_weight_channel_axes and get_reduction_axes within this method appears logically sound, as it first determines the channel axes and then uses these along with the shape of the constant to determine the reduction axes. This should work well for the intended purpose of refining tensor statistics aggregation and reduction functionality.
nncf/experimental/tensor/functions/numpy_numeric.py (1)
  • 173-180: The update to the mean function to include a dtype parameter is a positive change, enhancing the flexibility of data type specification in computations. The conversion of the dtype parameter using DTYPE_MAP before calculating the mean ensures that the function can handle different specified data types correctly. This change aligns well with the PR's objective of streamlining the handling of tensor data types in statistical functions.
nncf/experimental/tensor/functions/torch_numeric.py (1)
  • 186-193: The inclusion of a dtype parameter in the mean function for PyTorch tensors is a valuable enhancement, allowing for more precise control over the data type used in computations. The conversion of the dtype using DTYPE_MAP before calling torch.mean ensures that the function can correctly handle the specified data types. This update is consistent with the PR's goal of improving the handling of tensor data types in statistical functions and enhances the framework's flexibility.
nncf/common/tensor_statistics/aggregator.py (6)
  • 30-41: The addition of warning messages (EMPTY_DATASET_MESSAGE, BATCH_SIZE_IS_BIGGER_THAN_SUBSET_SIZE_MESSAGE, BATCH_SIZE_MODEL_WARNING, DECREASING_SAMPLES_NUMBER_MESSAGE) is a good practice for improving user experience by providing clear and informative feedback regarding potential issues with dataset validation and batch size handling.
  • 56-62: The constructor of StatisticsAggregator now initializes self.batch_size by calling self.dataset.get_batch_size() and defaults to 1 if the returned value is None. This approach ensures that a valid batch size is always used. However, it's crucial to ensure that self.dataset.get_batch_size() is guaranteed to return either a valid integer or None, as any other type could lead to unexpected behavior.
Verification successful

The get_batch_size method in nncf/data/dataset.py is annotated to return Optional[int], which confirms it is designed to return either an integer or None. This aligns with the review comment's requirement for the method to ensure a valid batch size is always used or default to None.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that get_batch_size() returns either an integer or None.
ast-grep --lang python --pattern $'class Dataset {
  $$$
  get_batch_size() {
    return $_
  }
  $$$
}'

Length of output: 450



Script:

#!/bin/bash
# Search for the get_batch_size method in Python files to inspect its implementation and return types.
rg "def get_batch_size\(self\)" -t py

Length of output: 107

* 61-62: Raising a `ValidationError` if `self.dataset_sample_size` is 0 is a robust way to prevent proceeding with an empty dataset. This check enhances the robustness of the statistics collection process by ensuring that there is at least one sample in the dataset. * 98-99: The warning about the potential inaccuracy of collected statistics when `self.batch_size > 1` for models that do not support batch axis is a thoughtful addition. It guides users to adjust their batch size to 1 for more accurate statistics collection. This is especially important for models where batch size can significantly impact the collected statistics. * 111-115: The logic to handle cases where the `iterations_num` is 0 and to adjust `statistics_samples_num` based on the actual number of samples processed is well-implemented. It ensures that the statistics collection process is aligned with the provided batch size and subset size, enhancing the accuracy and reliability of the collected statistics. Additionally, logging a warning when the number of samples for statistics collection is decreased is a good practice for transparency. * 126-126: Raising a `ValidationError` if no statistics are collected (`empty_statistics` is `True`) after attempting to collect statistics is a critical check. It ensures that the statistics collection process has successfully processed at least one batch of data, preventing silent failures or incorrect assumptions about the collected statistics.
nncf/quantization/algorithms/min_max/backend.py (3)
  • 185-195: The addition of the abstract method get_target_point_shape is a significant enhancement. It allows for the retrieval of the shape of a target point tensor, which is essential for determining the appropriate axes for quantization and statistics collection. This method enhances the flexibility and adaptability of the quantization process by accommodating different tensor shapes.
  • 197-206: Introducing the abstract method get_channel_axes is a valuable addition. It enables the determination of axes for per-channel quantization, which is crucial for applying quantization accurately across different dimensions of a tensor. This method supports the implementation of more precise and efficient quantization strategies by allowing for channel-wise adjustments.
  • 211-223: The modifications to the get_statistic_collector method, including the addition of parameters use_abs_max, reduction_axes, aggregation_axes, and num_samples, significantly enhance its functionality. These changes allow for more granular control over the statistic collection process, enabling the customization of reduction and aggregation behavior as well as the handling of absolute maximum values. This flexibility is crucial for tailoring the statistic collection to specific needs and scenarios.
nncf/common/quantization/initialization/range.py (3)
  • 211-228: The addition of the _get_reduction_axes method is a significant improvement. It calculates the axes for a reducer considering the aggregation axes, ensuring that only tensor-related axes are used for reduction. This method enhances the precision of the reduction process by accurately identifying the axes that should be considered, thereby improving the quality of the statistics collected for quantization initialization.
  • 230-237: Introducing the _get_aggregation_axes method is a valuable enhancement. It determines the axes for aggregator based on whether statistics should be aggregated per sample. This method provides flexibility in handling different aggregation scenarios, allowing for more accurate and tailored statistics collection based on the specific needs of the quantization process.
  • 239-255: The get_reduction_aggregation_axes method is a crucial addition. It calculates both the reduction and aggregation axes for a tensor, taking into account the shape of the tensor, the quantization axes, and whether statistics should be calculated per sample. This method streamlines the process of determining the appropriate axes for statistics collection, enhancing the efficiency and accuracy of the quantization initialization process.
tests/post_training/test_quantize_conformance.py (2)
  • 48-50: The addition of a batch_size fixture is a good practice for parameterizing tests based on external configuration. This allows for more flexible testing scenarios, especially when dealing with different batch sizes which can significantly affect performance and behavior in quantization processes.
  • 221-233: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [204-230]

Including the batch_size parameter in the test_ptq_quantization function's pipeline kwargs is a necessary change to test the behavior of post-training quantization with different batch sizes. This ensures that the quantization process is tested under conditions that closely mimic real-world usage scenarios. It's important to verify that all dependent functions and classes properly handle the batch_size parameter to avoid unexpected behavior.

nncf/quantization/algorithms/min_max/openvino_backend.py (3)
  • 141-147: The get_target_point_shape method has been refactored to handle different target point types, providing the shape of the tensor associated with the target point. This is a crucial change for accurately determining the shape of tensors for quantization, especially in a complex framework like OpenVINO. Ensure that all target point types are covered and correctly handled.
  • 151-154: The get_channel_axes method correctly identifies the axes of the channels for weight target points, which is essential for per-channel quantization. This change aligns with the need for more granular control over quantization axes, particularly in convolutional layers where per-channel quantization can significantly impact model accuracy.
  • 184-198: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [159-195]

The refactoring of the get_statistic_collector method to include use_abs_max, reduction_axes, and aggregation_axes parameters enhances the flexibility and accuracy of statistics collection for quantization. The use of absolute max values is particularly important for ensuring robustness in quantization, especially in scenarios with asymmetric data distributions. It's crucial to verify that all possible statistics and aggregator types are supported and correctly implemented for the OpenVINO backend.

Verification successful

The verification process has successfully identified the contents of OV_REDUCERS_MAP and AGGREGATORS_MAP. The OV_REDUCERS_MAP includes support for StatisticsType.MIN, MAX, ABS_MAX, MEAN, QUANTILE, and ABS_QUANTILE. The AGGREGATORS_MAP supports AggregatorType.MIN, MAX, MEAN, MEAN_NO_OUTLIERS, MEDIAN, and MEDIAN_NO_OUTLIERS.

This confirms that the refactoring of the get_statistic_collector method to include use_abs_max, reduction_axes, and aggregation_axes parameters is supported by a comprehensive implementation of statistics and aggregator types for the OpenVINO backend, as required by the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all supported statistics and aggregator types are correctly implemented in the OV_REDUCERS_MAP and AGGREGATORS_MAP.
rg --type py "OV_REDUCERS_MAP" -A 5 | grep -q "StatisticsType"
rg --type py "AGGREGATORS_MAP" -A 5 | grep -q "AggregatorType"

Length of output: 121



Script:

#!/bin/bash
# Find and print the contents of OV_REDUCERS_MAP and AGGREGATORS_MAP to verify supported statistics and aggregator types.
rg --type py "OV_REDUCERS_MAP = {" -A 20
rg --type py "AGGREGATORS_MAP = {" -A 20

Length of output: 289



Script:

#!/bin/bash
# Correcting the regex syntax and attempting to print the contents of OV_REDUCERS_MAP and AGGREGATORS_MAP again.
rg --type py "OV_REDUCERS_MAP = \{" -A 20
rg --type py "AGGREGATORS_MAP = \{" -A 20

Length of output: 1457

nncf/quantization/algorithms/min_max/onnx_backend.py (3)
  • 12-12: The addition of Tuple to the imports is necessary for type hinting in the modified methods. This is a minor but important change for maintaining code clarity and type safety.
  • 30-30: Renaming get_quantization_axis to get_weight_quantization_axis improves the clarity of the method's purpose, which is specifically to determine the quantization axis for weight tensors. This naming convention aligns better with the method's functionality and makes the codebase more understandable.
  • 183-208: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [171-205]

The refactoring of the get_statistic_collector method in the ONNX backend to handle use_abs_max, reduction_axes, and aggregation_axes parameters is a significant improvement. This change allows for more precise and flexible statistics collection, which is crucial for effective quantization. It's important to ensure that the ONNX backend supports all necessary statistics and aggregator types and that the logic for handling absolute max values and quantiles is correctly implemented.

Verification successful

Given the lack of output from the previous script, it's necessary to directly inspect the definitions of ONNX_REDUCERS_MAP and AGGREGATORS_MAP to verify their contents and ensure they correctly implement all supported statistics and aggregator types. Additionally, we should examine the logic for handling absolute max values and quantiles. Let's proceed with a more targeted approach to gather the required information.


The provided context from the shell scripts offers a comprehensive view of the usage of use_abs_max, reduction_axes, aggregation_axes, and handling of quantiles across various parts of the codebase. It confirms the implementation and usage of these parameters and logic in multiple backend-specific and general-purpose methods, including those for ONNX, OpenVINO, Torch, and TensorFlow backends. The context also shows tests and other algorithmic implementations that rely on these parameters, indicating their integration into the broader system.

Given the extensive references to the parameters and logic in question across different parts of the codebase, it's clear that the refactoring to handle use_abs_max, reduction_axes, and aggregation_axes parameters, as well as the logic for handling absolute max values and quantiles, has been implemented as described. The code snippets provided in the new context demonstrate the application of these parameters in statistical collection and processing, which is crucial for effective quantization.

Based on the evidence provided by the new context, the review comment regarding the significant improvement brought by the refactoring of the get_statistic_collector method in the ONNX backend to handle these parameters and logic is verified. The changes allow for more precise and flexible statistics collection, which is essential for effective quantization.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all supported statistics and aggregator types are correctly implemented in the ONNX_REDUCERS_MAP and AGGREGATORS_MAP.
rg --type py "ONNX_REDUCERS_MAP" -A 5 | grep -q "StatisticsType"
rg --type py "AGGREGATORS_MAP" -A 5 | grep -q "AggregatorType"

Length of output: 123



Script:

#!/bin/bash
# Inspect the definitions of ONNX_REDUCERS_MAP and AGGREGATORS_MAP
rg --type py "ONNX_REDUCERS_MAP = {" -A 10
rg --type py "AGGREGATORS_MAP = {" -A 10

# Check for the implementation of logic for handling absolute max values and quantiles
rg --type py "use_abs_max" -A 5 -B 5
rg --type py "quantile" -A 5 -B 5

Length of output: 108513

tests/post_training/test_templates/helpers.py (2)
  • 33-40: The addition of the length parameter to the StaticDatasetMock class's __init__ method is a good enhancement for specifying the dataset length. This change allows for more flexible dataset mock creation, which can be particularly useful for testing with datasets of varying sizes. Ensure that all usages of StaticDatasetMock throughout the test suite have been updated to include the new length argument where necessary.
  • 55-67: The update to the get_static_dataset function to include a new length parameter and its subsequent use when calling StaticDatasetMock is a logical extension of the changes made to StaticDatasetMock. This ensures that the dataset length can be controlled at the point of dataset creation, enhancing test flexibility and precision. It's important to verify that all calls to get_static_dataset across the test suite have been reviewed and updated as needed to pass the appropriate length argument.
tests/post_training/pipelines/base.py (1)
  • 184-190: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [187-197]

The introduction of a batch_size parameter to the BaseTestPipeline class constructor is a valuable addition for controlling the batch size during model evaluation and benchmarking. This change allows for more granular control over resource utilization and performance measurement. It's crucial to ensure that all subclasses and usages of BaseTestPipeline are updated to handle this new parameter appropriately, including passing it where necessary and adjusting any logic that depends on the batch size.

nncf/quantization/algorithms/min_max/torch_backend.py (1)
  • 156-182: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [174-204]

The get_statistic_collector method has been modified to include new parameters and logic adjustments, particularly related to the use_abs_max flag. The method now supports the ABS_MAX statistic type, which is a significant addition for handling absolute maximum values during quantization. It's crucial to verify that this change does not introduce any regressions in existing functionality and that it's compatible with the overall quantization process. Additionally, consider adding comments to explain the rationale behind specific logic decisions, such as the handling of the ABS_MAX statistic type, to improve code readability and maintainability.

Verification successful

The review comment highlighted the introduction of the use_abs_max flag and adjustments related to the ABS_MAX statistic type in the get_statistic_collector method, emphasizing the importance of ensuring these changes do not introduce regressions in the quantization process. The verification process involved examining test files, documentation, and other parts of the codebase that interact with the get_statistic_collector method.

From the provided context and the examination of the relevant files, it is evident that:

  1. Test Coverage: The presence of tests specifically mentioning the get_statistic_collector method and related functionality (tests/torch/tensor_statistics/test_tensor_statistics.py, tests/post_training/test_templates/test_channel_alignment.py, etc.) suggests that the changes have been considered in the testing phase. This is a positive indication that potential regressions might have been caught during testing.

  2. Documentation and Code Comments: The file nncf/torch/tensor_statistics/collectors.py contains detailed documentation and comments explaining the functionality of various collectors, including those related to the ABS_MAX statistic type (PTAbsMaxReducer). This documentation provides insights into the rationale behind the changes and how they are expected to integrate with the existing quantization process.

  3. Usage Across the Codebase: The method get_statistic_collector and related functionality are referenced in multiple parts of the codebase, including different backends (nncf/quantization/algorithms/min_max/torch_backend.py, nncf/quantization/algorithms/channel_alignment/algorithm.py, etc.), indicating that the changes are significant and intended to be universally applicable.

Given the evidence from the test files, documentation, and usage across the codebase, it can be concluded that the changes related to the use_abs_max flag and the handling of the ABS_MAX statistic type have been thoroughly considered, tested, and documented. While the direct verification of no regressions is beyond the scope of this analysis, the presence of specific tests and detailed documentation is a strong indicator that the changes have been implemented with care to maintain compatibility with the overall quantization process.

Based on the analysis, the review comment regarding the verification of no regressions due to the changes in the get_statistic_collector method is addressed by the presence of relevant tests, detailed documentation, and consistent usage across the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify no regressions in quantization process due to changes in get_statistic_collector
# This script is a placeholder and should be replaced with actual verification steps
echo "Verify no regressions in quantization process"

Length of output: 100



Script:

#!/bin/bash
# Search for tests related to the get_statistic_collector method and the quantization process
rg "get_statistic_collector" --files-with-matches tests

# Look for documentation or comments related to the use_abs_max flag and ABS_MAX statistic type
rg "use_abs_max|ABS_MAX" --files-with-matches

# Identify other parts of the codebase that interact with the get_statistic_collector method
rg "get_statistic_collector" --files-with-matches

Length of output: 1566



Script:

#!/bin/bash
# Examine the content of the test files related to the get_statistic_collector method and the new logic
cat tests/post_training/test_templates/test_channel_alignment.py

# Review documentation or comments in one of the files that mention the use_abs_max flag and the ABS_MAX statistic type for insights
cat nncf/torch/tensor_statistics/collectors.py

# Analyze the usage of the get_statistic_collector method in another part of the codebase
cat nncf/quantization/algorithms/channel_alignment/algorithm.py

Length of output: 67818

tests/torch/test_statistics_aggregator.py (1)
  • 171-171: The addition of the mocker parameter to the test functions test_successive_statistics_aggregation, test_nested_statistics_aggregation, and the modification of the __get_statistic_points method signature to include the mocker parameter are consistent with the use of the pytest-mock plugin for mocking dependencies in tests. This change enhances the test's flexibility and allows for more controlled testing environments. Ensure that the mocker is used effectively within the tests to mock external dependencies or behaviors as needed. Additionally, it's good practice to include comments or documentation on how the mocker is being utilized within the test cases for clarity.

Also applies to: 258-258, 313-326

nncf/torch/quantization/init_range.py (2)
  • 110-113: The method get_reduction_aggregation_axes is introduced to replace the previous get_reduction_axes and get_aggregation_axes methods. It's crucial to ensure that all calls to the old methods have been updated to use this new method. Additionally, verify that the logic within this method correctly handles the input parameters to return the appropriate ReductionAxes and AggregationAxes.
  • 161-161: The call to get_reduction_aggregation_axes within generate_stat_collector_for_range_init_config correctly passes the use_per_sample_stats parameter. Ensure that the logic for determining use_per_sample_stats accurately reflects the intended behavior for each range initialization type.
tests/post_training/test_templates/test_quantizer_config.py (2)
  • 85-85: The introduction of the is_per_sample boolean parameter in the TestGetStatisticsCollectorParameters class is a significant change. Ensure that this parameter is correctly used in all relevant test cases to reflect the new functionality related to per-sample statistics collection.
  • 89-123: The modifications to the @pytest.fixture decorator to include test parameters with different configurations for TestGetStatisticsCollectorParameters are well done. It's important to verify that these configurations cover all necessary scenarios for testing the impact of the is_per_sample parameter on statistic collector parameters and assertions.
tests/post_training/test_templates/test_ptq_params.py (1)
  • 143-143: The addition of a blank line before the stat_points assignment improves readability by visually separating the setup phase of the test from the action phase. This change is consistent with Python's PEP 8 guidelines, which recommend using blank lines to separate functions and classes, and around blocks of code to indicate logical sections.
nncf/openvino/graph/node_utils.py (1)
  • 373-378: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of the get_channel_agnostic_reduction_axes function seems aligned with the PR's objectives to refine axis manipulation functionality. However, it's crucial to ensure that this removal does not introduce breaking changes by leaving any references to the function elsewhere in the codebase or impacting expected functionality negatively.

nncf/quantization/advanced_parameters.py (1)
  • 209-215: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [193-223]

The addition of the statistics_per_sample parameter to the AdvancedQuantizationParameters class is a significant enhancement. It allows for more granular control over how statistics are calculated, specifically enabling or disabling per-sample statistics calculation. This can be particularly useful in scenarios where batch-level statistics might not be representative of individual sample characteristics, potentially leading to more accurate quantization.

However, it's important to ensure that this new parameter is properly documented, including its default behavior and how it interacts with other parameters or quantization processes. Additionally, considering the potential impact on performance and memory usage, especially for large batch sizes, it might be beneficial to provide guidance on when to use this feature.

nncf/quantization/algorithms/smooth_quant/algorithm.py (2)
  • 24-24: The import of get_reduction_axes from nncf.common.graph.utils is correctly placed and follows the project's import conventions. This utility function is essential for determining the axes over which reduction operations should be performed, which is a common requirement in quantization and normalization processes.
  • 373-373: Replacing the previous method call with get_reduction_axes in the _calculate_input_reduction_axes method is a good improvement. This change likely makes the axis calculation more robust and maintainable by leveraging a common utility function designed for this purpose. It's important to ensure that the get_reduction_axes function is thoroughly tested, especially in edge cases where tensor shapes might be unusual or where the channel axis is not standard.

One minor suggestion is to add a comment explaining the rationale behind choosing the specific axes for reduction, especially for those who might not be familiar with the intricacies of tensor operations in neural networks. This can improve the readability and maintainability of the code.

nncf/onnx/graph/metatypes/onnx_metatypes.py (1)
  • 449-450: The renaming of ONNXRoiAlignMetatype to ONNXROIAlignMetatype and the update of its name attribute from "RoiAlignOp" to "ROIAlignOp" improves naming consistency and clarity. However, it's essential to ensure that all references to this metatype, both within this file and across the codebase, are updated to reflect the new class name and attribute value. This includes checking for dynamic references that might not be directly visible.
Verification successful

The search for references to the old class name "ONNXRoiAlignMetatype" and the old name attribute value "RoiAlignOp" within the Python files of the codebase did not yield any results. This suggests that the renaming to ONNXROIAlignMetatype and the update of its name attribute to "ROIAlignOp" were successfully reflected across the codebase, with no remaining references to the old identifiers. It's important to remain aware of the search's scope, which was limited to Python files and exact string matches. However, based on the provided evidence, it appears that the renaming and update were thoroughly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for old class name references in the codebase
rg --type py "ONNXRoiAlignMetatype"
# Search for old name attribute references in the codebase
rg --type py '"RoiAlignOp"'

Length of output: 65

nncf/openvino/graph/metatypes/openvino_metatypes.py (2)
  • 472-473: The renaming of OVROIAlignMetatype to OVROIAlignMetatype aligns with the naming conventions used throughout the file, ensuring consistency. This change is straightforward and appears to be correctly implemented.
  • 478-480: The addition of the OVROIPoolingMetatype class is a significant enhancement. It's important to ensure that the op_names attribute correctly lists all operation names associated with ROIPooling in OpenVINO. If there are any version-specific names or aliases that should be included, they need to be added to the op_names list for comprehensive coverage.
Verification successful

Based on the search results within the repository, "ROIPooling" appears to be the only operation name referenced for the OVROIPoolingMetatype. No additional aliases or operation names were found. This conclusion is drawn from the repository's context and does not exclude the possibility of other operation names or aliases existing outside of it.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if "ROIPooling" is the only operation name for ROIPooling in OpenVINO or if there are any aliases.
# This script is a placeholder for the actual verification process, which would involve checking OpenVINO documentation or source code.
echo "Check OpenVINO documentation or source code for ROIPooling operation names and aliases."

Length of output: 184



Script:

#!/bin/bash
# Search for "ROIPooling" and potential aliases in the repository to verify if there are any additional operation names.
rg "ROIPooling" -C 3

Length of output: 1179

nncf/quantization/algorithms/channel_alignment/algorithm.py (2)
  • 25-25: The addition of the get_reduction_axes import from nncf.common.graph.utils is correctly placed and follows Python's import conventions. This change aligns with the PR's objective to enhance axis manipulation functionality.
  • 393-393: Replacing self._backend_entity.get_channel_agnostic_reduction_axes with get_reduction_axes directly calls a utility function, which simplifies the code by removing the need to access backend-specific implementations for obtaining reduction axes. This change should improve the maintainability and clarity of the code, assuming get_reduction_axes provides the same or enhanced functionality compared to the previous method. However, it's crucial to ensure that get_reduction_axes is fully compatible with the expected inputs and outputs of the replaced method.
Verification successful

The replacement of get_channel_agnostic_reduction_axes with get_reduction_axes appears to be well-integrated into the codebase, with the latter function being directly tested for its functionality. The absence of the former function in the search results supports the notion that it has been replaced. Based on the information available, it seems reasonable to conclude that get_reduction_axes is intended to provide compatible or enhanced functionality compared to the previous method, and its usage is supported by tests within the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that get_reduction_axes provides compatible functionality
# This script is a placeholder for the actual verification process, which should include:
# 1. Reviewing the implementation of get_reduction_axes.
# 2. Ensuring it handles all cases previously covered by get_channel_agnostic_reduction_axes.
# 3. Testing the new implementation in the context of the ChannelAlignment algorithm.
echo "Manual verification needed to ensure get_reduction_axes compatibility."

Length of output: 150



Script:

#!/bin/bash
# Locate the implementation of get_reduction_axes
fd ".*\.py$" --exec rg "def get_reduction_axes" {}

# Locate the implementation of get_channel_agnostic_reduction_axes if it still exists
fd ".*\.py$" --exec rg "def get_channel_agnostic_reduction_axes" {}

# Search for tests related to get_reduction_axes
fd ".*test.*\.py$" --exec rg "get_reduction_axes" {}

Length of output: 1321

tests/post_training/test_templates/test_channel_alignment.py (2)
  • 531-531: The call to MockBackend.get_statistic_collector has been updated with new parameters. Ensure that the new parameters (2, 3), 1e-4, ref_subset_size, ref_inplace align with the expected functionality and that the changes are consistent with the objectives of enhancing tensor statistics aggregation and reduction functionality. It's important to verify that the new parameters are correctly utilized within the get_statistic_collector method and that they contribute to the intended improvements in data handling and processing.
  • 558-558: The modification of _aggregation_axes to (0, 1) in the test_statistic_collectors method changes the axes over which aggregation is performed. This adjustment should be carefully reviewed to ensure it aligns with the intended axis manipulation enhancements described in the PR objectives. It's crucial to verify that this change accurately reflects the new logic for determining reduction axes based on tensor statistics and that it contributes to the overall improvements in the framework's efficiency and flexibility.
nncf/quantization/quantize_model.py (2)
  • 113-113: The call to _update_advanced_quantization_parameters within the quantize function is correctly placed and ensures that advanced quantization parameters are updated based on the batch size of the calibration dataset before proceeding with quantization. This is a good practice for ensuring that the quantization process is tailored to the dataset characteristics.
  • 248-250: Similar to the quantize function, the quantize_with_accuracy_control function correctly updates the advanced quantization parameters using _update_advanced_quantization_parameters. This consistency across functions is commendable and ensures that the advanced parameters are appropriately handled regardless of the quantization approach used.
nncf/torch/graph/operator_metatypes.py (1)
  • 1055-1064: The addition of OPERATIONS_OUTPUT_HAS_NO_BATCH_AXIS is a thoughtful approach to addressing potential inaccuracies in statistics collection due to operations that mix outputs for different samples into one axis. It's crucial to keep this list updated as new metatypes are introduced or existing ones are modified to ensure the accuracy of statistics results.
tests/common/test_statistics_aggregator.py (7)
  • 27-27: The import of EMPTY_DATASET_MESSAGE is added to support new test cases handling empty datasets. This is a good practice as it leverages a predefined message for consistency across error handling.
  • 35-35: The import of MinMaxQuantization is necessary for the new method get_min_max_algo_cls which returns the MinMaxQuantization class. This aligns with the PR's objective to refine tensor statistics aggregation and reduction functionality.
  • 44-50: The MockedDataset class is introduced to simulate a dataset with no elements, particularly useful for testing scenarios where the dataset is empty. This is a straightforward and effective way to test edge cases without needing to manipulate actual datasets.
  • 132-133: The get_min_max_algo_cls method is added to return the MinMaxQuantization class. This method simplifies the process of obtaining the class for quantization algorithms, supporting the PR's goal of improving the quantization process.
  • 398-398: The addition of the mocker parameter in the test_statistics_aggregator_min_max function (and similar additions in other test functions) is crucial for enabling the mocking of dependencies during testing. This enhances the test's reliability by isolating it from external changes and dependencies.
  • 907-914: The test_collect_with_empty_dataset method correctly tests the behavior of the statistics aggregator when provided with an empty dataset. It ensures that an appropriate error is raised, aligning with the objective of improving dataset validation and batch size warnings.
  • 916-935: The test_collect_with_empty_dataset_no_len method tests the scenario where a dataset without a len() method (but effectively empty) is used. This test is important for ensuring robustness in handling datasets that might not conform to typical expectations, such as those lacking a len() method.
tests/openvino/tools/calibrate.py (3)
  • 104-105: The addition of the --batch_size argument to the command-line parser is correctly implemented with a default value of 1. This change allows users to specify the batch size for data loading, which can improve data handling efficiency.
  • 1038-1043: The update_config function correctly updates the batch size in the accuracy checker configuration. This function iterates through the models and datasets within the accuracy checker configuration and updates the batch attribute to the new batch_size value. This is a straightforward and effective way to propagate the batch size specified by the user to the underlying dataset handling logic.
  • 1055-1055: The call to update_config in the main function correctly passes the args.batch_size argument to update the batch size in the accuracy checker configuration. This ensures that the user-specified batch size is applied to the datasets used in the calibration process.
nncf/quantization/algorithms/min_max/algorithm.py (2)
  • 401-444: The _get_stat_collector method has been updated to utilize the is_per_sample parameter, which is derived from the newly introduced statistics_per_sample. This change allows for more granular control over how statistics are collected, potentially improving the accuracy of quantization for certain models. However, ensure that the logic correctly handles cases where per-sample statistics collection is not applicable or desired, especially for weight tensors where is_per_sample is forcibly set to False.

Ensure that the implementation correctly handles edge cases and that the performance impact of collecting statistics per sample is acceptable.

  • 937-938: The call to _get_stat_collector within the get_statistic_points method correctly passes the statistics_per_sample parameter. This ensures that the statistic collection behavior is consistent with the configuration specified during the initialization of the MinMaxQuantization instance. This change aligns with the objective of enhancing the flexibility of statistics collection based on the new parameter.

tests/openvino/tools/calibrate.py Show resolved Hide resolved
nncf/experimental/tensor/functions/numeric.py Show resolved Hide resolved
nncf/quantization/quantize_model.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants