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

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

Info

Publication number
WO2021036904A1
WO2021036904A1 PCT/CN2020/110299 CN2020110299W WO2021036904A1 WO 2021036904 A1 WO2021036904 A1 WO 2021036904A1 CN 2020110299 W CN2020110299 W CN 2020110299W WO 2021036904 A1 WO2021036904 A1 WO 2021036904A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
quantized
iteration
bit width
target
Prior art date
Application number
PCT/CN2020/110299
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
Priority claimed from CN201910888552.3A external-priority patent/CN112085151A/zh
Application filed by 安徽寒武纪信息科技有限公司 filed Critical 安徽寒武纪信息科技有限公司
Priority to JP2020567490A priority Critical patent/JP7146952B2/ja
Priority to US17/254,998 priority patent/US12001955B2/en
Priority to EP20824880.7A priority patent/EP4020321A4/en
Publication of WO2021036904A1 publication Critical patent/WO2021036904A1/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/04Architecture, e.g. interconnection topology
    • G06N3/0495Quantised networks; Sparse networks; Compressed networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/084Backpropagation, e.g. using gradient descent
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/21Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
    • G06F18/214Generating training patterns; Bootstrap methods, e.g. bagging or boosting
    • 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
    • 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
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • 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
    • G06N3/0464Convolutional networks [CNN, ConvNet]

