Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt Neural Coder to INC New API TF and ONNX part #858

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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