Model training video memory optimization method, device, electronic device and storage medium
By backing up parameters during model training, determining candidate temporary connections, and performing half-precision training, the problems of low memory utilization and slow training speed are solved, achieving efficient use of video memory and increasing training speed.
Patent Information
- Application Number
- CN202410763197.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-06-13
AI Technical Summary
In the existing technology, the problems of low memory utilization and slow training speed in model training have not been effectively solved.
By obtaining the original parameters of the model for backup, determine the candidate model connection for temporary retirement based on the model structure, do not allocate its video memory, but allocate video memory for other connections, and during the loop training process, the candidate temporary withdrawal ratio is determined according to the preset retirement ratio. The model connection performs random temporary regression, and adopts half-precision training and parameter gradient update to improve memory utilization and training speed.
It improves the utilization rate of video memory and training speed in model training, and can train large models with high complexity and excellent performance with less video memory resources.
Smart Images

Figure CN118313429B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of deep learning and large models, and in particular to a method, device, electronic device and storage medium for optimizing video memory for model training. Background Art
[0002] In the field of artificial intelligence, large model technology has become increasingly popular due to its excellent performance and wide application prospects. These models, such as those used in natural language processing and image recognition systems, are known for their huge number of parameters and complex network structures. However, this technological advancement has also brought about huge demands for hardware resources, especially video memory. Video memory, as a key resource for training these large models, often limits the scale and training speed of the model.
[0003] The commonly used method at present is to use mixed precision training models. Mixed precision training is a technology that uses a combination of single-precision (32-bit floating point) representation and half-precision (16-bit floating point) representation to process computing tasks. Some network parameters in the deep learning model are converted to half-precision types. During training, part of the calculation is performed using single-precision types, and part of the calculation is performed using half-precision, so as to improve the model accuracy while reducing the storage space occupied and execution time during the model training process. This method mainly uses the advantage of half-precision representation that can reduce the required storage space while maintaining sufficient accuracy, thereby reducing the burden on video memory. However, due to the development of artificial intelligence, the scale of models is getting larger and larger, and it is difficult to meet the required video memory using mixed precision training alone.
[0004] There is currently no effective solution to the problems of low video memory utilization and slow training speed in model training in related technologies. Summary of the invention
[0005] In this embodiment, a model training video memory optimization method, device, electronic device and storage medium are provided to solve the problems of low video memory utilization and slow training speed in model training in related technologies.
[0006] In a first aspect, a method for optimizing video memory for model training is provided in this embodiment, including:
[0007] Obtain the original parameters of the model, back up the original parameters of the model, and obtain backup parameters;
[0008] Determine a candidate temporarily retired model connection according to the model structure; do not allocate video memory to the candidate temporarily retired model connection, and allocate video memory to other model connections except the candidate temporarily retired model connection;
[0009] The cyclic training process is performed until the preset training termination condition is reached to obtain the target training model; the cyclic training process includes:
[0010] According to the preset temporary withdrawal ratio, the candidate temporary withdrawal model connections are randomly temporarily withdrawn to obtain the target connection;
[0011] According to the target connection, copy the parameters from the backup parameters for half-precision training to obtain the half-precision parameter gradient;
[0012] Update the backup parameters according to the half-precision parameter gradients.
[0013] In some of the embodiments, determining a candidate temporarily retired model connection according to the model structure includes:
[0014] Traverse the model structure and determine the specific location of Dropout in the model structure;
[0015] The model connection for candidate temporary withdrawal is determined according to the specific location of Dropout.
[0016] In some of the embodiments, determining a candidate dropout model connection according to a specific location of the Dropout includes:
[0017] According to the specific location of Dropout, temporary withdrawal is performed with rows or columns as the dimension to determine the model connection of the candidate temporary withdrawal.
[0018] In some of the embodiments, the candidate connection for temporary withdrawal is an invalid computing module in the modules before and after Dropout.
[0019] In some of the embodiments, according to the target connection, copying parameters from the backup parameters for half-precision training to obtain half-precision parameter gradients includes:
[0020] Copy the parameters from the backup parameters and use half-precision input to perform forward calculations in the target connection to obtain the loss function;
[0021] The half-precision parameter gradient is calculated according to the loss function.
[0022] In some of the embodiments, according to the target connection, copying parameters from the backup parameters for half-precision training to obtain half-precision parameter gradients includes:
[0023] According to the chain derivation rule, according to the target connection, the parameters are copied from the backup parameters for half-precision training to obtain the half-precision parameter gradient.
[0024] In some of the embodiments, updating the backup parameters according to the half-precision parameter gradient includes:
[0025] The parameter gradient corresponding to the candidate model connection for random withdrawal according to the preset withdrawal ratio is added to the half-precision parameter gradient to obtain a complete half-precision parameter gradient;
[0026] Update the backup parameters based on the full half-precision parameter gradients.
[0027] In a second aspect, a model training video memory optimization device is provided in this embodiment, including: an acquisition module, a determination module and a training module, wherein:
[0028] The acquisition module is used to acquire the original parameters of the model, back up the original parameters of the model, and obtain the backup parameters;
[0029] A determination module, used for determining a candidate temporarily retired model connection according to the model structure; not allocating video memory to the candidate temporarily retired model connection, and allocating video memory to other model connections except the candidate temporarily retired model connection;
[0030] The training module is used to execute the cyclic training process until the preset training termination condition is reached to obtain the target training model; the cyclic training process includes:
[0031] According to the preset temporary withdrawal ratio, the candidate temporary withdrawal model connections are randomly temporarily withdrawn to obtain the target connection;
[0032] According to the target connection, copy the parameters from the backup parameters for half-precision training to obtain the half-precision parameter gradient;
[0033] Update the backup parameters according to the half-precision parameter gradients.
[0034] In a third aspect, an electronic device is provided in this embodiment, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the model training video memory optimization method described in the first aspect is implemented.
[0035] In a fourth aspect, a storage medium is provided in this embodiment, on which a computer program is stored, and when the program is executed by a processor, the model training video memory optimization method described in the first aspect is implemented.
[0036] Compared with the related art, the model training video memory optimization method provided in this embodiment obtains the original parameters of the model, backs up the original parameters of the model, and obtains backup parameters; determines the candidate temporarily retired model connection according to the model structure; does not allocate video memory to the candidate temporarily retired model connection, and allocates video memory to other model connections except the candidate temporarily retired model connection; executes a cyclic training process until a preset training termination condition is reached to obtain a target training model; the cyclic training process includes: according to a preset temporary retirement ratio, randomly temporarily retiring the candidate temporarily retired model connection to obtain a target connection; according to the target connection, copying parameters from the backup parameters for half-precision training to obtain half-precision parameter gradients; updating the backup parameters according to the half-precision parameter gradients, thereby improving the utilization rate of video memory and the training speed in model training.
[0037] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0039] Figure 1 This is a hardware structure block diagram of the terminal of the model training video memory optimization method of this embodiment.
[0040] Figure 2 4 is a flowchart of the model training video memory optimization method of this embodiment.
[0041] Figure 3 This is a flowchart of another model training video memory optimization method of this embodiment.
[0042] Figure 4 It is a structural block diagram of the model training memory optimization device of this embodiment. DETAILED DESCRIPTION
[0043] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0044] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0045] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 : is a hardware structure block diagram of a terminal of the model training video memory optimization method of this embodiment. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 and a memory 104 for storing data, wherein the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0046] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the model training video memory optimization method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0047] The transmission device 106 is used to receive or send data via a network. The above network includes a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0048] In this embodiment, a method for optimizing video memory for model training is provided. Figure 2 is a flowchart of the model training video memory optimization method of this embodiment. Figure 2 As shown, the process includes the following steps:
[0049] Step S201, obtaining original parameters of the model, backing up the original parameters of the model, and obtaining backup parameters.
[0050] Specifically, in this embodiment, a deep learning model (such as a convolutional neural network CNN) is taken as an example to illustrate the optimization of video memory during the model training process. The model training process mainly involves continuously adjusting the model parameters. First, the original model parameters are obtained, and the original model parameters are backed up to obtain the backup parameters for updating and use during the training process.
[0051] Step S202, determining a candidate temporarily retired model connection according to the model structure; not allocating video memory to the candidate temporarily retired model connection, and allocating video memory to other model connections except the candidate temporarily retired model connection.
[0052] Specifically, in order to reduce video memory consumption and improve computing efficiency, before model training, connections that need to be temporarily retired are pre-determined according to the model structure. First, the model structure is analyzed, and each layer of the model is analyzed, including the type of layer (such as convolution layer, pooling layer, fully connected layer, etc.), the activation function and weight of the layer, etc. According to the model structure, connections that have little impact on model performance or consume more video memory are selected as candidate temporarily retired connections. For example, connections between certain convolution layers can be selected, or connections between certain fully connected layers can be selected. After the candidate temporarily retired model connection is determined, video memory is not directly allocated to the candidate temporarily retired connection; for other model connections except the candidate temporarily retired model connection, video memory is allocated according to the type and size of the connection, such as allocating video memory for the output of the model weight, bias, and activation function. By releasing the video memory of the candidate temporarily retired model connection, during the training process, according to the video memory usage and model performance, the video memory allocation can be dynamically adjusted. When the video memory usage reaches a certain threshold, the video memory released by the candidate temporarily retired model connection can be called to improve the training performance of the model and improve the computing efficiency.
[0053] Step S203, executing a cyclic training process until a preset training termination condition is reached to obtain a target training model; the cyclic training process includes:
[0054] Step S2031, randomly retiring the candidate retiring model connections according to a preset retiring ratio, and obtaining a target connection;
[0055] Step S2032, according to the target connection, copy the parameters from the backup parameters for half-precision training to obtain half-precision parameter gradients;
[0056] Step S2033: Update the backup parameters according to the half-precision parameter gradient.
[0057] Specifically, in the training process of the deep learning model, in order to improve the training efficiency and reduce the consumption of video memory, this embodiment adopts a random temporary withdrawal strategy including candidate temporary withdrawal connections and a half-precision training method. The following is the specific training process of this embodiment:
[0058] First, before training, the model parameters are initialized and backed up, and the backup parameters will be updated during the training process. According to the complexity of the model and the memory limit, a preset temporary withdrawal ratio is set, which is used to determine the number of connections to be temporarily withdrawn in each training batch. According to the preset temporary withdrawal ratio, a portion of candidate temporary withdrawal model connections are randomly selected for temporary withdrawal. The temporarily withdrawn connections will be temporarily removed or ignored in the current training batch to reduce memory consumption. After the temporary withdrawal process is completed, the remaining connections constitute the target connections of the current training batch. In order to further improve the training speed and reduce memory consumption, this embodiment adopts a half-precision training strategy. The parameters required for the current iteration are copied from the backup parameters and converted to half-precision (such as FP16) for training in the target connection. After the half-precision training is completed, the half-precision parameter gradient on the target connection is calculated. The backup parameters are updated according to the calculated half-precision parameter gradient, for example, the backup parameters are updated using an optimization algorithm (such as SGD, Adam, etc.). After completing the iteration of a training batch, check whether the preset training termination condition is met, wherein the preset training termination condition may be a predetermined number of training times or a predetermined accuracy rate of the model, which may be specifically set according to the actual situation, and this embodiment does not specifically limit this. If the preset termination condition is not met, the iteration of the next training batch is continued in this manner until the preset termination condition is met, and the training is stopped to obtain the target training model.
[0059] Through the above steps S201 to S203, the original parameters of the model are obtained, and the original parameters of the model are backed up to obtain backup parameters; the candidate model connection to be temporarily retired is determined according to the model structure; the video memory is not allocated to the candidate model connection to be temporarily retired, and the video memory is allocated to other model connections except the candidate model connection to be temporarily retired; the cyclic training process is performed until the preset training termination condition is reached to obtain the target training model; the cyclic training process includes: according to the preset retirement ratio, the candidate model connection to be temporarily retired is randomly retired to obtain the target connection; according to the target connection, the parameters are copied from the backup parameters for half-precision training to obtain the half-precision parameter gradient; the backup parameters are updated according to the half-precision parameter gradient. Compared with the mixed precision training method used in the prior art to reduce the use of video memory, the present application determines the connection that needs to be temporarily retired in advance before the training starts, and randomly retires the connection that needs to be temporarily retired without allocating video memory, and then adopts the mixed precision training method to perform model training, wherein the video memory released by the retired connection can also be used for other purposes in the model training process, thereby improving the utilization rate of video memory in model training and improving the training speed. On this basis, large-scale models with high complexity and excellent performance can also be trained using less graphics memory resources.
[0060] In some embodiments, determining a candidate model connection for temporary withdrawal according to a model structure includes: traversing the model structure to determine a specific position of Dropout in the model structure; and determining a candidate model connection for temporary withdrawal according to the specific position of Dropout. According to the specific position of Dropout, temporary withdrawal is performed with rows or columns as dimensions to determine a candidate model connection for temporary withdrawal. The candidate connection for temporary withdrawal is an invalid computing module in the modules before and after Dropout.
[0061] Specifically, Dropout is a technique used to prevent overfitting and improve the generalization ability of the model. Dropout randomly deletes a portion of neurons during training so that the model has a different structure in each iteration. In this way, Dropout can reduce the interaction between feature detectors (hidden layer nodes) so that the model will not rely too much on certain local features.
[0062] First, traverse the original model structure to confirm the specific location of Dropout in the original model structure. According to the specific location of Dropout, confirm the impact of the modules before and after Dropout, that is, the invalid calculation modules in the modules before and after Dropout. The specific calculation process is as follows:
[0063] In the prior art, Dropout uses a random backoff method. For example, a calculation result A is backed off at p=50%. The calculation process is:
[0064]
[0065] The random withdrawal result is:
[0066]
[0067] In this embodiment, it is specified that Dropout is temporarily withdrawn according to rows or columns, and the result obtained by temporarily withdrawing according to columns is:
[0068]
[0069] According to the chain derivation rule, the gradient of a parameter in a certain layer of the model is:
[0070]
[0071] Where L is the loss function, W is the weight of the layer, and Z is the output of the layer. Taking the multilayer perceptron (MLP layer) as an example, the output Z is the product of the weight matrix W and the input X plus the bias b, that is, ,but for , T stands for transpose; is the gradient of the loss function L with respect to the output Z after the linear transformation of this layer, The gradient of the output Z of this layer with respect to the weight W.
[0072] Therefore, for the MLP layer, if its input is the output of Dropout, since part of the input is set to 0, the gradient of the weight parameter corresponding to part of the input of the MLP layer is also 0, that is:
[0073]
[0074] During the back propagation process, if its output is the input of Dropout, since Dropout's operation on the backward gradient keeps the gradient of the discarded neurons at 0, and the gradient of the retained neurons is multiplied by a coefficient 1 / (1-P), where p is the Dropout rate, the gradient of some parameters of the MLP layer is also 0, that is:
[0075]
[0076] is the loss function L on the output of the Dropout layer gradient.
[0077] Based on the above characteristics, it is possible to predetermine which layers in the model may have parameters whose parameter matrices do not need to be updated, that is, parameters with a gradient of 0. The modules where the parameters with a gradient of 0 are located are recorded as invalid computing modules, and the connections where the invalid computing modules are located are recorded as candidate temporary withdrawal connections.
[0078] In another embodiment, according to the target connection, copying parameters from the backup parameters for half-precision training to obtain half-precision parameter gradients includes:
[0079] Copy the parameters from the backup parameters, use half-precision input to perform forward calculation in the target connection to obtain the loss function; according to the loss function and the chain derivation rule, calculate the half-precision parameter gradient.
[0080] Specifically, half-precision training is a technique in the field of deep learning that is used to reduce the use of computing resources and memory when training neural networks. Traditional deep learning model training usually uses single precision (32-bit floating point numbers, i.e. float32) to represent model weights, activation values, gradients and other information. However, as the model size increases and the amount of data increases, this representation method requires a lot of computing resources and memory.
[0081] Half-precision training reduces computing resource consumption and memory by using half-precision (16-bit floating point numbers, or float16). Half-precision floating point numbers use fewer bits to represent values, thereby reducing the memory and bandwidth required to store and transmit data. In addition, some modern hardware (such as NVIDIA's Tensor Cores) can perform efficient calculations on half-precision floating point numbers, further improving training speed.
[0082] After temporarily retiring the candidate connection, the target connection is obtained, the backup parameters are copied, the backup parameters are converted into half-precision parameters, forward propagation is performed using half-precision input data, and the loss function is calculated. Then, according to the chain derivation rule, back propagation is performed to calculate the half-precision parameter gradient.
[0083] In some other embodiments, updating the backup parameter according to the half-precision parameter gradient includes:
[0084] The parameter gradient corresponding to the candidate temporarily retired model connection that is randomly retired according to the preset retirement ratio is added to the half-precision parameter gradient to obtain a complete half-precision parameter gradient; the backup parameter is updated according to the complete half-precision parameter gradient.
[0085] Specifically, since the candidate model connection is pre-retired before the training starts, the parameter gradient corresponding to the model connection is also temporarily retired. Therefore, in order to obtain a complete half-precision parameter gradient, after the half-precision training is completed, the parameter gradient of the candidate model connection that was pre-retired is added to the half-precision parameter gradient obtained after the training, wherein the parameter gradient corresponding to the candidate model connection that was pre-retired is supplemented with 0 to obtain a complete half-precision parameter gradient. The backup parameters are updated according to the completed half-precision parameter gradient to adjust the accuracy of the model.
[0086] This embodiment also provides a method for optimizing video memory for model training. Figure 3 is a flowchart of another model training video memory optimization method of this embodiment. Figure 3 As shown, the process includes the following steps:
[0087] Step S301, obtaining original parameters of the model, backing up the original parameters of the model, and obtaining backup parameters;
[0088] Step S302, determining the specific position of the Dropout in the model structure according to the model structure, temporarily retiring the connection of the layer where the Dropout is located in the dimension of rows or columns, not allocating video memory to the temporarily retiring connection, and obtaining the target connection;
[0089] Step S303, copying the backup parameters, using half-precision input to perform forward calculation in the target connection to obtain the loss function;
[0090] Step S304, calculating the half-precision parameter gradient according to the chain derivation rule and the loss function;
[0091] Step S305, adding the parameter gradient 0 corresponding to the temporarily retired connection to the half-precision parameter gradient to obtain a complete half-precision parameter gradient;
[0092] Step S306, updating the backup parameters according to the complete half-precision parameter gradient;
[0093] Step S307, determining whether the model training reaches a preset training termination condition, if so, executing step S308, otherwise, executing step S302;
[0094] Step S308, stop model training and obtain the target training model.
[0095] Through the above steps S301 to S308, by pre-temporarily retiring the connections that do not need to be calculated according to the specific position of Dropout in the model, not allocating video memory to the temporarily retired connections, and then using half-precision training, the storage space required for training is reduced while ensuring the training accuracy, and finally the single-precision backup parameters are updated with the half-precision parameter gradient obtained by training, and the convergence and performance of the model are ensured by using a mixed precision method. Compared with the current method of only using mixed precision training, since the pre-temporarily retired connections release the video memory, the released video memory can also be used for other purposes in the model training process, thereby improving the utilization of the video memory in the model training and improving the training speed.
[0096] In this embodiment, a model training video memory optimization device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and will not be repeated hereafter. The terms "module", "unit", "sub-unit", etc. used below can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0097] Figure 4 is a structural block diagram of the model training video memory optimization device of this embodiment, such as Figure 4 As shown, the device 40 includes: an acquisition module 41, a determination module 42 and a training module 43, wherein:
[0098] The acquisition module 41 is used to acquire the original parameters of the model, back up the original parameters of the model, and obtain the backup parameters;
[0099] A determination module 42 is used to determine a candidate temporarily retired model connection according to the model structure; not allocate video memory to the candidate temporarily retired model connection, and allocate video memory to other model connections except the candidate temporarily retired model connection;
[0100] The training module 43 is used to execute a cyclic training process until a preset training termination condition is reached to obtain a target training model; the cyclic training process includes:
[0101] According to the preset temporary withdrawal ratio, the candidate temporary withdrawal model connections are randomly temporarily withdrawn to obtain the target connection;
[0102] According to the target connection, copy the parameters from the backup parameters for half-precision training to obtain the half-precision parameter gradient;
[0103] Update the backup parameters according to the half-precision parameter gradients.
[0104] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0105] In this embodiment, an electronic device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0106] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0107] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0108] S1, obtaining the original parameters of the model, backing up the original parameters of the model, and obtaining backup parameters;
[0109] S2, determining a candidate temporarily retired model connection according to the model structure; not allocating video memory to the candidate temporarily retired model connection, and allocating video memory to other model connections except the candidate temporarily retired model connection;
[0110] S3, executing a cyclic training process until a preset training termination condition is reached to obtain a target training model; the cyclic training process includes:
[0111] According to the preset temporary withdrawal ratio, the candidate temporary withdrawal model connections are randomly temporarily withdrawn to obtain the target connection;
[0112] According to the target connection, copy the parameters from the backup parameters for half-precision training to obtain the half-precision parameter gradient;
[0113] Update the backup parameters according to the half-precision parameter gradients.
[0114] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0115] In addition, in combination with the model training video memory optimization method provided in the above embodiments, a storage medium can also be provided in this embodiment to implement the method. The storage medium stores a computer program; when the computer program is executed by a processor, any one of the model training video memory optimization methods in the above embodiments is implemented.
[0116] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0117] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0118] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0119] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0120] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of patent protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A method for optimizing video memory for model training, characterized in that: include: Acquire original parameters of the model, and back up the original parameters of the model to obtain backup parameters; Determine a candidate temporarily retired model connection according to the model structure; do not allocate the video memory to the candidate temporarily retired model connection, and allocate the video memory to other model connections except the candidate temporarily retired model connection; Execute the cyclic training process until the preset training termination condition is reached to obtain the target training model; The cycle training process includes: According to a preset temporary withdrawal ratio, the candidate temporary withdrawal model connection is randomly temporarily withdrawn to obtain a target connection; According to the target connection, copy parameters from the backup parameters for half-precision training to obtain half-precision parameter gradients; The backup parameter is updated according to the half-precision parameter gradient.
2. The model training video memory optimization method according to claim 1, characterized in that: The step of determining a candidate temporarily retired model connection according to the model structure includes: Traversing the model structure to determine the specific location of Dropout in the model structure; The candidate dropout model connection is determined according to the specific location of the Dropout.
3. The model training video memory optimization method according to claim 2, characterized in that: The step of determining the candidate dropout model connection according to the specific location of the Dropout includes: According to the specific position of the Dropout, a temporary dropout is performed with rows or columns as dimensions to determine the model connection of the candidate temporary dropout.
4. The model training video memory optimization method according to claim 2, characterized in that: The candidate temporarily retired connection is an invalid computing module in the modules before and after the Dropout.
5. The model training video memory optimization method according to claim 1, characterized in that: The step of copying parameters from the backup parameters for half-precision training according to the target connection to obtain half-precision parameter gradients includes: Copy parameters from the backup parameters, use half-precision input to perform forward calculation in the target connection to obtain a loss function; The semi-precision parameter gradient is calculated according to the loss function.
6. The model training video memory optimization method according to claim 1, characterized in that: The step of copying parameters from the backup parameters for half-precision training according to the target connection to obtain half-precision parameter gradients includes: According to the chain derivation rule, according to the target connection, the parameters are copied from the backup parameters for half-precision training to obtain the half-precision parameter gradient.
7. The model training video memory optimization method according to claim 1, characterized in that: The updating of the backup parameter according to the half-precision parameter gradient includes: The parameter gradient corresponding to the candidate model connection for random withdrawal according to the preset withdrawal ratio is added to the half-precision parameter gradient to obtain a complete half-precision parameter gradient; The backup parameters are updated according to the complete half-precision parameter gradients.
8. A model training video memory optimization device, characterized in that: include: Acquisition module, determination module and training module, where: The acquisition module is used to acquire original model parameters, back up the original model parameters, and obtain backup parameters; The determination module is used to determine a candidate temporarily retired model connection according to the model structure; not allocate the video memory to the candidate temporarily retired model connection, and allocate the video memory to other model connections except the candidate temporarily retired model connection; The training module is used to execute a cyclic training process until a preset training termination condition is reached to obtain a target training model; the cyclic training process includes: According to a preset temporary withdrawal ratio, the candidate temporary withdrawal model connection is randomly temporarily withdrawn to obtain a target connection; According to the target connection, copy parameters from the backup parameters for half-precision training to obtain half-precision parameter gradients; The backup parameter is updated according to the half-precision parameter gradient.
9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the model training video memory optimization method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the model training video memory optimization method described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Training method and device of survey model of remote sensing image target, equipment and medium
CN113222039A
Defect detection model training method, device and equipment and readable storage medium
CN113888524A
Network obstacle model training method and device, nonvolatile storage medium and electronic equipment
CN117195045A
Model training method and device based on distributed parallel computing
CN117436514A
Operator scheduling operation time comparison method and device, and storage medium
WO2023150912A1
