Model training, image generation method, device, medium, equipment and program product

By dynamically adjusting the weights and invocation probabilities of the expert network in the multi-expert hybrid model, the problem of unbalanced load in MoE training is solved, improving the training effect and image generation quality of the model, especially in the image generation task of the multimodal diffusion model.

CN122115601APending Publication Date: 2026-05-29BEIJING DAJIA INTERNET INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
Filing Date
2026-01-14
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Multi-expert hybrid models (MoE) suffer from uneven load distribution among expert networks during training, which affects the training performance, especially in image generation tasks. This leads to some expert networks being over-utilized or under-trained, impacting the model's generalization ability and the quality of generated images.

Method used

The initial expert weights are determined by analyzing the training samples of the current training batch through a gating network, and the expert weights are dynamically adjusted based on the calling information of the historical training batches to optimize the calling probability of each expert network. A sliding time window mechanism is used to smooth load fluctuations, and a sampling strategy is combined to balance the distribution of training samples to ensure that the load of each expert network is balanced.

Benefits of technology

Load balancing among expert networks was achieved, improving the training effect and image generation quality of the model, and enhancing the model's generalization ability and processing ability for different types of images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122115601A_ABST
    Figure CN122115601A_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a model training, image generation method, device, medium, equipment and program product, and the specific implementation scheme is: using a gating network, determining the initial expert weight corresponding to each expert network based on the training sample in the current training batch; based on the historical calling information of each expert network in the historical training batch before the current training batch, adjusting the initial expert weight to obtain the target expert weight; based on the target expert weight, determining the calling probability of each expert network in the current training batch, and performing model training of the current training batch on the model according to the calling probability. Through the dynamic adjustment of the initial expert weight based on the historical calling information of each expert network in the historical training batch after determining the initial expert weight corresponding to each expert network, the calling probability of each expert network can be optimized, the load balancing of each expert network is realized, and the training effect of the model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of artificial intelligence and machine learning technology, and in particular to model training, image generation methods, devices, media, equipment and program products. Background Technology

[0002] With the rapid development of artificial intelligence technology, Mixture of Experts (MoE) models have achieved remarkable success in natural language processing and multimodal generation tasks.

[0003] The MoE architecture introduces multiple expert networks and gating networks.

[0004] Currently, there is an imbalance in the load of expert networks during the training of MoE, which affects the training effect of the model. Summary of the Invention

[0005] This application provides a model training, image generation method, apparatus, medium, device, and program product.

[0006] This application provides the following solution: According to the first aspect, a model training method is provided, the model including a gating network and multiple expert networks, the method comprising: Using a gating network, the initial expert weights for each expert network are determined based on the training samples in the current training batch. Based on the historical call information of each expert network in previous training batches, the initial expert weights are adjusted to obtain the target expert weights. Based on the target expert weights, the probability of calling each expert network in the current training batch is determined, and the model is trained for the current training batch according to the calling probabilities.

[0007] As an optional approach, the initial expert weights are adjusted based on the historical call information of each expert network in previous training batches to obtain the target expert weights, including: Get the historical call frequency of each expert network in the previous preset number of consecutive historical training batches; Based on the difference between the historical call frequency and the preset equalization frequency, the historical load deviation of each expert network is determined. The preset equalization frequency is related to the number of expert networks. The initial expert weights are adjusted based on historical load deviations to obtain the target expert weights.

[0008] As an optional approach, the historical load deviation of each expert network is determined based on the difference between the historical call frequency and the preset equalization frequency, including: The difference between the historical call frequency and the preset equalization frequency is determined as the first deviation; The historical load deviation of the previous historical training batch of the current training batch is determined as the second deviation; Based on the first bias and the second bias, the historical load bias of each expert network in the current training batch is determined.

[0009] As an optional approach, the model is trained for the current training batch based on the invocation probability, including: Based on the invocation probability, each expert network is invoked to process the training samples of the current training batch, and the processing results of each expert network are obtained. The output of the expert network is weighted and fused based on the initial expert weights to obtain the model processing result for the current training batch. The model loss is calculated based on the model processing results and the preset training objectives, and the model parameters are updated based on the model loss to complete the model training for the current training batch.

[0010] As an alternative approach, the above methods also include: Obtain the original sample set that includes samples from multiple categories; Based on the total number of samples in the original sample set, the number of samples in each type, and the model training progress corresponding to the current training round, determine the sampling weights corresponding to each category. The original sample set is sampled based on the sampling weights to obtain the training samples for the current training round.

