TW201928794A - Neural network training method and related product having the advantages of small calculation amount and low power consumption - Google Patents

Neural network training method and related product having the advantages of small calculation amount and low power consumption Download PDF

Info

Publication number
TW201928794A
TW201928794A TW107144042A TW107144042A TW201928794A TW 201928794 A TW201928794 A TW 201928794A TW 107144042 A TW107144042 A TW 107144042A TW 107144042 A TW107144042 A TW 107144042A TW 201928794 A TW201928794 A TW 201928794A
Authority
TW
Taiwan
Prior art keywords
data
layer
input data
nth
reverse
Prior art date
Application number
TW107144042A
Other languages
Chinese (zh)
Other versions
TWI793225B (en
Inventor
劉少禮
宋新開
王秉睿
張堯
胡帥
Original Assignee
大陸商北京中科寒武紀科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 大陸商北京中科寒武紀科技有限公司 filed Critical 大陸商北京中科寒武紀科技有限公司
Publication of TW201928794A publication Critical patent/TW201928794A/en
Application granted granted Critical
Publication of TWI793225B publication Critical patent/TWI793225B/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/06Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons
    • G06N3/063Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons using electronic means
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The present disclosure provides a neural network training method performed on an integrated circuit chip device and a related product, the neural network comprising multiple layers, wherein the method includes the following steps: receiving a training instruction, and determining first layer input data and first layer weight data according to the training instruction, the computing device performing the nth layer forward operation of the neural network through the first layer input data and the first layer weight data to obtain the nth output result; obtaining the nth output result gradient according to the nth output result, and obtaining an nth inverse operation of the nth layer inverse operation according to the training instruction, and the computing device obtaining nth inverse operation complexity according to the nth output result gradient, the nth layer input data, the nth layer weight group data, and the nth inverse operation. The technical solution provided by the present disclosure has the advantages of small calculation amount and low power consumption.

Description

神經網絡訓練方法及相關產品Neural network training method and related products

本披露涉及神經網絡領域,尤其涉及一種神經網絡訓練方法及相關產品。The present disclosure relates to the field of neural networks, and in particular, to a neural network training method and related products.

人工神經網絡(Artificial Neural Network, ANN ),是20世紀80 年代以來人工智能領域興起的研究熱點。它從信息處理角度對人腦神經元網絡進行抽象, 建立某種簡單模型,按不同的連接方式組成不同的網絡。在工程與學術界也常直接簡稱為神經網絡或類神經網絡。神經網絡是一種運算模型,由大量的節點(或稱神經元)之間相互聯接構成。現有的神經網絡的運算基於CPU(Central Processing Unit,中央處理器)或GPU(Graphics Processing Unit,圖形處理器)來實現神經網絡的正向運算,此種正向運算的計算量大,功耗高。Artificial neural network (Artificial Neural Network, ANN) is a research hotspot that has emerged in the field of artificial intelligence since the 1980s. It abstracts the human brain neuron network from the perspective of information processing, establishes some simple model, and forms different networks according to different connection methods. In engineering and academia, it is often referred to as neural network or neural network. A neural network is a computing model that consists of a large number of nodes (or neurons) connected to each other. The existing neural network operations are based on the CPU (Central Processing Unit, Central Processing Unit) or GPU (Graphics Processing Unit, Graphics Processor) to implement the forward operation of the neural network. This forward operation has a large amount of calculation and high power consumption. .

本披露實施例提供了一種神經網絡訓練方法及相關產品,可提升計算裝置的處理速度,提高效率。The embodiments of the present disclosure provide a neural network training method and related products, which can improve the processing speed and efficiency of a computing device.

第一方面,提供一種集成電路芯片裝置上執行的神經網絡的訓練方法,該神經網絡包含n層,其中,所述方法包括如下步驟:According to a first aspect, a method for training a neural network executed on an integrated circuit chip device is provided. The neural network includes n layers, and the method includes the following steps:

接收訓練指令,依據該訓練指令確定第一層輸入數據和第一層權值組數據,計算裝置通過第一層輸入數據和第一層權值組數據執行神經網絡的n層正向運算得到正向運算的第n輸出結果;Receive a training instruction, determine the first layer of input data and the first layer of weight group data according to the training instruction, and the computing device executes the n-layer forward operation of the neural network to obtain a positive value through the first layer of input data and the first layer of weight group data. Output the result to the nth operation;

依據所述第n輸出結果得到第n輸出結果梯度,依據所述訓練指令獲取第n層反向運算的第n反向運算,依據第n輸出結果梯度、第n層輸入數據、第n層權值組數據以及第n反向運算得到第n反向運算複雜度,依據所述第n反向運算複雜度確定第n輸出結果梯度、第n層輸入數據、第n層權值組數據對應的第n反向數據類型,將第n輸出結果梯度、第n層輸入數據、第n層權值組數據以第n反向數據類型執行神經網絡的第n層反向運算得到第n層權值組梯度和第n層輸入數據梯度; 應用所述第n層權值組梯度對第n層權值組數據進行更新;所述第n反向數據類型包括:定點類型或浮點類型;An n-th output result gradient is obtained according to the n-th output result, an n-th inverse operation of an n-th layer inverse operation is obtained according to the training instruction, an n-th output result gradient, an n-th input data, and an n-th weight are obtained according to the n-th output result gradient. The value group data and the nth inverse operation obtain the nth inverse operation complexity, and the nth output result gradient, the nth layer input data, and the nth layer weight group data corresponding to the nth output result gradient are determined according to the nth inverse operation complexity. The nth inverse data type, which uses the nth output result gradient, the nth layer input data, and the nth layer weight group data to perform the nth layer inverse operation of the neural network using the nth inverse data type to obtain the nth layer weight Group gradient and n-th input data gradient; applying the n-th weight group gradient to update the n-th weight group data; the n-th reverse data type includes: fixed-point type or floating-point type;

將第n層輸入數據梯度作為第n-1層的第n-1輸出結果梯度執行n-1層方向運算得到n-1層權值組梯度,應用n-1層權值組梯度更新對應層的權值組數據,所述權值組數據包括;至少二個權值。Use the n-th input data gradient as the n-1th output result of the n-1th layer. Perform the n-1 layer direction operation to get the n-1 layer weight group gradient. Apply the n-1 layer weight group gradient to update the corresponding layer. Weight group data, the weight group data includes; at least two weights.

第二方面,提供一種集成電路芯片裝置,所述集成電路芯片裝置用於執行神經網絡的訓練運算,所述神經網絡包括n層;所述集成電路芯片裝置包括:處理電路以及外部介面;According to a second aspect, an integrated circuit chip device is provided for performing a training operation of a neural network, the neural network includes n layers; the integrated circuit chip device includes: a processing circuit and an external interface;

所述外部介面,用於接收訓練指令;The external interface is used to receive training instructions;

所述處理電路,用於依據該訓練指令確定第一層輸入數據和第一層權值組數據,計算裝置通過第一層輸入數據和第一層權值組數據執行神經網絡的n層正向運算得到正向運算的第n輸出結果;The processing circuit is configured to determine the first layer input data and the first layer weight group data according to the training instruction, and the computing device executes the n layer forward direction of the neural network through the first layer input data and the first layer weight group data. The operation obtains the n-th output result of the forward operation;

所述處理電路,還用於依據所述第n輸出結果得到第n輸出結果梯度,依據所述訓練指令獲取第n層反向運算的第n反向運算,依據第n輸出結果梯度、第n層輸入數據、第n層權值組數據以及第n反向運算得到第n反向運算複雜度,依據所述第n反向運算複雜度確定第n輸出結果梯度、第n層輸入數據、第n層權值組數據對應的第n反向數據類型,將第n輸出結果梯度、第n層輸入數據、第n層權值組數據以第n反向數據類型執行神經網絡的第n層反向運算得到第n層權值組梯度和第n層輸入數據梯度; 應用所述第n層權值組梯度對第n層權值組數據進行更新;所述第n反向數據類型包括:定點類型或浮點類型;The processing circuit is further configured to obtain the n-th output result gradient according to the n-th output result, obtain the n-th reverse operation of the n-th layer reverse operation according to the training instruction, and obtain the n-th output result gradient, n Layer input data, nth layer weight group data, and nth inverse operation to obtain the nth inverse operation complexity, and determine the nth output result gradient, nth layer input data, and nth inverse operation complexity according to the nth inverse operation complexity. The n-th reverse data type corresponding to the n-th weight group data. The n-th output result gradient, the n-th input data, and the n-th weight group data are executed as the n-th reverse data type of the neural network. The operation obtains the n-th weight group gradient and the n-th input data gradient; applying the n-th weight group gradient to update the n-th weight group data; the n-th reverse data type includes: fixed point Type or floating point type;

所述處理電路,還用於將第n層輸入數據梯度作為第n-1層的第n-1輸出結果梯度執行n-1層方向運算得到n-1層權值組梯度,應用n-1層權值組梯度更新對應層的權值組數據,所述權值組數據包括;至少二個權值。The processing circuit is further configured to use the n-th input data gradient as the n-1th output result gradient of the n-1th layer, perform the n-1 layer direction operation to obtain the n-1 layer weight group gradient, and apply n-1 The layer weight group gradient updates the weight group data of the corresponding layer, the weight group data includes; at least two weights.

第三方面,提供一種神經網絡運算裝置,所述神經網絡運算裝置包括一個或多個第二方面提供的集成電路芯片裝置。In a third aspect, a neural network computing device is provided. The neural network computing device includes one or more integrated circuit chip devices provided in the second aspect.

第四方面,提供一種組合處理裝置,所述組合處理裝置包括:第三方面提供的神經網絡運算裝置、通用互聯介面和通用處理裝置;According to a fourth aspect, a combined processing device is provided. The combined processing device includes: a neural network computing device, a universal interconnection interface, and a universal processing device provided in the third aspect;

所述神經網絡運算裝置通過所述通用互聯介面與所述通用處理裝置連接。The neural network computing device is connected to the universal processing device through the universal interconnection interface.

第五方面,提供一種芯片,所述芯片集成第二方面的裝置、第三方面的裝置或第四方面的裝置。According to a fifth aspect, a chip is provided, and the chip integrates the device of the second aspect, the device of the third aspect, or the device of the fourth aspect.

第六方面,提供一種電子設備,所述電子設備包括第四方面的芯片。According to a sixth aspect, an electronic device is provided, and the electronic device includes the chip of the fourth aspect.

可以看出,通過本披露實施例,提供數據轉換運算電路將數據塊的類型進行轉換後運算,節省了傳輸資源以及計算資源,所以其具有功耗低,計算量小的優點。It can be seen that, according to the embodiment of the present disclosure, a data conversion operation circuit is provided to perform a conversion operation on the type of the data block, which saves transmission resources and calculation resources, so it has the advantages of low power consumption and small calculation amount.

為了使本技術領域的人員更好地理解本披露方案,下面將結合本披露實施例中的圖式,對本披露實施例中的技術方案進行清楚、完整地描述,顯然,所描述的實施例僅僅是本披露一部分實施例,而不是全部的實施例。基於本披露中的實施例,所屬技術領域中具有通常知識者在沒有作出創造性勞動前提下所獲得的所有其他實施例,都屬於本披露保護的範圍。In order to enable those skilled in the art to better understand the disclosure scheme, the technical solutions in the embodiments of the present disclosure will be described clearly and completely in combination with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are merely These embodiments are part of, but not all of the embodiments of this disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by persons with ordinary knowledge in the technical field without making creative labor fall into the scope of protection of the present disclosure.

在第一方面提供的方法中,所述依據所述第n反向運算複雜度確定第n輸出結果梯度、第n層輸入數據、第n層權值組數據對應的第n反向數據類型,包括:In the method provided by the first aspect, determining the n-th reverse data type corresponding to the n-th output result gradient, the n-th input data, and the n-th weight group data according to the n-th reverse operation complexity, include:

將第n反向運算複雜度與預設閾值比較,如所述第n反向運算複雜度高於所述預設閾值,確定所述第n反向數據類型為定點類型,如所述第n反向運算複雜度低於或等於所述預設閾值,計算裝置確定所述第n反向數據類型為浮點類型。Comparing the complexity of the n-th reverse operation with a preset threshold, if the complexity of the n-th reverse operation is higher than the preset threshold, determining that the n-th reverse data type is a fixed-point type, such as the n-th The complexity of the reverse operation is lower than or equal to the preset threshold, and the computing device determines that the n-th reverse data type is a floating point type.

在第一方面提供的方法中,所述方法在依據所述第n反向運算複雜度確定第n輸出結果梯度、第n層輸入數據、第n層權值組數據對應的第n反向數據類型之後還包括:In the method provided by the first aspect, the method determines the n-th output result gradient, the n-th input data, and the n-th reverse data corresponding to the n-th weight group data according to the n-th reverse operation complexity. After the type also includes:

確定所述第n輸出結果梯度、第n層輸入數據、第n層權值組數據屬於的第n+1反向數據類型,如所述第n+1反向數據類型與所述第n反向數據類型不同,將屬於第n+1反向數據類型的所述第n輸出結果梯度、第n層輸入數據、第n層權值組數據轉換成屬於第n反向數據類型的所述第n輸出結果梯度、第n層輸入數據、第n層權值組數據。Determine the n + 1th reverse data type to which the nth output result gradient, nth layer input data, and nth layer weight group data belong, such as the n + 1th reverse data type and the nth inverse data type The data types are different, and the n-th output result gradient, the n-th input data, and the n-th weight group data that belong to the n + 1-th reverse data type are converted into the n-th reverse data type. n output result gradient, n-th input data, and n-th weight group data.

在第一方面提供的方法中,如所述n層反向運算為卷積運算,卷積輸入數據為所述第n層輸入數據,卷積核為所述第n輸出結果梯度,In the method provided by the first aspect, if the n-layer inverse operation is a convolution operation, the convolution input data is the n-th layer input data, and the convolution kernel is the n-th output result gradient,

第n反向運算複雜度=α*C*kW*kW*M*N*W*C*H;The nth reverse operation complexity = α * C * kW * kW * M * N * W * C * H;

其中,α為卷積系數,取值範圍為大於1;C、kW、kW、M為卷積核四個維度的值,N、W、C、H為卷積輸入數據四個維度的值;Among them, α is the convolution coefficient, and the value range is greater than 1. C, kW, kW, and M are the values of the four dimensions of the convolution kernel, and N, W, C, and H are the values of the four dimensions of the convolution input data;

如所述複雜度大於設定閾值,確定該第n反向數據類型為浮點數據類型,確定該卷積輸入數據以及卷積核是否為浮點數據,如該卷積輸入數據以及卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將卷積核轉換成浮點數據,然後將卷積輸入數據、卷積核以浮點數據類型執行卷積運算。If the complexity is greater than a set threshold, determine that the n-th reverse data type is a floating point data type, and determine whether the convolution input data and the convolution kernel are floating point data, such as the convolution input data and the convolution. The kernel is not floating-point data. The convolution input data is converted into floating-point data, the convolution kernel is converted into floating-point data, and then the convolution input data and the convolution kernel are performed as floating-point data types. Product operation.

在第一方面提供的方法中,如所述第n反向運算為:矩陣乘矩陣運算,所述輸入數據為第n層輸入數據,所述權值為所述第n輸出結果梯度;In the method provided by the first aspect, as the nth inverse operation is: matrix multiplication matrix operation, the input data is nth layer input data, and the weight value is the nth output result gradient;

複雜度=β*F*G*E*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為第n層輸入數據的行、列值,E、F為權值的行、列值;Complexity = β * F * G * E * F; Among them, β is a matrix coefficient, the value range is 1 or more, F, G are the row and column values of the nth layer of input data, and E and F are weighted Row and column values;

如所述複雜度大於設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及權值是否為浮點數據,如該第n層輸入數據以及權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將權值轉換成浮點數據,然後將第n層輸入數據、權值以浮點數據類型執行矩陣乘矩陣運算。If the complexity is greater than a set threshold, determine that the n-th reverse data type is a floating-point data type, and determine whether the n-th input data and weights are floating-point data, such as the n-th input data and weights. The value is not floating-point data. The n-th layer of input data is converted to floating-point data, the weights are converted to floating-point data, and then the n-th layer of input data and weights are executed as a floating-point data type. Multiplication matrix operation.

在第一方面提供的方法中,如所述第n反向運算為:矩陣乘向量運算,所述輸入數據為第n層輸入數據,所述權值為所述第n輸出結果梯度;In the method provided by the first aspect, as the n-th reverse operation is: a matrix multiplication vector operation, the input data is n-th layer input data, and the weight is the n-th output result gradient;

複雜度=β*F*G*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為第n層輸入數據的行、列值,F為第n輸出結果梯度的列值;Complexity = β * F * G * F; where β is a matrix coefficient and the value range is greater than or equal to 1, F and G are the row and column values of the input data of the nth layer, and F is the column of the nth output result gradient value;

如所述複雜度大於設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及權值是否為浮點數據,如該第n層輸入數據以及權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將權值轉換成浮點數據,然後將第n層輸入數據、權值以浮點數據類型執行矩陣乘向量運算。If the complexity is greater than a set threshold, determine that the n-th reverse data type is a floating-point data type, and determine whether the n-th input data and weights are floating-point data, such as the n-th input data and weights. The value is not floating-point data. The n-th layer of input data is converted to floating-point data, the weights are converted to floating-point data, and then the n-th layer of input data and weights are executed as a floating-point data type. Multiply vector operations.

在第一方面提供的方法中,所述第n反向運算還可以包括:偏執運算、全連接運算、GEMM運算、GEMV運算、激活運算中的一種或任意組合。In the method provided by the first aspect, the n-th reverse operation may further include one or any combination of paranoid operation, fully connected operation, GEMM operation, GEMV operation, and activation operation.

在第二方面提供的裝置中,所述處理電路,具體將第n反向運算複雜度與預設閾值比較,如所述第n反向運算複雜度高於所述預設閾值,確定所述第n反向數據類型為定點類型,如所述第n反向運算複雜度低於或等於所述預設閾值,確定所述第n反向數據類型為浮點類型。In the apparatus provided by the second aspect, the processing circuit specifically compares the complexity of the n-th reverse operation with a preset threshold, and determines that the complexity of the n-th reverse operation is higher than the preset threshold. The n-th reverse data type is a fixed-point type. If the complexity of the n-th reverse operation is lower than or equal to the preset threshold, it is determined that the n-th reverse data type is a floating-point type.

在第二方面提供的裝置中,所述集成電路芯片裝置還包括:數據類型轉換電路;In the device provided by the second aspect, the integrated circuit chip device further includes: a data type conversion circuit;

所述處理電路,還用於確定所述第n輸出結果梯度、第n層輸入數據、第n層權值組數據屬於的第n+1反向數據類型,如所述第n+1反向數據類型與所述第n反向數據類型不同,向所述數據類型轉換電路發送轉換命令,The processing circuit is further configured to determine an n + 1th reverse data type to which the nth output result gradient, the nth layer input data, and the nth layer weight group data belong, such as the n + 1th reverse A data type different from the n-th reverse data type, and sending a conversion command to the data type conversion circuit,

所述數據類型轉換電路,用於將屬於第n+1反向數據類型的所述第n輸出結果梯度、第n層輸入數據、第n層權值組數據轉換成屬於第n反向數據類型的所述第n輸出結果梯度、第n層輸入數據、第n層權值組數據。The data type conversion circuit is configured to convert the n-th output result gradient, the n-th input data, and the n-th weight group data that belong to the (n + 1) th reverse data type to the n-th reverse data type The n-th output result gradient, n-th input data, and n-th weight group data.

在第二方面提供的裝置中,如所述n層反向運算為卷積運算,卷積輸入數據為所述第n層輸入數據,卷積核為所述第n輸出結果梯度,In the device provided by the second aspect, if the n-layer inverse operation is a convolution operation, the convolution input data is the n-th layer input data, and the convolution kernel is the n-th output result gradient,

所述處理電路,用於計算第n反向運算複雜度,The processing circuit is configured to calculate an n-th reverse operation complexity,

第n反向運算複雜度=α*C*kW*kW*M*N*W*C*H;The nth reverse operation complexity = α * C * kW * kW * M * N * W * C * H;

其中,α為卷積系數,取值範圍為大於1;C、kW、kW、M為卷積核四個維度的值,N、W、C、H為卷積輸入數據四個維度的值;Among them, α is the convolution coefficient, and the value range is greater than 1. C, kW, kW, and M are the values of the four dimensions of the convolution kernel, and N, W, C, and H are the values of the four dimensions of the convolution input data;

所述處理電路,還用於如所述複雜度大於設定閾值,確定該第n反向數據類型為浮點數據類型,確定該卷積輸入數據以及卷積核是否為浮點數據;如該卷積輸入數據以及卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將卷積核轉換成浮點數據,然後將卷積輸入數據、卷積核以浮點數據類型執行卷積運算。The processing circuit is further configured to determine that the n-th reverse data type is a floating-point data type, and determine whether the convolution input data and the convolution kernel are floating-point data if the complexity is greater than a set threshold; The convolution input data and the convolution kernel are not floating-point data. The convolution input data is converted into floating-point data, the convolution kernel is converted into floating-point data, and then the convolution input data and the convolution kernel are converted. Performs a convolution operation as a floating-point data type.

在第二方面提供的裝置中,如所述第n反向運算為:矩陣乘矩陣運算,所述輸入數據為第n層輸入數據,所述權值為所述第n輸出結果梯度;In the apparatus provided by the second aspect, as the n-th reverse operation is: matrix multiplication matrix operation, the input data is n-th layer input data, and the weight is the n-th output result gradient;

所述處理電路,用於計算第n反向運算複雜度,The processing circuit is configured to calculate an n-th reverse operation complexity,

第n反向運算複雜度=β*F*G*E*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為第n層輸入數據的行、列值,E、F為權值的行、列值;The nth inverse operation complexity = β * F * G * E * F; where β is a matrix coefficient and the value range is greater than or equal to 1, F and G are the row and column values of the input data of the nth layer, E, F is the row and column value of the weight;

所述處理單元,用於如所述複雜度大於設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及權值是否為浮點數據,如該第n層輸入數據以及權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將權值轉換成浮點數據,然後將第n層輸入數據、權值以浮點數據類型執行矩陣乘矩陣運算。The processing unit is configured to determine that the n-th reverse data type is a floating-point data type, and determine whether the n-th-level input data and the weight are floating-point data, if the complexity is greater than a set threshold, such as The n-th input data and weights are not floating-point data. The n-th input data is converted to floating-point data, the weights are converted to floating-point data, and then the n-th input data and weights are Floating-point data types perform matrix-by-matrix operations.

在第二方面提供的裝置中,如所述第n反向運算為:矩陣乘向量運算,所述輸入數據為第n層輸入數據,所述權值為所述第n輸出結果梯度;In the apparatus provided by the second aspect, as the n-th inverse operation is: a matrix multiplying vector operation, the input data is n-th layer input data, and the weight is the n-th output result gradient;

所述處理電路,用於計算第n反向運算複雜度,The processing circuit is configured to calculate an n-th reverse operation complexity,

第n反向運算複雜度=β*F*G*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為第n層輸入數據的行、列值,F為第n輸出結果梯度的列值;The complexity of the n-th reverse operation = β * F * G * F; where β is a matrix coefficient, and the value range is greater than or equal to 1, F and G are the row and column values of the input data of the nth layer, and F is the nth Output the column values of the gradient;

所述處理電路,還用於如所述複雜度大於設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及權值是否為浮點數據,如該第n層輸入數據以及權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將權值轉換成浮點數據,然後將第n層輸入數據、權值以浮點數據類型執行矩陣乘向量運算。The processing circuit is further configured to determine that the n-th reverse data type is a floating-point data type, and determine whether the n-th input data and the weight are floating-point data, if the complexity is greater than a set threshold, such as The n-th layer of input data and weights are not floating-point data, the n-th layer of input data is converted to floating-point data, the weights are converted to floating-point data, and then the n-th layer of input data and weights Performs matrix multiplication vector operations on floating point data types.

如圖1所示,神經網絡訓練的步驟包括:As shown in Figure 1, the steps of neural network training include:

一個(多層)神經網絡中的各層依次執行正向運算;The layers in a (multi-layer) neural network perform forward operations in order;

按照相反的層的順序依次執行反向運算得到權值梯度;Perform the inverse operation in turn in the order of the opposite layers to obtain the weight gradient;

用計算得到的權值的梯度去更新正向運算的權值;Use the calculated weight gradient to update the weight of the forward operation;

這就是神經網絡的訓練的依次迭代,整個訓練過程需要重復執行(即多次迭代計算)這個過程多次;This is the sequential iteration of the training of the neural network, and the entire training process needs to be repeatedly performed (that is, multiple iterative calculations). This process is repeated multiple times;

如圖1a所示,為本披露實施例提供的一種神經網絡的正向運算,每一層使用自己的輸入數據和權值按照層的類型所指定的運算規則計算得到相應的輸出數據;As shown in FIG. 1a, a neural network forward operation provided by an embodiment of the present disclosure, each layer uses its own input data and weights to calculate corresponding output data according to the operation rules specified by the layer type;

神經網絡的正向運算過程(也叫推理,inference)是逐層處理各層的輸入數據,經過一定的計算,得到輸出數據的過程,具有如下特徵:The neural network's forward computing process (also called inference) is a process of processing the input data of each layer layer by layer and obtaining the output data after a certain calculation. It has the following characteristics:

某一層的輸入:Inputs for a layer:

某一層的輸入可以是神經網絡的輸入數據;The input of a certain layer can be the input data of a neural network;

某一層的輸入可以是其他層的輸出;The input of one layer can be the output of other layers;

某一層的輸入可以是本層上一時刻的輸出(對應於循環神經網絡的情況);The input of a certain layer can be the output of the previous moment in this layer (corresponding to the case of recurrent neural network);

某一層可以同時從多個上述輸入源獲取輸入;A layer can obtain input from multiple input sources at the same time;

某一層的輸出:Output of a layer:

某一層的輸出可以作為神經網絡的輸出結果;The output of a layer can be used as the output of a neural network;

某一層的輸出可以是其它層的輸入;The output of one layer can be the input of other layers;

某一層的輸出可以是下一時刻本層的輸入(循環神經網絡的情況);The output of a layer can be the input of this layer at the next moment (in the case of a recurrent neural network);

某一層的輸出可以向上述多個輸出方向輸出結果;The output of a certain layer can output results to the above multiple output directions;

具體地,所述神經網絡中的層的運算的類型包括但不限於以下幾種:Specifically, the types of operations of the layers in the neural network include but are not limited to the following:

卷積層(即執行卷積運算);Convolutional layer (ie performing a convolution operation);

全連接層(即執行全連接運算);Fully connected layer (that is, performing a fully connected operation);

歸一化(規則化)層:包括LRN(Local Response Normalization)層,BN(Batch Normalization)層等類型;Normalization (regularization) layer: including LRN (Local Response Normalization) layer, BN (Batch Normalization) layer and other types;

池化層;Pooling layer

激活層:包括但不限於以下類型Sigmoid層,ReLU層,PReLu層,LeakyReLu層,Tanh層;Activation layer: including but not limited to the following types of Sigmoid layer, ReLU layer, PReLu layer, LeakyReLu layer, Tanh layer;

層的反向運算,每一層的反向運算需要執行兩部分運算:一部分是使用可能是稀疏表示的輸出數據梯度和可能是稀疏表示的輸入數據計算出權值的梯度(用於在「權值更新」步驟更新本層的權值),另一部分是使用可能是稀疏表示的輸出數據梯度和可能是稀疏表示的權值,計算出輸入數據梯度(用於作為反向運算中下一層的輸出數據梯度以供其進行反向運算);Layer inversion operation, each layer needs to perform two parts of the operation: one is to use the output data gradient that may be a sparse representation and the input data that may be a sparse representation to calculate the weight gradient (used in the "weight Update "step to update the weights of this layer), the other part is to calculate the gradient of the input data using the output data gradient that may be sparse representation and the weight value that may be sparse representation (for the output data of the next layer in the inverse operation) Gradient for inverse operation);

