WO2021082653A1 - 数据处理方法、装置、计算机设备和存储介质 - Google Patents

数据处理方法、装置、计算机设备和存储介质 Download PDF

Info

Publication number
WO2021082653A1
WO2021082653A1 PCT/CN2020/110438 CN2020110438W WO2021082653A1 WO 2021082653 A1 WO2021082653 A1 WO 2021082653A1 CN 2020110438 W CN2020110438 W CN 2020110438W WO 2021082653 A1 WO2021082653 A1 WO 2021082653A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
quantized
winograd
result
quantization
Prior art date
Application number
PCT/CN2020/110438
Other languages
English (en)
French (fr)
Inventor
张英男
曾洪博
张尧
刘少礼
黄迪
周诗怡
张曦珊
刘畅
郭家明
高钰峰
Original Assignee
中科寒武纪科技股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中科寒武纪科技股份有限公司 filed Critical 中科寒武纪科技股份有限公司
Publication of WO2021082653A1 publication Critical patent/WO2021082653A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/06Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons
    • G06N3/063Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons using electronic means
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/30007Arrangements for executing specific machine instructions to perform operations on data operands
    • G06F9/30036Instructions to perform operations on packed data, e.g. vector, tile or matrix operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T1/00General purpose image data processing
    • G06T1/20Processor architectures; Processor configuration, e.g. pipelining

