Skip to content

Commit ae8c6a7

Browse files
dzakharJaccovG
authored andcommitted
Checking of quantization params:
- Add checkers for quant params - add checking of Zero Point limitations for sa8. - Adjust user tests for new requirements
1 parent f8b2778 commit ae8c6a7

File tree

18 files changed

+359
-126
lines changed

18 files changed

+359
-126
lines changed

doc/documents/mli_kernels/trans_leaky_relu.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ satisfy the following conditions before calling the function:
9696
single scale factor and a single zero offset.
9797

9898
- Zero offset of ``in`` and ``out`` tensors must be within [-128, 127] range.
99+
100+
- Zero offset of ``slope_coeffs`` tensor must be within [-16384, 16383] range.
99101

100102
Depending on the debug level (see section :ref:`err_codes`) this function performs a parameter
101103
check and returns the result as an ``mli_status`` code as described in section :ref:`kernl_sp_conf`.

doc/documents/mli_kernels/trans_param_relu.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ satisfy the following conditions before calling the function:
126126
- ``in``, ``out`` and ``slope_coeff`` tensors must be quantized on the tensor level. This implies
127127
that the tensor contains a single scale factor and a single zero offset.
128128

129-
- Zero offset of ``in``, ``out`` and ``slope_coeffs`` tensors must be within [-128, 127] range.
129+
- Zero offset of ``in`` and ``out`` tensors must be within [-128, 127] range.
130+
131+
- Zero offset of ``slope_coeffs`` tensor must be within [-16384, 16383] range.
130132

131133
Depending on the debug level (see section :ref:`err_codes`) this function performs a parameter
132134
check and returns the result as an ``mli_status`` code as described in section :ref:`kernl_sp_conf`.

