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

WIP [TorchFX] Documetation update #2917

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ learning frameworks.

### Post-Training Compression Algorithms

| Compression algorithm | OpenVINO | PyTorch | TensorFlow | ONNX |
| :------------------------------------------------------------------------------------------------------- | :-------: | :-------: | :-----------: | :-----------: |
| [Post-Training Quantization](./docs/usage/post_training_compression/post_training_quantization/Usage.md) | Supported | Supported | Supported | Supported |
| [Weights Compression](./docs/usage/post_training_compression/weights_compression/Usage.md) | Supported | Supported | Not supported | Not supported |
| [Activation Sparsity](./nncf/experimental/torch/sparsify_activations/ActivationSparsity.md) | Not supported | Experimental |Not supported| Not supported |
| Compression algorithm | OpenVINO | PyTorch | TorchFX | TensorFlow | ONNX |
| :------------------------------------------------------------------------------------------------------- | :-------: | :-------: | :-----------: | :-----------: | :-----------: |
| [Post-Training Quantization](./docs/usage/post_training_compression/post_training_quantization/Usage.md) | Supported | Supported | Experimental | Supported | Supported |
| [Weights Compression](./docs/usage/post_training_compression/weights_compression/Usage.md) | Supported | Supported | Not supported | Not supported | Not supported |
| [Activation Sparsity](./nncf/experimental/torch/sparsify_activations/ActivationSparsity.md) | Not supported | Experimental | Not supported| Not supported| Not supported |

### Training-Time Compression Algorithms

Expand Down Expand Up @@ -138,6 +138,43 @@ quantized_model = nncf.quantize(model, calibration_dataset)

</details>

<details><summary><b>TorchFX</b></summary>

```python
import nncf
import torch.fx
from torchvision import datasets, models
from torch._export import capture_pre_autograd_graph
from nncf.torch.dynamic_graph.patch_pytorch import unpatch_torch_operators

# Unpatch torch operators first
unpatch_torch_operators()

# Instantiate your uncompressed model
model = models.mobilenet_v2()

# Provide validation part of the dataset to collect statistics needed for the compression algorithm
val_dataset = datasets.ImageFolder("/path", transform=transforms.Compose([transforms.ToTensor()]))
dataset_loader = torch.utils.data.DataLoader(val_dataset)

# Step 1: Initialize the transformation function
def transform_fn(data_item):
images, _ = data_item
return images

# Step 2: Initialize NNCF Dataset
calibration_dataset = nncf.Dataset(dataset_loader, transform_fn)

# Step 3: Export model to TorchFX
input_shape = (1, 3, 224, 224)
fx_model = capture_pre_autograd_graph(model.eval(), args=torch.ones(input_shape))

# Step 4: Run the quantization pipeline
quantized_fx_model = nncf.quantize(fx_model, calibration_dataset)

```

</details>
<details><summary><b>TensorFlow</b></summary>

```python
Expand Down
2 changes: 1 addition & 1 deletion docs/Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Post-training Compression

- [Post Training Quantization (PTQ)](./usage/post_training_compression/post_training_quantization/Usage.md) (OpenVINO, PyTorch, ONNX, TensorFlow)
- [Post Training Quantization (PTQ)](./usage/post_training_compression/post_training_quantization/Usage.md) (OpenVINO, PyTorch, TorchFX, ONNX, TensorFlow)
- Symmetric and asymmetric quantization modes
- Signed and unsigned
- Per tensor/per channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Every backend has its own return value format for the data transformation functi
backend inference framework.
Below are the formats of data transformation function for each supported backend.

<details><summary><b>PyTorch, TensorFlow, OpenVINO</b></summary>
<details><summary><b>PyTorch, TorchFX, TensorFlow, OpenVINO</b></summary>

The return format of the data transformation function is directly the input tensors consumed by the model. \
_If you are not sure that your implementation of data transformation function is correct you can validate it by using the
Expand Down
Loading