[0011] As an optional approach, based on the total number of samples in the original sample set, the number of samples in each category, and the model training progress corresponding to the current training round, the sampling weights corresponding to each category are determined, including: Obtain the balance coefficient related to the model training progress in the current training round; Based on the total number of samples in the original sample set, the number of samples in each category, and the balance coefficient, the sampling weights corresponding to each category are determined. The balance coefficient is used to make the sampling weights of each category approach uniformity when the model training progress meets the first preset progress condition, and to make the sampling weights of each category approach the actual proportion of each category in the sample set when the model training progress meets the second preset progress condition.

[0012] As an alternative approach, the model is an image generation model, the training samples are images, and the training samples are divided into multiple categories based on the image content.

[0013] According to the second aspect, an image generation method is provided, the method comprising: Obtain the image to be processed; The image to be processed is input into the image generation model, and the processed image is output by the image generation model. The image generation model is trained using the model training method described above.

[0014] According to a third aspect, a model training apparatus is provided, the model including a gating network and multiple expert networks, the apparatus comprising: The expert weight determination module is used to determine the initial expert weights for each expert network based on the training samples in the current training batch using a gating network. The expert weight adjustment module is used to adjust the initial expert weights based on the historical call information of each expert network in previous training batches to obtain the target expert weights. The model training module is used to determine the probability of calling each expert network in the current training batch based on the target expert weights, and to train the model for the current training batch according to the calling probability.

[0015] According to the fourth aspect, a model training device is provided, the model including a gating network and multiple expert networks, the device comprising: The image acquisition module is used to acquire the image to be processed. The image generation module is used to input the image to be processed into the image generation model and obtain the processed image output by the image generation model; The image generation model is trained using the model training method described above.

[0016] According to the fifth aspect, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the above-described model training method.

[0017] According to a sixth aspect, an electronic device is provided, comprising: One or more processors; and A memory associated with one or more processors, the memory being used to store program instructions that, when read and executed by one or more processors, perform the steps of the method for training the model described above.

[0018] In a seventh aspect, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described model training method.

[0019] According to the specific embodiments provided in this application, the following technical effects are disclosed: This application analyzes training samples in the current training batch using a gating network to determine the initial expert weights for each expert network. Then, based on historical call information for each expert network in previous training batches, the initial expert weights are adjusted to obtain target expert weights. Based on these target expert weights, the call probability for each expert network in the current training batch is determined, and the model is trained for the current training batch according to these call probabilities. By dynamically adjusting the initial expert weights based on historical call information in previous training batches after determining their initial weights, this application optimizes the call probability of each expert network, ensuring a balanced load across all expert networks and thus improving the model's training performance.

[0020] Of course, any product implementing this application does not necessarily need to achieve all of the advantages described above at the same time. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments 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.

[0022] Figure 1 This is a system architecture diagram applicable to the embodiments of this application.

[0023] Figure 2 This is a flowchart illustrating the model training method provided in an embodiment of this application.

[0024] Figure 3 This is a schematic flowchart of the image generation method provided in an embodiment of this application.

[0025] Figure 4 This is a schematic diagram of the structure of the model training device provided in the embodiments of this application.

[0026] Figure 5 This is a schematic diagram of the structure of the image generation apparatus provided in the embodiments of this application.

[0027] Figure 6 A schematic block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0028] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0029] The terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. The singular forms “a,” “the,” and “the” used in the embodiments of this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.

[0030] It should be understood that the term "and / or" used in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.

[0031] Depending on the context, the word "if" as used here can be interpreted as "when," "when," "in response to determination," or "in response to detection." Similarly, depending on the context, the phrase "if determination" or "if detection (of the stated condition or event)" can be interpreted as "when determination," "in response to determination," "when detection (of the stated condition or event)," or "in response to detection (of the stated condition or event)."

[0032] The Mixture of Experts (MoE) architecture incorporates multiple expert networks and a gating network. During MOE training, the gating network assigns different training samples to the expert network best suited for that type of task, thereby improving training performance while controlling computational costs.

[0033] However, the traditional MOE training method still suffers from an imbalance in the load on each expert network. Some expert networks are overused, leading to overfitting to a specific class, while other expert networks are under-trained due to low usage rates, thus affecting the training effect of the model.

[0034] Taking image generation tasks as an example, especially image generation tasks based on the Multi-modal Diffusion Model (MMDiT), the image data used during training may include multiple categories such as people, natural landscapes, buildings, and anime illustrations. These categories of images have huge differences in texture complexity, semantic structure, and spatial distribution, which leads to extremely uneven distribution of training samples. In this case, the traditional MOE training method cannot guarantee the load balance of each expert network, resulting in the overall capacity of the model not being fully utilized, the generalization ability being limited, and the quality and diversity of generated images being difficult to guarantee.

