-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a BERT example using Intel Neural Compressor SmoothQuant (#411)
## Describe your changes Add a BERT example using Intel® Neural Compressor SmoothQuant. Add an introduction of Intel® Neural Compressor SmoothQuant to the README. ## Checklist before requesting a review - [ ] Add unit tests for this change. - [ ] Make sure all tests can pass. - [x] Update documents if necessary. - [x] Format your code by running `pre-commit run --all-files` - [ ] Is this a user-facing change? If yes, give a description of this change to be included in the release notes. ## (Optional) Issue link --------- Signed-off-by: yuwenzho <[email protected]>
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"input_model":{ | ||
"type": "PyTorchModel", | ||
"config": { | ||
"model_loader": "load_pytorch_origin_model", | ||
"model_script": "user_script.py", | ||
"io_config": { | ||
"input_names": ["input_ids", "attention_mask", "token_type_ids"], | ||
"input_shapes": [[1, 128], [1, 128], [1, 128]], | ||
"input_types": ["int64", "int64", "int64"], | ||
"output_names": ["output"] | ||
} | ||
} | ||
}, | ||
"evaluators": { | ||
"common_evaluator": { | ||
"metrics":[ | ||
{ | ||
"name": "accuracy", | ||
"type": "accuracy", | ||
"sub_types": [ | ||
{"name": "accuracy_score", "priority": 1, "goal": {"type": "percent-max-degradation", "value": 2}} | ||
], | ||
"user_config":{ | ||
"post_processing_func": "post_process", | ||
"user_script": "user_script.py", | ||
"dataloader_func": "create_dataloader", | ||
"batch_size": 1 | ||
} | ||
}, | ||
{ | ||
"name": "latency", | ||
"type": "latency", | ||
"sub_types": [ | ||
{"name": "avg", "priority": 2, "goal": {"type": "percent-min-improvement", "value": 20}} | ||
], | ||
"user_config":{ | ||
"user_script": "user_script.py", | ||
"dataloader_func": "create_dataloader", | ||
"batch_size": 1 | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"passes": { | ||
"conversion": { | ||
"type": "OnnxConversion", | ||
"config": { | ||
"target_opset": 13 | ||
} | ||
}, | ||
"transformers_optimization": { | ||
"type": "OrtTransformersOptimization", | ||
"config": {"model_type": "bert"} | ||
}, | ||
"quantization": { | ||
"type": "IncStaticQuantization", | ||
"disable_search": true, | ||
"config": { | ||
"quant_format": "QOperator", | ||
"user_script": "user_script.py", | ||
"dataloader_func": "inc_glue_calibration_reader", | ||
"recipes":{ | ||
"smooth_quant": true, | ||
"smooth_quant_args": {"alpha": 0.7} | ||
}, | ||
"metric": { | ||
"name": "accuracy", | ||
"type": "custom", | ||
"sub_types": [ | ||
{"name": "accuracy_custom", "priority": 1, "higher_is_better": true, "goal": {"type": "percent-max-degradation", "value": 2}} | ||
], | ||
"user_config":{ | ||
"user_script": "user_script.py", | ||
"evaluate_func": "eval_accuracy", | ||
"batch_size": 1 | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"engine": { | ||
"search_strategy": { | ||
"execution_order": "joint", | ||
"search_algorithm": "exhaustive" | ||
}, | ||
"evaluator": "common_evaluator", | ||
"cache_dir": "cache", | ||
"output_dir": "models/bert_inc_static_ptq_cpu" | ||
} | ||
} |