Definitions

  • the present disclosure relates to the field of computer technology, and in particular to a data processing method, device, computer equipment and storage medium.
  • neural network algorithm is a very popular machine learning algorithm recently, and has achieved very good results in various fields, such as image recognition, speech recognition, natural language processing, etc.
  • image recognition speech recognition
  • speech recognition natural language processing
  • the complexity of the algorithm is getting higher and higher.
  • the scale of the model is gradually increasing.
  • Using GPU and CPU to process these large-scale models requires a lot of computing time and consumes a lot of power.
  • a data processing method including:
  • a data processing device including:
  • the data quantization module performs quantization processing on the to-be-quantized data according to the determined quantization parameter to obtain quantized data, wherein the quantization parameter is determined according to the statistical result of the corresponding data to be quantized and the data bit width;
  • the convolution processing module continues to perform winograd convolution processing according to the quantized data to obtain a quantized winograd convolution result
  • the inverse quantization processing module performs inverse quantization processing on the quantized winograd convolution result to obtain the winograd convolution result.
  • an artificial intelligence chip is provided, and the chip includes the data processing device according to any one of the foregoing.
  • an electronic device including the aforementioned artificial intelligence chip.
  • a board card includes: a storage device, an interface device, a control device, and the aforementioned artificial intelligence chip;
  • the artificial intelligence chip is connected to the storage device, the control device, and the interface device respectively;
  • the storage device is used to store data
  • the interface device is used to implement data transmission between the artificial intelligence chip and external equipment
  • the control device is used to monitor the state of the artificial intelligence chip.
  • an electronic device including:
  • a memory for storing processor executable instructions
  • the processor is configured to call instructions stored in the memory to execute the method described in any one of the foregoing.
  • a computer-readable storage medium having computer program instructions stored thereon, wherein the computer program instructions implement the method described in any one of the foregoing when the computer program instructions are executed by a processor .
  • the quantized data is quantized according to the determined quantization parameter to obtain the quantized data, wherein the quantization parameter is based on the statistical result of the corresponding data to be quantized and The data bit width is determined; continue to perform winograd convolution processing according to the quantized data to obtain the quantized winograd convolution result; perform inverse quantization processing on the quantized winograd convolution result to obtain the winograd convolution result. It can improve the accuracy of quantization, save the operation time of winograd convolution and reduce energy consumption.
  • Fig. 1 shows a flowchart of a data processing method according to an embodiment of the present disclosure.
  • Fig. 2 shows a schematic diagram of a symmetric fixed-point number representation according to an embodiment of the present disclosure.
  • Fig. 3 shows a schematic diagram of a fixed-point number representation with an offset introduced according to an embodiment of the present disclosure.
  • Fig. 4a and Fig. 4b are graphs of the variation range of the weight data of the neural network during the training process.
  • Fig. 5 shows a block diagram of a data processing device according to an embodiment of the present disclosure.
  • Fig. 6 shows a structural block diagram of a board according to an embodiment of the present disclosure.
  • FIG. 7 shows a block diagram of an electronic device 800 according to an embodiment of the present disclosure.
  • FIG. 8 shows a block diagram of an electronic device 1900 according to an embodiment of the present disclosure.
  • the term “if” can be interpreted as “when” or “once” or “in response to determination” or “in response to detection” depending on the context.
  • the phrase “if determined” or “if detected [described condition or event]” can be interpreted as meaning “once determined” or “in response to determination” or “once detected [described condition or event]” depending on the context ]” or “in response to detection of [condition or event described]”.
  • the data processing method can be applied to a processor, and the processor can be a general-purpose processor, such as a CPU (Central Processing Unit, central processing unit), or it can be artificial intelligence processing for performing artificial intelligence operations.
  • Device IPU
  • Artificial intelligence operations can include machine learning operations, brain-like operations, and so on. Among them, machine learning operations include neural network operations, k-means operations, support vector machine operations, and so on.
  • the artificial intelligence processor may, for example, include GPU (Graphics Processing Unit), NPU (Neural-Network Processing Unit, neural network processing unit), DSP (Digital Signal Process, digital signal processing unit), field programmable gate array (Field-Programmable Gate Array, FPGA) One or a combination of chips.
  • GPU Graphics Processing Unit
  • NPU Neuro-Network Processing Unit
  • DSP Digital Signal Process, digital signal processing unit
  • field programmable gate array Field-Programmable Gate Array
  • FPGA Field-Programmable Gate Array
  • the present disclosure does not limit the specific types of processors.
  • the processor mentioned in the present disclosure may include multiple processing units, and each processing unit can independently run various tasks assigned to it, such as convolution computing tasks and pooling tasks. Or fully connected tasks, etc.
  • the present disclosure does not limit the processing unit and the tasks run by the processing unit.
  • the processor includes multiple processing units and storage units.
  • the multiple processing units are used to execute instruction sequences, and the storage units are used to store data, and may include random access memory (RAM, Random Access Memory) and register files.
  • RAM random access memory
  • Multiple processing units in the processor can not only share part of the storage space, for example, share part of the RAM storage space and register file, but also have their own storage space at the same time.
  • Winograd convolution is a convolution acceleration implementation method based on polynomial interpolation algorithm. It passes the two inputs of the convolution operation: the neuron and the weight are divided into a certain scale and then the linear transformation (winograd positive transformation) is performed respectively, and then the transformed neuron and the weight are aligned and multiplied, and finally the pair The bit multiplication result is linearly transformed again (winograd inverse transformation) to obtain a convolution result equivalent to the original convolution operation.
  • g represents the weight value
  • G represents the left multiplication positive transformation matrix corresponding to the weight value
  • G T represents the right multiplication positive transformation matrix corresponding to the weight value
  • d represents the input neuron
  • B represents the right multiplication positive transformation matrix corresponding to the input neuron
  • B T represents the left multiplication forward transformation matrix corresponding to the input neuron
  • represents the bitwise multiplication operation
  • A represents the right multiplication and inverse transformation matrix
  • AT represents the left multiplication and inverse transformation matrix.
  • the present disclosure provides a data processing method, device, computer equipment, and storage medium, which can disassemble the multiplication operation in the winograd convolution process into addition operation, thereby saving calculation time, reducing energy consumption, and The data in the winograd convolution process is quantified to further improve the calculation performance.
  • Fig. 1 shows a flowchart of a data processing method according to an embodiment of the present disclosure. As shown in Fig. 1, the method is applied to a processor, and the method includes steps S11 to S13.
  • step S11 the data to be quantized is quantized according to the determined quantization parameter to obtain quantized data, wherein the quantization parameter is determined according to the statistical result of the corresponding data to be quantized and the data bit width.
  • the method may further include: performing statistics on the data to be quantified, and determining the statistical result of each type of data to be quantized; and determining the corresponding quantized data by using the statistical result of each type of data to be quantified and the data bit width.
  • the statistical result may include any one of the following: the maximum absolute value of each type of data to be quantized, half of the distance between the maximum value and the minimum value of each type of data to be quantized One,
  • the quantization parameter may include one or more of a point position parameter, a scaling factor, and an offset amount,
  • the maximum value of the absolute value is the absolute value of the maximum value or the minimum value in each type of data to be quantized.
  • the scaling factor is determined according to the point position parameter, the statistical result, and the data bit width.
  • the offset is determined according to the statistical result of each type of data to be quantized.
  • the point position parameter is determined according to the statistical result and the data bit width.
  • the quantization parameter can be divided into the following six situations.
  • the following formula (1) can be used to quantize the quantized data to obtain quantized data I x :
  • s is the point position parameter
  • I x is the n-bit binary representation value of the data x after quantization
  • F x is the floating point value of the data x before quantization
  • round is the rounding operation performed by rounding. It should be noted that this is not only limited to the rounding operation, but other rounding operation methods can also be used, for example: rounding up, rounding down, and rounding to zero. Replace the round operation in formula (1).
  • n-bit fixed-point numbers can represent the maximum value of floating-point numbers A is 2 s (2 n-1 -1), then n-bit fixed-point numbers can represent the maximum value in the number field of the data to be quantized as 2 s (2 n -1 -1), the n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is -2 s (2 n-1 -1). It can be seen from formula (1) that when the quantization parameter corresponding to the first case is used to quantize the data to be quantized, the quantization interval is 2 s and the quantization interval is denoted as C.
  • the quantized n-bit binary representation value I x of the data x is inversely quantized to obtain the inversely quantized data
  • the dequantized data The data format of is the same as the data format of the corresponding data F x before quantization, and both are floating-point values.
  • the quantization parameter is the first scaling factor f 1 .
  • the following formula (4) can be used to quantify the quantized data to obtain quantized data I x :
  • f 1 is the first scaling factor
  • I x is the n-bit binary representation value after data x is quantized
  • F x is the floating point value before data x is quantized
  • round is the rounding operation performed by rounding. It should be noted that this is not only limited to the rounding operation, but other rounding operation methods can also be used, for example: rounding up, rounding down, and rounding to zero. Replace the round operation in formula (4). It can be seen from equation (4) that when the quantization parameter corresponding to the second case is used to quantize the data to be quantized, the quantization interval is f 1 and the quantization interval is denoted as C.
  • the point position parameter s is a fixed known value and no longer changes.
  • Set 2 s T, and T is a fixed value.
  • the fixed point number of n bits can be used Represents the maximum value A of a floating point number is (2 n-1 -1) ⁇ T. In this case, the maximum value A depends on the data bit width n.
  • the n-bit fixed-point number can indicate that the maximum value in the number field of the data to be quantized is (2 n-1 -1) ⁇ f 1
  • the n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is -(2 n-1 -1) ⁇ f 1
  • 2 s ⁇ f 2 as a whole is used as the first scaling factor f 1 . At this time, it can be regarded as there is no independent point position parameter s.
  • f 2 is the second scaling factor.
  • the n-bit fixed-point number can indicate that the maximum value in the number field of the data to be quantized is (2 n-1 -1) ⁇ f 1
  • the n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is -(2 n-1 -1) ⁇ f 1 .
  • the quantized n-bit binary representation value I x of data x is dequantized to obtain dequantized data
  • the dequantized data The data format of is the same as the data format of the corresponding data F x before quantization, and both are floating-point values.
  • the quantization parameter is the point position parameter s and the second scaling factor f 2 .
  • the following formula (6) can be used to quantize the data to be quantized to obtain the quantized data I x :
  • s is the point position parameter
  • f 2 is the second scaling factor
  • I x is the n-bit binary representation value after the quantization of the data x
  • F x is the floating point value before the quantization of the data x
  • round is the rounding operation performed by rounding. It should be noted that this is not only limited to the rounding operation, but other rounding operation methods can also be used, for example: rounding up, rounding down, and rounding to zero. Replace the round operation in formula (6).
  • the maximum value A in the number field of the data to be quantized that can be represented by a fixed-point number of n bits is 2 s (2 n-1 -1). It can be seen from equation (6) that when the quantization parameter corresponding to the third case is used to quantize the data to be quantized, the quantization interval is 2 s ⁇ f 2 , and the quantization interval is denoted as C.
  • the n-bit fixed-point number can indicate that the maximum value in the number field of the data to be quantized is (2 n-1 -1) ⁇ 2 s ⁇ f 2
  • the n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is -(2 n-1 -1) ⁇ 2 s ⁇ f 2 .
  • the quantized n-bit binary representation value I x of the data x is inversely quantized to obtain the inversely quantized data
  • the dequantized data The data format of is the same as the data format of the corresponding data F x before quantization, and both are floating-point values.
  • FIG. 2 shows a schematic diagram of a symmetric fixed-point number representation according to an embodiment of the present disclosure.
  • the number field of the data to be quantized as shown in Fig. 2 is distributed with "0" as the symmetric center.
  • Z is the maximum absolute value of all floating-point numbers in the number domain of the data to be quantized.
  • A is the maximum floating-point number that can be represented by an n-bit fixed-point number.
  • the conversion of a floating-point number A to a fixed-point number is 2 n-1 -1.
  • A needs to include Z.
  • the floating-point data in the process of neural network operations tends to be normal distribution in a certain interval, but it does not necessarily satisfy the distribution with "0" as the symmetric center.
  • Fig. 3 shows a schematic diagram of a fixed-point number representation with an offset introduced according to an embodiment of the present disclosure.
  • the number field of the data to be quantized is not distributed symmetrically with "0" as the center.
  • Z min is the minimum value of all floating-point numbers in the number field of the data to be quantized
  • Z max is the maximum value of all floating-point numbers in the number field of the data to be quantized.
  • P is the center point between Z min ⁇ Z max , which shifts the number field of the data to be quantized as a whole, so that the number field of the data to be quantized after translation is distributed with "0" as the symmetric center.
  • the maximum absolute value in the number field is Z. It can be seen from Fig. 3 that the offset is the horizontal distance between the "0" point and the "P" point, and this distance is called the offset O. among them,
  • the quantization parameter includes the point position parameter and the offset.
  • the following formula (8) can be used to quantize the data to be quantized to obtain the quantized data I x :
  • s is the point position parameter
  • O is the offset
  • I x is the n-bit binary representation value after the quantization of the data x
  • F x is the floating point value before the quantization of the data x
  • round is the rounding operation performed by rounding. It should be noted that this is not only limited to the rounding operation, but other rounding operation methods can also be used, for example: rounding up, rounding down, and rounding to zero. Replace the round operation in formula (8).
  • n-bit fixed-point numbers can represent the maximum value of floating-point numbers A is 2 s (2 n-1 -1), then n-bit fixed-point numbers can represent the maximum value in the number field of the data to be quantized as 2 s (2 n -1 -1)+O, n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is -2 s (2 n-1 -1)+O. It can be seen from formula (8) that when the quantization parameter corresponding to the fourth case is used to quantize the data to be quantized, the quantization interval is 2 s and the quantization interval is denoted as C.
  • the quantized n-bit binary representation value I x of data x is dequantized to obtain dequantized data
  • the dequantized data The data format of is the same as the data format of the corresponding data F x before quantization, and both are floating-point values.
  • the quantization parameter includes the first scaling factor f 1 and the offset O.
  • the following formula (10) can be used to quantize the quantized data to obtain quantized data I x :
  • f 1 is the first scaling factor
  • O is the offset
  • I x is the n-bit binary representation value after data x is quantized
  • F x is the floating point value before data x is quantized
  • round is the rounding operation performed by rounding.
  • this is not only limited to the rounding operation, but other rounding operation methods can also be used, for example: rounding up, rounding down, and rounding to zero. Replace the round operation in formula (10).
  • the point position parameter s is a fixed known value and no longer changes.
  • Set 2 s T
  • T is a fixed value.
  • the maximum value A of floating-point numbers that can be represented by n-bit fixed-point numbers is (2 n-1 -1) ⁇ T.
  • the maximum value A depends on the data bit width n.
  • the n-bit fixed-point number can indicate that the maximum value in the number field of the data to be quantized is (2 n-1 -1) ⁇ f 1
  • the n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is -(2 n-1 -1) ⁇ f 1 .
  • f 2 is the second scaling factor.
  • the n-bit fixed-point number can indicate that the maximum value in the number field of the data to be quantized is (2 n-1 -1) ⁇ f 1 +O, and the n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is -(2 n -1 -1) ⁇ f 1 +O.
  • the quantized n-bit binary representation value I x of the data x is inversely quantized to obtain the inversely quantized data
  • the dequantized data The data format of is the same as the data format of the corresponding data F x before quantization, and both are floating-point values.
  • the quantization parameter includes the point position parameter, the second scaling factor f 2 and the offset O.
  • the following formula (12) can be used to quantize the quantized data to obtain the quantized data I x :
  • s is the point position parameter
  • the offset is O
  • f 2 is the second scaling factor
  • I x is the n-bit binary representation value after the quantization of the data x
  • F x is the floating point value before the quantization of the data x
  • round is the rounding operation performed by rounding. It should be noted that this is not only limited to the rounding operation, but other rounding operation methods can also be used, for example: rounding up, rounding down, and rounding to zero. Replace the round operation in formula (12).
  • the maximum value A in the number field of the data to be quantized that can be represented by a fixed-point number of n bits is 2 s (2 n-1 -1). It can be seen from equation (12) that when the quantization parameter corresponding to the sixth case is used to quantize the data to be quantized, the quantization interval is 2 s ⁇ f 2 , and the quantization interval is denoted as C.
  • Z can be accurately expressed without loss.
  • f 2 1
  • the n-bit fixed-point number can indicate that the maximum value in the number field of the data to be quantized is (2 n-1 -1) ⁇ 2 s ⁇ f 2 +O
  • the n-bit fixed-point number can indicate that the minimum value in the number field of the data to be quantized is- (2 n-1 -1) ⁇ 2 s ⁇ f 2 +O.
  • the quantized n-bit binary representation value I x of data x is dequantized to obtain dequantized data
  • the dequantized data The data format of is the same as the data format of the corresponding data F x before quantization, and both are floating-point values.
  • the point position parameter and the scaling factor are both related to the data bit width. Different data bit widths result in different point position parameters and scaling factors, thereby affecting the quantization accuracy.
  • Quantization is the process of converting high-precision numbers expressed in the past with 32bit or 64bit into fixed-point numbers that take up less memory space. The process of converting high-precision numbers into fixed-point numbers will cause a certain loss in accuracy. In the training or fine-tuning process, within a certain range of iterations (iterations), using the same data bit width quantization has little effect on the overall accuracy of the neural network operation.
  • the same data bit width quantization cannot meet the accuracy requirements of training or fine-tuning.
  • the data bit width n can be artificially set to a preset value. In the range of different iteration times, call the corresponding data bit width n set in advance.
  • the method may further include:
  • the data bit width is adjusted to determine the quantization parameter using the adjusted data bit width
  • the quantization error is determined according to the quantized data in the corresponding layer and the corresponding data before quantization.
  • adjusting the data bit width according to the quantization error corresponding to the data bit width may include: comparing the quantization error with a threshold value, and adjusting the data bit width according to the comparison result.
  • the threshold may include at least one of the first threshold and the second threshold. The first threshold is greater than the second threshold.
  • the quantization error is compared with the threshold, and the data bits are adjusted according to the comparison result, which may include any of the following:
  • the data bit width remains unchanged.
  • the first threshold and the second threshold may be empirical values, or may be variable hyperparameters. Conventional hyperparameter optimization methods are suitable for both the first threshold and the second threshold, and the hyperparameter optimization scheme will not be repeated here.
  • the data bit width can be adjusted according to a fixed bit length, or according to the difference between the quantization error and the error threshold, the data bit width can be adjusted according to the variable adjustment step, and finally according to The actual needs of the neural network operation process, adjust the data bit width to be longer or shorter.
  • the data bit width n of the current convolutional layer is 16, and the data bit width n is adjusted to 12 according to the quantization error. That is to say, in practical applications, the data bit width n is 12 instead of 16 to meet the accuracy requirements in the neural network operation process, so that the fixed-point operation speed can be greatly improved within the accuracy allowable range. Thereby improving the resource utilization rate of the artificial intelligence processor chip.
  • the method may further include: dequantizing the quantized data to obtain the dequantized data, wherein the data format of the dequantized data is the same as the data format of the corresponding data before quantization; The quantized data and the corresponding inverse quantized data determine the quantization error.
  • the data before quantization may be data to be quantized.
  • the processor may calculate the quantization error according to the data to be quantized and the corresponding inverse quantization data.
  • the processor may determine an error term according to the to-be-quantized data Z and its corresponding inverted quantized data Z (n) , and determine the quantization error according to the error term.
  • the processor may respectively calculate the difference between the data to be quantized Z and the corresponding inverse quantization data Z (n) , obtain m difference values, and use the sum of the m difference values as the error term . After that, the processor can determine the quantization error according to the error term.
  • the specific quantization error can be determined according to the following formula:
  • i is the subscript of the i-th data to be quantized in the data set to be quantized. i is an integer greater than or equal to 1 and less than or equal to m.
  • Fig. 4a and Fig. 4b are graphs of the variation range of the weight data of the neural network during the training process.
  • the abscissa represents the number of iterations
  • the ordinate represents the maximum value of the weight after taking the logarithm.
  • the weight data variation amplitude curve shown in FIG. 4a shows the variation of weight data corresponding to different iterations in the same epoch of any convolutional layer of the neural network.
  • the conv0 layer corresponds to the weight data change amplitude curve A
  • the conv1 layer corresponds to the weight data change amplitude curve B
  • the conv2 layer corresponds to the weight data change amplitude curve C
  • the conv3 layer corresponds to the weight data change amplitude curve D
  • conv4 The layer corresponds to the change range curve e of the weight data. It can be seen from Fig. 4a and Fig. 4b that in the same epoch, in the initial training stage, the weight change range of each iteration is relatively large. In the middle and late stages of training, the weights of each iteration will not change too much.
  • the weight data of the corresponding layer of each generation has similarity within a certain iteration interval.
  • the data bit width used in the quantization of the corresponding layer in the previous iteration can be used.
  • the data used in the quantization of the corresponding layer of the previous generation is used.
  • the bit width quantizes the weight data of the corresponding layer of the current generation, or quantizes the weight data of the current layer based on the preset data bit width n of the current layer to obtain the quantized fixed-point number. Determine the quantization error according to the quantized weight data and the corresponding weight data before quantization.
  • the data bit width used when quantizing the corresponding layer of the previous generation or the preset data bit of the current layer The width is adjusted, and the adjusted data bit width is applied to the quantization of the weight data of the corresponding layer of the current generation.
  • the weight data between each layer of the neural network is independent of each other, and does not have similarity. Because the weight data does not have similarity, the neuron data between each layer is also independent of each other and does not have similarity. Therefore, in the neural network training or fine-tuning process, the data bit width of each layer in each iteration of the neural network is applied to the corresponding layer.
  • the data bit widths corresponding to the neuron data and the gradient data are also the same, which will not be repeated here.
  • the data before quantization is the data to be quantified involved in the weight update iteration process within the target iteration interval.
  • the target iteration interval includes at least one weight update iteration, and the same data bit width is used in the quantization process within the same target iteration interval.
  • the target iteration interval is determined according to the change trend value of the point position parameter of the data to be quantified involved in the weight update iteration process at the pre-determined time point.
  • the target iteration interval is determined according to the change trend value of the point position parameter of the data to be quantified and the change trend value of the data bit width involved in the weight update iteration process at the predicted time point.
  • the pre-determined time point is the time point used to determine whether the data bit width needs to be adjusted, and the pre-determined time point corresponds to the time point when the weight update iteration is completed.
  • the step of determining the target iteration interval may include:
  • the change trend value of the point position parameter is based on the weight corresponding to the current predictive time point.
  • the value of the point position parameter in the iteration process is determined by the sliding average value, or according to the point position parameter in the iteration process of the weight corresponding to the current predictive time point, and the point position parameter in the iteration process of the weight corresponding to the last predictive time point
  • the moving average is determined.
  • the expression of formula (15) is:
  • M is the moving average of the point position parameter s increasing with training iterations.
  • M (t) is the moving average of the point position parameter s corresponding to the t-th predictive time point as the training iteration increases, and M (t) is obtained according to formula (16).
  • s (t) is the point position parameter s corresponding to the t-th predictive time point.
  • M (t-1) is the sliding average value of the point position parameter s corresponding to the t-1th predictive time point
  • is the hyperparameter.
  • diff update1 measures the change trend of the point position parameter s, because the change of the point position parameter s is also reflected in disguised form in the change of the maximum value Z max in the current data to be quantified. The larger the diff update1 is, it indicates that the value range changes drastically, and an update frequency with a shorter interval is required, that is, the target iteration interval is smaller.
  • the target iteration interval is determined according to equation (17).
  • the same data bit width is used in the quantization process within the same target iteration interval, and the data bit width used in the quantization process within different target iteration intervals may be the same or different.
  • I is the target iteration interval.
  • ⁇ and ⁇ are hyperparameters.
  • diff update1 is the change trend value of the point position parameter.
  • the pre-determined time point includes the first pre-determined time point, and the first pre-determined time point is determined according to the target iteration interval. Specifically, at the t-th pre-judgment time point in the training or fine-tuning process, the weight data of the corresponding layer of the current generation is quantized using the data bit width used in the quantization of the corresponding layer of the previous generation to obtain the quantized fixed point number, According to the weight data before quantization and the corresponding weight data before quantization, the quantization error is determined. The quantization error is respectively compared with the first threshold and the second threshold, and the comparison result is used to determine whether to adjust the data bit width used in the quantization of the corresponding layer of the previous generation.
  • the t-th first predictive time point corresponds to the 100th generation, and the data bit width used by the 99th generation is n 1 .
  • the quantization error is confirmed according to the data bit width n 1 , and the quantization error is compared with the first threshold and the second threshold to obtain the comparison result. If it is confirmed according to the comparison result that the data bit width n 1 does not need to be changed, use equation (17) to confirm that the target iteration interval is 8 generations.
  • the 100th generation is the initial iteration within the current target iteration interval, then the 100th to 107th generations are used as The current target iteration interval.
  • each generation still uses the data bit width n 1 used in the previous target iteration interval.
  • the data bit width used in quantization between different target iteration intervals can be the same.
  • the 108th generation in the next target iteration interval is regarded as the t+1 first predictive time point
  • the 101st to 108th generations are regarded as the current
  • the target iteration interval is the 108th generation in the current target iteration interval as the t+1 first predictive time point.
  • the quantization error according to an acknowledgment data bit n the quantization error with a first threshold value, the second threshold value to obtain a comparison result. According to the comparison result, it is determined that the data bit width n 1 needs to be changed to n 2 , and the target iteration interval is confirmed to be 55 generations using equation (17).
  • the 108th to 163rd generations or the 109th to 163rd generations are used as the target iteration interval, and each generation uses the data bit width n 2 when quantizing within the target iteration interval.
  • the data bit width used in quantization between different target iteration intervals can be different.
  • equation (15) is applicable to obtain the change trend value of the point position parameter. If the first predictive time point at the current moment is the initial iteration of the current target iteration interval, then in formula (15), M (t) is the point position parameter corresponding to the time point corresponding to the initial iteration of the current target iteration interval s is the moving average value that increases with the training iteration, s (t) is the point position parameter s corresponding to the time point of the initial iteration of the current target iteration interval, and M (t-1) is the start of the previous target iteration interval The moving average of the point position parameter s corresponding to the corresponding time point of the iteration increases with the training iteration.
  • M (t) is the point position parameter corresponding to the time point corresponding to the last iteration of the current target iteration interval s is the moving average value that increases with the training iteration
  • s (t) is the point position parameter s corresponding to the last iteration of the current target iteration interval
  • M (t-1) is the last target iteration interval
  • the pre-determined time point may also include the second pre-determined time point.
  • the second predictive time point is determined according to the data variation range curve. Based on the data fluctuation range of the big data in the neural network training process, the data fluctuation range curve as shown in Fig. 4a is obtained.
  • the current generation first uses the data bit width n 1 of the previous generation to quantize, and the obtained quantization result determines the corresponding quantization error with the corresponding data before quantization.
  • the quantization error is respectively compared with the first threshold and The second threshold is compared, and the data bit width n 1 is adjusted according to the comparison result to obtain the data bit width n 2 .
  • the data bit width n 2 is used to quantify the weight data to be quantized related to the current generation.
  • the target iteration interval according to formula (17) determines whether to adjust the data bit width and how to adjust, and determine the next target iteration interval according to formula (17) To get the next first prediction time point.
  • the weight data varies greatly before and after each iteration from the start of training to the iteration interval of the T-th generation, the weight data of the corresponding layer of each generation does not have similarity. In order to meet the accuracy problem, the current quantization The data of each layer of the previous generation cannot continue to use the corresponding quantization parameters of the corresponding layer of the previous generation.
  • the data bit width can be adjusted from generation to generation in the previous T generation.
  • the target iteration interval of the previous T generation can be preset in advance according to the law revealed by the data change amplitude curve shown in Figure 4a, that is: according to the data change amplitude curve before T
  • the target iteration interval of the generation is directly preset, and there is no need to confirm through formula (17) that the time point when the corresponding weight update iteration of each generation of the previous T generation is completed is used as the second predictive time point. This makes the resources of the artificial intelligence processor chip more reasonable use.
  • the data variation curve shown in Figure 4a has little variation from the T generation.
  • the quantization parameters are reconfirmed without generations.
  • the current generation corresponds to the previous quantization.
  • the confirmed target iteration interval is 55 generations, this requires that the time point corresponding to the 55th generation from the Tth generation or after T+1 is used as the first predictive time point to determine whether to adjust the data bit width and how to adjust it, and according to Formula (17) determines the next target iteration interval, thereby determining the next first predictive time point, until all algebraic operations in the same period (epoch) are completed. On this basis, after each epoch, adaptive adjustments are made to the data bit width or quantization parameters, and finally the quantized data is used to obtain a neural network whose accuracy meets the expectations.
  • the value of T is determined to be 130 according to the weight data variation range curve shown in FIG. 4a (this value does not correspond to FIG. 4a.
  • the 130th generation in the training process is regarded as the second predictive time point, and the current first predictive time point is the 100th generation in the training process.
  • the formula (17) The target iteration interval is determined to be 35 generations. In the target iteration interval, train to the 130th generation and reach the second predictive time point.
  • the target iteration interval determined in this case is 42 generations. From the 130th generation to the 172nd generation as the target iteration interval, the 135th generation corresponding to the first predictive time point determined when the target iteration interval is 35 generations is within the target iteration interval of 42 generations. In the 135th generation, It is possible to judge whether the data bit width needs to be adjusted and how to adjust it according to formula (17).
  • the second prediction time point is preset in advance according to the data variation curve.
  • the data bit width is directly adjusted according to the quantization error, and the adjusted data bit width is used to quantize the data to be quantized in the current generation.
  • the target iteration interval is obtained according to formula (17) to determine the corresponding first predictive time point, and at each first predictive time point, it is determined whether to adjust the data bit width and how to adjust. In this way, while satisfying the accuracy of floating-point operations required by neural network operations, the resources of the artificial intelligence processor chip are reasonably used, which greatly improves the efficiency of quantization.
  • the step of determining the target iteration interval may include:
  • the pre-judgment time point determine the change trend value of the position parameter of the corresponding point of the data to be quantified and the change trend value of the data bit width during the weight iteration process; among them, the pre-judgment time point is used to determine whether the data bit width needs to be adjusted
  • the predicted time point corresponds to the time point when the weight update iteration is completed;
  • the corresponding quantization error can be used to determine the change trend value of the data bit width according to equation (18).
  • is the hyperparameter
  • diff bit is the quantization error
  • diff update2 is the change trend value of the data bit width.
  • the diff update2 measures the change trend of the data bit width n used in quantization. The larger the diff update2 , the more likely it is to update the fixed-point bit width, which requires a shorter update frequency.
  • the change trend value of the point position parameter can still be obtained according to formula (15), and for M (t) in formula (15), it can be obtained according to formula (16).
  • diff update1 measures the change trend of the point position parameter s, because the change of the point position parameter s is also reflected in disguised form in the change of the maximum value Z max in the current data to be quantified. The larger the diff update1 is, it indicates that the value range changes drastically, and an update frequency with a shorter interval is required, that is, the target iteration interval is smaller.
  • the target iteration interval is determined according to equation (19).
  • the same data bit width is used in the quantization process within the same target iteration interval, and the data bit width used in the quantization process within different target iteration intervals may be the same or different.
  • I is the target iteration interval.
  • ⁇ and ⁇ are hyperparameters.
  • diff update1 is the change trend value of the point position parameter.
  • diff update2 is the change trend value of the data bit width.
  • diff update1 is used to measure the change of the point position parameter s, but the change of the point position parameter s caused by the change of the data bit width n should be ignored. Because this has already reflected the change of data bit width n in diff update2. If this neglected operation is not done in diff update1 , then the target iteration interval I determined according to formula (19) is inaccurate, resulting in too many first prediction time points, and it is easy to do it frequently during training or fine-tuning. Whether the data bit width n is updated and how to update the operation, resulting in the artificial intelligence processor chip's resources are not reasonably used.
  • diff update1 is determined according to M (t) . Assuming that the data bit width corresponding to the t-1th predictive time point is n 1 , the corresponding point position parameter is s 1 , and the moving average of the point position parameter increasing with the training iteration is m 1 . The data to be quantized is quantized by using the data bit width n 1 to obtain the quantized fixed-point number.
  • the data bit width used in the quantization of the t-th predictive time point is n 2 .
  • one of the following two optimization methods can be selected when determining M (t).
  • the first method If the data bit width increases by
  • the data bit width n and the point position parameter s have a great influence on the quantization, and the scaling factor f and the offset O in the quantization parameter have little influence on the quantization. Therefore, regardless of whether the data bit width n changes and the point position parameter s is variable, it is also a very meaningful thing to determine the target iteration interval of the point position parameter s.
  • the process of determining the target iteration interval may include the following steps:
  • the pre-judgment time point is the time point used to judge whether the quantitative parameters need to be adjusted, and the pre-judgment time The point corresponds to the time point when the weight update iteration is completed;
  • the quantization parameter is preferably a point position parameter.
  • step S12 the winograd convolution processing is continued to be performed according to the quantized data to obtain the quantized winograd convolution result.
  • step S13 inverse quantization processing is performed on the quantized winograd convolution result to obtain the winograd convolution result.
  • the winograd convolution processing process includes:
  • the data to be quantized may be any one of the data to be operated, the winograd forward transformation result of the data to be operated, and the result of the bitwise multiplication.
  • the data to be calculated includes at least one of input neurons, weights, and gradients.
  • the data to be quantized, data to be calculated and other data mentioned in the embodiments of the present disclosure may be data that can appear in the actual data processing process, and may correspond to data such as image data, video data, audio data, text data, etc.
  • the data may correspond to data such as image data, video data, audio data, text data, etc.
  • the method provided by the present disclosure is used for scene applications such as image processing, video processing, and audio processing.
  • the data to be calculated as image data can be expressed in the form of NHWC (batch, height, width, channels), N is the number of images, HW is the number of pixels in the height and width directions, and C can be Represents the number of channels, for example, C can represent three channels of RGB (Red, Ggreen, Blue).
  • the data to be quantized can be quantized to speed up the processing speed of winograd convolution.
  • the data to be quantized may be a 32-bit floating point number.
  • the data to be quantized may also be floating-point numbers with other digits, or other data types.
  • quantizing the data to be quantized according to the determined pair of cutoff thresholds to obtain quantized data includes any of the following operations:
  • the winograd positive transformation result of each data in the data to be calculated is used as the data to be quantized for quantization processing
  • the bit multiplication result is used as the data to be quantized for quantization processing.
  • the winograd convolution process may be:
  • the winograd convolution process may be:
  • the winograd positive transformation of the data to be calculated is disassembled into a summation operation, and the calculation is performed to obtain the winograd positive transformation result of the data to be calculated; the determined pair of truncation thresholds are used to quantize the winograd positive transformation result of the data to be calculated, and the quantized winograd positive transformation result is obtained.
  • the winograd positive transformation result of the operation data is performed, and the bitwise multiplication result is obtained; the winograd inverse transform of the bitwise multiplication result is disassembled into a summation operation, and the result is obtained
  • the quantized winograd convolution result is inversely quantized to obtain the winograd convolution result.
  • the winograd convolution process can be:
  • the winograd positive transformation of the data to be calculated is disassembled into a summation operation, and the calculation is performed to obtain the winograd positive transformation result of the data to be calculated; the parity multiplication operation of the winograd positive transformation result of the data to be calculated is performed to obtain the parity multiplication result;
  • the determined pair of truncated thresholds quantize the alignment multiplication result to obtain the quantized alignment multiplication result; the winograd inverse transform of the quantized alignment multiplication result is disassembled into a summation operation, and the quantized winograd convolution result is obtained. Perform inverse quantization processing on the quantized winograd convolution result to obtain the winograd convolution result.
  • the disassembling the winograd positive transformation of the data to be operated into a summation operation, and performing calculation to obtain the winograd positive transformation result of each data in the data to be operated includes:
  • Each data in the data to be calculated is disassembled into multiple first sub-tensors, and the multiple first sub-tensors of each data in the data to be calculated are subjected to winograd forward transformation and summed to obtain The winograd positive transformation result of each data in the data to be calculated,
  • the number of multiple first sub-tensors split from each data is the same as the number of non-zero elements in the corresponding data, and each first sub-tensor has an element corresponding to the corresponding position in the corresponding data.
  • the elements are the same, and all other elements are 0.
  • the input neuron is a 4 ⁇ 4 matrix including 16 elements. Therefore, the data to be calculated can be decomposed into 16 first sub-tensors.
  • the 16 first sub-tensors are:
  • each first sub-tensor is the same as the element at the corresponding position in the data to be calculated, and the other elements are all 0.
  • the element of is the same as the element at the position of the input neuron in the first row and first column, and the other elements are all 0, and the other first subtensors also have the same attributes.
  • the above disassembly methods are only some examples of the present disclosure and do not limit the present disclosure in any way.
  • the number of first subtensors obtained by the disassembly It may be less than the number of elements of the data to be calculated, for example, the number of multiple first subtensors is the same as the number of non-zero elements of the data to be calculated.
  • the winograd positive transformation result of the first sub-tensor corresponding to the first sub-tensor is: the value of the element at the first position in the first sub-tensor Is 1, where the position of the first position in the first sub-tensor is the same as the position of the non-zero element in the first sub-tensor;
  • the winograd positive transformation results of the multiple first subtensors are added to obtain the winograd positive transformation result of the data to be operated.
  • the first-element sub-tensor corresponding to d 00 can be
  • the first sub-tensor is to extract the values of non-zero elements in the first sub-tensor, and the values of non-zero elements can be used as coefficients of the first sub-tensor.
  • the winograd positive transformation result of the first sub-tensor corresponding to the first sub-tensor can be obtained in advance through the following process: For each first sub-tensor, the first sub-tensor corresponding to the first sub-tensor The left side of the sub-tensor is multiplied by the positive transformation, the left-multiplied matrix, and the right is multiplied by the positive transformation, and the right-multiplied matrix is used to obtain the winograd positive transformation result of the first sub-tensor.
  • the form of the corresponding first element sub-tensor is determined, and the corresponding positive transformation left-multiplication matrix and forward transformation right-multiplication matrix are also determined.
  • the winograd positive transformation result of the first sub-tensor can be calculated in advance, and the specific process is as described above.
  • the corresponding winograd positive transformation result of the first sub-tensor is:
  • the winograd positive transformation result of the corresponding first-element sub-tensor is:
  • the matrix multiplication operation can be broken down into an addition operation.
  • the process of calculating the winograd positive transformation result of the first element sub-tensor involves more multiplication operations.
  • the pre-calculated winograd positive transformation results of the first element subtensor of various scales can be stored in In the computing device, in this way, in the actual computing process, it can be directly obtained without repeated computing, thereby shortening computing time and saving computing resources.
  • the value of the non-zero element in the first sub-tensor can be multiplied by the winograd positive transformation result of the corresponding first sub-tensor, then The winograd positive transformation result of the first subtensor can be obtained.
  • the corresponding winograd positive transformation result is:
  • the winograd positive transformation results of all the first sub-tensors are calculated through the above process, and the winograd positive transformation results of multiple first sub-tensors are added to obtain the winograd positive transformation results of the data to be calculated.
  • first sub-tensors are obtained by disassembling the data to be calculated, and the winograd positive transformation result of the first sub-tensor corresponding to the first sub-tensor obtained in advance and the first sub-tensor are obtained.
  • the non-zero element value of a sub-tensor can be summed to obtain the winograd positive transformation result of the data to be operated.
  • the winograd positive transformation result of calculating the weight can be used, and the calculation method of the winograd positive transformation result of the weight can be traditional Matrix multiplication calculation can also refer to the above-mentioned disassembly to calculate the summation operation to obtain the winograd positive transformation result.
  • the bitwise multiplication operation of the winograd positive conversion result of the data to be operated can be continued to obtain the bitwise multiplication result.
  • the bitwise multiplication may refer to the data obtained by multiplying the data at the corresponding positions of the two tensors as the value of the corresponding position in the bitwise multiplication result.
  • the disassembling the winograd inverse transform of the alignment multiplication result into a summation operation to obtain the winograd convolution result may include:
  • the number of the plurality of second sub-tensors is the same as the number of non-zero elements in the result of the alignment multiplication, and each second sub-tensor in the plurality of second sub-tensors has an element and The elements at the corresponding positions in the alignment multiplication result are the same, and other elements are all 0.
  • the result of the alignment multiplication is disassembled into multiple second sub-tensors, for example, it can be disassembled into 16, and the 16 second sub-tensors are:
  • winograd inverse transformation can be performed on the multiple second sub-tensors and summed to obtain the winograd convolution result of the data to be operated.
  • performing winograd inverse transformation on the multiple second sub-tensors and summing them to obtain the winograd convolution result of the data to be operated may include the following process:
  • the second sub-tensor corresponding to the second sub-tensor is: the value of the element at the second position in the second sub-tensor Is 1, where the position of the second position in the second sub-tensor is the same as the position of the non-zero element in the second sub-tensor;
  • the winograd inverse transform results of the multiple second sub-tensors are added to obtain the winograd convolution result of the data to be operated.
  • the method for determining the second meta-sub-tensor corresponding to the second sub-tensor is the same as the method for determining the first meta-sub-tensor above, and will not be repeated here.
  • the winograd inverse transform result of the second sub-tensor is obtained in advance through the following process: For each second sub-tensor, the left side of the second sub-tensor corresponding to the second sub-tensor is multiplied by the inverse transform Multiplying the matrix on the left, multiplying the matrix on the right by the inverse transformation, and multiplying the matrix on the right to obtain the winograd inverse transformation result of the second element subtensor.
  • the form of the corresponding second-element sub-tensor is determined, and the corresponding inverse transform left multiplication matrix and inverse transform right multiplication matrix are also determined. Therefore, the winograd inverse transformation result of the second sub-tensor can be calculated in advance, and the specific process is as described above.
  • the left multiplication matrix of the inverse transformation is a 2 ⁇ 4 matrix, for example:
  • the inverse transformation right multiplication matrix is a 4 ⁇ 2 matrix, for example:
  • the dimension of the inverse transformation matrix can be determined according to the dimension of the input neuron and the dimension of the weight value and the convolution step length.
  • the above is only an example, and the present disclosure is not limited in any way.
  • the inverse transformation matrix is given by Therefore, the matrix multiplication operation of the inverse transformation can be broken down into addition and shift operations. Multiply the inverse transformation matrix by the second-element sub-tensor to obtain the winograd inverse transformation result of the second-element sub-tensor.
  • the element value in the winograd inverse transformation result of the second-element sub-tensor is determined by With other configurations, fractions can be calculated by simple shift operations, which can still save calculation time compared to multiplication operations.
  • the winograd inverse transform result of the second sub-tensor is obtained; multiple second sub-tensors.
  • the specific process of “adding the results of the winograd inverse transform of the quantity to obtain the result of the winograd convolution of the data to be operated” can refer to the above, except that the result of the inverse winograd transform of the second sub-tensor is not completely from 0 to ⁇ 1, but The score can be calculated by a simple shift operation. Compared with the multiplication operation, the present disclosure can still achieve the effects of saving calculation time and reducing energy consumption after disassembling the ordinary inverse transformation process.
  • multiple second sub-tensors are obtained by disassembling the bit-multiplication results, and the winograd inverse transform results of the second-element sub-tensors corresponding to the second sub-tensors obtained in advance and The non-zero element value of the second subtensor can be summed to obtain the winograd convolution result of the data to be operated.
  • the data to be quantized is quantized according to the determined quantization parameter to obtain the quantized data, wherein the quantization parameter is determined according to the statistical result of the corresponding data to be quantized and the data bit width; according to the quantization
  • the subsequent data continues to perform winograd convolution processing to obtain a quantized winograd convolution result; perform inverse quantization processing on the quantized winograd convolution result to obtain a winograd convolution result. It can improve the accuracy of quantization, save the operation time of winograd convolution and reduce energy consumption.
  • steps in the flowchart of FIG. 1 are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order for the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in FIG. 1 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution of these sub-steps or stages The sequence is not necessarily performed sequentially, but may be performed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.
  • Fig. 5 shows a block diagram of a data processing device according to an embodiment of the present disclosure.
  • the device includes: a data quantization module 41, a convolution processing module 42, and an inverse quantization processing module 43.
  • the data quantization module 41 quantizes the data to be quantized according to the determined quantization parameter to obtain quantized data, wherein the quantization parameter is determined according to the statistical result and the data bit width of the corresponding data to be quantized.
  • the convolution processing module 42 continues to perform winograd convolution processing according to the quantized data to obtain a quantized winograd convolution result.
  • the inverse quantization processing module 43 performs inverse quantization processing on the quantized winograd convolution result to obtain the winograd convolution result.
  • the winograd convolution processing process includes: disassembling the winograd positive transformation of the data to be calculated into a summation operation, and performing calculations to obtain the winograd positive of each data in the data to be calculated Transformation result; perform the bitwise multiplication operation between the winograd forward conversion results of the corresponding data in the data to be operated to obtain the bitwise multiplication result; disassemble the winograd inverse transform of the bitwise multiplication result into a summation operation, Obtain the winograd convolution result, wherein the data to be quantized is any one of the data to be operated, the winograd forward transformation result of the data to be operated, and the result of the bitwise multiplication.
  • quantizing the data to be quantized according to the determined quantization parameters to obtain the quantized data includes any of the following operations: before disassembling the winograd positive transformation of the data to be calculated into a summation operation , Quantize the data to be calculated as the data to be quantized; before performing the bit multiplication operation, use the winograd forward transformation result of each data in the data to be calculated as the data to be quantized for quantization; perform the winograd inverse transformation split Before the solution is a summation operation, the bit multiplication result is used as the data to be quantized for quantization processing.
  • the disassembling the winograd forward transformation of the data to be operated into a summation operation, and performing calculation to obtain the winograd forward transformation result of each data in the data to be operated includes: Each data in the data to be calculated is disassembled into multiple first sub-tensors, and the multiple first sub-tensors of each data in the data to be calculated are subjected to winograd forward transformation and summed to obtain the to-be-calculated data.
  • the winograd positive transformation result of each data in the operation data where the number of multiple first sub-tensors split from each data is the same as the number of non-zero elements in the corresponding data, and each first sub-tensor One element in the tensor is the same as the element at the corresponding position in the corresponding data, and the other elements are all 0.
  • the decomposing the winograd inverse transform of the alignment multiplication result into a summation operation to obtain the winograd convolution result includes: decomposing the alignment multiplication result into Multiple second sub-tensors, perform winograd inverse transformation on the multiple second sub-tensors and sum them to obtain the winograd convolution result of the data to be operated; wherein, the value of the multiple second sub-tensors The number is the same as the number of non-zero elements in the alignment multiplication result, and each second sub-tensor in the plurality of second sub-tensors has an element that corresponds to the element at the corresponding position in the alignment multiplication result Same, other elements are 0.
  • the statistical result includes any one of the following: the maximum absolute value of each type of data to be quantized, and one-half of the distance between the maximum value and the minimum value of each type of data to be quantized
  • the quantization parameter includes one or more of a point position parameter, a scaling factor, and an offset, wherein the maximum absolute value is the absolute value of the maximum or minimum value in each type of data to be quantized.
  • the scaling factor is determined according to the point position parameter, the statistical result, and the data bit width.
  • the offset is determined according to the statistical result of each type of data to be quantized.
  • the point position parameter is determined according to the statistical result and the data bit width.
  • the device further includes: a bit width adjustment module, which adjusts the data bit width according to the quantization error corresponding to the data bit width, so as to determine the quantization by using the adjusted data bit width Parameters, wherein the quantization error is determined according to the quantized data in the corresponding layer and the corresponding data before quantization.
  • a bit width adjustment module which adjusts the data bit width according to the quantization error corresponding to the data bit width, so as to determine the quantization by using the adjusted data bit width Parameters, wherein the quantization error is determined according to the quantized data in the corresponding layer and the corresponding data before quantization.
  • the data before quantization is the data to be quantified involved in the weight update iteration process within the target iteration interval; wherein, the target iteration interval includes at least one weight update iteration, and The same data bit width is used in the quantization process within the same target iteration interval.
  • the data to be calculated includes at least one of input neurons, weights, and gradients.
  • the foregoing device embodiments are only illustrative, and the device of the present disclosure may also be implemented in other ways.
  • the division of units/modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation.
  • multiple units, modules or components may be combined or integrated into another system, or some features may be omitted or not implemented.
  • the functional units/modules in the various embodiments of the present disclosure may be integrated into one unit/module, or each unit/module may exist alone physically, or two or more units/modules may exist.
  • the modules are integrated together.
  • the above-mentioned integrated unit/module can be implemented in the form of hardware or software program module.
  • the hardware may be a digital circuit, an analog circuit, and so on.
  • the physical realization of the hardware structure includes but is not limited to transistors, memristors and so on.
  • the artificial intelligence processor may be any appropriate hardware processor, such as CPU, GPU, FPGA, DSP, ASIC, and so on.
  • the storage unit may be any suitable magnetic storage medium or magneto-optical storage medium, such as RRAM (Resistive Random Access Memory), DRAM (Dynamic Random Access Memory), Static random access memory SRAM (Static Random-Access Memory), enhanced dynamic random access memory EDRAM (Enhanced Dynamic Random Access Memory), high-bandwidth memory HBM (High-Bandwidth Memory), hybrid storage cube HMC (Hybrid Memory Cube), etc. Wait.
  • RRAM Resistive Random Access Memory
  • DRAM Dynamic Random Access Memory
  • Static random access memory SRAM Static Random-Access Memory
  • enhanced dynamic random access memory EDRAM Enhanced Dynamic Random Access Memory
  • high-bandwidth memory HBM High-Bandwidth Memory
  • hybrid storage cube HMC Hybrid Memory Cube
  • the integrated unit/module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer readable memory.
  • the technical solution of the present disclosure essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, It includes several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present disclosure.
  • the aforementioned memory includes: U disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
  • an artificial intelligence chip is also disclosed, which includes the above-mentioned data processing device.
  • a board card which includes a storage device, an interface device, a control device, and the above-mentioned artificial intelligence chip; wherein the artificial intelligence chip is related to the storage device and the control device.
  • the interface devices are respectively connected; the storage device is used to store data; the interface device is used to implement data transmission between the artificial intelligence chip and external equipment; the control device is used to The state of the artificial intelligence chip is monitored.
  • Fig. 6 shows a structural block diagram of a board card according to an embodiment of the present disclosure.
  • the board card may include other supporting components in addition to the chip 389 described above.
  • the supporting components include, but are not limited to: a storage device 390, Interface device 391 and control device 392;
  • the storage device 390 is connected to the artificial intelligence chip through a bus for storing data.
  • the storage device may include multiple groups of storage units 393. Each group of the storage unit and the artificial intelligence chip are connected through a bus. It can be understood that each group of the storage units may be DDR SDRAM (English: Double Data Rate SDRAM, double-rate synchronous dynamic random access memory).
  • the storage device may include 4 groups of the storage units. Each group of the storage unit may include a plurality of DDR4 particles (chips).
  • the artificial intelligence chip may include four 72-bit DDR4 controllers. In the 72-bit DDR4 controller, 64 bits are used for data transmission and 8 bits are used for ECC verification. It can be understood that when DDR4-3200 particles are used in each group of the storage units, the theoretical bandwidth of data transmission can reach 25600MB/s.
  • each group of the storage unit includes a plurality of double-rate synchronous dynamic random access memories arranged in parallel.
  • DDR can transmit data twice in one clock cycle.
  • a controller for controlling the DDR is provided in the chip, which is used to control the data transmission and data storage of each storage unit.
  • the interface device is electrically connected with the artificial intelligence chip.
  • the interface device is used to implement data transmission between the artificial intelligence chip and an external device (such as a server or a computer).
  • the interface device may be a standard PCIE interface.
  • the data to be processed is transferred from the server to the chip through a standard PCIE interface to realize data transfer.
  • the interface device may also be other interfaces. The present disclosure does not limit the specific manifestations of the other interfaces mentioned above, as long as the interface unit can realize the switching function.
  • the calculation result of the artificial intelligence chip is still transmitted by the interface device back to an external device (such as a server).
  • the control device is electrically connected with the artificial intelligence chip.
  • the control device is used to monitor the state of the artificial intelligence chip.
  • the artificial intelligence chip and the control device may be electrically connected through an SPI interface.
  • the control device may include a single-chip microcomputer (Micro Controller Unit, MCU).
  • MCU Micro Controller Unit
  • the artificial intelligence chip may include multiple processing chips, multiple processing cores, or multiple processing circuits, and can drive multiple loads. Therefore, the artificial intelligence chip can be in different working states such as multi-load and light-load.
  • the control device can realize the regulation and control of the working states of multiple processing chips, multiple processing and or multiple processing circuits in the artificial intelligence chip.
  • an electronic device which includes the aforementioned artificial intelligence chip.
  • Electronic equipment includes data processing devices, robots, computers, printers, scanners, tablets, smart terminals, mobile phones, driving recorders, navigators, sensors, cameras, servers, cloud servers, cameras, cameras, projectors, watches, headsets , Mobile storage, wearable devices, vehicles, household appliances, and/or medical equipment.
  • the transportation means include airplanes, ships, and/or vehicles;
  • the household appliances include TVs, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, electric lights, gas stoves, and range hoods;
  • the medical equipment includes nuclear magnetic resonance, B-ultrasound and/or electrocardiograph.
  • the embodiments of the present disclosure also provide a computer-readable storage medium on which computer program instructions are stored, and the computer program instructions implement the above-mentioned method when executed by a processor.
  • the computer-readable storage medium may be a non-volatile computer-readable storage medium.
  • An embodiment of the present disclosure also provides an electronic device, including: a processor; a memory for storing executable instructions of the processor; wherein the processor is configured to call the instructions stored in the memory to execute the above method.
  • FIG. 7 shows a block diagram of an electronic device 800 according to an embodiment of the present disclosure.
  • the electronic device 800 may be a mobile phone, a computer, a digital broadcasting terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, and other terminals.
  • the electronic device 800 may include one or more of the following components: a processing component 802, a memory 804, a power supply component 806, a multimedia component 808, an audio component 810, an input/output (I/O) interface 812, and a sensor component 814 , And communication component 816.
  • the processing component 802 generally controls the overall operations of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations.
  • the processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the aforementioned method.
  • the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components.
  • the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
  • the memory 804 is configured to store various types of data to support operations in the electronic device 800. Examples of these data include instructions for any application or method operating on the electronic device 800, contact data, phone book data, messages, pictures, videos, etc.
  • the memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable and Programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
  • SRAM static random access memory
  • EEPROM electrically erasable programmable read-only memory
  • EPROM erasable and Programmable read only memory
  • PROM programmable read only memory
  • ROM read only memory
  • magnetic memory flash memory
  • flash memory magnetic disk or optical disk.
  • the power supply component 806 provides power for various components of the electronic device 800.
  • the power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
  • the multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and the user.
  • the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user.
  • the touch panel includes one or more touch sensors to sense touch, sliding, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure related to the touch or slide operation.
  • the multimedia component 808 includes a front camera and/or a rear camera. When the electronic device 800 is in an operation mode, such as a shooting mode or a video mode, the front camera and/or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have focal length and optical zoom capabilities.
  • the audio component 810 is configured to output and/or input audio signals.
  • the audio component 810 includes a microphone (MIC), and when the electronic device 800 is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal.
  • the received audio signal may be further stored in the memory 804 or transmitted via the communication component 816.
  • the audio component 810 further includes a speaker for outputting audio signals.
  • the I/O interface 812 provides an interface between the processing component 802 and a peripheral interface module.
  • the above-mentioned peripheral interface module may be a keyboard, a click wheel, a button, and the like. These buttons may include, but are not limited to: home button, volume button, start button, and lock button.
  • the sensor component 814 includes one or more sensors for providing the electronic device 800 with various aspects of state evaluation.
  • the sensor component 814 can detect the on/off status of the electronic device 800 and the relative positioning of the components.
  • the component is the display and the keypad of the electronic device 800.
  • the sensor component 814 can also detect the electronic device 800 or the electronic device 800.
  • the position of the component changes, the presence or absence of contact between the user and the electronic device 800, the orientation or acceleration/deceleration of the electronic device 800, and the temperature change of the electronic device 800.
  • the sensor component 814 may include a proximity sensor configured to detect the presence of nearby objects when there is no physical contact.
  • the sensor component 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications.
  • the sensor component 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
  • the communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices.
  • the electronic device 800 can access a wireless network based on a communication standard, such as WiFi, 2G, or 3G, or a combination thereof.
  • the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel.
  • the communication component 816 further includes a near field communication (NFC) module to facilitate short-range communication.
  • the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
  • RFID radio frequency identification
  • IrDA infrared data association
  • UWB ultra-wideband
  • Bluetooth Bluetooth
  • the electronic device 800 may be implemented by one or more application-specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field-available A programmable gate array (FPGA), controller, microcontroller, microprocessor, or other electronic components are implemented to implement the above methods.
  • ASIC application-specific integrated circuits
  • DSP digital signal processors
  • DSPD digital signal processing devices
  • PLD programmable logic devices
  • FPGA field-available A programmable gate array
  • controller microcontroller, microprocessor, or other electronic components are implemented to implement the above methods.
  • a non-volatile computer-readable storage medium such as the memory 804 including computer program instructions, which can be executed by the processor 820 of the electronic device 800 to complete the foregoing method.
  • FIG. 8 shows a block diagram of an electronic device 1900 according to an embodiment of the present disclosure.
  • the electronic device 1900 may be provided as a server.
  • the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as application programs.
  • the application program stored in the memory 1932 may include one or more modules each corresponding to a set of instructions.
  • the processing component 1922 is configured to execute instructions to perform the above-described methods.
  • the electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to the network, and an input output (I/O) interface 1958 .
  • the electronic device 1900 can operate based on an operating system stored in the memory 1932, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM or the like.
  • a non-volatile computer-readable storage medium is also provided, such as the memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to complete the foregoing method.
  • a data processing method comprising:
  • the winograd convolution processing process includes:
  • the data to be quantized is any one of the data to be calculated, the winograd conversion result of the data to be calculated, and the result of the bitwise multiplication.
  • the quantized data is quantized according to the determined quantization parameters to obtain the quantized data, including any of the following operations:
  • the winograd positive transformation result of each data in the data to be calculated is used as the data to be quantized for quantization processing
  • the bit multiplication result is used as the data to be quantized for quantization processing.
  • Clause A4 According to the method described in Clause A2, said disassembling the winograd positive transformation of the data to be operated into a summation operation, and performing calculations to obtain the winograd positive transformation result of each data in the data to be operated, including:
  • Each data in the data to be calculated is disassembled into multiple first sub-tensors, and the multiple first sub-tensors of each data in the data to be calculated are subjected to winograd forward transformation and summed to obtain The winograd positive transformation result of each data in the data to be calculated,
  • the number of multiple first sub-tensors split from each data is the same as the number of non-zero elements in the corresponding data, and each first sub-tensor has an element corresponding to the corresponding position in the corresponding data.
  • the elements are the same, and all other elements are 0.
  • the number of the plurality of second sub-tensors is the same as the number of non-zero elements in the result of the alignment multiplication, and each second sub-tensor in the plurality of second sub-tensors has an element and The elements at the corresponding positions in the alignment multiplication result are the same, and other elements are all 0.
  • Clause A6 The method according to Clause A1, wherein the statistical result includes any one of the following: the maximum value of the absolute value of each type of data to be quantized, the dichotomy of the distance between the maximum value and the minimum value of each type of data to be quantized one,
  • the quantization parameters include one or more of point position parameters, scaling coefficients and offsets,
  • the maximum value of the absolute value is the absolute value of the maximum value or the minimum value in each type of data to be quantized.
  • the offset is determined according to the statistical result of each type of data to be quantified.
  • Clause A10 The method according to Clause A6, the method further comprising:
  • the data bit width is adjusted to determine the quantization parameter using the adjusted data bit width
  • the quantization error is determined according to the quantized data in the corresponding layer and the corresponding data before quantization.
  • the data before quantification is the data to be quantified involved in the weight update iteration process within the target iteration interval;
  • the target iteration interval includes at least one weight update iteration, and the same data bit width is used in the quantization process within the same target iteration interval.
  • Clause A12. The method according to clause A2, wherein the data to be calculated includes at least one of input neurons, weights, and gradients.
  • a data processing device comprising:
  • the data quantization module performs quantization processing on the to-be-quantized data according to the determined quantization parameter to obtain quantized data, wherein the quantization parameter is determined according to the statistical result of the corresponding data to be quantized and the data bit width;
  • the convolution processing module continues to perform winograd convolution processing according to the quantized data to obtain a quantized winograd convolution result
  • the inverse quantization processing module performs inverse quantization processing on the quantized winograd convolution result to obtain the winograd convolution result.
  • the data to be quantized is any one of the data to be calculated, the winograd conversion result of the data to be calculated, and the result of the bitwise multiplication.
  • Clause A15 The device according to Clause A14 performs quantization processing on the quantized data according to the determined quantization parameters to obtain the quantized data, including any of the following operations:
  • the winograd positive transformation result of each data in the data to be calculated is used as the data to be quantized for quantization processing
  • the bit multiplication result is used as the data to be quantized for quantization processing.
  • Each data in the data to be calculated is disassembled into multiple first sub-tensors, and the multiple first sub-tensors of each data in the data to be calculated are subjected to winograd forward transformation and summed to obtain The winograd positive transformation result of each data in the data to be calculated,
  • the number of multiple first sub-tensors split from each data is the same as the number of non-zero elements in the corresponding data, and each first sub-tensor has an element corresponding to the corresponding position in the corresponding data.
  • the elements are the same, and all other elements are 0.
  • the number of the plurality of second sub-tensors is the same as the number of non-zero elements in the result of the alignment multiplication, and each second sub-tensor in the plurality of second sub-tensors has an element and The elements at the corresponding positions in the alignment multiplication result are the same, and other elements are all 0.
  • Clause A18 The device according to clause A13, wherein the statistical result includes any one of the following: the maximum value of the absolute value in each type of data to be quantized, the dichotomy of the distance between the maximum value and the minimum value in each type of data to be quantized one,
  • the quantization parameters include one or more of point position parameters, scaling coefficients and offsets,
  • the maximum value of the absolute value is the absolute value of the maximum value or the minimum value in each type of data to be quantized.
  • the bit width adjustment module adjusts the data bit width according to the quantization error corresponding to the data bit width to determine the quantization parameter using the adjusted data bit width
  • the quantization error is determined according to the quantized data in the corresponding layer and the corresponding data before quantization.
  • Clause A23 The device according to clause A22, wherein the data before quantification is the data to be quantified involved in the weight update iteration process within the target iteration interval;
  • the target iteration interval includes at least one weight update iteration, and the same data bit width is used in the quantization process within the same target iteration interval.
  • Clause A24 The device according to clause A14, wherein the data to be calculated includes at least one of input neurons, weights, and gradients.
  • Clause A26 An electronic device comprising the artificial intelligence chip as described in Clause A25.
  • a board comprising: a storage device, an interface device, a control device, and the artificial intelligence chip as described in Clause A25;
  • the artificial intelligence chip is connected to the storage device, the control device, and the interface device respectively;
  • the storage device is used to store data
  • the interface device is used to implement data transmission between the artificial intelligence chip and external equipment
  • the control device is used to monitor the state of the artificial intelligence chip.
  • the storage device includes: multiple groups of storage units, each group of the storage unit is connected to the artificial intelligence chip through a bus, and the storage unit is: DDR SDRAM;
  • the chip includes: a DDR controller, which is used to control data transmission and data storage of each storage unit;
  • the interface device is: a standard PCIE interface.
  • An electronic device including:
  • a memory for storing processor executable instructions
  • the processor is configured to call instructions stored in the memory to execute the method described in any one of clauses A1 to A12.
  • Clause A30 A computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implement the method described in any one of Clauses A1 to A12.

Abstract

本申请涉及数据处理方法、装置、计算机设备和存储介质。其所公开的板卡包括:存储器件、接口装置和控制器件以及包括数据处理装置的人工智能芯片;其中,人工智能芯片与存储器件、控制器件以及接口装置分别连接;存储器件,用于存储数据;接口装置,用于实现人工智能芯片与外部设备之间的数据传输;控制器件,用于对人工智能芯片的状态进行监控。本申请实施例所提供的数据处理方法、装置、计算机设备和存储介质,可以提高量化的精度,同时节约winograd卷积的运算时间,减少能耗。

Description

数据处理方法、装置、计算机设备和存储介质 技术领域
本公开涉及计算机技术领域,特别是涉及一种数据处理方法、装置、计算机设备和存储介质。
背景技术
在人工智能技术领域,神经网络算法是最近非常流行的一种机器学习算法,在各种领域中都取得了非常好的效果,比如图像识别,语音识别,自然语言处理等。随着神经网络算法的发展,算法的复杂度也越来越高,为了提高识别度,模型的规模也在逐渐增大。用GPU和CPU处理起这些大规模的模型,要花费大量的计算时间,并且耗电量很大。
发明内容
基于此,有必要针对上述技术问题,提供一种能够能够节约计算时间、减少能耗,提高计算精度的数据处理方法、装置、计算机设备和存储介质。
根据本公开的一方面,提供了一种数据处理方法,所述方法包括:
根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;
根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;
对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
根据本公开的另一方面,提供了一种数据处理装置,所述装置包括:
数据量化模块,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;
卷积处理模块,根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;
反量化处理模块,对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
根据本公开的另一方面,提供了一种人工智能芯片,所述芯片包括如前述任意一项所述的数据处理装置。
根据本公开的另一方面,提供了一种电子设备,所述电子设备包括如前述的人工智能芯片。
根据本公开的另一方面,提供了一种板卡,所述板卡包括:存储器件、接口装置和控制器件以及如前述的人工智能芯片;
其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;
所述存储器件,用于存储数据;
所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;
所述控制器件,用于对所述人工智能芯片的状态进行监控。
根据本公开的另一方面,提供了一种电子设备,包括:
处理器;
用于存储处理器可执行指令的存储器;
其中,所述处理器被配置为调用所述存储器存储的指令,以执行前述中任意一项所述的方法。
根据本公开的另一方面,提供了一种计算机可读存储介质,其上存储有计算机程序指令,其特征在于,所述计算机程序指令被处理器执行时实现前述中任意一项所述的方法。
根据本公开的数据处理方法、装置、计算机设备和存储介质,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;根据量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;对量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。可以提高量化的精度的同时,节约winograd卷积的运算时间,减少能耗。
根据下面参考附图对示例性实施例的详细说明,本公开的其它特征及方面将变得清楚。
附图说明
包含在说明书中并且构成说明书的一部分的附图与说明书一起示出了本公开的示例性实施例、特征和方面,并且用于解释本公开的原理。
图1示出根据本公开实施例的数据处理方法的流程图。
图2示出根据本公开实施例的对称的定点数表示的示意图。
图3示出根据本公开实施例的引入偏移量的定点数表示的示意图。
图4a、图4b为训练过程中神经网络的权值数据变动幅度曲线图。
图5示出根据本公开实施例的数据处理装置的框图。
图6示出根据本公开实施例的板卡的结构框图。
图7示出根据本公开实施例的一种电子设备800的框图。
图8示出根据本公开实施例的一种电子设备1900的框图。
具体实施方式
下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本公开一部分实施例,而不是全部的实施例。基于本公开中的实施例,本领域技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。
应当理解,本公开的权利要求、说明书及附图中的术语“第一”、“第二”、“第三”和“第四”等是用于区别不同对象,而不是用于描述特定顺序。本公开的说明书和权利要求书中使用的术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。
还应当理解,在此本公开说明书中所使用的术语仅仅是出于描述特定实施例的目的,而并不意在限定本公开。如在本公开说明书和权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。还应当进一步理解,在本公开说明书和权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。
如在本说明书和权利要求书中所使用的那样,术语“如果”可以依据上下文被解释为“当...时”或“一旦”或“响应于确定”或“响应于检测到”。类似地,短语“如果确定”或“如果检测到[所描述条件或事件]”可以依据上下文被解释为意指“一旦确定”或“响应于确定”或“一旦检测到[所描述条件或事件]”或“响应于检测到[所描述条件或事件]”。
根据本公开实施例的数据处理方法可应用于处理器中,该处理器可以是通用处理器,例如CPU(Central Processing Unit,中央处理器),也可以是用于执行人工智能运算的人工智能处理器(IPU)。人工智能运算可包括机器学习运算,类脑运算等。其中,机器学习运算包括神经网络运算、k-means运算、支持向量机运算等。该人工智能处理器可例如包括GPU(Graphics Processing Unit,图形处理单元)、NPU(Neural-Network Processing Unit,神经网络处理单元)、DSP(Digital Signal Process,数字信号处理单元)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)芯片中的一种或组合。本公开对处理器的具体类型不作限制。
在一种可能的实现方式中,本公开中所提及的处理器可包括多个处理单元,每个处理单元可以独立运行所分配到的各种任务,如:卷积运算任务、池化任务或全连接任务等。本公开对处理单元及处理单元所运行的任务不作限制。
处理器包括多个处理单元以及存储单元,多个处理单元用于执行指令序列,存储单元用于存储数据,可包括随机存储器(RAM,Random Access Memory)和寄存器堆。处理器中的多个处理单元既可共用部分存储空间,例如共用部分RAM存储空间和寄存器堆,又可同时拥有各自的存储空间。
winograd卷积是一种基于多项式插值算法的卷积加速实现方式。它通过对卷积操作的两个输入: 神经元、权值进行一定规模切分后分别进行线性变换(winograd正变换),再将变换后的神经元和权值进行对位乘法,最后对对位乘法结果再次进行线性变换(winograd逆变换)得到与原卷积操作等价的卷积结果。
winograd变换的表达式如下所示:
对于一维的神经元和权值:S=A T((Gg)⊙(B Td))
对于二维的神经元和权值:S=A T((GgG T)⊙(B TdB))A
其中,g表示权值,G表示权值对应的左乘正变换矩阵,G T表示权值对应的右乘正变换矩阵,d表示输入神经元,B表示输入神经元对应的右乘正变换矩阵,B T表示输入神经元对应的左乘正变换矩阵,⊙表示对位乘运算,A表示右乘逆变换矩阵,A T表示左乘逆变换矩阵。对于不同维度的输入神经元,都有与其相对应的B和B T;同样的,对于不同维度的权值,都有与其相对应的G和G T
通过winograd卷积替代原始卷积操作能够带来硬件能效比和运算时间上的较大收益,同时也可以在不增加、或者增加较少的硬件开销的情况下实现更高的神经网络性能。但是,winograd卷积的弊端仍然较为明显,大量的乘法运算在计算过程中仍然消耗较长的运算时间。
为了解决上述技术问题,本公开提供了一种数据处理方法、装置、计算机设备和存储介质,可以将winograd卷积过程中的乘法运算拆解为加法运算,从而节约计算时间、减少能耗,并且对winograd卷积过程中的数据进行量化处理,进一步的提高计算性能。
图1示出根据本公开实施例的数据处理方法的流程图。如图1所示,该方法应用于处理器,该方法包括步骤S11至步骤S13。
在步骤S11中,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的。
在一种可能的实现方式中,该方法还可以包括:对待量化数据进行统计,确定每种待量化数据的统计结果;利用每种待量化数据的统计结果以及数据位宽确定对应量化数据。
在一种可能的实现方式中,所述统计结果可以包括以下任一种:每种待量化数据中的绝对值最大值、每种待量化数据中的最大值和最小值的距离的二分之一,
所述量化参数可以包括点位置参数、缩放系数和偏移量中的一种或多种,
其中,所述绝对值最大值是每种待量化数据中的最大值或最小值的绝对值。
在一种可能的实现方式中,所述缩放系数是根据所述点位置参数、所述统计结果、所述数据位宽确定的。
在一种可能的实现方式中,所述偏移量是根据每种待量化数据的统计结果确定的。
在一种可能的实现方式中,所述点位置参数是根据所述统计结果和所述数据位宽确定的。
在一种可能的实现方式中,量化参数可以分以下六种情况。第一种情况:量化参数是点位置参数s。这种情况下,可以利用如下的公式(1)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110438-appb-000001
其中,s为点位置参数,I x为数据x量化后的n位二进制表示值,F x为数据x量化前的浮点值,round为进行四舍五入的取整运算。需要说明的是,此处不仅仅局限于round这一种取整运算,也可以采用其他的取整运算方法,例如:采用向上取整、向下取整、向零取整等取整运算,替换公式(1)中的round取整运算。此时,用n位定点数可以表示浮点数的最大值A为2 s(2 n-1-1),那么n位定 点数可以表示待量化数据的数域中最大值为2 s(2 n-1-1),n位定点数可以表示待量化数据的数域中最小值为-2 s(2 n-1-1)。由式(1)可知,采用第一种情况对应的量化参数对待量化数据进行量化时,量化间隔为2 s,量化间隔记为C。
设Z为待量化数据的数域中所有浮点数的绝对值最大值,则A需要包含Z,且Z要大于
Figure PCTCN2020110438-appb-000002
因此有如下公式(2)约束:
2 s(2 n-1-1)≥Z>2 s-1(2 n-1-1)    (2)
因此,
Figure PCTCN2020110438-appb-000003
得到
Figure PCTCN2020110438-appb-000004
Figure PCTCN2020110438-appb-000005
根据式(3)对数据x量化后的n位二进制表示值I x进行反量化,获得反量化数据
Figure PCTCN2020110438-appb-000006
其中,所述反量化数据
Figure PCTCN2020110438-appb-000007
的数据格式与对应的量化前的数据F x的数据格式相同,均为浮点值。
Figure PCTCN2020110438-appb-000008
第二种情况:量化参数是第一缩放系数f 1。这种情况下,可以利用如下的公式(4)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110438-appb-000009
其中,f 1为第一缩放系数,I x为数据x量化后的n位二进制表示值,F x为数据x量化前的浮点值,round为进行四舍五入的取整运算。需要说明的是,此处不仅仅局限于round这一种取整运算,也可以采用其他的取整运算方法,例如:采用向上取整、向下取整、向零取整等取整运算,替换公式(4)中的round取整运算。由式(4)可知,采用第二种情况对应的量化参数对待量化数据进行量化时,量化间隔为f 1,量化间隔记为C。
对于第一缩放系数f 1来说,有一种情况,即:点位置参数s为固定已知值,不再发生变化,设2 s=T,T为固定值,那么,用n位定点数可以表示浮点数的最大值A为(2 n-1-1)×T。这种情况下,最大值A取决于数据位宽n。设Z为待量化数据的数域中所有数的绝对值最大值,则
Figure PCTCN2020110438-appb-000010
此时Z=(2 n-1-1)×f 1。n位定点数可以表示待量化数据的数域中最大值为(2 n-1-1)×f 1,n位定点数可以 表示待量化数据的数域中最小值为-(2 n-1-1)×f 1。还有一种情况,在工程应用中,2 s×f 2作为一个整体当做第一缩放系数f 1。此时,就可以当做不存在独立的点位置参数s。其中,f 2为第二缩放系数。设Z为待量化数据的数域中所有数的绝对值最大值,则
Figure PCTCN2020110438-appb-000011
此时Z=(2 n-1-1)×f 1。n位定点数可以表示待量化数据的数域中最大值为(2 n-1-1)×f 1,n位定点数可以表示待量化数据的数域中最小值为-(2 n-1-1)×f 1
根据式(5)对数据x量化后的n位二进制表示值I x进行反量化,获得反量化数据
Figure PCTCN2020110438-appb-000012
其中,所述反量化数据
Figure PCTCN2020110438-appb-000013
的数据格式与对应的量化前的数据F x的数据格式相同,均为浮点值。
Figure PCTCN2020110438-appb-000014
第三种情况:量化参数是点位置参数s和第二缩放系数f 2。这种情况下,可以利用如下的公式(6)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110438-appb-000015
其中,s为点位置参数,f 2为第二缩放系数,
Figure PCTCN2020110438-appb-000016
I x为数据x量化后的n位二进制表示值,F x为数据x量化前的浮点值,round为进行四舍五入的取整运算。需要说明的是,此处不仅仅局限于round这一种取整运算,也可以采用其他的取整运算方法,例如:采用向上取整、向下取整、向零取整等取整运算,替换公式(6)中的round取整运算。用n位定点数可以表示的待量化数据的数域中的最大值A为2 s(2 n-1-1)。由式(6)可知,采用第三种情况对应的量化参数对待量化数据进行量化时,量化间隔为2 s×f 2,量化间隔记为C。
设Z为待量化数据的数域中所有数的绝对值最大值,此时,根据公式(2)可得:
Figure PCTCN2020110438-appb-000017
Figure PCTCN2020110438-appb-000018
Figure PCTCN2020110438-appb-000019
时,根据公式(2),Z可以无损精确表示。当f 2=1时,公式(6)与公式(1),
Figure PCTCN2020110438-appb-000020
n位定点数可以表示待量化数据的数域中最大值为 (2 n-1-1)×2 s×f 2,n位定点数可以表示待量化数据的数域中最小值为-(2 n-1-1)×2 s×f 2
根据式(7)对数据x量化后的n位二进制表示值I x进行反量化,获得反量化数据
Figure PCTCN2020110438-appb-000021
其中,所述反量化数据
Figure PCTCN2020110438-appb-000022
的数据格式与对应的量化前的数据F x的数据格式相同,均为浮点值。
Figure PCTCN2020110438-appb-000023
在本实施例中,图2示出根据本公开实施例的对称的定点数表示的示意图。如图2所示的待量化数据的数域是以“0”为对称中心分布。Z为待量化数据的数域中所有浮点数的绝对值最大值,在图2中,A为n位定点数可以表示的浮点数的最大值,浮点数A转换为定点数是2 n-1-1。为了避免溢出,A需要包含Z。在实际运算中,神经网络运算过程中的浮点数据趋向于某个确定区间的正态分布,但是并不一定满足以“0”为对称中心的分布,这时用定点数表示时,容易出现溢出情况。为了改善这一情况,量化参数中引入偏移量。图3示出根据本公开实施例的引入偏移量的定点数表示的示意图。如图3所示。待量化数据的数域不是以“0”为对称中心分布,Z min是待量化数据的数域中所有浮点数的最小值,Z max是待量化数据的数域中所有浮点数的最大值。P为Z min~Z max之间的中心点,将待量化数据的数域整体偏移,使得平移后的待量化数据的数域以“0”为对称中心分布,平移后的待量化数据的数域中的绝对值最大值为Z。由图3可知,偏移量为“0”点到“P”点之间的水平距离,该距离称为偏移量O。其中,
Figure PCTCN2020110438-appb-000024
基于上述关于偏移量O的描述,出现第四种量化参数的情况。第四种情况:量化参数包括点位置参数和偏移量。这种情况下,可以利用如下的公式(8)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110438-appb-000025
其中,s为点位置参数,O为偏移量,
Figure PCTCN2020110438-appb-000026
I x为数据x量化后的n位二进制表示值,F x为数据x量化前的浮点值,round为进行四舍五入的取整运算。需要说明的是,此处不仅仅局限于round这一种取整运算,也可以采用其他的取整运算方法,例如:采用向上取整、向下取整、向零取整等取整运算,替换公式(8)中的round取整运算。此时,用n位定点数可以表示浮点数的最大值A为2 s(2 n-1-1),那么n位定点数可以表示待量化数据的数域中最大值为2 s(2 n-1-1)+O,n位定点数可以表示待量化数据的数域中最小值为-2 s(2 n-1-1)+O。由式(8)可知,采用第四种情况对应的量化参数对待量化数据进行量化时,量化间隔为2 s,量化间隔记为C。
设Z为待量化数据的数域中所有浮点数的绝对值最大值,
Figure PCTCN2020110438-appb-000027
则A需要包含Z,且Z要大于
Figure PCTCN2020110438-appb-000028
根据公式(2)获得
Figure PCTCN2020110438-appb-000029
进而得到
Figure PCTCN2020110438-appb-000030
根据式(9)对数据x量化后的n位二进制表示值I x进行反量化,获得反量化数据
Figure PCTCN2020110438-appb-000031
其中,所述反量化数据
Figure PCTCN2020110438-appb-000032
的数据格式与对应的量化前的数据F x的数据格式相同,均为浮点值。
Figure PCTCN2020110438-appb-000033
基于上述关于偏移量O的描述,出现第五种量化参数的情况。第五种情况:量化参数包括第一缩放系数f 1和偏移量O。这种情况下,可以利用如下的公式(10)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110438-appb-000034
其中,f 1为第一缩放系数,O为偏移量,I x为数据x量化后的n位二进制表示值,F x为数据x量化前的浮点值,round为进行四舍五入的取整运算。需要说明的是,此处不仅仅局限于round这一种取整运算,也可以采用其他的取整运算方法,例如:采用向上取整、向下取整、向零取整等取整运算,替换公式(10)中的round取整运算。此时,有一种情况,即:点位置参数s为固定已知值,不再发生变化,设2 s=T,T为固定值。那么,用n位定点数可以表示浮点数的最大值A为(2 n-1-1)×T。这种情况下,最大值A取决于数据位宽n。设Z为待量化数据的数域中所有数的绝对值最大值,则
Figure PCTCN2020110438-appb-000035
此时Z=(2 n-1-1)×f 1。n位定点数可以表示待量化数据的数域中最大值为(2 n-1-1)×f 1,n位定点数可以表示待量化数据的数域中最小值为-(2 n-1-1)×f 1。还有一种情况,在工程应用中,2 s×f 2作为一个整体当做第一缩放系数f 1。此时,就可以当做不存在独立的点位置参数s。其中,f 2为第二缩放系数。设Z为待量化数据的数域中所有数的绝对值最大值,则
Figure PCTCN2020110438-appb-000036
此时Z=(2 n-1-1)×f 1。n位定点数可以表示待量化数据的数域中最大值为(2 n-1-1)×f 1+O,n位定点数可以表示待量化数据的数域中最小值为-(2 n-1-1)×f 1+O。
由式(10)可知,采用第五种情况对应的量化参数对待量化数据进行量化时,量化间隔为f 1,量化间隔记为C。
根据式(11)对数据x量化后的n位二进制表示值I x进行反量化,获得反量化数据
Figure PCTCN2020110438-appb-000037
其中,所述反量化数据
Figure PCTCN2020110438-appb-000038
的数据格式与对应的量化前的数据F x的数据格式相同,均为浮点值。
Figure PCTCN2020110438-appb-000039
基于上述关于偏移量O的描述,出现第六种量化参数的情况。第六种情况:量化参数包括点位置参数、第二缩放系数f 2和偏移量O。这种情况下,可以利用如下的公式(12)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110438-appb-000040
其中,s为点位置参数,偏移量O,f 2为第二缩放系数,
Figure PCTCN2020110438-appb-000041
I x为数据x量化后的n位二进制表示值,F x为数据x量化前的浮点值,round为进行四舍五入的取整运算。需要说明的是,此处不仅仅局限于round这一种取整运算,也可以采用其他的取整运算方法,例如:采用向上取整、向下取整、向零取整等取整运算,替换公式(12)中的round取整运算。用n位定点数可以表示的待量化数据的数域中的最大值A为2 s(2 n-1-1)。由式(12)可知,采用第六种情况对应的量化参数对待量化数据进行量化时,量化间隔为2 s×f 2,量化间隔记为C。
设Z为待量化数据的数域中所有数的绝对值最大值,此时,根据公式(2)可得:
Figure PCTCN2020110438-appb-000042
Figure PCTCN2020110438-appb-000043
Figure PCTCN2020110438-appb-000044
时,根据公式(2),Z可以无损精确表示。当f 2=1时,
Figure PCTCN2020110438-appb-000045
n位定点数可以表示待量化数据的数域中最大值为(2 n-1-1)×2 s×f 2+O,n位定点数可以表示待量化数据的数域中最小值为-(2 n-1-1)×2 s×f 2+O。
根据式(13)对数据x量化后的n位二进制表示值I x进行反量化,获得反量化数据
Figure PCTCN2020110438-appb-000046
其中,所述反量化数据
Figure PCTCN2020110438-appb-000047
的数据格式与对应的量化前的数据F x的数据格式相同,均为浮点值。
Figure PCTCN2020110438-appb-000048
在本实施例中,由公式(1)~公式(13)可知,点位置参数和缩放系数均与数据位宽有关。不同的数据位宽,导致点位置参数和缩放系数不同,从而影响量化精度。量化就是将以往用32bit或者64bit表达的高精度数转换成占用较少内存空间的定点数的过程,高精度数转换为定点数的过程就会在精度上引起一定的损失。在训练或微调过程中,在一定的迭代(iterations)的次数范围内,使用相同的数据位宽量化对神经网络运算的总体精度影响不大。超过一定的迭代次数,再使用同一数据位宽量化就无法满足训练或微调对精度的要求。这就需要随着训练或微调的过程对数据位宽n进行调整。简单地,可以人为将数据位宽n设置为预设值。在不同的迭代次数范围内,调用提前设置的对应的数据位宽n。
在一种可能的实现方式中,所述方法还可以包括:
根据所述数据位宽对应的量化误差,对所述数据位宽进行调整,以利用调整后的数据位宽确定量化参数,
其中,所述量化误差是根据对应层中量化后的数据与对应的量化前的数据确定的。
在一种可能的实现方式中,根据数据位宽对应的量化误差,对数据位宽进行调整,可以包括:对量化误差与阈值进行比较,根据比较结果调整数据位宽。其中,阈值可以包括第一阈值和第二阈值中的至少一个。第一阈值大于第二阈值。
在一种可能的实现方式中,对量化误差与阈值进行比较,根据比较结果调整数据位,可以包括以下任一项:
在量化误差大于或等于第一阈值时,增加数据位宽;
在量化误差小于或等于第二阈值时,减少数据位宽;
在量化误差处于第一阈值和第二阈值之间时,数据位宽保持不变。
在该实现方式中,第一阈值和第二阈值可以为经验值,也可以为可变的超参数。常规的超参数的优化方法均适于第一阈值和第二阈值,这里不再赘述超参数的优化方案。
需要强调的是,可以将数据位宽按照固定的位数步长进行调整,也可以根据量化误差与误差阈值之间的差值的不同,按照可变的调整步长调整数据位宽,最终根据神经网络运算过程的实际需要,将数据位宽调整的更长或更短。比如:当前卷积层的数据位宽n为16,根据量化误差将数据位宽n调整为12。也就是说,在实际应用中,数据位宽n取值为12而不必取值为16即可满足神经网络运算过程中对精度的需求,这样在精度允许范围内可以大大提到定点运算速度,从而提升了人工智能处理器芯片的资源利用率。
在一种可能的实现方式中,该方法还可以包括:对量化后的数据进行反量化,获得反量化数据,其中,反量化数据的数据格式与对应的量化前的数据的数据格式相同;根据量化后的数据以及对应的反量化数据确定量化误差。
在一种可能的实现方式中,量化前的数据可以是待量化数据。
在一种可能的实现方式中,处理器可以根据待量化数据及其对应的反量化数据计算获得量化误差。设待量化数据为Z=[z 1,z 2…,z m],该待量化数据对应的反量化数据为Z (n)=[z 1 (n),z 2 (n)…,z m (n)]。处理器可以根据该待量化数据Z及其对应的翻反量化数据Z (n)确定误差项,并根据该误差项确定量化误差。
在一种可能的实现方式中,处理器可以分别计算待量化数据Z与对应的反量化数据Z (n)的差值,获得m个差值,并将该m个差值的和作为误差项。之后,处理器可以根据该误差项确定量化误差。具体的量化误差可以按照如下公式确定:
Figure PCTCN2020110438-appb-000049
其中,i为待量化数据集合中第i个待量化数据的下标。i为大于或等于1、且小于或等于m的整数。
应当理解的是,上述量化误差的确定方式仅是本公开的一个示例,本领域技术人员可以根据实际需要对量化误差的确定方式进行设置,本公开对此不作限制。
对于数据位宽来说,图4a、图4b为训练过程中神经网络的权值数据变动幅度曲线图。在图4a和图4b中,横坐标表示是迭代数,纵坐标表示是权值取对数后的最大值。图4a所示的权值数据变动幅度曲线展示神经网络的任一卷积层同一周期(epoch)内在不同迭代对应的权值数据变动情况。在图4b中,conv0层对应权值数据变动幅度曲线A,conv1层对应权值数据变动幅度曲线B,conv2层对应权值数据变动幅度曲线C,conv3层对应权值数据变动幅度曲线D,conv4层对应权值数据变动幅度曲线e。由图4a和图4b可知,同一个周期(epoch)内,在训练初期,每次迭代权值变化幅度比较大。在训练中后期,每次迭代权值的变化幅度不会太大。此种情况下,在训练中后期,因为每次迭代前后权值数据变化幅度不大,使得每代的对应层的权值数据之间在一定的迭代间隔内具有相似性,在神经网络训练过程中每层涉及的数据量化时可以采用上一迭代时对应层量化时使用的数据位宽。但是,在训练初期,由于每次迭代前后权值数据的变化幅度比较大,为了满足量化所需的浮点运算的精度,在训练初期的每一次迭代,利用上一代对应层量化时采用的数据位宽对当前代的对应层的权值数据进行量化,或者基于当前层预设的数据位宽n对当前层的权值数据进行量化,获得量化后的定点数。根据量化后的权值数据和对应的量化前的权值数据,确定量化误差,根据量化误差与阈值的比较结果,对上一代对应层量化时采用的数据位宽或者当前层预设的数据位宽进行调整,将调整后的数据位宽应用于当前代的对应层的权值数据的量化。进一步地,在训练或微调过程中,神经网络的每层之间的权值数据相互独立,不具备相似性。因权值数据不具备相似性使得每层之间的神经元数据也相互独立,不具备相似性。因此,在神经网络训练或微调过程中,神经网络的每一迭代内的每层的数据位宽应用于对应层。上述以权值数据为例,在神经网络训练或微调过程中,神经元数据和梯度数据分别对应的数据位宽亦如此,此处不再赘述。
在一种可能的实现方式中,所述量化前的数据是在目标迭代间隔内的权值更新迭代过程中涉及的待量化数据。其中,所述目标迭代间隔包括至少一次权值更新迭代,且同一目标迭代间隔内量化过程中采用相同的所述数据位宽。
在一种可能的实现方式中,目标迭代间隔是根据在预判时间点权值更新迭代过程中涉及的待量化数据的点位置参数的变化趋势值确定的。或者目标迭代间隔是根据在预判时间点权值更新迭代过程中涉及的待量化数据的点位置参数的变化趋势值和数据位宽的变化趋势值确定的。其中,预判时间点是用于判断是否需要对数据位宽进行调整的时间点,预判时间点对应权值更新迭代完成时的时间点。
在一种可能的实现方式中,目标迭代间隔的确定步骤可以包括:
在预判时间点,确定权值迭代过程中待量化数据对应点位置参数的变化趋势值;
根据点位置参数的变化趋势值确定对应目标迭代间隔。
在该实现方式中,按照式(15),点位置参数的变化趋势值根据当前预判时间点对应的权值迭代过程中的点位置参数的滑动平均值、上一预判时间点对应的权值迭代过程中的点位置参数的滑动平均值确定,或者根据当前预判时间点对应的权值迭代过程中的点位置参数、上一预判时间点对应的权值迭代过程中的点位置参数的滑动平均值确定。公式(15)的表达式为:
diff update1=|M (t)-M (t-1)|=α|s (t)-M (t-1)|    (15)
式15中,M为点位置参数s随着训练迭代增加的滑动平均值。其中,M (t)为第t个预判时间点对应的点位置参数s随着训练迭代增加的滑动平均值,根据公式(16)获得M (t)。s (t)为第t个预判时间点对应的点位置参数s。M (t-1)为第t-1个预判时间点对应的点位置参数s的滑动平均值,α为超参数。diff update1衡量点位置参数s变化趋势,由于点位置参数s的变化也变相体现在当前待量化数 据中数据最大值Z max的变化情况。diff update1越大,说明数值范围变化剧烈,需要间隔更短的更新频率,即目标迭代间隔更小。
M (t)←α×s (t-1)+(1-α)×M (t-1)     (16)
在该实现方式中,根据式(17)确定目标迭代间隔。对于目标迭代间隔来说,同一目标迭代间隔内量化过程中采用相同的数据位宽,不同目标迭代间隔内量化过程中采用的数据位宽可以相同,也可以不同。
Figure PCTCN2020110438-appb-000050
式(17)中,I为目标迭代间隔。β、γ为超参数。diff update1为点位置参数的变化趋势值。
在该实现方式中,预判时间点包括第一预判时间点,根据目标迭代间隔确定第一预判时间点。具体地,在训练或微调过程中的第t个预判时间点,利用上一代对应层量化时采用的数据位宽对当前代的对应层的权值数据进行量化,获得量化后的定点数,根据量化前的权值数据和对应的量化前的权值数据,确定量化误差。将量化误差分别与第一阈值和第二阈值进行比较,利用比较结果确定是否对上一代对应层量化时采用的数据位宽进行调整。假如:第t个第一预判时间点对应第100代,第99代使用的数据位宽为n 1。在第100代,根据数据位宽n 1确认量化误差,将量化误差与第一阈值、第二阈值进行比较,获得比较结果。如果根据比较结果确认数据位宽n 1无需改变,利用式(17)确认目标迭代间隔为8代,当第100代作为当前目标迭代间隔内的起始迭代,那么第100代~第107代作为当前目标迭代间隔,当第100代作为上一目标迭代间隔的最末迭代,那么第101代~第108代作为当前目标迭代间隔。在当前目标迭代间隔内量化时每代仍然延用上一个目标迭代间隔所使用的数据位宽n 1。这种情况,不同的目标迭代间隔之间量化时所使用的数据位宽可以相同。如果以第100代~第107代作为当前的目标迭代间隔,那么下一个目标迭代间隔内的第108代作为第t+1个第一预判时间点,如果第101代~第108代作为当前的目标迭代间隔,那么当前的目标迭代间隔内的第108代作为第t+1个第一预判时间点。在第t+1个第一预判时间点,根据数据位宽n 1确认量化误差,将量化误差与第一阈值、第二阈值进行比较,获得比较结果。根据比较结果确定数据位宽n 1需要更改为n 2,并利用式(17)确认目标迭代间隔为55代。那么第108代~第163代或者第109代~第163代作为目标迭代间隔,在该目标迭代间隔内量化时每代使用数据位宽n 2。这种情况下,不同的目标迭代间隔之间量化时所使用的数据位宽可以不同。
在该实现方式中,不管第一预判时间点是目标迭代间隔内的起始迭代还是最末迭代,均适于式(15)来获得点位置参数的变化趋势值。如果当前时刻的第一预判时间点为当前目标迭代间隔的起始迭代,那么在式(15)中,M (t)为当前目标迭代间隔的起始迭代对应时间点所对应的点位置参数s随着训练迭代增加的滑动平均值,s (t)为当前目标迭代间隔的起始迭代对应时间点所对应的点位置参数s,M (t-1)为上一目标迭代间隔的起始迭代对应时间点所对应的点位置参数s随着训练迭代增加的滑动平均值。如果当前时刻的第一预判时间点为当前目标迭代间隔的最末迭代,那么在式(15)中,M (t)为当前目标迭代间隔的最末迭代对应时间点所对应的点位置参数s随着训练迭代增加的滑动平均值,s (t)为当前目标迭代间隔的最末迭代对应时间点所对应的点位置参数s,M (t-1)为上一目标迭代间隔的最末迭代对应时间点所对应的点位置参数s随着训练迭代增加的滑动平均值。
在该实现方式中,在包括第一预判时间点的基础上,预判时间点还可以包括第二预判时间点。第二预判时间点是根据数据变动幅度曲线确定的。基于大数据在神经网络训练过程中数据变动幅度情况,获得如图4a所示的数据变动幅度曲线。
以权值数据为例,由图4a所示的数据变动幅度曲线可知,从训练开始到第T代的迭代间隔周期内,每次权值更新时,数据变动幅度非常大。在当前预判时间点,量化时,当前代先利用上一代的数据位宽n 1进行量化,获得的量化结果与对应的量化前的数据确定对应的量化误差,量化误差分别与第一阈值、第二阈值进行比较,根据比较结果对数据位宽n 1进行调整,获得数据位宽n 2。利用数据位宽n 2对当前代涉及的待量化权值数据进行量化。然后根据式(17)确定目标迭代间隔,从而确定第一预判时间点,在第一预判时间点再判断是否调整数据位宽以及如何调整,并根据公式(17)确定下一目标迭代间隔来获得下一个第一预判时间点。由于训练开始到第T代的迭代间隔周期内,每一次迭代前后权值数据变化幅度非常大,使得每代的对应层的权值数据之间不具有相似性,为了满足精度问题,量化时当前代的每层的数据不能延用上一代的对应层的对应量化参数,在前T代可以代代调整数据位宽,此时,量化时前T代中每代使用的数据位宽均不同,目标迭代间隔为1代。为了人工智能处理器芯片的资源达到最优化利用,前T代的目标迭代间隔可以根据图4a所示的数据变动幅度曲线图所揭示的规律提前预设好,即:根据数据变动幅度曲线前T代的目标迭代间隔直接预设,无需经过公式(17)确认前T代的每代对应的权值更新迭代完成时的时间点作为第二预判时间点。从而使得人工智能处理器芯片的资源更为合理的利用。图4a所示的数据变动幅度曲线从第T代开始变动幅度不大,在训练的中后期不用代代都重新确认量化参数,在第T代或者第T+1代,利用当前代对应量化前的数据以及量化后的数据确定量化误差,根据量化误差确定对数据位宽是否需要调整以及如何调整,还要根据公式(17)确定目标迭代间隔。如果确认的目标迭代间隔为55代,这就要求从第T代或第T+1之后隔55代对应的时间点作为第一预判时间点再判断是否调整数据位宽以及如何调整,并根据公式(17)确定下一目标迭代间隔,从而确定下一个第一预判时间点,直至同一周期(epoch)内所有代运算完成。在此基础上,在每个周期(epoch)之后,再对数据位宽或量化参数做适应性调整,最终使用量化后的数据获得精度符合预期的神经网络。
在该实现方式中,假如:根据图4a所示的权值数据变动幅度曲线图确定T取值为130(这个数值与图4a不对应,为方便描述,仅仅是假设T取值为130,不限于在假设值。),那么训练过程中的第130代作为第二预判时间点,当前的第一预判时间点为训练过程中的第100代,在第100代,经公式(17)确定目标迭代间隔为35代。在该目标迭代间隔内,训练至第130代,到达第二预判时间点,此时就要在第130代对应的时间点确定对数据位宽是否需要调整以及如何调整,还要根据公式(17)确定目标迭代间隔。假如该情况下确定的目标迭代间隔为42代。就要从第130代起至第172代作为目标迭代间隔,目标迭代间隔为35代时确定的第一预判时间点对应的第135代处于目标迭代间隔为42代内,在第135代,可以再根据公式(17)判断是否需要调整数据位宽以及如何调整。也可以不在第135代做评估预判,直接到第172代再执行是否需要调整数据位宽的评估以及如何调整。总之,是否在第135代进行评估和预判均适于本公开所提供的技术方案。
综上,根据数据变动幅度曲线提前预设第二预判时间点,在训练或微调的初期,无需花费人工智能处理器芯片的资源来确定目的迭代间隔,在预设好的第二预判时间点上直接根据量化误差来调整数据位宽,并利用调整好的数据位宽来量化当前代涉及的待量化数据。在训练或微调的中后期,根据公式(17)获得目标迭代间隔,从而确定对应的第一预判时间点,在每个第一预判时间点上确定是否调整数据位宽以及如何调整。这样在能够满足神经网络运算所需的浮点运算的精度的同时合理利用人工智能处理器芯片的资源,大大提高了量化时的效率。
在一种可能的实现方式中,为了获得更准确的数据位宽的目标迭代间隔,不仅仅根据点位置参数的变化趋势值,可以同时考虑点位置参数的变化趋势值和数据位宽的变化趋势值。目标迭代间隔的确定步骤可以包括:
在预判时间点,确定权值迭代过程中待量化数据对应点位置参数的变化趋势值、数据位宽的变化趋势值;其中,预判时间点是用于判断是否需要对数据位宽进行调整的时间点,预判时间点对应权值 更新迭代完成时的时间点;
根据点位置参数的变化趋势值和数据位宽的变化趋势值确定对应目标迭代间隔。
在该实现方式中,可以根据式(18)来利用对应量化误差确定数据位宽的变化趋势值。
Figure PCTCN2020110438-appb-000051
式(19)中,δ为超参数,diff bit为量化误差;diff update2为数据位宽的变化趋势值。diff update2衡量量化时采用的数据位宽n的变化趋势,diff update2越大越有可能需要更新定点的位宽,需要间隔更短的更新频率。
在该实现方式中,点位置参数的变化趋势值仍然可根据式(15)获得,对于式(15)中的M (t)根据公式(16)获得。diff update1衡量点位置参数s变化趋势,由于点位置参数s的变化也变相体现在当前待量化数据中数据最大值Z max的变化情况。diff update1越大,说明数值范围变化剧烈,需要间隔更短的更新频率,即目标迭代间隔更小。
在该实现方式中,根据式(19)确定目标迭代间隔。对于目标迭代间隔来说,同一目标迭代间隔内量化过程中采用相同的数据位宽,不同目标迭代间隔内量化过程中采用的数据位宽可以相同,也可以不同。
Figure PCTCN2020110438-appb-000052
式(19)中,I为目标迭代间隔。β、γ为超参数。diff update1为点位置参数的变化趋势值。diff update2为数据位宽的变化趋势值。
在该实现方式中,diff update1是用来衡量点位置参数s的变化情况,但是由数据位宽n的变化而导致的点位置参数s的变化是要忽略掉的。因为这已经在diff update2中体现过了数据位宽n的变化。如果在diff update1中不做这个忽略的操作,那么根据式(19)确定的目标迭代间隔I是不准确的,造成第一预判时间点过多,在训练或微调过程中,易频繁的做数据位宽n是否更新以及如何更新的操作,从而造成人工智能处理器芯片的资源没有合理利用。
在该实现方式中,diff update1根据M (t)确定。假设第t-1个预判时间点对应的数据位宽为n 1,对应的点位置参数为s 1,点位置参数随着训练迭代增加的滑动平均值为m 1。利用数据位宽n 1对待量化数据进行量化,获得量化后的定点数。根据量化前的数据和对应的量化后的数据,确定量化误差diff bit,根据量化误差diff bit与阈值的比较结果,将数据位宽n 1调整为n 2,数据位宽调整了|n 1-n 2|位,第t个预判时间点量化时使用的数据位宽为n 2。为了忽略由数据位宽的变化而导致的点位置参数的变化, 在确定M (t)时可以选出下述两种优化方式中的其中一种即可。第一种方式:如果数据位宽增加了|n 1-n 2|位,则s (t-1)取值为s 1-|n 1-n 2|,M (t-1)取值为m 1-|n 1-n 2|,将s (t-1)、M (t-1)代入公式(16)中,获得M (t),即为第t个预判时间点对应的点位置参数随着训练迭代增加的滑动平均值。如果数据位宽减少了|n 1-n 2|位,则s (t-1)取值为s 1+|n 1-n 2|,M (t-1)取值为m 1+|n 1-n 2|,将s (t-1)、M (t-1)代入公式(16)中,获得M (t),即为第t个预判时间点对应的点位置参数随着训练迭代增加的滑动平均值。第二种方式:不管数据位宽是增加了|n 1-n 2|位还是减少了|n 1-n 2|,s (t-1)取值为s 1,M (t-1)取值为m 1,将s (t-1)、M (t-1)代入公式(16)中,获得M (t)。在数据位宽增加|n 1-n 2|位时,将M (t)减去|n 1-n 2|,在数据位宽减少|n 1-n 2|位时,将M (t)加上|n 1-n 2|,结果作为第t个预判时间点对应的点位置参数随着训练迭代增加的滑动平均值。这两种方式是等价的,均可以忽略由数据位宽的变化而导致的点位置参数的变化,获得更为精准的目标迭代间隔,从而提高人工智能处理器芯片的资源利用率。
在实际应用中,数据位宽n和点位置参数s对量化影响很大,量化参数中的缩放系数f以及偏移量O对量化影响不大。所以,不管数据位宽n是否发生变化、点位置参数s可变的情况下,确定点位置参数s的目标迭代间隔也是一件非常有意义的事情。
在一种可能的实现方式中,确定目标迭代间隔的过程可以包括以下步骤:
在预判时间点,确定权值迭代过程中涉及的待量化数据对应点位置参数的变化趋势值;其中,预判时间点是用于判断是否需要对量化参数进行调整的时间点,预判时间点对应权值更新迭代完成时的时间点;
根据点位置参数的变化趋势值确定对应目标迭代间隔。
在该实现方式中,量化参数优选为点位置参数。
在步骤S12中,根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果。
在步骤S13中,对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
在一种可能的实现方式中,所述winograd卷积处理过程,包括:
将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果;
执行所述待运算数据中对应数据的winograd正变换结果之间的对位乘操作,得到对位乘结果;
将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,
其中,所述待量化数据可以为所述待运算数据、所述待运算数据的winograd正变换结果和所述对位乘结果中的任一种。
在一种可能的实现方式中,所述待运算数据包括输入神经元、权值和梯度中的至少一种。
在本公开实施例中所提及的待量化数据、待运算数据等数据可以是实际数据处理过程中所能够出现的数据,可以是与图像数据、视频数据、音频数据、文本数据等数据相对应的数据。例如,利用本公开所提供的方法进行图像处理、视频处理、音频处理等场景的应用。以待运算数据为图像数据为例,待运算数据可以表示为NHWC(batch,height,width,channels)的形式,N表示图像的数量,HW分别表示在高度和宽度方向的像素个数,C可以表示通道数,例如,C可以表示RGB(Red,Ggreen,Blue)三个通道,上述表示方式仅为本公开的一个示例,本公开不限于此。需要说明的是,上述方法可以应 用于任何可以量化、进行winograd卷积运算处理的数据,本领域技术人员可以根据实际需要对数据的类型及其对应的应用场景进行设置,本公开对此不作限制。
举例来说,可以对待量化数据进行量化,从而加快winograd卷积的处理速度。在一些实施例中,待量化数据可以为32位的浮点数。备选地,待量化的数据也可以为其他位数的浮点数,或者其他的数据类型。
在一种可能的实现方式中,根据确定出的所述一对截断阈值对所述待量化数据进行量化处理,得到量化后的数据,包括以下任一操作:
在将待运算数据的winograd正变换拆解为求和运算之前,将所述待运算数据作为待量化数据进行量化处理;
在进行对位乘操作之前,将待运算数据中每个数据的winograd正变换结果作为待量化数据进行量化处理;
在进行winograd逆变换拆解为求和运算之前,将所述对位乘结果作为待量化数据进行量化处理。
示例性的,待量化数据为待运算数据,则winograd卷积过程可以为:
采用确定的一对截断阈值量化待运算数据,得到量化后的待运算数据;将量化后的待运算数据的winograd正变换拆解为求和运算,并进行计算得到量化后的待运算数据的winograd正变换结果;执行量化后的待运算数据的winograd正变换结果的对位乘操作,得到对位乘结果;将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述量化后的winograd卷积结果,对该量化后的winograd卷积结果进行反量化处理,得到winograd卷积结果。
示例性的,待量化数据为待运算数据的winograd正变换结果,则winograd卷积过程可以为:
将待运算数据的winograd正变换拆解为求和运算,并进行计算得到待运算数据的winograd正变换结果;采用确定的一对截断阈值量化待运算数据的winograd正变换结果,得到量化后的待运算数据的winograd正变换结果;执行量化后的待运算数据的winograd正变换结果的对位乘操作,得到对位乘结果;将对对位乘结果的winograd逆变换拆解为求和运算,得到所述量化后的winograd卷积结果,对该量化后的winograd卷积结果进行反量化处理,得到winograd卷积结果。
示例性的,待量化数据为对位乘结果,则winograd卷积过程可以为:
将待运算数据的winograd正变换拆解为求和运算,并进行计算得到待运算数据的winograd正变换结果;执行待运算数据的winograd正变换结果的对位乘操作,得到对位乘结果;采用确定的一对截断阈值量化对位乘结果,得到量化后的对位乘结果;将对量化后的对位乘结果的winograd逆变换拆解为求和运算,得到量化后的winograd卷积结果。对该量化后的winograd卷积结果进行反量化处理,得到winograd卷积结果。
在一种可能的实现方式中,所述将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果,包括:
将所述待运算数据中的每个数据分别拆解为多个第一子张量,对所述待运算数据中的每个数据的多个第一子张量进行winograd正变换并求和得到所述待运算数据中每个数据的winograd正变换结果,
其中,每个数据拆分出的多个第一子张量的个数与对应的数据中不为0元素的个数相同,每个第一子张量中有一个元素与对应数据中的对应位置的元素相同、其他元素均为0。
举例来说,假设输入神经元表示为:
Figure PCTCN2020110438-appb-000053
输入神经元为4×4的矩阵,包括16个元素,因此,可以将待运算数据拆解为16个第一子张量。
那么,按照本公开的拆解方式,16个第一子张量分别为:
Figure PCTCN2020110438-appb-000054
每个第一子张量中有一个元素与所述待运算数据中的对应位置的元素相同、其他元素均为0是指:以第一子张量d 00为例,在第一行第一列位置的元素与输入神经元在第一行第一列的位置的元素相同,其他元素都为0,其他第一子张量也有相同的属性。
需要说明的是,以上拆解方式仅仅是本公开的一些示例,不以任何方式限制本公开,例如,如果待运算数据中具有值为0的元素,拆解得到的第一子张量的数量可以少于待运算数据的元素的个数,例如,多个第一子张量的个数与所述待运算数据的不为0的元素的个数相同。
在一种可能的实现方式中,对所述待运算数据中的每个数据的多个第一子张量进行winograd正变换并求和得到所述待运算数据中每个数据的winograd正变换结果,可以包括:
获取第一子张量对应的第一元子张量的winograd正变换结果;其中,第一子张量对应的第一元子张量为:在第一元子张量中第一位置的元素的值为1,其中,第一位置在第一元子张量中所处的位置与第一子张量中的非0元素所处的位置相同;
将第一子张量中不为0的元素值作为系数乘以对应的第一元子张量的winograd正变换结果,得到第一子张量的winograd正变换结果;
将多个第一子张量的winograd正变换结果相加得到所述待运算数据的winograd正变换结果。
仍然以第一子张量d 00为例,d 00对应的第一元子张量可以为
Figure PCTCN2020110438-appb-000055
也就是说,第一元子张量是将第一子张量中的非0元素值提取出来,非0元素的值可以作为第一元子张量的系数。
其中,第一子张量对应的第一元子张量的winograd正变换结果可以是通过以下过程预先得到的:对于每一个第一子张量,将该第一子张量对应的第一元子张量左边乘以正变换左乘矩阵、右边乘以正变换右乘矩阵得到第一元子张量的winograd正变换结果。
对于不同尺寸的矩阵,对应的第一元子张量的形式是确定的,对应的正变换左乘矩阵和正变换右乘矩阵也是确定的。
因此,可以预先计算出第一元子张量的winograd正变换结果,具体过程如上所述。举例来说,仍然以d 00为例,其对应的第一元子张量的winograd正变换结果为:
Figure PCTCN2020110438-appb-000056
再比如,以d 01为例,其对应的第一元子张量的winograd正变换结果为:
Figure PCTCN2020110438-appb-000057
由于正变换左乘矩阵和正变换右乘矩阵的元素值都是0、±1,第一元子张量的元素值为0或1,第一元子张量的winograd正变换结果中的元素也是0、±1。因此,可以将矩阵乘操作拆解为加法操作。
计算第一元子张量的winograd正变换结果的过程涉及较多的乘法运算,通过本公开的方式,可以将预先计算好的各种规模的第一元子张量的winograd正变换结果保存在运算装置中,这样,在实际的运算过程中,可以直接获取,而不需要重复运算,从而缩短计算时间、节约计算资源。
在获得第一子张量对应的第一元子张量的winograd正变换结果,可以将第一子张量中不为0的元 素值乘以对应的第一元子张量的winograd正变换结果,就可以得到第一子张量的winograd正变换结果。举例来说,仍然以d 00为例,其对应的winograd正变换结果为:
Figure PCTCN2020110438-appb-000058
再比如,以d 01为例,d 01的winograd正变换结果为
Figure PCTCN2020110438-appb-000059
通过以上过程计算得到所有第一子张量的winograd正变换结果,将多个第一子张量的winograd正变换结果相加,即可得到所述待运算数据的winograd正变换结果。
Figure PCTCN2020110438-appb-000060
Figure PCTCN2020110438-appb-000061
由于转换得到的第一元子张量的winograd正变换结果中的元素也是0、±1,因此,上述等式(20)、(21)右侧仅涉及求和运算。
根据本公开上述实施方式可知,通过将待运算数据进行拆解得到多个第一子张量,根据预先计算得到的第一子张量对应的第一元子张量的winograd正变换结果以及第一子张量的非0元素值即可进行求和运算得到待运算数据的winograd正变换结果。
在采用上文提到的拆解为求和运算得到输入神经元的winograd正变换结果后,可以采用计算权值的winograd正变换结果,其中权值的winograd正变换结果的计算方式可以采用传统的矩阵乘法计算,也可以参照上文提到的拆解为求和运算进行计算得到winograd正变换结果。
在得到待运算数据(输入神经元、权值、梯度)的winograd正变换结果后,可以继续执行待运算数据的winograd正变换结果的对位乘操作,得到对位乘结果。其中,对位乘可以是指对两个张量对应位置的数据相乘得到的数据作为对位乘结果中相应位置的值。
假设输入神经元的winograd正变换结果B Td 4×4B可以表示为:
Figure PCTCN2020110438-appb-000062
权值的winograd正变换结果
Figure PCTCN2020110438-appb-000063
可以表示为:
Figure PCTCN2020110438-appb-000064
那么对位乘结果可以为:
Figure PCTCN2020110438-appb-000065
待运算数据的winograd卷积结果可以表示为S 4×4=A T(G 4×4⊙D 4×4)A,本公开的从功能处理单元可以将A T(G 4×4⊙D 4×4)A拆解为求和运算,并进行计算得到所述待运算数据的winograd卷积结果,从而可以进一步节约计算时间、减少能耗。
在一种可能的实现方式中,所述将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,可以包括:
将所述对位乘结果拆解为多个第二子张量,对所述多个第二子张量进行winograd逆变换并求和,得到所述待运算数据的winograd卷积结果;
其中,所述多个第二子张量的个数与所述对位乘结果中不为0元素的个数相同,所述多个第二子张量中的每个第二子张量中有一个元素与所述对位乘结果中的对应位置的元素相同、其他元素均为0。
假设对位乘结果为:
Figure PCTCN2020110438-appb-000066
将对位乘结果拆解为多个第二子张量,例如可以拆解为16个,16个第二子张量分别为:
Figure PCTCN2020110438-appb-000067
在拆解完后,可以对所述多个第二子张量进行winograd逆变换并求和得到所述待运算数据的winograd卷积结果。
在一种可能的实现方式中,对所述多个第二子张量进行winograd逆变换并求和得到所述待运算数据的winograd卷积结果,可以包括以下过程:
获取第二子张量对应的第二元子张量的winograd逆变换结果;其中,第二子张量对应的第二元子张量为:在第二元子张量中第二位置的元素的值为1,其中,第二位置在第二元子张量中所处的位置与第二子张量中的非0元素所处的位置相同;
将第二子张量中不为0的元素值作为系数乘以对应的第二元子张量的winograd逆变换结果,得到第二子张量的winograd逆变换结果;
将多个第二子张量的winograd逆变换结果相加得到所述待运算数据的winograd卷积结果。
第二子张量对应的第二元子张量确定的方式和上文中第一元子张量确定的方式相同,不再赘述。其中,第二元子张量的winograd逆变换结果是通过以下过程预先得到的:对于每一个第二子张量,将该第二子张量对应的第二元子张量左边乘以逆变换左乘矩阵、右边乘以逆变换右乘矩阵得到第二元子张量的winograd逆变换结果。
对于不同尺寸的矩阵,对应的第二元子张量的形式是确定的,对应的逆变换左乘矩阵和逆变换右乘矩阵也是确定的。因此,可以预先计算出第二元子张量的winograd逆变换结果,具体过程如上所述。对于本文上述列举的示例,逆变换左乘矩阵为2×4的矩阵,例如可以为:
Figure PCTCN2020110438-appb-000068
逆变换右乘矩阵为4×2的矩阵,例如可以为:
Figure PCTCN2020110438-appb-000069
逆变换矩阵的维度可以根据输入神经元的维度以及权值的维度和卷积步长确定,上文仅仅是一个示例,不以任何方式限制本公开。
逆变换矩阵由
Figure PCTCN2020110438-appb-000070
构成,因此逆变换的矩阵乘操作可以拆解为加法和移位操作实现。将逆变换矩阵乘以第二元子张量即可得到第二元子张量的winograd逆变换结果,第二元子张量的winograd逆 变换结果内的元素值由
Figure PCTCN2020110438-appb-000071
等构成,分数可以通过简单的移位操作计算,相比于乘法操作仍然可以节省计算时间。
对于“将第二子张量中不为0的元素值作为系数乘以对应的第二元子张量的winograd逆变换结果,得到第二子张量的winograd逆变换结果;将多个第二子张量的winograd逆变换结果相加得到所述待运算数据的winograd卷积结果”的具体过程可以参照上文,只不过第二元子张量的winograd逆变换结果不完全由0、±1,但分数可以通过简单的移位操作计算,相比于乘法操作,本公开将普通的逆变换过程拆解后仍然可以实现节约计算时间、减少能耗的效果。
根据本公开上述实施方式可知,通过将对位乘结果进行拆解得到多个第二子张量,根据预先计算得到的第二子张量对应的第二元子张量的winograd逆变换结果以及第二子张量的非0元素值即可进行求和运算得到待运算数据的winograd卷积结果。
根据本公开的数据处理方法,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;根据量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;对量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。可以提高量化的精度的同时,节约winograd卷积的运算时间,减少能耗。
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本公开并不受所描述的动作顺序的限制,因为依据本公开,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于可选实施例,所涉及的动作和模块并不一定是本公开所必须的。
进一步需要说明的是,虽然图1的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图1中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些子步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。
图5示出根据本公开实施例的数据处理装置的框图。如图5所示,该装置包括:数据量化模块41、卷积处理模块42和反量化处理模块43。数据量化模块41,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的。卷积处理模块42,根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果。反量化处理模块43,对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
在一种可能的实现方式中,所述winograd卷积处理过程,包括:将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果;执行所述待运算数据中对应数据的winograd正变换结果之间的对位乘操作,得到对位乘结果;将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,其中,所述待量化数据为所述待运算数据、所述待运算数据的winograd正变换结果和所述对位乘结果中的任一种。
在一种可能的实现方式中,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,包括以下任一操作:在将待运算数据的winograd正变换拆解为求和运算之前,将所述待运算数据作为待量化数据进行量化处理;在进行对位乘操作之前,将待运算数据中每个数据的winograd正变换结果作为待量化数据进行量化处理;在进行winograd逆变换拆解为求和运算之前,将所述对位乘结果作为待量化数据进行量化处理。
在一种可能的实现方式中,所述将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果,包括:将所述待运算数据中的每个数据分别拆解为多个第一子张量,对所述待运算数据中的每个数据的多个第一子张量进行winograd正变换并求和 得到所述待运算数据中每个数据的winograd正变换结果,其中,每个数据拆分出的多个第一子张量的个数与对应的数据中不为0元素的个数相同,每个第一子张量中有一个元素与对应数据中的对应位置的元素相同、其他元素均为0。
在一种可能的实现方式中,所述将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,包括:将所述对位乘结果拆解为多个第二子张量,对所述多个第二子张量进行winograd逆变换并求和,得到所述待运算数据的winograd卷积结果;其中,所述多个第二子张量的个数与所述对位乘结果中不为0元素的个数相同,所述多个第二子张量中的每个第二子张量中有一个元素与所述对位乘结果中的对应位置的元素相同、其他元素均为0。
在一种可能的实现方式中,所述统计结果包括以下任一种:每种待量化数据中的绝对值最大值、每种待量化数据中的最大值和最小值的距离的二分之一,所述量化参数包括点位置参数、缩放系数和偏移量中的一种或多种,其中,所述绝对值最大值是每种待量化数据中的最大值或最小值的绝对值。
在一种可能的实现方式中,所述缩放系数是根据所述点位置参数、所述统计结果、所述数据位宽确定的。
在一种可能的实现方式中,所述偏移量是根据每种待量化数据的统计结果确定的。
在一种可能的实现方式中,所述点位置参数是根据所述统计结果和所述数据位宽确定的。
在一种可能的实现方式中,所述装置还包括:位宽调整模块,根据所述数据位宽对应的量化误差,对所述数据位宽进行调整,以利用调整后的数据位宽确定量化参数,其中,所述量化误差是根据对应层中量化后的数据与对应的量化前的数据确定的。
在一种可能的实现方式中,所述量化前的数据是在目标迭代间隔内的权值更新迭代过程中涉及的待量化数据;其中,所述目标迭代间隔包括至少一次权值更新迭代,且同一目标迭代间隔内量化过程中采用相同的所述数据位宽。
在一种可能的实现方式中,所述待运算数据包括输入神经元、权值和梯度中的至少一种。
应该理解,上述的装置实施例仅是示意性的,本公开的装置还可通过其它的方式实现。例如,上述实施例中所述单元/模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。例如,多个单元、模块或组件可以结合,或者可以集成到另一个系统,或一些特征可以忽略或不执行。
另外,若无特别说明,在本公开各个实施例中的各功能单元/模块可以集成在一个单元/模块中,也可以是各个单元/模块单独物理存在,也可以两个或两个以上单元/模块集成在一起。上述集成的单元/模块既可以采用硬件的形式实现,也可以采用软件程序模块的形式实现。
所述集成的单元/模块如果以硬件的形式实现时,该硬件可以是数字电路,模拟电路等等。硬件结构的物理实现包括但不局限于晶体管,忆阻器等等。若无特别说明,所述人工智能处理器可以是任何适当的硬件处理器,比如CPU、GPU、FPGA、DSP和ASIC等等。若无特别说明,所述存储单元可以是任何适当的磁存储介质或者磁光存储介质,比如,阻变式存储器RRAM(Resistive Random Access Memory)、动态随机存取存储器DRAM(Dynamic Random Access Memory)、静态随机存取存储器SRAM(Static Random-Access Memory)、增强动态随机存取存储器EDRAM(Enhanced Dynamic Random Access Memory)、高带宽内存HBM(High-Bandwidth Memory)、混合存储立方HMC(Hybrid Memory Cube)等等。
所述集成的单元/模块如果以软件程序模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储器中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储器中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储器包括:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
在一种可能的实现方式中,还公开了一种人工智能芯片,其包括了上述数据处理装置。
在一种可能的实现方式中,还公开了一种板卡,其包括存储器件、接口装置和控制器件以及上述 人工智能芯片;其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;所述存储器件,用于存储数据;所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;所述控制器件,用于对所述人工智能芯片的状态进行监控。
图6示出根据本公开实施例的板卡的结构框图,参阅图6,上述板卡除了包括上述芯片389以外,还可以包括其他的配套部件,该配套部件包括但不限于:存储器件390、接口装置391和控制器件392;
所述存储器件390与所述人工智能芯片通过总线连接,用于存储数据。所述存储器件可以包括多组存储单元393。每一组所述存储单元与所述人工智能芯片通过总线连接。可以理解,每一组所述存储单元可以是DDR SDRAM(英文:Double Data Rate SDRAM,双倍速率同步动态随机存储器)。
DDR不需要提高时钟频率就能加倍提高SDRAM的速度。DDR允许在时钟脉冲的上升沿和下降沿读出数据。DDR的速度是标准SDRAM的两倍。在一个实施例中,所述存储装置可以包括4组所述存储单元。每一组所述存储单元可以包括多个DDR4颗粒(芯片)。在一个实施例中,所述人工智能芯片内部可以包括4个72位DDR4控制器,上述72位DDR4控制器中64bit用于传输数据,8bit用于ECC校验。可以理解,当每一组所述存储单元中采用DDR4-3200颗粒时,数据传输的理论带宽可达到25600MB/s。
在一个实施例中,每一组所述存储单元包括多个并联设置的双倍速率同步动态随机存储器。DDR在一个时钟周期内可以传输两次数据。在所述芯片中设置控制DDR的控制器,用于对每个所述存储单元的数据传输与数据存储的控制。
所述接口装置与所述人工智能芯片电连接。所述接口装置用于实现所述人工智能芯片与外部设备(例如服务器或计算机)之间的数据传输。例如在一个实施例中,所述接口装置可以为标准PCIE接口。比如,待处理的数据由服务器通过标准PCIE接口传递至所述芯片,实现数据转移。优选的,当采用PCIE 3.0X 16接口传输时,理论带宽可达到16000MB/s。在另一个实施例中,所述接口装置还可以是其他的接口,本公开并不限制上述其他的接口的具体表现形式,所述接口单元能够实现转接功能即可。另外,所述人工智能芯片的计算结果仍由所述接口装置传送回外部设备(例如服务器)。
所述控制器件与所述人工智能芯片电连接。所述控制器件用于对所述人工智能芯片的状态进行监控。具体的,所述人工智能芯片与所述控制器件可以通过SPI接口电连接。所述控制器件可以包括单片机(Micro Controller Unit,MCU)。如所述人工智能芯片可以包括多个处理芯片、多个处理核或多个处理电路,可以带动多个负载。因此,所述人工智能芯片可以处于多负载和轻负载等不同的工作状态。通过所述控制装置可以实现对所述人工智能芯片中多个处理芯片、多个处理和或多个处理电路的工作状态的调控。
在一种可能的实现方式中,公开了一种电子设备,其包括了上述人工智能芯片。电子设备包括数据处理装置、机器人、电脑、打印机、扫描仪、平板电脑、智能终端、手机、行车记录仪、导航仪、传感器、摄像头、服务器、云端服务器、相机、摄像机、投影仪、手表、耳机、移动存储、可穿戴设备、交通工具、家用电器、和/或医疗设备。所述交通工具包括飞机、轮船和/或车辆;所述家用电器包括电视、空调、微波炉、冰箱、电饭煲、加湿器、洗衣机、电灯、燃气灶、油烟机;所述医疗设备包括核磁共振仪、B超仪和/或心电图仪。
本公开实施例还提出一种计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现上述方法。计算机可读存储介质可以是非易失性计算机可读存储介质。
本公开实施例还提出一种电子设备,包括:处理器;用于存储处理器可执行指令的存储器;其中,所述处理器被配置为调用所述存储器存储的指令,以执行上述方法。
图7示出根据本公开实施例的一种电子设备800的框图。例如,电子设备800可以是移动电话,计算机,数字广播终端,消息收发设备,游戏控制台,平板设备,医疗设备,健身设备,个人数字助理等终端。
参照图7,电子设备800可以包括以下一个或多个组件:处理组件802,存储器804,电源组件806,多媒体组件808,音频组件810,输入/输出(I/O)的接口812,传感器组件814,以及通信组件816。
处理组件802通常控制电子设备800的整体操作,诸如与显示,电话呼叫,数据通信,相机操作和记录操作相关联的操作。处理组件802可以包括一个或多个处理器820来执行指令,以完成上述的方法 的全部或部分步骤。此外,处理组件802可以包括一个或多个模块,便于处理组件802和其他组件之间的交互。例如,处理组件802可以包括多媒体模块,以方便多媒体组件808和处理组件802之间的交互。
存储器804被配置为存储各种类型的数据以支持在电子设备800的操作。这些数据的示例包括用于在电子设备800上操作的任何应用程序或方法的指令,联系人数据,电话簿数据,消息,图片,视频等。存储器804可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。
电源组件806为电子设备800的各种组件提供电力。电源组件806可以包括电源管理系统,一个或多个电源,及其他与为电子设备800生成、管理和分配电力相关联的组件。
多媒体组件808包括在所述电子设备800和用户之间的提供一个输出接口的屏幕。在一些实施例中,屏幕可以包括液晶显示器(LCD)和触摸面板(TP)。如果屏幕包括触摸面板,屏幕可以被实现为触摸屏,以接收来自用户的输入信号。触摸面板包括一个或多个触摸传感器以感测触摸、滑动和触摸面板上的手势。所述触摸传感器可以不仅感测触摸或滑动动作的边界,而且还检测与所述触摸或滑动操作相关的持续时间和压力。在一些实施例中,多媒体组件808包括一个前置摄像头和/或后置摄像头。当电子设备800处于操作模式,如拍摄模式或视频模式时,前置摄像头和/或后置摄像头可以接收外部的多媒体数据。每个前置摄像头和后置摄像头可以是一个固定的光学透镜系统或具有焦距和光学变焦能力。
音频组件810被配置为输出和/或输入音频信号。例如,音频组件810包括一个麦克风(MIC),当电子设备800处于操作模式,如呼叫模式、记录模式和语音识别模式时,麦克风被配置为接收外部音频信号。所接收的音频信号可以被进一步存储在存储器804或经由通信组件816发送。在一些实施例中,音频组件810还包括一个扬声器,用于输出音频信号。
I/O接口812为处理组件802和外围接口模块之间提供接口,上述外围接口模块可以是键盘,点击轮,按钮等。这些按钮可包括但不限于:主页按钮、音量按钮、启动按钮和锁定按钮。
传感器组件814包括一个或多个传感器,用于为电子设备800提供各个方面的状态评估。例如,传感器组件814可以检测到电子设备800的打开/关闭状态,组件的相对定位,例如所述组件为电子设备800的显示器和小键盘,传感器组件814还可以检测电子设备800或电子设备800一个组件的位置改变,用户与电子设备800接触的存在或不存在,电子设备800方位或加速/减速和电子设备800的温度变化。传感器组件814可以包括接近传感器,被配置用来在没有任何的物理接触时检测附近物体的存在。传感器组件814还可以包括光传感器,如CMOS或CCD图像传感器,用于在成像应用中使用。在一些实施例中,该传感器组件814还可以包括加速度传感器,陀螺仪传感器,磁传感器,压力传感器或温度传感器。
通信组件816被配置为便于电子设备800和其他设备之间有线或无线方式的通信。电子设备800可以接入基于通信标准的无线网络,如WiFi,2G或3G,或它们的组合。在一个示例性实施例中,通信组件816经由广播信道接收来自外部广播管理系统的广播信号或广播相关信息。在一个示例性实施例中,所述通信组件816还包括近场通信(NFC)模块,以促进短程通信。例如,在NFC模块可基于射频识别(RFID)技术,红外数据协会(IrDA)技术,超宽带(UWB)技术,蓝牙(BT)技术和其他技术来实现。
在示例性实施例中,电子设备800可以被一个或多个应用专用集成电路(ASIC)、数字信号处理器(DSP)、数字信号处理设备(DSPD)、可编程逻辑器件(PLD)、现场可编程门阵列(FPGA)、控制器、微控制器、微处理器或其他电子元件实现,用于执行上述方法。
在示例性实施例中,还提供了一种非易失性计算机可读存储介质,例如包括计算机程序指令的存储器804,上述计算机程序指令可由电子设备800的处理器820执行以完成上述方法。
图8示出根据本公开实施例的一种电子设备1900的框图。例如,电子设备1900可以被提供为一服务器。参照图8,电子设备1900包括处理组件1922,其进一步包括一个或多个处理器,以及由存储器1932所代表的存储器资源,用于存储可由处理组件1922的执行的指令,例如应用程序。存储器1932 中存储的应用程序可以包括一个或一个以上的每一个对应于一组指令的模块。此外,处理组件1922被配置为执行指令,以执行上述方法。
电子设备1900还可以包括一个电源组件1926被配置为执行电子设备1900的电源管理,一个有线或无线网络接口1950被配置为将电子设备1900连接到网络,和一个输入输出(I/O)接口1958。电子设备1900可以操作基于存储在存储器1932的操作系统,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM或类似。
在示例性实施例中,还提供了一种非易失性计算机可读存储介质,例如包括计算机程序指令的存储器1932,上述计算机程序指令可由电子设备1900的处理组件1922执行以完成上述方法。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。上述实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。
依据以下条款可更好地理解前述内容:
条款A1.一种数据处理方法,所述方法包括:
根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;
根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;
对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
条款A2.根据条款A1所述的方法,所述winograd卷积处理过程,包括:
将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果;
执行所述待运算数据中对应数据的winograd正变换结果之间的对位乘操作,得到对位乘结果;
将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,
其中,所述待量化数据为所述待运算数据、所述待运算数据的winograd正变换结果和所述对位乘结果中的任一种。
条款A3.根据条款A2所述的方法,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,包括以下任一操作:
在将待运算数据的winograd正变换拆解为求和运算之前,将所述待运算数据作为待量化数据进行量化处理;
在进行对位乘操作之前,将待运算数据中每个数据的winograd正变换结果作为待量化数据进行量化处理;
在进行winograd逆变换拆解为求和运算之前,将所述对位乘结果作为待量化数据进行量化处理。
条款A4.根据条款A2所述的方法,所述将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果,包括:
将所述待运算数据中的每个数据分别拆解为多个第一子张量,对所述待运算数据中的每个数据的多个第一子张量进行winograd正变换并求和得到所述待运算数据中每个数据的winograd正变换结果,
其中,每个数据拆分出的多个第一子张量的个数与对应的数据中不为0元素的个数相同,每个第一子张量中有一个元素与对应数据中的对应位置的元素相同、其他元素均为0。
条款A5.根据条款A2所述的方法,所述将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,包括:
将所述对位乘结果拆解为多个第二子张量,对所述多个第二子张量进行winograd逆变换并求和,得到所述待运算数据的winograd卷积结果;
其中,所述多个第二子张量的个数与所述对位乘结果中不为0元素的个数相同,所述多个第二子张量中的每个第二子张量中有一个元素与所述对位乘结果中的对应位置的元素相同、其他元素均为0。
条款A6.根据条款A1所述的方法,所述统计结果包括以下任一种:每种待量化数据中的绝对值最 大值、每种待量化数据中的最大值和最小值的距离的二分之一,
所述量化参数包括点位置参数、缩放系数和偏移量中的一种或多种,
其中,所述绝对值最大值是每种待量化数据中的最大值或最小值的绝对值。
条款A7.根据条款A6所述的方法,所述缩放系数是根据所述点位置参数、所述统计结果、所述数据位宽确定的。
条款A8.根据条款A6所述的方法,所述偏移量是根据每种待量化数据的统计结果确定的。
条款A9.根据条款A6所述的方法,所述点位置参数是根据所述统计结果和所述数据位宽确定的。
条款A10.根据条款A6所述的方法,所述方法还包括:
根据所述数据位宽对应的量化误差,对所述数据位宽进行调整,以利用调整后的数据位宽确定量化参数,
其中,所述量化误差是根据对应层中量化后的数据与对应的量化前的数据确定的。
条款A11.根据条款A10所述的方法,所述量化前的数据是在目标迭代间隔内的权值更新迭代过程中涉及的待量化数据;
其中,所述目标迭代间隔包括至少一次权值更新迭代,且同一目标迭代间隔内量化过程中采用相同的所述数据位宽。
条款A12.根据条款A2所述的方法,所述待运算数据包括输入神经元、权值和梯度中的至少一种。
条款A13.一种数据处理装置,所述装置包括:
数据量化模块,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;
卷积处理模块,根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;
反量化处理模块,对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
条款A14.根据条款A13所述的装置,所述winograd卷积处理过程,包括:
将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果;
执行所述待运算数据中对应数据的winograd正变换结果之间的对位乘操作,得到对位乘结果;
将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,
其中,所述待量化数据为所述待运算数据、所述待运算数据的winograd正变换结果和所述对位乘结果中的任一种。
条款A15.根据条款A14所述的装置,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,包括以下任一操作:
在将待运算数据的winograd正变换拆解为求和运算之前,将所述待运算数据作为待量化数据进行量化处理;
在进行对位乘操作之前,将待运算数据中每个数据的winograd正变换结果作为待量化数据进行量化处理;
在进行winograd逆变换拆解为求和运算之前,将所述对位乘结果作为待量化数据进行量化处理。
条款A16.根据条款A14所述的装置,所述将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果,包括:
将所述待运算数据中的每个数据分别拆解为多个第一子张量,对所述待运算数据中的每个数据的多个第一子张量进行winograd正变换并求和得到所述待运算数据中每个数据的winograd正变换结果,
其中,每个数据拆分出的多个第一子张量的个数与对应的数据中不为0元素的个数相同,每个第一子张量中有一个元素与对应数据中的对应位置的元素相同、其他元素均为0。
条款A17.根据条款A14所述的装置,所述将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,包括:
将所述对位乘结果拆解为多个第二子张量,对所述多个第二子张量进行winograd逆变换并求和, 得到所述待运算数据的winograd卷积结果;
其中,所述多个第二子张量的个数与所述对位乘结果中不为0元素的个数相同,所述多个第二子张量中的每个第二子张量中有一个元素与所述对位乘结果中的对应位置的元素相同、其他元素均为0。
条款A18.根据条款A13所述的装置,所述统计结果包括以下任一种:每种待量化数据中的绝对值最大值、每种待量化数据中的最大值和最小值的距离的二分之一,
所述量化参数包括点位置参数、缩放系数和偏移量中的一种或多种,
其中,所述绝对值最大值是每种待量化数据中的最大值或最小值的绝对值。
条款A19.根据条款A18所述的装置,所述缩放系数是根据所述点位置参数、所述统计结果、所述数据位宽确定的。
条款A20.根据条款A18所述的装置,所述偏移量是根据每种待量化数据的统计结果确定的。
条款A21.根据条款A18所述的装置,所述点位置参数是根据所述统计结果和所述数据位宽确定的。
条款A22.根据条款A18所述的装置,所述装置还包括:
位宽调整模块,根据所述数据位宽对应的量化误差,对所述数据位宽进行调整,以利用调整后的数据位宽确定量化参数,
其中,所述量化误差是根据对应层中量化后的数据与对应的量化前的数据确定的。
条款A23.根据条款A22所述的装置,所述量化前的数据是在目标迭代间隔内的权值更新迭代过程中涉及的待量化数据;
其中,所述目标迭代间隔包括至少一次权值更新迭代,且同一目标迭代间隔内量化过程中采用相同的所述数据位宽。
条款A24.根据条款A14所述的装置,所述待运算数据包括输入神经元、权值和梯度中的至少一种。
条款A25.一种人工智能芯片,所述芯片包括如条款A13至条款A24中任意一项所述的数据处理装置。
条款A26.一种电子设备,所述电子设备包括如条款A25所述的人工智能芯片。
条款A27.一种板卡,所述板卡包括:存储器件、接口装置和控制器件以及如条款A25所述的人工智能芯片;
其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;
所述存储器件,用于存储数据;
所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;
所述控制器件,用于对所述人工智能芯片的状态进行监控。
条款A28.根据条款A27所述的板卡,
所述存储器件包括:多组存储单元,每一组所述存储单元与所述人工智能芯片通过总线连接,所述存储单元为:DDR SDRAM;
所述芯片包括:DDR控制器,用于对每个所述存储单元的数据传输与数据存储的控制;
所述接口装置为:标准PCIE接口。
条款A29.一种电子设备,包括:
处理器;
用于存储处理器可执行指令的存储器;
其中,所述处理器被配置为调用所述存储器存储的指令,以执行条款A1至条款A12中任意一项所述的方法。
条款A30.一种计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现条款A1至条款A12中任意一项所述的方法。
以上对本公开实施例进行了详细介绍,本文中应用了具体个例对本公开的原理及实施方式进行了阐述,以上实施例的说明仅用于帮助理解本公开的方法及其核心思想。同时,本领域技术人员依据本公开的思想,基于本公开的具体实施方式及应用范围上做出的改变或变形之处,都属于本公开保护的范围。综上所述,本说明书内容不应理解为对本公开的限制。