[0035] In view of this, this application provides a new approach. To facilitate understanding of this application, the system architecture on which this application is based is first described. For example... Figure 1 The diagram shows an exemplary system architecture that can be applied to embodiments of this application, such as... Figure 1 As shown, the system architecture may include: a server-side component and a user-side component running on a user terminal.

[0036] The server-side and the client-side are the two main components of an application service. The server-side uses a server as its primary hardware infrastructure and can include one or more software service modules. The client-side can be a client application, a mini-program, or a web application running through a browser.

[0037] The user terminal can include, but is not limited to, smart mobile terminals, wearable devices, and PCs (Personal Computers). Smart mobile devices can include smartphones, tablets, PDAs (Personal Digital Assistants), and connected car terminals. Wearable devices can include smartwatches, smart glasses, smart bracelets, VR (Virtual Reality) devices, AR (Augmented Reality) devices, and mixed reality devices (devices that support both virtual and augmented reality), etc.

[0038] A server can be a standalone server, a server cluster, or a cloud server. A cloud server, also known as a cloud computing server or cloud host, is a hosting product within the cloud computing service system, designed to address the shortcomings of traditional physical hosts and Virtual Private Servers (VPS) services, such as high management difficulty and weak service scalability.

[0039] Alternatively, the model training method provided in this application can be executed on the server side to complete the model training process. After the model training is completed, the client can send an inference request to the server, which can then use the trained model to perform inference and return the model output to the client.

[0040] It should be understood that, Figure 1 The number of servers, clients, and user terminals shown is merely illustrative. Depending on implementation needs, there can be any number of servers, clients, and user terminals.

[0041] Figure 2 This is a flowchart of a model training method provided in an embodiment of this application. This method can be performed by... Figure 1 The server-side execution in the system shown. For example... Figure 2 As shown, the method may include the following steps: Step S210: Using a gating network, determine the initial expert weights for each expert network based on the training samples in the current training batch; Step S220: Based on the historical call information of each expert network in previous training batches, adjust the initial expert weights to obtain the target expert weights; Step S230: Based on the target expert weights, determine the probability of calling each expert network in the current training batch, and train the model for the current training batch according to the calling probability.

[0042] As can be seen from the above process, this application analyzes the training samples in the current training batch through a gating network to determine the initial expert weights corresponding to each expert network. Then, based on the historical call information of each expert network in previous training batches, the initial expert weights are adjusted to obtain the target expert weights. Based on the target expert weights, the call probability of each expert network in the current training batch is determined, and the model is trained for the current training batch according to the call probability. This application, by dynamically adjusting the initial expert weights based on the historical call information of each expert network in previous training batches after determining the initial expert weights, can optimize the call probability of each expert network, making the load of each expert network balanced, thereby improving the training effect of the model.

[0043] The following describes in detail each step of the above process and the effects that can be further produced, with reference to the embodiments.

[0044] First, the above step S210, namely "using a gating network to determine the initial expert weights corresponding to each expert network based on the training samples in the current training batch", will be described in detail with reference to the embodiments.

[0045] Specifically, the model involved in the embodiments of this application can be a Mixture of Experts (MoE) model, which includes a gating network and multiple expert networks.

[0046] Gated networks are the core scheduling component in MoE, used to dynamically allocate the expert networks to be invoked based on the features of the training samples input into them.

[0047] For example, a gating network is a learnable neural network model, typically a lightweight feedforward network or a linear layer.

[0048] The initial expert weights are the raw scores output by each expert network based on the features of the input training samples. These scores reflect the "fitness" or "ability" that the gating network considers the expert to be handling the current input sample.

[0049] For example, training samples (such as images) are passed through the backbone network of the model to extract features from the training samples, and then the features of the training samples are input into a gating network to generate initial expert weights.

[0050] A training batch, also known as a batch, refers to a set of training samples used during a forward pass and a backward pass of model training.

[0051] The current training batch can be understood as the training batch that the model is currently processing.

[0052] The following describes in detail step S220, namely, "adjusting the initial expert weights based on the historical call information of each expert network in the historical training batches before the current training batch, and obtaining the target expert weights," with reference to the embodiments.

[0053] Among them, historical training batches refer to training batches that have been completed earlier than the currently being processed training batch (i.e., the "current training batch") on the model training timeline.

[0054] Historical call information represents the load of each expert network in previous training batches. It indicates the accumulated imbalance among expert networks during training. Adjusting the initial expert weights based on this historical call information allows for the increase of expert weights in networks with low loads in previous training batches, while reducing the expert weights in networks with high loads. This ensures that all expert networks are used evenly and receive sufficient training, maximizing the model's overall capacity and generalization ability.

[0055] The following describes in detail step S230, namely, "based on the target expert weights, determine the calling probability of each expert network in the current training batch, and train the model for the current training batch according to the calling probability", with reference to the embodiments.

