-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
057e643
commit ddc36e8
Showing
35 changed files
with
1,295 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
OnnxOperator | ||
############ | ||
|
||
.. autoclass:: netspresso.enums.__init__.OnnxOperator | ||
:members: | ||
:undoc-members: | ||
:member-order: bysource | ||
:exclude-members: create_literal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
QuantizationMode | ||
################ | ||
|
||
.. autoclass:: netspresso.enums.__init__.QuantizationMode | ||
:members: | ||
:undoc-members: | ||
:member-order: bysource | ||
:exclude-members: create_literal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
QuantizationPrecision | ||
##################### | ||
|
||
.. autoclass:: netspresso.enums.__init__.QuantizationPrecision | ||
:members: | ||
:undoc-members: | ||
:member-order: bysource | ||
:exclude-members: create_literal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SimilarityMetric | ||
################ | ||
|
||
.. autoclass:: netspresso.enums.__init__.SimilarityMetric | ||
:members: | ||
:undoc-members: | ||
:member-order: bysource | ||
:exclude-members: create_literal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
docs/description/api/quantizer/quantize/automatic_quantization.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Automatic Quantization | ||
====================== | ||
|
||
.. autofunction:: netspresso.quantizer.__init__.Quantizer.automatic_quantization | ||
|
||
|
||
Example | ||
------- | ||
|
||
.. code-block:: python | ||
from netspresso import NetsPresso | ||
from netspresso.enums import QuantizationPrecision | ||
netspresso = NetsPresso(email="YOUR_EMAIL", password="YOUR_PASSWORD") | ||
quantizer = netspresso.quantizer() | ||
quantization_result = quantizer.automatic_quantization( | ||
input_model_path="./examples/sample_models/test.onnx", | ||
output_dir="./outputs/quantized/automatic_quantization", | ||
dataset_path="./examples/sample_datasets/pickle_calibration_dataset_128x128.npy", | ||
weight_precision=QuantizationPrecision.INT8, | ||
activation_precision=QuantizationPrecision.INT8, | ||
threshold=0, | ||
) |
35 changes: 35 additions & 0 deletions
35
...cription/api/quantizer/quantize/custom_precision_quantization_by_layer_name.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Custom Precision Quantization by Layer Name | ||
=========================================== | ||
|
||
.. autofunction:: netspresso.quantizer.__init__.Quantizer.custom_precision_quantization_by_layer_name | ||
|
||
|
||
Example | ||
------- | ||
|
||
.. code-block:: python | ||
from netspresso import NetsPresso | ||
from netspresso.enums import QuantizationPrecision | ||
netspresso = NetsPresso(email="YOUR_EMAIL", password="YOUR_PASSWORD") | ||
quantizer = netspresso.quantizer() | ||
recommendation_metadata = quantizer.get_recommendation_precision( | ||
input_model_path="./examples/sample_models/test.onnx", | ||
output_dir="./outputs/quantized/automatic_quantization", | ||
dataset_path="./examples/sample_datasets/pickle_calibration_dataset_128x128.npy", | ||
weight_precision=QuantizationPrecision.INT8, | ||
activation_precision=QuantizationPrecision.INT8, | ||
threshold=0, | ||
) | ||
recommendation_precisions = quantizer.load_recommendation_precision_result(recommendation_metadata.recommendation_result_path) | ||
quantization_result = quantizer.custom_precision_quantization_by_layer_name( | ||
input_model_path="./examples/sample_models/test.onnx", | ||
output_dir="./outputs/quantized/custom_precision_quantization_by_layer_name", | ||
dataset_path="./examples/sample_datasets/pickle_calibration_dataset_128x128.npy", | ||
precision_by_layer_name=recommendation_precisions.layers, | ||
) |
35 changes: 35 additions & 0 deletions
35
...ption/api/quantizer/quantize/custom_precision_quantization_by_operator_type.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Custom Precision Quantization by Operator Type | ||
============================================== | ||
|
||
.. autofunction:: netspresso.quantizer.__init__.Quantizer.custom_precision_quantization_by_operator_type | ||
|
||
|
||
Example | ||
------- | ||
|
||
.. code-block:: python | ||
from netspresso import NetsPresso | ||
from netspresso.enums import QuantizationPrecision | ||
netspresso = NetsPresso(email="YOUR_EMAIL", password="YOUR_PASSWORD") | ||
quantizer = netspresso.quantizer() | ||
recommendation_metadata = quantizer.get_recommendation_precision( | ||
input_model_path="./examples/sample_models/test.onnx", | ||
output_dir="./outputs/quantized/automatic_quantization", | ||
dataset_path="./examples/sample_datasets/pickle_calibration_dataset_128x128.npy", | ||
weight_precision=QuantizationPrecision.INT8, | ||
activation_precision=QuantizationPrecision.INT8, | ||
threshold=0, | ||
) | ||
recommendation_precisions = quantizer.load_recommendation_precision_result(recommendation_metadata.recommendation_result_path) | ||
quantization_result = quantizer.custom_precision_quantization_by_operator_type( | ||
input_model_path="./examples/sample_models/test.onnx", | ||
output_dir="./outputs/quantized/custom_precision_quantization_by_operator_type", | ||
dataset_path="./examples/sample_datasets/pickle_calibration_dataset_128x128.npy", | ||
precision_by_operator_type=recommendation_precisions.operators, | ||
) |
27 changes: 27 additions & 0 deletions
27
docs/description/api/quantizer/quantize/recommendation_precision.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Recommendation precision | ||
======================== | ||
|
||
.. autofunction:: netspresso.quantizer.__init__.Quantizer.get_recommendation_precision | ||
|
||
|
||
Example | ||
------- | ||
|
||
.. code-block:: python | ||
from netspresso import NetsPresso | ||
from netspresso.enums import QuantizationPrecision | ||
netspresso = NetsPresso(email="YOUR_EMAIL", password="YOUR_PASSWORD") | ||
quantizer = netspresso.quantizer() | ||
recommendation_metadata = quantizer.get_recommendation_precision( | ||
input_model_path="./examples/sample_models/test.onnx", | ||
output_dir="./outputs/quantized/automatic_quantization", | ||
dataset_path="./examples/sample_datasets/pickle_calibration_dataset_128x128.npy", | ||
weight_precision=QuantizationPrecision.INT8, | ||
activation_precision=QuantizationPrecision.INT8, | ||
threshold=0, | ||
) | ||
recommendation_precisions = quantizer.load_recommendation_precision_result(recommendation_metadata.recommendation_result_path) |
26 changes: 26 additions & 0 deletions
26
docs/description/api/quantizer/quantize/uniform_precision_quantization.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Plain Quantization | ||
====================== | ||
|
||
.. autofunction:: netspresso.quantizer.__init__.Quantizer.uniform_precision_quantization | ||
|
||
|
||
Example | ||
------- | ||
|
||
.. code-block:: python | ||
from netspresso import NetsPresso | ||
from netspresso.enums import QuantizationPrecision, SimilarityMetric | ||
netspresso = NetsPresso(email="YOUR_EMAIL", password="YOUR_PASSWORD") | ||
quantizer = netspresso.quantizer() | ||
quantization_result = quantizer.uniform_precision_quantization( | ||
input_model_path="./examples/sample_models/test.onnx", | ||
output_dir="./outputs/quantized/uniform_precision_quantization", | ||
dataset_path="./examples/sample_datasets/pickle_calibration_dataset_128x128.npy", | ||
metric=SimilarityMetric.SNR, | ||
weight_precision=QuantizationPrecision.INT8, | ||
activation_precision=QuantizationPrecision.INT8, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Quantizer | ||
========== | ||
|
||
|
||
Quantize | ||
-------- | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
quantize/uniform_precision_quantization | ||
quantize/automatic_quantization | ||
quantize/recommendation_precision | ||
quantize/custom_precision_quantization_by_layer_name | ||
quantize/custom_precision_quantization_by_operator_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pathlib import Path | ||
|
||
from netspresso import NetsPresso | ||
from netspresso.enums import QuantizationPrecision, SimilarityMetric | ||
|
||
|
||
EMAIL = "YOUR_EMAIL" | ||
PASSWORD = "YOUR_PASSWORD" | ||
|
||
netspresso = NetsPresso(email=EMAIL, password=PASSWORD) | ||
|
||
# 1. Declare quantizer | ||
quantizer = netspresso.quantizer() | ||
|
||
# 2. Set variables for quantize | ||
input_model = "./examples/sample_models/test.onnx" | ||
OUTPUT_DIR = "./outputs/quantized/automatic_quantization" | ||
CALIBRATION_DATASET_PATH = "./examples/sample_datasets/pickle_calibration_dataset_128x128.npy" | ||
|
||
# 3. Automatic Quantization | ||
quantization_result = quantizer.automatic_quantization( | ||
input_model_path=input_model, | ||
output_dir=f"{OUTPUT_DIR}/{Path(input_model).stem}", | ||
dataset_path=CALIBRATION_DATASET_PATH, | ||
weight_precision=QuantizationPrecision.INT8, | ||
activation_precision=QuantizationPrecision.INT8, | ||
metric=SimilarityMetric.SNR, | ||
threshold=0, | ||
) |
38 changes: 38 additions & 0 deletions
38
examples/quantizer/custom_precision_quantization_by_layer_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from pathlib import Path | ||
|
||
from netspresso import NetsPresso | ||
from netspresso.enums import QuantizationPrecision | ||
|
||
|
||
EMAIL = "YOUR_EMAIL" | ||
PASSWORD = "YOUR_PASSWORD" | ||
|
||
netspresso = NetsPresso(email=EMAIL, password=PASSWORD) | ||
|
||
|
||
# 1. Declare quantizer | ||
quantizer = netspresso.quantizer() | ||
|
||
# 2. Set variables for quantize | ||
input_model = "./examples/sample_models/test.onnx" | ||
OUTPUT_DIR = "./outputs/quantized/onnx2onnx_2" | ||
CALIBRATION_DATASET_PATH = "./examples/sample_datasets/pickle_calibration_dataset_128x128.npy" | ||
|
||
# 3-1. Recommendation precision | ||
recommendation_metadata = quantizer.get_recommendation_precision( | ||
input_model_path=input_model, | ||
output_dir=f"{OUTPUT_DIR}/{Path(input_model).stem}", | ||
dataset_path=CALIBRATION_DATASET_PATH, | ||
weight_precision=QuantizationPrecision.INT8, | ||
activation_precision=QuantizationPrecision.INT8, | ||
threshold=0, | ||
) | ||
recommendation_precisions = quantizer.load_recommendation_precision_result(recommendation_metadata.recommendation_result_path) | ||
|
||
# 3-2. Custom Quantization | ||
quantization_result = quantizer.custom_precision_quantization_by_layer_name( | ||
input_model_path=input_model, | ||
output_dir=f"{OUTPUT_DIR}/{Path(input_model).stem}", | ||
precision_by_layer_name=recommendation_precisions.layers, | ||
dataset_path=CALIBRATION_DATASET_PATH, | ||
) |
Oops, something went wrong.