A model training method and related apparatus

By employing a multi-GPU parallel training and waiting mechanism, the problem of long training time for deep learning models is solved, enabling fast and high-precision model training, which is suitable for applications such as content recommendation.

CN117011564BActive Publication Date: 2026-04-14TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-26
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Training deep learning models is time-consuming; in a single-machine setup, training typically takes several days or even a week, which cannot meet the time requirements of users.

Method used

The method of parallel training using multiple graphics processors allows for a difference between the amount of sub-training data and the amount of training data. A waiting mechanism ensures that all graphics processors complete gradient calculations before parameter updates, avoiding data discard and improving training speed and accuracy.

Benefits of technology

In a standalone environment, it significantly shortens model training time, improves model training speed and accuracy, and meets users' content recommendation time requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117011564B_ABST
    Figure CN117011564B_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a model training method and related device, and relates to machine learning. The method comprises the following steps: obtaining a training data set with classification labels; obtaining target training data for the i-th round of training by sampling; and processing equipment comprising N image processors. The target training data is divided into N sub-training data, and the N sub-training data and the N image processors correspond to each other. At least two of the N sub-training data have a data quantity difference value, and / or at least two of the N sub-training data have a training data quantity difference value. Then, the N sub-training data are classified and predicted by the N image processors. N gradients corresponding to the N sub-training data are calculated based on the corresponding classification labels. When the image processors complete the gradient calculation, corresponding completion identifiers are generated. When the number of the completion identifiers is N, the N gradients are integrated, the initial classification model is updated for the i-th round of parameters, and a classification model is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence, and in particular to model training methods and related apparatus. Background Technology

[0002] Deep learning models can be used in various applications to recommend content based on user behavior and habits. However, training deep learning models is very time-consuming. Furthermore, due to cost considerations, deep models are typically trained on a single machine.

[0003] Typically, in a standalone environment, it can take several days or even a week to train a deep learning model that meets user needs.

[0004] Therefore, there is an urgent need for a model training method with faster training speed. Summary of the Invention

[0005] To address the aforementioned technical problems, this application provides a model training method and related apparatus that can quickly complete model training in a standalone mode.

[0006] The embodiments of this application disclose the following technical solutions:

[0007] On the one hand, embodiments of this application provide a model training method, the method comprising:

[0008] A training data set is obtained for training an initial classification model in a processing device, wherein the training data in the training data set has classification labels, and the processing device includes N graphics processors, where N>1;

[0009] Target training data for the i-th round of model training is obtained by sampling from the training data set;

[0010] For the N graphics processors, the target training data is divided into N sub-training data, each of the N sub-training data and the N graphics processors is one-to-one, and at least two of the N sub-training data have a difference in the amount of data, and / or at least two of the N sub-training data have a difference in the number of training data.

[0011] The N graphics processors perform classification prediction on the N sub-training data, and calculate N gradients corresponding to the N sub-training data based on the corresponding classification labels. When the graphics processor completes the gradient calculation for the sub-training data, a corresponding completion identifier is generated.

[0012] When the number of completed identifiers is determined to be N, the parameters of the initial classification model are updated for the i-th round of model training by combining the N gradients, and the classification model is obtained.

[0013] On the other hand, embodiments of this application provide a model training apparatus, the apparatus comprising:

[0014] A communication module is used to acquire a training data set for training an initial classification model in a processing device, wherein the training data in the training data set has classification labels, and the processing device includes N graphics processors, where N>1;

[0015] A sampling module is used to sample from the training data set to obtain target training data for the i-th round of model training in the model training;

[0016] The splitting module is used to divide the target training data into N sub-training data for the N graphics processors. The N sub-training data corresponds one-to-one with the N graphics processors. At least two sub-training data have a difference in data volume, and / or at least two training data have a difference in the number of training data.

[0017] The prediction module is used to classify and predict the N sub-training data through the N graphics processors, and calculate the N gradients corresponding to the N sub-training data based on the corresponding classification labels. When the graphics processor completes the gradient calculation of the sub-training data, it generates a corresponding completion identifier.

[0018] The update module is used to update the parameters of the initial classification model in the i-th round of model training by combining the N gradients when it is determined that the number of completed identifiers is N, so as to obtain the classification model.

[0019] In another aspect, embodiments of this application provide a computer device, the computer device including a processor and a memory:

[0020] The memory is used to store program code and transmit the program code to the processor;

[0021] The processor is used to execute the model training method described above according to the instructions in the program code.

[0022] In another aspect, embodiments of this application provide a computer-readable storage medium for storing a computer program for executing the model training method described above.

[0023] In another aspect, embodiments of this application provide a computer program product including instructions that, when run on a computer, cause the computer to perform the model training method described above.

[0024] As can be seen from the above technical solution, this application provides a model training method. Specifically, it includes a processing device with N graphics processors acquiring a training data set for training an initial classification model, wherein the training data in the training data set has classification labels. Then, it samples from the training data set to obtain target training data for the i-th round of model training. For the N graphics processors, the processing device divides the target training data into N sub-training data, with each of the N sub-training data corresponding to one of the N graphics processors, so that the N graphics processors simultaneously train their respective sub-training data. Simultaneous processing by the N graphics processors improves the model training speed.

[0025] Among them, at least two sub-sub ...