lib/src/kernels/common/mli_krn_gru_cell.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ MLI_FORCE_INLINE void gru_cell_prepare_and_run(
7575
one_el_params.sa.zero_point.mem.i16 = ir_asym_params.sa.zero_point.mem.i16 = 0;
7676
one_el_params.sa.scale_frac_bits.mem.i8 = 0;
7777
ir_asym_params.sa.scale_frac_bits.mem.i8 = 6;
78+
one_el_params.sa.scale.capacity = ir_asym_params.sa.scale.capacity = 0;
79+
one_el_params.sa.zero_point.capacity = ir_asym_params.sa.zero_point.capacity = 0;
80+
one_el_params.sa.scale_frac_bits.capacity = ir_asym_params.sa.scale_frac_bits.capacity = 0;
7881
} else {
7982
one_el_params.fx.frac_bits = 0;
8083
// 1sign and 3 integer bits for TANH/SIGM input is enough

lib/src/kernels/common/mli_krn_lstm_cell.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ MLI_FORCE_INLINE void lstm_cell_prepare_and_run(
7575
ir_asym_params.sa.scale.mem.i16 = 1;
7676
ir_asym_params.sa.zero_point.mem.i16 = 0;
7777
ir_asym_params.sa.scale_frac_bits.mem.i16 = 4;
78-
ir_asym_params.sa.scale.capacity = ir_asym_params.sa.zero_point.capacity = 1;
79-
ir_asym_params.sa.scale_frac_bits.capacity = 1;
78+
ir_asym_params.sa.scale.capacity = ir_asym_params.sa.zero_point.capacity = 0;
79+
ir_asym_params.sa.scale_frac_bits.capacity = 0;
8080
ir_tensor.el_params = ir_asym_params;
8181
} else {
8282
// 1sign and 3 integer bits for TANH/SIGM input is enough

lib/src/private/src/mli_check.cc

Lines changed: 310 additions & 84 deletions
Large diffs are not rendered by default.

user_tests/tests/mli_krn_avepool/tests_mli_krn_avepool.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ struct avepool_test_operands {
5252
const crc32_calc test_1_chksum_fx16{ 0x292DDF4E },
5353
test_2_chksum_fx16{ 0xA7542BBE },
5454
test_3_chksum_fx16{ 0x872AD40B },
55-
test_4_chksum_sa8{ 0xFEE5E73E },
55+
test_4_chksum_sa8{ 0xEFD3DFB7 },
5656
test_5_chksum_fx16{ 0x2F40CE76 },
5757
test_6_chksum_fx16{ 0x4871DD9B },
5858
test_7_chksum_fx16{ 0x56FC93D9 },
59-
test_8_chksum_fx16{ 0x63A4213E }, test_8_chksum_sa8{ 0x6E1BFA56 };
59+
test_8_chksum_fx16{ 0x63A4213E }, test_8_chksum_sa8{ 0xA6A02AAB };
6060

6161
#if defined(AVEPOOL_16BIT_MUL)
6262
// Shared CRC Results
6363
const crc32_calc test_1_chksum_sa8{ 0x1564B755 },
6464
test_2_chksum_sa8{ 0xD825FD74 },
6565
test_3_chksum_sa8{ 0x0F472106 },
66-
test_5_chksum_sa8{ 0x999C378F },
66+
test_5_chksum_sa8{ 0x188343E4 },
6767
test_6_chksum_sa8{ 0x784CA521 },
6868
test_7_chksum_sa8{ 0x67A9C0DA };
6969
#else
7070
// Shared CRC Results
7171
const crc32_calc test_2_chksum_sa8{ 0x60655C05 },
7272
test_3_chksum_sa8{ 0x978CB97E },
73-
test_5_chksum_sa8{ 0x72125356 },
73+
test_5_chksum_sa8{ 0x04313259 },
7474
test_7_chksum_sa8{ 0x891BA7D0 };
7575
// Platform Specific CRC Results
7676
#if defined(CRC_RM_UP)
@@ -111,7 +111,7 @@ const quality_metrics thresholds_fx16_test_huge_vals {
111111

112112
const quality_metrics thresholds_sa8_test_huge_vals {
113113
quality_metrics::kPassValueMaxAbsErr, quality_metrics::kPassValueSnr,
114-
/* SNR_DB = */52.f, /*Quant Error Perc = */ 88.f };
114+
/* SNR_DB = */51.9f, /*Quant Error Perc = */ 81.f };
115115

116116

117117

user_tests/tests/mli_krn_avepool/vectors_mli_krn_avepool.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static const float test_8_out_data[] = {
261261
static const int test_8_out_fx8_frac = -10;
262262

263263
static const int test_8_out_sa_dim = -1;
264-
static const float test_8_out_scale = 262.5616455078125f;
264+
static const float test_8_out_scale = 369.3381520669291f;
265265
static const float test_8_out_zero_point = 46905.9453125f;
266266
static const int8_t test_8_out_scales_frac[] = {6};
267267

@@ -431,7 +431,7 @@ static const float test_4_out_data[] = {
431431
static const int test_4_out_fx8_frac = 5;
432432

433433
static const int test_4_out_sa_dim = -1;
434-
static const float test_4_out_scale = 0.004397408105432987f;
434+
static const float test_4_out_scale = 0.01259965690102164f;
435435
static const float test_4_out_zero_point = 1.6001564264297485f;
436436
static const int8_t test_4_out_scales_frac[] = {21};
437437

@@ -468,7 +468,7 @@ static const float test_5_out_data[] = {
468468
static const int test_5_out_fx8_frac = 5;
469469

470470
static const int test_5_out_sa_dim = -1;
471-
static const float test_5_out_scale = 0.007898799143731594f;
471+
static const float test_5_out_scale = 0.01242864695120984f;
472472
static const float test_5_out_zero_point = 1.57843816280365f;
473473
static const int8_t test_5_out_scales_frac[] = {20};
474474

user_tests/tests/mli_krn_eltwise/tests_mli_krn_eltwise.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ struct eltwise_test_operands {
5151

5252
// Shared CRC Results
5353
const crc32_calc test_1_chksum_sa8{ 0xd48163e7 },
54-
test_2_chksum_sa8{ 0x6CE064A1 },
54+
test_2_chksum_sa8{ 0x5EDDFBDA },
5555
test_3_chksum_sa8{ 0x3b9100e1 },
5656
test_4_chksum_sa8{ 0xF22D7321 },
57-
test_5_chksum_sa8{ 0x8ECBC7B8 },
57+
test_5_chksum_sa8{ 0x9A14384C },
5858
test_6_chksum_fx16{ 0xfc026def }, test_6_chksum_sa8{ 0x3a54561 },
5959
test_7_chksum_fx16{ 0x488ed527 }, test_7_chksum_sa8{ 0xDA50B98A },
6060
test_8_chksum_fx16{ 0x68889D84 }, test_8_chksum_sa8{ 0x168B3B32 },
61-
test_9_chksum_fx16{ 0x9417F3D7 }, test_9_chksum_sa8{ 0x3382BC48 },
61+
test_9_chksum_fx16{ 0x9417F3D7 }, test_9_chksum_sa8{ 0xA83B910E },
6262
test_10_chksum_fx16{ 0xD728E430 }, test_10_chksum_sa8{ 0xE34DA6B0 },
6363
test_11_chksum_fx16{ 0xBF03F2E0 }, test_11_chksum_sa8{ 0xD36B7E94 };
6464

user_tests/tests/mli_krn_eltwise/vectors_mli_krn_eltwise.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static const float test_2_out_data[] = {
226226
0.282000f, 0.428892f, 0.321141f, 0.207858f, 0.549861f, 0.451810f, 0.371921f,
227227
0.661887f, 0.559452f};
228228

229-
static const float test_2_out_scale = 0.0024969152f;
229+
static const float test_2_out_scale = 0.0036528209f;
230230
static const float test_2_out_zero_point = 0.4639082551f;
231231
static const int8_t test_2_out_scales_frac[] = {23};
232232
static const int test_2_out_sa_dim = -1;
@@ -358,9 +358,9 @@ static const float test_5_out_data[] = {
358358
0.718000f, 0.571108f, 0.678859f, 0.792142f, 0.450139f, 0.548190f, 0.628079f,
359359
0.338113f, 0.440548f};
360360

361-
static const float test_5_out_scale = 0.0024969152f;
361+
static const float test_5_out_scale = 0.00422119484f;
362362
static const float test_5_out_zero_point = 0.5360917449f;
363-
static const int8_t test_5_out_scales_frac[] = {23};
363+
static const int8_t test_5_out_scales_frac[] = {22};
364364
static const int test_5_out_sa_dim = -1;
365365

366366
static const int test_5_out_fx8_frac = 7;
@@ -537,9 +537,9 @@ static const float test_9_out_data[] = {
537537
0.500000f, 0.500000f, 0.527085f, 0.500000f, 0.500000f, 0.500000f, 0.500000f,
538538
0.500000f, 0.500000f};
539539

540-
static const float test_9_out_scale = 0.0013092763f;
540+
static const float test_9_out_scale = 0.0052631578947f;
541541
static const float test_9_out_zero_point = 0.6669327021f;
542-
static const int8_t test_9_out_scales_frac[] = {24};
542+
static const int8_t test_9_out_scales_frac[] = {22};
543543
static const int test_9_out_sa_dim = -1;
544544

545545
static const int test_9_out_fx8_frac = 7;

user_tests/tests/mli_krn_gru_cell/tests_mli_krn_gru_cell.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ struct gru_cell_test_operands {
5858
// When developer finished implementation of kernel and consider it as ok, one needs to populate
5959
// proper checksums for tests in order to highlight any change which affects results.
6060
#if defined(CRC_RM_UP)
61-
const crc32_calc test_1_chksum_fx16{ 0xB4797831 }, test_1_chksum_fx16_fx8_fx8{ 0x85787025 }, test_1_chksum_sa8{ 0xC6301C0E },
62-
test_2_chksum_fx16{ 0xB4797831 }, test_2_chksum_fx16_fx8_fx8{ 0x85787025 }, test_2_chksum_sa8{ 0xC6301C0E },
61+
const crc32_calc test_1_chksum_fx16{ 0xB4797831 }, test_1_chksum_fx16_fx8_fx8{ 0x85787025 }, test_1_chksum_sa8{ 0x804E6240 },
62+
test_2_chksum_fx16{ 0xB4797831 }, test_2_chksum_fx16_fx8_fx8{ 0x85787025 }, test_2_chksum_sa8{ 0x804E6240 },
6363
test_3_chksum_fx16{ 0x5C7BCDF8 }, test_3_chksum_fx16_fx8_fx8{ 0x94A6998D }, test_3_chksum_sa8{ 0x5D944070 },
6464
test_4_chksum_fx16{ 0x873F4283 }, test_4_chksum_fx16_fx8_fx8{ 0x8A055C99 }, test_4_chksum_sa8{ 0xCFF7F69C },
6565
test_5_chksum_fx16{ 0x7369955E }, test_5_chksum_fx16_fx8_fx8{ 0xDE351B81 }, test_5_chksum_sa8{ 0xA2A9874F },
6666
test_6_chksum_fx16{ 0xBDACDE93 }, test_6_chksum_fx16_fx8_fx8{ 0x71B26E98 }, test_6_chksum_sa8{ 0xD424459E };
6767
#elif defined(CRC_RM_CONVERGENT)
68-
const crc32_calc test_1_chksum_fx16{ 0xB4797831 }, test_1_chksum_fx16_fx8_fx8{ 0x85787025 }, test_1_chksum_sa8{ 0xC6301C0E },
69-
test_2_chksum_fx16{ 0xB4797831 }, test_2_chksum_fx16_fx8_fx8{ 0x85787025 }, test_2_chksum_sa8{ 0xC6301C0E },
68+
const crc32_calc test_1_chksum_fx16{ 0xB4797831 }, test_1_chksum_fx16_fx8_fx8{ 0x85787025 }, test_1_chksum_sa8{ 0x804E6240 },
69+
test_2_chksum_fx16{ 0xB4797831 }, test_2_chksum_fx16_fx8_fx8{ 0x85787025 }, test_2_chksum_sa8{ 0x804E6240 },
7070
test_3_chksum_fx16{ 0x5C7BCDF8 }, test_3_chksum_fx16_fx8_fx8{ 0xE1B56E1E }, test_3_chksum_sa8{ 0x5D944070 },
7171
test_4_chksum_fx16{ 0xF50124D0 }, test_4_chksum_fx16_fx8_fx8{ 0x8A055C99 }, test_4_chksum_sa8{ 0xCFF7F69C },
7272
test_5_chksum_fx16{ 0x7369955E }, test_5_chksum_fx16_fx8_fx8{ 0xDE351B81 }, test_5_chksum_sa8{ 0xA2A9874F },

0 commit comments

Comments
 (0)