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

Fix quantize pass error when excluding a quantization supported op #13596

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

ciyongch
Copy link
Contributor

Description

This PR is to address the error when excluding a quantization supported op in a model like the case below, where both op1 and op2 support quantization.
op1 -> op2
When excluding op1 from the model, the pattern is changed to
op1 -> _contrib_quantize -> quantized_op2
There's an incorrect connection (incorrect entry index) between _contrib_quantize and quantize_op2 for min/max inputs in current code base.

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 http: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

@TaoLv @pengzhao-intel @apeforest

@pengzhao-intel
Copy link
Contributor

Thanks for the fix.
Could you attach the picture of the graph before and after the change?

@ciyongch
Copy link
Contributor Author

@pengzhao-intel The picture of graph might not reflect the error, an enhanced test was added to cover this kind of cases. I paste the full symbol file of the test case w/ and w/o the fix.

The incorrect connection (error entry index) is located at 3nd/4th input (counting from 0), [21, 4294967295, 0], [21, 0, 0]

    {
      "op": "_contrib_quantized_conv", 
      "name": "quantized_conv1", 
      "attrs": {
        "kernel": "(1, 1)", 
        "no_bias": "False", 
        "num_filter": "4", 
        "pad": "(0, 0)"
      }, 
      "inputs": [[21, 0, 0], [22, 0, 0], [23, 0, 0], [21, 4294967295, 0], [21, 0, 0], [24, 0, 0], [25, 0, 0], [26, 0, 0], [27, 0, 0]]
    },

After fixed, the connection is as below, 3nd/4th inputs are correct now [21, 1, 0], [21, 2, 0]

    {
      "op": "_contrib_quantized_conv", 
      "name": "quantized_conv1", 
      "attrs": {
        "kernel": "(1, 1)", 
        "no_bias": "False", 
        "num_filter": "4", 
        "pad": "(0, 0)"
      }, 
      "inputs": [[21, 0, 0], [22, 0, 0], [23, 0, 0], [21, 1, 0], [21, 2, 0], [24, 0, 0], [25, 0, 0], [26, 0, 0], [27, 0, 0]]
    }, 
    {

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.

Thanks for the explanation. It makes sense.

@ciyongch
Copy link
Contributor Author

ping @apeforest @TaoLv to have a reveiw :)

Copy link
Member

@TaoLv TaoLv left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for the fix.

@roywei
Copy link
Member

roywei commented Dec 12, 2018

@mxnet-label-bot add [Operator, pr-awaiting-review]
@ciyongch Thanks for the contribution, is there an issue related to this fix?

@marcoabreu marcoabreu added Operator pr-awaiting-review PR is waiting for code review labels Dec 12, 2018
@ciyongch
Copy link
Contributor Author

@roywei No open issue related to it so far. We found this error when trying to quantize Resnet50_v1 at local (with excluding some ops which supports quantization from the model script manually). In this case, NeedQuantize(e.node, excluded_nodes) is much more accurate than quantized_op_map.count(e.node->op()).
A test case is also added to cover this kind of error.

@reminisce reminisce merged commit e36f888 into apache:master Dec 12, 2018
zhaoyao73 added a commit to zhaoyao73/incubator-mxnet that referenced this pull request Dec 13, 2018
* upstream/master: (38 commits)
  Feature/mkldnn static (apache#13628)
  Fix the bug of BidirectionalCell (apache#13575)
  Set install path for libmxnet.so dynamic lib on Mac OS (apache#13629)
  add batch norm test (apache#13625)
  Scripts for building dependency libraries of MXNet (apache#13282)
  fix quantize pass error when the quantization supported Op are excluded in the model (apache#13596)
  Optimize C++ API (apache#13496)
  Fix warning in waitall doc (apache#13618)
  [MXNET-1225] Always use config.mk in make install instructions (apache#13364)
  [MXNET-1224]: improve scala maven jni build and packing. (apache#13493)
  [MXNET-1155] Add scala packageTest utility (apache#13046)
  fix the Float not showing correctly problem (apache#13617)
  apache#13385 [Clojure] - Turn examples into integration tests (apache#13554)
  Add Intel MKL blas to Jenkins (apache#13607)
  Revert "[MXNET-1198] MXNet Java API (apache#13162)"
  Reducing the length of setup tutorial (apache#13306)
  [MXNET-1182] Predictor example (apache#13237)
  [MXNET-1187] Added Java SSD Inference Tutorial for website (apache#13201)
  add defaults and clean up the tests (apache#13295)
  [MXNET-1181] Added command line alternative to IntelliJ in install instructions (apache#13267)
  ...
@ciyongch ciyongch deleted the enhance_quantize_pass branch May 22, 2019 02:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Operator pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants