Skip to content

Commit

Permalink
[luci] Propagate qparam backward in onnx-fake quant model (#14489)
Browse files Browse the repository at this point in the history
This propagates qparam backward in onnx-fake quant model.

ONE-DCO-1.0-Signed-off-by: Hyukjin Jeong <[email protected]>
  • Loading branch information
jinevening authored Dec 24, 2024
1 parent 28a44e2 commit 5c65065
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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);
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

0 comments on commit 5c65065

Please sign in to comment.