反向運算按照與正向運算相反的順序,從最後一層開始反向傳遞梯度。The reverse operation transfers gradients in the reverse order from the last layer, starting from the last layer.

在一種可選方案中,某一層反向計算得到的輸出數據梯度可以來自:In an optional solution, the gradient of the output data obtained by inverse calculation of a certain layer can come from:

神經網絡最後的損失函數(lost function或者cost function)回傳的梯度;The gradient returned by the last loss function or cost function of the neural network;

其它層的輸入數據梯度;Input data gradients of other layers;

本層上一時刻的輸入數據梯度(對應於循環神經網絡的情況);The input data gradient at the previous moment in this layer (corresponding to the case of recurrent neural network);

某一層可以同時從多個上述源獲取輸出數據梯度;A certain layer can obtain output data gradients from multiple sources at the same time;

在執行完神經網絡的反向運算之後,就計算出了各層的權值的梯度,在這個步驟中,所述裝置的第一輸入緩存和第二輸入緩存分別用於存儲本層的權值和權值的梯度,然後在運算單元中使用權值梯度對權值進行更新;After performing the inverse operation of the neural network, the gradient of the weights of each layer is calculated. In this step, the first input buffer and the second input buffer of the device are used to store the weights and Weight gradient, and then use the weight gradient in the arithmetic unit to update the weight;

