Quantization method of neural network and apparatus for performing the same
A quantization method of a neural network, and an apparatus for performing the quantization method are provided. The quantization method includes obtaining parameters of the neural network, quantizing the parameters using a quantization scheme in which at least one positive quantization level and at least one negative quantization level symmetric to each other by excluding zero from quantization levels, and outputting the quantized parameters.
1 . A quantization method of a neural network, the method comprising:
obtaining parameters of the neural network;
quantizing the parameters using a quantization scheme in which at least one positive quantization level and at least one negative quantization level are symmetric to each other by excluding zero from quantization levels; and
outputting the quantized parameters,
wherein the quantizing further comprises:
normalizing the parameters based on a step size for determining a quantization interval of the neural network;
generating an intermediate value based on the normalized parameters; and
performing quantization by applying a clip function to the intermediate value, a minimum value and a maximum value of a quantization range determined by a number of quantization bits.
2 . The method of claim 1 , wherein the quantizing of the parameters comprises quantizing the parameters based on vbar=clip(round(v/s+0.5)−0.5, −2b−1+0.5, 2b−1−0.5),
wherein v denotes the parameters, s denotes a step sidestep size for determining a quantization range of the neural network, and b denotes a number of quantization bits.
3 . The method of claim 1 , further comprising training the parameters through quantization-aware training.
4 . The method of claim 1 , wherein a step size for determining a quantization range of the neural network is determined based on joint training with the parameters.
5 . The method of claim 1 , wherein a step size for determining a quantization range of the neural network is determined based on the following equation:
∂
v
∂
s
=
{
-
v
s
+
(
⌈
v
s
⌉
-
0.5
)
if
-
Q
n
<
(
⌈
v
s
⌉
-
0.5
)
≤
Q
p
Q
n
if
(
⌈
v
s
⌉
-
0.5
)
≤
-
Q
n
Q
p
if
(
⌈
v
s
⌉
-
0.5
)
≥
Q
p
,
wherein v denotes the parameters, s denotes the step side, −Qn denotes a lowest quantization level, Qn denotes an absolute value of the lowest quantization level, and Qp denotes a highest quantization level.
6 . The method of claim 1 , wherein a multiply-accumulate (MAC) operation based on the quantized parameters is performed by binary neural network (BNN) hardware with an XNOR-Popcount structure.
7 . The method of claim 1 , wherein the quantized parameters are symmetric with respect to zero and equally assigned to a positive number and a negative number.
8 . The method of claim 1 , further comprising training the neural network trained with the quantized parameters.
9 . A non-transitory computer-readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the quantization method of claim 1 .
10 . An apparatus for a quantization method of a neural network, the apparatus comprising:
a processor configured to:
obtain parameters of the neural network;
quantize the parameters using a quantization scheme in which at least one positive quantization level and at least one negative quantization level are symmetric to each other by excluding zero from quantization levels; and
output the quantized parameters,
wherein the processor quantizes the parameters by:
normalizing the parameters based on a step size for determining a quantization interval of the neural network;
generating an intermediate value based on the normalized parameters; and
performing quantization by applying a clip function to the intermediate value, a minimum value and a maximum value of a quantization range determined by a number of quantization bits.
11 . The apparatus of claim 10 , wherein the processor is further configured to quantize the parameters based on the following equation:
v bar=clip(round( v/s+ 0.5)−0.5, −2 b− 1+0.5, 2 b− 1−0.5),
wherein v denotes the parameters, s denotes a step size for determining a quantization range of the neural network, and b denotes a number of quantization bits.
12 . The apparatus of claim 10 , wherein the processor is further configured to train the parameters through quantization-aware training.
13 . The apparatus of claim 10 , wherein a step size for determining a quantization range of the neural network is determined based on joint training with the parameters.
14 . The apparatus of claim 10 , wherein a step size for determining a quantization range of the neural network is determined based on the following equation:
∂
v
∂
s
=
{
-
v
s
+
(
⌈
v
s
⌉
-
0.5
)
if
-
Q
n
<
(
⌈
v
s
⌉
-
0.5
)
≤
Q
p
Q
n
if
(
⌈
v
s
⌉
-
0.5
)
≤
-
Q
n
Q
p
if
(
⌈
v
s
⌉
-
0.5
)
≥
Q
p
,
wherein v denotes the parameters, s denotes the step side, −Qn denotes a lowest quantization level, Qn denotes an absolute value of the lowest quantization level, and Qp denotes a highest quantization level.
15 . The apparatus of claim 10 , wherein a multiply-accumulate (MAC) operation based on the quantized parameters is performed by binary neural network (BNN) hardware with an XNOR-Popcount structure.
16 . The apparatus of claim 10 , wherein the quantized parameters are symmetric with respect to zero and equally assigned to a positive number and a negative number.
17 . The apparatus of claim 10 , further comprising
a communicator configured to perform a wireless communication; and
a memory configured to store at least one program,
wherein the processor is configured to execute the at least one program.
18 . A processor-implemented method, the method comprising:
receiving input data for a neural network task;
obtaining parameters of a neural network performing the neural network task;
quantizing the parameters using a quantization scheme in which at least one positive quantization level and at least one negative quantization level are symmetric to each other by excluding zero from quantization levels;
outputting the quantized parameters; and
performing the task on the input data using the neural network with the quantized parameters to generate a task result,
wherein the quantizing further comprises:
excluding zero from the quantization levels so that at least one positive quantization level and at least one negative quantization level are completely symmetric to each other,
wherein the quantizing comprises:
normalizing the parameters based on a step size for determining a quantization interval of the neural network;
generating an intermediate value based on the normalized parameters; and
performing quantization by applying a clip function to the intermediate value, a minimum value and a maximum value of a quantization range determined by a number of quantization bits.
19 . The method of claim 18 , wherein the quantizing further comprises:
distributing the quantization levels equally to positive and negative numbers, respectively, with a uniform range between parameters.