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

[luci] Propagate qparam backward in onnx-fake quant model #14489

Merged
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
10 changes: 2 additions & 8 deletions compiler/luci/pass/src/PropagateQParamBackwardPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ void overwrite_quantparam(const luci::CircleNode *source, luci::CircleNode *targ
target_qparam->scale = source_qparam->scale;
target_qparam->zerop = source_qparam->zerop;
target_qparam->quantized_dimension = source_qparam->quantized_dimension;

target->dtype(source->dtype());
}

/**
Expand Down Expand Up @@ -188,8 +190,6 @@ void propagate_pack_quantparam(luci::CirclePack *pack)
if (succs.size() > 1)
continue;

// Non-const input must have been quantized
assert(node->quantparam() != nullptr);
Comment on lines -191 to -192
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 pass is now used for QuantizeOnnxFakeQuantModelPass, which makes this assumption invalid.

Q) Is it safe to remove the assert?
A) I think yes. The assert was just for checking the behavior of QuantizeWithMinMaxPass. Even though node->quantparam() == nullptr, overwrite_quantparam can work without any problem.

overwrite_quantparam(pack, node);
}
}
Expand Down Expand Up @@ -260,8 +260,6 @@ void propagate_one_hot_quantparam(luci::CircleOneHot *one_hot)
if (succs.size() > 1)
return;

// Non-const input must have been quantized
assert(node->quantparam() != nullptr);
overwrite_quantparam(one_hot, node);
}
};
Expand Down Expand Up @@ -340,8 +338,6 @@ void propagate_concat_quantparam(luci::CircleConcatenation *concat)
if (succs.size() > 1)
continue;

// Non-const input must have been quantized
assert(node->quantparam() != nullptr);
overwrite_quantparam(concat, node);
}
}
Expand Down Expand Up @@ -440,8 +436,6 @@ void propagate_pad_v2_quantparam(luci::CirclePadV2 *pad_v2)
if (succs.size() > 1)
return;

// Non-const input must have been quantized
assert(node->quantparam() != nullptr);
overwrite_quantparam(pad_v2, node);
}
};
Expand Down
7 changes: 7 additions & 0 deletions compiler/luci/pass/src/QuantizeOnnxFakeQuantModelPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "luci/Pass/QuantizeOnnxFakeQuantModelPass.h"
#include "luci/Pass/PropagateQParamBackwardPass.h"
#include "QuantizeOnnxQDQPass.h"
#include "QuantizeOnnxDequantizeLinearPass.h"
#include "QuantizeWithPredecessorPass.h"
Expand Down Expand Up @@ -92,6 +93,12 @@ bool QuantizeOnnxFakeQuantModelPass::run(loco::Graph *g)
pass.run(g);
}

// Backward propagation of activation qparam
{
PropagateQParamBackwardPass pqbp(_ctx->default_activation_dtype);
pqbp.run(g);
}

// Update qparam of output of special Ops
for (auto node : loco::active_nodes(loco::output_nodes(g)))
{
Expand Down