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

Unifying post-quantization properties #20724

Merged
merged 3 commits into from
Nov 25, 2021

Conversation

DominikaJedynak
Copy link
Contributor

@DominikaJedynak DominikaJedynak commented Nov 3, 2021

Description

Unifying requantize/dequantize post-quantization fuses for different operators into single property.

@mxnet-bot
Copy link

Hey @DominikaJedynak , Thanks for submitting the PR
All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands:

  • To trigger all jobs: @mxnet-bot run ci [all]
  • To trigger specific jobs: @mxnet-bot run ci [job1, job2]

CI supported jobs: [windows-gpu, unix-cpu, sanity, centos-cpu, clang, unix-gpu, miscellaneous, website, windows-cpu, edge, centos-gpu]


Note:
Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin.
All CI tests must pass before the PR can be merged.

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 3, 2021
@DominikaJedynak
Copy link
Contributor Author

@mxnet-bot run ci [centos-gpu, unix-cpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu, centos-gpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 3, 2021
@DominikaJedynak
Copy link
Contributor Author

@mxnet-bot run ci [centos-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [centos-gpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review labels Nov 4, 2021
@DominikaJedynak
Copy link
Contributor Author

@mxnet-bot run ci [unix-cpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 9, 2021
Copy link
Contributor

@bgawrych bgawrych left a comment

Choose a reason for hiding this comment

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

Overall LGTM - one comment below

support_requantize_fusion_op_name.insert("_sg_onednn_conv");
support_requantize_fusion_op_name.insert("_contrib_quantized_elemwise_add");
support_requantize_fusion_op_name.insert("_contrib_quantized_npi_add");
disable_fuse_all = dmlc::GetEnv("MXNET_DISABLE_ONEDNN_FUSE_ALL", false);
Copy link
Contributor

@bgawrych bgawrych Nov 10, 2021

Choose a reason for hiding this comment

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

What about changing this flag to something less general? I mean this flag doesn't disable all fuses (only the ones in this file). So better would be something like "MXNET_DISABLE_ONEDNN_FUSE_REQUANTIZE" and "MXNET_DISABLE_ONEDNN_FUSE_DEQUANTIZE". We also can negate default value to call it "MXNET_ONEDNN_FUSE_REQUANTIZE" and "MXNET_ONEDNN_FUSE_DEQUANTIZE".
+@anko-intel

Copy link
Contributor

Choose a reason for hiding this comment

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

Fully agree. "MXNET_ONEDNN_FUSE_REQUANTIZE" and "MXNET_ONEDNN_FUSE_DEQUANTIZE" are good proposals

Copy link
Contributor

@mozga-intel mozga-intel left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

"_sg_onednn_selfatt_valatt",
"_sg_onednn_batch_dot"};

class SgDNNLPostQuantizeSelector : public SubgraphSelectorV2 {
public:
/*! \brief pattern match status */
enum SelectStatus {
Copy link
Contributor

@mozga-intel mozga-intel Nov 8, 2021

Choose a reason for hiding this comment

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

[Future consideration] It could be fine to replace plain enum with class enum - to avoid implicitly conversion to other types (like another enum or int)

@@ -20,146 +20,209 @@
#define MXNET_OPERATOR_SUBGRAPH_DNNL_DNNL_POST_QUANTIZE_PROPERTY_H_
#if MXNET_USE_ONEDNN == 1

#include <memory>
#include <set>
#include <string>
#include <vector>

#include "../../nn/dnnl/dnnl_convolution-inl.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

[Future consideration] + @anko-intel

Suggested change
#include "../../nn/dnnl/dnnl_convolution-inl.h"
#include "./dnnl_convolution-inl.h"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This particular file is in nn/dnnl, not subgraph/dnnl, but I can change all paths in a way that avoids dots if you consider it more transparent

"_sg_onednn_selfatt_valatt",
"_sg_onednn_batch_dot"};

class SgDNNLPostQuantizeSelector : public SubgraphSelectorV2 {
public:
/*! \brief pattern match status */
enum SelectStatus {
Copy link
Contributor

@mozga-intel mozga-intel Nov 10, 2021

Choose a reason for hiding this comment

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

[Future consideration] Why the enum (enum SelectStatus) is public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was not part of my changes but you are right, it is better to make it private :)

support_requantize_fusion_op_name.insert("_contrib_quantized_npi_add");
explicit SgDNNLPostQuantizeSelector(const bool dis_fuse_all, const bool dis_float_output)
: disable_fuse_all(dis_fuse_all), disable_float_output(dis_float_output) {
support_requantize_fusion_op_name = support_req_fusion_op;
Copy link
Contributor

@mozga-intel mozga-intel Nov 10, 2021

Choose a reason for hiding this comment

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

What are the pros and cons of using this assignment? Roughly, why the set is global and then it's inexplicably assigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used in two different classes and is private in both, and I wanted to avoid duplicating. I will place this set inside anonymous namespace, as we discussed.

if (n.outputs.size() > 1) {
// check if requantize have other outputs than dequantize
// if it has we can't fuse dequantize
for (auto kv : n.outputs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about? If an object is const-> then kv is const, otherwise, the kv might be non-const.

Suggested change
for (auto kv : n.outputs) {
for (const auto kv : n.outputs) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kv.first, which is the only place where kv is used, is marked const, but I can make kv const as well for clarity

support_requantize_fusion_op_name.count(raw_node->op()->name)) {
status = kStart;
matched_list.clear();
matched_list.push_back(&n);
Copy link
Contributor

@mozga-intel mozga-intel Nov 10, 2021

Choose a reason for hiding this comment

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

If we clear the vector here, the capacity is the same as before; Then it might be better to use emplace_back(&n) instead of push_back(n) ~ I hope to avoid creating temp object before.
How about using?

Suggested change
matched_list.push_back(&n);
matched_list.emplace_back(&n);

#include "../common.h"
#include "dnnl_conv-inl.h"
#include "dnnl_subgraph_base-inl.h"

namespace mxnet {
namespace op {

class SgDNNLPostQuantizeSelector : public SubgraphSelector {
const std::set<std::string> support_req_fusion_op = {"_contrib_quantized_elemwise_add",
Copy link
Contributor

Choose a reason for hiding this comment

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

This global set is likely enabled in all TU. What is an advantage of using it in this place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commented above

@mseth10 mseth10 removed the pr-awaiting-review PR is waiting for code review label Nov 16, 2021
@mseth10 mseth10 added the pr-awaiting-testing PR is reviewed and waiting CI build and test label Nov 23, 2021
@mseth10 mseth10 added pr-work-in-progress PR is still work in progress and removed pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 23, 2021
@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 23, 2021
@DominikaJedynak
Copy link
Contributor Author

@mxnet-bot run ci [unix-cpu, miscellaneous ]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu, miscellaneous]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 23, 2021
@DominikaJedynak
Copy link
Contributor Author

@mxnet-bot run ci [unix-cpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 24, 2021
@DominikaJedynak
Copy link
Contributor Author

@mxnet-bot run ci [unix-cpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 24, 2021
Copy link
Contributor

@mozga-intel mozga-intel left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@bgawrych bgawrych merged commit 26f9fa6 into apache:master Nov 25, 2021
@DominikaJedynak DominikaJedynak deleted the unify_requantize_dequantize branch November 25, 2021 11:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants