From 7959942f61d69e3ea1beccc2747af72e725eea0e Mon Sep 17 00:00:00 2001 From: sgolebiewski-intel Date: Tue, 29 Aug 2023 14:58:47 +0200 Subject: [PATCH 1/5] improve-snippets --- docs/optimization_guide/nncf/ptq/code/ptq_onnx.py | 3 ++- docs/optimization_guide/nncf/ptq/code/ptq_openvino.py | 3 ++- docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py | 3 ++- docs/optimization_guide/nncf/ptq/code/ptq_torch.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py b/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py index fa9d1e35734d14..c8743329dc7d7c 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py @@ -16,7 +16,8 @@ def transform_fn(data_item): #! [dataset] #! [quantization] -model = ... # onnx.ModelProto object +import onnx +model = onnx.ModelProto() # onnx.ModelProto object quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py b/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py index eb2f89edf36098..952c683a507d4b 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py @@ -15,7 +15,8 @@ def transform_fn(data_item): #! [dataset] #! [quantization] -model = ... # openvino.runtime.Model object +import openvino as ov +model = ov.Model() # openvino.runtime.Model object quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py b/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py index fcb29c8741e5da..324a0fd59aad77 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py @@ -15,7 +15,8 @@ def transform_fn(data_item): #! [dataset] #! [quantization] -model = ... # tensorflow.Module object +import tensorflow as tf +model = tf.Module() # tensorflow.Module object quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_torch.py b/docs/optimization_guide/nncf/ptq/code/ptq_torch.py index a65f0998622042..e7acc3db378e55 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_torch.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_torch.py @@ -15,7 +15,8 @@ def transform_fn(data_item): #! [dataset] #! [quantization] -model = ... # torch.nn.Module object +import torch.nn as nn +model = nn.Module() # torch.nn.Module object quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] From 23af8d002b3b972d065f63614be31b2ff8809efd Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Wed, 30 Aug 2023 06:59:42 +0200 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Alexander Suslov --- docs/optimization_guide/nncf/ptq/code/ptq_onnx.py | 2 +- docs/optimization_guide/nncf/ptq/code/ptq_openvino.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py b/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py index c8743329dc7d7c..8b62c2b268b347 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py @@ -17,7 +17,7 @@ def transform_fn(data_item): #! [quantization] import onnx -model = onnx.ModelProto() # onnx.ModelProto object +model = onnx.load("model path") quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py b/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py index 952c683a507d4b..84a26277ac1e4e 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py @@ -15,8 +15,8 @@ def transform_fn(data_item): #! [dataset] #! [quantization] -import openvino as ov -model = ov.Model() # openvino.runtime.Model object +import openvino.runtime as ov +model = ov.Core().read_model("model path") quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] From 4663422004db4272219bc3382ccd1af5fcbf57e5 Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Wed, 30 Aug 2023 07:00:01 +0200 Subject: [PATCH 3/5] Update docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py Co-authored-by: Alexander Suslov --- docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py b/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py index 324a0fd59aad77..e4fc817ddb31d8 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_tensorflow.py @@ -16,7 +16,7 @@ def transform_fn(data_item): #! [quantization] import tensorflow as tf -model = tf.Module() # tensorflow.Module object +model = tf.saved_model.load("model_path") quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] From 3a02e9a69d148f79b5b57b61b1373e3ff5ec87e2 Mon Sep 17 00:00:00 2001 From: sgolebiewski-intel Date: Wed, 30 Aug 2023 07:19:08 +0200 Subject: [PATCH 4/5] update-path --- docs/optimization_guide/nncf/ptq/code/ptq_onnx.py | 2 +- docs/optimization_guide/nncf/ptq/code/ptq_openvino.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py b/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py index 8b62c2b268b347..b8104d449c566f 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_onnx.py @@ -17,7 +17,7 @@ def transform_fn(data_item): #! [quantization] import onnx -model = onnx.load("model path") +model = onnx.load("model_path") quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py b/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py index 84a26277ac1e4e..81e19fd99f5c8b 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_openvino.py @@ -16,14 +16,12 @@ def transform_fn(data_item): #! [quantization] import openvino.runtime as ov -model = ov.Core().read_model("model path") +model = ov.Core().read_model("model_path") quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization] #! [inference] -import openvino.runtime as ov - # compile the model to transform quantized operations to int8 model_int8 = ov.compile_model(quantized_model) From 31265c0db670a7dadfc1ad7b3ed3a9e6c7a02903 Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Wed, 30 Aug 2023 09:12:20 +0200 Subject: [PATCH 5/5] Update docs/optimization_guide/nncf/ptq/code/ptq_torch.py --- docs/optimization_guide/nncf/ptq/code/ptq_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/optimization_guide/nncf/ptq/code/ptq_torch.py b/docs/optimization_guide/nncf/ptq/code/ptq_torch.py index e7acc3db378e55..fbdf103b4f2bf9 100644 --- a/docs/optimization_guide/nncf/ptq/code/ptq_torch.py +++ b/docs/optimization_guide/nncf/ptq/code/ptq_torch.py @@ -15,8 +15,8 @@ def transform_fn(data_item): #! [dataset] #! [quantization] -import torch.nn as nn -model = nn.Module() # torch.nn.Module object +import torchvision +model = torchvision.models.resnet50(pretrained=True) quantized_model = nncf.quantize(model, calibration_dataset) #! [quantization]