[0056] In this embodiment of the application, after obtaining the target expert weight, the target expert weight can be converted into the calling probability of each expert network, thereby controlling the calling of each expert network according to the calling probability.

[0057] For example, the weights of each target expert can be normalized to obtain the calling probability of each expert network.

[0058] For example, multiple expert networks can be randomly sampled based on the invocation probability to determine the expert network invoked by each training sample.

[0059] In summary, based on steps S210 to S230, this application optimizes the calling probability of each expert network by dynamically adjusting the initial expert weights based on the historical calling information of each expert network in the historical training batches after determining the initial expert weights corresponding to each expert network, thereby balancing the load of each expert network and improving the training effect of the model.

[0060] Furthermore, the inventors of this application have discovered that in some tasks, the differences in training samples across different training batches are significant. For example, in image generation tasks, the semantic complexity and category composition of images used as training samples in different training batches vary greatly. If only the balanced invocation of expert networks within a single training batch is guaranteed, it may be impossible to guarantee the balanced invocation of expert networks from a global perspective, resulting in the problem of "local equilibrium, global imbalance." In this solution, by analyzing the load imbalance of each expert network in multiple historical training rounds and controlling the load of each expert network in the current training batch, it is possible to ensure that each expert network achieves long-term equilibrium on the model training timeline, that is, to achieve balanced invocation of expert networks from a global perspective.

[0061] In one optional approach of this application, the initial expert weights are adjusted based on the historical call information of each expert network in previous training batches to obtain the target expert weights, including: Get the historical call frequency of each expert network in the previous preset number of consecutive historical training batches; Based on the difference between the historical call frequency and the preset equalization frequency, the historical load deviation of each expert network is determined. The preset equalization frequency is related to the number of expert networks. The initial expert weights are adjusted based on historical load deviations to obtain the target expert weights.

[0062] Among them, the preset number of consecutive historical training batches preceding the current training batch can be understood as a "sliding time window" on the model training timeline. The historical call frequency of each expert network within this "sliding time window" can quantify the historical call information of each expert network.

[0063] The preset equalization frequency is the expected frequency at which each expert network is invoked under the ideal state of complete equalization.

[0064] The preset equalization frequency is directly related to the number of expert networks. For example, if the number of expert networks is E, the preset equalization frequency can be 1 / E, which means that in the ideal state of perfect equalization, each expert is called at the same expected frequency.

[0065] Historical load bias is the difference between the historical call frequency and the preset equalization frequency. In other words, it is the difference between the actual call frequency and the ideal call frequency of each expert network in history. It can be used to quantify the load bias of each expert network in multiple consecutive historical training rounds.

[0066] Adjusting the initial expert weights based on historical load bias involves dynamically adjusting the load of each expert network at the current training frequency based on the load bias of each expert network in multiple consecutive historical training rounds, so that the load distribution of multiple expert networks converges towards a long-term equilibrium state.

[0067] In this scheme, by maintaining a preset number of consecutive historical training batches before the current training batch as a "sliding time window," a mechanism similar to "moving average" is adopted. This effectively smooths the load fluctuations in the current training batch and prevents the load on the expert network from fluctuating drastically in the short term due to imbalances in training samples (for example, one training batch contains images of people, while another training batch contains images of landscapes). It also avoids long-term load imbalances.

[0068] In one optional embodiment of this application, the historical load deviation of each expert network is determined based on the difference between the historical call frequency and the preset equalization frequency, including: The difference between the historical call frequency and the preset equalization frequency is determined as the first deviation; The historical load deviation of the previous historical training batch of the current training batch is determined as the second deviation; Based on the first bias and the second bias, the historical load bias of each expert network in the current training batch is determined.

[0069] The first deviation represents the deviation of the load of each expert network from the ideal equilibrium state within the most recent "sliding time window". It can reflect the latest local load imbalance.

[0070] The second bias represents the accumulated long-term load bias up to the previous training batch. It includes load biases that are longer than the "sliding time window" and can reflect the inertia of load bias.

[0071] In this scheme, the historical load deviation determined based on the first and second deviations is integrated with the latest observed load deviation and the long-term accumulated load deviation. This allows the system to respond to recent load changes without being swayed by drastic short-term load fluctuations, achieving smooth and abrupt adjustment of the load on each expert system. Simultaneously, it imbues the system with a "memory" and "inertia" of long-term load deviations. This "memory" capability enables the system to effectively distinguish between accidental short-term load fluctuations (such as random deviations in a training batch of data) and trend-based long-term load imbalances (such as persistently high loads in an expert network). By strongly correcting the latter and smoothly filtering the former, true long-term load balancing is achieved more intelligently.

