# openvinotoolkit/nncf architecture

> Architecture diagram of the GitHub repository openvinotoolkit/nncf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openvinotoolkit/nncf
- Repository: https://github.com/openvinotoolkit/nncf

## Overview

NNCF is a neural-network compression framework for PyTorch, TorchFX, ONNX, and OpenVINO models. Its principal documented workflow accepts a model and calibration dataset through the quantization API, collects model statistics, applies a backend-aware compression pipeline, and returns a compressed model. Other major branches cover weight compression, training-time quantization and pruning, and experimental activation sparsity. The graph follows the README and supplied source excerpts; details of unsampled implementations and their wiring are represented only where documented.

Main entry points: [`src/nncf/quantization/algorithms/pipeline.py`](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/pipeline.py) (Pipeline executor), [`src/nncf`](https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf) (Compression API), [`src/nncf/common/graph/model_transformer.py`](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/graph/model_transformer.py) (Graph transformation), [`src/nncf/common/engine.py`](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/engine.py) (Inference engines)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["User API"]
  node_api_entry["Compression API"]
  node_dataset["Dataset wrapper<br/>[dataset.py]"]
end

subgraph group_shared["Shared compression core"]
  node_pipeline["PTQ pipeline<br/>[pipeline.py]"]
  node_executor["Pipeline executor<br/>[pipeline.py]"]
  node_graph["Model graph<br/>[graph.py]"]
  node_statistics["Statistics collection<br/>[aggregator.py]"]
  node_transform["Graph transformation"]
end

subgraph group_algorithms["Compression algorithms"]
  node_quantization["Min-max quantization<br/>[algorithm.py]"]
  node_smooth["SmoothQuant<br/>[algorithm.py]"]
  node_bias["Bias correction<br/>[algorithm.py]"]
  node_weights["Weight compression<br/>[algorithm.py]"]
  node_accuracy["Accuracy control<br/>[algorithm.py]"]
end

subgraph group_backends["Model backends"]
  node_torch["PyTorch support"]
  node_torchfx["TorchFX support"]
  node_onnx["ONNX support"]
  node_openvino["OpenVINO support"]
  node_engines["Inference engines<br/>[engine.py]"]
  node_export["Model export"]
end

subgraph group_training["Training and extras"]
  node_qat["Quantization-aware training<br/>[quantize_model.py]"]
  node_pruning["Pruning<br/>[prune_model.py]"]
  node_sparsity["Activation sparsity"]
end

node_user(("Model user"))
node_model["Input model"]
node_calibration["Calibration data"]
node_runtime["Backend runtimes"]
node_compressed["Compressed model"]

node_user -->|"configures"| node_api_entry
node_user -->|"provides"| node_model
node_user -->|"provides"| node_calibration
node_api_entry -->|"wraps data"| node_dataset
node_api_entry -->|"starts PTQ"| node_pipeline
node_pipeline -->|"creates steps"| node_executor
node_executor -->|"builds graph"| node_graph
node_executor -->|"collects stats"| node_statistics
node_dataset -->|"supplies samples"| node_statistics
node_executor -->|"runs step"| node_smooth
node_executor -->|"runs step"| node_quantization
node_executor -->|"runs step"| node_bias
node_executor -.->|"runs compression"| node_weights
node_executor -.->|"optional control"| node_accuracy
node_quantization -->|"transforms model"| node_transform
node_smooth -->|"transforms model"| node_transform
node_bias -->|"corrects model"| node_transform
node_api_entry -->|"dispatches backend"| node_torch
node_api_entry -.->|"dispatches backend"| node_torchfx
node_api_entry -->|"dispatches backend"| node_onnx
node_api_entry -->|"dispatches backend"| node_openvino
node_torch -->|"provides inference"| node_engines
node_onnx -->|"provides inference"| node_engines
node_openvino -->|"provides inference"| node_engines
node_engines -->|"runs inference"| node_runtime
node_transform -->|"returns model"| node_compressed
node_user -->|"fine-tunes"| node_qat
node_user -->|"configures"| node_pruning
node_user -.->|"opts into"| node_sparsity
node_torch -->|"exports model"| node_export
node_export -->|"exports to"| node_onnx