[0026] N graphics processing units (GPUs) are used to classify and predict N subsets of training data. Based on the corresponding classification labels, N gradients are calculated for each subset of training data. Once a GPU completes gradient calculation for a subset of training data, a completion flag is generated. Because the amount or quantity of training data may not be entirely equal, the N GPUs do not complete gradient calculations simultaneously. To prevent a GPU from proceeding to the next step before completing its gradient calculation, thus preventing the training data corresponding to that GPU from being excluded from the next calculation, a waiting mechanism is established, using completion flags to indicate the gradient calculation progress of that GPU. When the number of completion flags is determined to be N, indicating that all GPUs have completed gradient calculations, the N gradients are combined to update the parameters of the initial classification model in the i-th round of model training. This ensures that all target training data collected in this round can participate in the model update, improving the accuracy of model training. Attached Figure Description

[0027] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0028] Figure 1 A schematic diagram of the system architecture of a model training method provided in an embodiment of this application;

[0029] Figure 2 A schematic flowchart illustrating a model training method provided in an embodiment of this application;

[0030] Figure 3 A schematic diagram illustrating a model training and application process provided in an embodiment of this application;

[0031] Figure 4 A schematic diagram of GPU utilization for a variable-length feature input;

[0032] Figure 5 A schematic diagram illustrating GPU utilization for a fixed-length feature input;

[0033] Figure 6 A schematic diagram illustrating the collaborative operation of a CPU and a GPU provided in this application embodiment;

[0034] Figure 7 A schematic diagram illustrating GPU utilization provided in an embodiment of this application;

[0035] Figure 8 A schematic diagram of a ring-allreduce mode provided for an embodiment of this application;

[0036] Figure 9 A schematic diagram illustrating a waiting mechanism provided in an embodiment of this application;

[0037] Figure 10 A schematic diagram illustrating GPU utilization provided in an embodiment of this application;

[0038] Figure 11 This is a schematic diagram of the structure of a model training device provided in an embodiment of this application;

[0039] Figure 12 A structural diagram of a terminal device provided in an embodiment of this application;

[0040] Figure 13 This is a structural diagram of a server provided in an embodiment of this application. Detailed Implementation

[0041] The embodiments of this application will now be described with reference to the accompanying drawings.

[0042] Deep learning (DL) is a branch of machine learning (ML). Deep learning learns the inherent patterns and hierarchical representations of sample data, enabling machines to analyze and learn like humans, and to recognize data such as text, images, and sound.

[0043] Deep learning models can be used in various applications, such as recommending content to users by learning from their historical behavior. However, training deep learning models is very time-consuming because the training data is large, typically tens of gigabytes. Furthermore, for cost reasons, deep models are usually trained on a single machine.

[0044] Therefore, in a standalone environment, it typically takes several days or even a week to train a deep learning model that meets user needs, which does not meet the time requirements for content recommendation for users.

[0045] In view of this, this solution provides a faster model training method. This method can be implemented by any computer device including an access layer, which includes multiple graphics processors. The computer device can be a terminal device or a server. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, in-vehicle terminal, smart TV, etc., but is not limited to these. The terminal and server can be directly or indirectly connected via wired or wireless communication, which is not limited herein.

[0046] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.

[0047] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, machine learning, and deep learning.

[0048] Machine learning (ML) is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and instructional learning.

[0049] The solutions provided in this application relate to deep learning technology in artificial intelligence, and are specifically illustrated through the following embodiments:

[0050] like Figure 1 As shown, firstly, the processing device 100 acquires a training dataset for training the initial classification model. This training dataset includes multiple training data points, each with a classification label. The processing device includes N graphics processing units (GPUs), which acquire gradients for model updates.

[0051] During each training round, the processing device samples target training data from the training dataset to obtain the model training data for that round. When the i-th round of model training is required, target training data for the i-th round of model training is sampled from the training dataset.

[0052] Since the processing device includes N graphics processing units (GPUs), the target training data for this training round needs to be divided into N sub-training data based on the number of GPUs. Each GPU then processes its corresponding sub-training data. Each of the N sub-training data corresponds one-to-one with one of the N GPUs. In related technologies, to ensure consistency in the processing of the N GPUs, it is usually necessary to remove portions of the target training data that cannot be evenly divided. However, deleting training data may result in some data being unable to participate in this training round, or even in all training, thus affecting training accuracy. Therefore, this solution allows for differences between different sub-training data, specifically including differences in the amount of data and differences in the number of training data sets. This eliminates the need to delete training data, thereby improving training accuracy.

[0053] For example, when the processing device includes three graphics processors, graphics processor A, graphics processor B, and graphics processor C, the target training data for the model training in this round of sampling can be divided into sub-training data A, sub-training data B, and sub-training data C, where the amount of data in sub-training data A is greater than that in sub-training data B and sub-training data C.

[0054] N graphics processing units (GPUs) are used to classify and predict N subsets of training data. Based on the classification labels of each subset, N gradients are calculated for each subset. Once a GPU completes gradient calculation for its corresponding subset, a completion flag is generated to indicate that the GPU has finished calculating the gradients. Due to differences between the subsets, the time taken for different GPUs to complete gradient calculations typically varies.

[0055] For example, graphics processors B and C may complete gradient calculations first and generate corresponding completion identifiers B and C. At this point, graphics processors B and C do not proceed to the next calculation but wait for graphics processor A to complete its processing.