[0072] For example, the calculation method of historical load deviation can be expressed by the following formula (1).

[0073] ;Formula (1) in, This indicates that the current training batch is the [number]. One training batch, Indicates the first Historical load bias of each training batch Indicate the first Historical load bias of each training batch Indicates the frequency of historical calls. Indicates the preset equalization frequency. It is a hyperparameter, also known as the momentum factor, which is used to control the response speed to load deviations within the "sliding time window".

[0074] In this example, A fixed value of 0.999 can be used to ensure reliance on long-term load deviations and reduce sensitivity to short-term load deviations.

[0075] In this example, the length of the "sliding time window" needs to be set to a fixed value, i.e., a preset number of historical training epochs. If this preset number is too short, the smoothing effect on load deviation will be insufficient; if it is too long, the response to load deviation will be too sluggish, requiring fine-tuning of the preset number. In this solution, by setting... Setting it to a value close to 1 reduces sensitivity to the length of the "sliding time window" and also reduces the reliance on fine-tuning.

[0076] For example, the calculation method of the target expert weight can be expressed by the following formula (2).

[0077] ;Formula (2) in, Indicates the target expert weight. Indicates the initial expert weights. Indicates the first Historical load bias of each training batch Indicates The sign function as a variable. This represents the load balancing adjustment factor; in this example, It is usually set to 0.001.

[0078] It should be noted that the terms "first" and "second" used in this disclosure do not have any limitations on size, order, or quantity; they are merely used to distinguish between two different deviations, such as "first deviation" and "second deviation."

[0079] In one optional approach of this application, training the model for the current training batch based on the invocation probability includes: Based on the invocation probability, each expert network is invoked to process the training samples of the current training batch, and the processing results of each expert network are obtained. The output of the expert network is weighted and fused based on the initial expert weights to obtain the model processing result for the current training batch. The model loss is calculated based on the model processing results and the preset training objectives, and the model parameters are updated based on the model loss to complete the model training for the current training batch.

[0080] After adjusting the invocation probabilities of each expert network, the expert networks can be activated based on their invocation probabilities for each training sample. Each activated expert network then independently processes its assigned training sample and generates a corresponding output (i.e., the "processing result"). The processing results of each expert network are then weighted and fused using their initial weights to obtain the final model output (i.e., the "model processing result"). Finally, the model loss is calculated based on the model processing result and the preset training objective, and the model parameters are updated based on this loss.

[0081] In this embodiment, the target expert weight is a parameter adjusted to maintain the load balance of each expert network. When an expert network is invoked, its contribution to the overall output of the model should still be determined by its intrinsic matching degree with the input training samples (i.e., the "initial expert weight") to ensure the accuracy of the model output.

[0082] In this scheme, by decoupling the load balancing of each expert network from the forward computation of the model, the expert weight adjustment made for load balancing will not affect the quality of the model processing results, thereby ensuring the training effect of the model.

[0083] In the early stages of model training, the model has not yet fully learned the features of various training samples. At this time, the gating network's allocation of initial expert weights is random and inaccurate. If the initial expert weight ratio is directly adjusted, it may cause additional load bias. In this case, to ensure load balance among expert networks, we can start from the training sample level and actively balance the distribution of different categories of training samples in each training batch. As an optional approach in this application, the above method also includes: Obtain the original sample set that includes samples from multiple categories; Based on the total number of samples in the original sample set, the number of samples in each type, and the model training progress corresponding to the current training round, determine the sampling weights corresponding to each category. The original sample set is sampled based on the sampling weights to obtain the training samples for the current training round.

[0084] In this embodiment of the application, the original sample set can be understood as the complete set of training samples, and the training samples used in each training round can be selected from the original sample set.

[0085] The training samples in the original sample set can be divided into multiple categories. For example, in image generation tasks, the categories can be "people", "landscape", "animals", "architecture", "cartoon", etc.

[0086] Sampling weight refers to the proportion of training samples drawn from each category when sampling training samples in a training round.

[0087] Model training progress refers to the stage a model is in during the training process, usually quantified as the proportion of the current training round or the number of training steps completed to the total number of training rounds / total steps.

[0088] In this scheme, by determining the sampling weight based on the total number of samples in the original sample set, the number of samples under each type, and the model training progress, a sampling strategy related to the category distribution of samples and the model training progress can be provided so as to perform dynamic sampling according to the model training progress, so as to ensure that the extracted training samples can be in a balanced state that is adapted to the model training progress.

[0089] In this scheme, by adopting corresponding load balancing strategies at the training sample balancing level and the expert weight optimization level, the load balancing of each expert network during model training can be effectively guaranteed, thus ensuring the training effect of the model.

[0090] In one optional approach of this application, sampling weights corresponding to each category are determined based on the total number of samples in the original sample set, the number of samples in each category, and the model training progress corresponding to the current training round, including: Obtain the balance coefficient related to the model training progress in the current training round; Based on the total number of samples in the original sample set, the number of samples in each category, and the balance coefficient, the sampling weights corresponding to each category are determined. The balance coefficient is used to make the sampling weights of each category approach uniformity when the model training progress meets the first preset progress condition, and to make the sampling weights of each category approach the actual proportion of each category in the sample set when the model training progress meets the second preset progress condition.

[0091] In this embodiment, the balance coefficient is a dynamic variable related to the training progress, used to control the sampling strategy to smoothly transition between uniform sampling and sampling according to the actual number of training samples of each category based on the model training progress.

[0092] The first preset progress condition indicates that the model is in the early stage of training, for example, the training progress is <20%. At this time, by controlling the sampling strategy to approach uniform sampling, the sampled training samples contain more categories, so that the training samples of each category have a balanced exposure, which makes it easier for the model to learn the broad features of different categories of training samples and prevents the model from getting overfitted to the training samples of the category with a large amount of data in the early stage of training.

[0093] The second preset progress condition indicates that the model is in the later stage of training, for example, training progress > 80%. At this time, by controlling the sampling strategy to sample according to the actual proportion of training samples of each category, the model's final optimization target is aligned with the real data distribution, avoiding insufficient learning of mainstream data patterns due to long-term forced equilibration.

[0094] Uniform sampling ensures that the sampled training samples include a wide range of categories, giving each category a balanced exposure. This allows the model to learn a broad range of features from different categories and prevents the model from overfitting to the category with the largest amount of data in the early stages of training.

[0095] For example, the sampling weight can be calculated using the following formula (3).

[0096] ;Formula (3) in, This represents the total number of training samples in the original sample set. Indicates category The number of training samples, Sampling weights. Represents the balance coefficient. The value range of is [0, 1].

[0097] In this example, in the early stages of training A relatively large value, such as 1, can be set to ensure that the sampling ratio for different categories is nearly balanced, thus preventing the model from overfitting to a larger number of categories in the early stages of training. As training progresses, this value can be gradually reduced. The value of is chosen to gradually approximate the natural data distribution, especially in the later stages of training. A smaller value, such as 0, can be set so that the sampling distribution is ultimately based on natural sampling according to the data distribution.

[0098] Based on this scheme, the class composition of training samples in each training round can be made more reasonable, reducing the risk of cumulative load bias from the source.

[0099] In one alternative embodiment of this application, the model is an image generation model, the training samples are images, and the training samples are divided into multiple categories based on the image content.

[0100] The model in this application embodiment can be an image generation model, such as a multi-modal diffusion model (MMDiT), and the training samples are divided into multiple categories based on the image content, such as people, natural scenery, architecture, animation illustrations, etc.

[0101] In response to the significant differences in training samples of different categories in image generation tasks (such as differences between people and buildings, and between buildings and animations), the solution provided in this application can effectively overcome the above differences, ensure load balance during model training, and thus effectively improve the generalization ability and stability of MMDit.

[0102] In the technical solution of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0103] It should be noted that the images used in this application during model training are from public datasets and are not images specific to any particular user, nor do they reflect any personal information of any particular user.

[0104] According to another embodiment, an image generation method is provided. Figure 3 This is a flowchart of an image generation method provided in an embodiment of this application. The method can be generated by... Figure 1 The server-side execution in the system shown. For example... Figure 3As shown, the method may include the following steps: Step S310: Obtain the image to be processed; Step S320: Input the image to be processed into the image generation model to obtain the processed image output by the image generation model; wherein, the image generation model is trained by the model training method described above.

[0105] In this embodiment, the image generation model is trained using the model training method described above. Since the model training method can dynamically optimize the calling probability of each expert network, the load of each expert network is balanced, thereby improving the training effect of the model. This results in the image generation model trained based on the model training method having better processing capabilities, especially improving the processing effect on images to be processed that have different categories and significant differences, thereby generating higher quality processed images.

[0106] The methods provided in this application embodiment can be applied to various application scenarios, including but not limited to: MoE training scenarios.

[0107] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0108] According to another embodiment, a model training apparatus is provided. Figure 4 A schematic block diagram of the model training apparatus according to one embodiment is shown, the apparatus being disposed in Figure 1 The server side in the illustrated architecture. For example... Figure 4 As shown, the model training device 400 includes: The expert weight determination module 410 is used to determine the initial expert weights of each expert network based on the training samples in the current training batch using a gating network. The expert weight adjustment module 420 is used to adjust the initial expert weights based on the historical call information of each expert network in previous training batches before the current training batch, so as to obtain the target expert weights. The model training module 430 is used to determine the probability of calling each expert network in the current training batch based on the target expert weights, and to train the model for the current training batch according to the calling probability.

[0109] As an optional method, the expert weight adjustment module 420 is specifically used for: Get the historical call frequency of each expert network in the previous preset number of consecutive historical training batches; Based on the difference between the historical call frequency and the preset equalization frequency, the historical load deviation of each expert network is determined. The preset equalization frequency is related to the number of expert networks. The initial expert weights are adjusted based on historical load deviations to obtain the target expert weights.

[0110] As an optional approach, when determining the historical load deviation of each expert network based on the difference between the historical call frequency and the preset equalization frequency, the expert weight adjustment module 420 is specifically used for: The difference between the historical call frequency and the preset equalization frequency is determined as the first deviation; The historical load deviation of the previous historical training batch of the current training batch is determined as the second deviation; Based on the first bias and the second bias, the historical load bias of each expert network in the current training batch is determined.

[0111] As an optional method, when training the model for the current training batch based on the calling probability, the model training module 430 is specifically used for: Based on the invocation probability, each expert network is invoked to process the training samples of the current training batch, and the processing results of each expert network are obtained. The output of the expert network is weighted and fused based on the initial expert weights to obtain the model processing result for the current training batch. The model loss is calculated based on the model processing results and the preset training objectives, and the model parameters are updated based on the model loss to complete the model training for the current training batch.

[0112] As an optional approach, the above-mentioned device also includes an equalization sampling module (not shown in the figure), used for: Obtain the original sample set that includes samples from multiple categories; Based on the total number of samples in the original sample set, the number of samples in each type, and the model training progress corresponding to the current training round, determine the sampling weights corresponding to each category. The original sample set is sampled based on the sampling weights to obtain the training samples for the current training round.

[0113] As an optional approach, the equalization sampling module (not shown in the figure) determines the sampling weights for each category based on the total number of samples in the original sample set, the number of samples in each category, and the model training progress corresponding to the current training epoch. Specifically, it is used for: Obtain the balance coefficient related to the model training progress in the current training round; Based on the total number of samples in the original sample set, the number of samples in each category, and the balance coefficient, the sampling weights corresponding to each category are determined. The balance coefficient is used to make the sampling weights of each category approach uniformity when the model training progress meets the first preset progress condition, and to make the sampling weights of each category approach the actual proportion of each category in the sample set when the model training progress meets the second preset progress condition.

[0114] As an alternative approach, the model is an image generation model, the training samples are images, and the training samples are divided into multiple categories based on the image content.

[0115] According to another embodiment, an image generation apparatus is provided. Figure 5 A schematic block diagram of an image generation apparatus according to one embodiment is shown, the apparatus being disposed in Figure 1 The server side in the illustrated architecture. For example... Figure 5 As shown, the image generation apparatus 500 includes: Image acquisition module 510 is used to acquire the image to be processed; The image generation module 520 is used to input the image to be processed into the image generation model and obtain the processed image output by the image generation model; The image generation model is trained using the model training method described above.

[0116] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. 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 this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0117] In addition, embodiments of this application also provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of any of the methods in the foregoing method embodiments.

[0118] And an electronic device, comprising: One or more processors; and A memory associated with one or more processors, the memory being used to store program instructions that, when read and executed by one or more processors, perform the steps of any of the methods in the foregoing method embodiments.

[0119] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the methods in the foregoing method embodiments.

[0120] in, Figure 6 An exemplary architecture of an electronic device is shown, which may include a processor 610, a video display adapter 611, a disk drive 612, an input / output interface 613, a network interface 614, and a memory 620. The processor 610, video display adapter 611, disk drive 612, input / output interface 613, network interface 614, and memory 620 can communicate with each other via a communication bus 630.

[0121] The processor 610 can be implemented using a general-purpose CPU, microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits to execute relevant programs and implement the technical solution provided in this application.

[0122] The memory 620 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 620 can store the operating system 621 for controlling the operation of the electronic device 600, and the basic input / output system (BIOS) 622 for controlling the low-level operations of the electronic device 600. Additionally, it can store a web browser 623, a data storage management system 624, and a model training or image generation device 625, etc. The aforementioned model training or image generation device 625 can be the application program that specifically implements the aforementioned steps in the embodiments of this application. In summary, when the technical solution provided in this application is implemented through software or firmware, the relevant program code is stored in the memory 620 and is called and executed by the processor 610.

[0123] Input / output interface 613 is used to connect input / output modules to realize information input and output. Input / output modules can be configured as components in the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touch screens, microphones, various sensors, etc., and output devices may include displays, speakers, vibrators, indicator lights, etc.

[0124] Network interface 614 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0125] Bus 630 includes a pathway for transmitting information between various components of the device, such as processor 610, video display adapter 611, disk drive 612, input / output interface 613, network interface 614, and memory 620.

[0126] It should be noted that although the above-described device only shows the processor 610, video display adapter 611, disk drive 612, input / output interface 613, network interface 614, memory 620, bus 630, etc., in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the solution of this application, and does not necessarily include all the components shown in the figures.

[0127] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer program product. This computer program product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in various embodiments or some parts of the embodiments of this application.

[0128] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A model training method, characterized in that, The model includes a gated network and multiple expert networks, and the method includes: Using the gating network, the initial expert weights corresponding to each expert network are determined based on the training samples in the current training batch; Based on the historical call information of each expert network in previous training batches, the initial expert weights are adjusted to obtain the target expert weights. Based on the target expert weights, the probability of calling each of the expert networks in the current training batch is determined, and the model is trained for the current training batch according to the calling probabilities.

2. The method according to claim 1, characterized in that, The step of adjusting the initial expert weights based on historical call information of each expert network in previous training batches to obtain the target expert weights includes: Obtain the historical call frequency of each expert network in a preset number of consecutive historical training batches preceding the current training batch; Based on the difference between the historical call frequency and the preset equalization frequency, the historical load deviation corresponding to each expert network is determined, and the preset equalization frequency is related to the number of expert networks; The initial expert weights are adjusted based on the historical load deviations to obtain the target expert weights.

3. The method according to claim 2, characterized in that, The step of determining the historical load deviation of each expert network based on the difference between the historical call frequency and the preset equalization frequency includes: The difference between the historical call frequency and the preset equalization frequency is determined as the first deviation; The historical load deviation of the previous historical training batch of the current training batch is determined as the second deviation; Based on the first deviation and the second deviation, the historical load deviation of each expert network in the current training batch is determined.

4. The method according to claim 1, characterized in that, The step of training the model for the current training batch based on the invocation probability includes: Based on the invocation probability, each of the expert networks is invoked to process the training samples of the current training batch, and the processing results of each expert network are obtained. The output of the expert network is weighted and fused based on the initial expert weights to obtain the model processing result of the current training batch; The model loss is calculated based on the model processing results and the preset training objective, and the model parameters are updated based on the model loss to complete the model training for the current training batch.

5. The method according to claim 1, characterized in that, Also includes: Obtain the original sample set that includes samples from multiple categories; Based on the total number of samples in the original sample set, the number of samples under each type, and the model training progress corresponding to the current training round, the sampling weights corresponding to each category are determined. The original sample set is sampled based on the sampling weights to obtain the training samples for the current training round.

6. The method according to claim 5, characterized in that, The step of determining the sampling weights corresponding to each category based on the total number of samples in the original sample set, the number of samples under each category, and the model training progress corresponding to the current training round includes: Obtain the balance coefficient related to the model training progress corresponding to the current training round; Based on the total number of samples in the original sample set, the number of samples under each type, and based on the balance coefficient, the sampling weight corresponding to each category is determined; The balance coefficient is used to make the sampling weights corresponding to each category approach uniformity when the model training progress meets the first preset progress condition, and to make the sampling weights corresponding to each category approach the actual proportion of each category in the sample set when the model training progress meets the second preset progress condition.

7. The method according to any one of claims 1-6, characterized in that, The model is an image generation model, the training samples are images, and the training samples are divided into multiple categories based on the image content.

8. An image generation method, characterized in that, include: Obtain the image to be processed; The image to be processed is input into the image generation model to obtain the processed image output by the image generation model; The image generation model is trained using the model training method described in any one of claims 1-7.

9. A model training device, characterized in that, The model includes a gated network and multiple expert networks, and the device includes: The expert weight determination module is used to determine the initial expert weights corresponding to each expert network based on the training samples in the current training batch using the gating network. The expert weight adjustment module is used to adjust the initial expert weights based on the historical call information of each expert network in the historical training batches before the current training batch, so as to obtain the target expert weights. The model training module is used to determine the calling probability of each of the expert networks in the current training batch based on the target expert weights, and to train the model in the current training batch according to the calling probability.

10. An image generation apparatus, characterized in that, include: The image acquisition module is used to acquire the image to be processed. An image generation module is used to input the image to be processed into an image generation model to obtain a processed image output by the image generation model; The image generation model is trained using the model training method described in any one of claims 1-7.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the method according to any one of claims 1-8.

12. An electronic device, characterized in that, include: One or more processors; as well as A memory associated with the one or more processors, the memory being used to store program instructions that, when read and executed by the one or more processors, perform the steps of the method according to any one of claims 1-8.

13. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the method according to any one of claims 1-8.