Claims (30)

  1. 一种数据处理方法,其特征在于,所述方法包括:
    根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;
    根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;
    对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
  2. 根据权利要求1所述的方法,其特征在于,所述winograd卷积处理过程,包括:
    将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果;
    执行所述待运算数据中对应数据的winograd正变换结果之间的对位乘操作,得到对位乘结果;
    将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,
    其中,所述待量化数据为所述待运算数据、所述待运算数据的winograd正变换结果和所述对位乘结果中的任一种。
  3. 根据权利要求2所述的方法,其特征在于,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,包括以下任一操作:
    在将待运算数据的winograd正变换拆解为求和运算之前,将所述待运算数据作为待量化数据进行量化处理;
    在进行对位乘操作之前,将待运算数据中每个数据的winograd正变换结果作为待量化数据进行量化处理;
    在进行winograd逆变换拆解为求和运算之前,将所述对位乘结果作为待量化数据进行量化处理。
  4. 根据权利要求2所述的方法,其特征在于,所述将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果,包括:
    将所述待运算数据中的每个数据分别拆解为多个第一子张量,对所述待运算数据中的每个数据的多个第一子张量进行winograd正变换并求和得到所述待运算数据中每个数据的winograd正变换结果,
    其中,每个数据拆分出的多个第一子张量的个数与对应的数据中不为0元素的个数相同,每个第一子张量中有一个元素与对应数据中的对应位置的元素相同、其他元素均为0。
  5. 根据权利要求2所述的方法,其特征在于,所述将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,包括:
    将所述对位乘结果拆解为多个第二子张量,对所述多个第二子张量进行winograd逆变换并求和,得到所述待运算数据的winograd卷积结果;
    其中,所述多个第二子张量的个数与所述对位乘结果中不为0元素的个数相同,所述多个第二子张量中的每个第二子张量中有一个元素与所述对位乘结果中的对应位置的元素相同、其他元素均为0。
  6. 根据权利要求1所述的方法,其特征在于,所述统计结果包括以下任一种:每种待量化数据中的绝对值最大值、每种待量化数据中的最大值和最小值的距离的二分之一,
    所述量化参数包括点位置参数、缩放系数和偏移量中的一种或多种,
    其中,所述绝对值最大值是每种待量化数据中的最大值或最小值的绝对值。
  7. 根据权利要求6所述的方法,其特征在于,所述缩放系数是根据所述点位置参数、所述统计结果、所述数据位宽确定的。
  8. 根据权利要求6所述的方法,其特征在于,所述偏移量是根据每种待量化数据的统计结果确定 的。
  9. 根据权利要求6所述的方法,其特征在于,所述点位置参数是根据所述统计结果和所述数据位宽确定的。
  10. 根据权利要求6所述的方法,其特征在于,所述方法还包括:
    根据所述数据位宽对应的量化误差,对所述数据位宽进行调整,以利用调整后的数据位宽确定量化参数,
    其中,所述量化误差是根据对应层中量化后的数据与对应的量化前的数据确定的。
  11. 根据权利要求10所述的方法,其特征在于,所述量化前的数据是在目标迭代间隔内的权值更新迭代过程中涉及的待量化数据;
    其中,所述目标迭代间隔包括至少一次权值更新迭代,且同一目标迭代间隔内量化过程中采用相同的所述数据位宽。
  12. 根据权利要求2所述的方法,其特征在于,所述待运算数据包括输入神经元、权值和梯度中的至少一种。
  13. 一种数据处理装置,其特征在于,所述装置包括:
    数据量化模块,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,其中,所述量化参数是根据对应的待量化数据的统计结果和数据位宽确定的;
    卷积处理模块,根据所述量化后的数据继续执行winograd卷积处理,得到量化后的winograd卷积结果;
    反量化处理模块,对所述量化后的winograd卷积结果执行反量化处理,得到winograd卷积结果。
  14. 根据权利要求13所述的装置,其特征在于,所述winograd卷积处理过程,包括:
    将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果;
    执行所述待运算数据中对应数据的winograd正变换结果之间的对位乘操作,得到对位乘结果;
    将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,
    其中,所述待量化数据为所述待运算数据、所述待运算数据的winograd正变换结果和所述对位乘结果中的任一种。
  15. 根据权利要求14所述的装置,其特征在于,根据确定出的量化参数对待量化数据进行量化处理,得到量化后的数据,包括以下任一操作:
    在将待运算数据的winograd正变换拆解为求和运算之前,将所述待运算数据作为待量化数据进行量化处理;
    在进行对位乘操作之前,将待运算数据中每个数据的winograd正变换结果作为待量化数据进行量化处理;
    在进行winograd逆变换拆解为求和运算之前,将所述对位乘结果作为待量化数据进行量化处理。
  16. 根据权利要求14所述的装置,其特征在于,所述将待运算数据的winograd正变换拆解为求和运算,并进行计算得到所述待运算数据中每个数据的winograd正变换结果,包括:
    将所述待运算数据中的每个数据分别拆解为多个第一子张量,对所述待运算数据中的每个数据的多个第一子张量进行winograd正变换并求和得到所述待运算数据中每个数据的winograd正变换结果,
    其中,每个数据拆分出的多个第一子张量的个数与对应的数据中不为0元素的个数相同,每个第一子张量中有一个元素与对应数据中的对应位置的元素相同、其他元素均为0。
  17. 根据权利要求14所述的装置,其特征在于,所述将对所述对位乘结果的winograd逆变换拆解为求和运算,得到所述winograd卷积结果,包括:
    将所述对位乘结果拆解为多个第二子张量,对所述多个第二子张量进行winograd逆变换并求和,得到所述待运算数据的winograd卷积结果;
    其中,所述多个第二子张量的个数与所述对位乘结果中不为0元素的个数相同,所述多个第二子张量中的每个第二子张量中有一个元素与所述对位乘结果中的对应位置的元素相同、其他元素均为0。
  18. 根据权利要求13所述的装置,所述统计结果包括以下任一种:每种待量化数据中的绝对值最大值、每种待量化数据中的最大值和最小值的距离的二分之一,
    所述量化参数包括点位置参数、缩放系数和偏移量中的一种或多种,
    其中,所述绝对值最大值是每种待量化数据中的最大值或最小值的绝对值。
  19. 根据权利要求18所述的装置,其特征在于,所述缩放系数是根据所述点位置参数、所述统计结果、所述数据位宽确定的。
  20. 根据权利要求18所述的装置,其特征在于,所述偏移量是根据每种待量化数据的统计结果确定的。
  21. 根据权利要求18所述的装置,其特征在于,所述点位置参数是根据所述统计结果和所述数据位宽确定的。
  22. 根据权利要求18所述的装置,其特征在于,所述装置还包括:
    位宽调整模块,根据所述数据位宽对应的量化误差,对所述数据位宽进行调整,以利用调整后的数据位宽确定量化参数,
    其中,所述量化误差是根据对应层中量化后的数据与对应的量化前的数据确定的。
  23. 根据权利要求22所述的装置,其特征在于,所述量化前的数据是在目标迭代间隔内的权值更新迭代过程中涉及的待量化数据;
    其中,所述目标迭代间隔包括至少一次权值更新迭代,且同一目标迭代间隔内量化过程中采用相同的所述数据位宽。
  24. 根据权利要求14所述的装置,其特征在于,所述待运算数据包括输入神经元、权值和梯度中的至少一种。
  25. 一种人工智能芯片,其特征在于,所述芯片包括如权利要求13至权利要求24中任意一项所述的数据处理装置。
  26. 一种电子设备,其特征在于,所述电子设备包括如权利要求25所述的人工智能芯片。
  27. 一种板卡,其特征在于,所述板卡包括:存储器件、接口装置和控制器件以及如权利要求25所述的人工智能芯片;
    其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;
    所述存储器件,用于存储数据;
    所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;
    所述控制器件,用于对所述人工智能芯片的状态进行监控。
  28. 根据权利要求27所述的板卡,其特征在于,
    所述存储器件包括:多组存储单元,每一组所述存储单元与所述人工智能芯片通过总线连接,所述存储单元为:DDR SDRAM;
    所述芯片包括:DDR控制器,用于对每个所述存储单元的数据传输与数据存储的控制;
    所述接口装置为:标准PCIE接口。
  29. 一种电子设备,其特征在于,包括:
    处理器;
    用于存储处理器可执行指令的存储器;
    其中,所述处理器被配置为调用所述存储器存储的指令,以执行权利要求1至权利要求12中任意一项所述的方法。
  30. 一种计算机可读存储介质,其特征在于,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现权利要求1至权利要求12中任意一项所述的方法。