上文中提到的運算都是神經網絡中的一層的運算,對於多層神經網絡,其實現過程是,在正向運算中,當上一層人工神經網絡執行完成之後,下一層的運算指令會將運算單元中計算出的輸出數據作為下一層的輸入數據進行運算(或者是對該輸出數據進行某些操作再作為下一層的輸入數據),同時,將權值也替換為下一層的權值;在反向運算中,當上一層人工神經網絡的反向運算執行完成後,下一層運算指令會將運算單元中計算出的輸入數據梯度作為下一層的輸出數據梯度進行運算(或者是對該輸入數據梯度進行某些操作再作為下一層的輸出數據梯度),同時將權值替換為下一層的權值;(用以下的圖表示,以下圖中虛線的箭頭表示反向運算,實線的箭頭表示正向運算,各圖下面的標注表示圖的含義)The operations mentioned above are all one-level operations in neural networks. For multi-layer neural networks, the implementation process is that in the forward operation, after the execution of the artificial neural network in the previous layer is completed, the operation instructions in the next layer will calculate the operation. The output data calculated in the unit is used as the input data of the next layer (or some operation is performed on the output data and then used as the input data of the next layer), and the weight is also replaced by the weight of the next layer; In the inverse operation, after the inverse operation of the artificial neural network in the previous layer is completed, the operation instructions in the next layer will calculate the input data gradient calculated in the operation unit as the output data gradient in the next layer (or the input data). The gradient performs some operations and then acts as the output data gradient of the next layer), and at the same time replaces the weight with the weight of the next layer; (represented by the following figure, the dotted arrow in the following figure represents the reverse operation, and the solid arrow represents (Forward operation, the label below each figure indicates the meaning of the figure)

定點化數據的表示方法Representation of fixed-point data

定點化的方法是指將網絡中的某個數據塊的數據表示轉換成特定的某種固定小數點位置的數據表示方式(映射到電路裝置上數據的0/1比特位擺放方式);The fixed-point method refers to converting the data representation of a data block in the network into a specific data representation of a fixed decimal point position (mapped to the 0/1 bit position of the data on the circuit device);

在一種可選方案中,將多個數據組成個數據塊作為一個整體使用同樣的定點表示方法進行定點化表示;In an optional solution, a plurality of data is combined into a data block as a whole to perform fixed-point representation using the same fixed-point representation method;

圖1b示出了根據本發明實施例的用於存儲數據的短位數定點數據結構的具體表示方法。其中,1Bit位用於表示符號,M位用於表示整數部分,N位用於表示小數部分;相比於32位浮點數據表示形式,本發明採用的短位定點數據表示形式除了佔用比特位數更少外,對於神經網絡中同一層、同一類型的數據,如第一個卷積層的所有權值數據,還另外設置了一個標誌位Point location記錄小數點的位置,這樣可以根據實際數據的分布調整數據表示的精度與可表示數據範圍。FIG. 1b shows a specific representation method of a short-bit fixed-point data structure for storing data according to an embodiment of the present invention. Among them, 1Bit is used to represent a symbol, M is used to represent an integer part, and N is used to represent a decimal part. Compared to a 32-bit floating-point data representation, the short-bit fixed-point data representation used in the present invention is in addition to occupying bits In addition to fewer digits, for the data of the same layer and the same type in the neural network, such as the ownership value data of the first convolution layer, a flag point location is also set to record the position of the decimal point, which can be based on the actual data. The accuracy and range of data that can be represented by the distribution adjustment data.

對於浮點數的表示即32bit來表示,但是對於此技術方案,其採用定點數可以減少一個數值的比特位的位數,從而降低傳輸的數據量以及運算的數據量。The floating-point number is represented by 32bit, but for this technical solution, the use of fixed-point numbers can reduce the number of bits of a numerical value, thereby reducing the amount of data transmitted and the amount of data calculated.

輸入數據用圖2a表示(N個樣本,每個樣本有C個通道,每個通道的特徵圖的高為H,寬為W),權值也即卷積核用圖2b表示(有M個卷積核,每個卷積核有C個通道,高和寬分別為KH和KW)。對於輸入數據的N個樣本,卷積運算的規則都是一樣的,下面解釋在一個樣本上進行卷積運算的過程,在一個樣本上,M個卷積核中的每一個都要進行同樣的運算,每個卷積核運算得到一張平面特徵圖,M個卷積核最終計算得到M個平面特徵圖,(對一個樣本,卷積的輸出是M個特徵圖),對於一個卷積核,要在一個樣本的每一個平面位置進行內積運算,然後沿著H和W方向進行滑動,例如,圖2c表示一個卷積核在輸入數據的一個樣本中右下角的位置進行內積運算的對應圖;圖2d表示卷積的位置向左滑動一格和圖2e表示卷積的位置向上滑動一格。The input data is shown in Figure 2a (N samples, each sample has C channels, and the height of the feature map of each channel is H and width W), and the weight, that is, the convolution kernel is shown in Figure 2b (M Convolution kernel, each convolution kernel has C channels, height and width are KH and KW respectively). For N samples of the input data, the rules of the convolution operation are the same. The process of performing the convolution operation on one sample is explained below. On one sample, each of the M convolution kernels must be the same. Operation, each convolution kernel operates to obtain a planar feature map, and M convolution kernels finally calculate to obtain M planar feature maps (for a sample, the output of the convolution is M feature maps), for a convolution kernel , To perform an inner product operation at each plane position of a sample, and then slide along the H and W directions. For example, Figure 2c shows a convolution kernel that performs an inner product operation at the lower right corner of a sample of input data. Correspondence map; Figure 2d shows the position of the convolution slide one grid to the left and Figure 2e shows the position of the convolution slide one grid up.

當第一運算為卷積運算,所述輸入數據為卷積輸入數據,所述權值數據為卷積核,When the first operation is a convolution operation, the input data is convolution input data, and the weight data is a convolution kernel,

第一複雜度=α*C*kW*kW*M*N*W*C*H;First complexity = α * C * kW * kW * M * N * W * C * H;

其中,α為卷積系數,取值範圍為大於1;C、kW、kW、M為卷積核四個維度的值,N、W、C、H為卷積輸入數據四個維度的值;Among them, α is the convolution coefficient, and the value range is greater than 1. C, kW, kW, and M are the values of the four dimensions of the convolution kernel, and N, W, C, and H are the values of the four dimensions of the convolution input data;

如所述第一複雜度大於設定閾值,確定該卷積輸入數據以及卷積核是否為浮點數據,如該卷積輸入數據以及卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將卷積核轉換成浮點數據,然後將卷積輸入數據、卷積核以浮點數據類型執行卷積運算。If the first complexity is greater than a set threshold, determine whether the convolution input data and the convolution kernel are floating point data. If the convolution input data and the convolution kernel are not floating point data, input the convolution input. The data is converted into floating-point data, the convolution kernel is converted into floating-point data, and then the convolution input data and the convolution kernel are used to perform convolution operations in the floating-point data type.

具體的,該卷積處理的方式可以採用如圖3a所示的芯片結構處理,主處理電路(也可以稱為主單元)的數據轉換運算電路可以在第一複雜度大於設定閾值時,將權值的部分或全部卷積核中的數據轉換成定點類型的數據,主處理電路的控制電路將權值的部分或全部卷積核中的數據發送到通過橫向數據輸入介面直接與主處理電路相連的那些基礎處理電路(也可以稱為基礎單元)(例如,圖3b中最上方的灰色填充的竪向數據通路);Specifically, the convolution processing method may adopt a chip structure processing as shown in FIG. 3a. The data conversion operation circuit of the main processing circuit (also referred to as the main unit) may convert the weight when the first complexity is greater than a set threshold. The data in some or all of the convolution kernels is converted into fixed-point data. The control circuit of the main processing circuit sends the data in some or all of the weighted convolution kernels to be directly connected to the main processing circuit through the horizontal data input interface. Those basic processing circuits (also called basic units) (for example, the gray-filled vertical data path at the top in Figure 3b);

在一種可選方案中,主處理電路的控制電路將權值中某個卷積核的數據每次發送一個數或者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3行第1個數,第2次發送第3行數據中的第2個數,第3次發送第3行的第3個數……,或者第1次發送第3行前兩個數,第二次發送第3行第3和第4個數,第三次發送第3行第5和第6個數……;)In an optional solution, the control circuit of the main processing circuit sends data of a certain convolution kernel in the weight value to a certain basic processing circuit at a time; (for example, for a certain basic processing circuit, the first Send the first number of the 3rd line once, send the 2nd number of the 3rd line data for the 2nd time, send the 3rd number of the 3rd line for the 3rd time ... or before the 3rd line of the 1st time Two numbers, the second time sends the 3rd and 4th numbers of the 3rd line, the third time sends the 5th and 6th numbers of the 3rd line ...;)

在一種可選方案中另一種情況是,主處理電路的控制電路將權值中某幾個卷積核的數據每次各發送一個數者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3,4,5行每行的第1個數,第2次發送第3,4,5行每行的第2個數,第3次發送第3,4,5行每行的第3個數……,或者第1次發送第3,4,5行每行前兩個數,第二次發送第3,4,5行每行第3和第4個數,第三次發送第3,4,5行每行第5和第6個數……;)In another alternative, the control circuit of the main processing circuit sends the data of some convolution kernels in the weight value to the basic processing circuit one by one each time; (for example, for a certain A basic processing circuit that sends the first number of each line 3,4,5 for the first time, the second number of each line 3,4,5 for the second time, and the third number of 3, The 3rd number of each line 4,5 ... or the first two numbers of 3,4,5 lines are sent for the first time, the 3rd and 4th of 5th lines are sent for the second time 4 numbers, 3rd, 4th, 5th lines send 5th and 6th numbers per line ...;)

主處理電路的控制電路把輸入數據按照卷積的位置進行劃分,主處理電路的控制電路將輸入數據中的部分或全部卷積位置中的數據發送到通過竪向數據輸入介面直接與主處理電路相連的那些基礎處理電路(例如,圖3b中基礎處理電路陣列左側的灰色填充的橫向數據通路);The control circuit of the main processing circuit divides the input data according to the position of the convolution. The control circuit of the main processing circuit sends the data in some or all of the convolution positions in the input data to the main processing circuit directly through the vertical data input interface. Connected basic processing circuits (for example, the gray-filled horizontal data path to the left of the basic processing circuit array in Figure 3b);

在一種可選方案中,主處理電路的控制電路將輸入數據中某個卷積位置的數據每次發送一個數或者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3列第1個數,第2次發送第3列數據中的第2個數,第3次發送第3列的第3個數……,或者第1次發送第3列前兩個數,第二次發送第3列第3和第4個數,第三次發送第3列第5和第6個數……;)In an optional solution, the control circuit of the main processing circuit sends data of a convolution position in the input data to a basic processing circuit at a time or a portion of the data each time; (for example, for a basic processing circuit, the first Send the first number in the third column once, send the second number in the third column data for the second time, send the third number in the third column for the third time ..., or before the first column 3 Two numbers, the third and third numbers are sent in the third column, the third and third and fifth numbers are sent in the third column ...;)

在一種可選方案中另一種情況是,主處理電路的控制電路將輸入數據中某幾個卷積位置的數據每次各發送一個數或者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3,4,5列每列的第1個數,第2次發送第3,4,5列每列的第2個數,第3次發送第3,4,5列每列的第3個數……,或者第1次發送第3,4,5列每列前兩個數,第二次發送第3,4,5列每列第3和第4個數,第三次發送第3,4,5列每列第5和第6個數……;)In another optional solution, the control circuit of the main processing circuit sends data of some convolution positions in the input data to a basic processing circuit each time or a part of the data; (for example, for a certain A basic processing circuit that sends the first number of each of the 3, 4, and 5 columns for the first time, sends the second number of each of the 3, 4, 5 columns for the second time, and sends the third number of 3, The 3rd number of each column in 4,5 columns ..., or the first two numbers of 3,4,5 columns are sent for the first time, and the 3rd and 4th of 5th columns are sent for the second time. 4 numbers, send the 3rd, 4th, 5th columns for the third time, 5th and 6th numbers for each column ...;)

基礎處理電路接收到權值的數據之後,將該數據通過其橫向的數據輸出介面傳輸給其相連接下一個基礎處理電路(例如,圖3b中基礎處理電路陣列中間的白色填充的橫向的數據通路);基礎處理電路接收到輸入數據的數據後,將該數據通過其竪向的數據輸出介面傳輸給與其相連接的下一個基礎處理電路(例如,圖3b中基礎處理電路陣列中間的白色填充的竪向的數據通路);After the basic processing circuit receives the weighted data, it transmits the data to its next basic processing circuit through its horizontal data output interface (for example, the white-filled horizontal data path in the middle of the basic processing circuit array in Figure 3b). ); After receiving the input data, the basic processing circuit transmits the data to the next basic processing circuit connected to it through its vertical data output interface (for example, the white filled pad in the middle of the basic processing circuit array in Figure 3b) Vertical data path);

每一個基礎處理電路對接收到的數據進行運算;Each basic processing circuit performs operations on the received data;

在一種可選方案中,基礎處理電路每次計算一組或多組兩個數據的乘法,然後將結果累加到寄存器和/或片上緩存上;In an optional solution, the basic processing circuit calculates a multiplication of one or more sets of two data at a time, and then accumulates the results in a register and / or an on-chip buffer;

在一種可選方案中,基礎處理電路每次計算一組或多組兩個向量的內積,然後將結果累加到寄存器和/或片上緩存上;In an optional solution, the basic processing circuit calculates an inner product of one or more groups of two vectors at a time, and then accumulates the results in a register and / or an on-chip buffer;

基礎處理電路計算出結果後,可以將結果從數據輸出介面傳輸出去;After the basic processing circuit calculates the result, the result can be transmitted from the data output interface;

在一種可選方案中,該計算結果可以是內積運算的最終結果或中間結果;In an optional solution, the calculation result may be a final result or an intermediate result of the inner product operation;

具體地,如果該基礎處理電路有直接與主處理電路相連接的輸出介面則從該介面傳輸結果,如果沒有,則向著能夠直接向主處理電路輸出的基礎處理電路的方向輸出結果(例如,圖3b中,最下面一行基礎處理電路將其輸出結果直接輸出給主處理電路,其他基礎處理電路從竪向的輸出介面向下傳輸運算結果)。Specifically, if the basic processing circuit has an output interface directly connected to the main processing circuit, the result is transmitted from the interface; if not, the result is output to the direction of the basic processing circuit that can directly output to the main processing circuit (for example, FIG. In 3b, the bottom line of the basic processing circuit directly outputs its output result to the main processing circuit, and the other basic processing circuits transmit the calculation results downward from the vertical output interface).

基礎處理電路接收到來自其他基礎處理電路的計算結果之後,將該數據傳輸給與其相連接的其他基礎處理電路或者主處理電路;After receiving the calculation results from other basic processing circuits, the basic processing circuit transmits the data to other basic processing circuits or main processing circuits connected to the data;

向著能夠直接向主處理電路輸出的方向輸出結果(例如,最下面一行基礎處理電路將其輸出結果直接輸出給主處理電路,其他基礎處理電路從竪向的輸出介面向下傳輸運算結果);Output the result in a direction that can be directly output to the main processing circuit (for example, the bottom row of the basic processing circuit outputs its output result directly to the main processing circuit, and the other basic processing circuits transmit the calculation result downward from the vertical output interface);

主處理電路接收到各個基礎處理電路內積運算的結果,即可得到輸出結果。The main processing circuit receives the result of the inner product operation of each basic processing circuit and can obtain the output result.

參閱圖4a,圖4a為一種矩陣乘以矩陣的運算,如所述第一運算為:矩陣乘矩陣運算,所述輸入數據為所述矩陣乘矩陣運算的第一矩陣,所述權值為所述矩陣乘矩陣運算的第二矩陣;Referring to FIG. 4a, FIG. 4a is a matrix-by-matrix operation. For example, the first operation is: matrix-by-matrix operation, the input data is the first matrix of the matrix-by-matrix operation, and the weight is The second matrix of matrix multiplication matrix operation;

第一複雜度=β*F*G*E*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為第一矩陣的行、列值,E、F為第二矩陣的行、列值;The first complexity = β * F * G * E * F; where β is a matrix coefficient and the value range is 1 or more, F and G are the row and column values of the first matrix, and E and F are the second matrix Row and column values

如所述第一複雜度大於設定閾值,確定該第一矩陣以及第二矩陣是否為浮點數據,如該第一矩陣以及第二矩陣不為浮點數據,將該第一矩陣轉換成浮點數據,將第二矩陣轉換成浮點數據,然後將第一矩陣、第二矩陣以浮點數據類型執行矩陣乘矩陣運算。If the first complexity is greater than a set threshold, determine whether the first matrix and the second matrix are floating-point data. If the first matrix and the second matrix are not floating-point data, convert the first matrix into For floating-point data, the second matrix is converted into floating-point data, and then the first matrix and the second matrix are performed as matrix floating-matrix operations in the floating-point data type.

參閱圖4b,使用如圖3b所示的裝置完成矩陣乘矩陣的運算;Referring to FIG. 4b, the matrix multiplication matrix operation is completed using the apparatus shown in FIG. 3b;

下面描述計算尺寸是M行L列的矩陣S和尺寸是L行N列的矩陣P的乘法的運算,(矩陣S中的每一行與矩陣P的每一列長度相同,如圖2d所示)所述神經網絡計算裝置擁有K個基礎處理電路:The following describes the calculation of a multiplication of a matrix S whose size is M rows and L columns and a matrix P whose size is L rows and N columns. (Each row in matrix S has the same length as each column of matrix P, as shown in Figure 2d.) The neural network computing device has K basic processing circuits:

步驟S401b、 主處理電路在如第一複雜度大於設定閾值時,將矩陣S和矩陣P轉換成定點類型數據,主處理電路的控制電路將矩陣S中的每一行數據分發到K個基礎處理電路中的某一個上,基礎處理電路將接收到的數據保存在片上緩存和/或寄存器中;具體的,可以發送至K個基礎處理電路中與主處理電路連接的基礎處理電路。Step S401b: When the first complexity is greater than a set threshold, the main processing circuit converts the matrix S and the matrix P into fixed-point type data, and the control circuit of the main processing circuit distributes each row of data in the matrix S to the K basic processing circuits. On one of them, the basic processing circuit stores the received data in an on-chip buffer and / or register; specifically, it can be sent to the basic processing circuits connected to the main processing circuit among the K basic processing circuits.

在一種可選方案中,如果S的行數M<=K則,主處理電路的控制電路給M個基礎處理電路分別分發S矩陣的一行;In an optional solution, if the number of rows of S M <= K, the control circuit of the main processing circuit distributes one row of the S matrix to the M basic processing circuits respectively;

在一種可選方案中,如果S的行數M>K,主處理電路的控制電路給每個基礎處理電路分別分發S矩陣中一行或多行的數據。In an alternative, if the number of rows of S is M> K, the control circuit of the main processing circuit distributes one or more rows of data in the S matrix to each basic processing circuit.

S中有Mi行分發到第i個基礎處理電路,這Mi行的集合稱為Ai,如圖2e表示第i個基礎處理電路上將要執行的計算。The Mi line in S is distributed to the i-th basic processing circuit. This set of Mi lines is called Ai, and Figure 2e shows the calculation to be performed on the i-th basic processing circuit.

在一種可選方案中,在每個基礎處理電路中,例如第i個基礎處理電路中:In an alternative, in each basic processing circuit, for example, in the i-th basic processing circuit:

