message: Respect the quantization parameters from QAT when applying post-training quantization
diff: @@ -22,6 +22,7 @@ limitations under the License.
  #include "llvm/ADT/STLExtras.h"
  #include "llvm/ADT/SmallVector.h"
  +#include "llvm/Support/Casting.h"
  #include "mlir/Dialect/Quant/FakeQuantSupport.h" // from @llvm-project
  #include "mlir/Dialect/Quant/QuantOps.h" // from @llvm-project
  #include "mlir/Dialect/Quant/QuantTypes.h" // from @llvm-project
  @@ -436,6 +437,16 @@ bool RemoveRedundantStatsOps(mlir::FuncOp func,
  llvm::SmallVector<quant::StatisticsOp, 16> all_stats_ops;
  llvm::DenseSet<Operation*> redundant_stats_ops;
  + // Step 0: remove the quant::StatisticsOp which are used by the tfl.quantize
  + // op in case it overrides the information from training FakeQuant ops.
  + func.walk([&](quant::QuantizeCastOp q) {
  + auto input_op = q.arg().getDefiningOp();
  + if (auto stats = llvm::dyn_cast_or_null<quant::StatisticsOp>(input_op)) {
  + q.setOperand(stats.arg());
  + if (stats.use_empty()) stats.erase();
  + }
  + });
  +
  // Step 1: forward pass: propagate any value scales which are not produces
  // by `SameOperandsAndResultsScale`. Additionally, remove the value scales
  // which are produced by the `restricted_output_params`.
  