PCT/CN2020/110438 2019-11-01 2020-08-21 数据处理方法、装置、计算机设备和存储介质 WO2021082653A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911060473.XA CN112766472B (zh) 2019-11-01 2019-11-01 数据处理方法、装置、计算机设备和存储介质
CN201911060473.X 2019-11-01

Publications (1)

Publication Number Publication Date
WO2021082653A1 true WO2021082653A1 (zh) 2021-05-06

Family

ID=75692036

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/110438 WO2021082653A1 (zh) 2019-11-01 2020-08-21 数据处理方法、装置、计算机设备和存储介质

Country Status (2)

Country Link
CN (1) CN112766472B (zh)
WO (1) WO2021082653A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109190754A (zh) * 2018-08-30 2019-01-11 北京地平线机器人技术研发有限公司 量化模型生成方法、装置和电子设备
CN109767000A (zh) * 2019-01-16 2019-05-17 厦门美图之家科技有限公司 基于Winograd算法的神经网络卷积方法及装置
CN109993296A (zh) * 2019-04-01 2019-07-09 北京中科寒武纪科技有限公司 量化实现方法及相关产品
CN110163333A (zh) * 2018-01-10 2019-08-23 成都信息工程大学 卷积神经网络的并行优化方法
US20190325004A1 (en) * 2017-06-01 2019-10-24 Samsung Electronics Co., Ltd. Apparatus and method for generating efficient convolution

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3557484B1 (en) * 2016-12-14 2021-11-17 Shanghai Cambricon Information Technology Co., Ltd Neural network convolution operation device and method
US10372787B2 (en) * 2017-12-12 2019-08-06 Facebook, Inc. Hardware accelerator pre-configured with coefficients for matrix-transform operations
US10474430B2 (en) * 2017-12-29 2019-11-12 Facebook, Inc. Mixed-precision processing elements, systems, and methods for computational models
CN110245741A (zh) * 2018-03-09 2019-09-17 佳能株式会社 多层神经网络模型的优化和应用方法、装置及存储介质
CN108765247B (zh) * 2018-05-15 2023-01-10 腾讯科技(深圳)有限公司 图像处理方法、装置、存储介质及设备
CN109522052B (zh) * 2018-11-27 2020-05-08 中科寒武纪科技股份有限公司 一种计算装置及板卡

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190325004A1 (en) * 2017-06-01 2019-10-24 Samsung Electronics Co., Ltd. Apparatus and method for generating efficient convolution
CN110163333A (zh) * 2018-01-10 2019-08-23 成都信息工程大学 卷积神经网络的并行优化方法
CN109190754A (zh) * 2018-08-30 2019-01-11 北京地平线机器人技术研发有限公司 量化模型生成方法、装置和电子设备
CN109767000A (zh) * 2019-01-16 2019-05-17 厦门美图之家科技有限公司 基于Winograd算法的神经网络卷积方法及装置
CN109993296A (zh) * 2019-04-01 2019-07-09 北京中科寒武纪科技有限公司 量化实现方法及相关产品