[0056] When the processing device determines that the number of completion markers acquired is N, that is, when all N graphics processors have completed gradient calculation, it combines the N gradients and updates the parameters of the initial classification model for the i-th round of model training. Specifically, after graphics processor A has also completed its corresponding gradient calculation, when the processing device determines that it has acquired 3 completion markers, it combines the 3 gradients and updates the parameters of the initial classification model for that round of model training.

[0057] Since different graphics processing units (GPUs) take different amounts of time to complete gradient calculations, a waiting mechanism is added to this scheme to prevent the gradients of a GPU from being unusable for parameter updates in a given round if the GPU has not completed gradient calculations. A completion flag is used to determine whether a GPU has completed gradient calculations. In this way, after all N GPUs have completed gradient calculations, the N gradients are combined to update the parameters of the initial classification model for the i-th round of model training.

[0058] Thus, since the processing device includes three graphics processors (GPUs), the target training data for the i-th round of model training can be divided into three sub-training data sets, allowing the three GPUs to process them simultaneously, thereby improving the training speed of the model. Furthermore, this scheme allows for differences in the amount or quantity of training data in the sub-training data sets corresponding to the three GPUs; for example, the amount of training data set A can be greater than that of sub-training data sets B and C. This avoids discarding training data due to the inability to divide it into three equal parts, ensuring that all training data can participate in the training and improving the model's accuracy. After the three GPUs complete gradient calculation, they generate corresponding completion markers, allowing the processing status of each GPU to be obtained. When all three GPUs have completed processing, i.e., when the processing device 100 obtains three completion markers, the parameters of the initial classification model for the i-th round of model training are updated by combining the three gradients. This prevents gradients from being excluded from parameter updates due to incomplete processing by the GPUs.

[0059] Figure 2 This is a flowchart illustrating a model training method provided in an embodiment of this application. In this embodiment, the processing device 100 is used as the aforementioned computer device for description. The method includes the following steps:

[0060] S202: The processing device acquires a set of training data for training the initial classification model.

[0061] The processing equipment includes N graphics processing units (GPUs), where N is greater than 1. By using N GPUs to perform calculations simultaneously, the training speed of the model is improved.

[0062] The training data in the training dataset has category labels. When this scheme is applied to content recommendation, the training data in the training dataset consists of historical accounts and historical content, and the category labels are used to identify whether there is a relationship between historical accounts and historical content.

[0063] like Figure 3 As shown, a real-time data access system (such as TDBank) acquires a user's historical application data (including account characteristics and recommended content characteristics) through a data generator (spout), and then determines corresponding tags for the account information and content information through a join result. The recommended content can be web pages, applications, etc.

[0064] It is understood that, in the specific embodiments of this application, the acquisition of user data sets, including user account data and recommended content data, is carried out only after obtaining the user's explicit consent. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions.

[0065] This model training method can be used for both batch and incremental model training. In some scenarios (such as content recommendation), batch and incremental models can be used in combination. For example, the batch model is used for training on large-scale data, while the incremental model is used to fine-tune the batch model using recent data. When this method is applied to both batch and incremental model training, the generation time of training data in batch training is longer than that in incremental training. However, the model training method in this application can also be applied to batch and incremental model training independently, and this application does not limit this application. When applied independently to batch or incremental model training, it can improve the training speed and accuracy of the model.

[0066] Because batch models involve large amounts of training data containing more information, they can be used as initial training models to consider multiple parameters and obtain a more comprehensive user recommendation model. Incremental models, on the other hand, are updated based on user behavior, ensuring the updated model reflects recent behavioral characteristics and avoids a disconnect between recommended content and recent user activity. Furthermore, there's no need to retrain the batch models, thus improving training speed.

[0067] When the model training method of this solution is applied to content recommendation, such as news feed recommendation, the training dataset for the batch model can include user data acquired over the past 60 days. The training dataset for the incremental model can include user data acquired over the past seven days. This solution provides a fast-training model for both batch and incremental models for content recommendation. Due to the fast training speed, a classification model that meets user needs can be generated quickly, enabling fast and accurate content recommendations and optimizing the user experience.

[0068] In some possible approaches, the weights of the training data can be determined based on the time difference between the generation of the training data and the prediction time for classification. The weight calculation formula can be obtained through formula (1):

[0069]

[0070] Where weight represents the weights corresponding to the training data, and data timeIndicates the time when the training data occurred, current time This represents the current time. As shown in formula (1), the time weights of the training data are inversely correlated with the corresponding time differences.

[0071] Typically, user behavior is time-sensitive. The closer the training data is to the prediction time, the better it reflects the user's recent behavioral characteristics. Therefore, the more recent the training data is, the greater its weight. This highlights the user's recent behavioral characteristics, making recommended content more aligned with the user's current needs and improving recommendation efficiency.

[0072] Loss function for weights weight It can be obtained through the cross-entropy loss function, as shown in formula (2):

[0073]

[0074] Among them, 2 (i) The label represents sample i, and can be 1 or 0. Let represent the probability that sample i is predicted as 1, and m represent the total number of samples.

[0075] S204: The processing device samples from the training dataset to obtain target training data for the i-th round of model training.

[0076] During the model training process, the processing device needs to perform multiple rounds of training on the model. At the beginning of each round of training, the processing device needs to sample the target training data for that round of model training from the training dataset.

[0077] S206: The processing device divides the target training data into N sub-training data for N graphics processors.

[0078] In this system, N sub-training data sets correspond one-to-one with N graphics processors, and each graphics processor has its own corresponding sub-training data sets.

