1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#pragma once
#include "caffe2/quantization/server/dnnlowp.h"
namespace dnnlowp {
class QuantizationErrorMinimization {
public:
virtual TensorQuantizationParams ChooseQuantizationParams(
const Histogram& hist,
bool preserve_sparsity = false,
int precision = 8) = 0;
virtual ~QuantizationErrorMinimization(){};
};
class NormMinimization : public QuantizationErrorMinimization {
public:
enum Kind {
L1,
L2,
};
NormMinimization(Kind kind) : kind_(kind) {}
/**
* Faster approximate search
*/
TensorQuantizationParams NonlinearQuantizationParamsSearch(
const Histogram& hist,
bool preserve_sparsity = false,
int precision = 8);
TensorQuantizationParams ChooseQuantizationParams(
const Histogram& hist,
bool preserve_sparsity = false,
int precision = 8) override;
protected:
Kind kind_;
};
class L1ErrorMinimization : public NormMinimization {
public:
L1ErrorMinimization() : NormMinimization(L1) {}
};
class P99 : public QuantizationErrorMinimization {
public:
float threshold_;
P99(float p99_threshold = 0.99) : threshold_(p99_threshold) {}
TensorQuantizationParams ChooseQuantizationParams(
const Histogram& hist,
bool preserve_sparsity = true,
int precision = 8) override;
}; // class P99QuantizationFactory
} // namespace dnnlowp
|