接收的由主處理電路分發的矩陣Ai,將矩陣Ai保存在第i個基礎處理電路寄存器和/或片上緩存中;優點是減少了之後的數據傳輸量,提高了計算效率,降低了功耗。The received matrix Ai distributed by the main processing circuit stores the matrix Ai in the i-th basic processing circuit register and / or on-chip cache; the advantage is that the subsequent data transmission amount is reduced, the calculation efficiency is improved, and the power consumption is reduced.

步驟S402b、 主處理電路的控制電路將矩陣P中各部分以廣播的方式傳輸給各個基礎處理電路;Step S402b: The control circuit of the main processing circuit transmits each part of the matrix P to each basic processing circuit in a broadcast manner;

在一種可選方案中,可以將矩陣P中各部分只廣播一次到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對這一次得到的矩陣P的數據進行充分地復用,完成對應與矩陣Ai中每一行的內積運算;本實施例中的復用具體可以為基礎處理電路在計算中重復使用,例如矩陣P的數據的復用,可以是對矩陣P的數據在多次使用。In an optional solution, each part of the matrix P may be broadcast only once to a register or an on-chip buffer of each basic processing circuit, and the i-th basic processing circuit fully multiplexes the data of the matrix P obtained this time. Complete the inner product operation corresponding to each row in the matrix Ai; the multiplexing in this embodiment may specifically be used repeatedly by the basic processing circuit in the calculation, for example, the multiplexing of the data of the matrix P may be the multiple of the data of the matrix P Times of use.

在一種可選方案中,主處理電路的控制電路可以將矩陣P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對每次得到的矩陣P的數據不進行復用,分次完成對應於矩陣Ai中的每一行的內積運算;In an optional solution, the control circuit of the main processing circuit may broadcast the various parts of the matrix P to the registers or on-chip buffers of each basic processing circuit multiple times. Without multiplexing, the inner product operation corresponding to each row in the matrix Ai is completed in stages;

在一種可選方案中,主處理電路的控制電路可以將矩陣P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對每次得到的矩陣P的數據進行部分復用,完成對應於矩陣Ai中的每一行的內積運算;In an optional solution, the control circuit of the main processing circuit may broadcast the various parts of the matrix P to the registers or on-chip buffers of each basic processing circuit multiple times. Perform partial multiplexing to complete the inner product operation corresponding to each row in the matrix Ai;

在一種可選方案中,每個基礎處理電路,例如第i個基礎處理電路,計算矩陣Ai的數據和矩陣P的數據的內積;In an optional solution, each basic processing circuit, for example, the i-th basic processing circuit, calculates an inner product of the data of the matrix Ai and the data of the matrix P;

步驟S403b、每個基礎處理電路的累加器電路將內積運算的結果進行累加並傳輸回主處理電路。Step S403b: The accumulator circuit of each basic processing circuit accumulates the result of the inner product operation and transmits the result to the main processing circuit.

在一種可選方案中,基礎處理電路可以將每次執行內積運算得到的部分和傳輸回主處理電路進行累加;In an optional solution, the basic processing circuit may transfer the part obtained by performing the inner product operation each time and transfer it to the main processing circuit for accumulation;

在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和保存在基礎處理電路的寄存器和/或片上緩存中,累加結束之後傳輸回主處理電路;In an optional solution, the part obtained by the inner product operation performed by each basic processing circuit may also be stored in a register and / or an on-chip buffer of the basic processing circuit, and transferred to the main processing circuit after the accumulation is completed;

在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和在部分情況下保存在基礎處理電路的寄存器和/或片上緩存中進行累加,部分情況下傳輸到主處理電路進行累加,累加結束之後傳輸回主處理電路。In an optional solution, the part obtained by the inner product operation performed by the basic processing circuit and in some cases may be stored in a register of the basic processing circuit and / or an on-chip buffer for accumulation, and may be transmitted to the host in some cases. The processing circuit performs accumulation, and after the accumulation is completed, it is transmitted back to the main processing circuit.

參閱圖4c,為一種矩陣乘以向量的運算示意圖。如所述第一運算為:矩陣乘向量運算,所述輸入數據為所述矩陣乘向量運算的第一矩陣,所述權值為所述矩陣乘向量運算的向量;Refer to FIG. 4c, which is a schematic diagram of a matrix multiplying a vector. For example, the first operation is: a matrix multiplying vector operation, the input data is a first matrix of the matrix multiplying vector operation, and the weight value is a vector of the matrix multiplying vector operation;

第一複雜度=β*F*G*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為第一矩陣的行、列值,F為向量的列值;The first complexity = β * F * G * F; where β is a matrix coefficient and the value range is greater than or equal to 1, F, G are the row and column values of the first matrix, and F is the column value of the vector;

如所述第一複雜度大於設定閾值,確定該第一矩陣以及向量是否為浮點數據,如該第一矩陣以及向量不為浮點數據,將該第一矩陣轉換成浮點數據,將向量轉換成浮點數據,然後將第一矩陣、向量以浮點數據類型執行矩陣乘向量運算。If the first complexity is greater than a set threshold, determine whether the first matrix and vector are floating point data. If the first matrix and vector are not floating point data, convert the first matrix to floating point data. , Convert the vector to floating-point data, and then perform matrix multiplication vector operations on the first matrix and vector with floating-point data type.

參閱圖4d,圖4d提供了了一種矩陣乘向量的實現方法,具體可以包括:Referring to FIG. 4d, FIG. 4d provides a method for implementing a matrix multiplication vector, which may specifically include:

步驟S401、主處理電路的數據轉換運算電路將矩陣S中的每一行數據轉換成定點類型的數據,主處理電路的控制電路分發到K個基礎處理電路中的某一個上,基礎處理電路將接收到的分發數據保存在基礎處理電路的片上緩存和/或寄存器中;Step S401: The data conversion operation circuit of the main processing circuit converts each row of data in the matrix S into data of a fixed point type, and the control circuit of the main processing circuit is distributed to one of the K basic processing circuits, and the basic processing circuit will receive The obtained distribution data is stored in the on-chip buffer and / or register of the basic processing circuit;

在一種可選方案中,如果矩陣S的行數M<=K則,主處理電路的控制電路給K個基礎處理電路分別分發S矩陣的一行;In an optional solution, if the number of rows of the matrix S is M <= K, the control circuit of the main processing circuit distributes one row of the S matrix to the K basic processing circuits respectively;

在一種可選方案中,如果矩陣S的行數M>K,則主處理電路的控制電路給每個基礎處理電路分別分發S矩陣中一行或多行的數據。In an alternative, if the number of rows M of the matrix S is greater than K, the control circuit of the main processing circuit distributes one or more rows of data in the S matrix to each basic processing circuit.

分發到第i個基礎處理電路的S中的行的集合為Ai,共有Mi個行,如圖2c表示第i個基礎處理電路上將要執行的計算。The set of rows distributed to S in the i-th basic processing circuit is Ai, with a total of Mi rows. As shown in FIG. 2c, the calculation to be performed on the i-th basic processing circuit is shown.

在一種可選方案中,在每個基礎處理電路中,例如第i個基礎處理電路中,可以將接收到的分發數據例如矩陣Ai保存在第i個基礎處理電路的寄存器和/或片上緩存中;優點是減少了之後的分發數據的數據傳輸量,提高了計算效率,降低了功耗。In an optional solution, in each basic processing circuit, for example, the i-th basic processing circuit, the received distribution data, such as a matrix Ai, may be stored in a register and / or an on-chip buffer of the i-th basic processing circuit. ; The advantage is that it reduces the data transmission amount of the distributed data in the future, improves the calculation efficiency, and reduces the power consumption.

步驟S402、 主處理電路的數據類型運算電路將向量P轉換成定點類型的數據,主處理電路的控制電路將定點類型的向量P中各部分以廣播的方式傳輸給K個基礎處理電路;Step S402: The data type operation circuit of the main processing circuit converts the vector P into data of a fixed point type, and the control circuit of the main processing circuit transmits the parts of the vector P of the fixed point type to the K basic processing circuits in a broadcast manner;

在一種可選方案中,主處理電路的控制電路可以將向量P中各部分只廣播一次到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對這一次得到的向量P的數據進行充分地復用,完成對應與矩陣Ai中每一行的內積運算。優點是,減少從主處理電路到基礎處理電路的向量P的重復傳輸的數據傳輸量,提高執行效率,降低傳輸功耗。In an optional solution, the control circuit of the main processing circuit may broadcast each part of the vector P to the registers or on-chip buffers of the basic processing circuits only once, and the data of the vector P obtained this time by the ith basic processing circuit Perform sufficient multiplexing to complete the inner product operation corresponding to each row in the matrix Ai. The advantage is that the data transmission amount of repeated transmission of the vector P from the main processing circuit to the basic processing circuit is reduced, the execution efficiency is improved, and the transmission power consumption is reduced.

在一種可選方案中,主處理電路的控制電路可以將向量P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對每次得到的向量P的數據不進行復用,分次完成對應於矩陣Ai中的每一行的內積運算;優點是,減少基礎處理電路內部的單次傳輸的向量P的數據傳輸量,並可以降低基礎處理電路緩存和/或寄存器的容量,提高執行效率,降低傳輸功耗,降低成本。In an optional solution, the control circuit of the main processing circuit may broadcast the parts of the vector P to the registers or on-chip buffers of each basic processing circuit multiple times. Without multiplexing, the inner product operation corresponding to each row in the matrix Ai is completed in stages; the advantage is that the data transmission amount of a single transmission vector P inside the basic processing circuit is reduced, and the basic processing circuit cache and / Or register capacity, improve execution efficiency, reduce transmission power consumption, and reduce costs.

在一種可選方案中,主處理電路的控制電路可以將向量P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對每次得到的向量P的數據進行部分復用,完成對應於矩陣Ai中的每一行的內積運算;優點是,減少從主處理電路到基礎處理電路的數據傳輸量,也減少基礎處理電路內部的數據傳輸量,提高執行效率,降低傳輸功耗。In an optional solution, the control circuit of the main processing circuit may broadcast the parts of the vector P to the registers or on-chip buffers of each basic processing circuit multiple times, and the i-th basic processing circuit may obtain the data of the vector P each time. Perform partial multiplexing to complete the inner product operation corresponding to each row in the matrix Ai; the advantage is that it reduces the amount of data transmission from the main processing circuit to the basic processing circuit, and also reduces the amount of data transmission inside the basic processing circuit, improving execution efficiency To reduce transmission power consumption.

步驟S403、 K個基礎處理電路的內積運算器電路計算矩陣S和向量P的數據的內積,例如第i個基礎處理電路,計算矩陣Ai的數據和向量P的數據的內積;Step S403: The inner product operator circuit of the K basic processing circuits calculates the inner product of the data of the matrix S and the vector P, for example, the i-th basic processing circuit calculates the inner product of the data of the matrix Ai and the data of the vector P;

步驟S404、 K個基礎處理電路的累加器電路將內積運算的結果進行累加得到累加結果,將累加結果以定點類型形式傳輸回主處理電路。Step S404: The accumulator circuits of the K basic processing circuits accumulate the results of the inner product operation to obtain an accumulation result, and transmit the accumulation result to the main processing circuit in a fixed-point type.

在一種可選方案中,可以將每次基礎處理電路執行內積運算得到的部分和(部分和即累加結果的一部分,例如累加結果為:F1*G1+ F2*G2+ F3*G3+ F4*G4+ F5*G5,那麼部分和可以為:F1*G1+ F2*G2+ F3*G3的值)傳輸回主處理電路進行累加;優點是,減少了基礎處理電路內部的運算量,提高基礎處理電路的運算效率。In an optional solution, the partial sum (partial sum is a part of the accumulated result) obtained when the inner product operation is performed each time by the basic processing circuit, for example, the accumulated result is: F1 * G1 + F2 * G2 + F3 * G3 + F4 * G4 + F5 * G5, then the partial sum can be: the value of F1 * G1 + F2 * G2 + F3 * G3) is transmitted back to the main processing circuit for accumulation; the advantage is that the internal calculation amount of the basic processing circuit is reduced and the operation efficiency of the basic processing circuit is improved.

在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和保存在基礎處理電路的寄存器和/或片上緩存中,累加結束之後傳輸回主處理電路;優點是,減少了基礎處理電路和主處理電路之間的數據傳輸量,提高了運算效率,降低了數據傳輸功耗。In an optional solution, the part obtained by the inner product operation performed by each basic processing circuit may be stored in a register and / or an on-chip buffer of the basic processing circuit, and then transferred back to the main processing circuit after the accumulation is completed; the advantage is, The data transmission amount between the basic processing circuit and the main processing circuit is reduced, the operation efficiency is improved, and the data transmission power consumption is reduced.

在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和在部分情況下保存在基礎處理電路的寄存器和/或片上緩存中進行累加,部分情況下傳輸到主處理電路進行累加,累加結束之後傳輸回主處理電路;優點是,減少了基礎處理電路和主處理電路之間的數據傳輸量,提高了運算效率,降低了數據傳輸功耗,減少了基礎處理電路內部的運算量,提高基礎處理電路的運算效率。In an optional solution, the part obtained by the inner product operation performed by the basic processing circuit and in some cases may be stored in a register of the basic processing circuit and / or an on-chip buffer for accumulation, and may be transmitted to the host in some cases. The processing circuit accumulates and transmits back to the main processing circuit after the accumulation; the advantage is that the data transmission amount between the basic processing circuit and the main processing circuit is reduced, the operation efficiency is improved, the data transmission power consumption is reduced, and the basic processing circuit is reduced The internal calculation amount improves the calculation efficiency of the basic processing circuit.

神經網絡訓練方法Neural network training method

在神經網絡訓練過程中所涉及到所有的數據可以採用不同的數據表示方法;All the data involved in the neural network training process can use different data representation methods;

具體地,所述數據表示方法包括但不限於以下情況:Specifically, the data representation method includes, but is not limited to, the following situations:

不同位寬的浮點數;Floating point numbers with different bit widths;

不同位寬的定點數,不同定點位置的定點數;Number of fixed points with different bit widths, and number of fixed points with different fixed point positions;

訓練過程的不同時刻(具體來說就是不同的迭代次數或者初始化的時刻)、訓練過程中的不同階段(即正向或者反向運算)、不同的層、同一層中的不同數據塊(即多個輸入數據塊,輸出數據塊),或者同一個數據塊中劃分的不同部分的子數據塊,都可以:Different moments in the training process (specifically, different times of iteration or initialization), different stages in the training process (that is, forward or reverse operations), different layers, different data blocks in the same layer (that is, multiple Input data blocks, output data blocks), or sub-data blocks of different parts divided in the same data block, can:

可以分別使用定點或者浮點;You can use fixed or floating point separately;

對於定點:For fixed points:

使用不同的定點位寬;Use different fixed point widths;

使用不同定點偏移值(也即定點位置);Use different fixed-point offset values (that is, fixed-point positions);

下面以一個實際的例子來說明神經網絡訓練的具體實現方法,如圖1a所示為單層運算的神經網絡訓練的具體的計算示意圖,如圖1a所示,輸入數據與權值或參數執行本層運算,本申請實施例提供的技術方案依據輸入數據、權值以及本層的正向運算量確定是否將該輸入數據和權值的類型進行轉換,具體的方式可以為:如該輸入數據以及權值存儲所佔用的寄存器或存儲器空間大於設定閾值且本層的正向運算量大於設定運算量,確定該輸入數據和權值數據為浮點數據時 ,將該輸入數據和權值數據轉換成定點數據。如該輸入數據以及權值存儲所佔用的寄存器或存儲器空間小於設定閾值,如該輸入數據和權值數據為定點數據,將輸入數據和權值數據轉換成浮點數據後,執行本層運算。The following uses a practical example to illustrate the specific implementation of neural network training. Figure 1a shows a specific calculation diagram of neural network training for a single-layer operation. As shown in Figure 1a, the input data and weights or parameters are used to execute this method. Layer operation. The technical solution provided in the embodiment of the present application determines whether to convert the input data and the type of the weight according to the input data, the weight value, and the forward operation amount of the layer. The specific method may be: such as the input data and The register or memory space occupied by the weight storage is greater than the set threshold and the forward operation amount of this layer is greater than the set operation amount. When it is determined that the input data and weight data are floating point data, the input data and weight data are converted Into fixed-point data. If the input data and the weight or the register or memory space occupied by the weight storage is less than the set threshold, if the input data and weight data are fixed-point data, the input data and weight data are converted into floating-point data, and then perform the calculation at this layer. .