[0079] In related technologies, the target training data is divided into N sub-training data sets, each with the same amount of data as the training data set. This allows N graphics processors to simultaneously process the *a*-th training data point within each sub-training data set. After processing, all N graphics processors simultaneously obtain the corresponding gradients and update the model. However, to ensure the target training data can be divided into N sub-training data sets with the same amount of data as the training data set, some data in the target training data set is deleted. This deletion of training data may prevent some data from participating in model training, affecting the accuracy of the model training.

[0080] In this approach, it is unnecessary to divide the target training data into N sub-training data sets with the same amount of data as the total training data. Specifically, in this approach, at least two of the N sub-training data sets have a difference in data size, and / or, at least two of the N sub-training data sets have a difference in the number of training data sets. This preserves all training data from the target training data set, avoiding the impact of deleting training data on the accuracy of model training.

[0081] S208: The processing device performs classification prediction on N sub-training data using N graphics processors, calculates N gradients corresponding to the N sub-training data based on the corresponding classification labels, and generates a corresponding completion identifier after the graphics processors have completed the gradient calculation for the sub-training data.

[0082] In some cases, the processing device can extract features from N sub-samples of training data using a central processing unit (CPU), and classify and predict the features corresponding to each of the N sub-samples of training data using N graphics processing units.

[0083] Typically, the feature length obtained from feature extraction is variable. When a GPU processes features of variable length, its utilization is usually low, such as... Figure 4 As shown, the GPU utilization rate is only 0.16.

[0084] In related technologies, variable-length features are typically truncated to obtain fixed-length features, which are then input into the GPU for computation, thereby improving GPU utilization. For example... Figure 5 As shown, when the feature length is fixed, the GPU utilization can reach 0.95.

[0085] However, feature truncation results in a loss of information contained in the training data, affecting the accuracy of model training. Therefore, it is necessary to improve GPU utilization when feature lengths are variable.

[0086] Specifically, the time taken to train the model can be analyzed using a timeline, such as... Figure 6 As shown, analysis of model training time reveals that a significant amount of time-consuming data processing occurs on the CPU. The analysis further indicates that, when feature lengths are variable, low GPU utilization is primarily due to the slow processing speed of the CPU.

[0087] The working principle of CPU and GPU collaborative processing is as follows: Figure 6As shown, the CPU extracts data features from the training data and transfers these features to the GPU. The GPU loads the computation graph from its memory, calculates the gradient based on the data features, and finally updates the model based on the gradient. When the data features are of variable length, the CPU's extraction speed is slow, resulting in fewer data features being transferred to the GPU, thus affecting GPU utilization.

[0088] Based on this, feature extraction of the sub-training data can be performed in parallel by M processes, thereby improving the CPU processing speed and transferring sufficient data features to the GPU to avoid the impact of CPU processing speed on GPU utilization.

[0089] Therefore, in this approach, features of variable length are not truncated to preserve as much information as possible from the training data, thereby improving the model's training accuracy. Furthermore, performing feature extraction on the sub-training data in parallel through multi-process processing improves CPU processing speed and increases GPU utilization.

[0090] Without feature truncation, feature extraction from training data via multi-process parallel processing can achieve GPU utilization of up to 68%. However, as... Figure 7 As shown, although three GPUs were used, only one GPU was actually used. Therefore, parallel training is needed to improve GPU utilization and increase the training speed of the model.

[0091] To improve model training speed, a ring-all-reduce architecture can be used. In the ring-all-reduce architecture, N GPUs participating in training form a ring, without a central node to aggregate all calculated gradients. The ring-all-reduce algorithm places the N GPUs participating in training in a logical ring. Each GPU receives data from the upstream GPU and sends data to the downstream GPU, thus fully utilizing the upstream and downstream bandwidth of each GPU.

[0092] Specifically, such as Figure 8 As shown, three graphics processing units (GPUs) are connected in a ring. GPU A receives data from GPU C and sends data to GPU B. GPU B receives data from GPU A and sends data to GPU C. GPU C receives data from GPU B and sends data to GPU A. Figure 10The diagram illustrates a scenario with varying amounts of training data. Specifically, in (1), GPU A includes three training data sets: 5 13, 8 19, and 42 1; GPU B includes three training data sets: 8 11, 4 2, and 7 7; and GPU C includes three training data sets: 9 27, 315, and 8 4. In (2), GPU A sends training data 5 13 to GPU B and receives training data 8 4 from GPU C. GPU A then integrates the received training data 8 4 with the existing training data 42 1 to obtain training data 50 5. Similarly, GPU B sends training data 4 2 to GPU C and receives training data 5 13 from GPU A. GPU B then integrates the received training data 5 13 with the existing training data 8 11 to obtain training data 13 24. Similarly, the graphics processor C sends the training data 8 4 to the graphics processor A and receives the training data 4 2 sent by the graphics processor B. The graphics processor C integrates the received training data 4 2 with the original training data 3 15 to obtain the training data 7 17.

[0093] In (3), GPU A sends training data 50 5 to GPU B and receives training data 7 17 sent by GPU C. GPU A integrates the received training data 7 17 with the original training data 8 19 to obtain training data 15 36. Similarly, GPU B sends training data 13 24 to GPU C and receives training data 50 5 sent by GPU A. GPU B integrates the received training data 50 5 with the original training data 7 7 to obtain training data 57 12. Similarly, GPU C sends training data 7 17 to GPU A and receives training data 13 24 sent by GPU B. GPU C integrates the received training data 13 24 with the original training data 9 27 to obtain training data 22 51. (4) is similar to (3).

