Method, apparatus, medium and device for adjusting neural network input based on RRAM array
By adjusting the input values in each row of the RRAM array, the accumulated error is reduced, thus solving the problem of inaccurate calculations in RRAM devices and improving the recognition accuracy of neural networks.
Patent Information
- Application Number
- CN202311181557.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-13
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2043-09-13
AI Technical Summary
Existing RRAM devices exhibit inaccuracies in neural network computation, leading to a decrease in the accuracy of computation and recognition results.
By acquiring the input data of the neural network, the ideal and actual unit current values of each row in the RRAM array are determined, the total error is calculated, and the input values are adjusted row by row to reduce the cumulative error, thus obtaining the target input data.
This improves the accuracy of calculation results from RRAM devices and ensures the accuracy of recognition results from neural networks.
Smart Images

Figure CN117217271B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computers, in particular to a neural network input adjustment method and device based on an RRAM array, a medium and an apparatus. BACKGROUND
[0002] Resistive random access memory (RRAM) is a new type of non-volatile memory that uses controllable resistance changes to store data. Its working principle is to apply a voltage of different sizes or polarities to the resistive random access memory (RRAM) to control the resistance value of the resistive random access memory (RRAM) to switch between high and low resistance states. In the current technical solution, the resistive random access memory (RRAM) device is often used for matrix-vector multiplication of a neural network to greatly improve the computing efficiency. However, the inaccuracy of the resistive random access memory (RRAM) device will cause the accuracy of the calculation result to decrease, thereby affecting the accuracy of the recognition result of the neural network. Therefore, how to improve the accuracy of the calculation result based on the resistive random access memory (RRAM) device and thereby ensure the accuracy of the recognition result of the neural network has become a technical problem to be solved. SUMMARY
[0003] Embodiments of the present application provide a neural network input adjustment method and device based on an RRAM array, a medium and an apparatus, thereby at least to some extent improving the accuracy of the calculation result based on the resistive random access memory (RRAM) device and thereby ensuring the accuracy of the recognition result of the neural network.
[0004] Other characteristics and advantages of the present application will become apparent from the following detailed description, or will be learned by practice of the present application.
[0005] According to one aspect of an embodiment of the present application, a neural network input adjustment method based on an RRAM array is provided, comprising:
[0006] obtaining input data of a neural network, the input data comprising to-be-input values corresponding to each row in an RRAM array;
[0007] determining ideal unit current values corresponding to each row in the RRAM array according to a plurality of weights of the neural network, the ideal unit current value being an ideal current value corresponding to the row when the input value is 1;
[0008] writing the plurality of weights into the RRAM array to determine actual unit current values corresponding to each row in the RRAM array, the actual unit current value being an actual current value corresponding to the row when the input value is 1;
[0009] determining a total error between actual output and ideal output of the RRAM array according to the to-be-input values, the ideal unit current values and the actual unit current values corresponding to each row in the RRAM array;
[0010] If an absolute value of the total error is greater than or equal to a first threshold value, a cumulative error corresponding to each row in the RRAM array is calculated row by row, and a to-be-input value corresponding to each row is adjusted according to the cumulative error corresponding to the row, so as to reduce the cumulative error corresponding to the row or reduce an increment of the cumulative error.
[0011] Target input data is obtained according to the adjusted to-be-input value corresponding to each row in the RRAM array.
[0012] According to an aspect of an embodiment of the present application, a neural network input adjustment device based on an RRAM array is provided, and the device comprises:
[0013] An obtaining module is configured to obtain input data of a neural network, wherein the input data comprises a to-be-input value corresponding to each row in an RRAM array;
[0014] A first determining module is configured to determine an ideal unit current value corresponding to each row in the RRAM array according to a plurality of weights of the neural network, wherein the ideal unit current value is an ideal current value corresponding to the row when the input value is 1;
[0015] A writing module is configured to write the plurality of weights into the RRAM array, and determine an actual unit current value corresponding to each row in the RRAM array, wherein the actual unit current value is an actual current value corresponding to the row when the input value is 1;
[0016] A second determining module is configured to determine a total error between an actual output and an ideal output of the RRAM array according to the to-be-input value, the ideal unit current value, and the actual unit current value corresponding to each row in the RRAM array;
[0017] An adjusting module is configured to, if an absolute value of the total error is greater than or equal to a first threshold value, calculate a cumulative error corresponding to each row in the RRAM array row by row, and adjust a to-be-input value corresponding to each row according to the cumulative error corresponding to the row, so as to reduce the cumulative error corresponding to the row or reduce an increment of the cumulative error.
[0018] A processing module is configured to obtain target input data according to the adjusted to-be-input value corresponding to each row in the RRAM array.
[0019] According to an aspect of an embodiment of the present application, a computer readable medium having a computer program stored thereon is provided, wherein the computer program is executed by a processor to implement the neural network input adjustment method based on the RRAM array as described in the above embodiments.
[0020] According to an aspect of some embodiments of the present application, an electronic device is provided, including: one or more processors; a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method for adjusting input of neural network based on RRAM array as described in the above embodiments.
[0021] According to an aspect of some embodiments of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method for adjusting input of neural network based on RRAM array as provided in the above embodiments.
[0022] In the technical solutions provided by some embodiments of the present application, input data of a neural network is obtained, the input data including to-be-input values corresponding to each row in a RRAM array, a plurality of weights of the neural network are determined, ideal unit current values corresponding to each row in the RRAM array are determined according to the plurality of weights, the plurality of weights are written into the RRAM array, actual unit current values corresponding to each row in the RRAM array are determined, then, a total error of the RRAM array between an actual output and an ideal output is determined according to the to-be-input values, the ideal unit current values and the actual unit current values corresponding to each row in the RRAM array, if an absolute value of the total error is greater than or equal to a first threshold, a cumulative error corresponding to each row in the RRAM array is calculated row by row, and the to-be-input value corresponding to a current row is adjusted according to the cumulative error corresponding to the current row, so as to reduce the cumulative error corresponding to the current row or the increase of the cumulative error, and then target input data is obtained according to the adjusted to-be-input values of each row, so as to be used for recognition of the neural network. In this way, the accuracy of the calculation result based on the RRAM device can be improved, and the accuracy of the recognition result of the neural network is ensured.
[0023] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF DRAWINGS
[0024] The drawings incorporated in the specification and constituting a part of the specification illustrate embodiments consistent with the present application and, together with the specification, serve to explain the principles of the present application. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor. In the drawings:
[0025] Figure 1A flowchart of a method for adjusting neural network input based on RRAM array according to an embodiment of the present application is shown.
[0026] Figure 2 A block diagram of an apparatus for adjusting neural network input based on RRAM array according to an embodiment of the present application is shown.
[0027] Figure 3 A structural diagram of a computer system of an electronic device suitable for implementing embodiments of the present application is shown. DETAILED DESCRIPTION
[0028] Example implementations will now be described more fully with reference to the accompanying drawings. Example implementations may, however, be implemented in many different forms and should not be construed as limited to the implementations set forth herein; rather, these implementations are provided so that this disclosure will be thorough and complete, and will fully convey the scope of example implementations to those skilled in the art.
[0029] Moreover, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the application. One skilled in the relevant art will recognize, however, that the
[0030] The block diagrams in the drawings show only the functional entities and not necessarily the physical separation of the functional entities. That is, the functional entities can be implemented in software, or in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0031] The flowcharts shown in the drawings are only exemplary illustrations and do not necessarily include all contents and operations / steps, nor are they necessarily executed in the order described. For example, some operations / steps can be further broken down, and some operations / steps can be combined or partially combined, so the actual execution order can be changed according to actual conditions.
[0032] Figure 1 A flowchart of a method for adjusting neural network input based on RRAM array according to an embodiment of the present application is shown. The method can be applied in a terminal device or a server, wherein the terminal device can include, but is not limited to, one or more of a smartphone, a tablet computer, a portable computer, and a desktop computer; the server can be a physical server or a cloud server.
[0033] As Figure 1 shown, the RRAM array-based neural network input adjustment method includes steps S110-S160, which are described in detail as follows (the method is applied to a terminal device as an example, which is referred to as a terminal hereinafter):
[0034] In step S110, input data of a neural network is obtained, and the input data includes to-be-input values corresponding to each row of an RRAM array.
[0035] The input data can be data used to input the neural network for recognition calculation, for example, can be pixel values of each pixel in an input image, etc.
[0036] The RRAM array can include a plurality of RRAM cells distributed in a matrix form.
[0037] In this embodiment, the terminal can obtain the input data of the neural network in real time (for example, real-time obtaining pixel values corresponding to an input image), or the terminal can obtain the input data from a storage space of the terminal, which is not specially limited. It is worth noting that the input data includes to-be-input values corresponding to each row of the RRAM array, that is, one row of RRAM cells corresponds to one to-be-input value.
[0038] In an embodiment of the present application, after obtaining the input data of the neural network, the method further includes:
[0039] Quantizing each to-be-input value in the input data, so as to use the quantized to-be-input value for subsequent adjustment.
[0040] In this embodiment, the terminal can quantize each to-be-input value to quantize floating-point data into fixed-point data, for example, quantizing the to-be-input value into 8-bit data, so that the range of the quantized to-be-input value is 0-255, if quantized into 2-bit, the range of the quantized to-be-input value is 0, 1, 2, 3, etc. Thus, a large amount of operation memory can be saved, and the operation efficiency of the subsequent operation can be improved. After quantization, the terminal can use the quantized to-be-input value for subsequent calculation.
[0041] In step S120, according to a plurality of weights of the neural network, an ideal unit current value corresponding to each row of the RRAM array is determined, and the ideal unit current value is an ideal current value corresponding to the row when the input value is 1.
[0042] In this embodiment, the terminal can obtain a plurality of weights of the neural network, and each weight corresponds to one RRAM cell. Based on the obtained plurality of weights, the terminal can calculate an ideal unit current value corresponding to each row of the RRAM array.
[0043] In an embodiment, determining the ideal unit current value corresponding to each row in the RRAM array according to a plurality of weights of the neural network comprises:
[0044] obtaining a plurality of weights of the neural network;
[0045] determining a weight mean value corresponding to each row in the RRAM array according to the plurality of weights of the neural network;
[0046] determining the ideal unit current value corresponding to each row in the RRAM array according to an input voltage corresponding to an input value of 1 and a conductance value corresponding to the weight mean value.
[0047] In this embodiment, the terminal can obtain the plurality of weights of the neural network from the storage space of the terminal, calculate the weight mean value corresponding to each row in the RRAM array based on the correspondence between the weights and the RRAM cells, and query the ideal average resistance of the whole row corresponding to the row based on the weight mean value corresponding to the row, for example, query based on a pre-configured correspondence table between the weight mean value and the ideal average resistance of the whole row. Then, the input voltage corresponding to the input value of 1 is multiplied by the conductance value corresponding to the weight mean value (i.e., the inverse of the ideal average resistance of the whole row), to obtain the output current (i.e., the ideal unit current value) corresponding to the row. For example, when the input value is 1, the corresponding input voltage is 0.1V, and the resistance value corresponding to the weight mean value is 100KΩ, the corresponding ideal unit current value is 1μA (i.e., 0.1 / 100000).
[0048] It should be noted that the input voltage and the input value have a corresponding relationship, which can be pre-configured. For example, when the input value is 1, the corresponding input voltage is 0.1V, when the input value is 2, the corresponding input voltage is 0.2V, and so on.
[0049] In step S130, a plurality of weights are written into the RRAM array, and an actual unit current value corresponding to each row in the RRAM array is determined, the actual unit current value being an actual current value corresponding to the row when the input value is 1.
[0050] In this embodiment, the terminal can write a plurality of weights into the RRAM array, and measure the actual average resistance of the whole row corresponding to each row in the actual RRAM array, to obtain the actual unit current value corresponding to the row based on the input voltage corresponding to the input value of 1 and the conductance value corresponding to the actual average resistance of the whole row (i.e., the inverse of the actual average resistance of the whole row). For example, when the input value is 1, the corresponding input voltage is 0.1V, and the actual average resistance of the whole row is 80KΩ, the actual unit current value is 1.25μA (i.e., 0.1 / 80000).
[0051] In step S140, according to the to-be-input value corresponding to each row in the RRAM array, the ideal unit current value and the actual unit current value, the total error of the RRAM array between the actual output and the ideal output is determined.
[0052] In this embodiment, the terminal can determine the total error of the RRAM array between the actual output and the ideal output based on the to-be-input value corresponding to each row in the RRAM array, the ideal unit current value and the actual unit current value. Specifically, the terminal can multiply the to-be-input value corresponding to each row by the product of the actual unit current value, subtract the product of the to-be-input value and the ideal unit current value, thereby obtaining the current error corresponding to the row, and then add the current errors corresponding to all rows, thereby obtaining the total error corresponding to the RRAM.
[0053] In step S150, if the absolute value of the total error is greater than or equal to a first threshold, the cumulative error corresponding to each row in the RRAM array is calculated row by row, and the to-be-input value corresponding to each row is adjusted according to the cumulative error corresponding to the row, so as to reduce the cumulative error corresponding to the row or the increase of the cumulative error.
[0054] The first threshold can be determined in advance by a person skilled in the art according to prior experience.
[0055] In this embodiment, it should be understood that since the weight can be positive or negative, and the to-be-input value can also be positive or negative, the total error calculated can also be positive or negative. Therefore, the terminal compares the absolute value of the total error calculated with the first threshold. If the absolute value of the total error is greater than or equal to the first threshold, it means that the error is too large, and the input data of the neural network needs to be adjusted. If the absolute value of the total error is less than the first threshold, it means that the error is small, and the input data of the neural network does not need to be adjusted, and the input data can be directly used as the calculation of the neural network.
[0056] When the input data of the neural network needs to be adjusted, the terminal can calculate the cumulative error corresponding to each row in the RRAM array row by row, and adjust the to-be-input value corresponding to each row according to the cumulative error corresponding to the row, so as to reduce the cumulative error corresponding to the row or the increase of the cumulative error.
[0057] In an embodiment of the present application, the cumulative error corresponding to each row in the RRAM array is calculated row by row, and the to-be-input value corresponding to each row is adjusted according to the cumulative error corresponding to the row, including:
[0058] The product of the to-be-input value corresponding to the current row in the RRAM array and the actual unit current value is subtracted from the product of the to-be-input value and the ideal unit current value, thereby obtaining the single-row error corresponding to the current row.
[0059] accumulating the single-row error of each calculated row including the current row to obtain the accumulated error corresponding to the current row;
[0060] if the absolute value of the accumulated error corresponding to the current row is less than the second threshold, maintaining the to-be-input value corresponding to the current row;
[0061] if the absolute value of the accumulated error corresponding to the current row is greater than or equal to the second threshold, adjusting the to-be-input value corresponding to the current row, and calculating the accumulated error corresponding to the next row according to the adjusted to-be-input value.
[0062] In this embodiment, the terminal can start from the first row to calculate the accumulated error, subtract the product of the to-be-input value corresponding to the current row in the RRAM array and the ideal unit current value from the product of the to-be-input value and the actual unit current value, thereby obtaining the single-row error corresponding to the current row. After obtaining the single-row error corresponding to the current row, the single-row error of each calculated row including the current row is accumulated, thereby obtaining the accumulated error corresponding to the current row. Then, the absolute value of the accumulated error corresponding to the current row is compared with the second threshold, wherein the second threshold is less than or equal to the first threshold, and the second threshold can be determined by a person skilled in the art according to prior experience.
[0063] When the absolute value of the accumulated error corresponding to the current row is less than the second threshold, it indicates that the current accumulated error is small, and the to-be-input value can not be adjusted, so as to reduce the number of judgments, reduce power consumption, and improve adjustment efficiency.
[0064] When the absolute value of the accumulated error corresponding to the current row is greater than or equal to the second threshold, it indicates that the current accumulated error is large, and the to-be-input value needs to be adjusted, so as to reduce the accumulated error corresponding to the current row or the increase of the accumulated error. Thus, the error caused by each row in the RRAM array can be controlled row by row, and the error is prevented from being too large. After adjustment, the accumulated error corresponding to the next row is calculated based on the adjusted to-be-input value of the current row, that is, the accumulated error corresponding to each row is calculated based on the adjusted to-be-input value of the calculated row, so as to ensure the accuracy of the accumulated error calculation.
[0065] In one embodiment of the present application, if the absolute value of the accumulated error corresponding to the current row is greater than or equal to the second threshold, the to-be-input value corresponding to the current row is adjusted, including:
[0066] if the accumulated error corresponding to the current row is positive and greater than or equal to the second threshold, the to-be-input value is subtracted by a predetermined value when the weight average corresponding to the current row is positive, and the to-be-input value is added by a predetermined value when the weight average corresponding to the current row is negative, and the predetermined value is positive;
[0067] If the accumulated error corresponding to the current row is negative and its absolute value is greater than or equal to the second threshold value, then if the weight mean value corresponding to the current row is positive, the input value is added by a predetermined value; if the weight mean value corresponding to the current row is negative, if the input value is positive, the input value is subtracted by the predetermined value, and if the input value is negative, the input value is added by the predetermined value.
[0068] If the input value corresponding to the current row is 0, no adjustment is made to the input value.
[0069] In this embodiment, since the weight and the input value have positive and negative, when the input value needs to be adjusted, the accumulated error, the weight and the positive and negative of the input value need to be considered. Specifically, if the accumulated error corresponding to the current row is positive and greater than or equal to the second threshold value, if the weight mean value corresponding to the current row is positive, the input value is subtracted by a predetermined value, and if the weight mean value corresponding to the current row is negative, the input value is added by a predetermined value, wherein the predetermined value is positive and can be determined by those skilled in the art in advance, for example, the predetermined value can be 1, that is, each adjustment is to add 1 or subtract 1 to the input value, etc. Thus, the accumulated error corresponding to the current row or the increase of the accumulated error can be reduced, thereby achieving the purpose of controlling the total error.
[0070] Then, if the accumulated error corresponding to the current row is negative and its absolute value is greater than or equal to the second threshold value, if the weight mean value corresponding to the current row is positive, the input value is added by a predetermined value; if the weight mean value corresponding to the current row is negative, if the input value is positive, the input value is subtracted by a predetermined value, and if the input value is negative, the input value is added by a predetermined value, to obtain the adjusted input value, to reduce the accumulated error corresponding to the current row or the increase of the accumulated error, thereby achieving the purpose of controlling the total error.
[0071] It is worth noting that when it is determined based on the accumulated error that the input value needs to be adjusted, and the input value is 0, regardless of whether the weight mean value is positive or negative, no adjustment is made to the input value.
[0072] Based on the foregoing embodiment, if there is a weight extreme value in the plurality of weights corresponding to the current row, when the input value corresponding to the current row needs to be adjusted, the input value is only allowed to be adjusted in the direction of 0, and the weight extreme value is a weight whose absolute value is greater than or equal to a third threshold value.
[0073] In this embodiment, the terminal can determine whether there is a weight extreme value, i.e., a weight whose absolute value is greater than or equal to a third threshold, in each row of the RRAM array according to the correspondence between the weight and the RRAM cell. The third threshold can be determined in advance by a person skilled in the art according to prior experience, for example, the third threshold can be determined by multiplying the maximum weight by 0.8, for example, if the maximum weight is 1, the third threshold is 0.8, i.e., 1*0.8, and the like. It should be understood that the sign of the weight is considered at this time.
[0074] When the terminal determines that the corresponding input value of a row needs to be adjusted based on the accumulated error, if there is a weight extreme value in the weight corresponding to the row, the input value is only allowed to be adjusted in the direction of 0. For example, based on the above-mentioned adjustment mode of the input value, the input value corresponding to a row is 1, according to the above-mentioned adjustment rule, the input value needs to be added by a predetermined value, however, there is at least one weight extreme value in the weight corresponding to the row, so the input value is not adjusted; if the input value corresponding to the row needs to be subtracted by a predetermined value according to the above-mentioned adjustment rule, there is at least one weight extreme value in the weight corresponding to the row, the input value is subtracted by the predetermined value according to the above-mentioned adjustment rule, i.e., the input value is only allowed to be adjusted in the direction of 0.
[0075] The rows without weight extreme values are adjusted according to the above-mentioned adjustment rule, i.e., the input value can be adjusted upward and downward. It should be understood that when there is a weight extreme value in the weight corresponding to a row, if the input value is adjusted in the direction away from 0, it is most likely that the final calculation result will exceed the range, and after exceeding the range, the calculation result will become more uncontrollable, therefore, when there is a weight extreme value in the weight corresponding to a row, the input value is only allowed to be adjusted in the direction of 0, so as to ensure the accuracy of the calculation result.
[0076] Please continue to refer to Figure 1 In step S160, the target input data is obtained according to the adjusted input value of each row in the RRAM array.
[0077] In this embodiment, the terminal can integrate the adjusted input value of each row to obtain the target input data of the neural network, so as to perform recognition calculation.
[0078] Based on Figure 1In the illustrated embodiment, input data of a neural network is obtained, the input data including to-be-input values corresponding to each row in an RRAM array, ideal unit current values corresponding to each row in the RRAM array are determined according to a plurality of weights of the neural network, the plurality of weights are written into the RRAM array, actual unit current values corresponding to each row in the RRAM array are determined, then, a total error of the RRAM array between an actual output and an ideal output is determined according to the to-be-input values, the ideal unit current values, and the actual unit current values corresponding to each row in the RRAM array, if an absolute value of the total error is greater than or equal to a first threshold, a cumulative error corresponding to each row in the RRAM array is calculated row by row, and the to-be-input value corresponding to a current row is adjusted according to the cumulative error corresponding to the current row, so as to reduce the cumulative error corresponding to the current row or an increase of the cumulative error, and target input data is obtained according to the adjusted to-be-input values of each row, to be used as recognition of the neural network. In this way, the accuracy of a calculation result based on an RRAM device can be improved, and the accuracy of a recognition result of the neural network is ensured.
[0079] The device embodiment of the present application is described below, which can be used to execute the neural network input adjustment method based on an RRAM array in the above-mentioned embodiments of the present application. For details not disclosed in the device embodiment of the present application, refer to the above-mentioned embodiments of the neural network input adjustment method based on an RRAM array.
[0080] Figure 2 A block diagram of a neural network input adjustment device based on an RRAM array according to one embodiment of the present application is shown.
[0081] Reference Figure 2 As shown, the neural network input adjustment device based on an RRAM array according to one embodiment of the present application includes:
[0082] An obtaining module is configured to obtain input data of a neural network, the input data including to-be-input values corresponding to each row in an RRAM array;
[0083] A first determining module is configured to determine ideal unit current values corresponding to each row in the RRAM array according to a plurality of weights of the neural network, the ideal unit current value being an ideal current value corresponding to the row when the input value is 1;
[0084] A writing module is configured to write the plurality of weights into the RRAM array, to determine actual unit current values corresponding to each row in the RRAM array, the actual unit current value being an actual current value corresponding to the row when the input value is 1;
[0085] a second determining module, configured to determine a total error of the RRAM array between an actual output and an ideal output according to a to-be-input value corresponding to each row in the RRAM array, an ideal unit current value, and an actual unit current value;
[0086] an adjusting module, configured to, if an absolute value of the total error is greater than or equal to a first threshold value, calculate a cumulative error corresponding to each row in the RRAM array row by row, and adjust the to-be-input value corresponding to each row according to the cumulative error corresponding to the row, so as to reduce the cumulative error corresponding to the row or an increase value of the cumulative error;
[0087] a processing module, configured to obtain target input data according to the adjusted to-be-input value corresponding to each row in the RRAM array.
[0088] In an embodiment of the present application, the adjusting of the to-be-input value corresponding to each row according to the cumulative error corresponding to the row includes:
[0089] multiplying the to-be-input value corresponding to a current row in the RRAM array by the actual unit current value, subtracting the product of the to-be-input value and the ideal unit current value, and obtaining a single-row error corresponding to the current row;
[0090] adding up the calculated single-row error corresponding to each row including the current row, and obtaining a cumulative error corresponding to the current row;
[0091] if an absolute value of the cumulative error corresponding to the current row is less than a second threshold value, maintaining the to-be-input value corresponding to the current row;
[0092] if the absolute value of the cumulative error corresponding to the current row is greater than or equal to the second threshold value, adjusting the to-be-input value corresponding to the current row, and calculating a cumulative error corresponding to a next row according to the adjusted to-be-input value.
[0093] In an embodiment of the present application, if the absolute value of the cumulative error corresponding to the current row is greater than or equal to the second threshold value, the adjusting of the to-be-input value corresponding to the current row includes:
[0094] if the cumulative error corresponding to the current row is a positive value and is greater than or equal to the second threshold value, subtracting a predetermined value from the to-be-input value when a weight average value corresponding to the current row is a positive value, or adding a predetermined value to the to-be-input value when the weight average value corresponding to the current row is a negative value, the predetermined value being a positive number;
[0095] If the accumulated error corresponding to the current row is negative and the absolute value of the accumulated error is greater than or equal to the second threshold value, the input value is adjusted by a predetermined value when the weight average value corresponding to the current row is positive; when the weight average value corresponding to the current row is negative, if the input value is positive, the input value is reduced by the predetermined value, and if the input value is negative, the input value is increased by the predetermined value.
[0096] If the input value corresponding to the current row is 0, the input value is not adjusted.
[0097] In an embodiment of the present application, if there is a weight extreme value in the plurality of weights corresponding to the current row, when the input value corresponding to the current row needs to be adjusted, the input value is only allowed to be adjusted in the direction of 0, and the weight extreme value is a weight whose absolute value is greater than or equal to a third threshold value.
[0098] In an embodiment of the present application, after obtaining the input data of the neural network, the obtaining module is further configured to:
[0099] Quantize each input value in the input data to adjust the input according to the quantized input value.
[0100] In an embodiment of the present application, the ideal unit current value corresponding to each row in the RRAM array is determined according to a plurality of weights of the neural network, including:
[0101] Obtaining a plurality of weights of a neural network;
[0102] Determining a weight average value corresponding to each row in the RRAM array according to a plurality of weights of the neural network;
[0103] Determining the ideal unit current value corresponding to each row in the RRAM array according to the conductance value corresponding to the weight average value and the input voltage corresponding to the input value of 1.
[0104] Figure 3 A structural schematic diagram of a computer system of an electronic device suitable for implementing embodiments of the present application is shown.
[0105] It should be noted that, Figure 3 The computer system of the electronic device shown is only an example and should not limit the functions and use range of embodiments of the present application.
[0106] As Figure 3As shown, the computer system includes a central processing unit (CPU) 301 which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 302 or loaded into a random access memory (RAM) 303 from a storage section 308, for example, to execute the methods described in the above embodiments. In the RAM 303, various programs and data required for the operation of the system are also stored. The CPU 301, the ROM 302, and the RAM 303 are connected to each other through a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0107] Connected to the I / O interface 305 are an input section 306 including a keyboard, a mouse, etc.; an output section 307 including a display device such as a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 308 including a hard disk, etc.; and a communication section 309 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to the I / O interface 305 as necessary. A removable recording medium 311 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is attached to the drive 310 as necessary, so that a computer program read therefrom is installed into the storage section 308 as necessary.
[0108] In particular, according to embodiments of the present application, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, embodiments of the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing a computer program for executing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via the communication section 309, and / or installed from the removable recording medium 311. When the computer program is executed by the central processing unit (CPU) 301, various functions defined in the system of the present application are performed.
[0109] It should be noted that the computer-readable medium in the embodiments of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination thereof. The computer-readable storage medium may, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any combination thereof. More specific examples of the computer-readable storage medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (Compact Disc Read-Only Memory, CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or apparatus. In the present application, the computer-readable signal medium can include a data signal carrying computer-readable computer programs in a baseband or as a part of a carrier wave. Such a propagated data signal can take various forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate or transmit programs for use by or in conjunction with an instruction execution system, device or apparatus. The computer programs contained in the computer-readable medium can be transmitted by any suitable medium, including but not limited to wireless, wired, or the like, or any suitable combination thereof.
[0110] The flowcharts and block diagrams in the drawings illustrate the possible implementation architectures, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In the flowcharts or block diagrams, each block can represent a module, a program segment or a part of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in different orders than that shown in the drawings. For example, two blocks represented in succession can actually be executed substantially in parallel, and sometimes in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams or flowcharts, and the combination of blocks in the block diagrams or flowcharts, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0111] The units described in the embodiments of the present application can be implemented by software, or by hardware, or by a combination of software and hardware. The units described can also be located in a single processor. In some cases, the names of the units do not limit the units themselves.
[0112] As another aspect, the present application also provides a computer readable medium, which can be included in the electronic device described in the above embodiments, or can exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to implement the method described in the above embodiments.
[0113] It should be noted that although several modules or units for performing actions are mentioned in the above detailed description, the division into the modules or units is not mandatory. In fact, according to the embodiments of the present application, features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, features and functions of one module or unit described above can be further divided into a plurality of modules or units.
[0114] From the above description of the embodiments, those skilled in the art will readily appreciate that the example embodiments described herein can be implemented by software and / or by hardware coupled with software. Accordingly, the technical solutions of the embodiments of the present application can be embodied in the form of a software product. The software product can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, or the like) or on a network, and includes a number of instructions for causing a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to perform the methods according to the embodiments of the present application.
[0115] Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the embodiments disclosed herein. The present application is intended to cover any variations, uses, or adaptations of the application following, in general, the principles of the application and including such
[0116] It should be understood that the present application is not limited to the precise construction that has been described above and illustrated in the accompanying drawings, and that various modifications and changes can be made by those skilled in the art without departing from the scope of the present application. The scope of the present application is limited only by the appended claims.
Claims
1. A method for adjusting neural network input based on RRAM array, characterized in that, The method comprises: obtaining input data of a neural network, the input data comprising to-be-input values corresponding to each row in an RRAM array; determining ideal unit current values corresponding to each row in the RRAM array according to a plurality of weights of the neural network, the ideal unit current value being an ideal current value corresponding to the row when the input value is 1; writing the plurality of weights into the RRAM array, and determining actual unit current values corresponding to each row in the RRAM array, the actual unit current value being an actual current value corresponding to the row when the input value is 1; determining a total error of the RRAM array between an actual output and an ideal output according to the to-be-input value, the ideal unit current value and the actual unit current value corresponding to each row in the RRAM array; if an absolute value of the total error is greater than or equal to a first threshold value, calculating a cumulative error corresponding to each row in the RRAM array row by row, and adjusting the to-be-input value corresponding to each row according to the cumulative error corresponding to the row to reduce the cumulative error corresponding to the row or an increase value of the cumulative error; obtaining target input data according to the adjusted to-be-input value corresponding to each row in the RRAM array.
2. The method of claim 1, wherein, The method of calculating the cumulative error corresponding to each row in the RRAM array row by row and adjusting the to-be-input value corresponding to each row according to the cumulative error corresponding to the row comprises: obtaining a single-row error corresponding to a current row by subtracting a product of the to-be-input value and the ideal unit current value from a product of the to-be-input value and the actual unit current value corresponding to the current row in the RRAM array; accumulating the single-row error corresponding to each row including the current row to obtain the cumulative error corresponding to the current row; if an absolute value of the cumulative error corresponding to the current row is less than a second threshold value, maintaining the to-be-input value corresponding to the current row; if the absolute value of the cumulative error corresponding to the current row is greater than or equal to the second threshold value, adjusting the to-be-input value corresponding to the current row, and calculating the cumulative error corresponding to a next row according to the adjusted to-be-input value.
3. The method of claim 2, wherein, The method of adjusting the to-be-input value corresponding to the current row if the absolute value of the cumulative error corresponding to the current row is greater than or equal to the second threshold value comprises: if the cumulative error corresponding to the current row is positive and greater than or equal to the second threshold value, and a weight mean value corresponding to the current row is positive, then the to-be-input value is reduced by a predetermined value, and if the weight mean value corresponding to the current row is negative, then the to-be-input value is increased by the predetermined value, the predetermined value being positive; if the cumulative error corresponding to the current row is negative and the absolute value thereof is greater than or equal to the second threshold value, and the weight mean value corresponding to the current row is positive, then the to-be-input value is increased by the predetermined value, and if the weight mean value corresponding to the current row is negative, then if the to-be-input value is positive, the to-be-input value is reduced by the predetermined value, and if the to-be-input value is negative, the to-be-input value is increased by the predetermined value; if the to-be-input value corresponding to the current row is 0, the to-be-input value is not adjusted.
4. The method of claim 3, wherein, If there is a weight extreme value in the plurality of weights corresponding to the current row, only the input value corresponding to the current row is allowed to be adjusted in the direction of 0 when the input value needs to be adjusted, and the weight extreme value is a weight whose absolute value is greater than or equal to a third threshold value.
5. The method according to any one of claims 1-4, characterized in that, After obtaining the input data of the neural network, the method further comprises: quantizing each input value in the input data to adjust the input according to the quantized input value.
6. The method according to any one of claims 1-4, characterized in that, According to a plurality of weights of the neural network, determining an ideal unit current value corresponding to each row in the RRAM array, comprising: obtaining a plurality of weights of a neural network; According to a plurality of weights of the neural network, determining an ideal unit current value corresponding to each row in the RRAM array, comprising: According to the input voltage corresponding to the input value of 1 and the conductance value corresponding to the weight average value, determining the ideal unit current value corresponding to each row in the RRAM array.
7. A neural network input adjustment device based on RRAM array, characterized in that, comprising: an acquisition module, configured to acquire input data of a neural network, the input data comprising input values corresponding to each row in an RRAM array; a first determination module, configured to determine an ideal unit current value corresponding to each row in the RRAM array according to a plurality of weights of the neural network, the ideal unit current value being an ideal current value corresponding to the row when the input value is 1; a writing module, configured to write a plurality of weights into the RRAM array, and determine an actual unit current value corresponding to each row in the RRAM array, the actual unit current value being an actual current value corresponding to the row when the input value is 1; a second determination module, configured to determine a total error of the RRAM array between actual output and ideal output according to the input value, the ideal unit current value and the actual unit current value corresponding to each row in the RRAM array; an adjustment module, configured to, if the absolute value of the total error is greater than or equal to a first threshold value, calculate a cumulative error corresponding to each row in the RRAM array row by row, and adjust the input value corresponding to each row according to the cumulative error corresponding to each row to reduce the cumulative error corresponding to the row or the increase of the cumulative error; a processing module, configured to obtain target input data according to the adjusted input value corresponding to each row in the RRAM array.
8. The apparatus of claim 7, wherein, The adjustment module is configured to: obtain a single-row error corresponding to the current row by subtracting the product of the input value corresponding to the current row in the RRAM array and the ideal unit current value from the product of the input value and the actual unit current value; add the single-row error corresponding to each row including the current row to obtain a cumulative error corresponding to the current row; if the absolute value of the cumulative error corresponding to the current row is less than a second threshold value, keep the input value corresponding to the current row; if the absolute value of the cumulative error corresponding to the current row is greater than or equal to the second threshold value, adjust the input value corresponding to the current row, and calculate the cumulative error corresponding to the next row according to the adjusted input value.
9. A computer readable medium having stored thereon a computer program, characterized in that The computer program is executed by the processor to implement the RRAM array-based neural network input adjustment method of any one of claims 1-6.
10. An electronic device, comprising: comprising: one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, cause the one or more processors to implement the RRAM array based neural network input adjustment method of any one of claims 1 to 6.
Citation Information
Patent Citations
Method of mitigating sneak path influence in memristor cross array and related equipment
CN111144058A
Neural network mapping method based on resistive random access memory and accelerator
CN112070204A