Model training method and device, computer readable storage medium and electronic equipment
Through compression processing and parallel training of training data, combined with dynamic task adjustment, the problems of high communication overhead and low resource utilization in distributed training are solved, and the training speed and model generalization ability are improved.
Patent Information
- Application Number
- CN202410733642.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-10-01
AI Technical Summary
Existing distributed training methods have high communication overhead and low resource utilization, resulting in slow training speed and inability to meet the needs of the original large model.
By obtaining training data for compression processing, dividing it into multiple data subsets and assigning them to multiple training nodes, parallel training is performed, local model gradients are calculated and aggregated into global gradients to update model parameters, and memory and update frequency are monitored in real time for dynamic task adjustment.
It reduces the data transmission and storage load, increases the training speed, makes full use of computing resources, reduces hardware costs, and enhances the generalization ability and stability of the model.
Smart Images

Figure CN118734065A_ABST
Abstract
Description
Background Art
[0002] With the rapid development of deep learning technology, large original models have been widely used in various fields. However, the training of large original models often requires a lot of computing resources and data, and traditional single-machine training methods can no longer meet the needs. Therefore, distributed training methods have become a research hotspot.
[0003] Although existing distributed training methods can improve training speed, they also bring a lot of communication overhead.
[0004] In view of this, there is an urgent need in this field to develop a new model training method and device.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure. Summary of the invention
[0006] The purpose of the present disclosure is to provide a model training method, a model training device, a computer-readable storage medium and an electronic device, thereby overcoming the technical problem of high communication overhead caused by the limitations of related technologies at least to a certain extent.
[0007] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0008] According to a first aspect of the present disclosure, a model training method is provided, comprising:
[0009] Acquiring training data, and compressing the training data to obtain compressed training data;
[0010] Dividing the compressed training data into a plurality of data subsets, and allocating the plurality of data subsets to a plurality of training nodes;
[0011] Performing parallel training on the original large model to be trained based on the data subsets allocated to each of the multiple training nodes, and obtaining the local model gradient calculated by each of the training nodes based on the model prediction result;
[0012] A global model gradient is determined based on the multiple local model gradients, so as to update the model parameters of the original large model to be trained based on the global model gradient.
[0013] In an exemplary embodiment of the present disclosure, the acquiring of training data includes:
[0014] Get the original training data;
[0015] Preprocessing the original training data to obtain the training data;
[0016] Wherein, the preprocessing includes: data cleaning processing and format conversion processing;
[0017] The data cleaning process includes one or more of the following: deduplication processing, denoising processing, outlier removal processing and missing value filling processing.
[0018] In an exemplary embodiment of the present disclosure, compressing the training data to obtain compressed training data includes:
[0019] The training data is subjected to dictionary-based data compression processing to obtain the compressed training data.
[0020] In an exemplary embodiment of the present disclosure, performing dictionary-based data compression processing on the training data to obtain the compressed training data includes:
[0021] Performing dictionary-based data compression processing on the training data through multiple threads to obtain the compressed training data;
[0022] Alternatively, the compressed training data is obtained by performing dictionary-based data compression on the training data through multiple compression nodes.
[0023] In an exemplary embodiment of the present disclosure, the training data includes a plurality of character strings, and performing dictionary-based data compression processing on the training data to obtain the compressed training data includes:
[0024] Creating a dictionary; the dictionary is used to store the mapping relationship between each of the character strings and its specific code;
[0025] Read each character string in the training data, and retrieve whether each character string exists in the dictionary;
[0026] In response to the character string existing in the dictionary, replacing the character string with a specific code corresponding to the character string;
[0027] In response to the character string not existing in the dictionary, the character string and the specific code corresponding to the character string are added to the dictionary, and the character string is replaced with the specific code corresponding to the character string.
[0028] In an exemplary embodiment of the present disclosure, the local model gradient is calculated in the following manner:
[0029] By each of the training nodes training the original large model based on the allocated data subset, a model prediction result output by the original large model is obtained;
[0030] Determining a model loss value according to the degree of difference between the model prediction result and the annotation label;
[0031] The back-propagation algorithm is used to calculate the local model gradient of the model loss value relative to the model parameters.
[0032] In an exemplary embodiment of the present disclosure, the local model gradient is calculated in the following manner:
[0033] After dividing the compressed training data into a plurality of data subsets, dividing the model parameters to be trained into a plurality of parameter subsets;
[0034] assigning the plurality of data subsets to the plurality of training nodes, and assigning the plurality of parameter subsets to the plurality of training nodes;
[0035] By each of the training nodes training the original large model based on the allocated data subset, a model prediction result output by the original large model is obtained;
[0036] Determine the model loss value according to the difference between the model prediction result and the annotation label;
[0037] The back propagation algorithm is used to calculate the local model gradient of the model loss value relative to the partial model parameters in the assigned parameter subset.
[0038] In an exemplary embodiment of the present disclosure, determining the global model gradient according to the plurality of local model gradients comprises:
[0039] The local model gradients corresponding to the multiple training nodes are aggregated to obtain the global model gradient.
[0040] In an exemplary embodiment of the present disclosure, after updating the model parameters of the original large model according to the global model gradient, the method further includes:
[0041] The updated model parameters are broadcast to each of the training nodes.
[0042] In an exemplary embodiment of the present disclosure, the method further includes:
[0043] During the model training process, the memory usage index of each training node is monitored in real time;
[0044] When the memory usage index exceeds a preset index threshold, the training task associated with the training node is transferred to other training nodes.
[0045] In an exemplary embodiment of the present disclosure, the method further includes:
[0046] During the model training process, counting the update frequency of each of the model parameters;
[0047] When the training progress reaches a preset progress threshold, obtaining target model parameters whose update frequency is lower than a preset frequency threshold;
[0048] Transferring the training task associated with the target model parameter to a target training node;
[0049] The target training node is a training node whose load value is lower than a preset load value.
[0050] According to a second aspect of the present disclosure, a model training device is provided, comprising:
[0051] A data processing module, used to obtain training data and compress the training data to obtain compressed training data;
[0052] A data distribution module, used for dividing the compressed training data into a plurality of data subsets, and distributing the plurality of data subsets to a plurality of training nodes;
[0053] A parallel training module, used to perform parallel training on the original large model to be trained based on the data subsets allocated to each of the multiple training nodes, and obtain the local model gradient calculated by each of the training nodes based on the model prediction result;
[0054] A parameter updating module is used to determine a global model gradient based on a plurality of local model gradients, so as to update the model parameters of the original large model to be trained according to the global model gradient.
[0055] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the model training method described in the first aspect is implemented.
[0056] According to a fourth aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the model training method described in the first aspect above by executing the executable instructions.
[0057] It can be seen from the above technical solutions that the model training method, model training device, computer-readable storage medium and electronic device in the exemplary embodiments of the present disclosure have at least the following advantages and positive effects:
[0058] In the technical solutions provided by some embodiments of the present disclosure, on the one hand, the present disclosure obtains training data and compresses the training data to obtain compressed training data, thereby reducing the load of data transmission and storage, accelerating the processing speed of training data, and significantly reducing the communication overhead of nodes in subsequent training processes; further, by dividing the compressed training data into multiple data subsets and allocating the multiple data subsets to multiple training nodes, the computing resources of multiple training nodes can be fully utilized, the processing time required for single-node processing is reduced, the hardware cost of training is reduced, the training speed of the model is improved, and the model development cycle is shortened; on the other hand, multiple training nodes are used to perform parallel training on the original large model to be trained based on their respective allocated data subsets, and the local model gradient calculated by each training node based on the model prediction result is obtained, and the global model gradient is determined according to the multiple local model gradients, so as to update the model parameters of the original large model to be trained according to the global model gradient, so that the model can be exposed to more diverse data samples, thereby enhancing the generalization ability of the model and making its performance on new data more stable and reliable.
[0059] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0061] Figure 1 A schematic diagram showing a flow chart of a model training method in an embodiment of the present disclosure;
[0062] Figure 2 A schematic diagram showing a flow chart of how to obtain training data in an embodiment of the present disclosure;
[0063] Figure 3 A flowchart showing how to perform dictionary-based data compression processing on training data to obtain compressed training data in an embodiment of the present disclosure;
[0064] Figure 4 A schematic diagram of a process for obtaining compressed training data in an embodiment of the present disclosure is shown;
[0065] Figure 5 A schematic diagram showing a flow chart of how to compress training data in an embodiment of the present disclosure;
[0066] Figure 6A schematic diagram showing a flow chart of how to divide model parameters in an embodiment of the present disclosure;
[0067] Figure 7 The overall flow chart of the model training method in the embodiment of the present disclosure is shown;
[0068] Figure 8 A schematic diagram showing the structure of a model training device in an exemplary embodiment of the present disclosure is shown;
[0069] Fig. 9 A schematic structural diagram of an electronic device in an exemplary embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0070] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0071] The terms "a", "an", "the" and "said" are used in this specification to indicate the presence of one or more elements / components / etc.; the terms "including" and "having" are used to express an open-ended inclusion and mean that additional elements / components / etc. may exist in addition to the listed elements / components / etc.; the terms "first" and "second" etc. are used only as labels and are not intended to limit the quantity of their objects.
[0072] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings represent the same or similar parts, and their repeated descriptions will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities.
[0073] The existing distributed training methods mainly include data parallelism, model parallelism and hybrid parallelism. Among them, data parallelism is to divide the training data into multiple subsets and train them in parallel on multiple training nodes; model parallelism is to divide the model parameters into multiple subsets and train them in parallel on multiple training nodes; hybrid parallelism is to combine data parallelism and model parallelism.
[0074] However, the above solution has at least the following problems:
[0075] High communication overhead: Training data and model parameters are often huge in size. During distributed training, they need to be transmitted between multiple training nodes, resulting in a large amount of communication overhead (i.e., high data transmission costs and heavy communication burden). Communication overhead affects the training speed, especially for the original large model training, where communication overhead becomes a bottleneck.
[0076] Low resource utilization: In traditional distributed training methods, each training node needs to store the entire model parameters, which may lead to problems such as insufficient video memory. In addition, during the training process, not all training nodes are always at full capacity, which leads to low resource utilization;
[0077] Slow training speed: Due to high communication overhead and low resource utilization, existing distributed raw large model training methods are often slow to train.
[0078] The present disclosure proposes a distributed original large model training method based on data compression and parallel communication. Based on the scheme in the present disclosure, the communication overhead can be effectively reduced and the training speed can be improved.
[0079] In the embodiments of the present disclosure, a model training method is first provided, which at least to some extent overcomes the defect of high communication overhead in the related art.
[0080] Figure 1 A flow chart of a model training method in an embodiment of the present disclosure is shown, and the executor of the model training method may be a server that performs model training.
[0081] refer to Figure 1 According to an embodiment of the present invention, the model training method comprises the following steps:
[0082] Step S110, obtaining training data, and compressing the training data to obtain compressed training data;
[0083] Step S120, dividing the compressed training data into a plurality of data subsets, and allocating the plurality of data subsets to a plurality of training nodes;
[0084] Step S130, performing parallel training on the original large model to be trained based on the data subsets allocated to each of the multiple training nodes, and obtaining the local model gradient calculated by each training node based on the model prediction result;
[0085] Step S140, determining a global model gradient based on multiple local model gradients, so as to update the model parameters of the original large model to be trained according to the global model gradient.
[0086] exist Figure 1 In the technical solution provided by the illustrated embodiment, on the one hand, the present disclosure obtains training data and compresses the training data to obtain compressed training data, thereby reducing the load of data transmission and storage, accelerating the processing speed of training data, and significantly reducing the communication overhead of nodes in the subsequent training process; further, by dividing the compressed training data into multiple data subsets and allocating the multiple data subsets to multiple training nodes, the computing resources of multiple training nodes can be fully utilized, the processing time required for single-node processing is reduced, the hardware cost of training is reduced, the training speed of the model is improved, and the model development cycle is shortened; on the other hand, multiple training nodes are used to perform parallel training on the original large model to be trained based on their respective allocated data subsets, and the local model gradient calculated by each training node based on the model prediction result is obtained, and the global model gradient is determined according to the multiple local model gradients, so as to update the model parameters of the original large model to be trained according to the global model gradient, so that the model can be exposed to more diverse data samples, thereby enhancing the generalization ability of the model and making its performance on new data more stable and reliable.
[0087] The following Figure 1 The specific implementation process of each step is described in detail:
[0088] In step S110, training data is acquired and compressed to obtain compressed training data.
[0089] In this step, first, you can obtain training data. Training data refers to a set of information used to allow algorithms or models to learn and extract regularities in the process of machine learning, deep learning, and statistical modeling. Simply put, this is the data used by the model to "learn" before formal application. These data usually contain input features (independent variables) and corresponding output labels (dependent variables) or results. The model learns a mapping function or decision boundary by analyzing the relationship between input features and output results, so that it can predict or classify the correct output when faced with new, unseen data.
[0090] After the training data is acquired, the training data may be compressed to obtain compressed training data.
[0091] First, refer to Figure 2 , Figure 2 A flowchart showing how to obtain training data in an embodiment of the present disclosure includes steps S201 and S202:
[0092] In step S201, original training data is obtained.
[0093] In this step, original training data may be obtained from a data source, where the original training data is training data before being processed.
[0094] In step S202, the original training data is preprocessed to obtain training data.
[0095] In this step, the original training data may be preprocessed to obtain training data.
[0096] Exemplarily, the above-mentioned preprocessing may include: data cleaning processing (which is a key step in the preprocessing stage of data analysis and machine learning, aimed at improving data quality and ensuring the effectiveness of subsequent analysis) and format conversion processing (i.e., after data cleaning, converting the cleaned data into a format suitable for training).
[0097] The data cleaning process includes one or more of the following:
[0098] Deduplication: Deduplication refers to identifying and removing identical records or rows from a data set to avoid biasing analysis results due to duplicate data. Duplicate data can be caused by errors in the data collection process or multiple entries. Deduplication can be achieved by comparing all fields of the record or specific key fields to ensure that each item in the data set is unique.
[0099] Denoising: Denoising involves identifying and correcting erroneous or inaccurate information in the data, which is often referred to as "noise". Noise can come from measurement errors, input errors, data transmission errors, etc. Denoising can be done by setting reasonable thresholds to filter out extreme values, or using signal processing, smoothing techniques, data filtering and other methods to reduce random errors and inconsistencies, making the data closer to its true value.
[0100] Outlier removal: Outliers are values that are significantly different from other observations in the data set. They may be caused by measurement errors, data entry errors, or other atypical events. Outlier removal includes identifying these values and deciding whether to remove them from the data set or adjust them in some way. Common methods include statistical-based methods (such as IQR, Z-score) or model-based methods to identify outliers and decide on the processing strategy based on the purpose of the analysis.
[0101] Missing value filling: Missing values refer to some entries in the data set that should have values but are actually empty or unrecorded. Ways to handle missing values include directly deleting records or columns with missing values (but this may result in information loss), filling missing values with a fixed value (such as mean, median, mode), using model prediction (such as K nearest neighbor, regression model) to estimate missing values, or using advanced statistical methods such as multiple imputation to generate possible filling values. The method you choose depends on the proportion of missing values, the cause of missing values, and the characteristics of the data.
[0102] After data cleaning and format conversion to obtain training data, the present disclosure can compress the training data to obtain compressed training data. Specifically, the present disclosure can perform dictionary-based data compression on the training data to obtain compressed training data. The dictionary-based data compression can be an LZW compression algorithm (short for Lempel-Ziv-Welch compression), which is a dictionary-based lossless data compression method.
[0103] Exemplary, reference Figure 3 , Figure 3 A flowchart showing how to perform dictionary-based data compression processing on training data to obtain compressed training data in an embodiment of the present disclosure includes steps S301 to S304:
[0104] In step S301 , a dictionary is created.
[0105] In this step, a dictionary may be created, that is, a mapping table between a string and its specific code (encoding value) may be constructed, so that the dictionary stores a mapping relationship between each string and its specific code.
[0106] In step S302, each character string in the training data is read, and it is searched whether each character string exists in the dictionary.
[0107] In this step, you can read each string in the training data and check whether each string exists in the dictionary.
[0108] In step S303, in response to the character string existing in the dictionary, the character string is replaced with a specific code corresponding to the character string.
[0109] In this step, if the retrieved character string is in the dictionary, the character string can be replaced with a specific code corresponding to the character string to achieve compression of the character string.
[0110] In step S304, in response to the character string not existing in the dictionary, the character string and the specific code corresponding to the character string are added to the dictionary, and the character string is replaced with the specific code corresponding to the character string.
[0111] In this step, if the string does not exist in the dictionary, the string can be used as a new entry and a specific code can be created for the string. After that, the string and its corresponding specific code can be added to the dictionary, and the string can be replaced with the specific code corresponding to the string to achieve compression of the string.
[0112] After all character strings included in the training data are compressed, compressed training data can be obtained.
[0113] It should be noted that, when performing dictionary-based data compression processing on training data, in order to improve compression speed and compression efficiency, in an optional implementation, the present disclosure may perform dictionary-based data compression processing on training data through multiple threads to obtain compressed training data. In another optional implementation, the present disclosure may perform dictionary-based data compression processing on training data in a distributed manner through multiple compression nodes to obtain compressed training data.
[0114] Data compression is one of the key technologies to reduce the communication overhead of distributed large model training. The traditional serial compression method will lead to low data compression efficiency and affect the training speed. However, the parallel compression method adopted in the present disclosure can significantly improve the data compression efficiency and greatly reduce the communication overhead.
[0115] refer to Figure 4 , Figure 4 A schematic diagram of a process for obtaining compressed training data in an embodiment of the present disclosure is shown, including steps S401 to S405:
[0116] In step S401, data collection, i.e. obtaining original training data from various data sources;
[0117] In step S402, data cleaning is performed, that is, the original training data is cleaned, such as removing noise, outliers, missing values, etc.;
[0118] In step S403, data conversion is performed, that is, the cleaned training data is converted into a format suitable for training;
[0119] In step S404, data compression is performed, i.e., the training data is compressed using a parallel compression method, which greatly reduces communication overhead;
[0120] In step S405, the data is stored, that is, the compressed training data set is stored in a distributed file system.
[0121] refer to Figure 5 , Figure 5 A flow chart showing how to compress training data in an embodiment of the present disclosure includes steps S501 to S505:
[0122] In step S501, start;
[0123] In step S502, a dictionary is created;
[0124] In step S503, it is detected whether each character string in the training data exists in the dictionary;
[0125] If not, add the string and the unique code corresponding to the string to the dictionary;
[0126] If yes, then proceed to step S504, retrieve the code corresponding to the string from the dictionary, replace the string with the code and output it;
[0127] In step S505, end.
[0128] After obtaining the compressed training data, you can then refer to Figure 1 In step S120, the compressed training data is divided into multiple data subsets, and the multiple data subsets are allocated to multiple training nodes.
[0129] In this step, the compressed training data may be divided into a plurality of data subsets, and then the plurality of data subsets may be assigned to a plurality of training nodes. For example, assuming that the compressed training data is divided into 10 (which may be set according to actual conditions, and the present disclosure does not make any special restrictions on this) data subsets, each data subset may be assigned to a training node; or, every two data subsets may be assigned to a training node, which may be set according to actual conditions, and the present disclosure does not make any special restrictions on this.
[0130] By dividing the compressed training data into multiple data subsets, the computing resources of multiple training nodes can be fully utilized, thereby improving the training speed.
[0131] In an optional embodiment, after dividing the compressed training data into multiple data subsets, the present disclosure may also divide the model parameters to be trained into multiple parameter subsets, and then the multiple data subsets may be assigned to multiple training nodes (for example: 10 data subsets are assigned to 10 training nodes), and the multiple parameter subsets may be assigned to multiple training nodes (for example: 10 parameter subsets are assigned to 10 training nodes).
[0132] refer to Figure 6 , Figure 6 A flow chart showing how to divide model parameters in an embodiment of the present disclosure includes steps S601 to S604:
[0133] In step S601, start;
[0134] In step S602, model parameters are loaded from the storage environment;
[0135] In step S603, the model parameters are divided into a plurality of parameter subsets (i.e., parameter subset 1, parameter subset 2, ..., parameter subset n);
[0136] In step S604, each divided parameter subset is copied to each corresponding training node (ie, Node1, Node2, ..., Noden).
[0137] Next reference Figure 1 In step S130, the original large model to be trained is trained in parallel by multiple training nodes based on the data subsets allocated to them respectively, and the local model gradient calculated by each training node based on the model prediction result is obtained.
[0138] In this step, referring to the relevant explanations of the above steps, if the present disclosure only divides the training data into multiple data subsets but does not divide the model parameters into multiple parameter subsets, then when executing this step, the local model gradient can be determined in the following way: each computing node training node trains the original large model based on the assigned data subset to obtain the model prediction result output by the original large model. After that, the model loss value can be determined according to the degree of difference between the model prediction result and the annotation label, and the local model gradient of the model loss value relative to the model parameters is calculated using the back propagation algorithm, that is, each computing node can calculate a local model gradient.
[0139] If the present disclosure divides the training data into multiple data subsets and divides the model parameters into multiple parameter subsets, then when executing this step, the local model gradient can be determined in the following way: each training node trains the original large model based on the assigned data subset to obtain the model prediction result output by the original large model; the model loss value is determined according to the difference between the model prediction result and the annotation label; and the back propagation algorithm is used to calculate the local model gradient of the model loss value relative to the part of the model parameters in the assigned parameter subset (that is, the part of the model parameters assigned to each computing node, not all the model parameters).
[0140] Among them, the model loss value quantifies the inconsistency or degree of error between the model's predicted output and the actual target value. Specifically, the loss value is calculated by a mathematical formula called a loss function or cost function. The loss function compares the model's prediction result on a given data point with the true label of the data point, and then outputs a non-negative real value based on the size of the difference between the two. The smaller the loss value, the closer the model's prediction is to the actual result and the better the model's performance; conversely, if the loss value is large, it means that there is a large error in the model prediction.
[0141] Local model gradient refers to the gradient of the loss function for a specific point (usually a point in the parameter space or a sample point in the data set) in machine learning or deep learning. The gradient is a vector that indicates the direction in which the directional derivative of the function at that point reaches the maximum value, as well as the magnitude of the maximum rate of change. In other words, it indicates the direction in which the function value increases fastest and the speed of increase.
[0142] In step S140, a global model gradient is determined based on a plurality of local model gradients, so as to update the model parameters of the original large model to be trained based on the global model gradient.
[0143] In this step, each training node can use All-Reduce (aggregate multiple local model gradients calculated by all nodes to the parameter server) or tree aggregation (organize the nodes in layers and use a tree structure to aggregate multiple local model gradients to the parameter server) to transmit the calculated local model gradients in parallel to the parameter server, so that the parameter server can determine the global model gradient.
[0144] After the global model gradient is determined, the model parameters of the original large model to be trained can be updated according to the global model gradient to iteratively train the original large model to be trained.
[0145] It should be noted that, in the model training process of the present disclosure, the training tasks corresponding to each training node can also be adjusted according to the dynamic adjustment strategy. Specifically:
[0146] In an optional implementation, the training tasks can be adjusted according to the memory usage index of each training node. Specifically, the memory usage index (for example, memory usage rate) of each training node can be monitored in real time during the model training process. When the memory usage index exceeds a preset index threshold (for example, 80%, which can be set according to actual conditions and is not specifically limited in the present disclosure), the training tasks associated with the training node are transferred to other training nodes (for example, other training nodes that are not assigned training tasks, or other training nodes whose memory usage rate is less than the preset usage rate).
[0147] In another optional implementation, the training tasks can be adjusted according to the training progress. Specifically, during the model training process, the update frequency of each model parameter can be counted. When the training progress reaches a preset progress threshold (for example, 70%, which can be set according to actual conditions and is not specifically limited in the present disclosure), the target model parameters with an update frequency lower than the preset frequency threshold are obtained (the lower the update frequency, the closer the parameters tend to fit, and thus, the importance of the parameters gradually decreases), and the training tasks associated with the target model parameters are transferred to the target training nodes with lower load (which can be training nodes with load values lower than the preset load values).
[0148] The load value refers to the amount of tasks or workload that the training node is processing. Specifically, the load value of the training node can be measured based on any one or more of the following factors:
[0149] Allocation of training tasks: During model training, the load may involve the number of training tasks allocated to each training node. For example, in deep learning training, operations such as parameter gradient calculation and parameter update will consume computing resources;
[0150] Resource usage: Load also reflects the usage of the training node, including CPU usage, memory usage, disk I / O operations, and network communication bandwidth. High load means that the node is close to or has reached the upper limit of its processing capacity;
[0151] Energy consumption or heat management: In large-scale data centers, highly loaded training nodes may consume more energy and generate more heat, which requires more efficient cooling systems to maintain normal operating temperatures.
[0152] refer to Figure 7 , Figure 7 The overall flow chart of the model training method in the embodiment of the present disclosure is shown as follows: Figure 7 As shown:
[0153] The model training process can involve multiple training nodes, which can be divided into a master node and multiple computing nodes;
[0154] First, in the data parallel stage, the training data can be divided into multiple subsets (Batch0, Batch1, ..., Batchn), and each subset is assigned to a training node. For example, the master node is assigned Batch0, and multiple computing nodes are assigned Batch1, ..., Batchn.
[0155] During the model training phase, each computing node outputs the model prediction results, and the master node summarizes the model prediction results;
[0156] In the model gradient calculation phase, each computing node calculates the loss, and the master node summarizes the loss;
[0157] In the gradient parallel stage, each computing node calculates the local model gradient according to the loss, and the master node aggregates the local model gradients to determine the global model gradient;
[0158] In the parameter update phase, the master node updates the model parameters according to the global model gradient;
[0159] In the parameter broadcast phase, the master node collects the updated model parameters and distributes them to each computing node, and each computing node updates the model parameters.
[0160] In general, the present disclosure effectively reduces the communication overhead in the distributed original large model training and improves the training speed through technologies such as data compression, model parameter partitioning, and parallel training. It has significant advantages and strengths, specifically:
[0161] First, in terms of data compression, the traditional serial compression method leads to low data compression efficiency, which affects the training speed; while the present disclosure adopts a parallel compression method, including multi-threaded compression and distributed compression, which can significantly improve data compression efficiency and greatly reduce communication overhead;
[0162] Secondly, in terms of data partitioning, the traditional static partitioning strategy will lead to uneven resource utilization and low training efficiency; while the present invention adopts a dynamic adjustment strategy, including adjustment based on video memory occupancy and adjustment based on training progress, which can effectively improve resource utilization, reduce training costs, and improve training efficiency.
[0163] Thirdly, in terms of parallel training, the traditional parallel training method has high communication overhead, which affects the training speed; while the present disclosure adopts multiple parallel strategies such as data parallelism, hybrid parallelism, pipeline parallelism, and adopts multiple gradient parallel methods such as All-Reduce and tree aggregation, which can effectively reduce communication overhead and improve training speed;
[0164] Thus, illustratively, the present disclosure can be applied in the field of scientific research, effectively reducing the communication overhead in the distributed original large model training, improving the training speed, and thus accelerating the progress of scientific research. Exemplarily, the present disclosure can also be applied in the field of industrial production to improve the efficiency of distributed original large model training, thereby providing more powerful data analysis capabilities for industrial production. Optionally, the present disclosure can also be applied to a wide range of fields such as large model training, distributed computing, and cloud computing, which can be set according to actual conditions, and the present disclosure does not make any special limitations on this.
[0165] The present disclosure also provides a model training device, Figure 8 A schematic diagram of the structure of a model training device in an exemplary embodiment of the present disclosure is shown; Figure 8 As shown, the model training device 800 may include a data processing module 810, a data allocation module 820, a parallel training module 830 and a parameter updating module 840. Among them:
[0166] The data processing module 810 is used to obtain training data and compress the training data to obtain compressed training data;
[0167] A data distribution module 820 is used to divide the compressed training data into multiple data subsets and distribute the multiple data subsets to multiple training nodes;
[0168] A parallel training module 830 is used to perform parallel training on the original large model to be trained based on the data subsets allocated to each of the multiple training nodes, and obtain the local model gradient calculated by each of the training nodes based on the model prediction result;
[0169] The parameter updating module 840 is used to determine the global model gradient according to the multiple local model gradients, so as to update the model parameters of the original large model to be trained according to the global model gradient.
[0170] In an exemplary embodiment of the present disclosure, the data processing module 810 acquires training data, including:
[0171] Get the original training data;
[0172] Preprocessing the original training data to obtain the training data;
[0173] Wherein, the preprocessing includes: data cleaning processing and format conversion processing;
[0174] The data cleaning process includes one or more of the following: deduplication processing, denoising processing, outlier removal processing and missing value filling processing.
[0175] In an exemplary embodiment of the present disclosure, the data processing module 810 compresses the training data to obtain compressed training data, including:
[0176] The training data is subjected to dictionary-based data compression processing to obtain the compressed training data.
[0177] In an exemplary embodiment of the present disclosure, the data processing module 810 performs dictionary-based data compression processing on the training data to obtain the compressed training data, including:
[0178] Performing dictionary-based data compression processing on the training data through multiple threads to obtain the compressed training data;
[0179] Alternatively, the compressed training data is obtained by performing dictionary-based data compression on the training data through multiple compression nodes.
[0180] In an exemplary embodiment of the present disclosure, the training data includes a plurality of character strings, and the data processing module 810 performs dictionary-based data compression processing on the training data to obtain the compressed training data, including:
[0181] Creating a dictionary; the dictionary is used to store the mapping relationship between each of the character strings and its specific code;
[0182] Read each character string in the training data, and retrieve whether each character string exists in the dictionary;
[0183] In response to the character string existing in the dictionary, replacing the character string with a specific code corresponding to the character string;
[0184] In response to the character string not existing in the dictionary, the character string and the specific code corresponding to the character string are added to the dictionary, and the character string is replaced with the specific code corresponding to the character string.
[0185] In an exemplary embodiment of the present disclosure, the local model gradient is calculated in the following manner:
[0186] By each of the training nodes training the original large model based on the allocated data subset, a model prediction result output by the original large model is obtained;
[0187] Determining a model loss value according to the degree of difference between the model prediction result and the annotation label;
[0188] The back-propagation algorithm is used to calculate the local model gradient of the model loss value relative to the model parameters.
[0189] In an exemplary embodiment of the present disclosure, the local model gradient is calculated in the following manner:
[0190] After dividing the compressed training data into a plurality of data subsets, dividing the model parameters to be trained into a plurality of parameter subsets;
[0191] assigning the plurality of data subsets to the plurality of training nodes, and assigning the plurality of parameter subsets to the plurality of training nodes;
[0192] By each of the training nodes training the original large model based on the allocated data subset, a model prediction result output by the original large model is obtained;
[0193] Determine the model loss value according to the difference between the model prediction result and the annotation label;
[0194] The back propagation algorithm is used to calculate the local model gradient of the model loss value relative to the partial model parameters in the assigned parameter subset.
[0195] In an exemplary embodiment of the present disclosure, the parameter updating module 840 determines the global model gradient according to the multiple local model gradients, including:
[0196] The local model gradients corresponding to the multiple training nodes are aggregated to obtain the global model gradient.
[0197] In an exemplary embodiment of the present disclosure, after updating the model parameters of the original large model according to the global model gradient, the parameter updating module 840 is configured to:
[0198] The updated model parameters are broadcast to each of the training nodes.
[0199] In an exemplary embodiment of the present disclosure, the parallel training module 830 is configured as follows:
[0200] During the model training process, the memory usage index of each training node is monitored in real time;
[0201] When the memory usage index exceeds a preset index threshold, the training task associated with the training node is transferred to other training nodes.
[0202] In an exemplary embodiment of the present disclosure, the parallel training module 830 is configured as follows:
[0203] During the model training process, counting the update frequency of each of the model parameters;
[0204] When the training progress reaches a preset progress threshold, obtaining target model parameters whose update frequency is lower than a preset frequency threshold;
[0205] Transferring the training task associated with the target model parameter to a target training node;
[0206] The target training node is a training node whose load value is lower than a preset load value.
[0207] The specific details of each module in the above-mentioned model training device have been described in detail in the corresponding model training method, so they will not be repeated here.
[0208] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0209] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0210] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0211] The present disclosure also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or may exist independently without being assembled into the electronic device.
[0212] The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0213] Computer-readable storage media can send, propagate or transmit programs for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable storage medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0214] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiments.
[0215] In addition, an electronic device capable of implementing the above method is also provided in an embodiment of the present disclosure.
[0216] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware implementation, complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0217] Refer to the following Fig. 9 The electronic device 900 according to this embodiment of the present disclosure is described. Fig. 9 The electronic device 900 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0218] like Fig. 9 As shown, the electronic device 900 is in the form of a general computing device. The components of the electronic device 900 may include, but are not limited to: at least one processor 910, at least one memory 920, a bus 930 connecting different system components (including the memory 920 and the processor 910), and a display 940.
[0219] The memory stores program codes, which can be executed by the processor 910, so that the processor 910 performs the steps according to various exemplary embodiments of the present disclosure described in the above “Exemplary Method” section of this specification. For example, the processor 910 can perform the following steps: Figure 1As shown in: Step S110, obtaining training data, and compressing the training data to obtain compressed training data; Step S120, dividing the compressed training data into multiple data subsets, and allocating the multiple data subsets to multiple training nodes; Step S130, performing parallel training on the original large model to be trained based on the respective allocated data subsets through the multiple training nodes, and obtaining the local model gradient calculated by each training node based on the model prediction result; Step S140, determining the global model gradient according to the multiple local model gradients, so as to update the model parameters of the original large model to be trained according to the global model gradient.
[0220] The memory 920 may include a readable medium in the form of a volatile storage, such as a random access memory (RAM) 9201 and / or a cache memory 9202 , and may further include a read-only memory (ROM) 9203 .
[0221] The memory 920 may also include a program / utility 9204 having a set (at least one) of program modules 9205, such program modules 9205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0222] Bus 930 may be a bus representing one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures.
[0223] The electronic device 900 may also communicate with one or more external devices 1000 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 900, and / or communicate with any device that enables the electronic device 900 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 950. In addition, the electronic device 900 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 960. As shown, the network adapter 960 communicates with other modules of the electronic device 900 via a bus 930. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 900, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0224] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
Claims
1. A model training method, characterized in that: include: Acquiring training data, and compressing the training data to obtain compressed training data; Dividing the compressed training data into a plurality of data subsets, and allocating the plurality of data subsets to a plurality of training nodes; Performing parallel training on the original large model to be trained based on the data subsets allocated to each of the multiple training nodes, and obtaining the local model gradient calculated by each of the training nodes based on the model prediction result; A global model gradient is determined based on the multiple local model gradients, so as to update the model parameters of the original large model to be trained based on the global model gradient.
2. The method according to claim 1, characterized in that The obtaining of training data comprises: Get the original training data; Preprocessing the original training data to obtain the training data; Wherein, the preprocessing includes: data cleaning processing and format conversion processing; The data cleaning process includes one or more of the following: deduplication processing, denoising processing, outlier removal processing and missing value filling processing.
3. The method according to claim 1, characterized in that The compressing the training data to obtain compressed training data includes: The training data is subjected to dictionary-based data compression processing to obtain the compressed training data.
4. The method according to claim 3, characterized in that The performing dictionary-based data compression processing on the training data to obtain the compressed training data includes: Performing dictionary-based data compression processing on the training data through multiple threads to obtain the compressed training data; Alternatively, the compressed training data is obtained by performing dictionary-based data compression on the training data through multiple compression nodes.
5. The method according to claim 3, characterized in that: The training data includes a plurality of character strings, and the step of performing dictionary-based data compression processing on the training data to obtain the compressed training data includes: Creating a dictionary; the dictionary is used to store the mapping relationship between each of the character strings and its specific code; Read each character string in the training data, and retrieve whether each character string exists in the dictionary; In response to the character string existing in the dictionary, replacing the character string with a specific code corresponding to the character string; In response to the character string not existing in the dictionary, the character string and the specific code corresponding to the character string are added to the dictionary, and the character string is replaced with the specific code corresponding to the character string.
6. The method according to claim 1, characterized in that The local model gradient is calculated in the following way: By each of the training nodes training the original large model based on the allocated data subset, a model prediction result output by the original large model is obtained; Determining a model loss value according to the degree of difference between the model prediction result and the annotation label; The back-propagation algorithm is used to calculate the local model gradient of the model loss value relative to the model parameters.
7. The method according to claim 1, characterized in that The local model gradient is calculated in the following way: After dividing the compressed training data into a plurality of data subsets, dividing the model parameters to be trained into a plurality of parameter subsets; assigning the plurality of data subsets to the plurality of training nodes, and assigning the plurality of parameter subsets to the plurality of training nodes; By each of the training nodes training the original large model based on the allocated data subset, a model prediction result output by the original large model is obtained; Determine the model loss value according to the difference between the model prediction result and the annotation label; The back propagation algorithm is used to calculate the local model gradient of the model loss value relative to the partial model parameters in the assigned parameter subset.
8. The method according to any one of claims 1 to 7, characterized in that: Determining the global model gradient according to the multiple local model gradients includes: The local model gradients corresponding to the multiple training nodes are aggregated to obtain the global model gradient.
9. The method according to claim 8, characterized in that After updating the model parameters of the original large model according to the global model gradient, the method further includes: The updated model parameters are broadcast to each of the training nodes.
10. The method according to claim 1, characterized in that The method further comprises: During the model training process, the memory usage index of each training node is monitored in real time; When the memory usage index exceeds a preset index threshold, the training task associated with the training node is transferred to other training nodes.
11. The method according to claim 1, characterized in that: The method further comprises: During the model training process, counting the update frequency of each of the model parameters; When the training progress reaches a preset progress threshold, obtaining target model parameters whose update frequency is lower than a preset frequency threshold; Transferring the training task associated with the target model parameter to a target training node; The target training node is a training node whose load value is lower than a preset load value.
12. A model training device, characterized in that: include: A data processing module, used to obtain training data and compress the training data to obtain compressed training data; A data distribution module, used for dividing the compressed training data into a plurality of data subsets, and distributing the plurality of data subsets to a plurality of training nodes; A parallel training module, used to perform parallel training on the original large model to be trained based on the data subsets allocated to each of the multiple training nodes, and obtain the local model gradient calculated by each of the training nodes based on the model prediction result; A parameter updating module is used to determine a global model gradient based on a plurality of local model gradients, so as to update the model parameters of the original large model to be trained according to the global model gradient.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the model training method described in any one of claims 1 to 11 is implemented.
14. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; Wherein, the processor is configured to execute the model training method described in any one of claims 1 to 11 by executing the executable instructions.
Citation Information
Cited By
Distributed training method and device, equipment and storage medium
CN122154848A
