OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[DOCS] NNCF section adjustments pass2 (#26461)
Karol Blaszczakadffbfd1a77b
diff --git a/docs/articles_en/assets/images/WHAT_TO_USE.svg b/docs/articles_en/assets/images/WHAT_TO_USE.svgindex 5cba27ea4ee..982d351c3d1 100644--- a/docs/articles_en/assets/images/WHAT_TO_USE.svg+++ b/docs/articles_en/assets/images/WHAT_TO_USE.svg@@ -1,3 +1,3 @@version https://git-lfs.github.com/spec/v1-oid sha256:2a30e182191979bf0693d9060eee2596313e162042f68bce31859670e21ad0c4-size 206149+oid sha256:16be25b0e2c357862066186e6fd72f7552c1160870ac667e2019c3a48abf07ca+size 226264diff --git a/docs/articles_en/assets/images/quantization_picture.svg b/docs/articles_en/assets/images/quantization_picture.svgindex b7049d5e16d..7d5c70f2fd6 100644--- a/docs/articles_en/assets/images/quantization_picture.svg+++ b/docs/articles_en/assets/images/quantization_picture.svg@@ -1,3 +1,3 @@version https://git-lfs.github.com/spec/v1-oid sha256:77b7a9b61ad2069a42807b524d386bf7a505e6bf7f3fd9416f3c89fb14f868d9-size 51194+oid sha256:81752df5a7a0e0fc5dc866a058c2494b546a8f55553bd30e3bf979186b5b5fbf+size 83912diff --git a/docs/articles_en/openvino-workflow/model-optimization-guide/compressing-models-during-training.rst b/docs/articles_en/openvino-workflow/model-optimization-guide/compressing-models-during-training.rstindex e8761bab85b..9e18707a7f3 100644--- a/docs/articles_en/openvino-workflow/model-optimization-guide/compressing-models-during-training.rst+++ b/docs/articles_en/openvino-workflow/model-optimization-guide/compressing-models-during-training.rst@@ -1,4 +1,4 @@-Compressing Models During Training+Training-time Optimization==================================@@ -10,83 +10,77 @@ Compressing Models During Trainingcompressing-models-during-training/filter-pruning-Introduction-####################--Training-time model compression improves model performance by applying optimizations (such as quantization) during the training. The training process minimizes the loss associated with the lower-precision optimizations, so it is able to maintain the model’s accuracy while reducing its latency and memory footprint. Generally, training-time model optimization results in better model performance and accuracy than :doc:`post-training optimization <quantizing-models-post-training>`, but it can require more effort to set up.--OpenVINO provides the Neural Network Compression Framework (NNCF) tool for implementing compression algorithms on models to improve their performance. NNCF is a Python library that integrates into PyTorch and TensorFlow training pipelines to add training-time compression methods to the pipeline. To apply training-time compression methods with NNCF, you need:+Training-time optimization offered by NNCF is based on model compression algorithms executed+alongside the training process. This approach results in the optimal balance between lower+accuracy and higher performance, and better results than post-training quantization. It also+enables you to set the minimum acceptable accuracy value for your optimized model, determining+the optimization efficiency.-- A floating-point model from the PyTorch or TensorFlow framework.-- A training pipeline set up in the PyTorch or TensorFlow framework.-- Training and validation datasets.--Adding compression to a training pipeline only requires a few lines of code. The compression techniques are defined through a single configuration file that specifies which algorithms to use during fine-tuning.--NNCF Quick Start Examples-+++++++++++++++++++++++++--See the following Jupyter Notebooks for step-by-step examples showing how to add model compression to a PyTorch or Tensorflow training pipeline with NNCF:--- `Quantization Aware Training with NNCF and PyTorch <https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/pytorch-quantization-aware-training>`__.-- `Quantization Aware Training with NNCF and TensorFlow <https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/tensorflow-quantization-aware-training>`__.--More detailed information about NNCF (e.g. installation guide) is present in the dedicated-:doc:`NNCF article <../model-optimization>`.--Working with NNCF-####################+With a few lines of code, you can apply NNCF compression to a PyTorch or TensorFlow training+script. Once the model is optimized, you may convert it to the+:doc:`OpenVINO IR format <../../documentation/openvino-ir-format>`, getting even better+inference results with OpenVINO Runtime. To optimize your model, you will need:-The figure below shows a common workflow of applying training-time compressions with NNCF. The NNCF optimizations are added to the TensorFlow or PyTorch training script, and then the model undergoes fine-tuning. The optimized model can then be exported to OpenVINO IR format for accelerated performance with OpenVINO Runtime.+* A PyTorch or TensorFlow floating-point model.+* A training pipeline set up in the original framework (PyTorch or TensorFlow).+* Training and validation datasets.+* A `JSON configuration file <https://github.com/openvinotoolkit/nncf/blob/develop/docs/ConfigFile.md>`__+ specifying which compression methods to use... image:: ../../assets/images/nncf_workflow.svg:align: center-Training-Time Compression Methods-+++++++++++++++++++++++++++++++++-NNCF provides several methods for improving model performance with training-time compression.+Training-Time Compression Methods+########################################Quantization----------------------Quantization is the process of converting the weights and activation values in a neural network from a high-precision format (such as 32-bit floating point) to a lower-precision format (such as 8-bit integer). It helps to reduce the model’s memory footprint and latency. NNCF uses quantization-aware training to quantize models.++++++++++++++++++++++++++-Quantization-aware training inserts nodes into the neural network during training that simulate the effect of lower precision. This allows the training algorithm to consider quantization errors as part of the overall training loss that gets minimized during training. The network is then able to achieve enhanced accuracy when quantized.+Uniform 8-bit quantization, the method officially supported by NNCF, converts all weights and+activation values in a model from a high-precision format, such as 32-bit floating point, to a+lower-precision format, such as 8-bit integer. During training, it inserts into the model nodes+that simulate the effect of a lower precision. This way, the training algorithm considers+quantization errors part of the overall training loss and tries to minimize their impact.++To learn more, see:++* guide on quantization for :doc:`PyTorch <./compressing-models-during-training/quantization-aware-training-pytorch>`.+* guide on quantization for :doc:`Tensorflow <./compressing-models-during-training/quantization-aware-training-tensorflow>`.+* Jupyter notebook on `Quantization Aware Training with NNCF and PyTorch <https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/pytorch-quantization-aware-training>`__.+* Jupyter notebook on `Quantization Aware Training with NNCF and TensorFlow <https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/tensorflow-quantization-aware-training>`__.-The officially supported method of quantization in NNCF is uniform 8-bit quantization. This means all the weights and activation functions in the neural network are converted to 8-bit values. See the :doc:`Quantization-aware Training guide <compressing-models-during-training/quantization-aware-training>` to learn more.Filter pruning---------------------++++++++++++++++++++++++++-Filter pruning algorithms compress models by zeroing out the output filters of convolutional layers based on a certain filter importance criterion. During fine-tuning, an importance criteria is used to search for redundant filters that don’t significantly contribute to the network’s output and zero them out. After fine-tuning, the zeroed-out filters are removed from the network. For more information, see the :doc:`Filter Pruning <compressing-models-during-training/filter-pruning>` page.+During fine-tuning, the importance criterion is used to search for redundant convolutional layer+filters that don't significantly contribute to the model's output. After fine-tuning, these+filters are removed from the model.-Experimental methods---------------------+For more information, see:-NNCF also provides state-of-the-art compression techniques that are still in the experimental stages of development and are only recommended for expert developers. These include:+* How to use :doc:`Filter Pruning <../model-optimization-guide/compressing-models-during-training/filter-pruning>`.+* Technical details of `Filter Pruning <https://github.com/openvinotoolkit/nncf/blob/develop/docs/usage/training_time_compression/other_algorithms/Pruning.md>`__.-- Mixed-precision quantization-- Sparsity-- Binarization-To learn more about these methods, visit the `NNCF repository on GitHub <https://github.com/openvinotoolkit/nncf>`__.+Experimental methods++++++++++++++++++++++++++-Recommended Workflow-+++++++++++++++++++++NNCF provides some state-of-the-art compression methods that are still in the experimental+stages of development and are only recommended for expert developers. These include:-Using compression-aware training requires a training pipeline, an annotated dataset, and compute resources (such as CPUs or GPUs). If you don't already have these set up and available, it can be easier to start post-training quantization to quickly see quantized results. Then you can use compression-aware training if the model isn't accurate enough. We recommend the following workflow for compressing models with NNCF:+* Mixed-precision quantization.+* Sparsity (check out the `Sparsity-Aware Training notebook <https://docs.openvino.ai/2024/notebooks/pytorch-quantization-sparsity-aware-training-with-output.html>`__).+* Movement Pruning (Movement Sparsity).++To learn `more about these methods <https://github.com/openvinotoolkit/nncf?tab=readme-ov-file#training-time-compression-algorithms>`__,+see developer documentation of the NNCF repository.-1. :doc:`Perform post-training quantization <quantizing-models-post-training>` on your model and then compare performance to the original model.-2. If the accuracy is too degraded, use :doc:`Quantization-aware Training <compressing-models-during-training/quantization-aware-training>` to increase accuracy while still achieving faster inference time.-3. If the quantized model is still too slow, use :doc:`Filter Pruning <compressing-models-during-training/filter-pruning>` to further improve the model’s inference speed.Additional Resources####################-- :doc:`Quantizing Models Post-training <quantizing-models-post-training>`+- :doc:`Post-training quantization <quantizing-models-post-training>`- :doc:`Model Optimization - NNCF <../model-optimization>`- `NNCF GitHub repository <https://github.com/openvinotoolkit/nncf>`__-- `NNCF FAQ <https://github.com/openvinotoolkit/nncf/blob/develop/docs/FAQ.md>`__-- `Quantization Aware Training with NNCF and PyTorch <https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/pytorch-quantization-aware-training>`__.-- `Quantization Aware Training with NNCF and TensorFlow <https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/tensorflow-quantization-aware-training>`__.-diff --git a/docs/articles_en/openvino-workflow/model-optimization-guide/quantizing-models-post-training.rst b/docs/articles_en/openvino-workflow/model-optimization-guide/quantizing-models-post-training.rstindex 599c23f90c9..aec99cc6f29 100644--- a/docs/articles_en/openvino-workflow/model-optimization-guide/quantizing-models-post-training.rst+++ b/docs/articles_en/openvino-workflow/model-optimization-guide/quantizing-models-post-training.rst@@ -1,4 +1,4 @@-Quantizing Models Post-training+Post-training Quantization===============================.. toctree::@@ -9,40 +9,45 @@ Quantizing Models Post-trainingquantizing-models-post-training/quantizing-with-accuracy-control-Post-training model optimization is the process of applying special methods that transform a-model into a more hardware-friendly representation, without retraining or fine-tuning it. The-most widely-adopted method is **8-bit post-training quantization** because it is:+Post-training quantization is a method of reducing the size of a model, to make it lighter,+faster, and less resource hungry. Importantly, this process does not require retraining,+fine-tuning, or using training datasets and pipelines in the source framework. With NNCF, you+can perform `8-bit quantization <#why-8-bit-post-training-quantization>`__, using mainly the two+flows:-* easy-to-use-* does not impact accuracy much-* provides significant performance improvement-* fits most hardware, since 8-bit computation is widely supported+| :doc:`Basic quantization (simple) <quantizing-models-post-training/basic-quantization-flow>`:+| Requires only a representative calibration dataset.-8-bit integer quantization lowers the precision of weights and activations to 8 bits. This-leads to almost 4x reduction in the model footprint and significant improvements in inference-speed, mostly due to reduced throughput. The reduction is performed before the actual inference,-when the model gets transformed into the quantized representation. The process does not require-any training datasets or pipelines in the source DL framework.+| :doc:`Accuracy-aware Quantization (advanced) <quantizing-models-post-training/quantizing-with-accuracy-control>`:+| Ensures the accuracy of the resulting model does not drop below a certain value.+ To do so, it requires both a calibration and a validation datasets, as well as a+ validation function to calculate the accuracy metric.-.. image:: ../../assets/images/quantization_picture.svg+.. note++ NNCF offers a Python API, for compressing PyTorch, TensorFlow 2.x, ONNX, and OpenVINO IR+ model formats. OpenVINO IR offers the most comprehensive support.+++Why 8-bit post-training quantization+####################################++The 8-bit quantization is just one of the available compression methods but one often+selected for:-:doc:`Neural Network Compression Framework (NNCF) <../model-optimization>`-provides a post-training quantization API, available in Python, that aims at reusing the code for-model training or validation that is usually available with the model in the source framework,-such as PyTorch or TensroFlow. The NNCF API is cross-framework and currently supports:-OpenVINO, PyTorch, TensorFlow 2.x, and ONNX. Post-training quantization for models in the-:doc:`OpenVINO IR format <../../documentation/openvino-ir-format>` is the most mature in terms-of supported methods and model coverage.+* significant performance results,+* little impact on accuracy,+* ease of use,+* wide hardware compatibility.++It lowers model weight and activation precisions to 8 bits (INT8), which for an FP64 model+is just a quarter of the original footprint, leading to a significant improvement in inference+speed.+++.. image:: ../../assets/images/quantization_picture.svg-The NNCF API offers two main options to apply 8-bit post-training quantization:-* :doc:`Basic quantization <quantizing-models-post-training/basic-quantization-flow>` -- the simplest quantization flow that allows applying 8-bit integer quantization to the model. A- representative calibration dataset is only needed in this case.-* :doc:`Quantization with accuracy control <quantizing-models-post-training/quantizing-with-accuracy-control>` -- the most advanced quantization flow that allows applying 8-bit quantization to the model with- accuracy control. Calibration and validation datasets, and a validation function to calculate- the accuracy metric are needed in this case.Additional Resources####################@@ -50,4 +55,3 @@ Additional Resources* :doc:`Optimizing Models at Training Time <compressing-models-during-training>`* :doc:`Model Optimization - NNCF <../model-optimization>`* `NNCF GitHub <https://github.com/openvinotoolkit/nncf>`__-diff --git a/docs/articles_en/openvino-workflow/model-optimization.rst b/docs/articles_en/openvino-workflow/model-optimization.rstindex 076a0ef8aad..b4b6cc64acb 100644--- a/docs/articles_en/openvino-workflow/model-optimization.rst+++ b/docs/articles_en/openvino-workflow/model-optimization.rst@@ -1,6 +1,9 @@Model Optimization - NNCF===============================================================================================+.. meta::+ :description: Learn about the optimization methods offered by OpenVINO's NNCF+.. toctree:::maxdepth: 1:hidden:@@ -39,6 +42,10 @@ the following optimizations:as Quantization-aware Training. This kind of optimization requires the use of the model'soriginal framework, for NNCF, it is either PyTorch or TensorFlow.+A common approach is to perform post-training quantization first, as it is the easiest option.+If the result proves unsatisfactory, quantization-aware training will give you higher accuracy+with the same level of performance boost. For the most performant product, adding filter pruning+will further streamline the model.To learn about the full scope of the framework, its installation, and technical details, visitboth `the NNCF repository <https://github.com/openvinotoolkit/nncf?tab=readme-ov-file>`__ and