A model training method, apparatus, medium, and device based on resistive random access memory (RRAM).
By determining and updating network weights in resistive switching memory, and using transformation relationships for model training, the problem of low efficiency of resistive switching memory in model training is solved, and the prediction accuracy and training efficiency of the model are improved.
Patent Information
- Application Number
- CN202311686862.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-07
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2043-12-07
AI Technical Summary
Existing model training efficiency based on resistive switching memory is low. Especially when training regression models, noise problems caused by conductance value writing errors affect the prediction accuracy and training efficiency of the model.
By obtaining the sample data and the initial network weight in the target model, determine its corresponding conductance value, and write it in the resistive switching memory. Use the conversion relationship to convert the data into a voltage value to control the memory output current, obtain the prediction result, and then according to The gradient information updates the network weights, replacing the initial weights in the target model for training.
It effectively solves the randomness problem caused by the resistance-switching memory conductance value writing error, improves the prediction accuracy and training efficiency of the model, and significantly reduces the consumption of data transmission and computing resources.
Smart Images

Figure CN117744731B
Abstract
Description
Technical Field
[0001] This specification relates to the field of neural networks, and in particular to a model training method, device, medium and equipment based on resistive random access memory. Background Art
[0002] With the continuous development of the field of neural networks, models based on neural networks can predict target data through input data. According to the nature of the data processed by different models, the models can be divided into linear system models for linear data and nonlinear system models for nonlinear data. According to the type of model output value, the models can also be divided into classification models and regression models.
[0003] However, in the existing model training, the data used to build the model and the data to be calculated need to be continuously transferred between the model and the storage, so that the data can be processed by the constructed model, and the model can be trained by the processed data, but the model training based on this data transfer needs to occupy a large amount of performance space. Based on this, resistive memory came into being. This device can simulate the model by writing the conductance value corresponding to the network weight of the model. Through this resistive memory, a large amount of model data transmission cost can be saved. However, since the conductance value range of resistive memory is often small, it is difficult to achieve accurate simulation of the model, which leads to low training efficiency of existing models based on resistive memory. In particular, for the training of regression models, if the data is processed by resistive memory, due to the presence of random factors such as conductance value writing errors in the resistive memory, noise will be present in the obtained prediction data, and if the regression model is trained using prediction data with noise, the training efficiency of the model will be greatly reduced.
[0004] Therefore, how to effectively improve the efficiency of model training is an urgent problem to be solved. Summary of the invention
[0005] This specification provides a model training method based on resistive random access memory to partially solve the above-mentioned problems existing in the prior art.
[0006] This manual adopts the following technical solutions:
[0007] This specification provides a model training method based on resistive random access memory, including: obtaining sample data, and determining each initial network weight included in the target model;
[0008] For each initial network weight, determining a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight;
[0009] Writing the conductance value corresponding to each initial network weight into the resistive memory, and converting the sample data according to a first conversion relationship to obtain a voltage value corresponding to the sample data for controlling the resistive memory;
[0010] Controlling the resistive random access memory according to the voltage value to obtain a current value of a current output by the resistive random access memory at a voltage corresponding to the voltage value;
[0011] Convert the current value according to a second conversion relationship to obtain a prediction result corresponding to the sample data;
[0012] Obtaining gradient information according to a deviation between an actual label corresponding to the sample data and the predicted result, and reading from the resistive random access memory each actual conductance value when the current is output according to the voltage of the voltage value, so as to determine a network weight corresponding to each actual conductance value;
[0013] The target model is trained according to the network weights corresponding to the actual conductance values and the gradient information.
[0014] Optionally, for each initial network weight, determining a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight specifically includes:
[0015] For each initial network weight, adjusting the value corresponding to the initial network weight to fall within a preset network weight range, to obtain an adjusted network weight corresponding to the initial network weight;
[0016] According to the maximum value of each adjusted network weight and the preset scale parameter, the conductance value corresponding to each adjusted network weight is determined as the conductance value corresponding to each initial network weight.
[0017] Optionally, the first conversion relationship is determined by a first conversion scale parameter, and the first conversion scale parameter is determined by the sample data with the largest value in the dimension among the sample data and a preset ratio parameter.
[0018] Optionally, the second conversion relationship is determined by a conversion relationship between each initial network weight and a conductance value corresponding to each initial network weight and a conversion scale parameter.
[0019] Optionally, training the target model according to the network weights corresponding to the actual conductance values and the gradient information specifically includes:
[0020] For each actual conductance value, determining a network weight corresponding to the actual conductance value;
[0021] Replacing each initial network weight in the target model with the network weight corresponding to each actual conductance value;
[0022] The target model is trained according to the replaced network weights and the gradient information.
[0023] Optionally, the method further comprises:
[0024] Determine each trained network weight in the trained model, and obtain the conductance value corresponding to each trained network weight;
[0025] Writing the conductance value corresponding to each trained network weight into the resistive random access memory to obtain an updated resistive random access memory;
[0026] Receiving data to be processed, and determining a voltage value corresponding to the data to be processed according to the data to be processed;
[0027] Controlling the updated resistive random access memory according to the voltage value corresponding to the data to be processed, so as to obtain a current value of a current output by the updated resistive random access memory at a voltage corresponding to the data to be processed, as the current value corresponding to the data to be processed;
[0028] According to the current value corresponding to the data to be processed, a prediction result corresponding to the data to be processed is obtained.
[0029] This specification provides a model training device based on resistive random access memory, including:
[0030] An acquisition module, used to acquire sample data and determine the initial network weights contained in the target model;
[0031] A first determination module is used to determine, for each initial network weight, a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight;
[0032] A writing module, used for writing the conductance value corresponding to each initial network weight into the resistive memory, and converting the sample data according to a first conversion relationship to obtain a voltage value corresponding to the sample data for controlling the resistive memory;
[0033] A control module, used for controlling the resistive random access memory according to the voltage value, so as to obtain a current value of a current output by the resistive random access memory at a voltage corresponding to the voltage value;
[0034] A conversion module, used for converting the current value according to a second conversion relationship to obtain a prediction result corresponding to the sample data;
[0035] A reading module, configured to obtain gradient information according to a deviation between an actual label corresponding to the sample data and the prediction result, and read from the resistive random access memory each actual conductance value when the current is output according to the voltage of the voltage value, so as to determine a network weight corresponding to each actual conductance value;
[0036] A training module is used to train the target model according to the network weights corresponding to each actual conductance value and the gradient information.
[0037] Optionally, the first determining module is specifically configured to:
[0038] For each initial network weight, the value corresponding to the initial network weight is adjusted to fall within the preset network weight range to obtain the adjusted network weight corresponding to the initial network weight; according to the maximum value of each adjusted network weight and the preset scale parameter, the conductance value corresponding to each adjusted network weight is determined as the conductance value corresponding to each initial network weight.
[0039] Optionally, the first conversion relationship is determined by a first conversion scale parameter, and the first conversion scale parameter is determined by the sample data with the largest value in the dimension among the sample data and a preset ratio parameter.
[0040] Optionally, the second conversion relationship is determined by a conversion relationship between each initial network weight and a conductance value corresponding to each initial network weight and a conversion scale parameter.
[0041] Optionally, the training module is specifically used to:
[0042] For each actual conductance value, determine the network weight corresponding to the actual conductance value; replace each initial network weight in the target model with the network weight corresponding to each actual conductance value; and train the target model according to each replaced network weight and the gradient information.
[0043] Optionally, the device further comprises:
[0044] The second determination module is used to determine each trained network weight in the trained model and obtain the conductance value corresponding to each trained network weight; write the conductance value corresponding to each trained network weight into the resistive random access memory to obtain an updated resistive random access memory; receive data to be processed and determine the voltage value corresponding to the data to be processed according to the data to be processed; control the updated resistive random access memory according to the voltage value corresponding to the data to be processed to obtain the current value of the current output by the updated resistive random access memory under the voltage corresponding to the voltage value of the data to be processed, as the current value corresponding to the data to be processed; obtain the prediction result corresponding to the data to be processed according to the current value corresponding to the data to be processed.
[0045] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned model training method based on resistive random access memory is implemented.
[0046] This specification provides an electronic device, including a processor and a computer program stored in a memory and executable on the processor, wherein the processor implements the above-mentioned model training method based on resistive random access memory when executing the program.
[0047] At least one of the above technical solutions adopted in this specification can achieve the following beneficial effects:
[0048] In the model training method based on resistive random access memory provided in the present specification, sample data is first obtained and each initial network weight contained in the target model is determined, and then the conductivity value in the resistive random access memory corresponding to each initial network weight is determined by a preset scale parameter, and each determined conductivity value is written into the resistive random access memory, and then the sample data is converted into a voltage value for controlling the resistive random access memory to control the output current of the resistive random access memory. The prediction result corresponding to the sample data can be obtained through the current value of the output current of the resistive random access memory, and the gradient information is obtained according to the deviation between the actual label corresponding to the sample data and the prediction result corresponding to the sample data, and then the network circle corresponding to each actual conductivity value in the resistive random access memory replaces each initial network weight in the target model, so as to train the target model with each initial network weight replaced according to the obtained gradient information.
[0049] It can be seen from the above method that by pre-adjusting each initial network weight, and then converting each adjusted network weight into a conductance value of the resistive memory according to a preset scale parameter and the maximum value of each adjusted network weight, each initial network weight is more reasonably mapped to a conductance value in the resistive memory, and after the resistive memory outputs current, the network weights corresponding to each conductance value in the resistive memory are first replaced by each network weight in the target model, and then the target model with the replaced network weights is trained through the current output by the resistive memory, thereby solving the problem of write error in the resistive memory when writing conductance values and affecting the training target model, and improving the training efficiency of the target model in the model training process based on the resistive memory. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The illustrative embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation on this specification. In the drawings:
[0051] Figure 1A flowchart of a model training method based on resistive random access memory provided in this specification;
[0052] Figure 2 A flowchart for simulating and iterating a model trained based on a resistive random access memory provided in this specification;
[0053] Figure 3 A schematic diagram of the structure of a model training device based on resistive random access memory provided in this specification;
[0054] Figure 4 A method provided in this specification corresponding to Figure 1 Schematic diagram of the structure of an electronic device. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solutions and advantages of this specification more clear, the technical solutions of this specification will be clearly and completely described below in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0056] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.
[0057] The execution subject of the model training method based on resistive memory provided in this specification can be a terminal device such as a laptop computer, a desktop computer, or a client installed in the terminal device, or a dedicated device for training the model, or a server. For the sake of ease of description, the following only takes the execution subject as an example to illustrate the model training method based on resistive memory provided in this specification.
[0058] In the existing neural network field, the training of neural network-based models often requires a large amount of sample data. In the existing model training methods, computing devices need to transmit a large amount of high-frequency data required for model training, such as data for building the model, sample data, and model output data. This directly leads to the existing model training process requiring a large amount of computing resources.
[0059] Based on the above problems, a resistive memory has emerged that can map the network weights in the model by using the conductance values in the device. By converting the sample data into the voltage that controls the resistive memory, the current value of the output current of the resistive memory that can be converted into the prediction result of the equivalent model can be obtained. This significantly reduces the transmission of a large amount of sample data during the model training process and the consumption of computing resources for calculation. However, at present, resistive memory cannot be used as a commonly used model training tool. The reason is that the accuracy of the conductance value written in the resistive memory is low, which directly leads to the difficulty of the resistive memory to accurately map the network weights in the model. In addition, when the conductance values corresponding to the initial network weights in the target model are written into the resistive memory, there will be write errors including conductance write deviation and conductance write invalidity, that is, the written conductance value is different from the target conductance value, which also affects the quality of the final prediction result.
[0060] As described above, the existing model training method based on RRAM has major defects. During the training process, the model is affected by the writing error of the RRAM and cannot obtain high-quality prediction results, thereby reducing the training efficiency of the model.
[0061] Based on this, the present specification provides a model training method based on resistive memory, and the dedicated equipment maps each initial network weight in the target model to each conductance value in the resistive memory, and then processes the sample data through the resistive memory through the conversion relationship between the sample data and the voltage value used to control the resistive memory, and the conversion relationship between the current value of the current output by the resistive memory and the prediction data required for the target model training, and then obtains the prediction result for the sample data, which significantly reduces the computing resource requirements for data transmission. After obtaining the gradient information through the prediction result, considering the randomness problem caused by the conductance value writing error in the resistive memory, before training the target model according to the gradient information, the network weights corresponding to each actual conductance value in the resistive memory are replaced by each initial network weight in the target model, and then the gradient information of the replaced target model is updated through the obtained gradient information to train the target model. By solving the randomness problem caused by the conductance value writing error in the resistive memory, the prediction accuracy of the target model trained based on the resistive memory is enhanced, and the training efficiency of the target model is improved.
[0062] The scheme provided in this manual will be described in detail below.
[0063] Figure 1 A flowchart of a model training method based on resistive random access memory provided in this specification includes:
[0064] S101: Obtain sample data and determine initial network weights included in the target model.
[0065] In this specification, the sample data obtained by the dedicated device is usually nonlinear data. Compared with linear data, nonlinear data cannot describe the correspondence between a set of data with corresponding relationships through a simple straight line relationship. By using nonlinear data as sample data to train the target model, the trained target model can be equipped with the ability to determine the data corresponding to the sample data through the input sample data.
[0066] Next, a model training method using nonlinear data as sample data is introduced. During the process of heating the air by the electric heating device, the input voltage u and the air temperature y during the electric heating period are continuously sampled at fixed time intervals to obtain 1000 sets of corresponding data as initial data. Then, 604 sets of initial data in the relatively stable middle part are selected and combined to obtain each sample data. A sample data can be represented as follows:
[0067]
[0068] Among them, N'=604, a=4, b=3, c=1. This sample data is actually represented as including the air temperature collected at the previous sampling point of the nth sampling point, the input voltage collected at the third sampling point before the nth sampling point, and the input voltage collected at the fourth sampling point before the nth sampling point. This sample data is used to predict the air temperature collected at the nth sampling point.
[0069] It should be noted that the specific form of the sample data is not specifically limited in this specification and can be determined according to actual needs. For example, in the above formula, an additional data can be added to the sample data, such as y n-5 , or changing the values of a, b, or c, through the model training method described in this application, a model with predictive ability can still be trained through sample data.
[0070] In addition, optionally, the dedicated device can select the first 300 groups from the 600 groups as sample data for training the target model, and the last 300 groups can be used as test data to test the trained target model.
[0071] After obtaining the sample data, the dedicated device needs to determine the initial network weights included in the target model to be trained. It should be noted that the initial network weights included in the target model to be trained can also be determined before obtaining the sample data, or the sample data and the initial network weights included in the target model to be trained can be obtained at the same time.
[0072] S102: For each initial network weight, determine a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight.
[0073] After the dedicated device determines the initial network weights contained in the target model, if the initial network weights are directly converted into the conductance values for controlling the resistive memory, due to the poor precision of the resistive memory, the large difference between the different conductance values that can be written, the small range of conductance values that can be written, and the small difference between some initial network weights, etc., in the process of converting the initial network weights into the conductance values in the resistive memory, the conductance values corresponding to multiple different initial network weights are the same, and the conductance values corresponding to most of the network weights are the maximum or minimum values within the conductance value range corresponding to the resistive memory. In the case where the resistive memory directly maps the target model, it will directly affect the training efficiency of the target model training process using the resistive memory as the data processing device.
[0074] Based on the above problems, this specification proposes a method of first adjusting each initial network weight, and then determining the conductance value corresponding to each adjusted network weight through the maximum value among the adjusted network weights, so that the conductance value corresponding to each adjusted network weight can avoid the problem of uneven distribution as much as possible.
[0075] Specifically, for each initial network weight, the value corresponding to the initial network weight falls within the preset network weight range to obtain the adjusted network parameter corresponding to the initial network weight. Taking the preset network weight range of [-1,1] as an example, for each initial network weight, if the value corresponding to the initial network weight is within this range, no change is made, and if the value corresponding to the initial network parameter exceeds this range, the initial network weight is adjusted to the value closest to the preset network weight range, that is, if the initial network weight is -1.5, the initial network weight is adjusted to -1.
[0076] After obtaining the adjusted network weights corresponding to all the initial network weights according to the above adjustment method, the maximum value of each adjusted network weight and the preset scale parameter are used to determine the conductance value corresponding to each adjusted network weight as the conductance value corresponding to each initial network weight. Among them, the preset scale parameter can be determined according to the preset network weight range and the conductance value range of the resistive random access memory. The purpose of presetting the above scale parameter is the same as the purpose of using the maximum value of the adjusted network weight value as the calculation element, which is to make the conductance value corresponding to each initial network weight calculated more evenly distributed in the writable conductance value range in the resistive random access memory.
[0077] The formula for calculating the conductance value corresponding to each adjusted network weight is as follows:
[0078]
[0079] Among them, it is necessary to first determine the maximum value W of each adjusted network weight max Since network weights are negative, when selecting the maximum value of each adjusted network weight, the maximum value of each adjusted network weight is selected. 60 is the preset scale parameter used for multiplier calculation. The round operation is to retain the decimal point of the calculation result in the brackets. The brackets are 1, which means that one decimal place is retained. According to W max After the results are calculated using the preset scale parameters, the calculated results are usually centered at 0. In order to evenly distribute the conductance values, the center point of the results needs to be adjusted to the vicinity of the center value of the conductance value that can be written to the resistive random access memory, that is, the calculated It is necessary to add a G value preset according to the center value of the conductance value that can be written into the resistive memory. 标准 , to determine the conductance value corresponding to each adjusted network weight as the conductance value corresponding to each initial network weight. 标准 It can also be set according to specific needs. For example, the G value can be preset according to the distribution density of the conductivity value that can be written into the resistive memory. 标准 .
[0080] It should be noted that in the method for calculating the conductance value corresponding to each initial network weight mentioned above in this application, the formula is not specifically limited, and the main method is still to limit each initial network weight by the conductance value range that can be written into the resistive memory and the preset scale parameter, so that the conductance value corresponding to each initial network weight after calculation is more evenly distributed to the writable conductance value range in the resistive memory.
[0081] S103: writing the conductance value corresponding to each initial network weight into the resistive memory, and transforming the sample data according to a first transformation relationship to obtain a voltage value corresponding to the sample data for controlling the resistive memory.
[0082] After determining the conductance value corresponding to each initial network weight, the dedicated device writes the conductance value corresponding to each initial network weight into the resistive memory, so that the resistive memory can output a current that can be converted into a prediction result corresponding to the sample data under the control of the voltage value converted according to the sample data. After writing each conductance value into each conductance in the resistive memory, the sample data needs to be converted into a corresponding voltage value for the resistive memory.
[0083] Specifically, it is necessary to first determine the conversion relationship between the sample data and the voltage value through a conversion scale parameter, and the conversion scale parameter is determined through the sample data with the largest value in the dimension among the sample data and a preset ratio parameter.
[0084] The formula for determining the conversion scale parameter and the formula for determining the voltage value for controlling the resistive memory corresponding to the sample data through the conversion scale parameter are as follows:
[0085]
[0086]
[0087] Among them, scale is the conversion scale parameter. In the process of calculating the conversion scale parameter, it is necessary to first determine the sample data with the largest value in the dimension among each sample data input. In the present application, for 300 groups of sample data, each group of sample data includes three data, that is, a total of 900 data, and the sample data with the largest value in the dimension among each sample data is the maximum value among the 900 data. 0.3 in the formula is a preset proportional parameter, which is also determined according to the maximum value of the input voltage of the resistive random access memory and other related parameters, such as, the proportional parameter is determined by the maximum value of the input voltage of the resistive random access memory and the current value range of the output current.
[0088] After determining the conversion scale parameter by using the sample data with the largest value in the dimension and the preset ratio parameter among the sample data, the first conversion relationship can be determined by the conversion scale parameter. For the resistive memory, the control of the resistive memory can be realized at multiple corresponding interfaces through multiple voltage values at the same time.
[0089] Continuing with the above example, for the sample data mentioned in step S101, the sample data includes:
[0090]
[0091] If the sample data is converted into a voltage value for controlling the resistive memory, three voltage values will be generated, among which y n-c 、u n-b and u n-a That is to say, for a sample data, the three voltage values corresponding to the sample data can be determined by transforming the scale parameter, namely, the three input 电压 After that, you can enter 电压 The three voltage values contained therein control the output current of the resistive memory.
[0092] It should be pointed out that the physical quantities corresponding to the multiple data contained in a sample data may be different. For example, in the above example, the physical quantity indicated by y corresponds to temperature, and the physical quantity corresponding to u corresponds to voltage. In this solution, when the two physical quantities are converted into voltage values for controlling the resistive random access memory, the preset proportional parameters used in the calculation are the same, but it is entirely possible to set a proportional parameter corresponding to each physical quantity, thereby improving the prediction accuracy of the trained target model. Of course, the same proportional parameters as the data in the sample data can also be set, and this solution does not make specific restrictions.
[0093] S104: Controlling the resistive random access memory according to the voltage value to obtain a current value of a current output by the resistive random access memory at a voltage corresponding to the voltage value.
[0094] S105: converting the current value according to the second conversion relationship to obtain the prediction result corresponding to the sample data. After the dedicated device determines the input voltage values corresponding to the sample data, for each sample data, the resistive memory can be controlled through the corresponding number of interfaces of the resistive memory according to the voltage values corresponding to the sample data to obtain the current output by the resistive memory, and the current value of the current can be converted into the prediction data corresponding to the sample data for the trainable target model.
[0095] Continuing with the above example, in step S103, for each set of sample data corresponding to three input voltage values, at the same time, for each input voltage value, an interface of the resistive random access memory is controlled by the voltage value. That is, the resistive random access memory is controlled by three voltage values at the same time to output current.
[0096] Specifically, before converting the current value, the dedicated device needs to first determine the second conversion relationship required for converting the current value through the conversion relationship between each initial network weight and the conductivity value corresponding to each initial network weight, as well as the conversion scale parameter. Then, the conversion between the current value and the corresponding predicted data is realized according to the second conversion relationship.
[0097] Through the conversion relationship between the above initial network weights and the conductance values corresponding to the initial network weights, we can get:
[0098]
[0099] In this formula, W max As explained above, W scale It is the multiplication coefficient in the conversion between each initial network weight and the conductivity value corresponding to each initial network weight.
[0100] The conversion scale parameter is the same as the conversion parameter coefficient used in the confirmation process of the first conversion relationship, and both are the following formulas, which will not be described in detail here:
[0101]
[0102] The multiplier coefficient W in the conversion relationship between each initial network weight and the conductivity value corresponding to each initial network weight is used. scale , and the conversion scale parameter scale, the second conversion relationship required for the conversion current value can be determined:
[0103]
[0104] Where I is the current value of the current output by the resistive memory. In order to enhance the efficiency of model training, a value is often added to the prediction data in model training to increase the flexibility of the function used by the trained target model when determining the prediction result based on the sample data, improve the fitting ability of the neurons in the target model, and thus improve the efficiency of model training. Therefore, in this application, when calculating After obtaining the results, bias is also added as an optimization item for model training. The final result Output is the prediction result corresponding to the sample data obtained by the dedicated device based on the resistive random access memory, which can be used for model training.
[0105] S106: Obtaining gradient information according to the deviation between the actual label corresponding to the sample data and the predicted result, and reading from the resistive random access memory each actual conductance value when the current is output according to the voltage of the voltage value, so as to determine the network weight corresponding to each actual conductance value.
[0106] S107: Training the target model according to the network weights corresponding to the actual conductance values and the gradient information.
[0107] After obtaining the prediction results corresponding to each sample data, the dedicated equipment can obtain gradient information based on the deviation between the actual label corresponding to the sample data and the prediction result. This gradient information can be used to train the target model.
[0108] However, when the conductance value is written to the resistive memory, a write error may occur. The write error includes write deviation and write invalidity. The write deviation means that there is a deviation between the target conductance value at the time of writing and the actual conductance value written. For example, the determined conductance value is 1, and the conductance value written into the resistive memory is 1.1. The write invalidity means that when the conductance value is written, the difference between the target conductance value at the time of writing and the actual conductance value written is too large, and even the conductance value does not change according to the write operation. For example, the determined conductance value is 10, and the conductance value written into the resistive memory is 0.1 or lower. The write error described above will cause the resistive memory to have differences between the internal conductance values and the expected conductance values when the actual output current is output. This directly leads to that if the dedicated equipment directly trains the target model through the obtained gradient information, the training efficiency of the model training is low and the accuracy is low.
[0109] Therefore, in order to avoid the problem caused by writing errors, before training the target model with the determined gradient information, it is necessary to first read the actual conductance values in the resistive memory, and then use the multiplier coefficient in the conversion between each initial network weight and the conductance value corresponding to each initial network weight. and G preset according to the central value of the conductance value that can be written into the resistive memory 标准 , converting each actual conductance value into the corresponding network weight.
[0110] By replacing the initial network weights in the target model with the network weights corresponding to the determined actual conductance values, the determined gradient information can be matched with the network weights in the target model. Then, the target model is trained based on the replaced network weights and gradient information.
[0111] After training the target model, each trained network weight in the trained model can be determined, and then the conductance value corresponding to each trained network weight can be obtained. Then, the conductance value corresponding to each trained network weight is written into the resistive random access memory to obtain an updated resistive random access memory. Through the updated resistive random access memory, fast data processing can be achieved to save computing resources.
[0112] In this way, under the premise of deploying the trained target model to the resistive memory, if a data prediction task is received later, the received data can be converted into a voltage value, and then the data is quickly processed through the resistive memory, and the current value of the current output by the resistive memory is converted to obtain the prediction result of the data prediction task. This greatly reduces the number of times the existing model transfers model data and input and output data between storage and model in actual use, significantly reduces the consumption of computing resources, and effectively increases the efficiency of the model in data processing.
[0113] It should be noted that after each training of the target model by the method provided in this specification, the training efficiency of the model can be accelerated by simulating neural network iteration. In addition, the dedicated equipment can learn the deviations caused by some system errors and randomness including conductance writing errors in the output current process of the resistive memory through simulating neural network iteration, enrich the connection between the sample data learned by the model and the corresponding labels, and improve the prediction accuracy of the target model trained based on the resistive memory.
[0114] The above simulation iteration process will be described below in conjunction with the corresponding flow chart.
[0115] Figure 2 A flowchart for simulating and iterating a model trained based on resistive memory is provided for this specification:
[0116] The dedicated model uses the sample data and the initial network weights of the target model to train the target model based on the resistive memory, and simulates and iterates the trained model. During the simulation iteration process, for each iterative training, the dedicated device inputs the sample data into the target model, obtains the prediction results corresponding to the sample data output by the target model, and then trains the target model by minimizing the deviation between the prediction results corresponding to the sample data output by the target model and the actual labels corresponding to the sample data as the optimization goal.
[0117] It should be noted that the model can also be comprehensively trained in two training methods, for example. First 200 simulation trainings, and then 1 training based on resistive memory. Taking the above training process as the loop target, taking 5 times as an example, each training is 200+1 model trainings, for a total of 1005 trainings. It should be noted that in practical applications, it is necessary to perform multiple rounds of training on the target model, and in the execution process of each round, the network weights contained in the target model at the beginning of the round of training are called initial network weights, and then the initial network weights are adjusted, and the conductance value corresponding to the initial network weights used to write resistive memory in this round of training is determined by the adjusted network weights. The method for adjusting the initial network weights is specifically described in step S102. This specification does not make specific restrictions.
[0118] Through the above method, the dedicated equipment can perform a large amount of data calculations through the resistive memory during the training process, significantly reducing the consumption of computing resources in the data processing process. And before training the model through gradient information, the initial weights of the target model are replaced with the network weights corresponding to the actual conductivity values in the resistive memory. On the basis of avoiding the influence of reduced training efficiency caused by write errors, the random factors brought by write errors can also enrich the connection between the sample data learned by the model and the corresponding labels, thereby improving the prediction accuracy of the target model and effectively improving the efficiency of model training.
[0119] The above one or more model training methods based on resistive random access memory in this specification are based on the same idea. This specification also provides corresponding devices, storage media and electronic devices.
[0120] Figure 3 A schematic diagram of a model training device based on a resistive random access memory is provided in an embodiment of this specification, and the device includes:
[0121] The acquisition module 301 is used to acquire sample data and determine each initial network weight included in the target model;
[0122] A first determining module 302 is used to determine, for each initial network weight, a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight;
[0123] A writing module 303 is used to write the conductance value corresponding to each initial network weight into the resistive memory, and to transform the sample data according to a first transformation relationship to obtain a voltage value corresponding to the sample data for controlling the resistive memory;
[0124] A control module 304, configured to control the resistive random access memory according to the voltage value, so as to obtain a current value of a current output by the resistive random access memory at a voltage corresponding to the voltage value;
[0125] A conversion module 305, configured to convert the current value according to a second conversion relationship to obtain a prediction result corresponding to the sample data;
[0126] A reading module 306 is used to obtain gradient information according to the deviation between the actual label corresponding to the sample data and the predicted result, and read from the resistive random access memory each actual conductance value when the current is output according to the voltage of the voltage value, so as to determine the network weight corresponding to each actual conductance value;
[0127] The training module 307 is used to train the target model according to the network weights corresponding to the actual conductance values and the gradient information.
[0128] Optionally, the first determining module 302 is specifically configured to:
[0129] For each initial network weight, the value corresponding to the initial network weight is adjusted to fall within the preset network weight range to obtain the adjusted network weight corresponding to the initial network weight; according to the maximum value of each adjusted network weight and the preset scale parameter, the conductance value corresponding to each adjusted network weight is determined as the conductance value corresponding to each initial network weight.
[0130] Optionally, the first conversion relationship is determined by a first conversion scale parameter, and the first conversion scale parameter is determined by the sample data with the largest value in the dimension among the sample data and a preset ratio parameter.
[0131] Optionally, the second conversion relationship is determined by a conversion relationship between each initial network weight and a conductance value corresponding to each initial network weight and a conversion scale parameter.
[0132] Optionally, the training module 307 is specifically used to:
[0133] For each actual conductance value, determine the network weight corresponding to the actual conductance value; replace each initial network weight in the target model with the network weight corresponding to each actual conductance value; and train the target model according to each replaced network weight and the gradient information.
[0134] Optionally, the device further comprises:
[0135] The second determination module 308 is used to determine each trained network weight in the trained model and obtain the conductance value corresponding to each trained network weight; write the conductance value corresponding to each trained network weight into the resistive random access memory to obtain an updated resistive random access memory; receive the data to be processed and determine the voltage value corresponding to the data to be processed according to the data to be processed; control the updated resistive random access memory according to the voltage value corresponding to the data to be processed to obtain the current value of the current output by the updated resistive random access memory under the voltage corresponding to the voltage value of the data to be processed, as the current value corresponding to the data to be processed; obtain the prediction result corresponding to the data to be processed according to the current value corresponding to the data to be processed.
[0136] This specification also provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, it can be used to perform the above Figure 1 A model training method based on resistive random access memory is provided.
[0137] based on Figure 1A model training method based on resistive memory is shown, and the embodiment of this specification also provides Figure 4 The structural diagram of the electronic device shown in FIG. Figure 4 At the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 A model training method based on resistive random access memory.
[0138] Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the executor of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0139] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0140] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0141] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0142] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0143] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0144] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0145] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0146] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0147] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0148] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0149] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0150] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0151] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0152] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0153] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0154] The above description is only an embodiment of the present specification and is not intended to limit the present specification. For those skilled in the art, the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of the claims of the present specification.
Claims
1. A model training method based on resistive random access memory, characterized in that: include: Obtain sample data and determine the initial network weights included in the target model; For each initial network weight, determining a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight; Writing the conductance value corresponding to each initial network weight into the resistive memory, and transforming the sample data according to a first transformation relationship to obtain a voltage value corresponding to the sample data for controlling the resistive memory, wherein the first transformation relationship is determined by a transformation scale parameter, and the transformation scale parameter is determined by the sample data with the largest value in the dimension among the sample data and a preset proportion parameter; Controlling the resistive random access memory according to the voltage value to obtain a current value of a current output by the resistive random access memory at a voltage corresponding to the voltage value; Convert the current value according to a second conversion relationship to obtain a prediction result corresponding to the sample data, wherein the second conversion relationship is determined by a conversion relationship between each initial network weight and the conductance value corresponding to each initial network weight and the conversion scale parameter; Obtaining gradient information according to a deviation between an actual label corresponding to the sample data and the predicted result, and reading from the resistive random access memory each actual conductance value when the current is output according to the voltage of the voltage value, so as to determine a network weight corresponding to each actual conductance value; The target model is trained according to the network weights corresponding to the actual conductance values and the gradient information.
2. The method according to claim 1, characterized in that For each initial network weight, determining a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight specifically includes: For each initial network weight, adjusting the value corresponding to the initial network weight to fall within a preset network weight range, to obtain an adjusted network weight corresponding to the initial network weight; According to the maximum value of each adjusted network weight and the preset scale parameter, the conductance value corresponding to each adjusted network weight is determined as the conductance value corresponding to each initial network weight.
3. The method according to claim 1, characterized in that Training the target model according to the network weights corresponding to the actual conductance values and the gradient information specifically includes: For each actual conductance value, determining a network weight corresponding to the actual conductance value; Replacing each initial network weight in the target model with the network weight corresponding to each actual conductance value; The target model is trained according to the replaced network weights and the gradient information.
4. The method according to claim 1, characterized in that The method further comprises: Determine each trained network weight in the trained target model, and obtain the conductance value corresponding to each trained network weight; Writing the conductance value corresponding to each trained network weight into the resistive random access memory to obtain an updated resistive random access memory; Receiving data to be processed, and determining a voltage value corresponding to the data to be processed according to the data to be processed; Controlling the updated resistive random access memory according to the voltage value corresponding to the data to be processed, so as to obtain a current value of a current output by the updated resistive random access memory at a voltage corresponding to the data to be processed, as the current value corresponding to the data to be processed; According to the current value corresponding to the data to be processed, a prediction result corresponding to the data to be processed is obtained.
5. A model training device based on resistive random access memory, characterized in that: include: An acquisition module, used to acquire sample data and determine the initial network weights contained in the target model; A first determination module is used to determine, for each initial network weight, a conductance value corresponding to the initial network weight in the resistive random access memory as the conductance value corresponding to the initial network weight; A writing module, used to write the conductance value corresponding to each initial network weight into the resistive memory, and to transform the sample data according to a first transformation relationship to obtain a voltage value corresponding to the sample data for controlling the resistive memory, wherein the first transformation relationship is determined by a transformation scale parameter, and the transformation scale parameter is determined by the sample data with the largest value in the dimension among the sample data and a preset proportion parameter; A control module, used for controlling the resistive random access memory according to the voltage value, so as to obtain a current value of a current output by the resistive random access memory at a voltage corresponding to the voltage value; a conversion module, configured to convert the current value according to a second conversion relationship to obtain a prediction result corresponding to the sample data, wherein the second conversion relationship is determined by a conversion relationship between each initial network weight and a conductance value corresponding to each initial network weight and the conversion scale parameter; A reading module, configured to obtain gradient information according to a deviation between an actual label corresponding to the sample data and the prediction result, and read from the resistive random access memory each actual conductance value when the current is output according to the voltage of the voltage value, so as to determine a network weight corresponding to each actual conductance value; A training module is used to train the target model according to the network weights corresponding to each actual conductance value and the gradient information.
6. The device according to claim 5, characterized in that The first determination module is specifically configured to: For each initial network weight, adjusting the value corresponding to the initial network weight to fall within a preset network weight range, to obtain an adjusted network weight corresponding to the initial network weight; According to the maximum value of each adjusted network weight and the preset scale parameter, the conductance value corresponding to each adjusted network weight is determined as the conductance value corresponding to each initial network weight.
7. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
8. An electronic device comprising a processor and a computer program stored in a memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.