對於上述數據類型轉換的原理本申請詳細說明一下,如圖1b所示,為一種定點類型數據的表達方法,對於計算系統,1個浮點數據的存儲位數為32bit,而對於定點數據,尤其是採用如圖1b所示的浮點類型的數據進行數據的表示,其1個定點數據的存儲位數可以做到16Bit以下,所以對於此轉換來說,可以極大的減少計算器之間的傳輸開銷,另外,對於計算器來說,較少比特位的數據存儲的空間也較小,即存儲開銷會較小,計算量也會減少,即計算開銷會減少,所以能夠減少計算開銷以及存儲的開銷,但是對於數據類型的轉換也是需要有部分的開銷的,下面簡稱轉換開銷,對於計算量大,數據存儲量大的數據,轉換開銷相對於後續的計算開銷、存儲開銷以及傳輸開銷來說幾乎可以忽略不計,所以對於計算量大,數據存儲量大的數據,本申請採用了將數據類型轉換成定點類型的數據的技術方案,反之,對於計算量小,數據存儲量小的數據,此時由於本身計算開銷、存儲開銷以及傳輸開銷就比較小,此時如果使用定點數據,由於定點數據的精度會略低於浮點數據,在計算量較小的前提下,需要保證計算的精度,所以這裡將定點類型的數據轉換成浮點數據,即通過增加較小的開銷來提高計算的精度的目的。The principle of the above data type conversion is explained in detail in this application. As shown in FIG. 1b, it is a method for expressing fixed-point data. For a computing system, the storage digits of a floating-point data are 32 bits. For fixed-point data, In particular, the floating-point data shown in Figure 1b is used to represent the data. The storage digits of one fixed-point data can be less than 16Bit, so for this conversion, the number of calculators can be greatly reduced. Transmission overhead. In addition, for a calculator, the storage space for data with fewer bits is smaller, that is, the storage overhead will be smaller, and the amount of calculation will be reduced. That is, the calculation overhead will be reduced, so the calculation overhead and storage can be reduced. Overhead, but also requires some overhead for the conversion of data types, referred to below as conversion overhead. For data with a large amount of calculation and large amount of data storage, the conversion overhead is relative to subsequent calculation overhead, storage overhead, and transmission overhead. It is almost negligible, so for data with a large amount of calculation and a large amount of data storage, this application uses the data type The technical solution for converting to fixed-point data. Conversely, for data with a small amount of calculation and small data storage, the calculation, storage, and transmission costs are relatively small at this time. If fixed-point data is used at this time, due to fixed-point data The accuracy will be slightly lower than the floating-point data. Under the premise of a small amount of calculation, the accuracy of the calculation needs to be guaranteed, so the fixed-point data is converted into floating-point data here, that is, the calculation is improved by adding a small overhead. The purpose of precision.

下面以一個實際的例子來說明,如圖4e所示,本層運算方式為矩陣乘法,輸入數據以及權值均為矩陣,為了方便說明這裡的輸入數據以矩陣I為例,權值以矩陣W為例,如圖4e所示,輸出數據=矩陣I*矩陣W;這裡如果矩陣I以及矩陣W的列數量以及行數量之和較大,即可以認為上述矩陣I以及矩陣W在存儲器和/或寄存器所佔空間較大以及計算量也較大,這樣如果矩陣I以及矩陣W為浮點數據,則將矩陣I以及矩陣W轉換成定點數據,然後在執行矩陣乘法的運算。The following uses a practical example to illustrate. As shown in FIG. 4e, the operation method of this layer is matrix multiplication, and the input data and weights are both matrices. For the convenience of explanation, the input data here is matrix I and the weights are matrix W For example, as shown in Figure 4e, the output data = matrix I * matrix W; if the sum of the number of columns and rows of matrix I and matrix W is large, the above matrix I and matrix W can be considered to be in memory and / or The register takes up a lot of space and has a large amount of calculation. In this way, if matrix I and matrix W are floating-point data, matrix I and matrix W are converted into fixed-point data, and then matrix multiplication is performed.

例如,矩陣I為1000*1000的矩陣,矩陣W也為1000*1000的矩陣,那麼對於列數量以及行數量之和為2000,其數量很大,對應的計算量就更大,矩陣乘以矩陣的內積運算的乘法運算即109次,對於此技術方案,由於矩陣I以及矩陣W的數量很大,不可能一次將所有的數據全部傳輸,這樣同一數據可能會多次傳輸,假設為定點數據傳輸,就可以極大的減少傳輸的數據量,進而減少傳輸開銷,相對於,較少比特位的計算以及存儲也可以減少計算開銷以及存儲開銷。For example, if matrix I is a matrix of 1000 * 1000, and matrix W is also a matrix of 1000 * 1000, then the sum of the number of columns and rows is 2000, which is a large number, and the corresponding calculation is greater. The matrix is multiplied by the matrix The multiplication of the inner product operation is 109 times. For this technical solution, due to the large number of matrix I and matrix W, it is impossible to transmit all the data at once, so the same data may be transmitted multiple times, assuming fixed-point data. Transmission, can greatly reduce the amount of data transmitted, and thus reduce transmission overhead. Relative to the calculation and storage of fewer bits can also reduce the calculation overhead and storage overhead.

對於將定點數據轉換成浮點數據的技術方案為,以反向運算為例,如圖4g所示的計算結構的上向箭頭方向為一種反向運算。以反向運算為例,對於方向運算,其方向運算的為輸出數據梯度,該輸出數據梯度具體可以為,如該輸出數據梯度為本次迭代計算的最後一層,該輸出數據梯度本次迭代計算的最後一層的輸出數據經過預設運算(該預設運算可以由廠家根據自身需要自行設定,這裡並不限定該預設運算的具體運算步驟)得到輸出數據梯度,如該輸出數據梯度為非本次迭代計算的最後一層,例如該輸出數據梯度為本次迭代計算的第n層,那麼該輸出數據梯度為第n+1層反向運算計算得到的輸入數據梯度。For the technical solution of converting fixed-point data into floating-point data, take the reverse operation as an example, and the upward arrow direction of the calculation structure shown in FIG. 4g is a reverse operation. Take the inverse operation as an example. For the direction operation, the direction operation is the output data gradient. The output data gradient can be, for example, the output data gradient is the last layer of this iterative calculation, and the output data gradient is iteratively calculated. The output data of the last layer is obtained by a preset operation (the preset operation can be set by the manufacturer according to his own needs, and the specific operation steps of the preset operation are not limited here) to obtain the output data gradient. If the output data gradient is not the original The last layer of the iteration calculation, for example, the output data gradient is the nth layer of this iteration calculation, then the output data gradient is the input data gradient calculated by the inverse operation of the n + 1th layer.

下面以一個實際的例子來說明,如圖4g所示,本層運算方式為矩陣乘法,輸入數據為矩陣,權值為標量,為了方便說明這裡的輸入數據以矩陣I為例,權值以標量C為例,如圖4g所示,輸出數據=矩陣I*C;此時由於權值為標量的數據,數據計算量較小,這樣如果矩陣I為定點數據,則將矩陣I轉換成浮點數據,然後在執行矩陣乘標量的運算。The following uses a practical example to illustrate, as shown in Figure 4g, the operation method of this layer is matrix multiplication, the input data is a matrix, and the weight is a scalar. For the convenience of explanation, the input data here is matrix I, and the weight is scalar. C as an example, as shown in Figure 4g, the output data = matrix I * C; at this time, because the weight value is scalar data, the amount of data calculation is small, so if the matrix I is fixed-point data, the matrix I is converted to floating point The data is then subjected to a matrix multiply scalar operation.

例如,矩陣I為10*10的矩陣,標量為C,那麼對於列數量以及行數量之和為20,其數量較小,(假設這裡大於100認為是較大,小於100認為是較小,對於該100的數字本領域技術人員可以任意設定。)對應的計算量就很小,矩陣乘以矩陣的內積運算的乘法運算即102次,由於計算量小,如果還是使用定點數據進行計算,會對其精度產生影響,為了使得計算精度更高,在較小計算量的前提下,通過浮點數據計算能夠提高計算精度。For example, if the matrix I is a 10 * 10 matrix and the scalar is C, then for the sum of the number of columns and the number of rows is 20, the number is small, (assuming that greater than 100 is considered larger, less than 100 is considered smaller, The number of 100 can be arbitrarily set by those skilled in the art.) The corresponding calculation amount is very small. The multiplication of matrix multiplication by the inner product operation of the matrix is 102 times. Because the calculation amount is small, if you still use fixed-point data for calculation, it will It has an impact on its accuracy. In order to make the calculation accuracy higher, under the premise of a small amount of calculation, the calculation accuracy can be improved by floating-point data calculation.

在一種可選方案中,網絡中各層的各個數據塊可以分別採用固定的定點位寬,但是其定點位置隨著訓練迭代週期變化;In an optional solution, each data block of each layer in the network may adopt a fixed fixed-point bit width, but its fixed-point position changes with the training iteration cycle;

具體來說,在訓練過程中,某個數據塊的數據表示方法可以如下設定;Specifically, during the training process, the data representation method of a certain data block can be set as follows;

具體地,在開始訓練的時候,可以對某個數據塊選擇任意數據表示方法;Specifically, at the beginning of training, an arbitrary data representation method can be selected for a certain data block;

在一種可選方案中,可以選擇特定位寬的浮點表示方法;In an alternative, a floating point representation method with a specific bit width can be selected;

在一種可選方案中,可以選擇特定形式的定點表示方法;In an alternative, a specific form of fixed-point representation can be selected;

可以選擇特定定點位寬;Can choose a specific fixed-point bit width;

可以選擇特定定點位置;Can choose a specific fixed-point position;

在一種可選的方案中,可以根據該數據塊中所有數據的絕對值的最大值來設置定點位置;In an optional solution, the fixed-point position can be set according to the maximum value of the absolute value of all the data in the data block;

在一種可選方案中,可以根據該數據塊中所有數據的絕對值的最小值來設置定點位置;In an optional solution, the fixed-point position may be set according to the minimum value of the absolute values of all the data in the data block;

在一種可選方案中,可以根據其他數據塊的定點位置來確定初始化時本數據塊的定點位置;In an optional solution, the fixed-point position of the data block during initialization may be determined according to the fixed-point positions of other data blocks;

在一種可選方案中,可以根據經驗值設置本數據塊的定點位置;In an optional solution, the fixed-point position of the data block can be set according to the experience value;

具體地,在訓練過程中,可以在任意迭代週期次數時改變某個數據塊的數據表示方法;Specifically, during the training process, the data representation method of a certain data block can be changed at any number of iteration cycles;

在一種可選方案中,對於某個數據塊而言,可以不進行調整;In an optional solution, no adjustment is required for a certain data block;

在一種可選方案中,可以每隔一定的迭代次數進行調整;In an optional solution, adjustment can be performed every certain number of iterations;

在一種可選方案中,可以每隔一定的訓練epoch數進行調整;In an alternative, it can be adjusted every certain training epoch number;

在一種可選方案中,可以按照不固定的迭代次數間隔進行調整;In an optional solution, adjustments can be made according to an irregular number of iterations;

在一種可選方案中,可以間隔不固定的訓練epoch數進行調整;In an alternative, the number of training epochs can be adjusted at irregular intervals;

具體地,在訓練過程中,調整某個數據塊的表示方法的時候可以調整為任意數據表示方法;Specifically, during the training process, when adjusting the representation method of a certain data block, it can be adjusted to any data representation method;

在一種可選方案中,如果一個數據塊是使用固定定點位寬定點數表示的,那麼其數據表示的定點位置的調整方式可以是:In an optional solution, if a data block is represented by a fixed fixed-point bit-width fixed-point number, the adjustment method of the fixed-point position represented by the data may be:

在一種可選方案中,每次按照初始化定點位置的設置方法來設置定點位置;In an optional solution, the fixed-point position is set each time according to a method of initializing the fixed-point position;

在一種可選方案中,如果某個數據塊按照定點位置的初始化設置方法計算出來的定點位置在某個迭代週期比上個迭代週期增大的,那就將本週期的定點位置向著增大的方法改變;反之,則向著減小的方向改變。In an optional solution, if the fixed-point position calculated by a data block according to the initial setting method of the fixed-point position increases in an iteration period compared to the previous iteration period, then the fixed-point position in the current period is increased. The method changes; otherwise, it changes in a decreasing direction.

本披露還提供一種集成電路芯片裝置,所述集成電路芯片裝置用於執行神經網絡的訓練,所述神經網絡包含多層,所述集成電路芯片裝置包括:處理電路以及外部介面;The present disclosure also provides an integrated circuit chip device for performing training of a neural network. The neural network includes multiple layers. The integrated circuit chip device includes a processing circuit and an external interface.

所述外部介面,用於接收訓練指令;The external interface is used to receive training instructions;

所述處理電路,用於依據該訓練指令確定第一層輸入數據和第一層權值數據,通過第一層輸入數據和第一層權值數據執行神經網絡的n層正向運算得到第n輸出結果;The processing circuit is configured to determine the first-layer input data and the first-layer weight data according to the training instruction, and perform the n-layer forward operation of the neural network to obtain the n-th through the first-layer input data and the first-layer weight data. Output result

所述處理電路,還用於依據第n輸出結果得到第n輸出結果梯度,依據所述訓練指令獲取第n層反向運算的第n反向運算,依據第n輸出結果梯度、第n層輸入數據、第n層權值組數據以及第n反向運算得到第n反向運算複雜度,依據所述第n反向運算複雜度確定第n輸出結果梯度、第n層輸入數據、第n層權值組數據對應的第n反向數據類型,將第n輸出結果梯度、第n層輸入數據、第n層權值組數據以第n反向數據類型執行神經網絡的n層反向運算得到n層運算的n個權值梯度;所述第n反向數據類型包括:定點類型或浮點類型;The processing circuit is further configured to obtain the n-th output result gradient according to the n-th output result, obtain the n-th reverse operation of the n-th layer reverse operation according to the training instruction, and obtain the n-th output result gradient and the n-th input according to the n-th output result. Data, the nth layer weight group data, and the nth inverse operation to obtain the nth inverse operation complexity. The nth output result gradient, the nth layer input data, and the nth layer are determined according to the nth inverse operation complexity. The nth inverse data type corresponding to the weight group data. The nth output result gradient, the nth layer input data, and the nth layer weight group data are obtained by performing the nth layer inverse operation of the neural network with the nth inverse data type. n weight gradients for n-layer operations; the n-th reverse data type includes: a fixed-point type or a floating-point type;

所述處理電路,還用於將應用所述n個權值梯度對n層運算的n個權值進行更新。The processing circuit is further configured to update the n weights of the n-layer operations by applying the n weight gradients.

本披露還揭露了一個神經網絡運算裝置,其包括一個或多個在如圖3a或如圖3b所示的芯片,用於從其他處理裝置中獲取待運算數據和控制信息,執行指定的神經網絡運算,執行結果通過I/O介面傳遞給外圍設備。外圍設備譬如攝像頭,顯示器,鼠標,鍵盤,網卡,wifi介面,服務器。當包含一個以上神如圖3a或如圖3b所示的芯片時,如圖3a或如圖3b所示的芯片間可以通過特定的結構進行鏈接並傳輸數據,譬如,通過PCIE總線進行互聯並傳輸數據,以支持更大規模的神經網絡的運算。此時,可以共享同一控制系統,也可以有各自獨立的控制系統;可以共享內存,也可以每個加速器有各自的內存。此外,其互聯方式可以是任意互聯拓撲。This disclosure also discloses a neural network computing device, which includes one or more chips as shown in FIG. 3a or FIG. 3b, for obtaining data to be calculated and control information from other processing devices, and executing a specified neural network. The calculation and execution results are passed to the peripheral device through the I / O interface. Peripheral equipment such as camera, monitor, mouse, keyboard, network card, wifi interface, server. When more than one chip shown in Figure 3a or Figure 3b is included, the chips shown in Figure 3a or Figure 3b can be linked and transmitted through a specific structure, for example, interconnected and transmitted through the PCIE bus. Data to support larger-scale neural network operations. At this time, you can share the same control system, or you can have separate control systems; you can share memory, or each accelerator can have its own memory. In addition, its interconnection method can be any interconnection topology.

該神經網絡運算裝置具有較高的兼容性,可通過PCIE介面與各種類型的服務器相連接。The neural network computing device has high compatibility and can be connected to various types of servers through a PCIE interface.