[0094] In (5), graphics processor A sends training data 22 51 to graphics processor B and receives training data 57 12 from graphics processor C, overwriting the original 50 5 with training data 57 12. This data 57 12 is obtained jointly from graphics processor A's 42 1, graphics processor B's 7 7, and graphics processor C's 8 4. Similarly, graphics processor B sends 15 36 to graphics processor C and receives training data 22 51 from graphics processor A, while graphics processor C sends 57 12 to graphics processor A and receives training data 15 36 from graphics processor B.

[0095] In the ring-allreduce architecture, there is no need for a central node to aggregate the gradients calculated by all GPUs. During each training round, each GPU completes the forward and backward computation of its corresponding sub-training data to obtain gradient data, and then the gradient data is synchronized through the Ring-allreduce algorithm.

[0096] The Ring-allreduce algorithm consists of two parts: scatter-reduce and allgather. The gradient data from one GPU is passed to the next GPU in the ring in multiple steps, while it also receives gradient data from the previous GPU multiple times. For a ring with N GPUs, each GPU needs to receive 2*(N-1) gradient data from other GPUs (receiving 1 / N of the data each time) and send 2*(N-1) gradient data to other GPUs (sending 1 / N of the data each time).

[0097] In this embodiment, after a graphics processor completes the forward and backward computations of the corresponding sub-training data and obtains the gradient data, it generates a corresponding completion identifier to indicate that the graphics processor has completed the gradient computation for this round. Since the amount of data included in graphics processor A is different, graphics processor A completes the gradient computation for this round later.

[0098] like Figure 9 As shown, graphics processor 1 requires a large amount of data, thus taking a considerable amount of time to complete the computation. In some possible implementations, state management can be achieved through distributed application coordination service software (such as ZooKeeper). Specifically, each graphics processor registers with ZooKeeper, and each graphics processor has node information. When a graphics processor completes its work, it writes the status information (status) to ZooKeeper as "done".

[0099] like Figure 10 As shown, after training the model using the ring-allreduce architecture, the GPU utilization rate increased to over 54%, thus fully utilizing the GPU's computing resources and effectively improving the model's training speed.

[0100] When the training data has time weights, the N subsets of training data are classified and predicted using N graphics processors, and the N gradients corresponding to the N subsets of training data are calculated based on the corresponding classification labels and time weights.

[0101] S210: When the processing device determines that the number of completed identifiers is N, it integrates the N gradients and updates the parameters of the initial classification model for the i-th round of model training.

[0102] Because at least two sub-training datasets in this scheme have a difference in data volume, and / or at least two sub-training datasets have a difference in the number of training data points, the N graphics processors in this scheme will not perform calculations or generate N gradients synchronously. If a gradient is not fully calculated, updating the model parameters by combining other gradients will prevent the corresponding sub-training dataset from participating in the parameter update, thus affecting the accuracy of the model training.

[0103] Therefore, in this scheme, a waiting mechanism can be established to ensure that all N gradients corresponding to the N subsets of training data can participate in model updates. Specifically, after the graphics processor completes gradient calculation, it generates a corresponding completion flag. The processing device manages whether the graphics processor has completed gradient calculation through the completion flag. When the processing device determines that the number of completion flags obtained is N, that is, when all N graphics processors have completed gradient calculation, the N gradients are combined, and the parameters of the initial classification model are updated for the i-th round of model training. As shown in the figure, when the ZooKeeper status of all graphics processors is "done", the gradient parameters are updated by combining the N gradients.

[0104] Based on the above description, this application provides a model training method. Specifically, a processing device including N graphics processors acquires a training data set for training an initial classification model, wherein the training data in the training data set has classification labels. Then, target training data for the i-th round of model training is sampled from the training data set. For the N graphics processors, the processing device divides the target training data into N sub-training data, with each of the N sub-training data corresponding one-to-one with the N graphics processors, so that the N graphics processors simultaneously train on their respective sub-training data, thereby improving the training speed of the model through simultaneous processing by the N graphics processors.

[0105] Among them, at least two sub-sub ...

[0106] N graphics processing units (GPUs) are used to classify and predict N subsets of training data. Based on the corresponding classification labels, N gradients are calculated for each subset of training data. Once a GPU completes gradient calculation for a subset of training data, a completion flag is generated. Because the amount or quantity of training data may not be entirely equal, the N GPUs do not complete gradient calculations simultaneously. To prevent a GPU from proceeding to the next step before completing its gradient calculation, thus preventing the training data corresponding to that GPU from being excluded from the next calculation, a waiting mechanism is established, using completion flags to indicate the gradient calculation progress of that GPU. When the number of completion flags is determined to be N, indicating that all GPUs have completed gradient calculations, the N gradients are combined to update the parameters of the initial classification model in the i-th round of model training. This ensures that all target training data collected in this round can participate in the model update, improving the accuracy of model training.

[0107] The model training method provided in this application can be applied to content recommendation. The training dataset consists of historical accounts and historical content, and classification labels are used to identify whether there is a relationship between historical accounts and historical content. When the classification model trained using this method is applied to content recommendation, the processing device acquires the account characteristics of the target account and the content characteristics of the content to be recommended. The classification model determines the correlation between the content to be recommended and the target account. If the correlation classification result shows a relationship, the content to be recommended is pushed to the target account.