Also Published As

Publication number Publication date
CN112766472B (zh) 2024-04-12
CN112766472A (zh) 2021-05-07

Similar Documents

Publication Publication Date Title
CN110889503B (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036905A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036908A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036890A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036904A1 (zh) 数据处理方法、装置、计算机设备和存储介质
US20200394522A1 (en) Neural Network Quantization Parameter Determination Method and Related Products
CN112085188A (zh) 一种神经网络的量化参数确定方法及相关产品
WO2021036362A1 (zh) 用于处理数据的方法、装置以及相关产品
WO2021114903A1 (zh) 数据处理方法、装置、计算机设备和存储介质
JP2023084094A (ja) 面積高効率畳み込みブロック
WO2019046722A1 (en) PROVIDING EFFICIENT FLOATING VIRGIN OPERATIONS USING MATRIX PROCESSORS IN PROCESSOR-BASED SYSTEMS
CN112085182A (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021083101A1 (zh) 数据处理方法、装置及相关产品
WO2021022903A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021082653A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021082654A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021083100A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021083097A1 (zh) 数据处理方法、装置、计算机设备和存储介质
US11475283B2 (en) Multi dimensional convolution in neural network processor
WO2021169914A1 (zh) 数据量化处理方法、装置、电子设备和存储介质
CN113298223B (zh) 数据处理方法、装置、计算机设备和存储介质
JP2024517707A (ja) 半導体ハードウェアにおいてニューラルネットワークを処理するための実装および方法
CN113297128A (zh) 数据处理方法、装置、计算机设备和存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20882127

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20882127

Country of ref document: EP

Kind code of ref document: A1