本披露還揭露了一個組合處理裝置,其包括上述的神經網絡運算裝置,通用互聯介面,和其他處理裝置(即通用處理裝置)。神經網絡運算裝置與其他處理裝置進行交互,共同完成用戶指定的操作。如5a為組合處理裝置的示意圖。The present disclosure also discloses a combined processing device, which includes the aforementioned neural network computing device, a universal interconnection interface, and other processing devices (ie, general processing devices). The neural network computing device interacts with other processing devices to complete a user-specified operation. For example, 5a is a schematic diagram of a combined processing device.

其他處理裝置,包括中央處理器CPU、圖形處理器GPU、神經網絡處理器等通用/專用處理器中的一種或以上的處理器類型。其他處理裝置所包括的處理器數量不做限制。其他處理裝置作為神經網絡運算裝置與外部數據和控制的介面,包括數據搬運,完成對本神經網絡運算裝置的開啓、停止等基本控制;其他處理裝置也可以和神經網絡運算裝置協作共同完成運算任務。Other processing devices include one or more types of processors such as a central processing unit CPU, a graphics processor GPU, and a neural network processor. The number of processors included in other processing devices is not limited. Other processing devices serve as the interface between the neural network computing device and external data and control, including data transfer, to complete the basic control of the neural network computing device, such as start and stop; other processing devices can also cooperate with the neural network computing device to complete computing tasks.

通用互聯介面,用於在所述神經網絡運算裝置與其他處理裝置間傳輸數據和控制指令。該神經網絡運算裝置從其他處理裝置中獲取所需的輸入數據,寫入神經網絡運算裝置片上的存儲裝置;可以從其他處理裝置中獲取控制指令,寫入神經網絡運算裝置片上的控制緩存;也可以讀取神經網絡運算裝置的存儲模塊中的數據並傳輸給其他處理裝置。A universal interconnection interface for transmitting data and control instructions between the neural network computing device and other processing devices. The neural network computing device obtains required input data from other processing devices and writes it to a storage device on the neural network computing device chip; it can obtain control instructions from other processing devices and write it to the control buffer on the neural network computing device chip; also The data in the storage module of the neural network computing device can be read and transmitted to other processing devices.

如圖5b所示,可選的,該結構還包括存儲裝置,用於保存在本運算單元/運算裝置或其他運算單元所需要的數據,尤其適用於所需要運算的數據在本神經網絡運算裝置或其他處理裝置的內部存儲中無法全部保存的數據。As shown in FIG. 5b, optionally, the structure further includes a storage device for storing data required by the operation unit / operation device or other operation units, and particularly suitable for the data required for operation in the neural network operation device. Or all data that cannot be saved in the internal storage of other processing devices.

該組合處理裝置可以作為手機、機器人、無人機、視頻監控設備等設備的SOC片上系統,有效降低控制部分的核心面積,提高處理速度,降低整體功耗。此情況時,該組合處理裝置的通用互聯介面與設備的某些部件相連接。某些部件譬如攝像頭,顯示器,鼠標,鍵盤,網卡,wifi介面。The combined processing device can be used as an SOC system-on-chip for devices such as mobile phones, robots, drones, and video surveillance equipment, effectively reducing the core area of the control section, increasing processing speed, and reducing overall power consumption. In this case, the universal interconnection interface of the combined processing device is connected to some parts of the equipment. Some components such as camera, monitor, mouse, keyboard, network card, wifi interface.

請參照圖5c,圖5c為本披露實施例提供的一種神經網絡處理器板卡的結構示意圖。如圖5c所示,上述神經網絡處理器板卡10包括神經網絡芯片封裝結構11、第一電氣及非電氣連接裝置12和第一基板(substrate)13。Please refer to FIG. 5c, which is a schematic structural diagram of a neural network processor board provided by an embodiment of the present disclosure. As shown in FIG. 5 c, the neural network processor board 10 includes a neural network chip package structure 11, a first electrical and non-electrical connection device 12, and a first substrate 13.

本披露對於神經網絡芯片封裝結構11的具體結構不作限定,可選的,如圖5d所示,上述神經網絡芯片封裝結構11包括:神經網絡芯片111、第二電氣及非電氣連接裝置112、第二基板113。The present disclosure does not limit the specific structure of the neural network chip package structure 11. Optionally, as shown in FIG. 5d, the aforementioned neural network chip package structure 11 includes: a neural network chip 111, a second electrical and non-electrical connection device 112, a first Two substrates 113.

本披露所涉及的神經網絡芯片111的具體形式不作限定,上述的神經網絡芯片111包含但不限於將神經網絡處理器集成的神經網絡晶片,上述晶片可以由硅材料、鍺材料、量子材料或分子材料等製成。根據實際情況(例如:較嚴苛的環境)和不同的應用需求可將上述神經網絡晶片進行封裝,以使神經網絡晶片的大部分被包裹住,而將神經網絡晶片上的引腳通過金線等導體連到封裝結構的外邊,用於和更外層進行電路連接。The specific form of the neural network chip 111 involved in this disclosure is not limited. The aforementioned neural network chip 111 includes, but is not limited to, a neural network chip that integrates a neural network processor. The above chip may be made of silicon material, germanium material, quantum material, or molecule. Materials. According to the actual situation (for example: harsh environment) and different application requirements, the above neural network chip can be packaged so that most of the neural network chip is wrapped, and the pins on the neural network chip are passed through gold wires. The isoconductor is connected to the outer side of the package structure for circuit connection with the outer layer.

本披露對於神經網絡芯片111的具體結構不作限定,可選的,請參照圖1a或圖1b所示的裝置。The present disclosure does not limit the specific structure of the neural network chip 111. For optional, please refer to the device shown in FIG. 1a or FIG. 1b.

本披露對於第一基板13和第二基板113的類型不做限定,可以是印制電路板(printed circuit board,PCB)或(printed wiring board,PWB),還可能為其它電路板。對PCB的製作材料也不做限定。The disclosure does not limit the types of the first substrate 13 and the second substrate 113, and may be a printed circuit board (PCB) or a printed wiring board (PWB), or may be other circuit boards. There are no restrictions on the materials used to make the PCB.

本披露所涉及的第二基板113用於承載上述神經網絡芯片111,通過第二電氣及非電氣連接裝置112將上述的神經網絡芯片111和第二基板113進行連接得到的神經網絡芯片封裝結構11,用於保護神經網絡芯片111,便於將神經網絡芯片封裝結構11與第一基板13進行進一步封裝。The second substrate 113 according to the present disclosure is used to carry the neural network chip 111, and a neural network chip package structure 11 obtained by connecting the neural network chip 111 and the second substrate 113 through a second electrical and non-electrical connection device 112. It is used to protect the neural network chip 111 and facilitate the further packaging of the neural network chip packaging structure 11 and the first substrate 13.

對於上述具體的第二電氣及非電氣連接裝置112的封裝方式和封裝方式對應的結構不作限定,可根據實際情況和不同的應用需求選擇合適的封裝方式並進行簡單地改進,例如:倒裝芯片球柵陣列封裝(Flip Chip Ball Grid Array Package,FCBGAP),薄型四方扁平式封裝(Low-profile Quad Flat Package,LQFP)、帶散熱器的四方扁平封裝(Quad Flat Package with Heat sink,HQFP)、無引腳四方扁平封裝(Quad Flat Non-lead Package,QFN)或小間距四方扁平式封裝(Fine-pitch Ball Grid Package,FBGA)等封裝方式。There is no limitation on the above-mentioned specific packaging method of the second electrical and non-electrical connection device 112 and the corresponding structure of the packaging method. A suitable packaging method can be selected and simply improved according to the actual situation and different application needs, such as flip chip Flip Chip Ball Grid Array Package (FCBGAP), Low-profile Quad Flat Package (LQFP), Quad Flat Package with Heat sink (HQFP), None Packaging methods such as Quad Flat Non-lead Package (QFN) or Fine-pitch Ball Grid Package (FBGA).

倒裝芯片(Flip Chip),適用於對封裝後的面積要求高或對導線的電感、信號的傳輸時間敏感的情況下。除此之外可以用引線鍵合(Wire Bonding)的封裝方式,減少成本,提高封裝結構的靈活性。Flip chip (Flip Chip) is suitable for the case where the area after packaging is high or the inductance of the wire and the signal transmission time are sensitive. In addition, wire bonding can be used to reduce the cost and improve the flexibility of the packaging structure.

球柵陣列(Ball Grid Array),能夠提供更多引腳,且引腳的平均導線長度短,具備高速傳遞信號的作用,其中,封裝可以用引腳網格陣列封裝(Pin Grid Array,PGA)、零插拔力(Zero Insertion Force,ZIF)、單邊接觸連接(Single Edge Contact Connection,SECC)、觸點陣列(Land Grid Array,LGA)等來代替。Ball Grid Array, which can provide more pins, and the average lead length of the pins is short, which has the function of transmitting signals at high speed. Among them, the package can be packaged with a pin grid array (Pin Grid Array, PGA) , Zero Insertion Force (ZIF), Single Edge Contact Connection (SECC), and Land Grid Array (LGA).

可選的,採用倒裝芯片球柵陣列(Flip Chip Ball Grid Array)的封裝方式對神經網絡芯片111和第二基板113進行封裝,具體的神經網絡芯片封裝結構的示意圖可參照圖6。如圖6所示,上述神經網絡芯片封裝結構包括:神經網絡芯片21、焊盤22、焊球23、第二基板24、第二基板24上的連接點25、引腳26。Optionally, the Flip Chip Ball Grid Array (Flip Chip Ball Grid Array) packaging method is used to package the neural network chip 111 and the second substrate 113. For a schematic diagram of a specific neural network chip packaging structure, refer to FIG. 6. As shown in FIG. 6, the aforementioned neural network chip package structure includes: a neural network chip 21, a pad 22, a solder ball 23, a second substrate 24, a connection point 25 on the second substrate 24, and a pin 26.

其中,焊盤22與神經網絡芯片21相連,通過在焊盤22和第二基板24上的連接點25之間焊接形成焊球23,將神經網絡芯片21和第二基板24連接,即實現了神經網絡芯片21的封裝。Among them, the pad 22 is connected to the neural network chip 21, and a solder ball 23 is formed by welding between the pad 22 and the connection point 25 on the second substrate 24, and the neural network chip 21 and the second substrate 24 are connected. Packaging of the neural network chip 21.

引腳26用於與封裝結構的外部電路(例如,神經網絡處理器板卡10上的第一基板13)相連,可實現外部數據和內部數據的傳輸,便於神經網絡芯片21或神經網絡芯片21對應的神經網絡處理器對數據進行處理。對於引腳的類型和數量本披露也不作限定,根據不同的封裝技術可選用不同的引腳形式,並遵從一定規則進行排列。Pin 26 is used to connect with the external circuit of the package structure (for example, the first substrate 13 on the neural network processor board 10), and can realize the transmission of external data and internal data, which is convenient for the neural network chip 21 or the neural network chip 21 The corresponding neural network processor processes the data. The type and quantity of pins are not limited in this disclosure. Different pin forms can be selected according to different packaging technologies and arranged in accordance with certain rules.

可選的,上述神經網絡芯片封裝結構還包括絕緣填充物,置於焊盤22、焊球23和連接點25之間的空隙中,用於防止焊球與焊球之間產生干擾。Optionally, the aforementioned neural network chip package structure further includes an insulating filler placed in a gap between the pad 22, the solder ball 23, and the connection point 25 to prevent interference between the solder ball and the solder ball.

其中,絕緣填充物的材料可以是氮化硅、氧化硅或氧氮化硅;干擾包含電磁干擾、電感干擾等。The material of the insulating filler may be silicon nitride, silicon oxide, or silicon oxynitride; interference includes electromagnetic interference, inductive interference, and the like.

可選的,上述神經網絡芯片封裝結構還包括散熱裝置,用於散髮神經網絡芯片21運行時的熱量。其中,散熱裝置可以是一塊導熱性良好的金屬片、散熱片或散熱器,例如,風扇。Optionally, the aforementioned neural network chip package structure further includes a heat dissipation device for dissipating heat during operation of the neural network chip 21. The heat dissipation device may be a metal sheet, a heat sink, or a heat sink with good thermal conductivity, such as a fan.

舉例來說,如圖6a所示,神經網絡芯片封裝結構11包括:神經網絡芯片21、焊盤22、焊球23、第二基板24、第二基板24上的連接點25、引腳26、絕緣填充物27、散熱膏28和金屬外殼散熱片29。其中,散熱膏28和金屬外殼散熱片29用於散髮神經網絡芯片21運行時的熱量。For example, as shown in FIG. 6a, the neural network chip package structure 11 includes: a neural network chip 21, a pad 22, a solder ball 23, a second substrate 24, a connection point 25, a pin 26, The insulating filler 27, the heat dissipation paste 28, and the metal case heat sink 29. Among them, the heat dissipation paste 28 and the metal shell heat sink 29 are used to dissipate heat during the operation of the neural network chip 21.

可選的,上述神經網絡芯片封裝結構11還包括補強結構,與焊盤22連接,且內埋於焊球23中,以增強焊球23與焊盤22之間的連接強度。Optionally, the aforementioned neural network chip package structure 11 further includes a reinforcing structure connected to the pad 22 and embedded in the solder ball 23 to enhance the connection strength between the solder ball 23 and the pad 22.

其中,補強結構可以是金屬線結構或柱狀結構,在此不做限定。The reinforcing structure may be a metal wire structure or a columnar structure, which is not limited herein.

本披露對於第一電氣及非電氣裝置12的具體形式也不作限定,可參照第二電氣及非電氣裝置112的描述,即通過焊接的方式將神經網絡芯片封裝結構11進行封裝,也可以採用連接線連接或插拔方式連接第二基板113和第一基板13的方式,便於後續更換第一基板13或神經網絡芯片封裝結構11。The present disclosure also does not limit the specific form of the first electrical and non-electrical device 12, and may refer to the description of the second electrical and non-electrical device 112, that is, the neural network chip packaging structure 11 is packaged by soldering, and connection may also be adopted. The method of connecting the second substrate 113 and the first substrate 13 in a line connection or plugging manner is convenient for subsequent replacement of the first substrate 13 or the neural network chip package structure 11.

可選的,第一基板13包括用於擴展存儲容量的內存單元的介面等,例如:同步動態隨機存儲器(Synchronous Dynamic Random Access Memory,SDRAM)、雙倍速率同步動態隨機存儲器(Double Date Rate SDRAM,DDR)等,通過擴展內存提高了神經網絡處理器的處理能力。Optionally, the first substrate 13 includes an interface of a memory unit for expanding the storage capacity, such as: synchronous dynamic random access memory (SDRAM), double-rate synchronous dynamic random access memory (Double Date Rate SDRAM, DDR), etc., to improve the processing capacity of the neural network processor by expanding the memory.

第一基板13上還可包括快速外部設備互連總線(Peripheral Component Interconnect-Express,PCI-E或PCIe)介面、小封裝可熱插拔(Small Form-factor Pluggable,SFP)介面、乙太網介面、控制器局域網總線(Controller Area Network,CAN)介面等等,用於封裝結構和外部電路之間的數據傳輸,可提高運算速度和操作的便利性。The first substrate 13 may further include a Peripheral Component Interconnect-Express (PCI-E or PCIe) interface, a Small Form-factor Pluggable (SFP) interface, and an Ethernet interface. , Controller Area Network (CAN) interface, etc., used for data transmission between the package structure and external circuits, which can improve the operation speed and the convenience of operation.

將神經網絡處理器封裝為神經網絡芯片111,將神經網絡芯片111封裝為神經網絡芯片封裝結構11,將神經網絡芯片封裝結構11封裝為神經網絡處理器板卡10,通過板卡上的介面(插槽或插芯)與外部電路(例如:計算機主板)進行數據交互,即直接通過使用神經網絡處理器板卡10實現神經網絡處理器的功能,並保護神經網絡芯片111。且神經網絡處理器板卡10上還可添加其他模塊,提高了神經網絡處理器的應用範圍和運算效率。The neural network processor is packaged as a neural network chip 111, the neural network chip 111 is packaged as a neural network chip package structure 11, the neural network chip package structure 11 is packaged as a neural network processor board 10, and an interface on the board ( Slots or inserts) perform data interaction with external circuits (for example, computer motherboards), that is, the function of the neural network processor is realized directly by using the neural network processor board 10 and the neural network chip 111 is protected. In addition, other modules can be added to the neural network processor board 10, which improves the application range and operation efficiency of the neural network processor.

