Model training acceleration method based on parameter dynamics
By adopting a model training acceleration method based on parameter dynamics in deep learning, combined with gradient clipping technology and efficient data reading, the problems of accuracy loss and low parameter adjustment efficiency caused by batch increase are solved, and the model training speed is improved. 20x improvement and rapid iteration of parameter tuning.
Patent Information
- Application Number
- CN202410993782.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-10-15
AI Technical Summary
In deep learning, although expanding the batch data volume can increase the model training speed, it will affect the model accuracy; the adaptive learning rate technology needs to be carefully selected, otherwise it may lead to performance degradation; the threshold setting of the gradient clipping technology is difficult to determine, affecting the model performance .
Adopt a model training acceleration method based on parameter dynamics, optimize data reading through tfrecord data format and gzip compression, combine with gradient clipping technology, dynamically adjust clipping thresholds, use the TensorFlow framework to achieve batch processing and concurrent reading, smooth the training process, and reduce the batch size The accuracy loss caused by this increase.
It significantly improves the model training speed and iteration rate, maintains the model effect, improves the training efficiency and timeliness, can update the model more frequently, adapts to real-time needs, and significantly speeds up the parameter tuning process.
Smart Images

Figure CN118779658A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical fields of pattern recognition, machine learning and artificial intelligence, and specifically is a model training acceleration method based on parameter dynamics. Background Art
[0002] Among the current model acceleration solutions, common methods include using GPUs, data parallelization, increasing batch data size, adjusting learning rates, adaptive learning rates, etc. Some of these methods require additional hardware resources, some require manual parameter adjustment, and some require improving training data by losing model effects;
[0003] In the existing technology, the model training speed is usually improved by increasing the amount of data in each training batch (batch size) to better utilize the performance of GPU; or the training efficiency and performance are improved by using the technology of adaptive learning rate to automatically adjust the learning rate according to the gradient of the parameters;
[0004] However, in deep learning, increasing the batch size can increase the model training speed, but it will have a negative impact on the accuracy of the model. This is because a larger batch size may cause the model to fall into a local minimum and fail to reach the global minimum, thereby reducing the generalization ability of the model;
[0005] Adaptive learning rate is an important technology to improve model training efficiency and performance, but it requires careful selection of algorithms and hyperparameters, otherwise it may lead to degraded model performance. In practical applications, different adaptive learning rate algorithms are suitable for different scenarios and models, and need to be selected and adjusted according to actual conditions to achieve the best performance of the model. In addition, in some scenarios, the adaptive learning rate may affect the convergence speed and generalization performance of the model;
[0006] At present, to solve the above problems, the existing technology introduces gradient clipping technology, which is a technology that smoothes the training process and reduces the sensitivity of hyperparameters; however, determining the threshold of gradient clipping is a problem that needs to be solved, because if the threshold is set too small, it will affect the performance of the model, and if the threshold is set too large, it will destroy those normal features with small gradients.
[0007] In deep learning, increasing the batch size can reduce the model training time, but if the data reading takes a long time, increasing the batch size will not bring obvious acceleration effect. Therefore, it is necessary to use an efficient data reading method to accelerate model training. Therefore, this application proposes an improvement to this problem. Summary of the invention
[0008] The purpose of the present invention is to provide a model training acceleration method based on parameter dynamics to solve the problems raised in the above background technology.
[0009] In order to achieve the above object, the present invention provides the following technical solution: a model training acceleration method based on parameter dynamics, the model training acceleration method comprises the following steps:
[0010] Step 1: Read data using tfrecord and gzip compression to reduce data synchronization and serialization time; batch the data first, then perform map data mapping operations; enable concurrent reading and data preloading to take advantage of multi-threaded processing and avoid waiting for data processing to complete model training;
[0011] Step 2: Gradient update: Using clipping technology can smooth the training process and reduce the accuracy loss caused by increasing batch size; the specific steps are:
[0012] S1, data collection and preprocessing: For each training batch (batch), collect the gradients (g) corresponding to different IDs in each feature, the occurrence frequencies of these IDs (cnts), and the model parameters (w) corresponding to each ID;
[0013] S2, parameter normalization: normalize the model parameter w and calculate its norm. Here, we use TensorFlow's tf.norm(w) function to obtain the L2 norm of w, denoted as clipnorm.
[0014] S3, norm adjustment: In order to avoid the adverse effects of excessive or small clipnorm values on the subsequent clipping process, the clipnorm is dynamically adjusted;
[0015] The adjustment method is: by setting a ratio factor (ratio) and a minimum value (min_w), ensure that clipnorm is at least the larger value of ratio*clipnorm and min_w, that is, clipnorm = tf.maximum(ratio*clipnorm,min_w);
[0016] S4, frequency-weighted clipping threshold: A clipping threshold (clip_t) is calculated for each ID based on the frequency of occurrence of the ID; IDs with high frequency mean that the training data is more abundant, so their clipping threshold is also increased accordingly to reduce the clipping intensity;
[0017] Specifically, clipnorm is multiplied by frequency cnts to obtain the clipping threshold for each ID, i.e., clip_t = clipnorm*cnts;
[0018] S5, gradient normalization: Then, the L2 norm of the gradient g of each ID is calculated to obtain l2norm, that is, l2norm = tf.norm(g);
[0019] S6, calculate the final clipping threshold: combine the L2 norm of the gradient and the previously calculated clipping threshold clip_t to calculate a final clipping ratio clip for each gradient; for IDs with larger gradient norms, their clipping ratios are smaller, which means that the clipping strength is larger; and vice versa; the specific calculation is clip = l2norm / tf.maximum(l2norm,clip_t);
[0020] S7, gradient clipping: clip the original gradient g according to the final clipping ratio clip to obtain the clipped gradient g_clip, that is, g_clip = g*clip;
[0021] S8, parameter update: Finally, the clipped gradient g_clip and the preset learning rate eta are used to update the model parameter w, that is, w = w-eta*g_clip.
[0022] Preferably, the tf.norm(w) function of TensorFlow mentioned in S2 in step 2 is:
[0023] tf.norm(input,ord='euclidean', axis=None, keepdims=False, name=None, eps=None);
[0024] Used to calculate the norm of a tensor;
[0025] input: a Tensor representing the input data for which the norm is to be calculated;
[0026] ord: specifies the type of norm to be calculated; the default is 'euclidean', which is the L2 norm;
[0027] Axis: specifies the axis on which the norm is calculated;
[0028] keepdims: If True, the output tensor will maintain the number of dimensions of the input tensor, but its size will be 1 in the dimensions being reduced; if False (default), the output tensor will have fewer dimensions than the input tensor;
[0029] name: the name of the operation;
[0030] eps: A small floating point number used to improve numerical stability; by default, this parameter is None.
[0031] Preferably, the scaling factor ratio and the minimum value min_w are adjustable hyperparameters for optimizing the gradient clipping effect according to specific task requirements.
[0032] Preferably, the tfrecord data format is used to efficiently store and read large-scale data sets, and the gzip compression technology is used to reduce data storage space and transmission time.
[0033] Preferably, batch processing and map operations are implemented through the TensorFlow framework to optimize the data processing flow and improve the efficiency of model training.
[0034] Preferably, concurrent reading and data preloading processing are implemented through TensorFlow's Dataset API to utilize multi-core CPU resources and reduce the waiting time for model training.
[0035] Preferably, gradient clipping achieves different degrees of clipping of gradients of different IDs by dynamically adjusting the clipping threshold, thereby balancing stability and accuracy during training.
[0036] Preferably, the model training acceleration method is applicable to various deep learning models, including but not limited to convolutional neural networks (CNN), recurrent neural networks (RNN) and Transformer models.
[0037] The beneficial effects of the present invention are as follows:
[0038] The present invention significantly enhances the training efficiency and operating performance of deep learning models by designing a method of automatic gradient clipping. The research focus of this patent is to further improve the model training speed without increasing hardware resources, without manual parameter adjustment, and ensuring that the model effect remains the same. Specifically, a method based on automatic gradient clipping is adopted to ensure that the expansion of the batch data volume will not reduce the model effect, and greatly improve the model training speed and strategy iteration rate, thereby improving the timeliness and strategy iteration rate of the model. The specific results are reflected in three aspects:
[0039] 1. Rapid training speed, more agile model updates and responses. By integrating efficient data stream processing and gradient optimization mechanisms, supplemented by refined model architecture and hyperparameter tuning, this solution successfully increased the model training speed by 20 times, greatly shortened the model iteration cycle, and enhanced its ability to respond to real-time needs.
[0040] 2. The efficiency of parameter tuning has increased dramatically, and the verification process has been significantly accelerated. Before optimization, a single parameter adjustment experiment could take up to a day, but the optimization measures of this patent allow up to 20 attempts per day, greatly accelerating the model optimization process and improving the accuracy and efficiency of parameter adjustment.
[0041] 3. The timeliness of the model is significantly enhanced, and the online effect continues to rise. Thanks to the dual improvement in training speed and performance, this solution enables the model to be updated more frequently based on the latest data, maintaining a high degree of timeliness and adaptability, thereby effectively promoting the continuous optimization and improvement of model performance in online application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 The figure is a simplified flow chart of the model training acceleration method of the present invention. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] like Figure 1 As shown, an embodiment of the present invention provides a model training acceleration method based on parameter dynamics, and the steps of the model training acceleration method are:
[0045] Step 1: Read data using tfrecord and gzip compression to reduce data synchronization and serialization time; batch the data first, then perform map data mapping operations; enable concurrent reading and data preloading to take advantage of multi-threaded processing and avoid waiting for data processing to complete model training;
[0046] Step 2: Gradient update: Using clipping technology can smooth the training process and reduce the accuracy loss caused by increasing batch size; the specific steps are:
[0047] S1, data collection and preprocessing: For each training batch (batch), collect the gradients (g) corresponding to different IDs in each feature, the occurrence frequencies of these IDs (cnts), and the model parameters (w) corresponding to each ID;
[0048] S2, parameter normalization: normalize the model parameter w and calculate its norm. Here, we use TensorFlow's tf.norm(w) function to obtain the L2 norm of w, denoted as clipnorm.
[0049] S3, norm adjustment: In order to avoid the adverse effects of excessive or small clipnorm values on the subsequent clipping process, the clipnorm is dynamically adjusted;
[0050] The adjustment method is: by setting a ratio factor (ratio) and a minimum value (min_w), ensure that clipnorm is at least the larger value of ratio*clipnorm and min_w, that is, clipnorm = tf.maximum(ratio*clipnorm,min_w);
[0051] S4, frequency-weighted clipping threshold: A clipping threshold (clip_t) is calculated for each ID based on the frequency of occurrence of the ID; IDs with high frequency mean that the training data is more abundant, so their clipping threshold is also increased accordingly to reduce the clipping intensity;
[0052] Specifically, clipnorm is multiplied by frequency cnts to obtain the clipping threshold for each ID, i.e., clip_t = clipnorm*cnts;
[0053] S5, gradient normalization: Then, the L2 norm of the gradient g of each ID is calculated to obtain l2norm, that is, l2norm = tf.norm(g);
[0054] S6, calculate the final clipping threshold: combine the L2 norm of the gradient and the previously calculated clipping threshold clip_t to calculate a final clipping ratio clip for each gradient; for IDs with larger gradient norms, their clipping ratios are smaller, which means that the clipping strength is larger; and vice versa; the specific calculation is clip = l2norm / tf.maximum(l2norm,clip_t);
[0055] S7, gradient clipping: clip the original gradient g according to the final clipping ratio clip to obtain the clipped gradient g_clip, that is, g_clip = g*clip;
[0056] S8, parameter update: Finally, the clipped gradient g_clip and the preset learning rate eta are used to update the model parameter w, that is, w = w-eta*g_clip.
[0057] Among them, the TensorFlow tf.norm(w) function mentioned in S2 in step 2 is:
[0058] tf.norm(input,ord='euclidean', axis=None, keepdims=False, name=None, eps=None);
[0059] Used to calculate the norm of a tensor;
[0060] input: a Tensor representing the input data for which the norm is to be calculated;
[0061] ord: specifies the type of norm to be calculated; the default is 'euclidean', which is the L2 norm; other common values include 'fro' (Frobenius norm, only valid for two-dimensional tensors, equivalent to the L2 norm but for matrices), 'nuclear' (nuclear norm, that is, the trace norm of the matrix), or an integer n (indicating the calculation of the L^n norm);
[0062] axis: specifies the axis on which the norm is calculated; if axis is an integer, the norm is calculated on this axis; if axis is a list or tuple of integers, the norm is calculated on these axes; if axis is None (default), the norm of the entire input tensor is calculated;
[0063] keepdims: If True, the output tensor will maintain the number of dimensions of the input tensor, but its size will be 1 in the dimensions being reduced; if False (default), the output tensor will have fewer dimensions than the input tensor;
[0064] name: the name of the operation;
[0065] eps: A small floating point number used to improve numerical stability; by default this parameter is None, but in some cases (particularly when ord is a small positive number), providing a small eps value can avoid division by zero errors.
[0066] Among them, the ratio factor and the minimum value min_w are adjustable hyperparameters, which are used to optimize the gradient clipping effect according to specific task requirements.
[0067] Among them, the tfrecord data format is used to efficiently store and read large-scale data sets, and the gzip compression technology is used to reduce data storage space and transmission time.
[0068] Among them, batch processing and map operations are implemented through the TensorFlow framework to optimize the data processing process and improve the efficiency of model training.
[0069] Among them, concurrent reading and data preloading processing are implemented through TensorFlow's Dataset API to utilize multi-core CPU resources and reduce the waiting time for model training.
[0070] Among them, gradient clipping dynamically adjusts the clipping threshold to achieve different degrees of clipping of gradients of different IDs, thereby balancing the stability and accuracy during training.
[0071] Among them, the model training acceleration method is applicable to various deep learning models, including but not limited to convolutional neural networks (CNN), recurrent neural networks (RNN) and Transformer models.
[0072] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article 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, article or device.
[0073] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A model training acceleration method based on parameter dynamicization, characterized in that: The steps of the model training acceleration method are as follows: Step 1: Read data using tfrecord and gzip compression to reduce data synchronization and serialization time; batch the data first, then perform map data mapping operations; enable concurrent reading and data preloading to take advantage of multi-threaded processing and avoid waiting for data processing to complete model training; Step 2: Gradient update: Using clipping technology can smooth the training process and reduce the accuracy loss caused by increasing batch size; the specific steps are: S1, data collection and preprocessing: For each training batch (batch), collect the gradients (g) corresponding to different IDs in each feature, the occurrence frequencies of these IDs (cnts), and the model parameters (w) corresponding to each ID; S2, parameter normalization: normalize the model parameter w and calculate its norm. Here, we use TensorFlow's tf.norm(w) function to obtain the L2 norm of w, denoted as clipnorm. S3, norm adjustment: In order to avoid the adverse effects of excessive or small clipnorm values on the subsequent clipping process, the clipnorm is dynamically adjusted; The adjustment method is: by setting a ratio factor (ratio) and a minimum value (min_w), ensure that clipnorm is at least the larger value of ratio*clipnorm and min_w, that is, clipnorm = tf.maximum(ratio*clipnorm,min_w); S4, frequency-weighted clipping threshold: A clipping threshold (clip_t) is calculated for each ID based on the frequency of occurrence of the ID; IDs with high frequency mean that the training data is more abundant, so their clipping threshold is also increased accordingly to reduce the clipping intensity; Specifically, clipnorm is multiplied by frequency cnts to obtain the clipping threshold for each ID, i.e., clip_t = clipnorm*cnts; S5, gradient normalization: Then, the L2 norm of the gradient g of each ID is calculated to obtain l2norm, that is, l2norm = tf.norm(g); S6, calculate the final clipping threshold: combine the L2 norm of the gradient and the previously calculated clipping threshold clip_t to calculate a final clipping ratio clip for each gradient; for IDs with larger gradient norms, their clipping ratios are smaller, which means that the clipping strength is larger; and vice versa; the specific calculation is clip = l 2norm / tf.maximum(l2norm,clip_t); S7, gradient clipping: clip the original gradient g according to the final clipping ratio clip to obtain the clipped gradient g_clip, that is, g_clip = g*clip; S8, parameter update: Finally, the clipped gradient g_clip and the preset learning rate eta are used to update the model parameter w, that is, w = w-eta*g_clip.
2. The model training acceleration method based on parameter dynamicization according to claim 1, characterized in that: The tf.norm(w) function of TensorFlow mentioned in S2 in step 2 is: tf.norm(input, ord='euclidean', axis=None, keepdims=False, name=None, eps=None); Used to calculate the norm of a tensor; input: a Tensor representing the input data for which the norm is to be calculated; ord: specifies the type of norm to be calculated; the default is 'euclidean', which is the L2 norm; Axis: specifies the axis on which the norm is calculated; keepdims: If True, the output tensor will maintain the number of dimensions of the input tensor, but its size will be 1 in the dimensions being reduced; if False (default), the output tensor will have fewer dimensions than the input tensor; name: the name of the operation; eps: A small floating point number used to improve numerical stability; by default, this parameter is None.
3. The model training acceleration method based on parameter dynamicization according to claim 1, characterized in that: The ratio factor ratio and the minimum value min_w are adjustable hyperparameters used to optimize the gradient clipping effect according to specific task requirements.
4. The model training acceleration method based on parameter dynamicization according to claim 1, characterized in that: The tfrecord data format is used to efficiently store and read large-scale data sets, and the gzip compression technology is used to reduce data storage space and transmission time.
5. The model training acceleration method based on parameter dynamicization according to claim 1, characterized in that: The batch processing and map operations are implemented through the TensorFlow framework to optimize the data processing flow and improve the model training efficiency.
6. The model training acceleration method based on parameter dynamicization according to claim 1, characterized in that: The concurrent reading and data preloading processing is implemented through the Dataset API of TensorFlow to utilize multi-core CPU resources and reduce the waiting time of model training.
7. The model training acceleration method based on parameter dynamicization according to claim 1, characterized in that: The gradient clipping achieves different degrees of clipping of gradients of different IDs by dynamically adjusting the clipping threshold, thereby balancing the stability and accuracy during the training process.
8. The model training acceleration method based on parameter dynamicization according to claim 1, characterized in that: The model training acceleration method is applicable to various deep learning models, including but not limited to convolutional neural network (CNN), recurrent neural network (RNN), and Transformer models.
Citation Information
Cited By
Dynamic optimization system for AI model training parameters
CN120633719A