[0108] Specifically, such as Figure 3 As shown, real-time user behavior data is reported to a message queue. The processing device, through a stream processing data platform, uses a data generator (spout) to obtain the account characteristics of the target account and the content characteristics of the content to be recommended. After obtaining these characteristics, the data is distributed to nodes (bolts). The bolts use a classification model to determine the correlation between the content to be recommended and the target account. If the correlation classification results show a relationship, the recommended content is stored in a database (TDE). TDE is an in-memory key-value store; when making recommendations to users, recommended content is retrieved from the TDE and presented to the user.

[0109] The classification model trained using this method can quickly and accurately determine the relationship between the content to be recommended and the target account, thereby enabling rapid and accurate recommendations for the target account, which in turn increases the click-through rate of recommended content, the time users spend on recommended content pages, and the user retention rate.

[0110] In the foregoing Figures 1-10 Based on the corresponding embodiments, Figure 11The diagram shows the structure of a model training device 1100, which includes a communication module 1102, a sampling module 1104, a splitting module 1106, a prediction module 1108, and an update module 1110.

[0111] The communication module 1102 is used to acquire a training data set for training an initial classification model in a processing device, wherein the training data in the training data set has classification labels, and the processing device includes N graphics processors, where N>1;

[0112] Sampling module 1104 is used to sample from the training data set to obtain target training data for the i-th round of model training in the model training;

[0113] The splitting module 1106 is used to divide the target training data into N sub-training data for the N graphics processors, wherein the N sub-training data corresponds one-to-one with the N graphics processors, and at least two sub-training data have a difference in data volume, and / or at least two training data have a difference in the number of training data.

[0114] The prediction module 1108 is used to perform classification prediction on the N sub-training data through the N graphics processors, and calculate N gradients corresponding to the N sub-training data based on the corresponding classification labels. When the graphics processor completes the gradient calculation of the sub-training data, it generates a corresponding completion identifier.

[0115] The update module 1110 is used to update the parameters of the initial classification model in the i-th round of model training by combining the N gradients when it is determined that the number of completed identifiers is N, so as to obtain the classification model.

[0116] In one possible implementation, the device further includes an extraction module for:

[0117] The central processing unit extracts features from the N training data to obtain the features corresponding to each training data in the N training data, and the feature lengths corresponding to each training data in the N training data have differences.

[0118] Prediction module 1108 is specifically used for:

[0119] The N graphics processors are used to classify and predict the features corresponding to the N training data.

[0120] In one possible implementation, the extraction module is also used for:

[0121] The N training data are processed in parallel by M processes of the central processing unit to extract features, and the features corresponding to the training data in the N training data are obtained respectively, where M>1.

[0122] In one possible implementation, the initial classification model is a batch model obtained through pre-training, the classification model is an incremental model obtained by incrementally updating the batch model, the generation time range of the training data in the training dataset is a first duration, the generation time range of the training data used to pre-train the batch model is a second duration, and the first duration is less than the second duration.

[0123] In one possible implementation, the device further includes a weight determination module for:

[0124] Based on the time difference between the generation time of the training data and the prediction time of the classification prediction, the time weights corresponding to the training data are determined respectively, and the time weights of the training data are inversely correlated with the corresponding time differences.

[0125] The prediction module 1108 is specifically used for:

[0126] The N training data are classified and predicted using the N graphics processors, and N gradients are calculated based on the corresponding classification labels and time weights for each of the N training data.

[0127] In one possible implementation, the initial classification model is an initialization classification model, and the classification model is a batch model trained based on the initialization classification model.

[0128] In one possible implementation, the training data in the training dataset consists of historical accounts and historical content, and the classification labels are used to identify whether there is a correlation between the historical accounts and the historical content. The device also includes a recommendation module for:

[0129] Obtain the account characteristics of the target account and the content characteristics of the content to be recommended;

[0130] The classification model is used to determine the correlation classification result between the content to be recommended and the target account;

[0131] If the correlation classification result determines that there is a correlation, the content to be recommended is pushed to the target account.

[0132] Therefore, a processing device comprising N graphics processors acquires a training dataset for training an initial classification model. The training data in this dataset has classification labels. Then, it samples this training dataset to obtain target training data for the i-th round of model training. For the N graphics processors, the processing device divides the target training data into N sub-training datasets, with each sub-data set corresponding to one of the N graphics processors. This allows each of the N graphics processors to simultaneously train its corresponding sub-data set, thereby increasing the model's training speed through simultaneous processing by the N graphics processors.

[0133] Among them, at least two sub-sub ...

[0134] N graphics processing units (GPUs) are used to classify and predict N subsets of training data. Based on the corresponding classification labels, N gradients are calculated for each subset of training data. Once a GPU completes gradient calculation for a subset of training data, a completion flag is generated. Because the amount or quantity of training data may not be entirely equal, the N GPUs do not complete gradient calculations simultaneously. To prevent a GPU from proceeding to the next step before completing its gradient calculation, thus preventing the training data corresponding to that GPU from being excluded from the next calculation, a waiting mechanism is established, using completion flags to indicate the gradient calculation progress of that GPU. When the number of completion flags is determined to be N, indicating that all GPUs have completed gradient calculations, the N gradients are combined to update the parameters of the initial classification model in the i-th round of model training. This ensures that all target training data collected in this round can participate in the model update, improving the accuracy of model training.

[0135] This application also provides a computer device, which is the computer device described above, and may include a terminal device or a server. The aforementioned model training device may be configured in this computer device. The computer device will now be described in conjunction with the accompanying drawings.

[0136] If the computer device is a terminal device, please refer to Figure 12 As shown, this application provides a terminal device, taking a mobile phone as an example:

[0137] Figure 12 This diagram illustrates a partial structural representation of a mobile phone related to the terminal device provided in this embodiment. (Reference) Figure 12 The mobile phone includes components such as a radio frequency (RF) circuit 1210, a memory 1220, an input unit 1230, a display unit 1240, a sensor 1250, an audio circuit 1260, a Wi-Fi module 1270, a processor 1280, and a power supply 1290. Those skilled in the art will understand that... Figure 12 The mobile phone structure shown does not constitute a limitation on the mobile phone and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0138] The following is combined Figure 12 A detailed introduction to each component of a mobile phone:

[0139] The RF circuit 1210 can be used to receive and transmit signals during information transmission or calls. In particular, it receives downlink information from the base station and processes it with the processor 1280; in addition, it transmits uplink data to the base station.

[0140] The memory 1220 can be used to store software programs and modules. The processor 1280 executes various functions and data processing of the mobile phone by running the software programs and modules stored in the memory 1220. The memory 1220 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 1220 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0141] The input unit 1230 can be used to receive input numeric or character information, and to generate key signal inputs related to user settings and function control of the mobile phone. Specifically, the input unit 1230 may include a touch panel 1231 and other input devices 1232.

[0142] The display unit 1240 can be used to display information input by the user or information provided to the user, as well as various menus of the mobile phone. The display unit 1240 may include a display panel 1241.

[0143] The mobile phone may also include at least one sensor 1250, such as a light sensor, a motion sensor, and other sensors.

[0144] The audio circuit 1260, speaker 1261, and microphone 1262 provide an audio interface between the user and the mobile phone.

[0145] WiFi is a short-range wireless transmission technology. Through the WiFi module 1270, mobile phones can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access.

[0146] The processor 1280 is the control center of the mobile phone. It connects to various parts of the mobile phone through various interfaces and lines. It performs various functions of the mobile phone and processes data by running or executing software programs and / or modules stored in the memory 1220 and calling data stored in the memory 1220.

[0147] The mobile phone also includes a power supply 1290 (such as a battery) that powers the various components.

[0148] In this embodiment, the processor 1280 included in the terminal device also has the following functions:

[0149] A training data set is obtained for training an initial classification model in a processing device, wherein the training data in the training data set has classification labels, and the processing device includes N graphics processors, where N>1;

[0150] Target training data for the i-th round of model training is obtained by sampling from the training data set;

[0151] For the N graphics processors, the target training data is divided into N sub-training data, each of the N sub-training data and the N graphics processors is one-to-one, and at least two of the N sub-training data have a difference in the amount of data, and / or at least two of the N sub-training data have a difference in the number of training data.

[0152] The N graphics processors perform classification prediction on the N sub-training data, and calculate N gradients corresponding to the N sub-training data based on the corresponding classification labels. When the graphics processor completes the gradient calculation for the sub-training data, a corresponding completion identifier is generated.

[0153] When the number of completed identifiers is determined to be N, the parameters of the initial classification model are updated for the i-th round of model training by combining the N gradients, and the classification model is obtained.

[0154] If the computer device is a server, this application embodiment also provides a server; please refer to [link to relevant documentation]. Figure 13 As shown, Figure 13The diagram illustrates the structure of a server 1300 provided in this embodiment. The server 1300 can vary significantly due to different configurations or performance characteristics. It may include one or more Central Processing Units (CPUs) 1322 (e.g., one or more processors) and a memory 1332, and one or more storage media 1330 (e.g., one or more mass storage devices) for storing application programs 1342 or data 1344. The memory 1332 and storage media 1330 may be temporary or persistent storage. The program stored in the storage media 1330 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the server. Furthermore, the CPU 1322 may be configured to communicate with the storage media 1330 and execute the series of instruction operations stored in the storage media 1330 on the server 1300.

[0155] Server 1300 may also include one or more power supplies 1326, one or more wired or wireless network interfaces 1350, one or more input / output interfaces 1358, and / or one or more operating systems 1341, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSD TM etc.

[0156] The steps performed by the server in the above embodiments can be based on Figure 13 The server structure shown.

[0157] In addition, this application embodiment also provides a storage medium for storing a computer program for executing the method provided in the above embodiment.

[0158] This application also provides a computer program product including instructions that, when run on a computer, cause the computer to perform the methods provided in the above embodiments.

[0159] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium can be at least one of the following media: read-only memory (ROM), RAM, magnetic disk, or optical disk, etc., and other media capable of storing program code.

[0160] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0161] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Moreover, based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A model training method, characterized in that, The method includes: A training data set is obtained for training an initial classification model in a processing device, wherein the training data in the training data set has classification labels, and the processing device includes N graphics processors, where N>1; Target training data for the i-th round of model training is obtained by sampling from the training data set; For the N graphics processors, the target training data is divided into N sub-training data, each of the N sub-training data and the N graphics processors is one-to-one, and at least two of the N sub-training data have a difference in the amount of data, and / or at least two of the N sub-training data have a difference in the number of training data. The N graphics processors perform classification prediction on the N sub-training data, and calculate N gradients corresponding to the N sub-training data based on the corresponding classification labels. When the graphics processor completes the gradient calculation for the sub-training data, a corresponding completion identifier is generated. When the number of completed identifiers is determined to be N, the parameters of the initial classification model are updated in the i-th round of model training by combining the N gradients to obtain the classification model; Based on the time difference between the generation time of the training data and the prediction time of the classification prediction, the time weights corresponding to the training data are determined respectively, and the time weights of the training data are inversely correlated with the corresponding time differences. The step of classifying and predicting the N training data using the N graphics processors, and calculating the N gradients corresponding to the N training data based on the corresponding classification labels, includes: The N training data are classified and predicted using the N graphics processors, and N gradients are calculated based on the corresponding classification labels and time weights for each of the N training data.