在一個實施例里,本公開公開了一個電子裝置,其包括了上述神經網絡處理器板卡10或神經網絡芯片封裝結構11。In one embodiment, the present disclosure discloses an electronic device including the neural network processor board 10 or the neural network chip package structure 11 described above.

電子裝置包括數據處理裝置、機器人、電腦、打印機、掃描儀、平板電腦、智能終端、手機、行車記錄儀、導航儀、傳感器、攝像頭、服務器、相機、攝像機、投影儀、手錶、耳機、移動存儲、可穿戴設備、交通工具、家用電器、和/或醫療設備。Electronic devices include data processing devices, robots, computers, printers, scanners, tablets, smart terminals, mobile phones, driving recorders, navigators, sensors, cameras, servers, cameras, camcorders, projectors, watches, headphones, mobile storage , Wearables, vehicles, home appliances, and / or medical devices.

所述交通工具包括飛機、輪船和/或車輛;所述家用電器包括電視、空調、微波爐、冰箱、電飯煲、加濕器、洗衣機、電燈、燃氣灶、油煙機;所述醫療設備包括核磁共振儀、B型超音波儀和/或心電圖儀。The vehicles include airplanes, ships, and / or vehicles; the household appliances include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, electric lights, gas stoves, cooker hoods, and the medical equipment includes nuclear magnetic resonance Instrument, type B ultrasound instrument and / or electrocardiograph.

以上所述的具體實施例,對本披露的目的、技術方案和有益效果進行了進一步詳細說明,所應理解的是,以上所述僅為本披露的具體實施例而已,並不用於限制本披露,凡在本披露的精神和原則之內,所做的任何修改、等同替換、改進等,均應包含在本披露的保護範圍之內。The specific embodiments described above further describe the purpose, technical solution and beneficial effects of the present disclosure. It should be understood that the above are only specific embodiments of the present disclosure and are not used to limit the present disclosure. Any modification, equivalent replacement, or improvement made within the spirit and principle of this disclosure shall be included in the protection scope of this disclosure.

A、B、S‧‧‧矩陣A, B, S‧‧‧ Matrix

P‧‧‧向量P‧‧‧ vector

S401b、S402b、S403b、S401、S402、S403、S404‧‧‧步驟S401b, S402b, S403b, S401, S402, S403, S404‧‧‧ steps

10‧‧‧神經網絡處理器卡板10‧‧‧ Neural Network Processor Card Board

11‧‧‧神經網絡芯片封裝結構11‧‧‧ neural network chip packaging structure

12‧‧‧第一電氣及非電氣連接裝置12‧‧‧First electrical and non-electrical connection device

13‧‧‧第一基板13‧‧‧First substrate

111‧‧‧神經網絡芯片111‧‧‧ neural network chip

112‧‧‧第二電氣及非電氣連接裝置112‧‧‧Second electrical and non-electrical connection device

113‧‧‧第二基板113‧‧‧second substrate

1111‧‧‧存儲單元1111‧‧‧Storage Unit

1112‧‧‧直接內存存取單元1112‧‧‧Direct Memory Access Unit

1113‧‧‧指令緩存單元1113‧‧‧Instruction cache unit

1114‧‧‧權緩存單元1114‧‧‧ Rights Cache Unit

1115‧‧‧輸入神經元緩存單元1115‧‧‧Input neuron buffer unit

1116‧‧‧輸出神經元緩存單元1116‧‧‧Output neuron buffer unit

1117‧‧‧控制單元1117‧‧‧Control Unit

1118‧‧‧運算單元1118‧‧‧ Computing Unit

21‧‧‧神經網絡芯片21‧‧‧Neural Network Chip

22‧‧‧焊盤22‧‧‧ pad

23‧‧‧焊球23‧‧‧Solder Ball

24‧‧‧第二基板24‧‧‧second substrate

25‧‧‧第二基板24上的連接點25‧‧‧ Connection points on the second substrate 24

26‧‧‧引腳26‧‧‧pin

27‧‧‧絕緣填充物27‧‧‧Insulation filler

28‧‧‧散熱膏28‧‧‧ Thermal Paste

29‧‧‧金屬外殼散熱片29‧‧‧ metal case heat sink

圖1是一種神經網絡的訓練方法示意圖。Figure 1 is a schematic diagram of a neural network training method.

圖1a是一種神經網絡的正向運算示意圖。Figure 1a is a schematic diagram of the forward operation of a neural network.

圖1b為一種定點數據類型的示意結構圖。FIG. 1b is a schematic structural diagram of a fixed-point data type.

圖2a為卷積輸入數據示意圖。Figure 2a is a schematic diagram of convolution input data.

圖2b為卷積核示意圖。Figure 2b is a schematic diagram of a convolution kernel.

圖2c為輸入數據的一個三維數據塊的運算窗口示意圖。FIG. 2c is a schematic diagram of a calculation window of a three-dimensional data block of input data.

圖2d為輸入數據的一個三維數據塊的另一運算窗口示意圖。FIG. 2d is a schematic diagram of another operation window of a three-dimensional data block of input data.

圖2e為輸入數據的一個三維數據塊的又一運算窗口示意圖.Figure 2e is a schematic diagram of another calculation window of a three-dimensional data block of the input data.

圖3a是一種神經網絡芯片的結構示意圖。Figure 3a is a schematic structural diagram of a neural network chip.

圖3b是另一種神經網絡芯片的結構示意圖。FIG. 3b is a schematic structural diagram of another neural network chip.

圖4a為矩陣乘以矩陣示意圖。Figure 4a is a schematic diagram of matrix multiplication by matrix.

圖4b為矩陣乘以矩陣的方法流程圖。FIG. 4b is a flowchart of a method of matrix by matrix.

圖4c為矩陣乘以向量示意圖。Figure 4c is a schematic diagram of a matrix multiplied by a vector.

圖4d為矩陣乘以向量的方法流程圖。FIG. 4d is a flowchart of a method of matrix multiplication by a vector.

圖4e為一種神經網絡訓練示意圖。Figure 4e is a schematic diagram of a neural network training.

圖4f為另一種神經網絡訓練示意圖。Figure 4f is another schematic diagram of neural network training.

圖4g為神經網絡正向與反向運算示意圖。Figure 4g is a schematic diagram of the forward and reverse operations of the neural network.

圖4h為神經網絡訓練多層結構示意圖。Figure 4h is a schematic diagram of a multilayer structure for neural network training.

圖5a為本披露還揭露了一個組合處理裝置結構示意圖。FIG. 5a is a schematic structural diagram of a combination processing device disclosed in the present disclosure.

圖5b為本披露還揭露了一個組合處理裝置另一種結構示意圖。FIG. 5b also discloses another structure diagram of a combined processing device in the present disclosure.

圖5c為本披露實施例提供的一種神經網絡處理器板卡的結構示意圖;5c is a schematic structural diagram of a neural network processor board provided in an embodiment of the present disclosure;

圖5d為本披露實施例流提供的一種神經網絡芯片封裝結構的結構示意圖;5d is a schematic structural diagram of a neural network chip package structure provided by an embodiment of the present disclosure;

圖5e為本披露實施例流提供的一種神經網絡芯片的結構示意圖;5e is a schematic structural diagram of a neural network chip according to an embodiment of the present disclosure;

圖6為本披露實施例流提供的一種神經網絡芯片封裝結構的示意圖;6 is a schematic diagram of a neural network chip package structure provided by the embodiment of the present disclosure;

圖6a為本披露實施例流提供的另一種神經網絡芯片封裝結構的示意圖。FIG. 6a is a schematic diagram of another neural network chip package structure provided by the embodiment of the present disclosure.

Claims (18)