Definitions

  • the present disclosure relates to the field of computer technology, and in particular to a neural network quantification method, device, computer equipment and storage medium.
  • Neural network is a mathematical model or calculation model that imitates the structure and function of biological neural networks. Through the training of sample data, the neural network continuously corrects the network weights and thresholds so that the error function decreases along the negative gradient direction and approximates the expected output. It is a widely used recognition and classification model, which is mostly used for function approximation, model recognition and classification, data compression and time series forecasting. Neural networks are used in image recognition, speech recognition, natural language processing and other fields. However, as the complexity of neural networks increases, the amount of data and data dimensions are increasing, and the increasing amount of data is equal to The data processing efficiency of the device, the storage capacity of the storage device, and the memory access efficiency pose greater challenges.
  • a fixed bit width is used to quantify the operation data of the neural network, that is, the floating-point operation data is converted into the fixed-point operation data, so as to realize the compression of the operation data of the neural network.
  • the same quantization scheme is used for the entire neural network, but there may be large differences between different operation data of the neural network, which often leads to lower accuracy and affects the data operation result.
  • a neural network quantification method which is applied to a terminal, and the terminal is used to run a neural network to perform a target task, and the method includes:
  • multiple data to be quantified are determined from the target data, each of the data to be quantified is a subset of the target data, and the target data is the nerve Any kind of data to be quantified in the to-be-quantized layer of the network, where the data to be calculated includes at least one of input neurons, weights, biases, and gradients;
  • a neural network quantification device which is applied to a terminal, the terminal is used to run a neural network to perform a target task, and the device includes:
  • the data determining module determines a plurality of data to be quantified from the target data according to the target task and/or the accuracy requirements of the terminal, each of the data to be quantified is a subset of the target data, and the target data Is any kind of data to be quantified to be calculated in the layer to be quantized of the neural network, and the data to be calculated includes at least one of input neurons, weights, biases, and gradients;
  • a data quantization module to quantize each of the data to be quantized according to the corresponding quantization parameter to obtain quantized data corresponding to each of the data to be quantized;
  • the result determining module obtains the quantization result of the target data according to the quantization data corresponding to each of the data to be quantized, so that the layer to be quantized performs operations according to the quantization result of the target data.
  • an artificial intelligence chip characterized in that the chip includes the above-mentioned neural network quantification device.
  • an electronic device including the above artificial intelligence chip.
  • a board card comprising: a storage device, an interface device, a control device, and the above-mentioned 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.
  • a non-volatile computer-readable storage medium having computer program instructions stored thereon, and when the computer program instructions are executed by a processor, the above neural network quantization method is realized.
  • the neural network quantification method, device, computer equipment, and storage medium include: determining from the target data of the layer to be quantized according to the target task and/or the accuracy requirements of the terminal A plurality of data to be quantized, each of the data to be quantized is a subset of the target data, the target data is any data to be quantized in the layer to be quantized of the neural network, and the data to be calculated
  • the data includes at least one of input neurons, weights, offsets, and gradients; each of the data to be quantized is quantized according to the corresponding quantization parameter to obtain the quantized data corresponding to each of the data to be quantized;
  • the quantized data corresponding to each of the data to be quantized obtain a quantization result of the target data, so that the layer to be quantized performs operations according to the quantization result of the target data.
  • the neural network quantification method, device, computer equipment, and storage medium determine multiple data to be quantized from the target data according to the accuracy requirements of the target task and/or terminal, and use the corresponding quantization parameters to perform the quantization of the data to be quantified. Quantification, while ensuring accuracy, reduces the storage space occupied by stored data, ensures the accuracy and reliability of the calculation results, and can improve the efficiency of calculations. Quantization also reduces the size of the neural network model and reduces The performance requirements of the terminal running the neural network model.
  • Fig. 1 shows a schematic diagram of a processor of a neural network quantization method according to an embodiment of the present disclosure.
  • Fig. 2 shows a flowchart of a neural network quantization method according to an embodiment of the present disclosure.
  • Fig. 3 shows a schematic diagram of a symmetric fixed-point number representation according to an embodiment of the present disclosure.
  • Fig. 4 shows a schematic diagram of a fixed-point number representation with an offset introduced according to an embodiment of the present disclosure.
  • Fig. 5 shows a flowchart of a neural network quantization method according to an embodiment of the present disclosure.
  • Fig. 6 shows a block diagram of a neural network quantization device according to an embodiment of the present disclosure.
  • Fig. 7 shows a structural block diagram of a board 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 to be calculated in the neural network is usually in the floating-point data format or the fixed-point data format with higher precision.
  • the floating-point data format or the fixed-point data format with higher precision is various to be calculated Data, which leads to a large amount of computation and memory access overhead for neural network operation.
  • the neural network quantification method, device, computer equipment and storage medium provided by the embodiments of the present disclosure can perform local quantization of the data to be calculated in the neural network according to different types of data to be calculated.
  • the quantized data format is usually It is a fixed-point data format with shorter bit width and lower precision. The use of lower-precision quantized data to perform neural network operations can reduce the amount of calculation and memory access.
  • the quantized data format can be a fixed-point data format with a shorter bit width.
  • the to-be-calculated data in the floating-point data format can be quantized into the to-be-calculated data in the fixed-point data format, and the to-be-calculated data in the fixed-point format with higher precision can also be quantized into the data to be calculated in the fixed-point format with lower precision.
  • multiple data to be quantized are determined from the target data, and the corresponding quantization parameters are used to quantify the data to be quantized. While ensuring accuracy, the storage space occupied by the stored data is reduced.
  • the quantization accuracy refers to the size of the error between the quantized data and the pre-quantized data.
  • the quantization accuracy can affect the accuracy of the neural network operation result. The higher the quantization accuracy, the higher the accuracy of the calculation result, but the greater the amount of calculation and the greater the memory access overhead.
  • the quantized data with a longer bit width has a higher quantization accuracy, and is also more accurate when used to perform neural network operations.
  • the quantization with a longer bit width has a larger amount of data calculation, a larger memory access overhead, and lower calculation efficiency.
  • the quantized data obtained by using different quantization parameters will have different quantization precisions, which will produce different quantization results, and will also have different effects on the calculation efficiency and accuracy of the calculation results.
  • the neural network is quantized to balance the calculation efficiency and the accuracy of the calculation results, and the quantized data bit width and quantization parameters that are more in line with the data characteristics of the data to be calculated can be used.
  • the data to be calculated in the neural network may include at least one of weights, neurons, biases, and gradients.
  • the data to be calculated is a matrix containing multiple elements.
  • traditional neural network quantization the whole data to be calculated is usually quantified and then operated.
  • a part of the overall quantized data to be calculated is usually used to perform calculations.
  • the convolutional layer when the overall quantized input neuron is used for convolution operation, according to the dimensionality and step size of the convolution kernel, the dimensionality equivalent to the convolution kernel is extracted from the overall quantized input neuron.
  • the quantized neuron performs convolution operation.
  • the overall quantized input neuron when used to perform the matrix multiplication operation, the quantized neurons are extracted row by row from the overall quantized input neuron to perform the matrix multiplication operation. Therefore, in the traditional neural network quantization method, the entire data to be calculated is quantized and then calculated according to the partially quantized data, and the overall calculation efficiency is low. In addition, the overall quantified data to be calculated before performing the calculation requires the storage of the overall quantized data to be calculated, which occupies a large storage space, which cannot meet the accuracy requirements of different terminals, and cannot meet the needs of terminals to perform different tasks using neural networks. Mission requirements.
  • the neural network quantification 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 an artificial intelligence for performing artificial intelligence operations.
  • processor processor
  • 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 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.
  • Fig. 1 shows a schematic diagram of a processor of a neural network quantization method according to an embodiment of the present disclosure.
  • the processor 100 includes multiple processing units 101 and a storage unit 102.
  • the multiple processing units 101 are used to execute instruction sequences, and the storage unit 102 is used to store data, and may include random access memory (RAM, Random Access Memory). And the register file.
  • the multiple processing units 101 in the processor 100 can not only share part of the storage space, for example, share part of the RAM storage space and the register file, but also have their own storage space at the same time.
  • Fig. 2 shows a flowchart of a neural network quantization method according to an embodiment of the present disclosure.
  • the method includes step S11 to step S13.
  • This method can be applied to a terminal including the processor 100 shown in FIG. 1, and the terminal is used to run a neural network to perform target tasks.
  • the processing unit 101 is configured to execute step S11 to step S13.
  • the storage unit 102 is used to store the data to be quantized, the quantization parameter, the data bit width, and other data related to the processing procedure from step S11 to step S13.
  • step S11 a plurality of data to be quantified are determined from the target data according to the target task and/or the accuracy requirements of the terminal, each of the data to be quantized is a subset of the target data, and the target
  • the data is any kind of data to be quantified to be calculated in the layer to be quantized of the neural network, and the data to be calculated includes at least one of input neurons, weights, biases, and gradients.
  • the amount of data to be calculated, the data volume of each data to be calculated, and the accuracy requirements determined based on the calculation accuracy of the terminal, the current processing capacity, and the storage capacity, the data to be calculated The types of operations involved, etc., determine the way to determine multiple data to be quantified from the target data.
  • the layer to be quantified in the neural network can be any layer in the neural network. Some or all of the layers in the neural network can be determined as the layers to be quantified according to requirements. When the neural network includes multiple layers to be quantized, each layer to be quantized may be continuous or discontinuous. According to different neural networks, the types of layers to be quantized may also be different. For example, the layers to be quantized may be convolutional layers, fully connected layers, etc. The present disclosure does not limit the number and types of quantized layers.
  • the data to be calculated includes at least one of neurons, weights, biases, and gradients. At least one of neurons, weights, biases, and gradients in the layer to be quantified can be quantified according to requirements.
  • the target data is any kind of data to be calculated to be quantified.
  • the data to be calculated are neurons, weights, and biases. If the neurons and weights need to be quantified, the neuron is target data 1, and the weight is target data 2.
  • the quantization method in the present disclosure can be used to quantify each target data to obtain the quantized data corresponding to each target data, and then use the quantized data and non-target data of various target data.
  • the to-be-calculated data that needs to be quantized performs the calculation of the to-be-quantized layer.
  • the reasoning stage of the neural network operation may include a stage in which the trained neural network is subjected to forward operation to complete the set task.
  • the inference stage of the neural network at least one of neurons, weights, biases, and gradients can be used as the data to be quantified. After quantization is performed according to the method in the embodiment of the present disclosure, the quantized data is used to complete the layer to be quantized. Operation.
  • the fine-tuning stage of the neural network operation may include: performing forward and backward operations of a preset number of iterations on the trained neural network, and fine-tuning the parameters to adapt to the stage of the set task.
  • at least one of neurons, weights, biases, and gradients can be quantified according to the method in the embodiment of the present disclosure, and then the quantized data is used to complete the forward direction of the layer to be quantized. Operation or reverse operation.
  • the training phase of the neural network operation may include: iterative training of the initialized neural network to obtain a trained neural network, and the trained neural network can perform specific tasks.
  • the training phase of the neural network at least one of neurons, weights, biases, and gradients can be quantized according to the method in the embodiment of the present disclosure, and then the quantized data is used to complete the forward operation of the layer to be quantized Or reverse operation.
  • a subset of the target data can be used as the data to be quantified, the target data can be divided into multiple subsets in different ways, and each subset can be regarded as the data to be quantified.
  • the target data can be divided into multiple data to be quantified according to the type of operation to be performed on the target data. For example, when the target data needs to be subjected to a convolution operation, the target data can be divided into multiple data to be quantized corresponding to the convolution kernel according to the height and width of the convolution kernel.
  • the target data is a left matrix that requires a matrix multiplication operation, the target data can be divided into multiple data to be quantized by rows.
  • the target data can be divided into multiple data to be quantized at one time, or the target data can be divided into multiple data to be quantized in sequence according to the order of operations.
  • the target data into multiple data may be quantified according to a preset data division method.
  • the preset data division method may be: division according to a fixed data size, or division according to a fixed data shape.
  • each data to be quantized can be quantized separately, and operations can be performed based on the quantized data of each data to be quantized.
  • the quantization time required for a data to be quantized is shorter than the overall quantization time of the target data.
  • the quantized data can be used to perform subsequent operations without waiting for all the target data. After the quantized data are all quantized, the calculation is performed. Therefore, the quantization method of target data in the present disclosure can improve the calculation efficiency of target data.
  • step S12 each of the data to be quantized is respectively quantized according to the corresponding quantization parameter to obtain quantized data corresponding to each of the data to be quantized.
  • the quantization parameter corresponding to the data to be quantized may be one quantization parameter or multiple quantization parameters.
  • the quantization parameters may include parameters used for quantizing the data to be quantized, such as point positions.
  • the point position can be used to determine the position of the decimal point in the quantized data.
  • the quantization parameters can also include scaling factors, offsets, and so on.
  • the method of determining the quantization parameter corresponding to the data to be quantized may include a method of determining the quantization parameter corresponding to the target data as the quantization parameter of the data to be quantized after determining the quantization parameter corresponding to the target data.
  • each target data may have a corresponding quantization parameter, and the quantization parameter corresponding to each target data may be different or the same, which is not limited in the present disclosure.
  • the quantization parameter corresponding to the target data can be determined as the quantization parameter corresponding to each data to be quantized. At this time, the quantization parameter corresponding to each data to be quantized is the same.
  • the method of determining the quantization parameter corresponding to the data to be quantized may also include a method of directly determining the quantization parameter corresponding to each data to be quantized.
  • the target data may not have a corresponding quantization parameter, or the target data may have a corresponding quantization parameter but the data to be quantized is not used.
  • the corresponding quantization parameter can be directly set for each data to be quantized.
  • the corresponding quantization parameter can also be calculated according to the data to be quantized. At this time, the quantization parameters corresponding to the data to be quantized may be the same or different.
  • the weight can be divided into multiple weight data to be quantized according to channels, and the weight data to be quantized in different channels can correspond to different quantization parameters.
  • the quantization parameter corresponding to each data to be quantized is different, after each data to be quantized is quantized using the corresponding quantization parameter, the obtained quantization result does not need to affect the calculation of the target data.
  • the method of determining the quantization parameter corresponding to the target data may include: looking up a preset quantization parameter to directly determine the quantization parameter, looking up a correspondence relationship to determine the quantization parameter, Or the way to calculate the quantization parameter based on the data to be quantified.
  • the method of determining the quantization parameter corresponding to the data to be quantized is taken as an example for description:
  • the quantization parameter corresponding to the data to be quantized can be directly set.
  • the set quantization parameters can be stored in the set storage space.
  • the set storage space can be on-chip or off-chip storage space.
  • the set quantization parameter can be stored in the set storage space.
  • each data to be quantized is quantized, it can be quantized after the corresponding quantization parameter is extracted in the set storage space.
  • the quantization parameter corresponding to each type of data to be quantized can be set according to empirical values.
  • the stored quantization parameters corresponding to each type of data to be quantized can also be updated according to requirements.
  • the quantization parameter can be determined by searching the correspondence relationship between the data feature and the quantization parameter according to the data feature of each data to be quantized. For example, when the data distribution of the data to be quantized is sparse and dense, it can correspond to different quantization parameters respectively.
  • the quantization parameter corresponding to the data distribution of the data to be quantized can be determined by searching for the corresponding relationship.
  • the quantization parameter corresponding to each layer to be quantized can be calculated by using the set quantization parameter calculation method according to the data to be quantized.
  • the point position in the quantization parameter can be calculated by using a rounding algorithm according to the maximum value of the absolute value of the data to be quantized and the preset data bit width.
  • step S13 the quantization result of the target data is obtained according to the quantization data corresponding to each of the data to be quantized, so that the layer to be quantized performs operations according to the quantization result of the target data.
  • the set quantization algorithm can be used to quantize the data to be quantized according to the quantization parameter to obtain the quantized data.
  • a rounding algorithm can be used as the quantization algorithm, and the quantized data can be rounded and quantized according to the data bit width and point position to obtain the quantized data.
  • the rounding algorithm may include rounding up, rounding down, rounding to zero, and rounding to five. The present disclosure does not limit the specific implementation of the quantization algorithm.
  • Each data to be quantized can be quantized using corresponding quantization parameters. Since the quantization parameter corresponding to each data to be quantized is more suitable for the characteristics of each data to be quantized, the quantization accuracy of each type of quantized data in each layer to be quantized is more in line with the calculation requirements of the target data, and also more in line with the layer to be quantized. Computing needs. Under the premise of ensuring the accuracy of the calculation result of the layer to be quantized, the calculation efficiency of the layer to be quantized can be improved, and a balance between the calculation efficiency of the layer to be quantized and the accuracy of the calculation result can be achieved. Further, the target data is divided into multiple data to be quantized and quantized separately.
  • the quantization of the second data to be quantized can be performed while performing calculations based on the quantization result obtained by the quantization.
  • the overall improvement of the computing efficiency of the target data also increases the computing efficiency of the layer to be quantified.
  • the quantized data of the data to be quantized can be combined to obtain the quantized result of the target data. It is also possible to perform a set operation on the quantized data of each data to be quantized to obtain the quantized result of the target data. For example, the quantized data of each data to be quantized can be weighted according to the set weight to obtain the quantized result of the target data. This disclosure does not limit this.
  • the data to be quantified can be quantified offline or online.
  • offline quantization may be to use quantization parameters to perform offline processing on the data to be quantized.
  • Online quantization can be the online processing of the data to be quantized using quantization parameters.
  • a neural network running on an artificial intelligence chip can send the data to be quantified and quantified parameters to an arithmetic device outside the artificial intelligence chip for offline quantification, or use an arithmetic device other than the artificial intelligence chip to analyze the data to be quantified in advance.
  • quantization parameters for offline quantization In the process of the artificial intelligence chip running the neural network, the artificial intelligence chip can use the quantitative parameters to quantify the quantified data online. In the present disclosure, there is no limitation on whether the quantization process of each data to be quantified is online or offline.
  • the neural network quantification method provided in this embodiment is applied to a terminal, and the terminal is used to run a neural network to perform a target task.
  • the method includes: according to the target task and/or the accuracy requirements of the terminal, from A plurality of data to be quantized is determined in the target data of the layer to be quantized. Each data to be quantized is a subset of the target data.
  • the target data is any data to be quantized in the layer to be quantized.
  • the data to be calculated includes input neurons.
  • At least one of, weight, bias, and gradient quantize each data to be quantized according to the corresponding quantization parameter to obtain quantized data corresponding to each data to be quantized; obtain quantized data corresponding to each data to be quantized
  • the quantized data of the target data so that the layer to be quantized performs operations based on the quantized data of the target data.
  • the quantization process and calculation process of each data to be quantized can be executed in parallel, which can improve the quantization efficiency and computing efficiency of the target data, and can also improve the layer to be quantized until the entire neural network is improved. Quantify efficiency and computing efficiency.
  • step S11 Five examples of implementation manners of step S11 are given below, that is, manner 1 to manner 5, so as to better understand the implementation process of step S11.
  • the target data in one or more layers to be quantized is determined as a piece of data to be quantized.
  • the quantitative data volume of the data quantized by the terminal each time can be determined according to the target task and the accuracy requirements of the terminal, and then according to the data volume of the target data and the quantitative data volume in different quantization layers, Determine the target data in one or more to-be-quantized layers as one to-be-quantized data.
  • the input neuron in a layer to be quantized is determined as a piece of data to be quantized.
  • Manner 2 According to the target task and/or the accuracy requirements of the terminal, the same type of data to be calculated in one or more layers to be quantized is determined as one data to be quantized.
  • the quantitative data volume of the data quantized by the terminal each time can be determined according to the target task and the accuracy requirements of the terminal, and then according to the data volume of the target data and the quantitative data volume in different quantization layers, A certain type of target data in one or more to-be-quantized layers is determined as one to-be-quantized data.
  • the input neurons in all the layers to be quantized are determined as one piece of data to be quantized.
  • Manner 3 According to the target task and/or the accuracy requirements of the terminal, the data in one or more channels in the target data corresponding to the layer to be quantized is determined as one data to be quantized.
  • the layer to be quantized When the layer to be quantized is a convolutional layer, the layer to be quantized contains channels. According to the channel and the quantized data volume of the data quantized by the terminal determined according to the accuracy requirements of the target task and the terminal, one or more The data in the channel is determined as a data to be quantized. For example, for a certain convolutional layer, the target data in 2 channels can be determined as one data to be quantized. Or, the target data in each channel can be determined as a piece of data to be quantized.
  • Manner 4 According to the target task and/or the accuracy requirements of the terminal, one or more batches of data in the target data corresponding to the layer to be quantified are determined as one data to be quantified;
  • the dimensions of the input neuron in the convolutional layer can include batch number (batch, B), channel (channel, C), height (height, H), and width (width, W) .
  • each batch of input neurons can be regarded as three-dimensional data with dimensions of channel, height, and width.
  • Each batch of input neurons can correspond to multiple convolution kernels, and the number of channels of each batch of input neurons is consistent with the number of channels of each convolution kernel corresponding to it.
  • any batch number of input neurons and for any one of the multiple convolution kernels corresponding to the batch number of input neurons, it can be based on the quantitative data volume and the batch number of input neuron data
  • the amount of data (subset) corresponding to the batch of input neurons and the convolution kernel is determined as a plurality of data to be quantified corresponding to the batch of input neurons and the convolution kernel. For example, assuming that the target data B1 has three batches of data, if one batch of data in the target data is determined as one to-be-quantized data, the target data B can be divided into three to-be-quantized data.
  • the quantization process is performed in parallel for each data to be quantized. Since the amount of data to be quantified is smaller than the input neuron, the calculation amount for quantifying a piece of data to be quantified is smaller than the calculation amount for the overall quantization of the input neuron. Therefore, the quantization method in this embodiment can improve the input neuron’s performance. Quantization speed, improve quantization efficiency. It is also possible to divide the input neuron according to the dimension and step size of the convolution kernel, and after each data to be quantized is obtained in turn, the obtained data to be quantized are respectively subjected to convolution operation with the convolution kernel. The quantization process and the convolution operation process of each data to be quantized can be executed in parallel, and the quantization method in this embodiment can improve the quantization efficiency and operation efficiency of the input neuron.
  • Manner 5 Determine the division size of the divided data according to the target task and/or the accuracy requirements of the terminal, and divide the target data in the corresponding layer to be quantized into one or more data to be quantized according to the division size.
  • the real-time processing capability of the terminal can be determined according to the target task and the precision requirements of the terminal, which can include: the speed at which the terminal quantizes the target data, the speed at which the quantized data is calculated, and what the terminal can handle when quantizing and calculating the target data
  • the amount of data represents information related to the processing capability of the terminal to process the target data.
  • the size of the data to be quantized can be determined according to the speed at which the target data is quantized and the speed at which the quantized data is operated, so that the time to quantize the data to be quantized is the same as the speed at which the quantized data is operated. Quantization and calculation are performed simultaneously, which can improve the calculation efficiency of the target data. The stronger the real-time processing capability of the terminal, the larger the size of the data to be quantified.
  • the method of determining the data to be quantified can be set as required.
  • the data to be quantified can include a kind of data to be calculated, such as input neuron (it can also be weight, bias, gradient, and input neuron below.
  • the data to be calculated can be part or all of the input neurons in a certain layer to be quantized, or it can be in multiple layers to be quantized, including all or part of the input neurons in each layer to be quantized. yuan.
  • the data to be quantized may also be all or part of the input neurons corresponding to a certain channel of the layer to be quantized, or all input neurons corresponding to several channels of the layer to be quantized.
  • the data to be quantified can also be part or all of a certain input neuron, and so on. That is to say, the target data can be divided according to any manner, and the present disclosure does not limit this.
  • a quantization parameter corresponding to the target data may be used for quantization in the process of quantizing the target data. After dividing the target data into multiple data to be quantized, the quantization parameter corresponding to each data to be quantized can be used for quantization.
  • the quantization parameter corresponding to each data to be quantized can be preset or calculated according to the data to be quantized. No matter what method is used to determine the quantization parameter corresponding to each data to be quantized, the quantization of the data to be quantized can be achieved.
  • the parameters are more in line with the quantitative requirements of the data to be quantified. For example, when the corresponding quantization parameter is calculated according to the target data, the quantization parameter can be calculated by using the maximum value and the minimum value of each element in the target data.
  • the maximum and minimum values of each element in the data to be quantized can be used to calculate the quantization parameter.
  • the quantization parameter of the data to be quantized can be more suitable for the target data than the quantization parameter of the target data.
  • the data characteristics of the quantized data can make the quantization result of the data to be quantized more accurate and the quantization precision higher.
  • the method may further include:
  • the corresponding quantization parameter is calculated according to each of the data to be quantized and the corresponding data bit width.
  • the reference data bit width or the data bit width reference range that meets the requirements can be determined according to the target task and the accuracy requirements of the terminal, and then the data bit width corresponding to the data to be quantized can be determined based on the characteristics of the data to be quantized.
  • the quantization parameter may include one or more of point position, scaling factor, and offset.
  • calculating the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width may include:
  • the first-type point position of each data to be quantized is obtained according to the maximum absolute value Z 1 in each data to be quantized and the corresponding data bit width.
  • the maximum absolute value Z 1 is the maximum value obtained by taking the absolute value of the data in the data to be quantized.
  • the quantization parameter may not include the offset, assuming that Z 1 is the maximum value of the absolute value of the element in the data to be quantized, and the data corresponding to the data to be quantized
  • the bit width is n
  • a 1 is the maximum value that can be represented by the quantized data after the quantized data is quantized with the data bit width n
  • a 1 is A 1 needs to include Z 1
  • Z 1 must be greater than Therefore
  • the processor may calculate the position s 1 of the first type point according to the maximum absolute value Z 1 and the data bit width n in the data to be quantized. For example, the following formula (2) can be used to calculate the first-type point position s 1 corresponding to the data to be quantified:
  • ceil is rounded up
  • Z 1 is the maximum absolute value in the data to be quantized
  • s 1 is the position of the first type of point
  • n is the data bit width.
  • calculating the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width may include:
  • the second-type point position s 2 of each data to be quantized is obtained according to the maximum value, the minimum value and the corresponding data bit width in each of the data to be quantized.
  • the maximum value Z max and the minimum value Z min in the data to be quantized can be obtained first, and then the following formula (3) is used for calculation according to the maximum value Z max and the minimum value Z min,
  • the absolute maximum value is obtained directly based on the maximum value and minimum value of the saved data to be quantized. Consume more resources to determine the absolute value of the quantitative data, saving the time to determine the statistical results.
  • calculating the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width includes:
  • the first-type scaling factor f'of each data to be quantized is obtained.
  • the first type of scaling factor f' may include a first scaling factor f 1 and a second scaling factor f 2 .
  • the first scaling factor f 1 can be calculated in the following way (5):
  • the second scaling factor f 2 can be calculated according to the following formula (6):
  • calculating the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width may include:
  • the offset of each data to be quantized is obtained.
  • FIG. 3 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 Figure 3 is distributed with "0" as the symmetric center.
  • Z 1 is the maximum absolute value of all floating-point numbers in the number domain of the data to be quantized.
  • a 1 is the maximum value of the floating-point number that can be represented by an n-bit fixed-point number.
  • the conversion of a floating-point number A 1 to a fixed-point number is ( 2 n-1 -1).
  • a 1 needs to include Z 1 .
  • Fig. 4 shows a schematic diagram of a fixed-point number representation with an offset introduced according to an embodiment of the present disclosure. As shown in Figure 4. The number field of the data to be quantized is not symmetrically distributed 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, and Z max is the maximum value of all floating-point numbers in the number field of the data to be quantized.
  • a 2 is the maximum value of the translated floating-point number represented by n-bit fixed-point number
  • a 2 is 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 to avoid data "overflow” .
  • the maximum absolute value in the number field of the data to be quantized after translation is Z 2 . It can be seen from Fig. 4 that the offset is the horizontal distance between the "0" point and the "P" point, and this distance is called the offset o.
  • the offset can be calculated according to the minimum value Z min and maximum value Z max according to the following formula (7):
  • o represents the offset
  • Z min represents the minimum value among all the elements of the data to be quantized
  • Z max represents the maximum value among all the elements of the data to be quantized.
  • calculating the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width may include:
  • the quantization parameter includes an offset
  • the second type of scaling factor f" of each of the data to be quantized is obtained.
  • the second type of scaling factor f" may include the first The third scaling factor f 3 and the fourth scaling factor f 4 .
  • a 2 is the maximum value that can be represented by the quantized data after quantizing the shifted data to be quantized with the data bit width n
  • a 2 is The maximum absolute value Z 2 in the number domain of the translated data to be quantized can be calculated according to Z max and the minimum value Z min in the data to be quantized, and then the third scaling factor f 3 is calculated according to the following formula (8):
  • the fourth scaling factor f 4 can be calculated according to the following formula (9):
  • the quantization parameters used are different, and the data used for quantization is different.
  • the quantization parameter may include the first-type point position s 1 .
  • the following formula (10) can be used to quantify the data to be quantized to obtain the quantized data I x :
  • I x is the quantized data
  • F x is the data to be quantized
  • round is the rounding operation performed by rounding.
  • the quantized data of the target data can be dequantized according to formula (11) to obtain the dequantized data of the target data
  • the quantization parameter may include a first-type point position and a first scaling factor.
  • the following formula (12) can be used to quantify the data to be quantized to obtain the quantized data I x :
  • the quantized data of the target data can be dequantized according to formula (13) to obtain the dequantized data of the target data
  • the quantization parameter may include a second scaling factor.
  • the following formula (14) can be used to quantify the data to be quantized to obtain the quantized data I x :
  • the quantized data of the target data can be inversely quantized according to formula (15) to obtain the inverse quantized data of the target data
  • the quantization parameter may include an offset.
  • the following formula (16) can be used to quantify the data to be quantized to obtain the quantized data I x :
  • the quantized data of the target data can be dequantized according to formula (17) to obtain the dequantized data of the target data
  • the quantization parameter may include the position and offset of the second type of point.
  • the following formula (18) can be used to quantify the data to be quantized to obtain the quantized data I x :
  • the quantized data of the target data can be inversely quantized according to formula (19) to obtain the inverse quantized data of the target data
  • the quantization parameter may include the second-type scaling factor f" and the offset o.
  • the following formula (20) may be used to quantize the quantized data to obtain the quantized data I x :
  • the quantized data of the target data can be inversely quantized according to formula (21) to obtain the inverse quantized data of the target data
  • the quantization parameter may include the position of the second-type point, the second-type scaling factor, and the offset.
  • the following formula (22) can be used to quantize the data to be quantized to obtain the quantized data I x :
  • the quantized data of the target data can be inversely quantized according to formula (23) to obtain the inverse quantized data of the target data
  • rounding operations can also be used, for example, rounding operations such as rounding up, rounding down, and rounding to zero may be used to replace the rounding operation round in the above formula. It is understandable that, in the case of a certain data bit width, in the quantized data obtained by quantization according to the point position, the more digits after the decimal point, the greater the quantization accuracy of the quantized data.
  • step S11 may include:
  • the quantization parameter corresponding to each type of data to be quantized in the layer to be quantized is determined by searching for the corresponding relationship between the data to be quantized and the quantization parameter.
  • the quantization parameter corresponding to each type of data to be quantized in each to-be-quantized layer may be a saved preset value.
  • a corresponding relationship between the data to be quantized and the quantization parameter can be established for the neural network.
  • the corresponding relationship can include the corresponding relationship between each type of data to be quantized and the quantization parameter in each layer to be quantized, and the corresponding relationship can be saved in each layer for shared access Storage space. It is also possible to establish multiple correspondences between the data to be quantized and the quantization parameters for the neural network, and each layer to be quantized corresponds to one of the correspondences.
  • the corresponding relationship of each layer can be stored in the storage space exclusive to this layer, or the corresponding relationship of each layer can be stored in the storage space that can be shared and accessed by each layer.
  • the correspondence between the data to be quantized and the quantization parameter may include correspondences between multiple data to be quantized and multiple quantization parameters corresponding thereto.
  • the corresponding relationship A between the data to be quantized and the quantization parameter may include two data to be quantized: neuron and weight of layer 1 to be quantized, and three quantization parameters of neuron corresponding point position 1, scaling factor 1, and offset 1.
  • the weight corresponds to the two quantization parameters of point position 2 and offset 2.
  • the present disclosure does not limit the specific format of the corresponding relationship between the quantized data and the quantized parameter.
  • the quantization parameter corresponding to each type of data to be quantized in the layer to be quantized can be determined by searching for the corresponding relationship between the data to be quantized and the quantization parameter.
  • Corresponding quantization parameters can be preset for each layer to be quantized, and the corresponding quantization parameters are stored through the corresponding relationship, and then used after searching for the layer to be quantized.
  • the method of acquiring the quantization parameter in this embodiment is simple and convenient.
  • Fig. 5 shows a flowchart of a neural network quantization method according to an embodiment of the present disclosure.
  • the method may further include step S14 to step S16.
  • step S14 a quantization error corresponding to each data to be quantized is determined according to each data to be quantized and the quantized data corresponding to each data to be quantized.
  • the quantization error of the data to be quantized can be determined according to the error between the quantized data corresponding to the data to be quantized and the data to be quantized. You can use the set error calculation method, such as the standard deviation calculation method, the root mean square error calculation method, etc., to calculate the quantization error of the data to be quantified.
  • F i is the corresponding floating point value to be quantized
  • i is the subscript of the data in the data to be quantized.
  • I is the dequantized data corresponding to the floating point value.
  • the quantization error diff bit can also be determined according to formula (25) according to the quantization interval, the number of quantized data, and the corresponding data before quantization.
  • C is the corresponding quantization interval during quantization
  • m is the number of quantized data obtained after quantization
  • F i is the floating point value corresponding to the to-be-quantized data
  • i is the subscript of the data in the to-be-quantized data.
  • the quantization error diff bit can also be determined according to formula (26) according to the quantized data and the corresponding inverse quantization data.
  • F i is the corresponding floating point value to be quantized
  • i is the subscript of the data in the data set to be quantized.
  • I is the dequantized data corresponding to the floating point value.
  • step S15 the data bit width corresponding to each data to be quantized is adjusted according to the quantization error and error threshold corresponding to each data to be quantized to obtain the adjustment bit width corresponding to each data to be quantized.
  • the error threshold can be determined based on empirical values, and the error threshold can be used to indicate the expected value of the quantization error.
  • the data bit width corresponding to the number to be quantized can be adjusted to obtain the adjustment bit width corresponding to the data to be quantized.
  • the data bit width can be adjusted to a longer bit width or a shorter bit width to increase or decrease the quantization accuracy.
  • the error threshold can be determined according to the maximum acceptable error. When the quantization error is greater than the error threshold, it means that the quantization accuracy cannot meet expectations, and the data bit width needs to be adjusted to a longer bit width. A smaller error threshold can also be determined according to the higher quantization accuracy. When the quantization error is less than the error threshold, it means that the quantization accuracy is higher, and the operating efficiency of the neural network will be affected. The data bit width can be appropriately adjusted to be shorter The bit width of, in order to appropriately reduce the quantization accuracy and improve the operating efficiency of the neural network.
  • the data bit width can be adjusted according to a fixed number of bits, or the data bit width can be adjusted according to a variable adjustment step according to the difference between the quantization error and the error threshold. This disclosure does not limit this.
  • step S16 the data bit width corresponding to each of the data to be quantized is updated to the corresponding adjustment bit width, and the corresponding adjusted quantization parameter is calculated according to each of the data to be quantized and the corresponding adjustment bit width, so that each The data to be quantized is quantized according to the corresponding adjusted quantization parameter.
  • the data bit width corresponding to the data to be quantized can be updated to the adjustment bit width. For example, if the data bit width before the update of the data to be quantized is 8 bits, and the adjustment bit width is 12 bits, the data bit width corresponding to the data to be quantized after the update is 12 bits.
  • the adjusted quantization parameter corresponding to the data to be quantized can be calculated according to the adjustment bit width and the data to be quantized.
  • the to-be-quantized data can be re-quantized according to the adjusted quantization parameter corresponding to the to-be-quantized data to obtain quantized data with higher or lower quantization accuracy, so that the to-be-quantized layer achieves a balance between quantization accuracy and processing efficiency.
  • the data to be quantified between the layers can be considered to have a certain relevance.
  • the adjusted quantization parameter of the layer to be quantized may be used as the adjusted quantization parameter of one or more subsequent layers for quantizing the data to be quantized in one or more subsequent layers of the to-be-quantized layer.
  • the adjusted quantization parameters obtained in the current iteration of the layer to be quantized can also be used to quantize the layer to be quantized in subsequent iterations.
  • the method further includes:
  • the quantization parameter of the layer to be quantized is used in one or more layers after the layer to be quantized.
  • the neural network performs quantization according to the adjusted quantization parameter, which may include re-quantizing the to-be-quantized data using the adjusted quantization parameter only in the to-be-quantized layer, and use the re-obtained quantized data in the calculation of the to-be-quantized layer. It can also include not using the adjusted quantization parameter to re-quantize the data to be quantized in the layer to be quantized, and using the adjusted quantization parameter in one or more subsequent layers of the layer to be quantized for quantization, and/or use the quantized parameter in the layer to be quantized in subsequent iterations Adjust the quantization parameter for quantization.
  • the adjusted quantization parameter may include re-quantizing the to-be-quantized data using the adjusted quantization parameter only in the to-be-quantized layer, and use the re-obtained quantized data in the calculation of the to-be-quantized layer. It can also include not using the adjusted quantization parameter to re-quantize the data to be quantized in the layer to be quantized, and using
  • It may also include using the adjusted quantization parameter to re-quantize in the layer to be quantized, and use the retrieved quantized data in the operation of the layer to be quantized, and use the adjusted quantization parameter to perform quantization in one or more subsequent layers of the layer to be quantized, and /Or in subsequent iterations, quantization is performed by adjusting the quantization parameter in the layer to be quantized.
  • This disclosure does not limit this.
  • the data bit width is adjusted according to the error between the data to be quantized and the quantized data corresponding to the data to be quantized, and the adjusted quantization parameter is calculated according to the adjusted data bit width.
  • different adjusted quantization parameters can be obtained to achieve different quantization requirements such as improving quantization accuracy or improving operation efficiency.
  • the adjusted quantization parameters calculated according to the data to be quantified and the quantized data of the data to be quantified can also be more in line with the data characteristics of the data to be quantized, and achieve a quantization result that more in line with the needs of the data to be quantized. It is between quantization accuracy and processing efficiency. Achieve a better balance.
  • step S15 may include:
  • the corresponding data bit width is increased to obtain the corresponding adjustment bit width.
  • the first error threshold may be determined according to the maximum quantization error that can be accepted.
  • the quantization error can be compared with the first error threshold. When the quantization error is greater than the first error threshold, it can be considered that the quantization error is already unacceptable.
  • the quantization accuracy of the data to be quantized can be improved by increasing the data bit width corresponding to the data to be quantized.
  • the data bit width corresponding to the data to be quantized can be increased according to a fixed adjustment step to obtain the adjustment bit width.
  • the fixed adjustment step size can be N bits, and N is a positive integer. Each time you adjust the data bit width, you can increase N bits.
  • the data bit width after each increase the original data bit width + N bits.
  • the data bit width corresponding to the data to be quantized can be increased according to the variable adjustment step length to obtain the adjustment bit width. For example, when the difference between the quantization error and the error threshold is greater than the first threshold, the data bit width can be adjusted according to the adjustment step M1, and when the difference between the quantization error and the error threshold is less than the first threshold, the data can be adjusted according to the adjustment step M1.
  • the step size M2 adjusts the data bit width, where the first threshold is greater than the second threshold, and M1 is greater than M2.
  • the variable adjustment step length can be determined according to requirements. The present disclosure does not limit the adjustment step length of the data bit width and whether the adjustment step length is variable.
  • the adjusted quantization parameter can be obtained by calculating the data to be quantized according to the adjusted bit width.
  • the quantized data obtained by using the adjusted quantization parameter to requantize the data to be quantized has higher quantization accuracy than the quantized data obtained by using the quantized parameter before adjustment.
  • the method may further include:
  • the bit width When increasing the data bit width corresponding to the data to be quantized according to the quantization error, adjust the bit width once to obtain the adjusted bit width, calculate the adjusted quantization parameter according to the adjusted bit width, and quantize the data to be quantized according to the adjusted quantization parameter to obtain the adjusted
  • the quantized data is calculated based on the adjusted quantized data and the to-be-quantized data to obtain the adjusted quantization error of the to-be-quantized data.
  • the adjusted quantization error may still be greater than the first error threshold, that is, the data bit width adjusted once may not meet the adjustment purpose.
  • the adjusted quantization error is still greater than the first error threshold, you can continue to adjust the adjusted data bit width, that is, increase the data bit width corresponding to the data to be quantized multiple times, until the adjusted bit width and the to-be quantized data are finally obtained.
  • the adjusted quantization error obtained from the data is less than the first error threshold.
  • the adjustment step length that is increased multiple times may be a fixed adjustment step length or a variable adjustment step length.
  • the final data bit width original data bit width+B*N bits, where N is the fixed adjustment step length for each increase, and B is the number of times the data bit width is increased.
  • the final data bit width original data bit width+M1+M2+...+Mm, where M1, M2...Mm are the variable adjustment step lengths that are increased each time.
  • the data bit width corresponding to the data to be quantized is increased to obtain the adjustment bit width corresponding to the data to be quantized.
  • the data bit width can be increased by setting the first error threshold and adjusting the step size, so that the adjusted data bit width can meet the quantization requirement.
  • the data bit width can also be adjusted multiple times. The setting of the first error threshold and the adjustment step length enables the quantization parameters to be flexibly adjusted according to the quantization requirements to meet different quantization requirements, so that the quantization accuracy can be adaptively adjusted according to its own data characteristics.
  • step S15 may include:
  • the corresponding data bit width is increased to obtain the corresponding adjustment bit width, and the second error threshold is less than the first error threshold
  • the second error threshold can be determined according to the acceptable quantization error and the expected operating efficiency of the neural network.
  • the quantization error can be compared with a second error threshold. When the quantization error is less than the second error threshold, it can be considered that the quantization error exceeds expectations, but the operating efficiency is too low to be acceptable.
  • the quantization accuracy can be reduced to improve the operating efficiency of the neural network, and the quantization accuracy of the data to be quantized can be reduced by reducing the data bit width corresponding to the data to be quantized.
  • the data bit width corresponding to the data to be quantized can be reduced according to a fixed adjustment step length to obtain the adjustment bit width.
  • the data bit width corresponding to the data to be quantized can be reduced according to the variable adjustment step length to obtain the adjustment bit width. For example, when the difference between the quantization error and the error threshold is greater than the first threshold, the data bit width can be adjusted according to the adjustment step M1, and when the difference between the quantization error and the error threshold is less than the first threshold, the data can be adjusted according to the adjustment step M1.
  • the step size M2 adjusts the data bit width, where the first threshold is greater than the second threshold, and M1 is greater than M2.
  • the variable adjustment step length can be determined according to requirements. The present disclosure does not limit the adjustment step length of the data bit width and whether the adjustment step length is variable.
  • the data to be quantized can be calculated according to the adjusted bit width to obtain the adjusted quantization parameter, and the quantized data obtained after re-quantization of the quantized data using the adjusted quantization parameter is higher than the quantization accuracy of the quantized data obtained by using the quantized parameter before adjustment. Lower.
  • the method may further include:
  • the bit width When increasing the data bit width corresponding to the data to be quantized according to the quantization error, adjust the bit width once to obtain the adjusted bit width, calculate the adjusted quantization parameter according to the adjusted bit width, and quantize the data to be quantized according to the adjusted quantization parameter to obtain the adjusted
  • the quantized data is calculated based on the adjusted quantized data and the to-be-quantized data to obtain the adjusted quantization error of the to-be-quantized data.
  • the adjusted quantization error may still be less than the second error threshold, that is, the data bit width adjusted once may not meet the adjustment purpose.
  • the adjusted quantization error is still less than the second error threshold, you can continue to adjust the adjusted data bit width, that is, reduce the data bit width corresponding to the data to be quantized multiple times, until the adjusted bit width and the to-be quantized data are finally obtained.
  • the adjusted quantization error obtained from the data is greater than the second error threshold.
  • the adjustment step length reduced multiple times may be a fixed adjustment step length or a variable adjustment step length.
  • the final data bit width original data bit width-B*N bits, where N is the fixed adjustment step length for each increase, and B is the number of times the data bit width is increased.
  • the final data bit width the original data bit width-M1-M2-...-Mm, where M1, M2...Mm are the variable adjustment step lengths that are reduced each time.
  • the data bit width corresponding to the data to be quantized is reduced to obtain the adjustment bit width corresponding to the data to be quantized.
  • the data bit width can be reduced by setting the second error threshold and adjusting the step size, so that the adjusted data bit width can meet the quantization requirement.
  • the data bit width can also be adjusted multiple times. The setting of the second error threshold and the adjustment step length enables the quantization parameters to be flexibly and adaptively adjusted according to the quantization requirements to meet different quantization requirements, so that the quantization accuracy is adjustable, and a balance is achieved between the quantization accuracy and the operating efficiency of the neural network .
  • the method further includes:
  • the data bit width corresponding to the data to be quantized is increased, and when the quantization error is less than the second error threshold, the data bit width corresponding to the data to be quantized is reduced to obtain The adjustment bit width corresponding to the data to be quantized.
  • the first error threshold is used to indicate that the quantization accuracy is too low, which can increase the number of bits in the data bit width
  • the second error threshold is used to indicate that the quantization accuracy is too high, which can reduce the data bit width. Digits.
  • the first error threshold is greater than the second error threshold.
  • the quantization error of the data to be quantized can be compared with the two error thresholds at the same time. When the quantization error is greater than the first error threshold, the number of bits of the data bit width is increased. When the quantization error is less than the first error threshold, For the second error threshold, reduce the number of digits of the data bit width. When the quantization error is between the first error threshold and the second error threshold, the data bit width can remain unchanged.
  • the data bit width can be increased or decreased according to the comparison result, and the first error threshold and the second error threshold can be used for more flexible adjustment.
  • Data bit width This makes the adjustment result of the data bit width more in line with quantitative requirements.
  • the method may further include:
  • the target iteration interval corresponding to the data to be quantized is determined, so that the layer to be quantized updates the quantization parameter of the data to be quantized according to the target iteration interval, and the target iteration The interval includes at least one iteration.
  • the fine-tuning phase and/or training phase of the neural network operation includes multiple iterations.
  • Each layer to be quantized in the neural network performs one forward operation and one reverse operation, and after updating the weight of the quantized layer, an iteration is completed.
  • the data to be quantized in the layer to be quantized and/or the quantized data corresponding to the quantized data can be used to measure whether the data to be quantized and/or the quantized data in different iterations can be the same.
  • the quantization parameter is quantized. If the data change range of the data to be quantified in the current iteration and the historical iteration is small, for example, less than the set range change threshold, the same quantization parameter can be used in multiple iterations with smaller data change range.
  • the quantization parameter corresponding to the data to be quantized can be determined by extracting the pre-stored quantization parameter.
  • the quantization parameter can also be calculated according to the data to be quantized and the data bit width. When quantizing the data to be quantized in different iterations, it is necessary to calculate the quantization parameters separately in each iteration. If the data to be quantized in multiple iterations and/or the quantized data corresponding to the data to be quantized has a small data variation range, the same quantization parameter can be used in multiple iterations with a small data variation range, and each iteration can be directly Use the quantization parameter calculated in the first iteration instead of calculating the quantization parameter in each iteration.
  • the weight value between each iteration is constantly updated. If the data change range of the weight value of multiple iterations is small, or the quantified data corresponding to the weight value of multiple iterations The data change range of is small, and the same quantization parameter can be used to quantify the weight in multiple iterations.
  • the target iteration interval can be determined according to the data variation range of the data to be quantified.
  • the target iteration interval includes at least one iteration.
  • the same quantization parameters can be used in each iteration within the target iteration interval, that is, the iteration within the target iteration interval will no longer be updated.
  • the quantization parameter of the quantized data The neural network updates the quantization parameters of the data to be quantized according to the target iteration interval, including the iterations within the target iteration interval, and does not obtain the preset quantization parameters or calculate the quantization parameters, that is, the iterations within the target iteration interval do not update the quantization parameters.
  • the preset quantization parameter is obtained or the quantization parameter is calculated, that is, the quantization parameter is updated in the iteration outside the target iteration interval.
  • the calculated data fluctuation range the corresponding relationship between the preset data fluctuation range and the iteration interval can be searched, and the target iteration interval corresponding to the calculated data fluctuation range can be determined.
  • the corresponding relationship between the data change range and the iteration interval can be preset according to requirements. You can also calculate the target iteration interval by using the set calculation method according to the calculated data variation range.
  • the present disclosure does not limit the calculation method of the data variation range and the acquisition method of the target iteration interval.
  • the data change range of the data to be quantized in the current iteration and historical iteration is obtained, and the data change range of the data to be quantized is determined according to the data change range of the data to be quantized.
  • the target iteration interval can be determined according to the data change range of the to-be-quantized data or the quantized data corresponding to the to-be-quantized data in multiple iterations.
  • the neural network can determine whether to update the quantization parameter according to the target iteration interval.
  • the quantization parameters are not updated in the iterations within the target iteration interval to ensure the quantization accuracy.
  • multiple iterations within the target iteration interval do not update the quantization parameters, which can reduce the number of extractions or calculations of the quantization parameters, thereby improving the computational efficiency of the neural network.
  • the method further includes:
  • the data bit width corresponding to the iteration of the data to be quantized in the target iteration interval is determined, so that the neural network is based on the data to be quantized.
  • the data bit width corresponding to the iteration within the target iteration interval determines the quantization parameter.
  • the quantization parameter of the data to be quantized can be preset or calculated according to the data bit width corresponding to the data to be quantized.
  • the data bit width corresponding to the data to be quantized in different layers to be quantized, or the data bit width corresponding to the data to be quantized in the same layer to be quantized in different iterations, can be adaptively adjusted according to the method in the above-mentioned embodiment of the present disclosure.
  • the iterative correspondence of the data to be quantized in the target iteration interval can be determined according to the preset data bit width of the data to be quantized in the current iteration The data bit width.
  • Each iteration within the target iteration interval may not use its own preset value.
  • the data bit width corresponding to the iteration of the data to be quantized within the target iteration interval can be determined according to the data bit width corresponding to the current iteration of the data to be quantized.
  • the data bit width can be adjusted adaptively, the data bit width can be adjusted once or adjusted multiple times.
  • the data bit width after adaptive adjustment of the data to be quantized in the current iteration can be used as the data bit width corresponding to each iteration within the target iteration interval, and the data bit width is no longer adaptively adjusted for each iteration within the target iteration interval. (Update).
  • the data bit width after adaptive adjustment can be used, or the data bit width before adaptive adjustment can be used, which is not limited in the present disclosure.
  • the data bit width can be adaptively adjusted according to the above-mentioned method of the present disclosure to obtain the data of the data to be quantized that is more in line with the current iteration.
  • the bit width can also use the calculation method of the target iteration interval in the present disclosure to calculate and use a new target iteration interval, thereby ensuring the quantization accuracy of iterations outside the target iteration interval and improving the operating efficiency of the neural network.
  • the data bit width of each iteration within the target iteration interval is the same, and each iteration can calculate the corresponding quantization parameter separately according to the same data bit width.
  • the quantization parameter may include at least one of a point position, a scaling factor, and an offset amount.
  • the quantization parameters can be calculated separately for each iteration within the target iteration interval based on the same data bit width.
  • the quantization parameters include the point position (including the first type of point position and the second type of point position), the zoom factor (including the first type of zoom factor and the second type of zoom factor) and the offset, each iteration within the target iteration interval .
  • the same data bit width can be used to calculate the respective corresponding point positions, scaling factors and offsets.
  • the corresponding quantization parameter of each iteration within the target iteration interval can be determined according to the quantization parameter of the current iteration.
  • the quantization parameters of each iteration within the target iteration interval are not calculated again based on the same data bit width, which can further improve the computational efficiency of the neural network.
  • the corresponding quantization parameter of each iteration within the target iteration interval can be determined according to all quantization parameters or part of the quantization parameters of the current iteration.
  • the quantization parameter includes the position of the second-type point, the second-type scaling factor, and the offset.
  • the data bit width of each iteration and the position of the second type point in the target iteration interval can be determined according to the data bit width of the current iteration and the position of the second type point.
  • the second-type scaling factor and offset of each iteration within the target iteration interval need to be calculated based on the same data bit width. It is also possible to determine the data bit width of each iteration within the target iteration interval, the position of the second type of point, the second type of zoom factor and the offset according to the data bit width of the current iteration, the position of the second type of point, the second type of zoom factor and the offset. Offset, the quantization parameters of each iteration within the target iteration interval do not need to be calculated.
  • the data bit width corresponding to the iteration of the data to be quantized in the target iteration interval is determined, so that the neural network is based on the data to be quantized in the target iteration interval. Iterate the corresponding data bit width to determine the quantization parameter.
  • the data bit width of each iteration in the target iteration interval is determined according to the data bit width of the current iteration. Since the data change range of the data to be quantized in each iteration within the target iteration interval meets the set conditions, the same data bit width is used for calculation
  • the obtained quantization parameters can ensure the quantization accuracy of each iteration within the target iteration interval.
  • Each iteration within the target iteration interval uses the same data bit width, which can also improve the computational efficiency of the neural network. After quantifying the neural network, a balance is reached between the accuracy of the calculation result and the calculation efficiency of the neural network.
  • the method may further include: determining the point position corresponding to the iteration of the to-be-quantized data within the target iteration interval according to the point position corresponding to the current iteration of the to-be-quantized data ,
  • the point position includes a first type of point position and/or a second type of point position.
  • the position of the first-type point corresponding to the current iteration of the data to be quantized is determined.
  • the position of the second-type point corresponding to the current iteration of the data to be quantized is determined.
  • the point position corresponding to the iteration within the target iteration interval can be determined according to the point position corresponding to the current iteration of the data to be quantified.
  • the point position of the data to be quantized in the current iteration can be set as the point position corresponding to each iteration of the data to be quantized in the target iteration interval, or the data to be quantized can be set according to the current iteration.
  • the point position calculated from the preset data bit width is used as the point position corresponding to each iteration of the data to be quantified in the target iteration interval.
  • the point position of the data to be quantized adjusted in the current iteration can be used as the point position of the data to be quantized in each iteration within the target iteration interval.
  • the point position corresponding to the iteration of the data to be quantized in the target iteration interval is determined, and at the same time, the scaling corresponding to the data to be quantized in the current iteration is also possible.
  • Coefficient, determining the scaling factor corresponding to the iteration of the data to be quantized in the target iteration interval, and/or determining the data to be quantized in the target iteration interval according to the offset corresponding to the data to be quantized in the current iteration The offset corresponding to the iteration within.
  • the point position corresponding to the iteration of the data to be quantized in the target iteration interval is determined, and the data to be quantized in the current iteration may also be determined according to the data to be quantized in the current iteration.
  • the bit width determines the data bit width corresponding to the iteration of the data to be quantized in the target iteration interval, where the data bit width corresponding to the current iteration of the data to be quantized can be the preset data bit width of the current iteration or self Adapt to the adjusted data bit width.
  • the point position corresponding to the iteration of the data to be quantized in the target iteration interval is determined.
  • the point position of each iteration in the target iteration interval is determined according to the point position of the current iteration. Since the data change range of the data to be quantified in each iteration within the target iteration interval meets the set conditions, the same point position can be used to ensure the target The quantization accuracy of each iteration within the iteration interval. Using the same point position for each iteration within the target iteration interval can also improve the computational efficiency of the neural network. After quantifying the neural network, a balance is reached between the accuracy of the calculation result and the calculation efficiency of the neural network.
  • obtaining the data change range of the data to be quantified in the current iteration and the historical iteration may include:
  • the moving average of the point positions of the data to be quantified corresponding to each iteration interval is calculated.
  • the location includes the first-category point location and/or the second-category point location;
  • determining the target iteration interval corresponding to the to-be-quantized data according to the data variation range of the to-be-quantized data so that the neural network updates the quantization parameter of the to-be-quantized data according to the target iteration interval may include:
  • the first type of the data to be quantified corresponding to each iteration interval is calculated
  • the historical iteration corresponding to the current iteration determined according to the historical iteration interval may be a historical iteration for calculating the target iteration interval.
  • the correspondence between the current iteration and the corresponding target iteration interval may include:
  • the target iteration interval can be counted from the current iteration, and the target iteration interval can be recalculated at the next iteration after the end of the target iteration interval corresponding to the current iteration.
  • the current iteration is the 100th generation
  • the target iteration interval is 3
  • the iterations within the target iteration interval include: the 100th, 101st, and 102nd generations.
  • the historical iteration corresponding to the current iteration determined according to the historical iteration interval is 100 generations.
  • the target iteration interval can be counted from the next iteration of the current iteration, and the target iteration interval can be recalculated from the last iteration within the target iteration interval.
  • the current iteration is the 100th generation
  • the target iteration interval is 3
  • the iterations within the target iteration interval include: the 101st, 102nd, and 103rd generations.
  • And use 104 as the new calculation to get the first iteration within the target iteration interval.
  • the historical iteration corresponding to the current iteration determined according to the historical iteration interval is 100 generations.
  • the target iteration interval can be counted from the next iteration of the current iteration, and the target iteration interval can be recalculated at the next iteration after the end of the target iteration interval.
  • the current iteration is the 100th generation
  • the target iteration interval is 3
  • the iterations within the target iteration interval include: the 101st, 102nd, and 103rd generations.
  • the target iteration interval corresponding to the 104th generation can be calculated in the 104th generation.
  • And use 105 as the new calculation to get the first iteration within the target iteration interval.
  • the historical iteration corresponding to the current iteration determined according to the historical iteration interval is 100 generations.
  • the target iteration interval may be counted from the Nth iteration after the current iteration, and N is greater than 1, which is not limited in the present disclosure.
  • the calculated moving average of the point positions of the data to be quantized corresponding to each iteration interval includes the first moving average of the point positions of the data to be quantized in the current iteration, and corresponds to the data to be quantized in the previous iteration interval.
  • Formula (27) can be used to calculate the first moving average m (t) of the corresponding point position of the current iteration:
  • t is the current iteration
  • t-1 is the historical iteration determined according to the previous iteration interval
  • m (t-1) is the second moving average of the historical iteration determined according to the previous iteration interval
  • s (t) is the point position of the current iteration, which can be the first type point position or the second type point position.
  • is the first parameter.
  • the first parameter may be a hyperparameter.
  • the sliding of the point position of the data to be quantified corresponding to each iteration interval is calculated.
  • Average According to the first moving average of the point position of the current iteration of the data to be quantified, and the second moving average of the point position of the corresponding iteration in the previous iteration interval, the first data variation range is obtained. Determine the target iteration interval corresponding to the data to be quantized according to the first data variation range, so that the neural network updates the quantization parameter of the data to be quantized according to the target iteration interval.
  • the target iteration interval can follow the change trend of the data point to be quantified, and the calculated target iteration interval can be based on the data point to be quantified.
  • the changing trend of the location changes. Since the quantization parameter is determined according to the target iteration interval, the quantization data obtained by quantization according to the quantization parameter can be more in line with the changing trend of the point position of the data to be quantized, and the operation efficiency of the neural network is improved while ensuring the quantization accuracy.
  • a data change range which can include:
  • the absolute value of the difference is determined as the first data variation range.
  • the first data change range diff update1 can be calculated using formula (28):
  • the target iteration interval corresponding to the data to be quantized may be determined according to the first data variation range, so that the neural network updates the quantization parameter of the data to be quantized according to the target iteration interval.
  • the target iteration interval I can be calculated according to formula (29):
  • is the second parameter
  • is the third parameter
  • the second parameter and the third parameter may be hyperparameters.
  • the first data change range can be used to measure the change trend of the point position.
  • the larger the first data change range it means that the numerical range of the quantized data changes drastically.
  • a shorter target iteration interval is required when updating the quantized parameters. I.
  • the difference between the first moving average value and the second moving average value is calculated; the absolute value of the difference value is determined as the first data variation range. According to the difference between the moving average values, an accurate first data variation range can be obtained.
  • the method may further include: obtaining the second data variation range according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration;
  • determining the target iteration interval corresponding to the to-be-quantized data according to the data variation range of the to-be-quantized data so that the neural network updates the quantization parameter of the to-be-quantized data according to the target iteration interval may include:
  • the second data variation range may be obtained according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration. It is also possible to obtain the second data variation range according to the data to be quantized and the inverse quantization data corresponding to the data to be quantized in the current iteration.
  • the second data variation amplitude diff bit between the data to be quantized and the dequantized data corresponding to the data to be quantized in the current iteration can be calculated according to formula (30). It is also possible to use other error calculation methods to calculate the second data variation range diff bit between the data to be quantized and the dequantized data. This disclosure does not limit this.
  • z i is the data to be quantized
  • z i (n) is the inverse quantized data corresponding to the data to be quantized.
  • the second data change range can be used to measure the change trend of the data bit width corresponding to the data to be quantified. The larger the second data change range is, the more likely the data to be quantized need to update the corresponding data bit width, and the interval is required. The shorter the iteration is to update, the greater the second data change range, and the smaller the target iteration interval is required.
  • the second data variation range is obtained according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration.
  • the quantization parameter of the data is obtained according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration.
  • the second data change range can be used to measure the change demand of the data bit width
  • the target iteration interval calculated according to the first data change range and the second data change range can track the changes of the point position and the data bit width at the same time, and the target iteration The interval can also be more in line with the data quantification requirements of the data to be quantified.
  • obtaining the second data variation range according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration may include:
  • the square of the error is determined as the second data variation range.
  • the second data change range diff update2 can be calculated using formula (31):
  • is the fourth parameter
  • the fourth parameter may be a hyperparameter
  • different quantization parameters can be obtained by using different data bit widths, and then different quantized data can be obtained, and different second data variation ranges can be generated.
  • the second data change range can be used to measure the change trend of the data bit width. The larger the second data change range, the shorter the target iteration interval is needed to update the data bit width more frequently, that is, the target iteration interval needs to be smaller.
  • determining the target iteration interval corresponding to the data to be quantized according to the first data variation amplitude and the second data variation amplitude of the data to be quantized may include:
  • the target iteration interval can be calculated according to formula (32):
  • is the second parameter
  • is the third parameter
  • the second parameter and the third parameter may be hyperparameters.
  • the target iteration interval obtained by using the first data change range and the second data change range can simultaneously measure the change trend of the data bit width and the point position.
  • the change trend of one of the two is larger, Then the target iteration interval can be changed accordingly.
  • the target iteration interval can simultaneously track changes in data bit width and point position and make corresponding adjustments.
  • the quantization parameter updated according to the target iteration interval can be more in line with the change trend of the target data, and finally the quantized data obtained according to the quantization parameter can be more in line with the quantization requirement.
  • obtaining the data change range of the data to be quantified in the current iteration and the historical iteration may include:
  • the data change range of the data to be quantified in the current iteration and the historical iteration is obtained, and the update period includes at least one iteration.
  • the data to be quantified varies greatly. If the target iteration interval is calculated in multiple iterations at the beginning of training or fine-tuning, the calculated target iteration interval may lose its usefulness. According to the preset update period, the target iteration interval is not calculated for each iteration within the update period, and the target iteration interval is not applicable so that multiple iterations use the same data bit width or point position.
  • the iteration progresses beyond the update period, that is, when the current iteration is outside the update period, obtain the data change range of the data to be quantified in the current iteration and historical iterations, and determine the data change range of the data to be quantified according to the data change range of the data to be quantified.
  • the target iteration interval corresponding to the data, so that the neural network updates the quantization parameter of the data to be quantized according to the target iteration interval. For example, if the preset update period is 100 generations, the target iteration interval is not calculated from the first generation to the 100th generation.
  • the iteration progresses to the 101st generation, that is, when the current iteration is the 101st generation, the current iteration is outside the update cycle.
  • the target iteration interval corresponding to the data to be quantized in the 101st generation, and the calculated target iteration interval is used in the 101st generation or a preset number of iterations with the 101st interval.
  • the update cycle can be counted from a preset generation number, for example, multiple iterations in the update cycle can be counted from the first generation, or multiple iterations in the update cycle can be counted from the Nth generation, which is not limited in the present disclosure.
  • the target iteration interval is calculated and used when the iteration progresses beyond the update period. It can avoid the problem that the target iteration interval is of little significance due to the large fluctuation of the data to be quantified in the initial stage of the training process or fine-tuning process of the neural network operation.
  • the neural network can be further improved when the target iteration interval is used. Operating efficiency.
  • the method may further include:
  • the point position of the data to be quantized in the current iteration is determined.
  • each cycle can include multiple iterations.
  • the data used for neural network calculations is completely calculated once into a cycle.
  • the weight changes of the neural network tend to stabilize.
  • the neurons, weights, bias, and gradient waiting for quantified data tend to stabilize.
  • the data to be quantized stabilizes, the data bit width and quantization parameters of the data to be quantized also stabilize.
  • the fine-tuning process after the fine-tuning is stable, the data bit width and quantization parameters of the data to be quantized also tend to be stable.
  • the preset period can be determined according to the period of training stability or fine-tuning stability.
  • the period after the period where the training is stable or the fine-tuning stable period can be determined as the preset period.
  • the stable training period is the Mth period, and the periods after the Mth period can be used as the preset period.
  • a target iteration interval can be calculated every interval, and the data bit width or quantization parameter can be adjusted once according to the calculated target iteration interval to reduce the update times of the data bit width or quantization parameter and improve the performance of the neural network. operating efficiency.
  • the preset period is the period after the Mth period.
  • the target iteration interval calculated according to the Pth iteration in the Mth cycle ends at the Qth iteration in the M+1th cycle.
  • the target iteration interval I m+1 corresponding to it is calculated according to the Q m+ 1th iteration in the M+1th cycle.
  • a period interval can be set. After the training or fine-tuning of the neural network operation reaches a stable level, the quantization parameters such as the data bit width or the point position are updated every period according to the period interval.
  • the period interval can reduce the update times of the data bit width or point position after the training is stable or the fine-tuning is stable, while ensuring the quantization accuracy, it can improve the operating efficiency of the neural network.
  • steps in the flowcharts of FIGS. 2 and 5 are displayed in sequence as indicated by the arrows, these steps are not necessarily executed 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 part of the steps in Figure 2 and Figure 5 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. These sub-steps or The execution order of the stages is not necessarily carried out sequentially, but may be executed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.
  • the embodiments of the present disclosure also provide a non-volatile computer-readable storage medium on which computer program instructions are stored.
  • the computer program instructions are executed by a processor, the above-mentioned neural network data quantization processing method is realized.
  • Fig. 6 shows a block diagram of a neural network quantization device according to an embodiment of the present disclosure.
  • the device is applied to a terminal including the processor 100 shown in FIG. 1, and the terminal is used to run a neural network to perform target tasks.
  • the device includes a data determination module 61, a data quantization module 62, and a result determination module 63.
  • a certain processing unit 101 is provided with a data determination module 61, a data quantization module 62, and a result determination module 63.
  • the data determination module 61, the data quantization module 62, and the result determination module 63 are provided in different processing units 101, respectively.
  • the storage unit 102 is used to store data related to the operation of the data determining module 61, the data quantizing module 62, and the result determining module 63, such as the data to be quantized, the quantization parameter, the data bit width, and the like.
  • the data determination module 61 determines a plurality of data to be quantified from the target data according to the target task and/or the accuracy requirements of the terminal, each of the data to be quantified is a subset of the target data, and the target
  • the data is any kind of data to be quantified to be calculated in the layer to be quantized of the neural network, and the data to be calculated includes at least one of input neurons, weights, biases, and gradients;
  • the data quantization module 62 quantizes each of the data to be quantized according to the corresponding quantization parameter to obtain quantized data corresponding to each of the data to be quantized;
  • the result determining module 63 obtains the quantization result of the target data according to the quantization data corresponding to each of the data to be quantized, so that the layer to be quantized performs operations according to the quantization result of the target data.
  • the data determining module includes at least one of the following sub-modules:
  • the first determining sub-module determines the target data in one or more layers to be quantized as a piece of data to be quantized according to the target task and/or the accuracy requirements of the terminal;
  • the second determining sub-module determines the same type of data to be calculated in one or more layers to be quantized as one data to be quantized according to the target task and/or the accuracy requirements of the terminal;
  • the third determining sub-module determines the data in one or more channels in the target data corresponding to the layer to be quantized as one data to be quantized according to the target task and/or the accuracy requirements of the terminal;
  • a fourth determining sub-module determine one or more batches of data corresponding to the target data of the layer to be quantized as one data to be quantized;
  • the fifth determining sub-module determines the division size of the divided data according to the target task and/or the accuracy requirements of the terminal, and divides the target data in the corresponding layer to be quantized into one or more data to be quantized according to the division size .
  • the device further includes:
  • the data bit width determination module determines the data bit width corresponding to the data to be quantified according to the target task and/or the accuracy requirements of the terminal;
  • the parameter determination module calculates the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width.
  • the parameter determination module includes:
  • the first point position determination sub-module when the quantization parameter does not include the offset, obtain the first value of each of the data to be quantized according to the maximum value of the absolute value in each of the data to be quantized and the corresponding data bit width. Class point location.
  • the parameter determination module includes:
  • the first maximum value determination sub-module when the quantization parameter does not include an offset, obtain the maximum value of the quantized data according to each of the data to be quantized and the corresponding data bit width;
  • the first scaling factor determining sub-module obtains the first type scaling factor of each data to be quantized according to the maximum absolute value of each data to be quantized and the maximum value of the quantized data.
  • the parameter determination module includes:
  • the second point position determination sub-module when the quantization parameter includes an offset, obtains the second value of each of the data to be quantized according to the maximum value, the minimum value and the corresponding data bit width in each of the data to be quantized Class point location.
  • the parameter determination module includes:
  • the second maximum value determining sub-module when the quantization parameter includes an offset, obtain the maximum value of the quantized data according to each of the data to be quantized and the corresponding data bit width;
  • the first scaling factor determining sub-module obtains the second type scaling factor of each of the data to be quantized according to the maximum value, the minimum value and the maximum value of the quantized data in each of the data to be quantized.
  • the parameter determination module includes:
  • the offset determining sub-module obtains the offset of each data to be quantized according to the maximum value and the minimum value in each of the data to be quantized.
  • the device further includes:
  • the first quantization error determination module determines the quantization error corresponding to each data to be quantized according to each data to be quantized and the quantized data corresponding to each data to be quantized;
  • the adjustment bit width determination module adjusts the data bit width corresponding to each data to be quantized according to the quantization error and error threshold corresponding to each data to be quantized to obtain the adjustment bit width corresponding to each data to be quantized;
  • the adjustment quantization parameter determination module updates the data bit width corresponding to each of the data to be quantized to the corresponding adjustment bit width, and calculates the corresponding adjustment quantization parameter according to each of the data to be quantized and the corresponding adjustment bit width, so that each The data to be quantized is quantized according to the corresponding adjusted quantization parameter.
  • the adjustment bit width determination module includes:
  • the first adjustment bit width determination sub-module when the quantization error is greater than a first error threshold, increases the corresponding data bit width to obtain the corresponding adjustment bit width.
  • the device further includes:
  • the first adjusted quantization error module calculates the adjusted quantization error of each of the data to be quantized according to each of the data to be quantized and the corresponding adjustment bit width;
  • the first adjustment bit width cyclic determination module continues to increase the corresponding adjustment bit width according to the adjusted quantization error and the first error threshold, until the adjusted quantization error is less than or equal to the first error Threshold.
  • the adjustment bit width determination module includes:
  • the second adjustment bit width determination sub-module when the quantization error is less than a second error threshold, increase the corresponding data bit width to obtain the corresponding adjustment bit width, and the second error threshold is less than the first error Threshold.
  • the device further includes:
  • a second adjusted quantization error module which calculates the adjusted quantization error of the to-be-quantized data according to the adjustment bit width and the to-be-quantized data;
  • the second adjustment bit width cyclic determination module continues to reduce the adjustment bit width according to the adjusted quantization error and the second error threshold, until the adjusted quantization calculated according to the adjustment bit width and the data to be quantized The error is greater than or equal to the second error threshold.
  • the device in the fine-tuning phase and/or training phase of the neural network operation, the device further includes:
  • the first data change range determination module which obtains the data change range of the data to be quantified in the current iteration and the historical iteration, where the historical iteration is the iteration before the current iteration;
  • the target iteration interval determination module determines the target iteration interval corresponding to the to-be-quantized data according to the data change range of the to-be-quantized data, so that the to-be-quantized layer updates the quantization of the to-be-quantized data according to the target iteration interval.
  • the target iteration interval includes at least one iteration.
  • the device further includes:
  • the first target iteration interval application module determines, according to the data bit width of the data to be quantized in the current iteration, the data bit width corresponding to the iteration of the data to be quantized in the target iteration interval, so that the nerve
  • the network determines the quantization parameter according to the data bit width corresponding to the iteration of the data to be quantized within the target iteration interval.
  • the device further includes:
  • the second target iteration interval application module determines the point position corresponding to the iteration of the to-be-quantized data within the target iteration interval according to the point position corresponding to the current iteration of the to-be-quantized data, where the point position includes the first Point position of the first type and/or point position of the second type.
  • the first data variation range determination module includes:
  • the sliding average calculation sub-module calculates the point position of the data to be quantified corresponding to each iteration interval according to the point position of the data to be quantified in the current iteration and the point position of the historical iteration corresponding to the current iteration determined according to the historical iteration interval. Sliding average value, where the point position includes a first-type point position and/or a second-type point position;
  • the first data variation range determination sub-module obtains the first data according to the first moving average value of the point position of the current iteration of the data to be quantified and the second moving average value of the point position corresponding to the iteration in the previous iteration interval Range of change
  • the target iteration interval determination module includes:
  • the first target iteration interval determination sub-module determines the target iteration interval corresponding to the data to be quantized according to the amplitude of the first data change, so that the neural network updates the quantization of the data to be quantized according to the target iteration interval parameter.
  • the first data variation range determination submodule includes:
  • the first amplitude determination sub-module calculates the difference between the first sliding average and the second sliding average; and determines the absolute value of the difference as the first data variation amplitude.
  • the device further includes:
  • the second data variation range determination module obtains the second data variation range according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration;
  • the target iteration interval determination module includes:
  • the second target iteration interval determination sub-module determines the target iteration interval corresponding to the to-be-quantized data according to the first data change range and the second data change range of the to-be-quantized data, so that the neural network is based on the
  • the target iteration interval updates the quantization parameter of the data to be quantized.
  • the second data variation range determination module includes:
  • the second amplitude determination sub-module calculates the error between the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration; and determines the square of the error as the second data variation amplitude.
  • the second target iteration interval determination submodule includes:
  • the interval determination sub-module determines the target iteration interval corresponding to the data to be quantified according to the maximum value of the first data change range and the second data change range.
  • the first data variation range determination module includes:
  • the second data change range determination submodule obtains the data change range of the data to be quantified in the current iteration and the historical iteration when the current iteration is outside the update period, and the update period includes at least one iteration.
  • the device further includes:
  • the cycle interval determination module when the current iteration is within a preset cycle, determines the cycle interval according to the current iteration, the iteration corresponding to the current iteration in the next cycle of the preset cycle, and the iteration interval corresponding to the current iteration;
  • the first period interval application module determines the data bit width of the data to be quantized in the iteration within the period interval according to the data bit width corresponding to the data to be quantized in the current iteration; or
  • the second cycle interval application module determines the point position of the data to be quantized in the iteration within the cycle interval according to the point position corresponding to the data to be quantized in the current iteration.
  • the neural network quantization device determines multiple data to be quantized from the target data according to the accuracy requirements of the target task and/or terminal, and uses the corresponding quantization parameters to perform the respective operations on the multiple data to be quantized in the target data. Quantification, while ensuring accuracy, reduces the storage space occupied by stored data, ensures the accuracy and reliability of the calculation results, and can improve the efficiency of calculations. Quantization also reduces the size of the neural network model and reduces The performance requirements of the terminal running the neural network model enable the neural network model to be applied to terminals such as mobile phones with relatively limited computing power, size, and power consumption.
  • 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.
  • a non-volatile computer-readable storage medium on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the above neural network quantization method is realized.
  • 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. 7 shows a structural block diagram of a board according to an embodiment of the present disclosure.
  • the above-mentioned board card may also include other supporting components, including but not limited to: a storage device 390, an interface device 391, and a 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 unit 102 in the above-mentioned processor 100 may include one or more groups of storage units 393.
  • the storage unit 102 includes a group of storage units 393, multiple processing units 101 share the storage unit 393 for data storage.
  • 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.
  • a neural network quantification method applied to a terminal, the terminal is used to run a neural network to perform a target task, the method includes:
  • multiple data to be quantified are determined from the target data, each of the data to be quantified is a subset of the target data, and the target data is the nerve Any kind of data to be quantified in the to-be-quantized layer of the network, where the data to be calculated includes at least one of input neurons, weights, biases, and gradients;
  • multiple data to be quantified are determined from the target data, including at least one of the following:
  • the division size of the divided data is determined according to the target task and/or the accuracy requirements of the terminal, and the target data corresponding to the layer to be quantized is divided into one or more data to be quantized according to the division size.
  • Clause A3 The method according to Clause A1 or Clause A2, the method further comprising:
  • the corresponding quantization parameter is calculated according to each of the data to be quantized and the corresponding data bit width.
  • Clause A4 The method according to clause A3, wherein the calculation of the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width includes:
  • the first-type point position of each data to be quantized is obtained according to the maximum absolute value of each data to be quantized and the corresponding data bit width.
  • Clause A5. The method according to clause A3, wherein the calculation of the corresponding quantization parameter based on each of the data to be quantized and the corresponding data bit width includes:
  • the first-type scaling coefficient of each data to be quantized is obtained.
  • the position of the second type point of each data to be quantized is obtained according to the maximum value, the minimum value and the corresponding data bit width in each of the data to be quantized.
  • the quantization parameter includes an offset
  • the second-type scaling coefficient of each data to be quantized is obtained.
  • the offset of each data to be quantized is obtained.
  • Clause A9 The method according to any one of Clauses A1 to A8, the method further comprising:
  • the data bit width corresponding to each of the data to be quantized is updated to the corresponding adjustment bit width, and the corresponding adjusted quantization parameter is calculated according to each of the data to be quantized and the corresponding adjustment bit width, so that each of the data to be quantized is based on The corresponding adjusted quantization parameter is quantized.
  • the corresponding data bit width is increased to obtain the corresponding adjustment bit width.
  • Clause A11 The method according to Clause A9 or 10, the method further comprising:
  • the corresponding data bit width is increased to obtain the corresponding adjustment bit width, and the second error threshold is less than the first error threshold.
  • Clause A14 The method according to any one of clauses A1 to A13, during the fine-tuning phase and/or training phase of the neural network operation, the method further includes:
  • the target iteration interval corresponding to the data to be quantized is determined, so that the layer to be quantized updates the quantization parameter of the data to be quantized according to the target iteration interval, and the target iteration The interval includes at least one iteration.
  • Clause A15 The method according to Clause A14, the method further comprising:
  • the data bit width corresponding to the iteration of the data to be quantized in the target iteration interval is determined, so that the neural network is based on the data to be quantized.
  • the data bit width corresponding to the iteration within the target iteration interval determines the quantization parameter.
  • Clause A16 The method according to Clause A15, the method further comprising:
  • the point position corresponding to the current iteration of the data to be quantized is determined, and the point position includes the first-type point position and/or the first type point position.
  • the second-class point location is determined.
  • the obtaining the data change range of the data to be quantified in the current iteration and the historical iteration includes:
  • the moving average of the point positions of the data to be quantified corresponding to each iteration interval is calculated.
  • the location includes the first-category point location and/or the second-category point location;
  • the determining the target iteration interval corresponding to the to-be-quantized data according to the data change range of the to-be-quantized data so that the neural network updates the quantization parameter of the to-be-quantized data according to the target iteration interval includes:
  • Clause A18 The method according to clause A17, according to the first moving average of the point position of the current iteration of the data to be quantified, and the second moving average of the point position of the corresponding iteration in the previous iteration interval, Obtain the first data change range, including:
  • the absolute value of the difference is determined as the first data variation range.
  • Clause A19 The method according to Clause A18, the method further comprising:
  • the determining the target iteration interval corresponding to the to-be-quantized data according to the data change range of the to-be-quantized data so that the neural network updates the quantization parameter of the to-be-quantized data according to the target iteration interval includes:
  • Clause A20 The method according to clause A19, wherein the obtaining a second data variation range according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration includes:
  • the square of the error is determined as the second data variation range.
  • the obtaining the data change range of the data to be quantified in the current iteration and the historical iteration includes:
  • the data change range of the data to be quantified in the current iteration and the historical iteration is obtained, and the update period includes at least one iteration.
  • the point position of the data to be quantized in the current iteration is determined.
  • a neural network quantification device applied to a terminal, the terminal is used to run a neural network to perform a target task, and the device includes:
  • the data determining module determines a plurality of data to be quantified from the target data according to the target task and/or the accuracy requirements of the terminal, each of the data to be quantified is a subset of the target data, and the target data Is any kind of data to be quantified to be calculated in the layer to be quantized of the neural network, and the data to be calculated includes at least one of input neurons, weights, biases, and gradients;
  • a data quantization module to quantize each of the data to be quantized according to the corresponding quantization parameter to obtain quantized data corresponding to each of the data to be quantized;
  • the result determining module obtains the quantization result of the target data according to the quantization data corresponding to each of the data to be quantized, so that the layer to be quantized performs operations according to the quantization result of the target data.
  • the first determining sub-module determines the target data in one or more layers to be quantized as a piece of data to be quantized according to the target task and/or the accuracy requirements of the terminal;
  • the second determining sub-module determines the same type of data to be calculated in one or more layers to be quantized as one data to be quantized according to the target task and/or the accuracy requirements of the terminal;
  • the third determining sub-module determines the data in one or more channels in the target data corresponding to the layer to be quantized as one data to be quantized according to the target task and/or the accuracy requirements of the terminal;
  • a fourth determining sub-module determine one or more batches of data corresponding to the target data of the layer to be quantized as one data to be quantized;
  • the fifth determining sub-module determines the division size of the divided data according to the target task and/or the accuracy requirements of the terminal, and divides the target data in the corresponding layer to be quantized into one or more data to be quantized according to the division size .
  • the data bit width determination module determines the data bit width corresponding to the data to be quantified according to the target task and/or the accuracy requirements of the terminal;
  • the parameter determination module calculates the corresponding quantization parameter according to each of the data to be quantized and the corresponding data bit width.
  • the first point position determination sub-module when the quantization parameter does not include the offset, obtain the first value of each of the data to be quantized according to the maximum value of the absolute value in each of the data to be quantized and the corresponding data bit width. Class point location.
  • parameter determination module includes:
  • the first maximum value determination sub-module when the quantization parameter does not include an offset, obtain the maximum value of the quantized data according to each of the data to be quantized and the corresponding data bit width;
  • the first scaling factor determining sub-module obtains the first type scaling factor of each data to be quantized according to the maximum absolute value of each data to be quantized and the maximum value of the quantized data.
  • the second point position determination sub-module when the quantization parameter includes an offset, obtains the second value of each of the data to be quantized according to the maximum value, the minimum value and the corresponding data bit width in each of the data to be quantized Class point location.
  • the second maximum value determining sub-module when the quantization parameter includes an offset, obtain the maximum value of the quantized data according to each of the data to be quantized and the corresponding data bit width;
  • the first scaling factor determining sub-module obtains the second type scaling factor of each of the data to be quantized according to the maximum value, the minimum value and the maximum value of the quantized data in each of the data to be quantized.
  • the offset determining sub-module obtains the offset of each data to be quantized according to the maximum value and the minimum value in each of the data to be quantized.
  • the first quantization error determination module determines the quantization error corresponding to each of the data to be quantized according to each of the data to be quantized and the quantized data corresponding to each of the data to be quantized;
  • the adjustment bit width determination module adjusts the data bit width corresponding to each data to be quantized according to the quantization error and error threshold corresponding to each data to be quantized to obtain the adjustment bit width corresponding to each data to be quantized;
  • the adjustment quantization parameter determination module updates the data bit width corresponding to each of the data to be quantized to the corresponding adjustment bit width, and calculates the corresponding adjustment quantization parameter according to each of the data to be quantized and the corresponding adjustment bit width, so that each The data to be quantized is quantized according to the corresponding adjusted quantization parameter.
  • the first adjustment bit width determination sub-module when the quantization error is greater than a first error threshold, increases the corresponding data bit width to obtain the corresponding adjustment bit width.
  • the first adjusted quantization error module calculates the adjusted quantization error of each of the data to be quantized according to each of the data to be quantized and the corresponding adjustment bit width;
  • the first adjustment bit width cyclic determination module continues to increase the corresponding adjustment bit width according to the adjusted quantization error and the first error threshold, until the adjusted quantization error is less than or equal to the first error Threshold.
  • the second adjustment bit width determination sub-module when the quantization error is less than a second error threshold, increase the corresponding data bit width to obtain the corresponding adjustment bit width, and the second error threshold is less than the first error Threshold.
  • a second adjusted quantization error module which calculates the adjusted quantization error of the to-be-quantized data according to the adjustment bit width and the to-be-quantized data;
  • the second adjustment bit width cyclic determination module continues to reduce the adjustment bit width according to the adjusted quantization error and the second error threshold, until the adjusted quantization calculated according to the adjustment bit width and the data to be quantized The error is greater than or equal to the second error threshold.
  • the device in the fine-tuning phase and/or training phase of the neural network operation, the device further includes:
  • the first data change range determination module which obtains the data change range of the data to be quantified in the current iteration and the historical iteration, where the historical iteration is the iteration before the current iteration;
  • the target iteration interval determination module determines the target iteration interval corresponding to the to-be-quantized data according to the data change range of the to-be-quantized data, so that the to-be-quantized layer updates the quantization of the to-be-quantized data according to the target iteration interval.
  • the target iteration interval includes at least one iteration.
  • the first target iteration interval application module determines, according to the data bit width of the data to be quantized in the current iteration, the data bit width corresponding to the iteration of the data to be quantized in the target iteration interval, so that the nerve
  • the network determines the quantization parameter according to the data bit width corresponding to the iteration of the data to be quantized within the target iteration interval.
  • the second target iteration interval application module determines the point position corresponding to the iteration of the to-be-quantized data within the target iteration interval according to the point position corresponding to the current iteration of the to-be-quantized data, where the point position includes the first Point position of the first type and/or point position of the second type.
  • Clause A40 The device according to clause A37, wherein the first data variation range determination module includes:
  • the sliding average calculation sub-module calculates the point position of the data to be quantified corresponding to each iteration interval according to the point position of the data to be quantified in the current iteration and the point position of the historical iteration corresponding to the current iteration determined according to the historical iteration interval. Sliding average value, where the point position includes a first-type point position and/or a second-type point position;
  • the first data variation range determination sub-module obtains the first data according to the first moving average value of the point position of the current iteration of the data to be quantified and the second moving average value of the point position corresponding to the iteration in the previous iteration interval Range of change
  • the target iteration interval determination module includes:
  • the first target iteration interval determination sub-module determines the target iteration interval corresponding to the data to be quantized according to the amplitude of the first data change, so that the neural network updates the quantization of the data to be quantized according to the target iteration interval parameter.
  • the first amplitude determination sub-module calculates the difference between the first sliding average and the second sliding average; and determines the absolute value of the difference as the first data variation amplitude.
  • the second data variation range determination module obtains the second data variation range according to the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration;
  • the target iteration interval determination module includes:
  • the second target iteration interval determination sub-module determines the target iteration interval corresponding to the to-be-quantized data according to the first data change range and the second data change range of the to-be-quantized data, so that the neural network is based on the
  • the target iteration interval updates the quantization parameter of the data to be quantized.
  • the second amplitude determination sub-module calculates the error between the data to be quantized and the quantized data corresponding to the data to be quantized in the current iteration; and determines the square of the error as the second data variation amplitude.
  • the interval determination sub-module determines the target iteration interval corresponding to the data to be quantified according to the maximum value of the first data change range and the second data change range.
  • Clause A45 The device according to any one of clauses A37 to A44, wherein the first data variation range determination module includes:
  • the second data change range determination submodule obtains the data change range of the data to be quantified in the current iteration and the historical iteration when the current iteration is outside the update period, and the update period includes at least one iteration.
  • the cycle interval determination module when the current iteration is within a preset cycle, determines the cycle interval according to the current iteration, the iteration corresponding to the current iteration in the next cycle of the preset cycle, and the iteration interval corresponding to the current iteration;
  • the first period interval application module determines the data bit width of the data to be quantized in the iteration within the period interval according to the data bit width corresponding to the data to be quantized in the current iteration; or
  • the second cycle interval application module determines the point position of the data to be quantized in the iteration within the cycle interval according to the point position corresponding to the data to be quantized in the current iteration.
  • An artificial intelligence chip comprising the neural network quantification device according to any one of clauses A24 to A46.
  • Clause A48 An electronic device including the artificial intelligence chip as described in Clause A47.
  • a board card comprising: a storage device, an interface device and a control device, and the artificial intelligence chip as described in Clause A47;
  • 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.
  • Clause A51 A non-volatile computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implements the neural network quantification method described in any one of Clauses A1 to A23 .

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Data Mining & Analysis (AREA)
  • Artificial Intelligence (AREA)
  • Evolutionary Computation (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Molecular Biology (AREA)
  • General Health & Medical Sciences (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Neurology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Biology (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

本公开涉及一种数据处理方法、装置、计算机设备和存储介质。其所公开的板卡包括:存储器件、接口装置和控制器件以及包括数据处理装置的人工智能芯片;其中,人工智能芯片与存储器件、控制器件以及接口装置分别连接;存储器件,用于存储数据;接口装置,用于实现人工智能芯片与外部设备之间的数据传输;控制器件,用于对人工智能芯片的状态进行监控。本公开实施例所提供的数据处理方法、装置、计算机设备和存储介质,利用对应的量化参数对待量化数据进行量化,在保证精度的同时,减小了存储数据所占用的存储空间,保证了运算结果的准确性和可靠性,且能够提高运算的效率。

Description

数据处理方法、装置、计算机设备和存储介质 技术领域
本公开涉及计算机技术领域,特别是涉及一种神经网络量化方法、装置、计算机设备和存储介质。
背景技术
神经网络(neural network,NN)是一种模仿生物神经网络的结构和功能的数学模型或计算模型。神经网络通过样本数据的训练,不断修正网络权值和阈值使误差函数沿负梯度方向下降,逼近期望输出。它是一种应用较为广泛的识别分类模型,多用于函数逼近、模型识别分类、数据压缩和时间序列预测等。神经网络被应用到图像识别、语音识别、自然语言处理等领域中,然而,随着神经网络复杂度提高,数据的数据量和数据维度都在不断增大,不断增大的数据量等对运算装置的数据处理效率、存储装置的存储容量及访存效率等提出了较大的挑战。相关技术中,采用固定位宽对神经网络的运算数据进行量化,即将浮点型的运算数据转换为定点型的运算数据,以实现神经网络的运算数据的压缩。但相关技术中针对整个神经网络采用相同的量化方案,但神经网络的不同运算数据之间可能存在较大的差异,往往会导致精度较低,影响数据运算结果。
发明内容
基于此,有必要针对上述技术问题,提供一种神经网络量化方法、装置、计算机设备和存储介质。
根据本公开的一方面,提供了一种神经网络量化方法,应用于终端,所述终端用于运行神经网络以执行目标任务,所述方法包括:
根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;
将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;
根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
根据本公开的另一方面,提供了一种神经网络量化装置,,应用于终端,所述终端用于运行神经网络以执行目标任务,所述装置包括:
数据确定模块,根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;
数据量化模块,将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;
结果确定模块,根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
根据本公开的另一方面,提供了一种人工智能芯片,其特征在于,所述芯片包括上述神经网络量化装置。
根据本公开的另一方面,提供了一种电子设备,所述电子设备包括上述人工智能芯片。
根据本公开的另一方面,提供了一种板卡,所述板卡包括:存储器件、接口装置和控制器件以及上述人工智能芯片;
其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;
所述存储器件,用于存储数据;
所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;
所述控制器件,用于对所述人工智能芯片的状态进行监控。
根据本公开的另一方面,提供了一种非易失性计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现上述神经网络量化方法。
本公开实施例所提供的神经网络量化方法、装置、计算机设备和存储介质,该方法包括:根据所述目标任务和/或所述终端的精度需求,从所述待量化层的目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。本公开实施例所提供的神经网络量化方法、装置、计算机设备和存储介质,根据目标任务和/或终端的精度需求从目标数据中确定多个待量化数据,利用对应的量化参数对待量化数据进行量化,在保证精度的同时,减小了存储数据所占用的存储空间,保证了运算结果的准确性和可靠性,且能够提高运算的效率,且量化同样缩减了神经网络模型的大小,降低了对运行该神经网络模型的终端的性能要求。
通过权要中的技术特征进行推导,能够达到对应背景技术中的技术问题的有益效果。根据下面参考附图对示例性实施例的详细说明,本公开的其它特征及方面将变得清楚。
附图说明
包含在说明书中并且构成说明书的一部分的附图与说明书一起示出了本公开的示例性实施例、特征和方面,并且用于解释本公开的原理。
图1示出根据本公开实施例的神经网络量化方法的处理器的示意图。
图2示出根据本公开实施例的神经网络量化方法的流程图。
图3示出根据本公开实施例的对称的定点数表示的示意图。
图4示出根据本公开实施例的引入偏移量的定点数表示的示意图。
图5示出根据本公开实施例的神经网络量化方法的流程图。
图6示出根据本公开一实施例的神经网络量化装置的框图。
图7示出根据本公开实施例的板卡的结构框图。
具体实施方式
下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本公开一部分实施例,而不是全部的实施例。基于本公开中的实施例,本领域技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。
应当理解,本公开的权利要求、说明书及附图中的术语“第一”、“第二”等是用于区别不同对象,而不是用于描述特定顺序。本公开的说明书和权利要求书中使用的术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。
还应当理解,在此本公开说明书中所使用的术语仅仅是出于描述特定实施例的目的,而并不意在限定本公开。如在本公开说明书和权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。还应当进一步理解,在本公开说明书和权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。
如在本说明书和权利要求书中所使用的那样,术语“如果”可以依据上下文被解释为“当...时”或“一旦”或“响应于确定”或“响应于检测到”。类似地,短语“如果确定”或“如果检测到[所描述条件或事件]”可以依据上下文被解释为意指“一旦确定”或“响应于确定”或“一旦检测到[所描述条件或事件]”或“响应于检测到[所描述条件或事件]”。
随着神经网络运算复杂度的提高,数据的数据量和数据维度也在不断增大,而传统的神经网络算 法通常采用浮点数据格式来执行神经网络运算,这就使得不断增大的数据量等对运算装置的数据处理效率、存储装置的存储容量及访存效率等提出了较大的挑战。为解决上述问题,相关技术中,对神经网络运算过程涉及的全部数据均由浮点数转化定点数,但由于不同的数据之间具有差异性,或者,同一数据在不同阶段具有差异性,仅“由浮点数转化定点数”时,往往会导致精度不够,从而会影响运算结果。
神经网络中待运算数据通常为浮点数据格式或精度较高的定点数据格式,在承载神经网络的装置中运行神经网络时,浮点数据格式或精度较高的定点数据格式的各种待运算数据,导致神经网络运行的运算量和访存开销都较大。为提高运算效率,本公开实施例所提供的神经网络量化方法、装置、计算机设备和存储介质,可以根据不同类待运算数据进行神经网络中的待运算数据的局部量化,量化后的数据格式通常为位宽较短、精度较低的定点数据格式。利用精度较低的量化后数据执行神经网络的运算,可以降低运算量和访存量。量化后的数据格式可以为位宽较短的定点数据格式。可以将浮点数据格式的待运算数据量化为定点数据格式的待运算数据,也可以将精度较高的定点格式的待运算数据量化为精度较低的定点格式的待运算数据。根据目标任务和/或终端的精度需求,从目标数据中确定出多个待量化数据,利用对应的量化参数对待量化数据进行量化,在保证精度的同时,减小了存储数据所占用的存储空间,保证了运算结果的准确性和可靠性,且能够提高运算的效率,且量化同样缩减了神经网络模型的大小,降低了对运行该神经网络模型的终端的性能要求,使神经网络模型可以应用于算力、体积、功耗相对受限的手机等终端。
可以理解的是,量化精度即量化后数据与量化前数据之间的误差的大小。量化精度可以影响神经网络运算结果的准确度。量化精度越高,运算结果的准确率越高,但运算量更大、访存开销也更大。相较于位宽较短的量化后数据,位宽较长的量化后数据的量化精度更高,用于执行神经网络的运算时准确率也更高。但在用于进行神经网络的运算时,位宽较长的量化后数据运算量更大、访存开销也较大,运算效率较低。同理,对于相同的待量化数据,采用不同的量化参数得到的量化后数据有不同的量化精度,将产生不同的量化结果,对运算效率和运算结果的准确率也会带来不同的影响。对神经网络进行量化,在运算效率和运算结果的准确率之间进行平衡,可以采用更加符合待运算数据的数据特征的量化后数据位宽和量化参数。
神经网络中的待运算数据可以包括权值、神经元、偏置、梯度中的至少一种。待运算数据为包含多个元素的矩阵。在传统的神经网络量化中,通常将待运算数据的整体进行量化后进行运算。而在利用量化后的待运算数据进行运算时,通常利用整体量化后的待运算数据中的一部分数据进行运算。例如,在卷积层,利用整体量化后的输入神经元进行卷积运算时,根据卷积核的维度和步长,在整体量化后的输入神经元中分别提取与卷积核的维度相当的量化后的神经元进行卷积运算。在全连接层,利用整体量化后的输入神经元进行矩阵乘运算时,在整体量化后的输入神经元中分别按行提取量化后的神经元进行矩阵乘的运算。因此,在传统的神经网络量化方法中,将待运算数据的整体进行量化后再按照部分量化后的数据进行运算,整体的运算效率较低。且将待运算数据的整体量化后再进行运算,需要将整体量化后的待运算数据进行存储,占用的存储空间较大,不能满足不同终端的精度需求,且不能满足终端利用神经网络执行不同任务的任务需求。
根据本公开实施例的神经网络量化方法可应用于处理器中,该处理器可以是通用处理器,例如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)芯片中的一种或组合。本公开对处理器的具体类型不作限制。
在一种可能的实现方式中,本公开中所提及的处理器可包括多个处理单元,每个处理单元可以独立运行所分配到的各种任务,如:卷积运算任务、池化任务或全连接任务等。本公开对处理单元及处理单元所运行的任务不作限制。
图1示出根据本公开实施例的神经网络量化方法的处理器的示意图。如图1所示,处理器100包括多个处理单元101以及存储单元102,多个处理单元101用于执行指令序列,存储单元102用于存储数据,可包括随机存储器(RAM,Random Access Memory)和寄存器堆。处理器100中的多个处理单元101既可共用部分存储空间,例如共用部分RAM存储空间和寄存器堆,又可同时拥有各自的存储空间。
图2示出根据本公开实施例的神经网络量化方法的流程图。如图2所示,该方法包括步骤S11至步骤S13。该方法可以应用于包括图1所示的处理器100的终端,终端用于运行神经网络以执行目标任务。其中,处理单元101用于执行步骤S11至步骤S13。存储单元102用于存储待量化数据、量化参数、数据位宽等与步骤S11至步骤S13的处理过程相关的数据。
在步骤S11中,根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种。
可以根据目标任务的任务类型、所需使用的待运算数据的数量、每个待运算数据的数据量,以及基于终端的计算精度、当前处理能力、存储能力等确定的精度需求,待运算数据所参与的运算类型等,确定从目标数据中确定出多个待量化数据的方式。
神经网络中的待量化层可以为神经网络中的任意一层。可以根据需求将神经网络中的部分层或全部层确定为待量化层。当神经网络中包括多个待量化层时,各待量化层可以连续也可以不连续。根据神经网络的不同,待量化层的种类也可以不同,例如待量化层可以为卷积层、全连接层等,本公开对待量化层的数量及类型不作限定。
在一种可能的实现方式中,所述待运算数据包括神经元、权值、偏置、梯度中的至少一种。可以根据需求将待量化层中的神经元、权值、偏置、梯度中的至少一种进行量化。目标数据为任意一种待量化的待运算数据。例如,待运算数据为神经元、权值和偏置,需要将神经元和权值进行量化,则神经元为目标数据1,权值为目标数据2。
当待量化层中有多种目标数据时,针对每种目标数据可以采用本公开中的量化方法进行量化后,得到与各目标数据对应的量化数据,再利用各种目标数据的量化数据和不需要进行量化的待运算数据执行待量化层的运算。
神经网络运算的推理阶段可包括:将训练好的神经网络进行前向运算以完成设定任务的阶段。在神经网络的推理阶段,可以将神经元、权值、偏置和梯度中的至少一种作为待量化数据,根据本公开实施例中的方法进行量化后,利用量化后的数据完成待量化层的运算。
神经网络运算的微调阶段可包括:将训练好的神经网络进行预设数量迭代的前向运算和反向运算,进行参数的微调以适应设定任务的阶段。在神经网络运算的微调阶段,可以将神经元、权值、偏置、梯度中的至少一种,根据本公开实施例中的方法进行量化后,利用量化后的数据完成待量化层的前向运算或反向运算。
神经网络运算的训练阶段可包括:将初始化的神经网络进行迭代训练以得到训练好的神经网络的阶段,训练好的神经网络可执行特定任务。在神经网络的训练阶段,可以将神经元、权值、偏置、梯度中的至少一种,根据本公开实施例中的方法进行量化后,利用量化后的数据完成待量化层的前向运算或反向运算。
可以将一个目标数据中的子集作为待量化数据,可以按照不同的方式将目标数据划分为多个子集,将每个子集作为一个待量化数据。将一个目标数据划分为多个待量化数据。可以根据目标数据所要进行的运算类型,将目标数据划分为多个待量化数据。例如,目标数据需要进行卷积运算时,可以根据卷积核的高度和宽度,将目标数据划分为与卷积核对应的多个待量化数据。目标数据为需要进行矩阵乘运算的左矩阵时,可以将目标数据按行划分为多个待量化数据。可以一次将目标数据划分为多个待量化数据,也可以按照运算的顺序,将目标数据依次划分为多个待量化数据。
也可以根据预先设定的数据划分方式,将目标数据划分为多个待量化数据。例如,预先设定的数据划分方式可以为:按照固定的数据大小进行划分,或按照固定的数据形状进行划分。
将目标数据划分为多个待量化数据后,可以将各待量化数据分别进行量化,并根据各待量化数据量化后的数据进行运算。一个待量化数据所需的量化时间,短于目标数据的整体的量化时间,将其中一个待量化数据量化完毕后,即可以用量化后的数据执行后续的运算,而不用等目标数据中的所有待量化数据均量化完成后再执行运算。因此本公开中的目标数据的量化方法,可以提高目标数据的运算效率。
在步骤S12中,将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据。
待量化数据对应的量化参数可以为一个量化参数,也可以为多个量化参数。量化参数可以包括点位置等用于对待量化数据进行量化的参数。点位置可以用于确定量化后数据中小数点的位置。量化参数还可以包括缩放系数、偏移量等。
确定与待量化数据对应的量化参数的方式,可以包括:确定与目标数据对应的量化参数后,并将与目标数据对应的量化参数确定为待量化数据的量化参数的方式。当待量化层包括多个目标数据时,各目标数据均可以有与之对应的量化参数,且各目标数据对应的量化参数可以不同,也可以相同,本公开对此不作限定。将目标数据划分为多个待量化数据后,可以将目标数据对应的量化参数确定为各待量化数据对应的量化参数,此时各待量化数据对应的量化参数相同。
确定与待量化数据对应的量化参数的方式,也可以包括:直接确定各待量化数据对应的量化参数的方式。目标数据可以没有与之对应的量化参数,或目标数据可以有与之对应的量化参数但待量化数据不采用。可以直接为各待量化数据设定对应的量化参数。也可以根据待量化数据计算得到对应的量化参数。此时各待量化数据对应的量化参数可以相同也可以不同。例如,当待量化层为卷积层,目标数据为权重时,可以将权重按照通道划分为多个待量化权重数据,不同通道的待量化权重数据可以对应不同的量化参数。当各待量化数据对应的量化参数不同时,各待量化数据利用对应的量化参数进行量化后,所得到的量化结果需不影响目标数据的运算。
确定与目标数据对应的量化参数的方式、或确定与待量化数据对应的量化参数的方式,可以包括:查找预设的量化参数直接确定量化参数的方式、查找对应关系以确定量化参数的方式,或根据待量化数据计算得到量化参数的方式。以下以确定与待量化数据对应的量化参数的方式为例进行说明:
可以直接设定与待量化数据对应的量化参数。可以将设定好的量化参数存储于设定的存储空间。设定的存储空间可以为片上或片外的存储空间。例如,可以将设定好的量化参数存储于设定的存储空间。各待量化数据在进行量化时,可以在设定的存储空间提取对应的量化参数后进行量化。可以根据经验值设定与每种待量化数据对应的量化参数。也可以根据需求更新所存储的与每种待量化数据对应的量化参数。
可以根据各待量化数据的数据特征,通过查找数据特征与量化参数的对应关系,确定量化参数。例如,待量化数据的数据分布为稀疏和稠密时可以分别对应不同的量化参数。可以通过查找对应关系确定与待量化数据的数据分布对应的量化参数。
还可以根据各待量化数据,利用设定的量化参数计算方法,计算得到各待量化层对应的量化参数。例如,可以根据待量化数据的绝对值最大值和预设的数据位宽,利用取整算法计算得到量化参数中的点位置。
在步骤S13中,根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
可以利用设定的量化算法,根据量化参数对待量化数据进行量化,得到量化数据。例如,可以利用取整算法作为量化算法,可以根据数据位宽和点位置对待量化数据进行取整量化得到量化数据。其中,取整算法可以包括向上取整、向下取整、向零取整和四舍五入取整等。本公开对量化算法的具体实现方式不作限定。
各待量化数据可以分别采用对应的量化参数进行量化。由于与各待量化数据对应的量化参数更为贴合各待量化数据自身的特征,使得各待量化层的每种量化数据的量化精度更加符合目标数据的运算需求,也就更加符合待量化层的运算需求。在保证待量化层的运算结果准确率的前提下,能够提高待 量化层的运算效率,达到待量化层的运算效率和运算结果准确率之间的平衡。进一步的,将目标数据划分为多个待量化数据分别量化,可以在量化完一个待量化数据后,根据量化得到的量化结果执行运算的同时,可以进行第二个待量化数据的量化,从而在整体上提高目标数据的运算效率,也就提高了待量化层的计算效率。
可以将各待量化数据的量化数据进行合并后得到目标数据的量化结果。也可以将各待量化数据的量化数据进行设定的运算后得到目标数据的量化结果。例如可以将各待量化数据的量化数据按照设定的权重进行加权运算后得到目标数据的量化结果。本公开对此不作限定。
在神经网络的推理、训练和微调过程中,可以对待量化数据进行离线量化或在线量化。其中,离线量化可以为利用量化参数对待量化数据进行离线处理。在线量化可以为利用量化参数对待量化数据进行在线处理。例如,神经网络运行在人工智能芯片上,可以将待量化数据和量化参数发送至人工智能芯片之外的运算装置进行离线量化,或利用人工智能芯片之外的运算装置对预先得到的待量化数据和量化参数进行离线量化。而在人工智能芯片运行神经网络的过程中,人工智能芯片可以对待量化数据利用量化参数进行在线量化。本公开中对各待量化数据的量化过程为在线或离线不作限定。
在本实施例所提供的神经网络量化方法,应用于终端,所述终端用于运行神经网络以执行目标任务,所述方法包括:根据所述目标任务和/或所述终端的精度需求,从待量化层的目标数据中确定多个待量化数据,各待量化数据均为目标数据的子集,目标数据为待量化层的任意一种待量化的待运算数据,待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;将各待量化数据分别根据对应的量化参数进行量化,得到与各待量化数据对应的量化数据;根据与各待量化数据对应的量化数据得到目标数据的量化数据,以使待量化层根据目标数据的量化数据进行运算。将目标数据划分为多个待量化数据后,各待量化数据的量化过程与运算过程可以并行执行,从而可以提高目标数据的量化效率和运算效率,也可以提高待量化层直至提高整个神经网络的量化效率和运算效率。
下面给出步骤S11的五种实现方式示例,也即方式1-方式5以便于更好的理解步骤S11的实现过程。
方式1:根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的目标数据确定为一个待量化数据。
在神经网络包括多个待量化层时,可以根据目标任务和终端的精度需求确定终端每一次所能量化的数据的量化数据量,进而根据不同量化层中目标数据的数据量以及量化数据量,将一个或多个待量化层中的目标数据确定为一个待量化数据。例如,将一个待量化层中的输入神经元确定为一个待量化数据。
方式2:根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的同一种待运算数据确定为一个待量化数据。
在神经网络包括多个待量化层时,可以根据目标任务和终端的精度需求确定终端每一次所能量化的数据的量化数据量,进而根据不同量化层中目标数据的数据量以及量化数据量,将一个或多个待量化层中的某一种目标数据确定为一个待量化数据。例如,将全部待量化层中的输入神经元确定为一个待量化数据。
方式3:根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个通道中的数据确定为一个待量化数据。
在待量化层为卷积层时,待量化层中含有通道,可以根据通道以及根据目标任务和终端的精度需求所确定的终端每一次所能量化的数据的量化数据量,将一个或多个通道中的数据确定为一个待量化数据。例如,对于某个卷积层,可以将2个通道中的目标数据确定为一个待量化数据。或者可以将每一个通道中的目标数据确定为一个待量化数据。
方式4:根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个批数的数据确定为一个待量化数据;
在待量化层为卷积层时,在卷积层的输入神经元的维度可以包括批数(batch,B)、通道(channel,C)、高度(height,H)和宽度(width,W)。当输入神经元的批数为多个时,各批数的输入神经元可以看作维度为通道、高度和宽度的三维数据。各批数的输入神经元可以对应多个卷积核,各批数的输 入神经元的通道数,和与之对应的各卷积核的通道数一致。
对于任意一个批数的输入神经元,以及对于与该批数的输入神经元对应的多个卷积核中的任意一个卷积核,可以根据量化数据量和该批数的输入神经元的数据量,将该批次的输入神经元与该卷积核对应的部分数据(子集),确定为该批次的输入神经元与该卷积核对应的多个待量化数据。例如,假定目标数据B1有3个批数的数据,若将目标数据中一个批数的数据确定为一个待量化数据,则该目标数据B可以被划分为3个待量化数据。
可以根据卷积核的维度和步长,将输入神经元划分得到全部的待量化数据后,将各待量化数据并行地执行量化过程。由于待量化数据的数据量小于输入神经元,对一个待量化数据进行量化的计算量,小于对输入神经元进行整体量化的计算量,因此,本实施例中的量化方法可以提高输入神经元的量化速度,提高量化效率。也可以将输入神经元根据卷积核的维度和步长进行划分,依次得到各待量化数据后,将得到的各待量化数据分别与卷积核进行卷积运算。各待量化数据的量化过程和卷积运算过程可以并行执行,本实施例中的量化方法可以提高输入神经元的量化效率和运算效率。
方式5:根据所述目标任务和/或所述终端的精度需求确定划分数据的划分尺寸,将对应待量化层中的目标数据按照所述划分尺寸划分为一个或多个待量化数据。
可以根据目标任务和终端的精度需求确定终端的实时处理能力,可以包括:终端对目标数据进行量化的速度,对量化后数据进行运算的速度,对目标数据进行量化和运算时终端所能处理的数据量等表征终端处理目标数据的处理能力相关的信息。例如,可以根据对目标数据进行量化的速度和对量化后数据进行运算的速度,确定待量化数据的尺寸,以使得对待量化数据进行量化的时间与对量化后数据进行运算的速度相同,这样可以量化和运算同步进行,可以提高目标数据的运算效率。终端的实时处理能力越强,待量化数据的尺寸越大。
在本实施例中,可以根据需要对确定待量化数据的方式进行设置,待量化数据可以包括一种待运算数据如输入神经元(也可以是权值、偏置、梯度,以下以输入神经元为例进行说明),该待运算数据可以是某一个待量化层中的部分或全部输入神经元,也可以是多个待量化层中的、包括每个待量化层中的全部或部分输入神经元。待量化数据还可以是对应于待量化层某一个通道的全部或部分输入神经元,或者对应于待量化层几个通道的全部输入神经元。待量化数据也可以是某一个输入神经元的部分或全部等等。也就是说,可以根据任意的方式对目标数据进行划分,本公开对此不作限制。
在一种可能的实现方式中,在对目标数据进行量化的过程中可以采用与目标数据对应的量化参数进行量化。而将目标数据划分为多个待量化数据后,可以采用与各待量化数据对应的量化参数进行量化。与各待量化数据对应的量化参数,可以采用预设的方式或根据待量化数据计算的方式,无论采用何种方式确定与各待量化数据对应的量化参数,都可以使得各待量化数据的量化参数,更加符合待量化数据自身的量化需求。例如,当根据目标数据计算得到对应的量化参数时,可以利用目标数据中各元素的最大值和最小值计算得到量化参数。而在根据待量化数据计算得到对应的量化参数时,可以利用待量化数据中各元素的最大值和最小值计算得到量化参数,待量化数据的量化参数比目标数据的量化参数能够更加贴合待量化数据的数据特征,可以使得待量化数据的量化结果更加准确,量化精度更高。
在一种可能的实现方式中,该方法还可以包括:
根据所述目标任务和/或所述终端的精度需求,确定待量化数据对应的数据位宽;
根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数。
在该实现方式中,可以根据目标任务和终端的精度需求,确定满足需求的参考数据位宽或数据位宽参考范围,进而结合待量化数据自身的特征确定待量化数据对应的数据位宽。
在该实现方式中,可以对待量化数据进行统计,根据统计结果和数据位宽确定待量化数据对应的量化参数。量化参数可以包括点位置、缩放系数和偏移量中的一种或多种。
在一种可能的实现方式中,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,可以包括:
当所述量化参数不包括偏移量时,根据各所述待量化数据中的绝对值最大值Z 1和对应的数据位宽, 得到各所述待量化数据的第一类点位置。其中,该绝对值最大值Z 1是待量化数据中数据取绝对值后所得到的最大值。
在该实现方式中,当待量化数据为相对于原点对称的数据时,量化参数可以不包括偏移量,假设Z 1为待量化数据中元素的绝对值的最大值,待量化数据对应的数据位宽为n,A 1为用数据位宽n对待量化数据进行量化后的量化数据可以表示的最大值,A 1
Figure PCTCN2020110299-appb-000001
A 1需要包含Z 1,且Z 1要大于
Figure PCTCN2020110299-appb-000002
因此有公式(1)的约束:
Figure PCTCN2020110299-appb-000003
处理器可以根据待量化数据中的绝对值最大值Z 1和数据位宽n,计算得到第一类点位置s 1。例如,可以利用如下公式(2)计算得到待量化数据对应的第一类点位置s 1
Figure PCTCN2020110299-appb-000004
其中,ceil为向上取整,Z 1为待量化数据中的绝对值最大值,s 1为第一类点位置,n为数据位宽。
在一种可能的实现方式中,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,可以包括:
当所述量化参数包括偏移量时,根据各所述待量化数据中的最大值、最小值和对应的数据位宽,得到各所述待量化数据的第二类点位置s 2
在该实现方式中,可以先获取待量化数据中的最大值Z max、最小值Z min,进而根据最大值Z max、最小值Z min利用下述公式(3)进行计算,
Figure PCTCN2020110299-appb-000005
进一步地,根据计算得到的Z 2和对应的数据位宽利用下述公式(4)计算第二类点位置s 2
Figure PCTCN2020110299-appb-000006
在该实现方式中,由于量化时,常规情况下会将待量化数据中的最大值和最小值保存下来,直接基于保存的待量化数据中的最大值和最小值来获取绝对值最大值,无需消耗更多的资源去对待量化数据求绝对值,节省确定统计结果的时间。
在一种可能的实现方式中,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
当所述量化参数不包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
根据各所述待量化数据中的绝对值最大值和所述量化后数据的最大值,得到各所述待量化数据的第一类缩放系数f’。其中,第一类缩放系数f’可以包括第一缩放系数f 1和第二缩放系数f 2
其中,该第一缩放系数f 1可以按照如下方式(5)进行计算:
Figure PCTCN2020110299-appb-000007
其中,第二缩放系数f 2可以按照如下公式(6)进行计算:
Figure PCTCN2020110299-appb-000008
在一种可能的实现方式中,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,可以包括:
根据各所述待量化数据中的最大值和最小值,得到各所述待量化数据的偏移量。
在该实现方式中,图3示出根据本公开实施例的对称的定点数表示的示意图。如图3所示的待量化数据的数域是以“0”为对称中心分布。Z 1为待量化数据的数域中所有浮点数的绝对值最大值,在图3中,A 1为n位定点数可以表示的浮点数的最大值,浮点数A 1转换为定点数是(2 n-1-1)。为了避免溢出,A 1需要包含Z 1。在实际运算中,神经网络运算过程中的浮点数据趋向于某个确定区间的正态分布,但是 并不一定满足以“0”为对称中心的分布,这时用定点数表示时,容易出现溢出情况。为了改善这一情况,量化参数中引入偏移量。图4示出根据本公开实施例的引入偏移量的定点数表示的示意图。如图4所示。待量化数据的数域不是以“0”为对称中心分布,Z min是待量化数据的数域中所有浮点数的最小值,Z max是待量化数据的数域中所有浮点数的最大值,A 2为用n位定点数表示的平移后的浮点数的最大值,A 2
Figure PCTCN2020110299-appb-000009
P为Z min~Z max之间的中心点,将待量化数据的数域整体偏移,使得平移后的待量化数据的数域以“0”为对称中心分布,以避免数据的“溢出”。平移后的待量化数据的数域中的绝对值最大值为Z 2。由图4可知,偏移量为“0”点到“P”点之间的水平距离,该距离称为偏移量o。
可以根据该最小值Z min和最大值Z max按照如下公式(7)计算获得偏移量:
Figure PCTCN2020110299-appb-000010
其中,o表示偏移量,Z min表示待量化数据所有元素中的最小值,Z max表示待量化数据所有元素中的最大值。
在一种可能的实现方式中,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,可以包括:
当所述量化参数包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
根据各所述待量化数据中的最大值、最小值和量化后数据的最大值,得到各所述待量化数据的第二类缩放系数f”。其中,第二类缩放系数f”可以包括第三缩放系数f 3和第四缩放系数f 4
在该实现方式中,当量化参数包括偏移量时,A 2为用数据位宽n对平移后的待量化数据进行量化后的量化数据可以表示的最大值,A 2
Figure PCTCN2020110299-appb-000011
可以根据待量化数据中的Z max、最小值Z min进行计算得到平移后的待量化数据的数域中的绝对值最大值Z 2,进而按照如下公式(8)计算第三缩放系数f 3
Figure PCTCN2020110299-appb-000012
进一步地,第四缩放系数f 4可以按照如下公式(9)进行计算:
Figure PCTCN2020110299-appb-000013
在对待量化数据进行量化时,所采用的量化参数不同,进行量化所使用的数据不同。
在一种可能的实现方式中,量化参数可以包括第一类点位置s 1。可以利用如下的公式(10)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110299-appb-000014
其中,I x为量化数据,F x为待量化数据,round为进行四舍五入的取整运算。
量化参数可以包括第一类点位置s 1时,可以根据公式(11)对目标数据的量化数据进行反量化,得到目标数据的反量化数据
Figure PCTCN2020110299-appb-000015
Figure PCTCN2020110299-appb-000016
在一种可能的实现方式中,量化参数可以包括第一类点位置和第一缩放系数。可以利用如下的公式(12)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110299-appb-000017
当量化参数包括第一类点位置和第一缩放系数时,可以根据公式(13)对目标数据的量化数据进行反量化,得到目标数据的反量化数据
Figure PCTCN2020110299-appb-000018
Figure PCTCN2020110299-appb-000019
在一种可能的实现方式中,量化参数可以包括第二缩放系数。可以利用如下的公式(14)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110299-appb-000020
当量化参数包括第二缩放系数时,可以根据公式(15)对目标数据的量化数据进行反量化,得到目标数据的反量化数据
Figure PCTCN2020110299-appb-000021
Figure PCTCN2020110299-appb-000022
在一种可能的实现方式中,量化参数可以包括偏移量。可以利用如下的公式(16)对待量化数据进行量化,得到量化数据I x
I x=round(F x-o)         公式(16)
当量化参数包括偏移量时,可以根据公式(17)对目标数据的量化数据进行反量化,得到目标数据的反量化数据
Figure PCTCN2020110299-appb-000023
Figure PCTCN2020110299-appb-000024
在一种可能的实现方式中,量化参数可以包括第二类点位置和偏移量。可以利用如下的公式(18)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110299-appb-000025
当量化参数包括第二类点位置和偏移量时,可以根据公式(19)对目标数据的量化数据进行反量化,得到目标数据的反量化数据
Figure PCTCN2020110299-appb-000026
Figure PCTCN2020110299-appb-000027
在一种可能的实现方式中,量化参数可以包括第二类缩放系数f”和偏移量o。可以利用如下的公式(20)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110299-appb-000028
当量化参数包括第二类缩放系数和偏移量时,可以根据公式(21)对目标数据的量化数据进行反量化,得到目标数据的反量化数据
Figure PCTCN2020110299-appb-000029
Figure PCTCN2020110299-appb-000030
在一种可能的实现方式中,量化参数可以包括第二类点位置、第二类缩放系数和偏移量。可以利用如下的公式(22)对待量化数据进行量化,得到量化数据I x
Figure PCTCN2020110299-appb-000031
当量化参数包括第二类点位置、第二类缩放系数和偏移量时,可以根据公式(23)对目标数据的量化数据进行反量化,得到目标数据的反量化数据
Figure PCTCN2020110299-appb-000032
Figure PCTCN2020110299-appb-000033
可以理解的是,也可以采用其他的取整运算方法,例如采用向上取整、向下取整、向零取整等取整运算,替换上述公式中的四舍五入的取整运算round。可以理解的是,在数据位宽一定的情况下,根据点位置量化得到的量化数据中,小数点后的位数越多,量化数据的量化精度越大。
在一种可能的实现方式中,上述步骤S11可以包括:
通过查找待量化数据与量化参数对应关系,确定与所述待量化层中每种待量化数据对应的量化参数。
在一种可能的实现方式中,各待量化层中与每种待量化数据对应的量化参数,可以是保存的预设 值。可以为神经网络建立一个待量化数据与量化参数之间的对应关系,该对应关系可以包括各待量化层的每种待量化数据与量化参数对应关系,并将对应关系保存在各层可以共享访问的存储空间。也可以为神经网络建立多个待量化数据与量化参数之间的对应关系,各待量化层分别对应其中一个对应关系。可以将各层的对应关系保存在本层独享的存储空间,也可以将各层的对应关系保存在各层可以共享访问的存储空间。
在待量化数据与量化参数对应关系中,可以包括多个待量化数据和与之对应的多个量化参数之间的对应关系。例如,待量化数据与量化参数对应关系A中,可以包括待量化层1的神经元和权值两个待量化数据,神经元对应点位置1、缩放系数1和偏移量1三个量化参数,权值对应点位置2和偏移量2两个量化参数。本公开对待量化数据与量化参数对应关系的具体格式不作限定。
在本实施例中,可以通过查找待量化数据与量化参数对应关系,确定与所述待量化层中每种待量化数据对应的量化参数。可以为各待量化层预设对应的量化参数,并通过对应关系进行存储后,供待量化层查找后使用。本实施例中量化参数的获取方式简单方便。
图5示出根据本公开实施例的神经网络量化方法的流程图。在一种可能的实现方式中,如图5所示,该方法还可以包括步骤S14至步骤S16。
在步骤S14中,根据各所述待量化数据和各所述待量化数据对应的量化数据,确定各所述待量化数据对应的量化误差。
可以根据待量化数据对应的量化数据与待量化数据之间的误差,确定待量化数据的量化误差。可以利用设定的误差计算方法,例如标准差计算方法、均方根误差计算方法等,计算待量化数据的量化误差。
也可以根据量化参数,将待量化数据对应的量化数据进行反量化后得到反量化数据,根据反量化数据与待量化数据之间的误差,按照公式(24)确定待量化数据的量化误差diff bit
Figure PCTCN2020110299-appb-000034
其中,F i为待量化对应的浮点值,其中,i为待量化数据中数据的下标。
Figure PCTCN2020110299-appb-000035
为浮点值对应的反量化数据。
还可以根据量化间隔、量化后的数据的个数以及对应的量化前的数据按照公式(25)确定量化误差diff bit
Figure PCTCN2020110299-appb-000036
其中,C为量化时对应的量化间隔,m为量化后获得的量化数据的个数,F i为待量化对应的浮点值,其中,i为待量化数据中数据的下标。
也可以根据量化后的数据以及对应的反量化数据按照公式(26)确定量化误差diff bit
Figure PCTCN2020110299-appb-000037
其中,F i为待量化对应的浮点值,其中,i为待量化数据集合中数据的下标。
Figure PCTCN2020110299-appb-000038
为浮点值对应的反量化数据。
在步骤S15中,根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽。
可以根据经验值确定误差阈值,误差阈值可以用于表示对量化误差的期望值。当量化误差大于或小于误差阈值时,可以调整待量化数对应的数据位宽,得到待量化数据对应的调整位宽。可以将数据位宽调整为更长的位宽或更短的位宽,以提高或降低量化精度。
可以根据能够接受的最大误差确定误差阈值,当量化误差大于误差阈值时,说明量化精度不能达到预期,需要将数据位宽调整为更长的位宽。也可以根据较高的量化精度确定一个较小的误差阈值,当量化误差小于误差阈值时,说明量化精度较高,神经网络的运行效率将受到影响,可以适当的将数据位宽调整为更短的位宽,以适当的降低量化精度,提高神经网络的运行效率。
可以将数据位宽按照固定的位数步长进行调整,也可以根据量化误差与误差阈值之间的差值的不同,按照可变的调整步长调整数据位宽。本公开对此不作限定。
在步骤S16中,将各所述待量化数据对应的数据位宽更新为对应的调整位宽,根据各所述待量化数据和对应的调整位宽计算得到对应的调整量化参数,以使各所述待量化数据根据所述对应的调整量化参数进行量化。
确定调整位宽后,可以将待量化数据对应的数据位宽更新为调整位宽。例如,待量化数据更新前的数据位宽为8位,调整位宽为12位,则更新后待量化数据对应的数据位宽为12位。可以根据调整位宽和待量化数据计算得到待量化数据对应的调整量化参数。可以根据待量化数据对应的调整量化参数重新对待量化数据进行量化,以得到量化精度更高或更低的量化数据,使得待量化层在量化精度和处理效率之间达到平衡。
在神经网络的推理、训练和微调过程中,各层之间的待量化数据可以认为具有一定的关联性。例如,各层的待量化数据之间的均值之间的差小于设定的均值阈值,且各层的待量化数据之间的最大值之间的差值也小于设定的差值阈值时,可以将待量化层的调整量化参数作为后续的一个或多个层的调整量化参数,用于对待量化层后续的一个或多个层的待量化数据进行量化。也可以在神经网络的训练和微调过程中,将待量化层在当前迭代得到的调整量化参数,用于在后续的迭代中对待量化层进行量化。
在一种可能的实现方式中,所述方法还包括:
在所述待量化层之后的一层或多层采用所述待量化层的量化参数。
神经网络根据调整量化参数进行量化,可以包括只在待量化层利用调整量化参数对待量化数据重新进行量化,并将重新得到的量化数据用于待量化层的运算。也可以包括在待量化层不使用调整量化参数重新对待量化数据进行量化,而在待量化层后续的一个或多个层使用调整量化参数进行量化,和/或后续的迭代中在待量化层使用调整量化参数进行量化。还可以包括在待量化层使用调整量化参数重新进行量化,并将重新得到的量化数据用于待量化层的运算,并且在待量化层后续的一个或多个层使用调整量化参数进行量化,和/或后续的迭代中在待量化层使用调整量化参数进行量化。本公开对此不作限定。
在本实施例中,根据待量化数据和待量化数据对应的量化数据之间的误差调整数据位宽,并根据调整后的数据位宽计算得到调整量化参数。通过设置不同的误差阈值可以得到不同的调整量化参数,达到提高量化精度或提高运行效率等不同的量化需求。根据待量化数据和待量化数据的量化数据计算得到的调整量化参数,也能够更加符合待量化数据自身的数据特征,达到更加符合待量化数据自身需求的量化结果,在量化精度和处理效率之间达到更好的平衡。
在一种可能的实现方式中,步骤S15可以包括:
当所述量化误差大于第一误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽。
可以根据能够接受的最大的量化误差,确定第一误差阈值。可以将量化误差与第一误差阈值进行 比较。当量化误差大于第一误差阈值时,可以认为量化误差已经不可接受。需要提高量化精度,可以通过增加待量化数据对应的数据位宽的方式,提高待量化数据的量化精度。
可以将待量化数据对应的数据位宽按照固定的调整步长增加,得到调整位宽。固定的调整步长可以为N位,N为正整数。每次调整数据位宽可以增加N位。每次增加后的数据位宽=原数据位宽+N位。
可以将待量化数据对应的数据位宽按照可变的调整步长增加,得到调整位宽。例如,当量化误差与误差阈值之间的差值大于第一阈值时,可以按照调整步长M1调整数据位宽,当量化误差与误差阈值之间的差值小于第一阈值时,可以按照调整步长M2调整数据位宽,其中,第一阈值大于第二阈值,M1大于M2。可以根据需求确定各可变的调整步长。本公开对数据位宽的调整步长及调整步长是否可变不作限定。
可以将待量化数据按照调整位宽计算得到调整后的量化参数。利用调整后的量化参数对待量化数据进行重新量化后得到的量化数据,比利用调整前的量化参数量化得到的量化数据的量化精度更高。
在一种可能的实现方式中,该方法还可以包括:
根据各所述待量化数据和对应的调整位宽计算各所述待量化数据调整后的量化误差;
根据所述调整后的量化误差和所述第一误差阈值继续增加所述对应的调整位宽,直至所述调整后的量化误差小于或等于所述第一误差阈值。
根据量化误差增加待量化数据对应的数据位宽时,调整一次位宽后得到调整位宽,根据调整位宽计算得到调整后的量化参数,根据调整后的量化参数量化待量化数据得到调整后的量化数据,再根据调整后的量化数据与待量化数据计算得到待量化数据调整后的量化误差,调整后的量化误差可能依然大于第一误差阈值,即根据调整一次的数据位宽可能不能满足调整目的。当调整后的量化误差依然大于第一误差阈值时,可以继续对调整后的数据位宽进行调整,即多次增加待量化数据对应的数据位宽,直至根据最终得到的调整位宽和待量化数据得到的调整后的量化误差小于第一误差阈值。
多次增加的调整步长可以是固定的调整步长,也可以是可变的调整步长。例如,最终的数据位宽=原数据位宽+B*N位,其中N为每次增加的固定的调整步长,B为数据位宽的增加次数。最终的数据位宽=原数据位宽+M1+M2+…+Mm,其中,M1、M2…Mm为每次增加的可变的调整步长。
在本实施例中,当量化误差大于第一误差阈值时,增加所述待量化数据对应的数据位宽,得到所述待量化数据对应的调整位宽。可以通过设置第一误差阈值和调整步长增加数据位宽,以使调整后的数据位宽能够满足量化的需求。当一次调整不能满足调整需求时,还可以对数据位宽进行多次调整。第一误差阈值和调整步长的设置,使得量化参数可以按照量化需求进行灵活调整,满足不同的量化需求,使得量化精度可根据自身数据特征进行自适应调整。
在一种可能的实现方式中,步骤S15可以包括:
当所述量化误差小于第二误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽,所述第二误差阈值小于所述第一误差阈值
可以根据能够接受的量化误差和期望的神经网络的运行效率,确定第二误差阈值。可以将量化误差与第二误差阈值进行比较。当量化误差小于第二误差阈值时,可以认为量化误差超出预期,但运行效率过低已经不可接受。可以降低量化精度以提高神经网络的运行效率,可以通过减少待量化数据对应的数据位宽的方式,降低待量化数据的量化精度。
可以将待量化数据对应的数据位宽按照固定的调整步长减少,得到调整位宽。固定的调整步长可以为N位,N为正整数。每次调整数据位宽可以减少N位。增加后的数据位宽=原数据位宽-N位。
可以将待量化数据对应的数据位宽按照可变的调整步长减少,得到调整位宽。例如,当量化误差与误差阈值之间的差值大于第一阈值时,可以按照调整步长M1调整数据位宽,当量化误差与误差阈值之间的差值小于第一阈值时,可以按照调整步长M2调整数据位宽,其中,第一阈值大于第二阈值,M1大于M2。可以根据需求确定各可变的调整步长。本公开对数据位宽的调整步长及调整步长是否可变不作限定。
可以将待量化数据按照调整位宽计算得到调整后的量化参数,利用调整后的量化参数对待量化数 据进行重新量化后得到的量化数据,比利用调整前的量化参数量化得到的量化数据的量化精度更低。
在一种可能的实现方式中,该方法还可以包括:
根据所述调整位宽和所述待量化数据计算所述待量化数据调整后的量化误差;
根据所述调整后的量化误差和所述第二误差阈值继续减少所述调整位宽,直至根据调整位宽和所述待量化数据计算得到的调整后的量化误差大于或等于所述第二误差阈值。
根据量化误差增加待量化数据对应的数据位宽时,调整一次位宽后得到调整位宽,根据调整位宽计算得到调整后的量化参数,根据调整后的量化参数量化待量化数据得到调整后的量化数据,再根据调整后的量化数据与待量化数据计算得到待量化数据调整后的量化误差,调整后的量化误差可能依然小于第二误差阈值,即根据调整一次的数据位宽可能不能满足调整目的。当调整后的量化误差依然小于第二误差阈值时,可以继续对调整后的数据位宽进行调整,即多次减少待量化数据对应的数据位宽,直至根据最终得到的调整位宽和待量化数据得到的调整后的量化误差大于第二误差阈值。
多次减少的调整步长可以是固定的调整步长,也可以是可变的调整步长。例如,最终的数据位宽=原数据位宽-B*N位,其中N为每次增加的固定的调整步长,B为数据位宽的增加次数。最终的数据位宽=原数据位宽-M1-M2-…-Mm,其中,M1、M2…Mm为每次减少的可变的调整步长。
在本实施例中,当量化误差小于第二误差阈值时,减少所述待量化数据对应的数据位宽,得到所述待量化数据对应的调整位宽。可以通过设置第二误差阈值和调整步长减少数据位宽,以使调整后的数据位宽能够满足量化的需求。当一次调整不能满足调整需求时,还可以对数据位宽进行多次调整。第二误差阈值和调整步长的设置,使得量化参数可以按照量化需求进行灵活的自适应调整,满足不同的量化需求,使得量化精度可调,在量化精度和神经网络的运行效率之间达到平衡。
在一种可能的实现方式中,所述方法还包括:
当所述量化误差大于第一误差阈值时,增加所述待量化数据对应的数据位宽,以及当所述量化误差小于第二误差阈值时,减少所述待量化数据对应的数据位宽,得到所述待量化数据对应的调整位宽。
也可以同时设置两个误差阈值,其中,第一误差阈值用于表示量化精度过低,可以增加数据位宽的位数,第二误差阈值用于表示量化精度过高,可以减少数据位宽的位数。第一误差阈值大于第二误差阈值,可以将待量化数据的量化误差同时与两个误差阈值进行比较,当量化误差大于第一误差阈值时,增加数据位宽的位数,当量化误差小于第二误差阈值时,减少数据位宽的位数。当量化误差位于第一误差阈值和第二误差阈值之间时,数据位宽可以保持不变。
在本实施例中,通过将量化误差与第一误差阈值和第二误差阈值同时进行比较,可以根据比较结果增加或减少数据位宽,可以利用第一误差阈值和第二误差阈值更加灵活的调整数据位宽。使得数据位宽的调整结果更加符合量化需求。
在一种可能的实现方式中,在所述神经网络运算的微调阶段和/或训练阶段,该方法还可以包括:
获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述历史迭代为所述当前迭代之前的迭代;
根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述待量化层根据所述目标迭代间隔更新所述待量化数据的量化参数,所述目标迭代间隔包括至少一次迭代。
在神经网络运算的微调阶段和/或训练阶段包括多次迭代。神经网络中的各待量化层,在进行一次正向运算和一次反向运算,并对待量化层的权值进行更新后,完成一次迭代。在多次迭代中,待量化层中的待量化数据和/或待量化数据对应的量化数据的数据变动幅度,可以用于衡量在不同迭代中的待量化数据和/或量化数据是否可采用相同的量化参数进行量化。若当前迭代以及历史迭代中待量化数据的数据变动幅度较小,例如小于设定的幅度变动阈值时,可以在数据变动幅度较小的多个迭代中采用相同的量化参数。
可以通过提取预存的量化参数的方式,确定与待量化数据对应的量化参数。在不同的迭代中对待量化数据进行量化时,需要在各迭代提取与待量化数据对应的量化参数。若多个迭代的待量化数据和/或待量化数据对应的量化数据的数据变动幅度较小,可将在数据变动幅度较小的多个迭代中采用的相同的量化参数进行暂存,各迭代在进行量化时可以利用暂存的量化参数进行量化运算,不用在每次 迭代提取量化参数。
也可以根据待量化数据和数据位宽计算得到量化参数。在不同的迭代中对待量化数据进行量化时,需要在各迭代分别计算量化参数。若多个迭代的待量化数据和/或待量化数据对应的量化数据的数据变动幅度较小,可在数据变动幅度较小的多个迭代中采用的相同的量化参数,则各迭代均可以直接使用其中第一个迭代计算得到的量化参数,而不是每次迭代计算量化参数。
可以理解的是,当待量化数据为权值时,各迭代之间的权值在不断更新,若多个迭代的权值的数据变动幅度较小,或多个迭代的权值对应的量化数据的数据变动幅度较小,可以在多个迭代中利用相同的量化参数对权值进行量化。
可以根据待量化数据的数据变动幅度确定目标迭代间隔,目标迭代间隔包括至少一次迭代,可以在目标迭代间隔内的各迭代使用相同的量化参数,即在目标迭代间隔内的各迭代不再更新待量化数据的量化参数。神经网络根据目标迭代间隔更新待量化数据的量化参数,包括在目标迭代间隔内的迭代,不获取预设的量化参数或不计算量化参数,即在目标迭代间隔内的迭代不更新量化参数。而在目标迭代间隔外的迭代,再获取预设的量化参数或计算量化参数,即在目标迭代间隔外的迭代更新量化参数。
可以理解的是,多个迭代之间的待量化数据或待量化数据的量化数据的数据变动幅度越小,确定出的目标迭代间隔包括的迭代次数越多。可以根据计算得到的数据变动幅度,查找预设的数据变动幅度与迭代间隔的对应关系,确定与计算得到的数据变动幅度对应的目标迭代间隔。可以根据需求预设数据变动幅度与迭代间隔的对应关系。也可以根据计算得到的数据变动幅度,利用设定的计算方法计算得到目标迭代间隔。本公开不限定数据变动幅度的计算方式,以及目标迭代间隔的获取方式。
在本实施例中,在神经网络运算的微调阶段和/或训练阶段,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,根据所述待量化数据的数据变动幅度,确定待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。可以根据多个迭代中待量化数据或待量化数据对应的量化数据的数据变动幅度,确定目标迭代间隔。神经网络可以根据目标迭代间隔确定是否更新量化参数。由于目标迭代间隔所包括的多个迭代的数据变动幅度较小,目标迭代间隔内的迭代不更新量化参数也可以保证量化精度。而目标迭代间隔内的多个迭代不更新量化参数,可以减少量化参数的提取次数或计算次数,从而提高神经网络的运算效率。
在一种可能的实现方式中,该方法还包括:
根据所述待量化数据在所述当前迭代的数据位宽,确定所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,以使所述神经网络根据所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,确定量化参数。
如本公开上述实施例所述,待量化数据的量化参数可以预设,也可以根据待量化数据对应的数据位宽计算得到。而不同待量化层中待量化数据对应的数据位宽,或相同待量化层中待量化数据在不同迭代中对应的数据位宽,可以根据本公开上述实施例中的方式进行自适应调整。
当待量化数据的数据位宽不可自适应调整,为预设的数据位宽时,可以根据待量化数据在当前迭代的预设的数据位宽,确定待量化数据在目标迭代间隔内的迭代对应的数据位宽。在目标迭代间隔内的各迭代可不使用自身的预设值。
当待量化数据的数据位宽可自适应调整时,可以根据待量化数据在当前迭代对应的数据位宽,确定待量化数据在目标迭代间隔内的迭代对应的数据位宽。在数据位宽可自适应调整时,数据位宽可进行一次调整或多次调整。可以将待量化数据在当前迭代进行自适应调整后的数据位宽,作为目标迭代间隔内的各迭代对应的数据位宽,在目标迭代间隔内的各迭代不再对数据位宽进行自适应调整(更新)。待量化数据在当前迭代可以使用自适应调整后的数据位宽,也可以使用自适应调整前的数据位宽,本公开对此不作限定。
在目标迭代间隔以外的其他迭代,由于待量化数据的数据变动幅度不满足设定条件,可以根据本公开上述的方法对数据位宽进行自适应调整,得到更加符合当前迭代的待量化数据的数据位宽,也可使用本公开中的目标迭代间隔的计算方法,计算得到新的目标迭代间隔并使用,从而在保证目标迭代间隔以外的迭代的量化精度的同时,提高神经网络的运行效率。
在目标迭代间隔内的各迭代的数据位宽相同,各迭代可以根据相同的数据位宽各自计算得到对应的量化参数。量化参数可以包括点位置、缩放系数和偏移量中的至少一种。可以在目标迭代间隔内的各迭代,根据相同的数据位宽分别计算得到量化参数。量化参数包括点位置(包括第一类点位置、第二类点位置)、缩放系数(包括第一类缩放系数和第二类缩放系数)和偏移量时,在目标迭代间隔内的各迭代,可利用相同的数据位宽,分别计算各自对应的点位置、缩放系数和偏移量。
在根据当前迭代的数据位宽,确定目标迭代间隔内各迭代的数据位宽的同时,可以根据当前迭代的量化参数,确定目标迭代间隔内各迭代的对应的量化参数。目标迭代间隔内各迭代的量化参数,也不再重新根据相同的数据位宽计算得到,可以进一步提高神经网络的运算效率。可以根据当前迭代的全部量化参数或部分量化参数,确定目标迭代间隔内各迭代的对应的量化参数。当根据当前迭代的部分量化参数,确定目标迭代间隔内各迭代的对应的量化参数时,剩余部分的量化参数,在目标迭代间隔内各迭代仍需计算。
例如,量化参数包括第二类点位置、第二类缩放系数和偏移量。可以根据当前迭代的数据位宽和第二类点位置,确定目标迭代间隔内各迭代的数据位宽和第二类点位置。则目标迭代间隔内各迭代的第二类缩放系数和偏移量需要根据相同的数据位宽计算得到。也可以根据当前迭代的数据位宽、第二类点位置、第二类缩放系数和偏移量,确定目标迭代间隔内各迭代的数据位宽、第二类点位置、第二类缩放系数和偏移量,则目标迭代间隔内各迭代的各量化参数均不需要计算得到。
在本实施例中,根据待量化数据在当前迭代对应的数据位宽,确定待量化数据在目标迭代间隔内的迭代对应的数据位宽,以使神经网络根据待量化数据在目标迭代间隔内的迭代对应的数据位宽,确定量化参数。在目标迭代间隔内的各迭代的数据位宽,根据当前迭代的数据位宽确定,由于目标迭代间隔内各迭代的待量化数据的数据变化幅度满足设定的条件,利用相同的数据位宽计算得到的量化参数,可以保证目标迭代间隔内的各迭代的量化精度。目标迭代间隔内各迭代使用相同的数据位宽,也可以提高神经网络的运算效率。在对神经网络进行量化后运算结果的准确率和神经网络的运算效率之间,达到平衡。
在一种可能的实现方式中,该方法还可以包括:根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置,所述点位置包括第一类点位置和/或第二类点位置。
其中,根据所述待量化数据在所述当前迭代对应的第一类点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的第一类点位置。根据所述待量化数据在所述当前迭代对应的第二类点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的第二类点位置。
在量化参数中,相对于缩放系数和偏移量,不同的点位置对相同待量化数据的量化结果产生的影响较大。可以根据待量化数据在当前迭代对应的点位置,确定目标迭代间隔内的迭代对应的点位置。当数据位宽不可自适应调整时,可以将待量化数据在当前迭代预设的点位置,作为待量化数据在目标迭代间隔内各迭代对应的点位置,也可以将待量化数据在当前迭代根据预设的数据位宽计算得到的点位置,作为待量化数据在目标迭代间隔内各迭代对应的点位置。当数据位宽可自适应调整时,可以将待量化数据在当前迭代调整后的点位置,作为待量化数据在目标迭代间隔内各迭代对应的点位置。
根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置的同时,也可以根据待量化数据在当前迭代对应的缩放系数,确定所述待量化数据在所述目标迭代间隔内的迭代对应的缩放系数,和/或根据待量化数据在当前迭代对应的偏移量,确定所述待量化数据在所述目标迭代间隔内的迭代对应的偏移量。
根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置的同时,还可以根据待量化数据在当前迭代对应的数据位宽,确定所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,其中,待量化数据在当前迭代对应的数据位宽,可以是当前迭代预设的数据位宽或自适应调整后的数据位宽。
在本实施例中,根据待量化数据在当前迭代对应的点位置,确定待量化数据在目标迭代间隔内的迭代对应的点位置。在目标迭代间隔内的各迭代的点位置,根据当前迭代的点位置确定,由于目标迭 代间隔内各迭代的待量化数据的数据变化幅度满足设定的条件,利用相同的点位置,可以保证目标迭代间隔内的各迭代的量化精度。目标迭代间隔内各迭代使用相同的点位置,也可以提高神经网络的运算效率。在对神经网络进行量化后运算结果的准确率和神经网络的运算效率之间,达到平衡。
在一种可能的实现方式中,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,可以包括:
根据待量化数据在当前迭代的点位置,和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的点位置,计算待量化数据对应各迭代间隔的点位置的滑动平均值,所述点位置包括第一类点位置和/或第二类点位置;
根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度;
其中,根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数,可以包括:
根据所述第一数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
其中,根据待量化数据在当前迭代的第一类点位置和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的第一类点位置,计算待量化数据对应各迭代间隔的第一类点位置的滑动平均值;根据所述待量化数据在当前迭代的第一类点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的第一类点位置的第二滑动平均值,得到所述待量化数据变动幅度。或者,根据待量化数据在当前迭代的第二类点位置和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的第二类点位置,计算待量化数据对应各迭代间隔的第二类点位置的滑动平均值;根据所述待量化数据在当前迭代的第二类点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的第二类点位置的第二滑动平均值,得到所述待量化数据变动幅度。
在一种可能的实现方式中,根据历史迭代间隔确定的与所述当前迭代对应的历史迭代,可以为计算目标迭代间隔的历史迭代。当前迭代与对应的目标迭代间隔之间的对应关系可以包括:
可以从当前迭代开始计数目标迭代间隔,并在当前迭代对应的目标迭代间隔结束后的下一个迭代开始重新计算目标迭代间隔。例如,当前迭代为第100代,目标迭代间隔为3,目标迭代间隔内的迭代包括:第100代、第101代和第102代,可以在第103代计算与第103代对应的目标迭代间隔,并以103代为新计算得到当目标迭代间隔内的第一个迭代。此时,当前迭代为103代时,根据历史迭代间隔确定的与所述当前迭代对应的历史迭代为100代。
可以从当前迭代的下一个迭代开始计数目标迭代间隔,并在目标迭代间隔内的最后一个迭代开始重新计算目标迭代间隔。例如,当前迭代为第100代,目标迭代间隔为3,目标迭代间隔内的迭代包括:第101代、第102代和第103代,可以在第103代计算与第103代对应的目标迭代间隔,并以104代为新计算得到当目标迭代间隔内的第一个迭代。此时,当前迭代为103代时,根据历史迭代间隔确定的与所述当前迭代对应的历史迭代为100代。
可以从当前迭代的下一个迭代开始计数目标迭代间隔,并在目标迭代间隔结束后的下一个迭代开始重新计算目标迭代间隔。例如,当前迭代为第100代,目标迭代间隔为3,目标迭代间隔内的迭代包括:第101代、第102代和第103代,可以在第104代计算与第104代对应的目标迭代间隔,并以105代为新计算得到当目标迭代间隔内的第一个迭代。此时,当前迭代为104代时,根据历史迭代间隔确定的与所述当前迭代对应的历史迭代为100代。
可以根据需求确定当前迭代以及目标迭代间隔之间的其他的对应关系,例如可以从当前迭代之后的第N个迭代开始计数目标迭代间隔,N大于1,本公开对此不作限定。
可以理解的是,计算得到的待量化数据对应各迭代间隔的点位置的滑动平均值,包括待量化数据在当前迭代的点位置的第一滑动平均值,和待量化数据在上一迭代间隔对应迭代的点位置的第二滑动平均值。可以利用公式(27)计算当前迭代对应点位置的第一滑动平均值m (t)
m (t)←α×s (t)+(1-α)×m (t-1)   公式(27)
其中,t为当前迭代,t-1为根据上一迭代间隔确定的历史迭代,m (t-1)为根据上一迭代间隔确定 的历史迭代的第二滑动平均值。s (t)为当前迭代的点位置,可以为第一类点位置或第二类点位置。α为第一参数。第一参数可以为超参数。
在本实施例中,根据待量化数据在当前迭代的点位置,和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的点位置,计算待量化数据对应各迭代间隔的点位置的滑动平均值;根据待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度。根据第一数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。由于第一数据变动幅度可以用于衡量点位置的变化趋势,使得目标迭代间隔可以跟随待量化数据点位置的变化趋势而变化,也使得计算得到的各目标迭代间隔的大小可以根据待量化数据点位置的变化趋势而变化。由于量化参数根据目标迭代间隔确定,也就使得根据量化参数进行量化得到的量化数据,能够更加符合待量化数据的点位置的变动趋势,在保证量化精度的同时,提高神经网络的运行效率。
在一种可能的实现方式中,所述根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度,可以包括:
计算所述第一滑动平均值和所述第二滑动平均值的差值;
将所述差值的绝对值确定为第一数据变动幅度。
可以利用公式(28)计算第一数据变动幅度diff update1
diff update1=|m (t)-m (t-1)|=α|s (t)-m (t-1)|     公式(28)
可以根据第一数据变动幅度,确定待量化数据对应的目标迭代间隔,以使神经网络根据目标迭代间隔更新所述待量化数据的量化参数。可以根据公式(29)计算得到目标迭代间隔I:
Figure PCTCN2020110299-appb-000039
其中,β为第二参数,γ为第三参数。第二参数和第三参数可以为超参数。
可以理解的是,第一数据变动幅度可以用于衡量点位置的变化趋势,第一数据变动幅度越大,说明量化数据的数值范围变化剧烈,在更新量化参数时需要间隔更短的目标迭代间隔I。
在本实施例中,计算所述第一滑动平均值和所述第二滑动平均值的差值;将差值的绝对值确定为第一数据变动幅度。根据滑动平均值之间的差值可以得到精确的第一数据变动幅度。
在一种可能的实现方式中,该方法还可以包括:根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度;
其中,根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数,可以包括:
根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
可以根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度。也可以根据在当前迭代所述待量化数据和所述待量化数据对应的反量化数据,得到第二数据变动幅度。
同样的,可以根据公式(30)计算得到在当前迭代中,所述待量化数据和所述待量化数据对应的反量化数据之间的第二数据变动幅度diff bit。也可以利用其它误差的计算方法,计算待量化数据和反量化数据之间的第二数据变动幅度diff bit。本公开对此不作限定。
Figure PCTCN2020110299-appb-000040
其中,z i为待量化数据,z i (n)为待量化数据对应的反量化数据。可以理解的是,第二数据变动幅度可以用于衡量待量化数据对应的数据位宽的变化趋势,第二数据变动幅度越大,待量化数据越有可能需要更新对应的数据位宽,需要间隔更短的迭代进行更新,则第二数据变动幅度越大,需要目标迭代间隔更小。
在本实施例中,根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数 据变动幅度。根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。第二数据变动幅度可以用于衡量数据位宽的变动需求,则根据第一数据变动幅度和第二数据变动幅度计算得到的目标迭代间隔,可以同时跟踪点位置和数据位宽的变动,目标迭代间隔也可以更加符合待量化数据自身的数据量化需求。
在一种可能的实现方式中,根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度,可以包括:
计算在当前迭代所述待量化数据和所述待量化数据对应的量化数据之间的误差;
将所述误差的平方确定为所述第二数据变动幅度。
可以利用公式(31)计算得到第二数据变动幅度diff update2
diff update2=δ*diff bit 2     公式(31)
其中,δ为第四参数,第四参数可以为超参数。
可以理解的是,利用不同的数据位宽可以得到不同的量化参数,进而得到不同的量化数据,产生不同的第二数据变动幅度。第二数据变动幅度可以用于衡量数据位宽的变化趋势,第二数据变动幅度越大,说明需要更短的目标迭代间隔来更加频繁的更新数据位宽,即目标迭代间隔需要更小。
在一种可能的实现方式中,根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,可以包括:
根据所述第一数据变动幅度和所述第二数据变动幅度中的最大值,确定所述待量化数据对应的目标迭代间隔。
可以根据公式(32)计算得到目标迭代间隔:
Figure PCTCN2020110299-appb-000041
其中,β为第二参数,γ为第三参数。第二参数和第三参数可以为超参数。
可以理解的是,利用第一数据变动幅度和第二数据变动幅度得到的目标迭代间隔,可以同时衡量数据位宽和点位置的变化趋势,当两者中的其一的变化趋势较大时,便可以使得目标迭代间隔产生相应的变化。目标迭代间隔可以同时追踪数据位宽和点位置的变化并做出相应的调整。使得根据目标迭代间隔更新的量化参数能够更加符合目标数据的变动趋势,最终使得根据量化参数得到的量化数据能够更加符合量化需求。
在一种可能的实现方式中,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,可以包括:
在当前迭代位于更新周期以外时,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述更新周期包括至少一个迭代。
在神经网络运算的训练过程和/或微调过程中,在训练开始或微调开始的多个迭代中,待量化数据的变化幅度较大。若在训练开始或微调开始的多个迭代中计算目标迭代间隔,则计算得到的目标迭代间隔可能会失去其使用的意义。可以根据预设更新周期,在更新周期以内的各迭代,不计算目标迭代间隔,也不适用目标迭代间隔使得多个迭代使用相同的数据位宽或点位置。
当迭代进行至更新周期以外时,即当前迭代位于更新周期以外时,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,并根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。例如,预设更新周期为100代,则自第1代开始至第100代的迭代中,不计算目标迭代间隔。当迭代进行至101代,即当前迭代为101代时,当前迭代位于更新周期以外,此时,可以根据第101代以及第1代至第100代的迭代中待量化数据的数据变动幅度,确定第101代的待量化数据对应的目标迭代间隔,并在第101代或与第101间隔预设代数的迭代中,使用计算得到的目标迭代间隔。
可以自预设的代数开始计数更新周期,例如可以自第一代开始计数更新周期中多个迭代,也可以自第N代开始计数更新周期中的多个迭代,本公开对此不作限定。
在本实施例中,当迭代进行至更新周期以外时计算并使用目标迭代间隔。可以避免在神经网络运算的训练过程或微调过程的初期,由于待量化数据的变动幅度较大引起的目标迭代间隔使用意义不大的问题,可以在使用目标迭代间隔的情况下,进一步提高神经网络的运行效率。
在一种可能的实现方式中,该方法还可以包括:
在当前迭代位于预设周期内时,根据当前迭代、在所述预设周期的下一周期中与所述当前迭代对应的迭代以及当前迭代对应的迭代间隔,确定周期间隔;
根据所述待量化数据在当前迭代对应的数据位宽,确定在所述周期间隔内的迭代中所述待量化数据的数据位宽;或
根据所述待量化数据在当前迭代对应的点位置,确定在所述周期间隔内的迭代中所述待量化数据的点位置。
在神经网络运算的训练过程或微调过程中,可以包括多个周期。各周期可以包括多个迭代。用于神经网络运算的数据被完整的运算一遍为一个周期。在训练过程中,随着迭代的进行,神经网络的权值变化趋于稳定,当训练稳定后,神经元、权值、偏置和梯度等待量化数据均趋于稳定。待量化数据趋于稳定后,待量化数据的数据位宽和量化参数也趋于稳定。同理,在微调过程中,微调稳定后,待量化数据的数据位宽和量化参数也趋于稳定。
因此,可以根据训练稳定或微调稳定的周期确定预设周期。可以将训练稳定或微调稳定所在周期以后的周期,确定为预设周期。例如训练稳定的周期为第M个周期,则可以将第M个周期以后的周期作为预设周期。在预设周期内,可以每间隔一个周期计算一个目标迭代间隔,并根据计算得到的目标迭代间隔调整一次数据位宽或量化参数,以减少数据位宽或量化参数的更新次数,提高神经网络的运行效率。
例如,预设周期为第M个周期以后的周期。在第M+1个周期中,根据第M个周期中的第P个迭代计算得到的目标迭代间隔,截止至第M+1个周期中的第Q个迭代。根据第M+1个周期中的第Q m+1个迭代计算得到与之对应的目标迭代间隔I m+1。在第M+2个周期中,与第M+1个周期中的第Q m+1个迭代对应的迭代为第Q m+2个迭代。在自第M+1个周期中的第Q m+1个迭代开始,直至第M+2个周期中第Q m+2+I m+1个迭代为止,为周期间隔。在周期间隔内的各迭代,均采用第M+1个周期中的第Q m+1个迭代确定的数据位宽或点位置等量化参数。
在本实施例中,可以设置周期间隔,在神经网络运算的训练或微调达到稳定后,根据周期间隔,每周期更新一次数据位宽或点位置等量化参数。周期间隔可以在训练稳定或微调稳定后,减少数据位宽或点位置的更新次数,在保证量化精度的同时,提高神经网络的运行效率。
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本公开并不受所描述的动作顺序的限制,因为依据本公开,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于可选实施例,所涉及的动作和模块并不一定是本公开所必须的。
进一步需要说明的是,虽然图2、图5的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图2、图5中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些子步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。
本公开实施例还提供了一种非易失性计算机可读存储介质,其上存储有计算机程序指令,计算机程序指令被处理器执行时实现上述神经网络的数据量化处理方法。
图6示出根据本公开一实施例的神经网络量化装置的框图。如图6所示,该装置应用于包含如图1所示的处理器100的终端,终端用于运行神经网络以执行目标任务,该装置包括数据确定模块61、数据量化模块62和结果确定模块63。其中,某一个处理单元101中设置有数据确定模块61、数据量化模块62和结果确定模块63。或者,数据确定模块61、数据量化模块62和结果确定模块63分别设置在不同 的处理单元101中。存储单元102用于存储待量化数据、量化参数、数据位宽等与数据确定模块61、数据量化模块62和结果确定模块63的运行相关的数据。
数据确定模块61,根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;
数据量化模块62,将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;
结果确定模块63,根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
在一种可能的实现方式中,所述数据确定模块,包括以下至少一个子模块:
第一确定子模块,根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的目标数据确定为一个待量化数据;
第二确定子模块,根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的同一种待运算数据确定为一个待量化数据;
第三确定子模块,根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个通道中的数据确定为一个待量化数据;
第四确定子模块,根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个批数的数据确定为一个待量化数据;
第五确定子模块,根据所述目标任务和/或所述终端的精度需求确定划分数据的划分尺寸,将对应待量化层中的目标数据按照所述划分尺寸划分为一个或多个待量化数据。
在一种可能的实现方式中,所述装置还包括:
数据位宽确定模块,根据所述目标任务和/或所述终端的精度需求,确定待量化数据对应的数据位宽;
参数确定模块,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数。
在一种可能的实现方式中,所述参数确定模块,包括:
第一点位置确定子模块,当所述量化参数不包括偏移量时,根据各所述待量化数据中的绝对值最大值和对应的数据位宽,得到各所述待量化数据的第一类点位置。
在一种可能的实现方式中,所述参数确定模块,包括:
第一最大值确定子模块,当所述量化参数不包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
第一缩放系数确定子模块,根据各所述待量化数据中的绝对值最大值和所述量化后数据的最大值,得到各所述待量化数据的第一类缩放系数。
在一种可能的实现方式中,所述参数确定模块,包括:
第二点位置确定子模块,当所述量化参数包括偏移量时,根据各所述待量化数据中的最大值、最小值和对应的数据位宽,得到各所述待量化数据的第二类点位置。
在一种可能的实现方式中,所述参数确定模块,包括:
第二最大值确定子模块,当所述量化参数包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
第一缩放系数确定子模块,根据各所述待量化数据中的最大值、最小值和量化后数据的最大值,得到各所述待量化数据的第二类缩放系数。
在一种可能的实现方式中,所述参数确定模块,包括:
偏移量确定子模块,根据各所述待量化数据中的最大值和最小值,得到各所述待量化数据的偏移量。
在一种可能的实现方式中,所述装置还包括:
第一量化误差确定模块,根据各所述待量化数据和各所述待量化数据对应的量化数据,确定各所 述待量化数据对应的量化误差;
调整位宽确定模块,根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽;
调整量化参数确定模块,将各所述待量化数据对应的数据位宽更新为对应的调整位宽,根据各所述待量化数据和对应的调整位宽计算得到对应的调整量化参数,以使各所述待量化数据根据所述对应的调整量化参数进行量化。
在一种可能的实现方式中,所述调整位宽确定模块,包括:
第一调整位宽确定子模块,当所述量化误差大于第一误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽。
在一种可能的实现方式中,所述装置还包括:
第一调整后量化误差模块,根据各所述待量化数据和对应的调整位宽计算各所述待量化数据调整后的量化误差;
第一调整位宽循环确定模块,根据所述调整后的量化误差和所述第一误差阈值继续增加所述对应的调整位宽,直至所述调整后的量化误差小于或等于所述第一误差阈值。
在一种可能的实现方式中,所述调整位宽确定模块,包括:
第二调整位宽确定子模块,当所述量化误差小于第二误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽,所述第二误差阈值小于所述第一误差阈值。
在一种可能的实现方式中,所述装置还包括:
第二调整后量化误差模块,根据所述调整位宽和所述待量化数据计算所述待量化数据调整后的量化误差;
第二调整位宽循环确定模块,根据所述调整后的量化误差和所述第二误差阈值继续减少所述调整位宽,直至根据调整位宽和所述待量化数据计算得到的调整后的量化误差大于或等于所述第二误差阈值。
在一种可能的实现方式中,在所述神经网络运算的微调阶段和/或训练阶段,所述装置还包括:
第一数据变动幅度确定模块,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述历史迭代为所述当前迭代之前的迭代;
目标迭代间隔确定模块,根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述待量化层根据所述目标迭代间隔更新所述待量化数据的量化参数,所述目标迭代间隔包括至少一次迭代。
在一种可能的实现方式中,所述装置还包括:
第一目标迭代间隔应用模块,根据所述待量化数据在所述当前迭代的数据位宽,确定所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,以使所述神经网络根据所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,确定量化参数。
在一种可能的实现方式中,所述装置还包括:
第二目标迭代间隔应用模块,根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置,所述点位置包括第一类点位置和/或第二类点位置。
在一种可能的实现方式中,所述第一数据变动幅度确定模块,包括:
滑动平均值计算子模块,根据待量化数据在当前迭代的点位置,和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的点位置,计算待量化数据对应各迭代间隔的点位置的滑动平均值,所述点位置包括第一类点位置和/或第二类点位置;
第一数据变动幅度确定子模块,根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度;
其中,所述目标迭代间隔确定模块,包括:
第一目标迭代间隔确定子模块,根据所述第一数据变动幅度,确定所述待量化数据对应的目标迭 代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
在一种可能的实现方式中,所述第一数据变动幅度确定子模块,包括:
第一幅度确定子模块,计算所述第一滑动平均值和所述第二滑动平均值的差值;将所述差值的绝对值确定为第一数据变动幅度。
在一种可能的实现方式中,所述装置还包括:
第二数据变动幅度确定模块,根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度;
其中,目标迭代间隔确定模块,包括:
第二目标迭代间隔确定子模块,根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
在一种可能的实现方式中,所述第二数据变动幅度确定模块,包括:
第二幅度确定子模块,计算在当前迭代所述待量化数据和所述待量化数据对应的量化数据之间的误差;将所述误差的平方确定为所述第二数据变动幅度。
在一种可能的实现方式中,所述第二目标迭代间隔确定子模块,包括:
间隔确定子模块,根据所述第一数据变动幅度和所述第二数据变动幅度中的最大值,确定所述待量化数据对应的目标迭代间隔。
在一种可能的实现方式中,所述第一数据变动幅度确定模块,包括:
第二数据变动幅度确定子模块,在当前迭代位于更新周期以外时,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述更新周期包括至少一个迭代。
在一种可能的实现方式中,所述装置还包括:
周期间隔确定模块,在当前迭代位于预设周期内时,根据当前迭代、在所述预设周期的下一周期中与所述当前迭代对应的迭代以及当前迭代对应的迭代间隔,确定周期间隔;
第一周期间隔应用模块,根据所述待量化数据在当前迭代对应的数据位宽,确定在所述周期间隔内的迭代中所述待量化数据的数据位宽;或
第二周期间隔应用模块,根据所述待量化数据在当前迭代对应的点位置,确定在所述周期间隔内的迭代中所述待量化数据的点位置。
本公开实施例所提供的神经网络量化装置,根据目标任务和/或终端的精度需求从目标数据中确定多个待量化数据,利用对应的量化参数对目标数据中的多个待量化数据分别进行量化,在保证精度的同时,减小了存储数据所占用的存储空间,保证了运算结果的准确性和可靠性,且能够提高运算的效率,且量化同样缩减了神经网络模型的大小,降低了对运行该神经网络模型的终端的性能要求,使神经网络模型可以应用于算力、体积、功耗相对受限的手机等终端。
应该理解,上述的装置实施例仅是示意性的,本公开的装置还可通过其它的方式实现。例如,上述实施例中所述单元/模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。例如,多个单元、模块或组件可以结合,或者可以集成到另一个系统,或一些特征可以忽略或不执行。
另外,若无特别说明,在本公开各个实施例中的各功能单元/模块可以集成在一个单元/模块中,也可以是各个单元/模块单独物理存在,也可以两个或两个以上单元/模块集成在一起。上述集成的单元/模块既可以采用硬件的形式实现,也可以采用软件程序模块的形式实现。
所述集成的单元/模块如果以硬件的形式实现时,该硬件可以是数字电路,模拟电路等等。硬件结构的物理实现包括但不局限于晶体管,忆阻器等等。若无特别说明,所述人工智能处理器可以是任何适当的硬件处理器,比如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)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
在一种可能的实现方式中,还公开了一种非易失性计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现上述神经网络量化方法。
在一种可能的实现方式中,还公开了一种人工智能芯片,其包括了上述数据处理装置。
在一种可能的实现方式中,还公开了一种板卡,其包括存储器件、接口装置和控制器件以及上述人工智能芯片;其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;所述存储器件,用于存储数据;所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;所述控制器件,用于对所述人工智能芯片的状态进行监控。
图7示出根据本公开实施例的板卡的结构框图。参阅图7,上述板卡除了包括上述芯片389以外,还可以包括其他的配套部件,该配套部件包括但不限于:存储器件390、接口装置391和控制器件392;
所述存储器件390与所述人工智能芯片通过总线连接,用于存储数据。所述存储器件可以包括多组存储单元393。每一组所述存储单元与所述人工智能芯片通过总线连接。可以理解,每一组所述存储单元可以是DDR SDRAM(英文:Double Data Rate SDRAM,双倍速率同步动态随机存储器)。
上述处理器100中的存储单元102可以包括一组或多组存储单元393。在存储单元102包括一组存储单元393时,多个处理单元101公用存储单元393进行数据存储。在存储单元102包括多组存储单元393时,可以为每一个处理单元101设置其专用的一组存储单元393,并为多个处理单元101中的部分或全部设置其公用的一组存储单元393。
DDR不需要提高时钟频率就能加倍提高SDRAM的速度。DDR允许在时钟脉冲的上升沿和下降沿读出数据。DDR的速度是标准SDRAM的两倍。在一个实施例中,所述存储装置可以包括4组所述存储单元。每一组所述存储单元可以包括多个DDR4颗粒(芯片)。在一个实施例中,所述人工智能芯片内部可以包括4个72位DDR4控制器,上述72位DDR4控制器中64bit用于传输数据,8bit用于ECC校验。可以理解,当每一组所述存储单元中采用DDR4-3200颗粒时,数据传输的理论带宽可达到25600MB/s。
在一个实施例中,每一组所述存储单元包括多个并联设置的双倍速率同步动态随机存储器。DDR在一个时钟周期内可以传输两次数据。在所述芯片中设置控制DDR的控制器,用于对每个所述存储单元的数据传输与数据存储的控制。
所述接口装置与所述人工智能芯片电连接。所述接口装置用于实现所述人工智能芯片与外部设备(例如服务器或计算机)之间的数据传输。例如在一个实施例中,所述接口装置可以为标准PCIE接口。比如,待处理的数据由服务器通过标准PCIE接口传递至所述芯片,实现数据转移。优选的,当采用PCIE3.0X 16接口传输时,理论带宽可达到16000MB/s。在另一个实施例中,所述接口装置还可以是其他的接口,本公开并不限制上述其他的接口的具体表现形式,所述接口单元能够实现转接功能即可。另外,所述人工智能芯片的计算结果仍由所述接口装置传送回外部设备(例如服务器)。
所述控制器件与所述人工智能芯片电连接。所述控制器件用于对所述人工智能芯片的状态进行监控。具体的,所述人工智能芯片与所述控制器件可以通过SPI接口电连接。所述控制器件可以包括单片机(Micro Controller Unit,MCU)。如所述人工智能芯片可以包括多个处理芯片、多个处理核或多个处理电路,可以带动多个负载。因此,所述人工智能芯片可以处于多负载和轻负载等不同的工作状态。通过所述控制装置可以实现对所述人工智能芯片中多个处理芯片、多个处理和或多个处理电路的工作状态的调控。
在一种可能的实现方式中,公开了一种电子设备,其包括了上述人工智能芯片。电子设备包括数 据处理装置、机器人、电脑、打印机、扫描仪、平板电脑、智能终端、手机、行车记录仪、导航仪、传感器、摄像头、服务器、云端服务器、相机、摄像机、投影仪、手表、耳机、移动存储、可穿戴设备、交通工具、家用电器、和/或医疗设备。所述交通工具包括飞机、轮船和/或车辆;所述家用电器包括电视、空调、微波炉、冰箱、电饭煲、加湿器、洗衣机、电灯、燃气灶、油烟机;所述医疗设备包括核磁共振仪、B超仪和/或心电图仪。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。上述实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。
依据以下条款可更好地理解前述内容:
条款A1.一种神经网络量化方法,应用于终端,所述终端用于运行神经网络以执行目标任务,所述方法包括:
根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;
将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;
根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
条款A2.根据条款A1所述的方法,根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,包括以下至少一项:
根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的目标数据确定为一个待量化数据;
根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的同一种待运算数据确定为一个待量化数据;
根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个通道中的数据确定为一个待量化数据;
根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个批数的数据确定为一个待量化数据;
根据所述目标任务和/或所述终端的精度需求确定划分数据的划分尺寸,将对应待量化层中的目标数据按照所述划分尺寸划分为一个或多个待量化数据。
条款A3.根据条款A1或条款A2所述的方法,所述方法还包括:
根据所述目标任务和/或所述终端的精度需求,确定待量化数据对应的数据位宽;
根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数。
条款A4.根据条款A3所述的方法,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
当所述量化参数不包括偏移量时,根据各所述待量化数据中的绝对值最大值和对应的数据位宽,得到各所述待量化数据的第一类点位置。
条款A5.根据条款A3所述的方法,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
当所述量化参数不包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
根据各所述待量化数据中的绝对值最大值和所述量化后数据的最大值,得到各所述待量化数据的第一类缩放系数。
条款A6.根据条款A3所述的方法,所述根据各所述待量化数据和对应的数据位宽计算得到对应的 量化参数,包括:
当所述量化参数包括偏移量时,根据各所述待量化数据中的最大值、最小值和对应的数据位宽,得到各所述待量化数据的第二类点位置。
条款A7.根据条款A3所述的方法,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
当所述量化参数包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
根据各所述待量化数据中的最大值、最小值和量化后数据的最大值,得到各所述待量化数据的第二类缩放系数。
条款A8.根据条款A3所述的方法,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
根据各所述待量化数据中的最大值和最小值,得到各所述待量化数据的偏移量。
条款A9.根据条款A1至条款A8中任一项所述的方法,所述方法还包括:
根据各所述待量化数据和各所述待量化数据对应的量化数据,确定各所述待量化数据对应的量化误差;
根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽;
将各所述待量化数据对应的数据位宽更新为对应的调整位宽,根据各所述待量化数据和对应的调整位宽计算得到对应的调整量化参数,以使各所述待量化数据根据所述对应的调整量化参数进行量化。
条款A10.根据条款A9所述的方法,所述根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽,包括:
当所述量化误差大于第一误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽。
条款A11.根据条款A9或10所述的方法,所述方法还包括:
根据各所述待量化数据和对应的调整位宽计算各所述待量化数据调整后的量化误差;
根据所述调整后的量化误差和所述第一误差阈值继续增加所述对应的调整位宽,直至所述调整后的量化误差小于或等于所述第一误差阈值。
条款A12.根据条款A9或10所述的方法,所述根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽,包括:
当所述量化误差小于第二误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽,所述第二误差阈值小于所述第一误差阈值。
条款A13.根据条款A12所述的方法,所述方法还包括:
根据所述调整位宽和所述待量化数据计算所述待量化数据调整后的量化误差;
根据所述调整后的量化误差和所述第二误差阈值继续减少所述调整位宽,直至根据调整位宽和所述待量化数据计算得到的调整后的量化误差大于或等于所述第二误差阈值。
条款A14.根据条款A1至条款A13中任一项所述的方法,在所述神经网络运算的微调阶段和/或训练阶段,所述方法还包括:
获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述历史迭代为所述当前迭代之前的迭代;
根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述待量化层根据所述目标迭代间隔更新所述待量化数据的量化参数,所述目标迭代间隔包括至少一次迭代。
条款A15.根据条款A14所述的方法,所述方法还包括:
根据所述待量化数据在所述当前迭代的数据位宽,确定所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,以使所述神经网络根据所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,确定量化参数。
条款A16.根据条款A15所述的方法,所述方法还包括:
根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置,所述点位置包括第一类点位置和/或第二类点位置。
条款A17.根据条款A14所述的方法,所述获取当前迭代以及历史迭代中待量化数据的数据变动幅度,包括:
根据待量化数据在当前迭代的点位置,和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的点位置,计算待量化数据对应各迭代间隔的点位置的滑动平均值,所述点位置包括第一类点位置和/或第二类点位置;
根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度;
所述根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数,包括:
根据所述第一数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
条款A18.根据条款A17所述的方法,所述根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度,包括:
计算所述第一滑动平均值和所述第二滑动平均值的差值;
将所述差值的绝对值确定为第一数据变动幅度。
条款A19.根据条款A18所述的方法,所述方法还包括:
根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度;
所述根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数,包括:
根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
条款A20.根据条款A19所述的方法,所述根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度,包括:
计算在当前迭代所述待量化数据和所述待量化数据对应的量化数据之间的误差;
将所述误差的平方确定为所述第二数据变动幅度。
条款A21.根据条款A19所述的方法,所述根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,包括:
根据所述第一数据变动幅度和所述第二数据变动幅度中的最大值,确定所述待量化数据对应的目标迭代间隔。
条款A22.根据条款A14至条款A21中任一项所述的方法,所述获取当前迭代以及历史迭代中待量化数据的数据变动幅度,包括:
在当前迭代位于更新周期以外时,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述更新周期包括至少一个迭代。
条款A23.根据条款A14至条款A22中任一项所述的方法,所述方法还包括:
在当前迭代位于预设周期内时,根据当前迭代、在所述预设周期的下一周期中与所述当前迭代对应的迭代以及当前迭代对应的迭代间隔,确定周期间隔;
根据所述待量化数据在当前迭代对应的数据位宽,确定在所述周期间隔内的迭代中所述待量化数据的数据位宽;或
根据所述待量化数据在当前迭代对应的点位置,确定在所述周期间隔内的迭代中所述待量化数据的点位置。
条款A24.一种神经网络量化装置,应用于终端,所述终端用于运行神经网络以执行目标任务,所述装置包括:
数据确定模块,根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数 据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;
数据量化模块,将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;
结果确定模块,根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
条款A25.根据条款A24所述的装置,所述数据确定模块,包括以下至少一个子模块:
第一确定子模块,根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的目标数据确定为一个待量化数据;
第二确定子模块,根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的同一种待运算数据确定为一个待量化数据;
第三确定子模块,根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个通道中的数据确定为一个待量化数据;
第四确定子模块,根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个批数的数据确定为一个待量化数据;
第五确定子模块,根据所述目标任务和/或所述终端的精度需求确定划分数据的划分尺寸,将对应待量化层中的目标数据按照所述划分尺寸划分为一个或多个待量化数据。
条款A26.根据条款A24或25所述的装置,所述装置还包括:
数据位宽确定模块,根据所述目标任务和/或所述终端的精度需求,确定待量化数据对应的数据位宽;
参数确定模块,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数。
条款A27.根据条款A26所述的装置,所述参数确定模块,包括:
第一点位置确定子模块,当所述量化参数不包括偏移量时,根据各所述待量化数据中的绝对值最大值和对应的数据位宽,得到各所述待量化数据的第一类点位置。
条款A28.根据条款A26所述的装置,所述参数确定模块,包括:
第一最大值确定子模块,当所述量化参数不包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
第一缩放系数确定子模块,根据各所述待量化数据中的绝对值最大值和所述量化后数据的最大值,得到各所述待量化数据的第一类缩放系数。
条款A29.根据条款A26所述的装置,所述参数确定模块,包括:
第二点位置确定子模块,当所述量化参数包括偏移量时,根据各所述待量化数据中的最大值、最小值和对应的数据位宽,得到各所述待量化数据的第二类点位置。
条款A30.根据条款A26所述的装置,所述参数确定模块,包括:
第二最大值确定子模块,当所述量化参数包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
第一缩放系数确定子模块,根据各所述待量化数据中的最大值、最小值和量化后数据的最大值,得到各所述待量化数据的第二类缩放系数。
条款A31.根据条款A26所述的装置,所述参数确定模块,包括:
偏移量确定子模块,根据各所述待量化数据中的最大值和最小值,得到各所述待量化数据的偏移量。
条款A32.根据条款A24至条款A31任一项所述的装置,所述装置还包括:
第一量化误差确定模块,根据各所述待量化数据和各所述待量化数据对应的量化数据,确定各所述待量化数据对应的量化误差;
调整位宽确定模块,根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽;
调整量化参数确定模块,将各所述待量化数据对应的数据位宽更新为对应的调整位宽,根据各所述待量化数据和对应的调整位宽计算得到对应的调整量化参数,以使各所述待量化数据根据所述对应的调整量化参数进行量化。
条款A33.根据条款A32所述的装置,所述调整位宽确定模块,包括:
第一调整位宽确定子模块,当所述量化误差大于第一误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽。
条款A34.根据条款A32或条款A33所述的装置,所述装置还包括:
第一调整后量化误差模块,根据各所述待量化数据和对应的调整位宽计算各所述待量化数据调整后的量化误差;
第一调整位宽循环确定模块,根据所述调整后的量化误差和所述第一误差阈值继续增加所述对应的调整位宽,直至所述调整后的量化误差小于或等于所述第一误差阈值。
条款A35.根据条款A32或条款A33所述的装置,所述调整位宽确定模块,包括:
第二调整位宽确定子模块,当所述量化误差小于第二误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽,所述第二误差阈值小于所述第一误差阈值。
条款A36.根据条款A35所述的装置,所述装置还包括:
第二调整后量化误差模块,根据所述调整位宽和所述待量化数据计算所述待量化数据调整后的量化误差;
第二调整位宽循环确定模块,根据所述调整后的量化误差和所述第二误差阈值继续减少所述调整位宽,直至根据调整位宽和所述待量化数据计算得到的调整后的量化误差大于或等于所述第二误差阈值。
条款A37.根据条款A24至条款A36任一项所述的装置,在所述神经网络运算的微调阶段和/或训练阶段,所述装置还包括:
第一数据变动幅度确定模块,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述历史迭代为所述当前迭代之前的迭代;
目标迭代间隔确定模块,根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述待量化层根据所述目标迭代间隔更新所述待量化数据的量化参数,所述目标迭代间隔包括至少一次迭代。
条款A38.根据条款A37所述的装置,所述装置还包括:
第一目标迭代间隔应用模块,根据所述待量化数据在所述当前迭代的数据位宽,确定所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,以使所述神经网络根据所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,确定量化参数。
条款A39.根据条款A38所述的装置,所述装置还包括:
第二目标迭代间隔应用模块,根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置,所述点位置包括第一类点位置和/或第二类点位置。
条款A40.根据条款A37所述的装置,所述第一数据变动幅度确定模块,包括:
滑动平均值计算子模块,根据待量化数据在当前迭代的点位置,和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的点位置,计算待量化数据对应各迭代间隔的点位置的滑动平均值,所述点位置包括第一类点位置和/或第二类点位置;
第一数据变动幅度确定子模块,根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度;
其中,所述目标迭代间隔确定模块,包括:
第一目标迭代间隔确定子模块,根据所述第一数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
条款A41.根据条款A40所述的装置,所述第一数据变动幅度确定子模块,包括:
第一幅度确定子模块,计算所述第一滑动平均值和所述第二滑动平均值的差值;将所述差值的绝对值确定为第一数据变动幅度。
条款A42.根据条款A41所述的装置,所述装置还包括:
第二数据变动幅度确定模块,根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度;
其中,目标迭代间隔确定模块,包括:
第二目标迭代间隔确定子模块,根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
条款A43.根据条款A42所述的装置,所述第二数据变动幅度确定模块,包括:
第二幅度确定子模块,计算在当前迭代所述待量化数据和所述待量化数据对应的量化数据之间的误差;将所述误差的平方确定为所述第二数据变动幅度。
条款A44.根据条款A42所述的装置,所述第二目标迭代间隔确定子模块,包括:
间隔确定子模块,根据所述第一数据变动幅度和所述第二数据变动幅度中的最大值,确定所述待量化数据对应的目标迭代间隔。
条款A45.根据条款A37至条款A44任一项所述的装置,所述第一数据变动幅度确定模块,包括:
第二数据变动幅度确定子模块,在当前迭代位于更新周期以外时,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述更新周期包括至少一个迭代。
条款A46.根据条款A37至条款A45任一项所述的装置,所述装置还包括:
周期间隔确定模块,在当前迭代位于预设周期内时,根据当前迭代、在所述预设周期的下一周期中与所述当前迭代对应的迭代以及当前迭代对应的迭代间隔,确定周期间隔;
第一周期间隔应用模块,根据所述待量化数据在当前迭代对应的数据位宽,确定在所述周期间隔内的迭代中所述待量化数据的数据位宽;或
第二周期间隔应用模块,根据所述待量化数据在当前迭代对应的点位置,确定在所述周期间隔内的迭代中所述待量化数据的点位置。
条款A47.一种人工智能芯片,所述芯片包括如条款A24至条款A46中任意一项所述的神经网络量化装置。
条款A48.一种电子设备,所述电子设备包括如条款A47所述的人工智能芯片。
条款A49.一种板卡,所述板卡包括:存储器件、接口装置和控制器件以及如条款A47所述的人工智能芯片;
其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;
所述存储器件,用于存储数据;
所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;
所述控制器件,用于对所述人工智能芯片的状态进行监控。
条款A50.根据条款A49所述的板卡,
所述存储器件包括:多组存储单元,每一组所述存储单元与所述人工智能芯片通过总线连接,所述存储单元为:DDR SDRAM;
所述芯片包括:DDR控制器,用于对每个所述存储单元的数据传输与数据存储的控制;
所述接口装置为:标准PCIE接口。
条款A51.一种非易失性计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现条款A1至条款A23中任意一项所述的神经网络量化方法。
以上对本公开实施例进行了详细介绍,本文中应用了具体个例对本公开的原理及实施方式进行了阐述,以上实施例的说明仅用于帮助理解本公开的方法及其核心思想。同时,本领域技术人员依据本公开的思想,基于本公开的具体实施方式及应用范围上做出的改变或变形之处,都属于本公开保护的范围。综上所述,本说明书内容不应理解为对本公开的限制。

Claims (51)

  1. 一种神经网络量化方法,其特征在于,应用于终端,所述终端用于运行神经网络以执行目标任务,所述方法包括:
    根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;
    将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;
    根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
  2. 根据权利要求1所述的方法,其特征在于,根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,包括以下至少一项:
    根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的目标数据确定为一个待量化数据;
    根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的同一种待运算数据确定为一个待量化数据;
    根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个通道中的数据确定为一个待量化数据;
    根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个批数的数据确定为一个待量化数据;
    根据所述目标任务和/或所述终端的精度需求确定划分数据的划分尺寸,将对应待量化层中的目标数据按照所述划分尺寸划分为一个或多个待量化数据。
  3. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:
    根据所述目标任务和/或所述终端的精度需求,确定待量化数据对应的数据位宽;
    根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数。
  4. 根据权利要求3所述的方法,其特征在于,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
    当所述量化参数不包括偏移量时,根据各所述待量化数据中的绝对值最大值和对应的数据位宽,得到各所述待量化数据的第一类点位置。
  5. 根据权利要求3所述的方法,其特征在于,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
    当所述量化参数不包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
    根据各所述待量化数据中的绝对值最大值和所述量化后数据的最大值,得到各所述待量化数据的第一类缩放系数。
  6. 根据权利要求3所述的方法,其特征在于,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
    当所述量化参数包括偏移量时,根据各所述待量化数据中的最大值、最小值和对应的数据位宽,得到各所述待量化数据的第二类点位置。
  7. 根据权利要求3所述的方法,其特征在于,所述根据各所述待量化数据和对应的数据位宽计算 得到对应的量化参数,包括:
    当所述量化参数包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
    根据各所述待量化数据中的最大值、最小值和量化后数据的最大值,得到各所述待量化数据的第二类缩放系数。
  8. 根据权利要求3所述的方法,其特征在于,所述根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数,包括:
    根据各所述待量化数据中的最大值和最小值,得到各所述待量化数据的偏移量。
  9. 根据权利要求1至8中任一项所述的方法,其特征在于,所述方法还包括:
    根据各所述待量化数据和各所述待量化数据对应的量化数据,确定各所述待量化数据对应的量化误差;
    根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽;
    将各所述待量化数据对应的数据位宽更新为对应的调整位宽,根据各所述待量化数据和对应的调整位宽计算得到对应的调整量化参数,以使各所述待量化数据根据所述对应的调整量化参数进行量化。
  10. 根据权利要求9所述的方法,其特征在于,所述根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽,包括:
    当所述量化误差大于第一误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽。
  11. 根据权利要求9或10所述的方法,其特征在于,所述方法还包括:
    根据各所述待量化数据和对应的调整位宽计算各所述待量化数据调整后的量化误差;
    根据所述调整后的量化误差和所述第一误差阈值继续增加所述对应的调整位宽,直至所述调整后的量化误差小于或等于所述第一误差阈值。
  12. 根据权利要求9或10所述的方法,其特征在于,所述根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽,包括:
    当所述量化误差小于第二误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽,所述第二误差阈值小于所述第一误差阈值。
  13. 根据权利要求12所述的方法,其特征在于,所述方法还包括:
    根据所述调整位宽和所述待量化数据计算所述待量化数据调整后的量化误差;
    根据所述调整后的量化误差和所述第二误差阈值继续减少所述调整位宽,直至根据调整位宽和所述待量化数据计算得到的调整后的量化误差大于或等于所述第二误差阈值。
  14. 根据权利要求1至13中任一项所述的方法,其特征在于,在所述神经网络运算的微调阶段和/或训练阶段,所述方法还包括:
    获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述历史迭代为所述当前迭代之前的迭代;
    根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述待量化层根据所述目标迭代间隔更新所述待量化数据的量化参数,所述目标迭代间隔包括至少一次迭代。
  15. 根据权利要求14所述的方法,其特征在于,所述方法还包括:
    根据所述待量化数据在所述当前迭代的数据位宽,确定所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,以使所述神经网络根据所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,确定量化参数。
  16. 根据权利要求15所述的方法,其特征在于,所述方法还包括:
    根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置,所述点位置包括第一类点位置和/或第二类点位置。
  17. 根据权利要求14所述的方法,其特征在于,所述获取当前迭代以及历史迭代中待量化数据的数据变动幅度,包括:
    根据待量化数据在当前迭代的点位置,和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的点位置,计算待量化数据对应各迭代间隔的点位置的滑动平均值,所述点位置包括第一类点位置和/或第二类点位置;
    根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度;
    所述根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数,包括:
    根据所述第一数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
  18. 根据权利要求17所述的方法,其特征在于,所述根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度,包括:
    计算所述第一滑动平均值和所述第二滑动平均值的差值;
    将所述差值的绝对值确定为第一数据变动幅度。
  19. 根据权利要求18所述的方法,其特征在于,所述方法还包括:
    根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度;
    所述根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数,包括:
    根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
  20. 根据权利要求19所述的方法,其特征在于,所述根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度,包括:
    计算在当前迭代所述待量化数据和所述待量化数据对应的量化数据之间的误差;
    将所述误差的平方确定为所述第二数据变动幅度。
  21. 根据权利要求19所述的方法,其特征在于,所述根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,包括:
    根据所述第一数据变动幅度和所述第二数据变动幅度中的最大值,确定所述待量化数据对应的目标迭代间隔。
  22. 根据权利要求14至21中任一项所述的方法,其特征在于,所述获取当前迭代以及历史迭代中待量化数据的数据变动幅度,包括:
    在当前迭代位于更新周期以外时,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述更新周期包括至少一个迭代。
  23. 根据权利要求14至22中任一项所述的方法,其特征在于,所述方法还包括:
    在当前迭代位于预设周期内时,根据当前迭代、在所述预设周期的下一周期中与所述当前迭代对应的迭代以及当前迭代对应的迭代间隔,确定周期间隔;
    根据所述待量化数据在当前迭代对应的数据位宽,确定在所述周期间隔内的迭代中所述待量化数据的数据位宽;或
    根据所述待量化数据在当前迭代对应的点位置,确定在所述周期间隔内的迭代中所述待量化数据的点位置。
  24. 一种神经网络量化装置,其特征在于,应用于终端,所述终端用于运行神经网络以执行目标任务,所述装置包括:
    数据确定模块,根据所述目标任务和/或所述终端的精度需求,从目标数据中确定多个待量化数据,各所述待量化数据均为所述目标数据的子集,所述目标数据为所述神经网络的待量化层的任意一种待量化的待运算数据,所述待运算数据包括输入神经元、权值、偏置、梯度中的至少一种;
    数据量化模块,将各所述待量化数据分别根据对应的量化参数进行量化,得到与各所述待量化数据对应的量化数据;
    结果确定模块,根据与各所述待量化数据对应的量化数据得到所述目标数据的量化结果,以使所述待量化层根据所述目标数据的量化结果进行运算。
  25. 根据权利要求24所述的装置,其特征在于,所述数据确定模块,包括以下至少一个子模块:
    第一确定子模块,根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的目标数据确定为一个待量化数据;
    第二确定子模块,根据所述目标任务和/或所述终端的精度需求,将一层或多层待量化层中的同一种待运算数据确定为一个待量化数据;
    第三确定子模块,根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个通道中的数据确定为一个待量化数据;
    第四确定子模块,根据所述目标任务和/或所述终端的精度需求,将对应待量化层的目标数据中一个或多个批数的数据确定为一个待量化数据;
    第五确定子模块,根据所述目标任务和/或所述终端的精度需求确定划分数据的划分尺寸,将对应待量化层中的目标数据按照所述划分尺寸划分为一个或多个待量化数据。
  26. 根据权利要求24或25所述的装置,其特征在于,所述装置还包括:
    数据位宽确定模块,根据所述目标任务和/或所述终端的精度需求,确定待量化数据对应的数据位宽;
    参数确定模块,根据各所述待量化数据和对应的数据位宽计算得到对应的量化参数。
  27. 根据权利要求26所述的装置,其特征在于,所述参数确定模块,包括:
    第一点位置确定子模块,当所述量化参数不包括偏移量时,根据各所述待量化数据中的绝对值最大值和对应的数据位宽,得到各所述待量化数据的第一类点位置。
  28. 根据权利要求26所述的装置,其特征在于,所述参数确定模块,包括:
    第一最大值确定子模块,当所述量化参数不包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
    第一缩放系数确定子模块,根据各所述待量化数据中的绝对值最大值和所述量化后数据的最大值,得到各所述待量化数据的第一类缩放系数。
  29. 根据权利要求26所述的装置,其特征在于,所述参数确定模块,包括:
    第二点位置确定子模块,当所述量化参数包括偏移量时,根据各所述待量化数据中的最大值、最小值和对应的数据位宽,得到各所述待量化数据的第二类点位置。
  30. 根据权利要求26所述的装置,其特征在于,所述参数确定模块,包括:
    第二最大值确定子模块,当所述量化参数包括偏移量时,根据各所述待量化数据和对应的数据位宽得到量化后数据的最大值;
    第一缩放系数确定子模块,根据各所述待量化数据中的最大值、最小值和量化后数据的最大值,得到各所述待量化数据的第二类缩放系数。
  31. 根据权利要求26所述的装置,其特征在于,所述参数确定模块,包括:
    偏移量确定子模块,根据各所述待量化数据中的最大值和最小值,得到各所述待量化数据的偏移量。
  32. 根据权利要求24至31任一项所述的装置,其特征在于,所述装置还包括:
    第一量化误差确定模块,根据各所述待量化数据和各所述待量化数据对应的量化数据,确定各所述待量化数据对应的量化误差;
    调整位宽确定模块,根据各所述待量化数据对应的量化误差和误差阈值,调整各所述待量化数据对应的数据位宽,得到各所述待量化数据对应的调整位宽;
    调整量化参数确定模块,将各所述待量化数据对应的数据位宽更新为对应的调整位宽,根据各所述待量化数据和对应的调整位宽计算得到对应的调整量化参数,以使各所述待量化数据根据所述对应的调整量化参数进行量化。
  33. 根据权利要求32所述的装置,其特征在于,所述调整位宽确定模块,包括:
    第一调整位宽确定子模块,当所述量化误差大于第一误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽。
  34. 根据权利要求32或33所述的装置,其特征在于,所述装置还包括:
    第一调整后量化误差模块,根据各所述待量化数据和对应的调整位宽计算各所述待量化数据调整后的量化误差;
    第一调整位宽循环确定模块,根据所述调整后的量化误差和所述第一误差阈值继续增加所述对应的调整位宽,直至所述调整后的量化误差小于或等于所述第一误差阈值。
  35. 根据权利要求32或33所述的装置,其特征在于,所述调整位宽确定模块,包括:
    第二调整位宽确定子模块,当所述量化误差小于第二误差阈值时,增加所述对应的数据位宽,得到所述对应调整位宽,所述第二误差阈值小于所述第一误差阈值。
  36. 根据权利要求35所述的装置,其特征在于,所述装置还包括:
    第二调整后量化误差模块,根据所述调整位宽和所述待量化数据计算所述待量化数据调整后的量化误差;
    第二调整位宽循环确定模块,根据所述调整后的量化误差和所述第二误差阈值继续减少所述调整位宽,直至根据调整位宽和所述待量化数据计算得到的调整后的量化误差大于或等于所述第二误差阈 值。
  37. 根据权利要求24至36任一项所述的装置,其特征在于,在所述神经网络运算的微调阶段和/或训练阶段,所述装置还包括:
    第一数据变动幅度确定模块,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述历史迭代为所述当前迭代之前的迭代;
    目标迭代间隔确定模块,根据所述待量化数据的数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述待量化层根据所述目标迭代间隔更新所述待量化数据的量化参数,所述目标迭代间隔包括至少一次迭代。
  38. 根据权利要求37所述的装置,其特征在于,所述装置还包括:
    第一目标迭代间隔应用模块,根据所述待量化数据在所述当前迭代的数据位宽,确定所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,以使所述神经网络根据所述待量化数据在所述目标迭代间隔内的迭代对应的数据位宽,确定量化参数。
  39. 根据权利要求38所述的装置,其特征在于,所述装置还包括:
    第二目标迭代间隔应用模块,根据所述待量化数据在所述当前迭代对应的点位置,确定所述待量化数据在所述目标迭代间隔内的迭代对应的点位置,所述点位置包括第一类点位置和/或第二类点位置。
  40. 根据权利要求37所述的装置,其特征在于,所述第一数据变动幅度确定模块,包括:
    滑动平均值计算子模块,根据待量化数据在当前迭代的点位置,和根据历史迭代间隔确定的与所述当前迭代对应的历史迭代的点位置,计算待量化数据对应各迭代间隔的点位置的滑动平均值,所述点位置包括第一类点位置和/或第二类点位置;
    第一数据变动幅度确定子模块,根据所述待量化数据在当前迭代的点位置的第一滑动平均值,以及在上一迭代间隔对应迭代的点位置的第二滑动平均值,得到第一数据变动幅度;
    其中,所述目标迭代间隔确定模块,包括:
    第一目标迭代间隔确定子模块,根据所述第一数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
  41. 根据权利要求40所述的装置,其特征在于,所述第一数据变动幅度确定子模块,包括:
    第一幅度确定子模块,计算所述第一滑动平均值和所述第二滑动平均值的差值;将所述差值的绝对值确定为第一数据变动幅度。
  42. 根据权利要求41所述的装置,其特征在于,所述装置还包括:
    第二数据变动幅度确定模块,根据在当前迭代所述待量化数据和所述待量化数据对应的量化数据,得到第二数据变动幅度;
    其中,目标迭代间隔确定模块,包括:
    第二目标迭代间隔确定子模块,根据所述待量化数据的第一数据变动幅度和所述第二数据变动幅度,确定所述待量化数据对应的目标迭代间隔,以使所述神经网络根据所述目标迭代间隔更新所述待量化数据的量化参数。
  43. 根据权利要求42所述的装置,其特征在于,所述第二数据变动幅度确定模块,包括:
    第二幅度确定子模块,计算在当前迭代所述待量化数据和所述待量化数据对应的量化数据之间的误差;将所述误差的平方确定为所述第二数据变动幅度。
  44. 根据权利要求42所述的装置,其特征在于,所述第二目标迭代间隔确定子模块,包括:
    间隔确定子模块,根据所述第一数据变动幅度和所述第二数据变动幅度中的最大值,确定所述待量化数据对应的目标迭代间隔。
  45. 根据权利要求37至44任一项所述的装置,其特征在于,所述第一数据变动幅度确定模块,包括:
    第二数据变动幅度确定子模块,在当前迭代位于更新周期以外时,获取当前迭代以及历史迭代中待量化数据的数据变动幅度,所述更新周期包括至少一个迭代。
  46. 根据权利要求37至45任一项所述的装置,其特征在于,所述装置还包括:
    周期间隔确定模块,在当前迭代位于预设周期内时,根据当前迭代、在所述预设周期的下一周期中与所述当前迭代对应的迭代以及当前迭代对应的迭代间隔,确定周期间隔;
    第一周期间隔应用模块,根据所述待量化数据在当前迭代对应的数据位宽,确定在所述周期间隔内的迭代中所述待量化数据的数据位宽;或
    第二周期间隔应用模块,根据所述待量化数据在当前迭代对应的点位置,确定在所述周期间隔内的迭代中所述待量化数据的点位置。
  47. 一种人工智能芯片,其特征在于,所述芯片包括如权利要求24至46中任意一项所述的神经网络量化装置。
  48. 一种电子设备,其特征在于,所述电子设备包括如权利要求47所述的人工智能芯片。
  49. 一种板卡,其特征在于,所述板卡包括:存储器件、接口装置和控制器件以及如权利要求47所述的人工智能芯片;
    其中,所述人工智能芯片与所述存储器件、所述控制器件以及所述接口装置分别连接;
    所述存储器件,用于存储数据;
    所述接口装置,用于实现所述人工智能芯片与外部设备之间的数据传输;
    所述控制器件,用于对所述人工智能芯片的状态进行监控。
  50. 根据权利要求49所述的板卡,其特征在于,
    所述存储器件包括:多组存储单元,每一组所述存储单元与所述人工智能芯片通过总线连接,所述存储单元为:DDR SDRAM;
    所述芯片包括:DDR控制器,用于对每个所述存储单元的数据传输与数据存储的控制;
    所述接口装置为:标准PCIE接口。
  51. 一种非易失性计算机可读存储介质,其上存储有计算机程序指令,其特征在于,所述计算机程序指令被处理器执行时实现权利要求1至23中任意一项所述的神经网络量化方法。
PCT/CN2020/110299 2019-08-23 2020-08-20 数据处理方法、装置、计算机设备和存储介质 WO2021036904A1 (zh)

Priority Applications (3)

Application Number Priority Date Filing Date Title
JP2020567490A JP7146952B2 (ja) 2019-08-23 2020-08-20 データ処理方法、装置、コンピュータデバイス、及び記憶媒体
US17/254,998 US12001955B2 (en) 2019-08-23 2020-08-20 Data processing method, device, computer equipment and storage medium
EP20824880.7A EP4020321A4 (en) 2019-08-23 2020-08-20 DATA PROCESSING METHOD, APPARATUS, COMPUTER APPARATUS AND STORAGE MEDIUM

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN201910786064 2019-08-23
CN201910786064.1 2019-08-23
CN201910888552.3A CN112085151A (zh) 2019-06-12 2019-09-19 数据处理方法、装置、计算机设备和存储介质
CN201910888552.3 2019-09-19

Publications (1)

Publication Number Publication Date
WO2021036904A1 true WO2021036904A1 (zh) 2021-03-04

Family

ID=74684048

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/110299 WO2021036904A1 (zh) 2019-08-23 2020-08-20 数据处理方法、装置、计算机设备和存储介质

Country Status (4)

Country Link
US (1) US12001955B2 (zh)
EP (1) EP4020321A4 (zh)
JP (1) JP7146952B2 (zh)
WO (1) WO2021036904A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114841325A (zh) * 2022-05-20 2022-08-02 安谋科技(中国)有限公司 神经网络模型的数据处理方法、介质及电子设备

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11437032B2 (en) 2017-09-29 2022-09-06 Shanghai Cambricon Information Technology Co., Ltd Image processing apparatus and method
US11397579B2 (en) 2018-02-13 2022-07-26 Shanghai Cambricon Information Technology Co., Ltd Computing device and method
US11630666B2 (en) 2018-02-13 2023-04-18 Shanghai Cambricon Information Technology Co., Ltd Computing device and method
EP3651077B1 (en) 2018-02-13 2021-10-27 Shanghai Cambricon Information Technology Co., Ltd Computation device and method
CN116991226A (zh) 2018-02-14 2023-11-03 上海寒武纪信息科技有限公司 处理器的控制装置、方法及设备
EP3624020A4 (en) 2018-05-18 2021-05-05 Shanghai Cambricon Information Technology Co., Ltd CALCULATION PROCEDURES AND RELATED PRODUCTS
KR102470893B1 (ko) 2018-06-27 2022-11-25 상하이 캠브리콘 인포메이션 테크놀로지 컴퍼니 리미티드 온 칩 코드의 브레이크 포인트에 의한 디버그 방법, 온 칩 프로세서 및 브레이크 포인트에 의한 칩 디버그 시스템
US11966583B2 (en) 2018-08-28 2024-04-23 Cambricon Technologies Corporation Limited Data pre-processing method and device, and related computer device and storage medium
US11703939B2 (en) 2018-09-28 2023-07-18 Shanghai Cambricon Information Technology Co., Ltd Signal processing device and related products
CN111383638A (zh) 2018-12-28 2020-07-07 上海寒武纪信息科技有限公司 信号处理装置、信号处理方法及相关产品
CN111832738B (zh) 2019-04-18 2024-01-09 中科寒武纪科技股份有限公司 一种数据处理方法及相关产品
US20200334522A1 (en) 2019-04-18 2020-10-22 Cambricon Technologies Corporation Limited Data processing method and related products
US11676028B2 (en) 2019-06-12 2023-06-13 Shanghai Cambricon Information Technology Co., Ltd Neural network quantization parameter determination method and related products
CN112085191B (zh) 2019-06-12 2024-04-02 上海寒武纪信息科技有限公司 一种神经网络的量化参数确定方法及相关产品
WO2021036905A1 (zh) 2019-08-27 2021-03-04 安徽寒武纪信息科技有限公司 数据处理方法、装置、计算机设备和存储介质
US11601134B2 (en) * 2020-01-10 2023-03-07 Robert Bosch Gmbh Optimized quantization for reduced resolution neural networks
CN118525492A (zh) * 2022-12-20 2024-08-20 北京小米移动软件有限公司 信息处理方法及装置、通信设备及存储介质

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150340032A1 (en) * 2014-05-23 2015-11-26 Google Inc. Training multiple neural networks with different accuracy
CN109754074A (zh) * 2018-12-29 2019-05-14 北京中科寒武纪科技有限公司 一种神经网络量化方法、装置以及相关产品

Family Cites Families (186)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0375860A (ja) 1989-08-18 1991-03-29 Hitachi Ltd パーソナライズド端末
US5052043A (en) 1990-05-07 1991-09-24 Eastman Kodak Company Neural network with back propagation controlled through an output confidence measure
US6144977A (en) 1995-07-10 2000-11-07 Motorola, Inc. Circuit and method of converting a floating point number to a programmable fixed point number
GB9602701D0 (en) 1996-02-09 1996-04-10 Canon Kk Image manipulation
US7242414B1 (en) 1999-07-30 2007-07-10 Mips Technologies, Inc. Processor having a compare extension of an instruction set architecture
JP2000293371A (ja) 1999-04-09 2000-10-20 Hitachi Ltd マイクロプログラム制御方法及び装置
US6671796B1 (en) 2000-02-25 2003-12-30 Sun Microsystems, Inc. Converting an arbitrary fixed point value to a floating point value
US6931639B1 (en) 2000-08-24 2005-08-16 International Business Machines Corporation Method for implementing a variable-partitioned queue for simultaneous multithreaded processors
EP1315846B1 (en) 2000-09-07 2007-02-21 Nippon Steel Corporation Hexavalent chromium-free surface-treating agent for sn- or al-based coated steel sheet, and surface treated steel sheet
US20020138714A1 (en) 2001-03-22 2002-09-26 Sun Microsystems, Inc. Scoreboard for scheduling of instructions in a microprocessor that provides out of order execution
CN1270273C (zh) 2001-04-19 2006-08-16 艾利森电话股份有限公司 自适应存储器分配
US20030167460A1 (en) 2002-02-26 2003-09-04 Desai Vipul Anil Processor instruction set simulation power estimation method
US7236995B2 (en) 2002-12-27 2007-06-26 Arm Limited Data processing apparatus and method for converting a number between fixed-point and floating-point representations
DE10316381A1 (de) 2003-04-10 2004-10-28 Bayer Technology Services Gmbh Verfahren zum Training von neuronalen Netzen
JP4202244B2 (ja) 2003-12-22 2008-12-24 Necエレクトロニクス株式会社 Vliw型dsp,及びその動作方法
US20060161375A1 (en) 2004-12-30 2006-07-20 Allen Duberstein Optimizing processing speed based on measured temperatures
US7721128B2 (en) 2005-11-29 2010-05-18 International Business Machines Corporation Implementation of thermal throttling logic
CN1851668A (zh) 2006-06-01 2006-10-25 北京天碁科技有限公司 片上系统芯片、片上系统芯片的跟踪调试系统及方法
DE102006059156B4 (de) 2006-12-14 2008-11-06 Advanced Micro Devices, Inc., Sunnyvale Verfahren zum Testen eines integrierten Schaltkreischips mit zumindest zwei Schaltungskernen sowie integrierter Schaltkreischip und Testsystem
US20110060587A1 (en) 2007-03-07 2011-03-10 Phillips Michael S Command and control utilizing ancillary information in a mobile voice-to-speech application
US8560591B2 (en) 2007-04-25 2013-10-15 International Business Machines Corporation Detection of potential need to use a larger data format in performing floating point operations
US8051118B2 (en) 2007-04-26 2011-11-01 International Business Machines Corporation Composition of decimal floating point data
US8051117B2 (en) 2007-04-26 2011-11-01 International Business Machines Corporation Shift significand of decimal floating point data
US8190664B2 (en) 2007-04-26 2012-05-29 International Business Machines Corporation Employing a mask field of an instruction to encode a sign of a result of the instruction
JP5184824B2 (ja) 2007-06-15 2013-04-17 キヤノン株式会社 演算処理装置及び方法
JP2009110353A (ja) 2007-10-31 2009-05-21 Hitachi Ltd マイクロコントローラ及び制御システム
US7904287B2 (en) 2007-11-13 2011-03-08 International Business Machines Corporation Method and system for real-time prediction of power usage for a change to another performance state
JP4998794B2 (ja) 2007-11-29 2012-08-15 Nkワークス株式会社 画像補正方法と画像補正装置
US20100073068A1 (en) 2008-09-22 2010-03-25 Hanwoo Cho Functional block level thermal control
CN101572829B (zh) 2009-06-10 2011-02-02 中国联合网络通信集团有限公司 Iptv视频质量监测方法、装置和系统
EP2336882A1 (en) 2009-12-18 2011-06-22 Telefonaktiebolaget L M Ericsson (PUBL) Technique for run-time provision of executable code using off-device services
WO2011132277A1 (ja) 2010-04-21 2011-10-27 トヨタ自動車株式会社 内燃機関の制御装置
JP2011253374A (ja) 2010-06-02 2011-12-15 Sony Corp 情報処理装置、および情報処理方法、並びにプログラム
US8452463B2 (en) 2010-06-04 2013-05-28 Apple Inc. Adjusting the thermal behavior of a computing system using indirect information about ambient temperature
US8694572B2 (en) 2010-07-06 2014-04-08 Silminds, Llc, Egypt Decimal floating-point fused multiply-add unit
US8924455B1 (en) 2011-02-25 2014-12-30 Xilinx, Inc. Multiplication of matrices using systolic arrays
CN102761509B (zh) 2011-04-27 2016-01-06 联芯科技有限公司 Ofdm系统的接收系统及降低接收系统内存的方法
CN103534664B (zh) 2011-05-12 2016-08-31 苹果公司 存在感测
CN102789413B (zh) 2011-05-23 2016-02-17 同济大学 一种并行程序的调试系统及方法
US8594982B2 (en) 2011-06-09 2013-11-26 Pulsar Informatics, Inc. Systems and methods for distributed calculation of fatigue-risk prediction and optimization
CN102404673B (zh) 2011-11-24 2013-12-18 苏州上声电子有限公司 数字化扬声器系统通道均衡与声场控制方法和装置
CN103152673B (zh) 2011-12-07 2015-07-08 中国科学院声学研究所 基于四元码动态失配整形的数字扬声器驱动方法和装置
CN102684701B (zh) 2012-04-27 2014-07-09 苏州上声电子有限公司 基于编码转换的数字扬声器驱动方法和装置
DE102012009502A1 (de) 2012-05-14 2013-11-14 Kisters Ag Verfahren zum Trainieren eines künstlichen neuronalen Netzes
US9417891B2 (en) 2012-06-11 2016-08-16 Vmware, Inc. Unified storage/VDI provisioning methodology
US9063731B2 (en) 2012-08-27 2015-06-23 Samsung Electronics Co., Ltd. Ultra low power apparatus and method to wake up a main processor
CN102903089B (zh) 2012-09-07 2014-12-17 山东大学 一种Linux环境下生成遥感图像快视图的方法
US9412366B2 (en) 2012-09-18 2016-08-09 Adobe Systems Incorporated Natural language image spatial and tonal localization
CN102981854A (zh) 2012-11-16 2013-03-20 天津市天祥世联网络科技有限公司 基于浮点数运算内联函数库的神经网络优化方法
WO2014081007A1 (ja) 2012-11-22 2014-05-30 学校法人慶應義塾 アクリル系共重合体、光学フィルム、偏光板および液晶表示装置
US9851977B2 (en) 2012-12-06 2017-12-26 Kalray Apparatus and method for combining thread warps with compatible execution masks for simultaneous execution and increased lane utilization
US9720732B1 (en) 2013-02-11 2017-08-01 Amazon Technologies, Inc. Parameter selection for optimization of task execution based on execution history for prior tasks
JP2014170295A (ja) 2013-03-01 2014-09-18 Honda Motor Co Ltd 物体認識システム及び物体認識方法
US12047340B2 (en) 2013-04-29 2024-07-23 Dell Products L.P. System for managing an instructure with security
JP6184891B2 (ja) 2014-03-12 2017-08-23 東芝メモリ株式会社 情報処理装置、半導体チップ、情報処理方法およびプログラム
US9507405B2 (en) 2014-06-18 2016-11-29 Oracle International Corporation System and method for managing power in a chip multiprocessor using a proportional feedback mechanism
US9575537B2 (en) 2014-07-25 2017-02-21 Intel Corporation Adaptive algorithm for thermal throttling of multi-core processors with non-homogeneous performance states
US10282100B2 (en) 2014-08-19 2019-05-07 Samsung Electronics Co., Ltd. Data management scheme in virtualized hyperscale environments
GB2524126B (en) 2014-08-28 2016-07-27 Imagination Tech Ltd Combining paths
ES2738319T3 (es) * 2014-09-12 2020-01-21 Microsoft Technology Licensing Llc Sistema informático para entrenar redes neuronales
US9916130B2 (en) 2014-11-03 2018-03-13 Arm Limited Apparatus and method for vector processing
FR3030077B1 (fr) 2014-12-10 2016-12-02 Arnault Ioualalen Procede d'ajustement de la precision d'un programme d'ordinateur manipulant au moins un nombre a virgule.
EP3035204B1 (en) 2014-12-19 2018-08-15 Intel Corporation Storage device and method for performing convolution operations
US20170061279A1 (en) 2015-01-14 2017-03-02 Intel Corporation Updating an artificial neural network using flexible fixed point representation
US20160328645A1 (en) 2015-05-08 2016-11-10 Qualcomm Incorporated Reduced computational complexity for fixed point neural network
US10262259B2 (en) 2015-05-08 2019-04-16 Qualcomm Incorporated Bit width selection for fixed point neural networks
US10373050B2 (en) * 2015-05-08 2019-08-06 Qualcomm Incorporated Fixed point neural network based on floating point neural network quantization
US10083395B2 (en) 2015-05-21 2018-09-25 Google Llc Batch processing in a neural network processor
CN104899641B (zh) 2015-05-25 2018-07-13 杭州朗和科技有限公司 深度神经网络学习方法、处理器和深度神经网络学习系统
CN115100016A (zh) 2015-06-10 2022-09-23 无比视视觉技术有限公司 用于处理图像的图像处理器和方法
CN104978303B (zh) 2015-06-19 2019-06-04 上海兆芯集成电路有限公司 单芯片整合的传感器集线器和多传感器管理方法
CN106469291A (zh) 2015-08-19 2017-03-01 中兴通讯股份有限公司 图像处理方法及终端
US10031765B2 (en) 2015-09-24 2018-07-24 Intel Corporation Instruction and logic for programmable fabric hierarchy and cache
US10812831B2 (en) 2015-09-30 2020-10-20 Piksel, Inc. Video stream delivery via adaptive quality enhancement using error correction models
US11061672B2 (en) 2015-10-02 2021-07-13 Via Alliance Semiconductor Co., Ltd. Chained split execution of fused compound arithmetic operations
CN106570559A (zh) 2015-10-09 2017-04-19 阿里巴巴集团控股有限公司 一种基于神经网络的数据处理方法和装置
WO2017087568A1 (en) 2015-11-17 2017-05-26 Eman Bayani A digital image capturing device system and method
CN106814639A (zh) 2015-11-27 2017-06-09 富泰华工业(深圳)有限公司 语音控制系统及方法
CN105893419A (zh) 2015-11-30 2016-08-24 乐视致新电子科技(天津)有限公司 一种多媒体照片生成方法、装置、设备及手机
US10699186B2 (en) 2015-12-02 2020-06-30 Google Llc Determining orders of execution of a neural network
CN110135581B (zh) 2016-01-20 2020-11-06 中科寒武纪科技股份有限公司 用于执行人工神经网络反向运算的装置和方法
CN106997236B (zh) 2016-01-25 2018-07-13 亮风台(上海)信息科技有限公司 基于多模态输入进行交互的方法和设备
US10664766B2 (en) 2016-01-27 2020-05-26 Bonsai AI, Inc. Graphical user interface to an artificial intelligence engine utilized to generate one or more trained artificial intelligence models
US10497089B2 (en) 2016-01-29 2019-12-03 Fotonation Limited Convolutional neural network
US10103714B2 (en) 2016-03-01 2018-10-16 Qualcomm Incorporated Adjust voltage for thermal mitigation
JP2017156511A (ja) 2016-03-01 2017-09-07 ソニー株式会社 情報処理装置、情報処理方法、およびプログラム
US10019779B2 (en) 2016-03-08 2018-07-10 Amazon Technologies, Inc. Browsing interface for item counterparts having different scales and lengths
US10552119B2 (en) 2016-04-29 2020-02-04 Intel Corporation Dynamic management of numerical representation in a distributed matrix processor architecture
CN107330515A (zh) 2016-04-29 2017-11-07 北京中科寒武纪科技有限公司 一种用于执行人工神经网络正向运算的装置和方法
US10187568B1 (en) 2016-05-02 2019-01-22 Bao Tran Video smart phone
US11055063B2 (en) 2016-05-02 2021-07-06 Marvell Asia Pte, Ltd. Systems and methods for deep learning processor
CN105978611B (zh) 2016-05-12 2019-09-17 京信通信系统(中国)有限公司 一种频域信号压缩方法及装置
AU2016203619A1 (en) 2016-05-31 2017-12-14 Canon Kabushiki Kaisha Layer-based operations scheduling to optimise memory for CNN applications
EP3252949B1 (en) 2016-06-01 2020-03-18 Intel IP Corporation Methods and devices for predistortion of signals
US20170357910A1 (en) 2016-06-10 2017-12-14 Apple Inc. System for iteratively training an artificial intelligence using cloud-based metrics
CN107545889B (zh) 2016-06-23 2020-10-23 华为终端有限公司 适用于模式识别的模型的优化方法、装置及终端设备
CN106156310A (zh) 2016-06-30 2016-11-23 努比亚技术有限公司 一种图片处理装置和方法
US10372588B2 (en) 2016-07-08 2019-08-06 International Business Machines Corporation Providing debug information on production containers using debug containers
DE102016214786A1 (de) 2016-08-09 2018-02-15 Fujitsu Limited Anwendungsprofiling-Jobmanagement-System, -Programm und -Verfahren
US20180046903A1 (en) 2016-08-12 2018-02-15 DeePhi Technology Co., Ltd. Deep processing unit (dpu) for implementing an artificial neural network (ann)
CN107657316B (zh) 2016-08-12 2020-04-07 北京深鉴智能科技有限公司 通用处理器与神经网络处理器的协同系统设计
CN106354568A (zh) 2016-08-23 2017-01-25 京信通信技术(广州)有限公司 一种不同进程间的通信方法及通信装置
CN107797913A (zh) 2016-09-07 2018-03-13 大陆汽车电子(连云港)有限公司 一种实时系统的软件分析系统与方法
US11907760B2 (en) 2016-09-23 2024-02-20 Apple Inc. Systems and methods of memory allocation for neural networks
CN106650922B (zh) 2016-09-29 2019-05-03 清华大学 硬件神经网络转换方法、计算装置、软硬件协作系统
US20180096243A1 (en) 2016-09-30 2018-04-05 General Electric Company Deep learning for data driven feature representation and anomaly detection
US10726330B2 (en) 2016-10-11 2020-07-28 The Research Foundation For The State University Of New York System, method, and accelerator to process convolutional neural network layers
CN106485316B (zh) 2016-10-31 2019-04-02 北京百度网讯科技有限公司 神经网络模型压缩方法以及装置
CN106502626A (zh) 2016-11-03 2017-03-15 北京百度网讯科技有限公司 数据处理方法和装置
US10216479B2 (en) 2016-12-06 2019-02-26 Arm Limited Apparatus and method for performing arithmetic operations to accumulate floating-point numbers
US10997492B2 (en) 2017-01-20 2021-05-04 Nvidia Corporation Automated methods for conversions to a lower precision data format
CN106951587A (zh) 2017-02-15 2017-07-14 芯启源(南京)半导体科技有限公司 Fpga调试系统及方法
CN106951962B (zh) 2017-03-22 2020-09-01 南京地平线机器人技术有限公司 用于神经网络的复合运算单元、方法和电子设备
US10402932B2 (en) 2017-04-17 2019-09-03 Intel Corporation Power-based and target-based graphics quality adjustment
US10332302B2 (en) 2017-04-17 2019-06-25 Intel Corporation Scatter gather engine
CN107025629B (zh) 2017-04-27 2021-03-26 维沃移动通信有限公司 一种图像处理方法及移动终端
US11842280B2 (en) 2017-05-05 2023-12-12 Nvidia Corporation Loss-scaling for deep neural network training with reduced precision
US10019668B1 (en) 2017-05-19 2018-07-10 Google Llc Scheduling neural network processing
US11144828B2 (en) 2017-06-09 2021-10-12 Htc Corporation Training task optimization system, training task optimization method and non-transitory computer readable medium for operating the same
US10944902B2 (en) 2017-06-20 2021-03-09 Adobe Inc. Digital image generation using capture support data
US9916531B1 (en) 2017-06-22 2018-03-13 Intel Corporation Accumulator constrained quantization of convolutional neural networks
WO2019005088A1 (en) 2017-06-30 2019-01-03 Intel Corporation HETEROGENEOUS MULTIPLIER
CN109214509B (zh) 2017-07-05 2021-07-06 中国科学院沈阳自动化研究所 一种用于深度神经网络高速实时量化结构和运算实现方法
CN107451654B (zh) 2017-07-05 2021-05-18 深圳市自行科技有限公司 卷积神经网络的加速运算方法、服务器及存储介质
US10427306B1 (en) 2017-07-06 2019-10-01 X Development Llc Multimodal object identification
CN107729990B (zh) 2017-07-20 2021-06-08 上海寒武纪信息科技有限公司 支持离散数据表示的用于执行正向运算的装置及方法
CN107451658B (zh) 2017-07-24 2020-12-15 杭州菲数科技有限公司 浮点运算定点化方法及系统
CN107688849B (zh) 2017-07-28 2021-04-13 赛灵思电子科技(北京)有限公司 一种动态策略定点化训练方法及装置
US11481218B2 (en) 2017-08-02 2022-10-25 Intel Corporation System and method enabling one-hot neural networks on a machine learning compute platform
KR102601604B1 (ko) 2017-08-04 2023-11-13 삼성전자주식회사 뉴럴 네트워크의 파라미터들을 양자화하는 방법 및 장치
WO2019031858A1 (en) 2017-08-08 2019-02-14 Samsung Electronics Co., Ltd. METHOD AND APPARATUS FOR DETERMINING MEMORY NEEDS IN A NETWORK
US20190050710A1 (en) * 2017-08-14 2019-02-14 Midea Group Co., Ltd. Adaptive bit-width reduction for neural networks
CN107644254A (zh) 2017-09-09 2018-01-30 复旦大学 一种卷积神经网络权重参数量化训练方法及系统
US11450319B2 (en) 2017-09-29 2022-09-20 Cambricon (Xi'an) Semiconductor Co., Ltd. Image processing apparatus and method
KR102380494B1 (ko) 2017-09-29 2022-03-29 상하이 캠브리콘 인포메이션 테크놀로지 컴퍼니 리미티드 화상처리장치 및 방법
US10223114B1 (en) 2017-09-29 2019-03-05 Intel Corporation Fixed point to floating point conversion
US10224954B1 (en) 2017-09-29 2019-03-05 Intel Corporation Floating point to fixed point conversion
US11437032B2 (en) 2017-09-29 2022-09-06 Shanghai Cambricon Information Technology Co., Ltd Image processing apparatus and method
JP6540770B2 (ja) 2017-10-17 2019-07-10 富士通株式会社 演算処理回路、演算処理回路を含む演算処理装置、演算処理装置を含む情報処理装置、および方法
US10410121B2 (en) 2017-10-25 2019-09-10 SparkCognition, Inc. Adjusting automated neural network generation based on evaluation of candidate neural networks
US20210061028A1 (en) 2017-10-26 2021-03-04 Applied Mechatronic Products Apparatus and method for vehicular monitoring, analysis, and control
KR20190054454A (ko) * 2017-11-13 2019-05-22 삼성전자주식회사 인공 신경망의 양자화 방법 및 장치
US10783634B2 (en) 2017-11-22 2020-09-22 General Electric Company Systems and methods to deliver point of care alerts for radiological findings
US10803379B2 (en) 2017-12-12 2020-10-13 Amazon Technologies, Inc. Multi-memory on-chip computational network
US11138505B2 (en) * 2017-12-21 2021-10-05 Fujitsu Limited Quantization of neural network parameters
CN108053028B (zh) 2017-12-21 2021-09-14 深圳励飞科技有限公司 数据定点化处理方法、装置、电子设备及计算机存储介质
US11636327B2 (en) 2017-12-29 2023-04-25 Intel Corporation Machine learning sparse computation mechanism for arbitrary neural networks, arithmetic compute microarchitecture, and sparsity for training mechanism
US11373088B2 (en) 2017-12-30 2022-06-28 Intel Corporation Machine learning accelerator mechanism
US20190251429A1 (en) 2018-02-12 2019-08-15 Kneron, Inc. Convolution operation device and method of scaling convolution input for convolution neural network
US11397579B2 (en) 2018-02-13 2022-07-26 Shanghai Cambricon Information Technology Co., Ltd Computing device and method
US11630666B2 (en) 2018-02-13 2023-04-18 Shanghai Cambricon Information Technology Co., Ltd Computing device and method
US11106598B2 (en) 2018-02-13 2021-08-31 Shanghai Cambricon Information Technology Co., Ltd. Computing device and method
CN116991226A (zh) 2018-02-14 2023-11-03 上海寒武纪信息科技有限公司 处理器的控制装置、方法及设备
JP7056225B2 (ja) 2018-02-26 2022-04-19 富士通株式会社 演算処理装置、情報処理装置、情報処理方法、およびプログラム
US10628275B2 (en) 2018-03-07 2020-04-21 Nxp B.V. Runtime software-based self-test with mutual inter-core checking
US11475306B2 (en) 2018-03-22 2022-10-18 Amazon Technologies, Inc. Processing for multiple input data sets
CN108510067B (zh) 2018-04-11 2021-11-09 西安电子科技大学 基于工程化实现的卷积神经网络量化方法
US11562213B2 (en) 2018-04-17 2023-01-24 Intel Corporation Methods and arrangements to manage memory in cascaded neural networks
US11645493B2 (en) * 2018-05-04 2023-05-09 Microsoft Technology Licensing, Llc Flow for quantized neural networks
US10691413B2 (en) 2018-05-04 2020-06-23 Microsoft Technology Licensing, Llc Block floating point computations using reduced bit-width vectors
EP3624020A4 (en) 2018-05-18 2021-05-05 Shanghai Cambricon Information Technology Co., Ltd CALCULATION PROCEDURES AND RELATED PRODUCTS
CN108717570A (zh) 2018-05-23 2018-10-30 电子科技大学 一种脉冲神经网络参数量化方法
CN115268082A (zh) 2018-05-31 2022-11-01 中强光电股份有限公司 头戴式显示装置
US10360304B1 (en) 2018-06-04 2019-07-23 Imageous, Inc. Natural language processing interface-enabled building conditions control system
CN109062540B (zh) 2018-06-06 2022-11-25 北京理工大学 一种基于cordic算法的可重构浮点运算装置
CN109063820A (zh) 2018-06-07 2018-12-21 中国科学技术大学 利用时频联合长时循环神经网络的数据处理方法
CN109146057B (zh) 2018-06-26 2020-12-08 杭州雄迈集成电路技术股份有限公司 一种基于查表计算的高精度的神经网络工程化方法
KR102470893B1 (ko) 2018-06-27 2022-11-25 상하이 캠브리콘 인포메이션 테크놀로지 컴퍼니 리미티드 온 칩 코드의 브레이크 포인트에 의한 디버그 방법, 온 칩 프로세서 및 브레이크 포인트에 의한 칩 디버그 시스템
CN110728364A (zh) 2018-07-17 2020-01-24 上海寒武纪信息科技有限公司 一种运算装置和运算方法
US11966583B2 (en) 2018-08-28 2024-04-23 Cambricon Technologies Corporation Limited Data pre-processing method and device, and related computer device and storage medium
US11703939B2 (en) 2018-09-28 2023-07-18 Shanghai Cambricon Information Technology Co., Ltd Signal processing device and related products
CN109472353B (zh) 2018-11-22 2020-11-03 浪潮集团有限公司 一种卷积神经网络量化电路及量化方法
CN109685202B (zh) 2018-12-17 2023-03-21 腾讯科技(深圳)有限公司 数据处理方法及装置、存储介质和电子装置
CN111383638A (zh) 2018-12-28 2020-07-07 上海寒武纪信息科技有限公司 信号处理装置、信号处理方法及相关产品
CN109800877B (zh) 2019-02-20 2022-12-30 腾讯科技(深圳)有限公司 神经网络的参数调整方法、装置及设备
CN109902745A (zh) 2019-03-01 2019-06-18 成都康乔电子有限责任公司 一种基于cnn的低精度训练与8位整型量化推理方法
CN110059733A (zh) 2019-04-01 2019-07-26 苏州科达科技股份有限公司 卷积神经网络的优化及快速目标检测方法、装置
CN109993296B (zh) 2019-04-01 2020-12-29 安徽寒武纪信息科技有限公司 量化实现方法及相关产品
CN111832738B (zh) 2019-04-18 2024-01-09 中科寒武纪科技股份有限公司 一种数据处理方法及相关产品
US20200334522A1 (en) 2019-04-18 2020-10-22 Cambricon Technologies Corporation Limited Data processing method and related products
CN112085191B (zh) 2019-06-12 2024-04-02 上海寒武纪信息科技有限公司 一种神经网络的量化参数确定方法及相关产品
US11676028B2 (en) 2019-06-12 2023-06-13 Shanghai Cambricon Information Technology Co., Ltd Neural network quantization parameter determination method and related products
WO2021036908A1 (zh) 2019-08-23 2021-03-04 安徽寒武纪信息科技有限公司 数据处理方法、装置、计算机设备和存储介质
JP7146954B2 (ja) 2019-08-23 2022-10-04 安徽寒武紀信息科技有限公司 データ処理方法、装置、コンピュータデバイス、及び記憶媒体
WO2021036905A1 (zh) 2019-08-27 2021-03-04 安徽寒武纪信息科技有限公司 数据处理方法、装置、计算机设备和存储介质
CN110780845B (zh) 2019-10-17 2021-11-30 浙江大学 一种用于量化卷积神经网络的可配置近似乘法器及其实现方法

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150340032A1 (en) * 2014-05-23 2015-11-26 Google Inc. Training multiple neural networks with different accuracy
CN109754074A (zh) * 2018-12-29 2019-05-14 北京中科寒武纪科技有限公司 一种神经网络量化方法、装置以及相关产品

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4020321A4 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114841325A (zh) * 2022-05-20 2022-08-02 安谋科技(中国)有限公司 神经网络模型的数据处理方法、介质及电子设备

Also Published As

Publication number Publication date
US20210264270A1 (en) 2021-08-26
EP4020321A1 (en) 2022-06-29
EP4020321A4 (en) 2024-01-17
JP2022501675A (ja) 2022-01-06
US12001955B2 (en) 2024-06-04
JP7146952B2 (ja) 2022-10-04

Similar Documents

Publication Publication Date Title
WO2021036904A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036908A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036905A1 (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036890A1 (zh) 数据处理方法、装置、计算机设备和存储介质
CN112085181B (zh) 神经网络量化方法及装置以及相关产品
WO2021022903A1 (zh) 数据处理方法、装置、计算机设备和存储介质
CN112085176B (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021036362A1 (zh) 用于处理数据的方法、装置以及相关产品
CN112085187A (zh) 数据处理方法、装置、计算机设备和存储介质
CN112085182A (zh) 数据处理方法、装置、计算机设备和存储介质
WO2021169914A1 (zh) 数据量化处理方法、装置、电子设备和存储介质
CN112085151A (zh) 数据处理方法、装置、计算机设备和存储介质
US20220366238A1 (en) Method and apparatus for adjusting quantization parameter of recurrent neural network, and related product
WO2021036412A1 (zh) 数据处理方法、装置、计算机设备和存储介质
CN112085177A (zh) 数据处理方法、装置、计算机设备和存储介质
US20220222041A1 (en) Method and apparatus for processing data, and related product

Legal Events

Date Code Title Description
ENP Entry into the national phase

Ref document number: 2020567490

Country of ref document: JP

Kind code of ref document: A

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

Ref document number: 20824880

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2020824880

Country of ref document: EP

Effective date: 20220323