Skip to content

Commit

Permalink
[luci/pass] Quantize Onnx-fq model (#12817)
Browse files Browse the repository at this point in the history
This enables to quantize onnx-fq model.

ONE-DCO-1.0-Signed-off-by: Hyukjin Jeong <[email protected]>
  • Loading branch information
jinevening authored Mar 29, 2024
1 parent f2c6558 commit 74a9862
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/luci/pass/include/luci/CircleQuantizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CircleQuantizer final
ForceQuantParam,
ConvertToFakeQuantizedModel,
QuantizeWeights,
QuantizeOnnxFakeQuantizedModel,
};

enum AlgorithmParameters
Expand Down
25 changes: 25 additions & 0 deletions compiler/luci/pass/src/CircleQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "luci/Pass/QuantizeWithMinMaxPass.h"
#include "luci/Pass/QuantizeDequantizeWeightsPass.h"
#include "luci/Pass/QuantizeWeightsPass.h"
#include "luci/Pass/QuantizeOnnxFakeQuantModelPass.h"

#include "luci/Pass/CircleShapeInferencePass.h"
#include "luci/Pass/CircleTypeInferencePass.h"
Expand Down Expand Up @@ -657,6 +658,30 @@ void CircleQuantizer::quantize(loco::Graph *g) const
weights_quantizer.run(g);
}

if (_options->query(Options::Algorithm::QuantizeOnnxFakeQuantizedModel))
{
auto ctx = std::make_unique<luci::QuantizeOnnxFakeQuantModelPass::Context>();
{
ctx->default_activation_dtype = loco::DataType::S16;
}

luci::QuantizeOnnxFakeQuantModelPass quantizer(std::move(ctx));

quantizer.run(g);

logo::Phase phase;

// Default passes
phase.emplace_back(std::make_unique<logo::RemoveDeadNodeWithQueryPass>());
phase.emplace_back(std::make_unique<luci::CircleShapeInferencePass>());
phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());

ProgressReporter prog(g, logo::PhaseStrategy::Restart);
logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
phase_runner.attach(&prog);
phase_runner.run(phase);
}

// Requantize
if (_options->query(Options::Algorithm::Requantize))
{
Expand Down

0 comments on commit 74a9862

Please sign in to comment.