click node_api_entry "https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf"
click node_dataset "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/data/dataset.py"
click node_pipeline "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/post_training/pipeline.py"
click node_executor "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/pipeline.py"
click node_graph "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/graph/graph.py"
click node_statistics "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/tensor_statistics/aggregator.py"
click node_quantization "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/min_max/algorithm.py"
click node_smooth "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/smooth_quant/algorithm.py"
click node_bias "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/fast_bias_correction/algorithm.py"
click node_weights "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/weight_compression/algorithm.py"
click node_accuracy "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/accuracy_control/algorithm.py"
click node_transform "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/graph/model_transformer.py"
click node_torch "https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/torch"
click node_torchfx "https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/experimental/torch/fx"
click node_onnx "https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/onnx"
click node_openvino "https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/openvino"
click node_engines "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/engine.py"
click node_qat "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/torch/function_hook/quantization/quantize_model.py"
click node_pruning "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/torch/function_hook/pruning/prune_model.py"
click node_sparsity "https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/experimental/torch/sparsify_activations/sparsify_activations_impl.py"
click node_export "https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/torch"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_entry,node_dataset,node_user toneBlue
class node_pipeline,node_executor,node_graph,node_statistics,node_transform toneAmber
class node_quantization,node_smooth,node_bias,node_weights,node_accuracy toneMint
class node_torch,node_torchfx,node_onnx,node_openvino,node_engines,node_export toneRose
class node_qat,node_pruning,node_sparsity,node_model,node_calibration,node_runtime,node_compressed toneIndigo
```

## Components

### User API

- [Compression API](https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf): `src/nncf`
- [Dataset wrapper](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/data/dataset.py): `src/nncf/data/dataset.py`

### Shared compression core

- [PTQ pipeline](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/post_training/pipeline.py): `src/nncf/quantization/algorithms/post_training/pipeline.py`
- [Pipeline executor](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/pipeline.py): `src/nncf/quantization/algorithms/pipeline.py`
- [Model graph](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/graph/graph.py): `src/nncf/common/graph/graph.py`
- [Statistics collection](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/tensor_statistics/aggregator.py): `src/nncf/common/tensor_statistics/aggregator.py`
- [Graph transformation](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/graph/model_transformer.py): `src/nncf/common/graph/model_transformer.py`

### Compression algorithms

- [Min-max quantization](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/min_max/algorithm.py): `src/nncf/quantization/algorithms/min_max/algorithm.py`
- [SmoothQuant](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/smooth_quant/algorithm.py): `src/nncf/quantization/algorithms/smooth_quant/algorithm.py`
- [Bias correction](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/fast_bias_correction/algorithm.py): `src/nncf/quantization/algorithms/fast_bias_correction/algorithm.py`
- [Weight compression](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/weight_compression/algorithm.py): `src/nncf/quantization/algorithms/weight_compression/algorithm.py`
- [Accuracy control](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/quantization/algorithms/accuracy_control/algorithm.py): `src/nncf/quantization/algorithms/accuracy_control/algorithm.py`

### Model backends

- [PyTorch support](https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/torch): `src/nncf/torch`
- [TorchFX support](https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/experimental/torch/fx): `src/nncf/experimental/torch/fx`
- [ONNX support](https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/onnx): `src/nncf/onnx`
- [OpenVINO support](https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/openvino): `src/nncf/openvino`
- [Inference engines](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/common/engine.py): `src/nncf/common/engine.py`
- [Model export](https://github.com/openvinotoolkit/nncf/tree/develop/src/nncf/torch): `src/nncf/torch`

### Training and extras

- [Quantization-aware training](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/torch/function_hook/quantization/quantize_model.py): `src/nncf/torch/function_hook/quantization/quantize_model.py`
- [Pruning](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/torch/function_hook/pruning/prune_model.py): `src/nncf/torch/function_hook/pruning/prune_model.py`
- [Activation sparsity](https://github.com/openvinotoolkit/nncf/blob/develop/src/nncf/experimental/torch/sparsify_activations/sparsify_activations_impl.py): `src/nncf/experimental/torch/sparsify_activations/sparsify_activations_impl.py`

### Other components

- **Model user**
- **Input model**
- **Calibration data**
- **Backend runtimes**
- **Compressed model**

## Connections

- Model user → Compression API: configures
- Model user → Input model: provides
- Model user → Calibration data: provides
- Compression API → Dataset wrapper: wraps data
- Compression API → PTQ pipeline: starts PTQ
- PTQ pipeline → Pipeline executor: creates steps
- Pipeline executor → Model graph: builds graph
- Pipeline executor → Statistics collection: collects stats
- Dataset wrapper → Statistics collection: supplies samples
- Pipeline executor → SmoothQuant: runs step
- Pipeline executor → Min-max quantization: runs step
- Pipeline executor → Bias correction: runs step
- Pipeline executor → Weight compression: runs compression
- Pipeline executor → Accuracy control: optional control
- Min-max quantization → Graph transformation: transforms model
- SmoothQuant → Graph transformation: transforms model
- Bias correction → Graph transformation: corrects model
- Compression API → PyTorch support: dispatches backend
- Compression API → TorchFX support: dispatches backend
- Compression API → ONNX support: dispatches backend
- Compression API → OpenVINO support: dispatches backend
- PyTorch support → Inference engines: provides inference
- ONNX support → Inference engines: provides inference
- OpenVINO support → Inference engines: provides inference
- Inference engines → Backend runtimes: runs inference
- Graph transformation → Compressed model: returns model
- Model user → Quantization-aware training: fine-tunes
- Model user → Pruning: configures
- Model user → Activation sparsity: opts into
- PyTorch support → Model export: exports model
- Model export → ONNX support: exports to
