Skip to content

Commit

Permalink
Adapt Neural Coder to INC New API (#858)
Browse files Browse the repository at this point in the history
Signed-off-by: zehao-intel <[email protected]>
  • Loading branch information
zehao-intel authored May 11, 2023
1 parent 113ca1e commit e74a8a0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 35 deletions.
1 change: 0 additions & 1 deletion neural_coder/backends/keras_inc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ transformation:
- |-
[+] from neural_compressor.quantization import fit
[+] from neural_compressor.config import PostTrainingQuantConfig
[+] from neural_compressor.experimental import common
[+] config = PostTrainingQuantConfig(backend='itex')
[+] quantized_model = fit(MODEL_NAME, conf=config, calib_dataloader=DATALOADER_NAME, eval_func=eval_func)
order:
Expand Down
12 changes: 4 additions & 8 deletions neural_coder/backends/onnx_inc_dynamic_quant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ transformation:
- insert_below_model_definition_line
content:
- |-
[+] from neural_compressor.experimental import Quantization, common
[+] from neural_compressor import options, conf
[+] conf.model.framework = 'onnxrt_integerops'
[+] conf.quantization.approach = 'post_training_dynamic_quant'
[+] quantizer = Quantization(conf)
[+] quantizer.model = common.Model(MODEL_NAME)
[+] quantizer.eval_func = EVAL_FUNCTION_NAME
[+] MODEL_NAME = quantizer()
[+] from neural_compressor.quantization import fit
[+] from neural_compressor.config import PostTrainingQuantConfig
[+] config = PostTrainingQuantConfig(approach='dynamic')
[+] MODEL_NAME = fit(MODEL_NAME, conf=config, calib_dataloader=DATALOADER_NAME, eval_func=EVAL_FUNCTION_NAME)
order:
- below:
above:
13 changes: 4 additions & 9 deletions neural_coder/backends/onnx_inc_static_quant_qdq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ transformation:
- insert_below_model_definition_line
content:
- |-
[+] from neural_compressor.experimental import Quantization, common
[+] from neural_compressor import options, conf
[+] conf.model.framework = 'onnxrt_qdqops'
[+] conf.quantization.approach = 'post_training_static_quant'
[+] quantizer = Quantization(conf)
[+] quantizer.model = common.Model(MODEL_NAME)
[+] quantizer.calib_dataloader = DATALOADER_NAME
[+] quantizer.eval_func = EVAL_FUNCTION_NAME
[+] MODEL_NAME = quantizer()
[+] from neural_compressor.quantization import fit
[+] from neural_compressor.config import PostTrainingQuantConfig
[+] config = PostTrainingQuantConfig(quant_format='QDQ')
[+] MODEL_NAME = fit(MODEL_NAME, conf=config, calib_dataloader=DATALOADER_NAME, eval_func=EVAL_FUNCTION_NAME)
order:
- below:
above:
13 changes: 4 additions & 9 deletions neural_coder/backends/onnx_inc_static_quant_qlinear.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ transformation:
- insert_below_model_definition_line
content:
- |-
[+] from neural_compressor.experimental import Quantization, common
[+] from neural_compressor import options, conf
[+] conf.model.framework = 'onnxrt_qlinearops'
[+] conf.quantization.approach = 'post_training_static_quant'
[+] quantizer = Quantization(conf)
[+] quantizer.model = common.Model(MODEL_NAME)
[+] quantizer.calib_dataloader = DATALOADER_NAME
[+] quantizer.eval_func = EVAL_FUNCTION_NAME
[+] MODEL_NAME = quantizer()
[+] from neural_compressor.quantization import fit
[+] from neural_compressor.config import PostTrainingQuantConfig
[+] config = PostTrainingQuantConfig(quant_format='default')
[+] MODEL_NAME = fit(MODEL_NAME, conf=config, calib_dataloader=DATALOADER_NAME, eval_func=EVAL_FUNCTION_NAME)
order:
- below:
above:
13 changes: 5 additions & 8 deletions neural_coder/coders/tensorflow/inc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ def transform(self):
model_name = "model"
indent_level = get_line_indent_level(line)
self.result.append(line)
self.result.append(" " * indent_level + "from neural_compressor.conf.config import QuantConf")
self.result.append(" " * indent_level + "from neural_compressor.experimental import Quantization")
self.result.append(" " * indent_level + "from neural_compressor.experimental import common")
self.result.append(" " * indent_level + "quant_config = QuantConf()")
self.result.append(" " * indent_level + "quant_config.usr_cfg.model.framework = 'tensorflow'")
self.result.append(" " * indent_level + "quantizer = Quantization(quant_config)")
self.result.append(" " * indent_level + "quantizer.model = common.Model(" + model_name + ")")
self.result.append(" " * indent_level + model_name + " = quantizer.fit()")
self.result.append(" " * indent_level + "from neural_compressor.quantization import fit")
self.result.append(" " * indent_level + "from neural_compressor.config import PostTrainingQuantConfig")
self.result.append(" " * indent_level + "from neural_compressor import common")
self.result.append(" " * indent_level + "config = PostTrainingQuantConfig()")
self.result.append(" " * indent_level + model_name + " = fit(" + model_name + ", conf=config)")
else:
self.result.append(line)
for index, line in enumerate(self.result):
Expand Down

0 comments on commit e74a8a0

Please sign in to comment.