Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Quantization]support exclude operators while quantization #15910

Merged
merged 13 commits into from
Aug 21, 2019

Conversation

xinyu-intel
Copy link
Contributor

Description

Two functionally enhancement for quantization tool:

  • support exclude operators while quantization.
  • address Model Quantization with CUDNN #15796 , automatically exclude operator which is not registered with a compute function on the target device.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@pengzhao-intel
Copy link
Contributor

@ZhennanQin @ciyongch please take a review :)

* \param num_excluded_sym_names number of layers excluded from being quantized in the input symbol
* \param excluded_sym_names node names to be excluded from being quantized
* \param num_excluded_op_names number of operators excluded from being quantized in the input symbol
* \param excluded_op_names operator names to be excluded from being quantized
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use one group of the parameter to implement two functionality in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some models may define layer names with specific style. so, it's not easy to group these two functions:(

auto qnode = q_ptr(node->attrs);
if (!isRegistered(qnode, dev_type)) {
LOG(INFO) << "Neither FCompute nor FComputeEx registered, " << node->op()->name
<< " excluded automatically.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excluded => is excluded

DFSVisit(subgraph_sym->outputs, [&](const nnvm::NodePtr& n) {
if (n->is_variable()) return;
if (excluded_nodes.count(n->attrs.name) ||
excluded_ops.count(node->op()->name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fused op is a new op, so we shouldn't check its inner node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found we cannot exclude fused conv layers when settingexcluded_op_names=['Convolution']. Is it necessary to check the inner node here?

Copy link
Contributor

@ciyongch ciyongch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any test case to cover subgraph ops?

https://www.tensorflow.org/performance/quantization.
The calibration implementation borrows the idea of Nvidia's 8-bit Inference with TensorRT:
https://on-demand.gputechconf.com/gtc/2017/presentation/s7310-8-bit-inference-with-tensorrt.pdf
and adapts the method to MXNet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this notes here for future reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file too long (>1000L):(

https://www.tensorflow.org/performance/quantization.
The calibration implementation borrows the idea of Nvidia's 8-bit Inference with TensorRT:
https://on-demand.gputechconf.com/gtc/2017/presentation/s7310-8-bit-inference-with-tensorrt.pdf
and adapts the method to MXNet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this notes here for future reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file too long (>1000L):(

@@ -678,6 +678,10 @@ def check_quantized_bn(data_shape, qdtype):

@with_seed()
def test_quantize_params():
if is_test_for_native_cpu():
print('skipped testing quantized_pooling for native cpu since it is not supported yet')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test name? testing quantize_params ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

@pengzhao-intel
Copy link
Contributor

@ZhennanQin @ciyongch please take a final review :)

Copy link
Contributor

@ciyongch ciyongch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Contributor

@ZhennanQin ZhennanQin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@pengzhao-intel pengzhao-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging now and thanks for the contribution.

@pengzhao-intel pengzhao-intel merged commit 0b5526b into apache:master Aug 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants