Added Asymmetric perchannel quantization support (#682)

Type: New Feature

Signed-off-by: Feiyue Chen <Feiyue.Chen@verisilicon.com>
This commit is contained in:
Chen Feiyue 2024-02-27 09:37:33 +08:00 committed by GitHub
parent 3b74cf01fb
commit 8ca1382474
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 2 deletions

View File

@ -43,7 +43,13 @@ enum class DataType {
UINT4
};
enum class QuantType { NONE, ASYMMETRIC, SYMMETRIC_PER_CHANNEL, DYNAMIC_FIXED_POINT };
enum class QuantType {
NONE,
ASYMMETRIC,
SYMMETRIC_PER_CHANNEL,
ASYMMETRIC_PER_CHANNEL,
DYNAMIC_FIXED_POINT
};
enum TensorAttribute {
CONSTANT = 1 << 0,

View File

@ -53,7 +53,26 @@ void PackTensorDtype(tim::vx::TensorSpec& spec, vsi_nn_dtype_t* dtype) {
break;
case tim::vx::QuantType::SYMMETRIC_PER_CHANNEL: {
dtype->scales = spec.quantization_.Scales().data();
dtype->scale_dim = spec.quantization_.ZeroPoints().size();
dtype->scale_dim = spec.quantization_.Scales().size();
#if (VSI_NN_VERSION_MAJOR == 1 && VSI_NN_VERSION_MINOR == 1 && \
VSI_NN_VERSION_PATCH <= 18)
{
std::vector<float> zps(spec.quantization_.ZeroPoints().size());
std::transform(spec.quantization_.ZeroPoints().begin(),
spec.quantization_.ZeroPoints().end(), zps.begin(),
[](const int& it) { return static_cast<float>(it); });
dtype->zero_points = zps.data();
}
#else
dtype->zero_points = spec.quantization_.ZeroPoints().data();
#endif
dtype->zero_points_dim = spec.quantization_.ZeroPoints().size();
dtype->channel_dim = spec.quantization_.ChannelDim();
break;
}
case tim::vx::QuantType::ASYMMETRIC_PER_CHANNEL: {
dtype->scales = spec.quantization_.Scales().data();
dtype->scale_dim = spec.quantization_.Scales().size();
#if (VSI_NN_VERSION_MAJOR == 1 && VSI_NN_VERSION_MINOR == 1 && \
VSI_NN_VERSION_PATCH <= 18)
{

View File

@ -65,6 +65,8 @@ vsi_nn_qnt_type_e TranslateQuantType(QuantType qtype) {
return VSI_NN_QNT_TYPE_AFFINE_ASYMMETRIC;
case QuantType::SYMMETRIC_PER_CHANNEL:
return VSI_NN_QNT_TYPE_AFFINE_PERCHANNEL_SYMMETRIC;
case QuantType::ASYMMETRIC_PER_CHANNEL:
return VSI_NN_QNT_TYPE_AFFINE_PERCHANNEL_ASYMMETRIC;
case QuantType::DYNAMIC_FIXED_POINT:
return VSI_NN_QNT_TYPE_DFP;
default: