You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/usage/training_time_compression/quantization_aware_training/Usage.md
+93-13
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
-
# Use NNCF for Quantization Aware Training in PyTorch
1
+
# Use NNCF for Quantization Aware Training
2
2
3
-
This is a step-by-step tutorial on how to integrate the NNCF package into the existing PyTorch project (please see the [TensorFlow quantization documentation](../other_algorithms/LegacyQuantization.md) for integration tutorial for the existing TensorFlow project).
4
-
The use case implies that the user already has a training pipeline that reproduces training of the model in the floating point precision and pretrained model.
3
+
This is a step-by-step tutorial on how to integrate the NNCF package into the existing PyTorch or TensorFlow projects.
4
+
The use case implies that the user already has a training pipeline that reproduces training of the model in the floating point precision and pretrained model.
5
5
The task is to prepare this model for accelerated inference by simulating the compression at train time.
6
6
Please refer to this [document](/docs/usage/training_time_compression/other_algorithms/LegacyQuantization.md) for details of the implementation.
7
7
@@ -11,11 +11,24 @@ Please refer to this [document](/docs/usage/training_time_compression/other_algo
11
11
12
12
Quantize the model using the [Post Training Quantization](../../post_training_compression/post_training_quantization/Usage.md) method.
13
13
14
+
<detailsopen><summary><b>PyTorch</b></summary>
15
+
14
16
```python
15
17
model = TorchModel() # instance of torch.nn.Module
16
18
quantized_model = nncf.quantize(model, ...)
17
19
```
18
20
21
+
</details>
22
+
23
+
<details><summary><b>TensorFlow</b></summary>
24
+
25
+
```python
26
+
model = TensorFlowModel() # instance of tf.keras.Model
27
+
quantized_model = nncf.quantize(model, ...)
28
+
```
29
+
30
+
</details>
31
+
19
32
### Step 2: Run the training pipeline
20
33
21
34
At this point, the NNCF is fully integrated into your training pipeline.
@@ -27,27 +40,46 @@ Important points you should consider when training your networks with compressio
27
40
28
41
### Step 3: Export the compressed model
29
42
30
-
After the compressed model has been fine-tuned to acceptable accuracy and compression stages, you can export it. There are two ways to export a model:
43
+
After the compressed model has been fine-tuned to acceptable accuracy and compression stages, you can export it.
44
+
45
+
<detailsopen><summary><b>PyTorch</b></summary>
46
+
47
+
Trace the model via inference in framework operations.
31
48
32
-
1. Trace the model via inference in framework operations.
With no target model code modifications, NNCF only supports native PyTorch modules with respect to trainable parameter (weight) compressed, such as `torch.nn.Conv2d`.
78
153
If your model contains a custom, non-PyTorch standard module with trainable weights that should be compressed, you can register it using the `@nncf.register_module` decorator:
79
154
@@ -91,4 +166,9 @@ If registered module should be ignored by specific algorithms use `ignored_algor
91
166
92
167
In the example above, the NNCF-compressed models that contain instances of `MyModule` will have the corresponding modules extended with functionality that will allow NNCF to quantize the `weight` parameter of `MyModule` before it takes part in `MyModule`'s `forward` calculation.
93
168
94
-
See a PyTorch [example](/examples/quantization_aware_training/torch/resnet18/README.md) for**Quantization** Compression scenario on Tiny ImageNet-200 dataset.
169
+
</details>
170
+
171
+
## Examples
172
+
173
+
- See a PyTorch [example](/examples/quantization_aware_training/torch/resnet18/README.md) for **Quantization** Compression scenario on Tiny ImageNet-200 dataset.
174
+
- See a TensorFlow [example](/examples/quantization_aware_training/tensorflow/mobilenet_v2/README.md) for **Quantization** Compression scenario on imagenette/320px-v2 dataset.
0 commit comments