一種集成電路芯片裝置上執行的神經網絡的訓練方法,該神經網絡包含n層,該n取值範圍為大於等於2的整數,其中,該方法包括如下步驟: 接收一訓練指令,依據該訓練指令確定第一層輸入數據和第一層權值組數據,計算裝置通過該第一層輸入數據和該第一層權值組數據執行神經網絡的n層正向運算得到正向運算的第n輸出結果; 依據該第n輸出結果得到第n輸出結果梯度,依據該訓練指令獲取第n層反向運算的第n反向運算,依據該第n輸出結果梯度、第n層輸入數據、第n層權值組數據以及該第n反向運算得到一第n反向運算複雜度,依據該第n反向運算複雜度確定該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據對應的第n反向數據類型,將該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據以該第n反向數據類型執行神經網絡的該第n層反向運算得到第n層權值組梯度和第n層輸入數據梯度; 應用該第n層權值組梯度對該第n層權值組數據進行更新;該第n反向數據類型包括定點類型或浮點類型; 將該第n層輸入數據梯度作為第n-1層的第n-1輸出結果梯度執行n-1層方向運算得到n-1層權值組梯度,應用該n-1層權值組梯度更新對應層的一權值組數據,該權值組數據包括至少二個權值。A training method for a neural network executed on an integrated circuit chip device. The neural network includes n layers, where the value of n is an integer greater than or equal to 2, wherein the method includes the following steps: receiving a training instruction according to the training instruction Determine the first layer input data and the first layer weight group data, and the computing device performs the n-layer forward operation of the neural network by using the first layer input data and the first layer weight group data to obtain the n-th output of the forward operation. Result; Obtain the n-th output result gradient according to the n-th output result, obtain the n-th inverse operation of the n-th layer inverse operation according to the training instruction, according to the n-th output result gradient, the n-th input data, and the n-th layer The weight group data and the n-th inverse operation obtain an n-th inverse operation complexity. The n-th output result gradient, the n-th layer input data, and the n-th weight are determined according to the n-th inverse operation complexity. The nth inverse data type corresponding to the value group data, the nth output result gradient, the nth layer input data, and the nth layer weight group data are executed in the nth inverse data type to perform the nth in the neural network. Layer reverse Calculate the n-th weight group gradient and the n-th input data gradient; apply the n-th weight group gradient to update the n-th weight group data; the n-th reverse data type includes fixed-point type or floating Point type: Use the n-th input data gradient as the n-1th output result of the n-1th layer. Perform the n-1 layer direction operation to get the n-1 layer weight group gradient. Apply the n-1 layer weight. The group gradient updates a weight group data of a corresponding layer, and the weight group data includes at least two weights. 根據申請專利範圍第1項的方法,其中,該依據該第n反向運算複雜度確定該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據對應的該第n反向數據類型,包括: 將該第n反向運算複雜度與一預設閾值比較,如該第n反向運算複雜度高於該預設閾值,確定該第n反向數據類型為定點類型,如該第n反向運算複雜度低於或等於該預設閾值,計算裝置確定該第n反向數據類型為浮點類型。The method according to item 1 of the scope of patent application, wherein the n-th output result gradient, the n-th layer input data, and the n-th weight group data corresponding to the n-th output result gradient are determined according to the n-th inverse operation complexity. The reverse data type includes: comparing the nth reverse operation complexity with a preset threshold, and if the nth reverse operation complexity is higher than the preset threshold, determining the nth reverse data type as a fixed-point type If the complexity of the n-th reverse operation is lower than or equal to the preset threshold, the computing device determines that the n-th reverse data type is a floating point type. 根據申請專利範圍第2項的方法,其中,該方法在依據該第n反向運算複雜度確定該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據對應的該第n反向數據類型之後還包括: 確定該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據屬於的第n+1反向數據類型,如該第n+1反向數據類型與該第n反向數據類型不同,將屬於該第n+1反向數據類型的該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據轉換成屬於該第n反向數據類型的該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據。The method according to item 2 of the scope of patent application, wherein the method determines the n-th output result gradient, the n-th layer input data, and the n-th weight group data corresponding to the n-th inverse operation complexity. The n-th reverse data type also includes: determining the n-th output result gradient, the n-th input data, and the n + 1-th reverse data type to which the n-th weight group data belongs, such as the n + 1 The reverse data type is different from the nth reverse data type. The nth output result gradient, the nth layer input data, and the nth weight group data that belong to the n + 1th reverse data type are converted into The n-th output result gradient, the n-th input data, and the n-th weight group data belonging to the n-th reverse data type. 根據申請專利範圍第1項的方法,其中,如該n層反向運算為卷積運算,卷積輸入數據為該第n層輸入數據,卷積核為該第n輸出結果梯度, 該第n反向運算複雜度=α*C*kW*kW*M*N*W*C*H; 其中,α為卷積系數,取值範圍為大於1;C、kW、kW、M為該卷積核四個維度的值,N、W、C、H為該卷積輸入數據四個維度的值; 如該第n反向運算複雜度大於一設定閾值,確定該第n反向數據類型為浮點數據類型,確定該卷積輸入數據以及該卷積核是否為浮點數據,如該卷積輸入數據以及該卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將該卷積核轉換成浮點數據,然後將該卷積輸入數據、該卷積核以浮點數據類型執行卷積運算。The method according to item 1 of the scope of patent application, wherein if the n-layer inverse operation is a convolution operation, the convolution input data is the n-layer input data, the convolution kernel is the n-th output result gradient, and the n-th Complexity of inverse calculation = α * C * kW * kW * M * N * W * C * H; where α is the convolution coefficient, and the value range is greater than 1; C, kW, kW, and M are the convolutions Kernel the values of the four dimensions, N, W, C, H are the values of the four dimensions of the convolutional input data; if the complexity of the nth reverse operation is greater than a set threshold, determine that the nth reverse data type is floating Point data type, to determine whether the convolution input data and the convolution kernel are floating point data. If the convolution input data and the convolution kernel are not floating point data, convert the convolution input data to floating point data. Point data, convert the convolution kernel into floating point data, and then input the convolution input data, and the convolution kernel performs a convolution operation in the floating point data type. 根據申請專利範圍第1項的方法,其中,如該第n反向運算為一矩陣乘矩陣運算,該輸入數據為該第n層輸入數據,該權值為該第n輸出結果梯度; 該第n反向運算複雜度=β*F*G*E*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為該第n層輸入數據的行、列值,E、F為該權值的行、列值; 如該第n反向運算複雜度大於一設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及該權值是否為浮點數據,如該第n層輸入數據以及該權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將該權值轉換成浮點數據,然後將該第n層輸入數據、該權值以浮點數據類型執行該矩陣乘矩陣運算。The method according to item 1 of the scope of patent application, wherein if the nth inverse operation is a matrix multiplication matrix operation, the input data is the nth layer input data, and the weight is the nth output result gradient; n Inverse operation complexity = β * F * G * E * F; where β is a matrix coefficient and the value range is greater than or equal to 1, F and G are the row and column values of the input data of the nth layer, and E, F is the row and column value of the weight; if the complexity of the n-th reverse operation is greater than a set threshold, determine that the n-th reverse data type is a floating-point data type, determine the n-th input data and the weight Whether the value is floating-point data, such as the n-th input data and the weight is not floating-point data, convert the n-th input data to floating-point data, and convert the weight to floating-point data , And then perform the matrix-by-matrix operation on the n-th input data and the weights as a floating-point data type. 根據申請專利範圍第1項的方法,其中,如該第n反向運算為一矩陣乘向量運算,該輸入數據為該第n層輸入數據,該權值為該第n輸出結果梯度; 該第n反向運算複雜度=β*F*G*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為該第n層輸入數據的行、列值,F為該第n輸出結果梯度的列值; 如該第n反向運算複雜度大於一設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及該權值是否為浮點數據,如該第n層輸入數據以及該權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將該權值轉換成浮點數據,然後將該第n層輸入數據、該權值以浮點數據類型執行該矩陣乘向量運算。The method according to item 1 of the scope of patent application, wherein if the nth inverse operation is a matrix multiplication vector operation, the input data is the nth layer input data, and the weight is the nth output result gradient; n Inverse operation complexity = β * F * G * F; where β is a matrix coefficient and the value range is greater than or equal to 1, F and G are the row and column values of the input data of the nth layer, and F is the first The column value of the n output result gradient; if the complexity of the n-th reverse operation is greater than a set threshold, determine that the n-th reverse data type is a floating-point data type, determine whether the n-th input data and whether the weight is Floating point data, such as the nth layer input data and the weight value is not floating point data, the nth layer input data is converted into floating point data, the weight value is converted into floating point data, and then The n-th layer of input data and the weights perform the matrix multiplication vector operation in a floating-point data type. 根據申請專利範圍第1-6項任意一項的方法,其中, 該n層反運算還包括:偏執運算、全連接運算、GEMM運算、GEMV運算、激活運算中的一種或任意組合。The method according to any one of claims 1 to 6, wherein the n-layer inverse operation further includes one or any combination of paranoid operation, fully connected operation, GEMM operation, GEMV operation, and activation operation. 一種集成電路芯片裝置,其中,該集成電路芯片裝置用於執行神經網絡的訓練運算,該神經網絡包括n層;該集成電路芯片裝置包括:處理電路以及外部介面; 該外部介面,用於接收一訓練指令; 該處理電路,用於依據該訓練指令確定第一層輸入數據和第一層權值組數據,計算裝置通過該第一層輸入數據和該第一層權值組數據執行神經網絡的n層正向運算得到正向運算的第n輸出結果; 該處理電路,還用於依據該第n輸出結果得到第n輸出結果梯度,依據該訓練指令獲取第n層反向運算的第n反向運算,依據該第n輸出結果梯度、第n層輸入數據、第n層權值組數據以及該第n反向運算得到一第n反向運算複雜度,依據該第n反向運算複雜度確定該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據對應的第n反向數據類型,將該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據以該第n反向數據類型執行神經網絡的該第n層反向運算得到第n層權值組梯度和第n層輸入數據梯度; 應用該第n層權值組梯度對該第n層權值組數據進行更新;該第n反向數據類型包括:定點類型或浮點類型; 該處理電路,還用於將該第n層輸入數據梯度作為第n-1層的第n-1輸出結果梯度執行n-1層方向運算得到n-1層權值組梯度,應用該n-1層權值組梯度更新對應層的權值組數據,該權值組數據包括;至少二個權值。An integrated circuit chip device, wherein the integrated circuit chip device is used to perform a training operation of a neural network, the neural network includes n layers; the integrated circuit chip device includes: a processing circuit and an external interface; the external interface is used for receiving a Training instruction; the processing circuit is configured to determine the first layer input data and the first layer weight group data according to the training instruction, and the computing device executes the neural network through the first layer input data and the first layer weight group data The n-layer forward operation obtains the n-th output result of the forward operation; the processing circuit is further configured to obtain the n-th output result gradient according to the n-th output result, and obtain the n-th inverse operation of the n-th layer reverse operation according to the training instruction. Directional operation, according to the nth output result gradient, nth layer input data, nth layer weight group data, and the nth inverse operation to obtain an nth inverse operation complexity, according to the nth inverse operation complexity Determine the n-th output result gradient, the n-th input data, and the n-th reverse data type corresponding to the n-th weight group data, the n-th output result gradient, and the n-th input The data, the n-th weight group data, and the n-th inverse data type to perform the n-th layer inverse operation of the neural network to obtain the n-th weight group gradient and the n-th input data gradient; apply the n-th layer The weight group gradient updates the n-th layer weight group data; the n-th reverse data type includes: a fixed-point type or a floating-point type; the processing circuit is further configured to use the n-th input data gradient as the n-th The n-1th output result gradient of the -1 layer performs the n-1 layer direction operation to obtain the n-1 layer weight group gradient, and applies the n-1 layer weight group gradient to update the weight group data of the corresponding layer, and the weight value Group data includes; at least two weights. 根據申請專利範圍第8項的集成電路芯片裝置,其中, 該處理電路,具體將該第n反向運算複雜度與一預設閾值比較,如該第n反向運算複雜度高於該預設閾值,確定該第n反向數據類型為定點類型,如該第n反向運算複雜度低於或等於該預設閾值,確定該第n反向數據類型為浮點類型。According to the integrated circuit chip device according to item 8 of the scope of patent application, the processing circuit specifically compares the nth inverse operation complexity with a preset threshold, such as the nth inverse operation complexity is higher than the preset A threshold value, determining that the n-th reverse data type is a fixed-point type, and if the complexity of the n-th reverse data operation is lower than or equal to the preset threshold, determining the n-th reverse data type as a floating-point type. 根據申請專利範圍第9項的集成電路芯片裝置,其中,該集成電路芯片裝置還包括:數據類型轉換電路; 該處理電路,還用於確定該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據屬於的第n+1反向數據類型,如該第n+1反向數據類型與該第n反向數據類型不同,向該數據類型轉換電路發送轉換命令, 該數據類型轉換電路,用於將屬於第n+1反向數據類型的該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據轉換成屬於該第n反向數據類型的該第n輸出結果梯度、該第n層輸入數據、該第n層權值組數據。The integrated circuit chip device according to item 9 of the scope of patent application, wherein the integrated circuit chip device further includes: a data type conversion circuit; the processing circuit is further configured to determine the n-th output result gradient, the n-th input data, The n + 1th reverse data type to which the nth layer weight group data belongs. If the n + 1th reverse data type is different from the nth reverse data type, a conversion command is sent to the data type conversion circuit. A data type conversion circuit, configured to convert the n-th output result gradient, the n-th layer input data, and the n-th weight group data that belong to the n + 1-th reverse data type into the n-th reverse data type The n-th output result gradient, the n-th input data, and the n-th weight group data. 根據申請專利範圍第8項的集成電路芯片裝置,其中,如該n層反向運算為卷積運算,卷積輸入數據為該第n層輸入數據,卷積核為該第n輸出結果梯度, 該處理電路,用於計算該第n反向運算複雜度, 該第n反向運算複雜度=α*C*kW*kW*M*N*W*C*H; 其中,α為卷積系數,取值範圍為大於1;C、kW、kW、M為該卷積核四個維度的值,N、W、C、H為該卷積輸入數據四個維度的值; 該處理電路,還用於如該第n反向運算複雜度大於一設定閾值,確定該第n反向數據類型為浮點數據類型,確定該卷積輸入數據以及該卷積核是否為浮點數據;如該卷積輸入數據以及該卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將該卷積核轉換成浮點數據,然後將該卷積輸入數據、該卷積核以浮點數據類型執行卷積運算。According to the integrated circuit chip device of the eighth patent application scope, if the n-layer inverse operation is a convolution operation, the convolution input data is the n-layer input data, and the convolution kernel is the n-th output result gradient, The processing circuit is configured to calculate the nth reverse operation complexity, where the nth reverse operation complexity = α * C * kW * kW * M * N * W * C * H; where α is a convolution coefficient , The value range is greater than 1; C, kW, kW, M are the values of the four dimensions of the convolution kernel, N, W, C, H are the values of the four dimensions of the convolution input data; the processing circuit, also It is used to determine if the complexity of the n-th reverse operation is greater than a set threshold, determine that the n-th reverse data type is a floating-point data type, determine whether the convolution input data and whether the convolution kernel is floating-point data; The convolution input data and the convolution kernel are not floating point data, the convolution input data is converted into floating point data, the convolution kernel is converted into floating point data, and then the convolution input data, The convolution kernel performs convolution operations on floating-point data types. 根據申請專利範圍第8項的集成電路芯片裝置,其中,如該第n反向運算為一矩陣乘矩陣運算,該輸入數據為該第n層輸入數據,該權值為該第n輸出結果梯度; 該處理電路,用於計算該第n反向運算複雜度, 該第n反向運算複雜度=β*F*G*E*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為該第n層輸入數據的行、列值,E、F為該權值的行、列值; 該處理單元,用於如該第n反向運算複雜度大於一設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及該權值是否為浮點數據,如該第n層輸入數據以及該權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將該權值轉換成浮點數據,然後將該第n層輸入數據、該權值以浮點數據類型執行該矩陣乘矩陣運算。According to the integrated circuit chip device of the eighth patent application scope, if the nth inverse operation is a matrix multiplication matrix operation, the input data is the nth layer input data, and the weight is the nth output result gradient The processing circuit is configured to calculate the complexity of the n-th reverse operation, where the complexity of the n-th reverse operation = β * F * G * E * F; where β is a matrix coefficient and the value range is greater than or equal to 1 , F, G are the row and column values of the nth layer of input data, and E and F are the row and column values of the weight; the processing unit is configured to, if the complexity of the nth inverse operation is greater than a set threshold, Determine that the n-th reverse data type is a floating-point data type, and determine whether the n-th input data and the weight are floating-point data, such as the n-th input data and the weight is not floating-point data , Convert the n-th input data to floating-point data, convert the weight to floating-point data, and then perform the matrix multiplication matrix operation on the n-th input data and the weight as a floating-point data type . 根據申請專利範圍第8項的集成電路芯片裝置,其中,如該第n反向運算為一矩陣乘向量運算,該輸入數據為該第n層輸入數據,該權值為該第n輸出結果梯度; 該處理電路,用於計算該第n反向運算複雜度, 該第n反向運算複雜度=β*F*G*F;其中,β為矩陣系數,取值範圍為大於等於1,F、G為該第n層輸入數據的行、列值,F為該第n輸出結果梯度的列值; 該處理電路,還用於如該第n反向運算複雜度大於一設定閾值,確定該第n反向數據類型為浮點數據類型,確定該第n層輸入數據以及該權值是否為浮點數據,如該第n層輸入數據以及該權值不為浮點數據,將該第n層輸入數據轉換成浮點數據,將該權值轉換成浮點數據,然後將該第n層輸入數據、該權值以浮點數據類型執行該矩陣乘向量運算。According to the integrated circuit chip device of the eighth patent application scope, if the nth inverse operation is a matrix multiplication vector operation, the input data is the nth layer input data, and the weight is the nth output result gradient The processing circuit is configured to calculate the complexity of the n-th reverse operation, where the complexity of the n-th reverse operation = β * F * G * F; where β is a matrix coefficient, and the value range is greater than or equal to 1, F And G are row and column values of the n-th layer of input data, and F is a column value of the n-th output result gradient; the processing circuit is further configured to determine the complexity of the n-th reverse operation greater than a set threshold to determine the The n-th reverse data type is a floating-point data type. Determine whether the n-th input data and the weight are floating-point data. If the n-th input data and the weight are not floating-point data, The nth layer input data is converted into floating point data, the weight value is converted into floating point data, and then the nth layer input data and the weight value are used to perform the matrix multiplication vector operation in a floating point data type. 根據申請專利範圍第8-13項任意一項的集成電路芯片裝置,其中, 該n反向運算還包括:偏執運算、全連接運算、GEMM運算、GEMV運算、激活運算中的一種或任意組合。The integrated circuit chip device according to any one of claims 8-13, wherein the n reverse operation further includes one or any combination of paranoid operation, fully connected operation, GEMM operation, GEMV operation, and activation operation. 一種神經網絡運算裝置,其中,該神經網絡運算裝置包括一個或多個如申請專利範圍第8-14項任意一項的集成電路芯片裝置。A neural network computing device, wherein the neural network computing device includes one or more integrated circuit chip devices according to any one of claims 8-14 of the scope of the patent application. 一種組合處理裝置,其中,該組合處理裝置包括:如申請專利範圍第15項的一神經網絡運算裝置、一通用互聯介面和一通用處理裝置; 該神經網絡運算裝置通過該通用互聯介面與該通用處理裝置連接。A combined processing device, wherein the combined processing device includes: a neural network computing device, a universal interconnection interface, and a universal processing device, such as item 15 of the scope of patent application; the neural network computing device communicates with the universal through the universal interconnection interface The processing device is connected. 一種芯片,其中,該芯片集成如申請專利範圍第8-14項任意一項的裝置。A chip, wherein the chip integrates a device such as any one of items 8-14 of the scope of patent application. 一種電子設備,其中,該電子設備包括如申請專利範圍第17項的芯片。An electronic device, wherein the electronic device includes a chip as in item 17 of the scope of patent application.
TW107144042A 2017-12-14 2018-12-07 Method for neural network training and related product TWI793225B (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201711347767.1A CN109961138B (en) 2017-12-14 2017-12-14 Neural network training method and related product
CN201711347767.1 2017-12-14

Publications (2)

Publication Number Publication Date
TW201928794A true TW201928794A (en) 2019-07-16
TWI793225B TWI793225B (en) 2023-02-21

Family

ID=67018622

Family Applications (1)

Application Number Title Priority Date Filing Date
TW107144042A TWI793225B (en) 2017-12-14 2018-12-07 Method for neural network training and related product

Country Status (2)

Country Link
CN (1) CN109961138B (en)
TW (1) TWI793225B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109978156B (en) * 2017-12-28 2020-06-12 中科寒武纪科技股份有限公司 Integrated circuit chip device and related product
EP3719712B1 (en) 2017-12-27 2022-09-07 Cambricon Technologies Corporation Limited Integrated circuit chip device
CN109977446B (en) * 2017-12-28 2020-07-07 中科寒武纪科技股份有限公司 Integrated circuit chip device and related product
CN110490315B (en) * 2019-08-14 2023-05-23 中科寒武纪科技股份有限公司 Reverse operation sparse method of neural network and related products
CN111523661B (en) * 2020-04-21 2023-03-24 厦门利德集团有限公司 Neural network optimization method for electric power safety operation based on information entropy and self-expectation
CN111860818B (en) * 2020-07-23 2022-11-08 哈尔滨工业大学(威海) SOM neural network algorithm processing method based on intelligent chip
CN114679388B (en) * 2022-02-22 2023-09-05 同济大学 Time-sensitive network data traffic prediction method, system and storage medium
CN117634459A (en) * 2024-01-24 2024-03-01 山东海量信息技术研究院 Target content generation and model training method, device, system, equipment and medium

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7747070B2 (en) * 2005-08-31 2010-06-29 Microsoft Corporation Training convolutional neural networks on graphics processing units
TWI417797B (en) * 2010-02-04 2013-12-01 Univ Nat Taipei Technology A Parallel Learning Architecture and Its Method for Transferred Neural Network
US20170061279A1 (en) * 2015-01-14 2017-03-02 Intel Corporation Updating an artificial neural network using flexible fixed point representation
US10515304B2 (en) * 2015-04-28 2019-12-24 Qualcomm Incorporated Filter specificity as training criterion for neural networks
US10380479B2 (en) * 2015-10-08 2019-08-13 International Business Machines Corporation Acceleration of convolutional neural network training using stochastic perforation
CN105488565A (en) * 2015-11-17 2016-04-13 中国科学院计算技术研究所 Calculation apparatus and method for accelerator chip accelerating deep neural network algorithm
CN106991476B (en) * 2016-01-20 2020-04-10 中科寒武纪科技股份有限公司 Apparatus and method for performing artificial neural network forward operations
CN110135581B (en) * 2016-01-20 2020-11-06 中科寒武纪科技股份有限公司 Apparatus and method for performing artificial neural network inverse operation
CN107301454B (en) * 2016-04-15 2021-01-22 中科寒武纪科技股份有限公司 Artificial neural network reverse training device and method supporting discrete data representation
CN111310904B (en) * 2016-04-29 2024-03-08 中科寒武纪科技股份有限公司 Apparatus and method for performing convolutional neural network training
CN109934331B (en) * 2016-04-29 2020-06-19 中科寒武纪科技股份有限公司 Apparatus and method for performing artificial neural network forward operations
US9646243B1 (en) * 2016-09-12 2017-05-09 International Business Machines Corporation Convolutional neural networks using resistive processing unit array

Also Published As

Publication number Publication date
TWI793225B (en) 2023-02-21
CN109961138A (en) 2019-07-02
CN109961138B (en) 2020-04-14

Similar Documents

Publication Publication Date Title
TWI793225B (en) Method for neural network training and related product
US11748605B2 (en) Integrated circuit chip device
TWI791725B (en) Neural network operation method, integrated circuit chip device and related products
US20230120704A1 (en) Integrated circuit chip apparatus
CN109961136B (en) Integrated circuit chip device and related product
TWI768159B (en) Integrated circuit chip apparatus and related product
TWI767098B (en) Method for neural network forward computation and related product
TWI793224B (en) Integrated circuit chip apparatus and related product
CN109977446B (en) Integrated circuit chip device and related product
CN109978156B (en) Integrated circuit chip device and related product
CN109978148B (en) Integrated circuit chip device and related product
CN109978157B (en) Integrated circuit chip device and related product
TWI768160B (en) Integrated circuit chip apparatus and related product
CN109978152B (en) Integrated circuit chip device and related product
TWI767097B (en) Integrated circuit chip apparatus and related product
WO2019165946A1 (en) Integrated circuit chip device, board card and related product
TWI795482B (en) Integrated circuit chip apparatus and related product
CN109978158B (en) Integrated circuit chip device and related product
WO2019165940A1 (en) Integrated circuit chip apparatus, board card and related product