1616from typing import Dict , Any , List , Optional , Tuple
1717import model_compression_toolkit as mct
1818from model_compression_toolkit .logger import Logger
19- from model_compression_toolkit .verify_packages import FOUND_TPC
2019from model_compression_toolkit .wrapper .constants import (
21- REPRESENTATIVE_DATA_GEN , CORE_CONFIG , FW_NAME , TARGET_PLATFORM_VERSION ,
22- TARGET_PLATFORM_NAME , TPC_VERSION , DEVICE_TYPE , EXTENDED_VERSION ,
20+ REPRESENTATIVE_DATA_GEN , CORE_CONFIG , FW_NAME , SDSP_VERSION ,
2321 NUM_OF_IMAGES , USE_HESSIAN_BASED_SCORES , IN_MODEL , IN_MODULE , MODEL ,
2422 TARGET_PLATFORM_CAPABILITIES , TARGET_RESOURCE_UTILIZATION ,
2523 ACTIVATION_ERROR_METHOD , WEIGHTS_ERROR_METHOD , WEIGHTS_BIAS_CORRECTION ,
@@ -56,8 +54,6 @@ def __init__(self):
5654 :header: "Parameter Key", "Default Value", "Description"
5755 :widths: 30, 30, 40
5856
59- "target_platform_version", "'v1'", "Target platform version (use_internal_tpc=True)"
60- "tpc_version", "'5.0'", "TPC version (use_internal_tpc=False)"
6157 "activation_error_method", "mct.core.QuantizationErrorMethod.MSE", "Activation quantization error method"
6258 "weights_bias_correction", "True", "Enable weights bias correction"
6359 "z_threshold", "float('inf')", "Z-threshold for quantization"
@@ -71,8 +67,6 @@ def __init__(self):
7167 :header: "Parameter Key", "Default Value", "Description"
7268 :widths: 30, 30, 40
7369
74- "target_platform_version", "'v1'", "Target platform version (use_internal_tpc=True)"
75- "tpc_version", "'5.0'", "TPC version (use_internal_tpc=False)"
7670 "num_of_images", "5", "Number of images for mixed precision"
7771 "use_hessian_based_scores", "False", "Use Hessian-based scores for mixed precision"
7872 "weights_compression_ratio", "None", "Weights compression ratio for resource util"
@@ -84,8 +78,6 @@ def __init__(self):
8478 :header: "Parameter Key", "Default Value", "Description"
8579 :widths: 30, 30, 40
8680
87- "target_platform_version", "'v1'", "Target platform version (use_internal_tpc=True)"
88- "tpc_version", "'5.0'", "TPC version (use_internal_tpc=False)"
8981 "n_epochs", "5", "Number of training epochs for GPTQ"
9082 "optimizer", "None", "Optimizer for GPTQ training"
9183 "save_model_path", "'./qmodel.keras' / './qmodel.onnx'", "Path to save quantized model (Keras/Pytorch)"
@@ -96,8 +88,6 @@ def __init__(self):
9688 :header: "Parameter Key", "Default Value", "Description"
9789 :widths: 30, 30, 40
9890
99- "target_platform_version", "'v1'", "Target platform version (use_internal_tpc=True)"
100- "tpc_version", "'5.0'", "TPC version (use_internal_tpc=False)"
10191 "n_epochs", "5", "Number of training epochs for GPTQ"
10292 "optimizer", "None", "Optimizer for GPTQ training"
10393 "num_of_images", "5", "Number of images for mixed precision"
@@ -109,8 +99,7 @@ def __init__(self):
10999 self .params : Dict [str , Any ] = {
110100 # TPC
111101 FW_NAME : 'pytorch' ,
112- TARGET_PLATFORM_VERSION : 'v1' ,
113- TPC_VERSION : '5.0' ,
102+ SDSP_VERSION : '3.14' ,
114103
115104 # QuantizationConfig
116105 ACTIVATION_ERROR_METHOD : mct .core .QuantizationErrorMethod .MSE ,
@@ -140,9 +129,8 @@ def __init__(self):
140129
141130 def _initialize_and_validate (self , float_model : Any ,
142131 representative_dataset : Optional [Any ],
143- method : str ,
144132 framework : str ,
145- use_internal_tpc : bool ,
133+ method : str ,
146134 use_mixed_precision : bool
147135 ) -> None :
148136 """
@@ -151,9 +139,8 @@ def _initialize_and_validate(self, float_model: Any,
151139 Args:
152140 float_model: The float model to be quantized.
153141 representative_dataset (Callable, np.array, tf.Tensor): Representative dataset for calibration.
154- method (str): Quantization method ('PTQ', 'GPTQ', 'LQPTQ').
155142 framework (str): Target framework ('tensorflow', 'pytorch').
156- use_internal_tpc (bool ): Whether to use MCT's built-in TPC .
143+ method (str ): Quantization method ('PTQ', 'GPTQ', 'LQPTQ') .
157144 use_mixed_precision (bool): Whether to use mixed-precision quantization.
158145
159146 Raises:
@@ -172,29 +159,25 @@ def _initialize_and_validate(self, float_model: Any,
172159 self .representative_dataset = representative_dataset
173160 self .method = method
174161 self .framework = framework
175- self .use_internal_tpc = use_internal_tpc
176162 self .use_mixed_precision = use_mixed_precision
177163
178164 # Keep only the parameters you need for the quantization mode
179165 if method == 'PTQ' :
180166 if not use_mixed_precision :
181- allowed_keys = [ FW_NAME , TARGET_PLATFORM_VERSION , TPC_VERSION ,
182- ACTIVATION_ERROR_METHOD , WEIGHTS_BIAS_CORRECTION ,
167+ allowed_keys = [ FW_NAME , SDSP_VERSION , ACTIVATION_ERROR_METHOD , WEIGHTS_BIAS_CORRECTION ,
183168 Z_THRESHOLD , LINEAR_COLLAPSING , RESIDUAL_COLLAPSING ,
184169 SAVE_MODEL_PATH ]
185170 else :
186- allowed_keys = [ FW_NAME , TARGET_PLATFORM_VERSION , TPC_VERSION ,
187- NUM_OF_IMAGES , USE_HESSIAN_BASED_SCORES ,
171+ allowed_keys = [ FW_NAME , SDSP_VERSION , NUM_OF_IMAGES , USE_HESSIAN_BASED_SCORES ,
188172 WEIGHTS_COMPRESSION_RATIO , SAVE_MODEL_PATH ]
189173 else :
190174 if not use_mixed_precision :
191- allowed_keys = [ FW_NAME , TARGET_PLATFORM_VERSION , TPC_VERSION ,
192- N_EPOCHS , OPTIMIZER , SAVE_MODEL_PATH ]
175+ allowed_keys = [FW_NAME , SDSP_VERSION , N_EPOCHS , OPTIMIZER ,
176+ SAVE_MODEL_PATH ]
193177 else :
194- allowed_keys = [ FW_NAME , TARGET_PLATFORM_VERSION , TPC_VERSION ,
195- N_EPOCHS , OPTIMIZER , NUM_OF_IMAGES ,
196- USE_HESSIAN_BASED_SCORES , WEIGHTS_COMPRESSION_RATIO ,
197- SAVE_MODEL_PATH ]
178+ allowed_keys = [FW_NAME , SDSP_VERSION , N_EPOCHS , OPTIMIZER ,
179+ NUM_OF_IMAGES , USE_HESSIAN_BASED_SCORES ,
180+ WEIGHTS_COMPRESSION_RATIO , SAVE_MODEL_PATH ]
198181
199182 self .params = { k : v for k , v in self .params .items () if k in allowed_keys }
200183
@@ -313,36 +296,18 @@ def _select_argname(self) -> None:
313296
314297 def _get_tpc (self ) -> None :
315298 """
316- Configure Target Platform Capabilities (TPC) based on selected option .
299+ Configure Target Platform Capabilities (TPC).
317300
318- Sets up either MCT's built-in TPC or external EdgeMDT TPC configuration
319- for the IMX500 target platform.
301+ Sets up TPC configuration for the target platform.
320302
321303 Note:
322304 This method sets self.tpc attribute with the configured TPC object.
323305 """
324- if self .use_internal_tpc :
325- # Use MCT's built-in TPC configuration
326- params_TPC = {
327- FW_NAME : self .params [FW_NAME ],
328- TARGET_PLATFORM_NAME : 'imx500' ,
329- TARGET_PLATFORM_VERSION : self .params [TARGET_PLATFORM_VERSION ],
330- }
331- # Get TPC from MCT framework
332- self .tpc = mct .get_target_platform_capabilities (** params_TPC )
333- else :
334- if FOUND_TPC :
335- import edgemdt_tpc
336- # Use external EdgeMDT TPC configuration
337- params_TPC = {
338- TPC_VERSION : self .params [TPC_VERSION ],
339- DEVICE_TYPE : 'imx500' ,
340- EXTENDED_VERSION : None
341- }
342- # Get TPC from EdgeMDT framework
343- self .tpc = edgemdt_tpc .get_target_platform_capabilities (** params_TPC )
344- else :
345- raise Exception ("EdgeMDT TPC module is not available." )
306+ # Get default TPC for the framework
307+ params_TPC = {
308+ SDSP_VERSION : self .params [SDSP_VERSION ]
309+ }
310+ self .tpc = mct .get_target_platform_capabilities_sdsp (** params_TPC )
346311
347312 def _setting_PTQ_mixed_precision (self ) -> Dict [str , Any ]:
348313 """
@@ -510,8 +475,6 @@ def _export_model(self, quantized_model: Any) -> None:
510475 params_export = {
511476 'model' : quantized_model ,
512477 'save_model_path' : self .params ['save_model_path' ],
513- 'serialization_format' : (mct .exporter .KerasExportSerializationFormat .KERAS ),
514- 'quantization_format' : (mct .exporter .QuantizationFormat .FAKELY_QUANT )
515478 }
516479 elif self .framework == 'pytorch' :
517480 params_export = {
@@ -523,9 +486,8 @@ def _export_model(self, quantized_model: Any) -> None:
523486
524487 def quantize_and_export (self , float_model : Any ,
525488 representative_dataset : Any ,
526- method : str = 'PTQ' ,
527489 framework : str = 'pytorch' ,
528- use_internal_tpc : bool = True ,
490+ method : str = 'PTQ' ,
529491 use_mixed_precision : bool = False ,
530492 param_items : Optional [List [List [Any ]]] = None
531493 ) -> Tuple [bool , Any ]:
@@ -536,12 +498,10 @@ def quantize_and_export(self, float_model: Any,
536498 float_model: The float model to be quantized.
537499 representative_dataset (Callable, np.array, tf.Tensor):
538500 Representative dataset for calibration.
539- method (str): Quantization method, e.g., 'PTQ' or 'GPTQ'.
540- Default: 'PTQ'
541501 framework (str): 'tensorflow' or 'pytorch'.
542502 Default: 'pytorch'
543- use_internal_tpc (bool ): Whether to use internal_tpc .
544- Default: True
503+ method (str ): Quantization method, e.g., 'PTQ' or 'GPTQ' .
504+ Default: 'PTQ'
545505 use_mixed_precision (bool): Whether to use mixed-precision
546506 quantization. Default: False
547507 param_items (list): List of parameter settings.
@@ -565,11 +525,10 @@ def quantize_and_export(self, float_model: Any,
565525
566526 >>> wrapper = mct.MCTWrapper()
567527
568- set method, framework , and other parameters
528+ set framework, method , and other parameters
569529
570- >>> method = 'PTQ'
571530 >>> framework = 'tensorflow'
572- >>> use_internal_tpc = True
531+ >>> method = 'PTQ'
573532 >>> use_mixed_precision = False
574533
575534 set parameters if needed
@@ -581,19 +540,17 @@ def quantize_and_export(self, float_model: Any,
581540 >>> flag, quantized_model = wrapper.quantize_and_export(
582541 ... float_model=float_model,
583542 ... representative_dataset=representative_dataset,
584- ... method=method,
585543 ... framework=framework,
586- ... use_internal_tpc=use_internal_tpc ,
544+ ... method=method ,
587545 ... use_mixed_precision=use_mixed_precision,
588546 ... param_items=param_items
589547 ... )
590548
591549 """
592550 try :
593551 # Step 1: Initialize and validate all input parameters
594- self ._initialize_and_validate (
595- float_model , representative_dataset , method , framework ,
596- use_internal_tpc , use_mixed_precision )
552+ self ._initialize_and_validate ( float_model , representative_dataset ,
553+ framework , method , use_mixed_precision )
597554
598555 # Step 2: Apply custom parameter modifications
599556 self ._modify_params (param_items )
0 commit comments