2. The method according to claim 1, characterized in that, The method further includes: The central processing unit extracts features from the N training data to obtain the features corresponding to each training data in the N training data, and the feature lengths corresponding to each training data in the N training data have differences. The classification and prediction of the N subsets of training data using the N graphics processors includes: The N graphics processors are used to classify and predict the features corresponding to the N training data.

3. The method according to claim 2, characterized in that, The step of extracting features from the N subsets of training data using a central processing unit to obtain the features corresponding to each training data in the N subsets of training data includes: The N training data are processed in parallel by M processes of the central processing unit to extract features, and the features corresponding to the training data in the N training data are obtained respectively, where M>1.

4. The method according to claim 1, characterized in that, The initial classification model is a batch model obtained through pre-training, and the classification model is an incremental model obtained by incrementally updating the batch model. The generation time range of the training data in the training dataset is a first duration, and the generation time range of the training data used to pre-train the batch model is a second duration, wherein the first duration is less than the second duration.

5. The method according to claim 1, characterized in that, The initial classification model is an initial classification model, and the classification model is a batch model trained based on the initial classification model.

6. The method according to claim 1, characterized in that, The training data in the training dataset consists of historical accounts and historical content. The classification labels are used to identify whether there is a correlation between the historical accounts and the historical content. The method further includes: Obtain the account characteristics of the target account and the content characteristics of the content to be recommended; The classification model is used to determine the correlation classification result between the content to be recommended and the target account; If the correlation classification result determines that there is a correlation, the content to be recommended is pushed to the target account.

7. A model training device, characterized in that, The device includes: A communication module is used to acquire a training data set for training an initial classification model in a processing device, wherein the training data in the training data set has classification labels, and the processing device includes N graphics processors, where N>1; A sampling module is used to sample from the training data set to obtain target training data for the i-th round of model training in the model training; The splitting module is used to divide the target training data into N sub-training data for the N graphics processors. The N sub-training data corresponds one-to-one with the N graphics processors. At least two sub-training data have a difference in data volume, and / or at least two training data have a difference in the number of training data. The prediction module is used to classify and predict the N sub-training data through the N graphics processors, and calculate the N gradients corresponding to the N sub-training data based on the corresponding classification labels. When the graphics processor completes the gradient calculation of the sub-training data, it generates a corresponding completion identifier. The update module is used to update the parameters of the initial classification model in the i-th round of model training by combining the N gradients when it is determined that the number of completed identifiers is N, so as to obtain the classification model. The device further includes a weight determination module, used for: Based on the time difference between the generation time of the training data and the prediction time of the classification prediction, the time weights corresponding to the training data are determined respectively, and the time weights of the training data are inversely correlated with the corresponding time differences. The prediction module is specifically used for: The N training data are classified and predicted using the N graphics processors, and N gradients are calculated based on the corresponding classification labels and time weights for each of the N training data.

8. The apparatus according to claim 7, characterized in that, The device further includes an extraction module for: The central processing unit extracts features from the N training data to obtain the features corresponding to each training data in the N training data, and the feature lengths corresponding to each training data in the N training data have differences. The prediction module is specifically used for: The N graphics processors are used to classify and predict the features corresponding to the N training data.

9. The apparatus according to claim 8, characterized in that, The extraction module is also used for: The N training data are processed in parallel by M processes of the central processing unit to extract features, and the features corresponding to the training data in the N training data are obtained respectively, where M>1.

10. The apparatus according to claim 7, characterized in that, The initial classification model is a batch model obtained through pre-training, and the classification model is an incremental model obtained by incrementally updating the batch model. The generation time range of the training data in the training dataset is a first duration, and the generation time range of the training data used to pre-train the batch model is a second duration, wherein the first duration is less than the second duration.

11. The apparatus according to claim 7, characterized in that, The initial classification model is an initial classification model, and the classification model is a batch model trained based on the initial classification model.

12. The apparatus according to claim 7, characterized in that, The training dataset consists of historical accounts and historical content. The classification labels are used to identify whether there is a correlation between the historical accounts and the historical content. The device also includes a recommendation module for: Obtain the account characteristics of the target account and the content characteristics of the content to be recommended; The classification model is used to determine the correlation classification result between the content to be recommended and the target account; If the correlation classification result determines that there is a correlation, the content to be recommended is pushed to the target account.

13. A computer device, characterized in that, The computer device includes a processor and memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the model training method according to any one of claims 1-7 according to the instructions in the program code.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program for performing the model training method according to any one of claims 1-7.

15. A computer program product comprising instructions that, when run on a computer, cause the computer to perform the method of any one of claims 1-7.

Citation Information

Patent Citations

  • Model training method, server and computer readable storage medium

    CN110134636A

  • Neural network linguistic model training method and device, equipment and storage medium

    CN110379416A