Skip to content

Commit 6579f58

Browse files
TPC Improvement (Additional of #1635) (#1650)
Remaining work on PR #1635 * TPC Improvement * Add TPC v5.0 for SDSP converter v3.18 (#1640) * Change get_target_platform_capabilities API in tutorials. (#1637, #1638) * Modify links in README for TPC (#1641) * Since there was a link to a previously unpublished page, we temporarily used a relative path in #1622. It has now been reverted to the official link. * Fix for missing parameter specifications in MCTWrapper. (#1642) * Change implementation of wrapper for TPC Improvement. * Maintenance Tutorials of MCTWrapper (#1639) * Update and Maintenance API Documents of MCTWrapper (#1644)
1 parent eacba53 commit 6579f58

36 files changed

Lines changed: 782 additions & 821 deletions

File tree

docs/api/api_docs/classes/Wrapper.html

Lines changed: 188 additions & 134 deletions
Large diffs are not rendered by default.

docs/api/api_docs/methods/get_keras_gptq_config.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ <h3>Navigation</h3>
5151
<dt class="field-even">Parameters<span class="colon">:</span></dt>
5252
<dd class="field-even"><ul class="simple">
5353
<li><p><strong>n_epochs</strong> (<em>int</em>) – Number of epochs for running the representative dataset for fine-tuning.</p></li>
54-
<li><p><strong>optimizer</strong> (<em>OptimizerV2</em>) – Keras optimizer to use for fine-tuning for auxiliry variable with a default learning rate set to 0.2.</p></li>
55-
<li><p><strong>optimizer_rest</strong> (<em>OptimizerV2</em>) – Keras optimizer to use for fine-tuning of the bias variable.</p></li>
54+
<li><p><strong>optimizer</strong> (<em>OptimizerV2</em>) – Keras optimizer to use for fine-tuning for auxiliary variable. Default: Adam(learning rate set to 3e-2).</p></li>
55+
<li><p><strong>optimizer_rest</strong> (<em>OptimizerV2</em>) – Keras optimizer to use for fine-tuning of the bias variable. Default: Adam(learning rate set to 1e-4).</p></li>
5656
<li><p><strong>loss</strong> (<em>Callable</em>) – loss to use during fine-tuning. should accept 4 lists of tensors. 1st list of quantized tensors, the 2nd list is the float tensors, the 3rd is a list of quantized weights and the 4th is a list of float weights.</p></li>
5757
<li><p><strong>log_function</strong> (<em>Callable</em>) – Function to log information about the gptq process.</p></li>
5858
<li><p><strong>use_hessian_based_weights</strong> (<em>bool</em>) – Whether to use Hessian-based weights for weighted average loss.</p></li>

docs/api/api_docs/methods/get_pytroch_gptq_config.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ <h3>Navigation</h3>
5151
<dt class="field-even">Parameters<span class="colon">:</span></dt>
5252
<dd class="field-even"><ul class="simple">
5353
<li><p><strong>n_epochs</strong> (<em>int</em>) – Number of epochs for running the representative dataset for fine-tuning.</p></li>
54-
<li><p><strong>optimizer</strong> (<em>Optimizer</em>) – Pytorch optimizer to use for fine-tuning for auxiliry variable.</p></li>
55-
<li><p><strong>optimizer_rest</strong> (<em>Optimizer</em>) – Pytorch optimizer to use for fine-tuning of the bias variable.</p></li>
54+
<li><p><strong>optimizer</strong> (<em>Optimizer</em>) – Pytorch optimizer to use for fine-tuning for auxiliary variable. Default: Adam(learning rate set to 3e-2).</p></li>
55+
<li><p><strong>optimizer_rest</strong> (<em>Optimizer</em>) – Pytorch optimizer to use for fine-tuning of the bias variable. Default: Adam(learning rate set to 1e-4).</p></li>
5656
<li><p><strong>loss</strong> (<em>Callable</em>) – loss to use during fine-tuning. See the default loss function for the exact interface.</p></li>
5757
<li><p><strong>log_function</strong> (<em>Callable</em>) – Function to log information about the gptq process.</p></li>
5858
<li><p><strong>use_hessian_based_weights</strong> (<em>bool</em>) – Whether to use Hessian-based weights for weighted average loss.</p></li>

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model_compression_toolkit/gptq/keras/quantization_facade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def get_keras_gptq_config(n_epochs: int,
7575
7676
args:
7777
n_epochs (int): Number of epochs for running the representative dataset for fine-tuning.
78-
optimizer (OptimizerV2): Keras optimizer to use for fine-tuning for auxiliry variable with a default learning rate set to 0.2.
79-
optimizer_rest (OptimizerV2): Keras optimizer to use for fine-tuning of the bias variable.
78+
optimizer (OptimizerV2): Keras optimizer to use for fine-tuning for auxiliary variable. Default: Adam(learning rate set to 3e-2).
79+
optimizer_rest (OptimizerV2): Keras optimizer to use for fine-tuning of the bias variable. Default: Adam(learning rate set to 1e-4).
8080
loss (Callable): loss to use during fine-tuning. should accept 4 lists of tensors. 1st list of quantized tensors, the 2nd list is the float tensors, the 3rd is a list of quantized weights and the 4th is a list of float weights.
8181
log_function (Callable): Function to log information about the gptq process.
8282
use_hessian_based_weights (bool): Whether to use Hessian-based weights for weighted average loss.

model_compression_toolkit/gptq/pytorch/quantization_facade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def get_pytorch_gptq_config(n_epochs: int,
6969
7070
args:
7171
n_epochs (int): Number of epochs for running the representative dataset for fine-tuning.
72-
optimizer (Optimizer): Pytorch optimizer to use for fine-tuning for auxiliry variable.
73-
optimizer_rest (Optimizer): Pytorch optimizer to use for fine-tuning of the bias variable.
72+
optimizer (Optimizer): Pytorch optimizer to use for fine-tuning for auxiliary variable. Default: Adam(learning rate set to 3e-2).
73+
optimizer_rest (Optimizer): Pytorch optimizer to use for fine-tuning of the bias variable. Default: Adam(learning rate set to 1e-4).
7474
loss (Callable): loss to use during fine-tuning. See the default loss function for the exact interface.
7575
log_function (Callable): Function to log information about the gptq process.
7676
use_hessian_based_weights (bool): Whether to use Hessian-based weights for weighted average loss.

model_compression_toolkit/target_platform_capabilities/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ in some operator for its weights/activations, fusing patterns, etc.)
1313
## Supported Target Platform Models
1414

1515
Currently, MCT contains three target-platform models
16-
(new models can be created and used by users as demonstrated [here](./tpc_models/imx500_tpc/v1_0/tpc.py)):
16+
(new models can be created and used by users as demonstrated [here](https://github.com/SonySemiconductorSolutions/mct-model-optimization/blob/main/model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_0/tpc.py)):
1717
- [IMX500](https://developer.sony.com/develop/imx500/)
1818
- [TFLite](https://www.tensorflow.org/lite/performance/quantization_spec)
1919
- [QNNPACK](https://github.com/pytorch/QNNPACK)
@@ -29,7 +29,7 @@ One may view the full default target-platform model and its parameters [here](./
2929

3030
The simplest way to initiate a TPC and use it in MCT is by using the function [get_target_platform_capabilities](https://sonysemiconductorsolutions.github.io/mct-model-optimization/api/api_docs/methods/get_target_platform_capabilities.html#ug-get-target-platform-capabilities).
3131

32-
This function gets a TPC object matching the tpc version and device type. Please check [here](../../README.md#supported-versions) for supported versions.
32+
This function gets a TPC object matching the tpc version and device type. Please check [here](https://github.com/SonySemiconductorSolutions/mct-model-optimization/blob/main/README.md#supported-versions) for supported versions.
3333

3434
For example:
3535

@@ -45,7 +45,7 @@ quantized_model, quantization_info = mct.ptq.keras_post_training_quantization(in
4545
target_platform_capabilities=tpc)
4646
```
4747

48-
You can also get a TPC for IMX500 using the function [get_target_platform_capabilities_sdsp](../../docs/api/api_docs/methods/get_target_platform_capabilities_sdsp.html#ug-get-target-platform-capabilities_sdsp) that specifies the sdsp converter version. Please check [here](../../README.md#supported-versions) for supported versions.
48+
You can also get a TPC for IMX500 using the function [get_target_platform_capabilities_sdsp](https://sonysemiconductorsolutions.github.io/mct-model-optimization/api/api_docs/methods/get_target_platform_capabilities_sdsp.html#ug-get-target-platform-capabilities_sdsp) that specifies the sdsp converter version. Please check [here](https://github.com/SonySemiconductorSolutions/mct-model-optimization/blob/main/README.md#supported-versions) for supported versions.
4949

5050
For example:
5151

model_compression_toolkit/target_platform_capabilities/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
SDSP_V3_14 = '3.14'
3232
SDSP_V3_16 = '3.16'
3333
SDSP_V3_17 = '3.17'
34+
SDSP_V3_18 = '3.18'
3435

3536
# TP Attributes
3637
KERNEL_ATTR = "kernel_attr"

model_compression_toolkit/target_platform_capabilities/tpc_models/get_target_platform_capabilities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515
from model_compression_toolkit.target_platform_capabilities.constants import IMX500_TP_MODEL, TPC_V1_0, TPC_V4_0, TPC_V5_0, \
16-
SDSP_V3_14, SDSP_V3_16, SDSP_V3_17
16+
SDSP_V3_14, SDSP_V3_16, SDSP_V3_17, SDSP_V3_18
1717
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformCapabilities
1818
from model_compression_toolkit.target_platform_capabilities.tpc_models import generate_tpc_func
1919

@@ -56,6 +56,7 @@ def get_target_platform_capabilities_sdsp(sdsp_version: str = SDSP_V3_14) -> Tar
5656
SDSP_V3_14: TPC_V1_0,
5757
SDSP_V3_16: TPC_V4_0,
5858
SDSP_V3_17: TPC_V5_0,
59+
SDSP_V3_18: TPC_V5_0,
5960
}
6061

6162
msg = (f"Error: The specified sdsp converter version '{sdsp_version}' is not valid. "

model_compression_toolkit/wrapper/constants.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@
1717
FW_NAME = 'fw_name'
1818
SDSP_VERSION = 'sdsp_version'
1919

20+
# QuantizationConfig parameters
21+
ACTIVATION_ERROR_METHOD = 'activation_error_method'
22+
WEIGHTS_BIAS_CORRECTION = 'weights_bias_correction'
23+
Z_THRESHOLD = 'z_threshold'
24+
LINEAR_COLLAPSING = 'linear_collapsing'
25+
RESIDUAL_COLLAPSING = 'residual_collapsing'
26+
2027
# MixedPrecisionQuantizationConfig parameters
28+
DISTANCE_WEIGHTING_METHOD = 'distance_weighting_method'
2129
NUM_OF_IMAGES = 'num_of_images'
2230
USE_HESSIAN_BASED_SCORES = 'use_hessian_based_scores'
31+
32+
# ResourceUtilization parameters
2333
WEIGHTS_COMPRESSION_RATIO = 'weights_compression_ratio'
2434

2535
# Resource utilization data parameters
@@ -32,14 +42,6 @@
3242
TARGET_RESOURCE_UTILIZATION = 'target_resource_utilization'
3343
IN_MODULE = 'in_module'
3444

35-
# QuantizationConfig parameters
36-
ACTIVATION_ERROR_METHOD = 'activation_error_method'
37-
WEIGHTS_ERROR_METHOD = 'weights_error_method'
38-
WEIGHTS_BIAS_CORRECTION = 'weights_bias_correction'
39-
Z_THRESHOLD = 'z_threshold'
40-
LINEAR_COLLAPSING = 'linear_collapsing'
41-
RESIDUAL_COLLAPSING = 'residual_collapsing'
42-
4345
# GPTQ specific parameters
4446
GPTQ_CONFIG = 'gptq_config'
4547
MODEL = 'model'
@@ -48,7 +50,12 @@
4850
N_EPOCHS = 'n_epochs'
4951
OPTIMIZER = 'optimizer'
5052

51-
# Export parameters
53+
# low_bit_quantizer_ptq
5254
CONVERTER_VER = 'converter_ver'
5355
LEARNING_RATE = 'learning_rate'
56+
57+
# Export parameters
5458
SAVE_MODEL_PATH = 'save_model_path'
59+
60+
# default compression ratio
61+
DEFAULT_COMPRESSION_RATIO = 0.75

0 commit comments

Comments
 (0)