Task reasoning method based on hybrid expert model

By setting routing score thresholds and dynamic lexical allocation for the expert feedforward network of the hybrid expert model, the problems of unbalanced resource allocation and load imbalance in the existing routing mechanism are solved, thereby improving the inference performance and applicability of the model.

CN123140265APending Publication Date: 2026-11-20GUANGZHOU XIAOPENG MOTORS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611201378.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-07
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing hybrid expert model routing mechanisms struggle to effectively balance resource allocation, load balancing, and inference performance, especially in tasks requiring high causality, stability, and incremental inference.

Method used

A novel routing mechanism is adopted, which dynamically adjusts the lexical allocation by setting a routing score threshold for each expert feedforward network, ensuring load balancing and reasonable resource allocation for each expert feedforward network. This includes allocating target lexicals to each expert feedforward network based on the routing score and threshold, and optimizing the inference results through an aggregation matrix.

Benefits of technology

It improves the inference performance and applicability of hybrid expert models, achieves load balancing and reasonable resource allocation, and is suitable for tasks with high requirements for causality, stability and incremental inference.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123140265A_ABST
    Figure CN123140265A_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a task reasoning method based on a mixed expert model, the mixed expert model comprises a plurality of first expert feedforward networks, and the method comprises the following steps: performing word segmentation processing on a text sequence to obtain a plurality of word units; according to a routing score between each word unit and each first expert feedforward network and a routing score threshold corresponding to each first expert feedforward network, assigning a target word unit to each first expert feedforward network, the target word unit being at least one of the plurality of word units; and processing the assigned target word unit through each first expert feedforward network to obtain a reasoning result. The embodiment of the application effectively balances expert resource allocation and load balancing, thereby improving the reasoning effect of the mixed expert model and improving the application range of the model reasoning task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and includes, but is not limited to, a task reasoning method based on a hybrid expert model. Background Technology

[0002] With the rapid development of large-scale pre-trained models and generative artificial intelligence, Mixture of Experts (MoE) models have emerged and are widely used in natural language processing tasks, such as intelligent question answering and information extraction.

[0003] Hybrid expert models typically include multiple expert feedforward networks and a routing module. When processing text input to a hybrid expert model, the input text is divided into multiple tokens. The routing module is used to determine which expert feedforward networks to assign each token to for processing. This process is called the routing mechanism.

[0004] In the process of developing this application, the inventors discovered that common routing mechanisms are mainly Top-Down routing. The K-selection mechanism assigns each term to a number of expert feedforward networks with the highest routing scores. However, this mechanism has a fixed and identical number of expert feedforward networks per term, and it cannot dynamically adjust the number of expert feedforward networks based on the processing difficulty and complexity of the term, resulting in uneven resource allocation and difficulty in ensuring load balancing of the expert feedforward networks. Other routing mechanisms involve each expert feedforward network selecting a number of terms with the highest routing scores. While this mechanism can balance the load of the expert feedforward networks, it is not suitable as a hybrid expert model with high requirements for causality, stability, and incremental inference.

[0005] This demonstrates that existing routing mechanisms in hybrid expert models struggle to effectively balance resource allocation, load balancing, and inference performance. Therefore, improvements to existing routing mechanisms are necessary. Summary of the Invention

[0006] In view of this, this application provides a task reasoning method based on a hybrid expert model, which solves the technical problem that existing routing mechanisms are unable to effectively balance resource allocation, load balancing and reasoning performance.

[0007] This application provides a task reasoning method based on a hybrid expert model, wherein the hybrid expert model includes multiple first expert feedforward networks, and the method includes: The text sequence is segmented into multiple word units, and the text sequence is the problem description text input to the hybrid expert model. Based on the routing score between each lexical unit and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network, a target lexical unit is assigned to each first expert feedforward network, wherein the target lexical unit is at least one of the plurality of lexical units; The assigned target lexical units are processed by each of the first expert feedforward networks to obtain an inference result, which is the response description text corresponding to the question description text.

[0008] In the above embodiments, unlike the routing mechanism where each expert feedforward network selects a fixed number of terms, the routing mechanism in this application embodiment has a routing score threshold for each first expert feedforward network. Therefore, whether a term is assigned to a particular first expert feedforward network can be determined independently, rather than by a predetermined fixed number of experts. Furthermore, whether a term is assigned to a particular first expert feedforward network is determined jointly by the routing score and the routing score threshold of that first expert feedforward network. This allows the number of first expert feedforward networks corresponding to each target term, and the number of target terms corresponding to each first expert feedforward network, to change dynamically, effectively balancing expert resource allocation and load balancing, thereby improving the inference performance of the hybrid expert model. Moreover, it does not require global sorting of the routing score of the current term and the routing scores of subsequent terms, making this routing mechanism applicable to models with high requirements for causality, stability, and incremental inference, effectively improving the applicability of the model's inference tasks.

[0009] In some embodiments, allocating target lexical units to each first expert feedforward network based on the routing score between each lexical unit and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network includes: For each of the first expert feedforward networks, the tokens in the routing scores that are greater than the corresponding routing score threshold are determined as the initial tokens of the first expert feedforward network; The initial lexical unit is determined as the target lexical unit, and the corresponding target lexical unit is allocated to the first expert feedforward network.

[0010] In the above embodiments, for each first expert feedforward network, the tokens with routing scores greater than the corresponding routing score threshold can be determined as the initial tokens of the first expert feedforward network, and the initial tokens can be determined as the target tokens. Since the routing score represents the matching degree between each first expert feedforward network and each token, taking the tokens with routing scores greater than the corresponding routing score threshold as the initial tokens means that the tokens with a high matching degree are assigned to the corresponding first expert feedforward network, which effectively improves the rationality of expert allocation.

[0011] In some embodiments, after determining the terms in the routing scores that are greater than the corresponding routing score threshold as initial terms for the first expert feedforward network, the method further includes: For each of the first expert feedforward networks, if the current load of the first expert feedforward network is greater than the target load, the routing scores between the first expert feedforward network and the corresponding initial token are sorted from high to low to obtain the routing sorting result of the first expert feedforward network. The current load is used to indicate the number of target tokens allocated to the first expert feedforward network, and the target load is used to indicate the number of planned tokens that the first expert feedforward network can process. The first M initial terms in the routing sorting result are determined as the target terms of the first expert feedforward network, where M is the remaining load of the first expert feedforward network and M is an integer greater than or equal to 1.

[0012] In the above embodiments, for each first expert feedforward network, if the current load of the first expert feedforward network is greater than the target load, not all initial words exceeding the processing capacity will be allocated to the first expert feedforward network. Instead, the first M initial words will be determined as target words to be allocated to the first expert feedforward network based on the routing ranking result. This method prioritizes the retention of initial words with higher routing scores within the available capacity, so that limited expert computing resources are prioritized for words with a high degree of matching with the first expert feedforward network. This achieves dynamic adjustment of expert allocation, avoids each first expert feedforward network from processing words exceeding its load capacity, and ensures load balance among the first expert feedforward networks.

[0013] In some embodiments, after assigning target lexical units to each of the first expert feedforward networks, the method further includes: For each of the first expert feedforward networks, the routing score threshold is updated based on the current load and target load of the first expert feedforward network, so that the current load is equal to the target load, and the number of the first expert feedforward networks corresponding to each term is equal to the preset number of expert feedforward networks. The current load is used to indicate the number of target lexical units allocated to the first expert feedforward network, and the target load is used to indicate the number of planned lexical units that the first expert feedforward network can process.

[0014] In the above embodiments, the routing score threshold is updated based on the deviation between the current load and the target load of the first expert feedforward network. By changing the routing score threshold, the number of terms subsequently allocated to each first expert feedforward network can be adjusted, so that the current load approaches the target load, and the number of first expert feedforward networks corresponding to each term approaches the preset number of expert feedforward networks. This achieves the purpose of balancing the load of each first expert feedforward network and also balances the computational load of the first expert feedforward network. In other words, the allocation result can simultaneously satisfy the expert load constraint and the computational budget constraint, thereby improving the stability of the hybrid expert model in performing inference tasks.

[0015] In some embodiments, updating the routing score threshold based on the current load and target load of the first expert feedforward network includes: If the current load is greater than the target load, increase the routing score threshold; If the current load is less than the target load, decrease the routing score threshold.

[0016] In the above embodiments, the method for updating the routing score threshold can be determined based on the load status of the first expert feedforward network. When the first expert feedforward network is overloaded, the routing score threshold is increased; when the first expert feedforward network is underloaded, the routing score threshold is decreased. This update method allows the change of the routing score threshold to be adjusted based on the actual current load, which can avoid allocating too many or too few terms to the first expert feedforward network, thus optimizing the allocation result and effectively balancing the expert computation and model inference performance.

[0017] In some embodiments, the routing score threshold includes a global threshold and a local threshold, and updating the routing score threshold based on the current load and target load of the first expert feedforward network includes: The current average number of experts corresponding to the plurality of lexical units is obtained based on the number of the plurality of lexical units and the number of the first expert feedforward networks corresponding to each lexical unit; Based on the current average number of experts and the target average number of experts corresponding to the plurality of lexical units, the global threshold is updated to obtain the updated global threshold. The global threshold is negatively correlated with the total number of the first expert feedforward network activated by the plurality of lexical units. Based on the current load and the target load, the local threshold is updated to obtain the updated local threshold, which is negatively correlated with the number of target lexical units allocated to each of the first expert feedforward networks; The routing score threshold is updated based on the updated global threshold and the updated local threshold.

[0018] In the above embodiments, the global threshold is updated based on the current average number of experts corresponding to multiple lexical units and the target average number of experts corresponding to multiple lexical units, thereby achieving the purpose of adjusting the total number of first expert feedforward networks activated by lexical units. This allows for overall adjustment of the computational load of the first expert feedforward networks. Simultaneously, the local threshold is updated based on the current load and target load of each first expert feedforward network, enabling the number of target lexical units allocated to each first expert feedforward network to be adjusted independently, thus controlling the load balance of each first expert feedforward network. Based on this, the use of global and local two-level threshold control not only avoids the situation where the overall computational load deviates from the budget when only local adjustment is performed, but also avoids the problem of not being able to handle the load differences between each first expert feedforward network when only global adjustment is performed. This effectively improves the fine-grainedness of computational resource allocation and achieves a balance between computational load and inference performance in the hybrid expert model.

[0019] In some embodiments, updating the global threshold based on the current average number of experts and the target average number of experts corresponding to the plurality of lexical units includes: If the current average number of experts is greater than the target average number of experts, increase the global threshold; or if the current average number of experts is less than the target average number of experts, decrease the global threshold. The step of updating the local threshold based on the current load and the target load includes: If the current load is greater than the target load, increase the local threshold; or if the current load is less than the target load, decrease the local threshold.

[0020] In the above embodiments, by controlling the increase or decrease of the global threshold, the overall activation of experts can be suppressed when the number of activations of the first expert feedforward network exceeds the computational budget, and the overall expert computing power can be released when the number of activations is insufficient, thereby improving the utilization rate of expert computing resources. By controlling the increase or decrease of the local threshold, the load difference between each first expert feedforward network can be reduced, effectively balancing the computational load of each first expert feedforward network, thereby optimizing the allocation of expert computing resources.

[0021] In some embodiments, the method further includes: Based on the number of the plurality of lexical units and the target average number of experts corresponding to the plurality of lexical units, the computational cost of the target experts corresponding to the plurality of lexical units is obtained. The computational cost of the target experts is used to indicate the total number of computation pairs formed by the plurality of lexical units and the plurality of first expert feedforward networks. The target load is obtained based on the target expert computational load and the number of the plurality of first expert feedforward networks.

[0022] In the above embodiments, the target expert computational load is determined based on the number of multiple lexical units and the target average number of experts corresponding to multiple lexical units. Then, the target load is obtained based on the target expert computational load and the number of multiple first expert feedforward networks. This ensures that the total computational load of all lexical units is limited to the overall budget. This resource allocation method, which controls the computational load of each first expert feedforward network from the lexical unit dimension, allows the target expert computational load and target load to change dynamically when the number of lexical units changes, thereby adapting to the processing of text sequences of different lengths.

[0023] In some embodiments, for each of the first expert feedforward networks, the target load is determined based on a capacity factor, which includes at least one of the historical load of the first expert feedforward network, the hardware resources of the hybrid expert model, the importance of the first expert feedforward network, and the expert category of each of the first expert feedforward networks.

[0024] In the above embodiments, the target load is determined by a capacity factor composed of one or more factors, so that the target load of each first expert feedforward network can be dynamically changed based on at least one of the following: the historical load of the first expert feedforward network, the hardware resources of the hybrid expert model, the importance of the first expert feedforward network, and the expert category of each first expert feedforward network. This makes the setting dimensions of the target load more diversified and improves the processing capability of the first expert feedforward network.

[0025] In some embodiments, the process of processing the assigned target lexical units through each of the first expert feedforward networks to obtain the inference result includes: The first expert feedforward network processes the assigned target word, and the output result of each first expert feedforward network for each target word is obtained. For each target word, the output of the corresponding first expert feedforward network is fused to obtain a fusion result; The fusion result is aggregated according to the aggregation matrix to obtain the inference result. The aggregation matrix is ​​obtained by transposing the selection matrix constructed by the computation pairs consisting of the multiple lexical units and the multiple first expert feedforward networks. The selection matrix is ​​used to indicate the position of the target lexical unit corresponding to each computation pair in the text sequence.

[0026] In the above embodiments, the aggregation matrix obtained by the transpose transformation of the constructed selection matrix is ​​aggregated based on the computation of multiple word units and multiple first expert feedforward networks. The aggregation matrix can aggregate the fusion results of the first expert feedforward networks corresponding to each target word unit to the position of the same target word unit in the text sequence. This replaces the traditional method of index accumulation or scatter accumulation with linear operations of regular matrix multiplication, thereby avoiding problems such as irregular storage access, write conflicts, or atomic accumulation. Moreover, the aggregation matrix can realize the writing of the hidden state of word units and the writing back of expert output results, which can be adapted to hybrid expert models that do not support complex index writing and writing back, thus improving the applicability of the model in handling inference tasks.

[0027] In some embodiments, the hybrid expert model further includes multiple second expert feedforward networks, and the method further includes: Each word is processed by each second expert feedforward network to obtain the inference result corresponding to each second expert feedforward network; For each word, the inference results corresponding to the first expert feedforward network and the inference results corresponding to the second expert feedforward network are fused to obtain an initial inference result; The initial inference results of each term are fused to obtain the target inference result of the hybrid expert model.

[0028] In the above embodiments, by processing each lexical unit through each second expert feedforward network, the situation where some lexical units are not involved in task inference due to some lexical units not being assigned to the first expert feedforward network for processing can be avoided. Furthermore, it eliminates the need to assign some lexical units to the first expert feedforward network with low matching degree, thus avoiding the additional resource overhead of re-matching the first expert feedforward network and improving the accuracy of the task inference results. Moreover, since each second expert feedforward network can process each lexical unit and fuse the inference results corresponding to the first and second expert feedforward networks, the influence of the first expert feedforward network on the inference results can be reduced, effectively ensuring the accuracy and high reliability of the task inference results.

[0029] In some embodiments, the hybrid expert model further includes a routing module, and after the text sequence is segmented to obtain multiple tokens, the method further includes: Obtain the hidden state of each lexical element, wherein the hidden state is used to characterize the features of each lexical element; The routing module processes the hidden state of each word using a preset routing calculation function to obtain the initial routing score between each word and each of the first expert feedforward networks. The initial routing score is adjusted according to the inference difficulty of each term to obtain the routing score between each term and each first expert feedforward network, wherein the inference difficulty is positively correlated with the number of first expert feedforward networks corresponding to each term.

[0030] In the above embodiments, the allocation of the first expert feedforward network can be made based on the hidden state of the features of the included word in the context by a preset routing calculation function to obtain the corresponding initial routing score. After calculating the initial routing score, the inference difficulty of the word is introduced. Since the inference difficulty is positively correlated with the number of first expert feedforward networks corresponding to each word, the allocation of the first expert feedforward network is more reasonable, which improves the accuracy of subsequent expert feedforward network allocation, improves the utilization rate of expert computing resources, and is conducive to improving the inference effect of the hybrid expert model.

[0031] In some embodiments, the hybrid expert model comprises multiple hybrid expert layers, and the method further includes: The plurality of hybrid expert layers are divided into at least one routing group, and each routing group includes a target hybrid expert layer and at least one other hybrid expert layer; For each of the routing groups, the target hybrid expert layer performs the step of assigning a target word to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network; Each of the other hybrid expert layers assigns the target word to each of the first expert feedforward networks according to the allocation result of the target hybrid expert layer, and performs the step of processing the allocated target word through each of the first expert feedforward networks.

[0032] In the above embodiments, multiple hybrid expert layers are divided into at least one routing group. Each routing group includes a target hybrid expert layer that performs complete expert allocation and at least one other hybrid expert layer that reuses the allocation result. The other hybrid expert layers execute according to the allocation result determined by the target hybrid expert layer, thereby reducing the number of calls to the routing module. This reduces the repeated expert selection process within the routing group, thereby reducing the consumption of computing resources and communication overhead of the hybrid expert layer.

[0033] This application provides a task reasoning device based on a hybrid expert model, wherein the hybrid expert model includes multiple first expert feedforward networks, and the device includes: The processing module is used to perform word segmentation on the text sequence to obtain multiple word units, wherein the text sequence is the problem description text input to the hybrid expert model; The allocation module is configured to allocate a target word to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network, wherein the target word is at least one of the plurality of words; The reasoning module is used to process the assigned target lexical units through each of the first expert feedforward networks to obtain a reasoning result, which is the response description text corresponding to the question description text.

[0034] This application provides an electronic device, including a memory and a processor. The memory stores a computer program that can run on the processor, and the processor executes the program to implement the method described in this application.

[0035] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the methods described in this application.

[0036] This application provides a computer program product, including a computer program that, when executed by a processor, implements the methods described in this application. Attached Figure Description

[0037] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application.

[0038] Figure 1 This is a flowchart illustrating a task reasoning method based on a hybrid expert model disclosed in an embodiment of this application; Figure 2 This is a schematic diagram of a routing score matrix disclosed in an embodiment of this application; Figure 3 This is a flowchart illustrating another task reasoning method based on a hybrid expert model disclosed in an embodiment of this application; Figure 4 This is a schematic diagram of a routing scheduling method disclosed in an embodiment of this application; Figure 5 This is a flowchart illustrating another task reasoning method based on a hybrid expert model disclosed in an embodiment of this application; Figure 6 This is a schematic diagram of a process for updating a routing score threshold disclosed in an embodiment of this application; Figure 7 This is a flowchart illustrating another task reasoning method based on a hybrid expert model disclosed in an embodiment of this application; Figure 8This is a schematic diagram of an expert feedforward network inference process disclosed in an embodiment of this application; Figure 9 This is a schematic diagram illustrating an aggregation process disclosed in an embodiment of this application to obtain a reasoning result; Figure 10 This is a structural block diagram of a task reasoning device based on a hybrid expert model disclosed in an embodiment of this application; Figure 11 This is a structural block diagram of an electronic device disclosed in an embodiment of this application. Detailed Implementation

[0039] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the specific technical solutions of this application will be further described in detail below with reference to the accompanying drawings of the embodiments of this application. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application.

[0040] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0041] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0042] It should be noted that the terms "first, second, third" used in the embodiments of this application are used to distinguish similar or different objects and do not represent a specific order of objects. It can be understood that "first, second, third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0043] With the rapid development of large-scale pre-trained models and generative artificial intelligence, Mixture of Experts (MoE) models have emerged and are widely used in natural language processing tasks, such as intelligent question answering and information extraction.

[0044] Hybrid expert models typically include multiple expert feedforward networks and a routing module. When processing the text input to the hybrid expert model, the input text is divided into multiple tokens. The routing module is equivalent to a dynamic scheduler, used to determine the degree of matching between each token and different expert feedforward networks, in order to decide which expert feedforward networks to assign each token to for processing. This process is called the routing mechanism.

[0045] In the process of developing this application, the inventors discovered that common routing mechanisms are mainly Top-Down routing. The K-selection mechanism involves the routing module calculating the routing score between each term and each expert feedforward network. The term is then assigned to the expert feedforward networks with the highest routing scores, in descending order. This mechanism is often called a term-based routing mechanism. For example, if a hybrid expert model includes n expert feedforward networks and m terms, and the number of expert feedforward networks selected for each term is fixed at k, then for the j-th term, the routing module selects the k expert feedforward networks with the highest routing scores from the n expert feedforward networks. Under ideal equilibrium conditions, the number of terms processed by each expert feedforward network is approximately mk / n.

[0046] However, in practice, the above-mentioned routing mechanism based on lexical selection has the following problems: (1) Since the routing scores of different lexicals to each expert feedforward network are distributed differently, in the actual model training and model inference process, some expert feedforward networks usually process more lexicals and some expert feedforward networks process fewer lexicals, resulting in unbalanced load; (2) In the model training or static graph deployment scenario, the expert feedforward network with the most load determines the overall execution latency, which leads to a reduction in the processing efficiency of the model; (3) In order to meet the deployment requirements, it is usually necessary to set the maximum load capacity for each expert feedforward network. Lexicals exceeding the capacity may not be able to be calculated by the expert feedforward network originally selected; (4) A fixed number of expert feedforward networks cannot reflect the actual processing difficulty of different lexicals, so that semantically simple lexicals and semantically key lexicals obtain the same number of expert feedforward networks, that is, it is impossible to dynamically allocate computing resources according to the difficulty of lexicals, which reduces the utilization rate of computing resources. Therefore, the number of expert feedforward networks for each word in this routing mechanism is fixed and the same, and it is impossible to dynamically adjust the number of expert feedforward networks based on the processing difficulty and complexity of the word, resulting in uneven resource allocation and difficulty in ensuring load balancing of the expert feedforward networks.

[0047] Other routing mechanisms involve each expert feedforward network selecting a number of terms with the highest routing scores. In other words, each expert feedforward network chooses a number of terms from all the input terms. This mechanism is often called an expert-selection-based routing mechanism. The advantage of this mechanism is that the number of terms processed by each expert feedforward network can be set to a fixed value, theoretically achieving load balancing among the expert feedforward networks. Furthermore, different terms have different probabilities of being selected by different numbers of expert feedforward networks, allowing terms with more important semantics or higher processing difficulty to receive more expert computing resources.

[0048] However, in practice, the above-mentioned routing mechanism based on lexical selection still has the following main problems: (1) Since the mechanism is based on the expert feedforward network to select lexicals, the selection of the expert feedforward network depends on other lexicals in the same input sequence; (2) In autoregressive language models, the expert assignment of the current lexical may be affected by subsequent lexicals, that is, the expert assignment of the current lexical needs to be compared globally with subsequent lexicals that have not yet participated in the current reasoning process, which can easily lead to the destruction of causal reasoning requirements; (3) Every time a new lexical is generated, a global comparison needs to be performed again, which is difficult to adapt to incremental reasoning. Therefore, although this routing mechanism can balance the load of the expert feedforward network, it is not suitable as a hybrid expert model with high requirements for causality, stability and incremental reasoning.

[0049] It is evident that existing routing mechanisms in hybrid expert models struggle to effectively balance resource allocation, load balancing, and inference performance. Therefore, improvements to existing routing mechanisms are necessary.

[0050] In view of this, this application discloses a task reasoning method based on a hybrid expert model. The hybrid expert model includes multiple first expert feedforward networks. The method includes: segmenting a text sequence into multiple tokens; allocating a target token to each first expert feedforward network based on the routing score between each token and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network, wherein the target token is at least one of the multiple tokens; and processing the allocated target tokens through each first expert feedforward network to obtain a reasoning result. This application effectively balances expert resource allocation and load balancing, thereby improving the reasoning performance of the hybrid expert model and expanding the applicability of the model for reasoning tasks.

[0051] The task reasoning method based on a hybrid expert model proposed in this application is applied to electronic devices. Optionally, the electronic device can be a mobile device such as a vehicle, drone, airplane, ship, or robot, or a terminal device such as a mobile phone, laptop, or wearable device, or a server, server cluster, data center, or cloud computing platform. This application does not limit the type of electronic device.

[0052] The task reasoning method based on a hybrid expert model proposed in this application can be applied to the training or inference phase of natural language processing tasks performed using a hybrid expert model. Natural language processing tasks may include, but are not limited to, text reasoning tasks such as question-answering generation, dialogue generation, code generation, machine translation, information extraction, text classification, and multimodal content understanding.

[0053] It should be noted that hybrid expert models can be used as an independent model to perform task inference, or as part of the network structure in large language models, multimodal models, encoder models, etc.

[0054] In this embodiment of the application, the hybrid expert model includes multiple first expert feedforward networks and a routing module. The first expert feedforward network is an expert network that processes some lexical units based on the selection result of the routing mechanism, and can therefore also be understood as a private expert feedforward network, an optional expert feedforward network, etc.

[0055] The first expert feedforward network is used to learn tokens that handle different semantic features, task features, or contextual features during model training, and to process tokens that handle different semantic features, task features, or contextual features during model inference tasks to complete inference. The routing module is used to assign corresponding tokens to each first expert feedforward network.

[0056] It should be noted that the number of first-expert feedforward networks can be determined based on factors such as model parameter size, task type, hardware resources, and model inference accuracy.

[0057] It should be understood that a lexical unit is the basic unit used by the hybrid expert model when processing text. It can be understood as a lexical unit obtained by segmenting the text sequence input to the hybrid expert model. Optionally, a lexical unit can be a Chinese character, multiple Chinese characters, a word, a punctuation mark, or other encoding units, etc. This application does not limit the type of lexical unit segmentation.

[0058] First-expert feedforward networks can each have independent model parameters. Through model training, different first-expert feedforward networks can form different parameter distributions, making them suitable for processing lexical units with different semantic, linguistic, domain, task, or contextual features. In other words, first-expert feedforward networks can have the same network structure or different network structures; this application does not impose any restrictions on this.

[0059] Optionally, the hybrid expert model may include one or more hybrid expert layers, and each hybrid expert layer may include multiple first expert feedforward networks and routing modules.

[0060] To make the purpose and technical solution of this application clearer and more intuitive, the driving control method disclosed in this application will be described in detail below with reference to the accompanying drawings.

[0061] The following explanation and description are provided for the convenience of illustrating the task reasoning method based on a hybrid expert model provided in the embodiments of this application. Please refer to... Figure 1 , Figure 1 This is a flowchart illustrating a task reasoning method based on a hybrid expert model disclosed in an embodiment of this application. Figure 1 The method shown may include the following steps: Step 110: Perform word segmentation on the text sequence to obtain multiple word units.

[0062] In this embodiment of the application, the text sequence is the problem description text input to the hybrid expert model. The electronic device can perform word segmentation on the input problem description text to convert the problem description text into a word sequence that the hybrid expert model can process, i.e., multiple words.

[0063] Optionally, the problem description text can be any form of text. Therefore, any input text used to instruct the hybrid expert model to generate, predict, identify, or process the corresponding output content can be used as the problem description text in this embodiment.

[0064] In some implementations, the text sequence can be segmented using a word segmenter to convert the problem description text into multiple tokens. Optionally, the word segmenter can be a SentencePiece word segmenter, a WordPiece word segmenter, a character-based word segmenter, a byte-based word segmenter, etc. This application does not limit the type of word segmenter.

[0065] It should be understood that for the same text sequence, different types of tokenizers may produce different numbers of tokens.

[0066] For example, please see Figure 2 , Figure 2 This is a schematic diagram of a routing score matrix disclosed in an embodiment of this application. Figure 2 As shown, the input text sequence is "The Capital of China is Beijing". After word segmentation, multiple word units are obtained from this text sequence. to The characters are "The", "Capital", "of", "China", "is", and "Beijing".

[0067] It should be noted that, Figure 2 The multiple word units shown in the Chinese text, based on English words, are for illustrative purposes only. In practical applications, these word units may correspond to a word, a part of a word, etc.

[0068] It should be noted that the text sequences involved in the embodiments of this application are information authorized by the user or fully authorized by all parties.

[0069] Step 120: Based on the routing score between each term and each first expert feedforward network and the routing score threshold of each first expert feedforward network, assign a target term to each first expert feedforward network. The target term is at least one of multiple terms.

[0070] In this embodiment, the routing score is used to represent the degree of matching between each first expert feedforward network and each word. A higher routing score generally indicates that the first expert feedforward network is more suitable for processing the word. It should be understood that a higher routing score indicates a higher degree of matching between the first expert feedforward network and the word; conversely, a lower routing score indicates a lower degree of matching between the first expert feedforward network and the word.

[0071] In some implementations, after segmenting the text sequence to obtain multiple tokens, the method further includes: obtaining the hidden state of each token, where the hidden state is used to characterize the features of each token; processing the hidden state of each token using a preset routing calculation function through a routing module to obtain an initial routing score between each token and each first expert feedforward network; adjusting the initial routing score according to the inference difficulty of each token to obtain a routing score between each token and each first expert feedforward network, where the inference difficulty is positively correlated with the number of first expert feedforward networks corresponding to each token.

[0072] The hidden state is a set of internal features formed after a word is processed by the preorder network layer corresponding to the hybrid expert layer where the first expert feedforward network is located. It includes at least one of the semantic features, contextual features, sequence position features, task features, and language features of the word.

[0073] The routing module can read the hidden state of each word and process the hidden state of each word using a preset routing calculation function to calculate a routing score between each word and each expert feedforward network, thereby obtaining the initial routing score between each word and each first expert feedforward network.

[0074] Optionally, the preset route calculation function used by the routing module includes, but is not limited to, linear mapping function, Softmax routing function, multilayer perceptron, normalized dot product function, cosine similarity function, etc., and this application does not limit it.

[0075] Different terms may have varying degrees of impact on the inference results of a hybrid expert model and require different computational resources. For example, terms that are semantically simple, have clear context, high predictive certainty, or low information density can be processed using only a small number of first-expert feedforward networks; terms that are semantically critical, have semantic ambiguity, are highly context-dependent, are difficult to process, or have high predictive uncertainty may require more first-expert feedforward networks for processing.

[0076] Based on this, the initial routing score can be adjusted according to the inference difficulty of each lexical unit. It should be understood that inference difficulty is used to characterize the relative degree of computational resources required by the model to process the corresponding lexical unit, and inference difficulty can be determined based on at least one of the following: semantic difficulty of the lexical unit, dependence on context, degree of semantic ambiguity, prediction certainty, information density, etc.

[0077] Optionally, semantically simple, context-aware, predictively certain, or information-dense terms can be identified as terms with low inference difficulty; semantically critical, ambiguous, context-dependent, difficult to process, or predictively uncertain terms can be identified as terms with high inference difficulty. Therefore, for terms with high inference difficulty, the corresponding routing score can be increased, allowing for the allocation of more first-expert feedforward networks to improve the model's inference performance; conversely, for terms with low inference difficulty, the corresponding routing score can be decreased, allowing for the allocation of fewer first-expert feedforward networks to improve the utilization of expert computing resources.

[0078] Optionally, the routing score between each word and each first-expert feedforward network can typically be represented by a routing score matrix. Assuming the hybrid expert model comprises E first-expert feedforward networks, and the input text sequence is segmented into T words, the routing score matrix P can be represented as: ; in, The routing score matrix P represents the routing score between the T-th word and the E-th first expert feedforward network. The first row of the routing score matrix P represents the word. The routing score between each first expert feedforward network, and the second line represents the lexical units. The routing score between each first expert feedforward network, and so on.

[0079] As an example, please see Figure 2 ,like Figure 2 As shown, the input text sequence, after word segmentation, yields 6 word units (respectively...). , , , , , The hybrid expert model includes four first-expert feedforward networks (respectively...). , , , The routing module uses a preset routing calculation function to process the hidden state of each word, resulting in a routing score matrix P. Each row in the routing score matrix P represents the routing score between a word and each of the first expert feedforward networks, and each column represents the routing score between each first expert feedforward network and each word. For example, word... and the first expert feedforward network The routing score between them is 0.06, and the term score is [missing information]. and the first expert feedforward network The routing score between them is 0.18.

[0080] from Figure 2 It can be seen that the fifth row of the routing score matrix represents the tokens. The hidden state, after being processed by the routing module, is... to The routing scores between them were 0.47, 0.26, 0.17, and 0.03, respectively. Compared to other expert feedforward networks, the word segment... With expert feedforward network It has a high degree of matching.

[0081] By adopting the above implementation method, the allocation of the first expert feedforward network can be made according to the hidden state of the features of the included word in the context by using a preset routing calculation function to obtain the corresponding initial routing score. After calculating the initial routing score, the inference difficulty of the word is introduced. Since the inference difficulty is positively correlated with the number of first expert feedforward networks corresponding to each word, the allocation of the first expert feedforward network is more reasonable, which improves the accuracy of subsequent expert feedforward network allocation, improves the utilization rate of expert computing resources, and is conducive to improving the inference effect of the hybrid expert model.

[0082] As described in the foregoing embodiments, for the problem description text input to the hybrid expert model, existing routing mechanisms typically select the same number of expert feedforward networks for each term. For example, regardless of whether the semantics of the term are explicit or whether the degree of contextual dependence is the same, the highest-scoring expert feedforward networks are selected from multiple expert feedforward networks, making it difficult to adaptively select different numbers of expert feedforward networks for different terms.

[0083] Based on this, in this embodiment of the application, a corresponding routing score threshold is set for each first expert feedforward network. The routing score threshold is used to influence the number of target words allocated to each first expert feedforward network. The routing score can be compared with the routing score threshold corresponding to each first expert feedforward network to obtain the expert allocation result, thus achieving the purpose of allocating target words to each first expert feedforward network.

[0084] It should be noted that the routing score thresholds corresponding to each first expert feedforward network can be the same, different, or partially the same and partially different; this application does not impose any restrictions on this.

[0085] Optionally, the routing score threshold is negatively correlated with the number of target words, meaning that the larger the routing score threshold, the fewer target words are allocated; conversely, the smaller the routing score threshold, the more target words are allocated.

[0086] Optionally, allocation conditions can be set, which can be either that the route score is greater than a route score threshold, or that the route score is equal to the route score threshold.

[0087] A target lexical refers to a lexical assigned to and processed by a corresponding first expert feedforward network. For a first expert feedforward network, its target lexical can be one or more of multiple input lexicals; for a single lexical, the same lexical can be used as the target lexical of different first expert feedforward networks.

[0088] For example, such as Figure 2 As shown, assuming a first expert feedforward network The routing score threshold is 0.25, which can be used to identify tokens. to With the first expert feedforward network The routing scores (0.06, 0.18, 0.26, 0.31, 0.47, 0.23) are compared with a routing score threshold of 0.25. If the allocation condition is that the routing score must be greater than the routing score threshold, then the term... , , It can be assigned to the first expert feedforward network .

[0089] It should be understood that, compared to selecting a fixed number of highest routing scores among multiple experts, the routing score threshold allows for separate allocation decisions between each term and each first expert feedforward network. This eliminates the need for each term to select a fixed number of expert feedforward networks. Instead, based on the routing score thresholds corresponding to different first expert feedforward networks, the routing score between each term and each first expert feedforward network is compared with the routing score threshold for each first expert feedforward network, thereby allocating several target terms to each first expert feedforward network. Therefore, each target term can correspond to one or more first expert feedforward networks, and the number of first expert feedforward networks corresponding to different target terms can be different.

[0090] In some implementations, an expert bias can be set for the routing score, and then the routing score with the expert bias added can be compared with a routing score threshold. The expert bias is used to reflect the association between each term and each first expert feedforward network. The higher the expert bias, the more likely the term is to be assigned to the corresponding first expert feedforward network.

[0091] Optionally, a minimum number of experts can be set for each term. When the routing scores between a term and all first expert feedforward networks do not meet the allocation criteria (e.g., the routing score is greater than the routing score threshold), one or more first expert feedforward networks with the highest routing scores can be assigned to that term.

[0092] Optionally, a maximum number of experts can be set for each term. When the routing scores between a term and a number of first expert feedforward networks all meet the allocation conditions (e.g., the routing score is greater than the routing score threshold), a preset number of first expert feedforward networks with higher routing scores can be retained from the first expert feedforward networks that meet the routing score threshold to prevent a single term from consuming too many computing resources.

[0093] Step 130: The assigned target lexical units are processed through each first expert feedforward network to obtain the inference result.

[0094] In this embodiment of the application, each first expert feedforward network processes the target lexical assigned to it. The first expert feedforward network can process the target lexical based on features such as the lexical identifier, embedding vector, and hidden state corresponding to the target lexical to obtain the reasoning result, which is the answer description text corresponding to the question description text.

[0095] Optionally, when a target word is assigned to multiple first expert feedforward networks, the outputs of the multiple first expert feedforward networks for the target word can be fused to obtain the inference result corresponding to the target word. The fusion process includes, but is not limited to, weighted summation, concatenation, or gated fusion.

[0096] In some implementations, the hybrid expert model further includes multiple second expert feedforward networks. After processing the assigned target lexical units through each first expert feedforward network to obtain the inference result, each lexical unit can also be processed through each second expert feedforward network to obtain the inference result corresponding to each second expert feedforward network. For each lexical unit, the inference results corresponding to the first expert feedforward network and the inference results corresponding to the second expert feedforward network are fused to obtain the initial inference result. The initial inference results of each lexical unit are then fused to obtain the target inference result of the hybrid expert model.

[0097] As described above, the first expert feedforward network is used to selectively process certain terms, and different terms can be assigned to different numbers of first expert feedforward networks. When the routing score between a term and all first expert feedforward networks does not meet the allocation condition (e.g., the routing score is greater than the routing score threshold), the term may not be processed by any first expert feedforward network; or, when the number of target terms assigned to a first expert feedforward network exceeds the number of terms that first expert feedforward network can process, the excess target terms need to be removed. If the removed terms are not selected by other first expert feedforward networks, the removed target terms may not be processed by any first expert feedforward network. Based on this, in this embodiment, a second expert feedforward network can be used to process each term.

[0098] It should be noted that since the second expert feedforward network processes each word, it can be understood as a shared expert feedforward network, a general expert feedforward network, etc.

[0099] After the second expert feedforward network processes each word and obtains the inference result corresponding to each second expert feedforward network, for each word, the inference result corresponding to the first expert feedforward network and the inference result corresponding to the second expert feedforward network can be fused to obtain the initial inference result.

[0100] Optionally, the method of fusing the inference results corresponding to the first expert feedforward network and the second expert feedforward network may include: the inference results of the first expert feedforward network and the inference results of the second expert feedforward network may also be fused by methods such as concatenated linear mapping, gated fusion, element-wise maximum value, attention fusion, etc., to obtain the initial inference result.

[0101] It should be understood that, for each word, the initial inference results of each word are fused to obtain the target inference result of the hybrid expert model. This means that the result fusion is for the same word, combining the outputs of multiple first expert feedforward networks that process that word with the outputs of multiple second expert feedforward networks.

[0102] For example, suppose the hybrid expert model includes 64 first expert feedforward networks and 2 second expert feedforward networks. The current input number of words is 2048. The first expert feedforward networks perform calculations according to their respective target words. At the same time, the hidden states of the 2048 words are input into the two second expert feedforward networks, so that both second expert feedforward networks process the 2048 words.

[0103] Optionally, the first expert feedforward network and the second expert feedforward network can have the same network structure or different network structures.

[0104] By employing the above implementation method, processing each lexical unit through each second expert feedforward network avoids the situation where some lexical units are not involved in task inference due to their non-assignment to the first expert feedforward network. Furthermore, it eliminates the need to assign some lexical units to the first expert feedforward network with low matching scores, avoiding the additional resource overhead of re-matching the first expert feedforward network and improving the accuracy of task inference results. Moreover, since each second expert feedforward network can process each lexical unit and fuse the inference results from both the first and second expert feedforward networks, the influence of the first expert feedforward network on the inference results is reduced, effectively ensuring the accuracy and high reliability of the task inference results.

[0105] In some implementations, the hybrid expert model consists of multiple hybrid expert layers, which can be divided into at least one routing group, with each routing group including a target hybrid expert layer and at least one other hybrid expert layer.

[0106] A hybrid expert model can include multiple sequentially connected model layers, at least some of which can be hybrid expert layers. Each hybrid expert layer includes multiple first expert feedforward networks and may include an independent routing module. If each hybrid expert layer independently executes a complete routing mechanism by its corresponding routing module, each hybrid expert layer needs to calculate a routing score based on the hidden state of the tokens and compare the routing score with a routing score threshold, thereby increasing the consumption of computational resources.

[0107] Based on this, multiple hybrid expert layers can be divided into at least one routing group, each routing group including a target hybrid expert layer and at least one other hybrid expert layer; for each routing group, the target hybrid expert layer performs the step of allocating target words to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network; each other hybrid expert layer performs the step of processing the allocated target words through each first expert feedforward network according to the allocation result of the target hybrid expert layer allocating target words to each first expert feedforward network.

[0108] Optionally, routing groups can be divided into fixed numbers of layers. For example, every four hybrid expert layers form a routing group, with the first layer of each routing group serving as the target hybrid expert layer and the remaining three layers serving as other hybrid expert layers.

[0109] It should be understood that the target hybrid expert layer is the hybrid expert layer in the routing group used to perform the complete expert allocation process. The target hybrid expert layer can be the first hybrid expert layer in each routing group. For one or more subsequent hybrid expert layers in each routing group, the allocation result of the first hybrid expert layer is reused, and the step of processing the allocated target tokens through each first expert feedforward network is performed.

[0110] It should be noted that other hybrid expert layers can reuse the processing procedures of the target hybrid expert layer, including but not limited to the mapping relationship between tokens and experts, routing masks, expert indexes, token indexes, and the mapping relationship between tokens and experts after load capacity pruning.

[0111] By adopting the above implementation method, multiple hybrid expert layers are divided into at least one routing group. Each routing group includes a target hybrid expert layer that performs complete expert allocation and at least one other hybrid expert layer that reuses the allocation result. The other hybrid expert layers execute according to the allocation result determined by the target hybrid expert layer, thereby reducing the number of calls to the routing module. This reduces the repeated expert selection process within the routing group, thereby reducing the consumption of computing resources and communication overhead of the hybrid expert layer.

[0112] As can be seen, implementing the above embodiments differs from the routing mechanism where each expert feedforward network selects a fixed number of terms. In this embodiment, the routing mechanism has different routing score thresholds for each first expert feedforward network. Whether a term is assigned to a particular first expert feedforward network can be determined independently, rather than by a predetermined fixed number of experts. Moreover, whether a term is assigned to a particular first expert feedforward network is determined by both the routing score and the routing score threshold of that first expert feedforward network. This allows the number of first expert feedforward networks corresponding to each target term and the number of target terms corresponding to each first expert feedforward network to change dynamically, effectively balancing expert resource allocation and load balancing, thereby improving the inference performance of the hybrid expert model. Furthermore, it does not require global sorting of the routing scores of the current term and subsequent terms, making this routing mechanism applicable to models with high requirements for causality, stability, and incremental inference, effectively expanding the applicability of the model's inference tasks.

[0113] In some embodiments, the allocation condition can be set to a routing score greater than a corresponding routing score threshold. This example will be described in detail below with reference to other accompanying figures. Please refer to... Figure 3 , Figure 3 This is a flowchart illustrating another task reasoning method based on a hybrid expert model disclosed in an embodiment of this application, as shown below. Figure 3 The method shown may include the following steps: Step 310: Perform word segmentation on the text sequence to obtain multiple word units.

[0114] The implementation method of step 310 can be referred to the content of step 110 above, and will not be repeated here.

[0115] Step 320: For each first expert feedforward network, the tokens in the routing score that are greater than the corresponding routing score threshold are determined as the initial tokens of the first expert feedforward network.

[0116] In this embodiment, the allocation condition is that the routing score is greater than a routing score threshold. That is, if the routing score between a certain term and a certain first expert feedforward network is greater than the routing score threshold corresponding to the first expert feedforward network, then the term is determined as the initial term of the first expert feedforward network. It should be understood that the term corresponding to the routing score between each term and each first expert feedforward network that is greater than the routing score threshold corresponding to each first expert feedforward network is determined as the initial term.

[0117] For example, please see Figure 4 , Figure 4 This is a schematic diagram of a routing scheduling method disclosed in an embodiment of this application. Figure 4 As shown, multiple word units are respectively to Multiple first-expert feedforward networks are respectively to Assuming a first-expert feedforward network to The corresponding routing score thresholds are 0.25, 0.40, 0.40, and 0.30, respectively. Using a routing score greater than the routing score threshold as the allocation condition, the following allocation results can be obtained: For the token Only the routing score of 0.42 is greater than that of the first expert feedforward network. The corresponding routing score threshold is 0.40, therefore the term... Assigned to the first expert feedforward network For word elements Only the routing score of 0.71 is greater than that of the first expert feedforward network. The corresponding routing score threshold is 0.40, therefore the term... Assigned to the first expert feedforward network For word elements The routing score of 0.26 is greater than that of the first expert feedforward network. The corresponding routing score threshold is 0.25, and the routing score of 0.34 is greater than that of the first expert feedforward network. The corresponding routing score threshold is 0.30, therefore, the term T3 is assigned to the first expert feedforward network. and the first expert feedforward network For word elements Since all four routing scores are greater than the routing score threshold corresponding to each first expert feedforward network, the term T4 is assigned to the first expert feedforward network respectively. , , , For word elements Only the routing score of 0.47 is greater than that of the first expert feedforward network. The corresponding routing score threshold is 0.25, therefore the term... Assigned to the first expert feedforward network For word elements The routing score of 0.60 is greater than that of the first expert feedforward network. The corresponding routing score threshold is 0.40, and a routing score of 0.45 is greater than that of the first expert feedforward network. The corresponding routing score threshold is 0.40, therefore the term... They were respectively assigned to the first expert feedforward network and the first expert feedforward network .

[0118] From the perspective of lexical units , , Each is processed by a first-expert feedforward network. and Processed by two first-expert feedforward networks respectively. It is processed by four first-expert feedforward networks. Therefore, the number of first-expert feedforward networks actually invoked for different lexical units can also be different.

[0119] in, The routing scores with all four first-expert feedforward networks exceed the routing score threshold corresponding to each first-expert feedforward network, indicating that... If it has a high degree of matching with multiple first-expert feedforward networks, then... By allocating more first-expert feedforward networks, processing results from multiple first-expert feedforward networks can be obtained. , and Since only one route score exceeds the corresponding route score threshold, it is not necessary to call the first expert feedforward network with a low matching degree in order to meet the fixed number of experts, thus realizing the dynamic allocation of experts.

[0120] In this embodiment, the allocation result between the lexical unit and the first expert feedforward network can be represented by a routing mask M. The elements of the routing mask M... It can be determined using the following formula: ; in, The element representing the route mask M The calculation process, Indicates the first t The word element and the first e Routing scores between first-expert feedforward networks This represents the routing score threshold; the condition within the parentheses is true when... The value of is 1, indicating that the first is 1. t The lexical unit was assigned to the 1st lexical unit. e A first-expert feedforward network; when the conditions in parentheses are not met. The value of 0 indicates that the first is 0. t The word element was not assigned to the first... e A first-in-class expert feedforward network.

[0121] It should be noted that the routing mask can be an explicitly stored binary matrix, or it can be represented by data structures that can characterize the allocation relationship between tokens and expert feedforward networks, such as token indexes, expert indexes, Boolean tensors, sparse tensors, and mapping tables. This application does not limit this.

[0122] As an example, such as Figure 4 As shown, it is assigned to the first expert feedforward network. to The terms are those whose corresponding column in the routing mask has a value of 1 (represented by black circles), and those that are not assigned have a corresponding column value of 0 (represented by white circles). For example, in a first-expert feedforward network... The target lexical units to be processed are , , First expert feedforward network The target lexical units to be processed are , , .

[0123] It should be understood that, since the routing score thresholds and distributions corresponding to different columns are different, the actual number of target terms to be processed by the first expert feedforward networks E1 to E4 can also be different. Similarly, since the number of 1s in each row of the routing mask can be different, the number of first expert feedforward networks corresponding to different terms can also be different. That is to say, a term can be processed by only one first expert feedforward network, or it can be processed by two or more first expert feedforward networks together.

[0124] It should be noted that when the hybrid expert model uses a dynamic tensor shape and computational resources are sufficient, the first expert feedforward network can directly process all initial tokens. However, in deployment environments with static computation graphs, fixed tensor shapes, or pre-allocated expert input buffers, it is usually necessary to limit the number of planned tokens that each first expert feedforward network can process. When the number of initial tokens exceeds this planned number, all initial tokens cannot be allocated to the corresponding first expert feedforward network for computation.

[0125] In some implementations, after determining the terms with routing scores greater than the corresponding routing score threshold as the initial terms of the first expert feedforward network, for each first expert feedforward network, if the current load of the first expert feedforward network is greater than the target load, the routing scores between the first expert feedforward network and the corresponding initial terms are sorted from high to low to obtain the routing sorting result of the first expert feedforward network; the first M initial terms in the routing sorting result are determined as the target terms of the first expert feedforward network, where M is the remaining load of the first expert feedforward network, and M is an integer greater than or equal to 1. Here, the current load indicates the number of target terms allocated to the first expert feedforward network, and the target load indicates the number of planned terms that the first expert feedforward network can process.

[0126] It should be understood that the target load is used to indicate the planned number of tokens that the first expert feedforward network can process in the current processing batch and the current execution cycle, i.e., the maximum number of tokens.

[0127] When the number of initial tokens is not greater than the target load, all initial tokens can be identified as target tokens. When the number of initial tokens is greater than the target load, it means that the number of initial tokens exceeds the maximum number of tokens that can be processed. In this case, the routing scores between each initial token and the first expert feedforward network are sorted from high to low, and the top M initial tokens are retained according to the remaining load of the first expert feedforward network.

[0128] Optionally, when two or more initial tokens have the same routing score, their relative order can be determined based on the token's position in the text sequence, the token's arrival time, the token's priority, a random number, or a preset stable sorting rule.

[0129] Optionally, the method for determining the target load may include: obtaining the target expert computational cost for processing multiple words based on the number of multiple words and the target average number of experts corresponding to the multiple words, wherein the target expert computational cost is used to indicate the total number of computation pairs formed by multiple words and multiple first expert feedforward networks; and obtaining the target load based on the target expert computational cost and the number of multiple first expert feedforward networks.

[0130] Different terms can correspond to different numbers of first-expert feedforward networks. For example, terms with lower processing difficulty can be processed by fewer first-expert feedforward networks, while terms with higher processing difficulty can be processed by more first-expert feedforward networks. Therefore, the overall computational cost of the hybrid expert model cannot be directly determined by the number of experts for a single term. To ensure that the dynamic allocation of the number of experts is still constrained by the overall computational budget, a target average number of experts corresponding to multiple terms can be pre-set, and the target expert computational cost corresponding to multiple terms can be determined based on the number of terms currently being processed. The target average number of experts indicates the planned number of experts for the first-expert feedforward networks that can correspond to each term.

[0131] It should be understood that the target expert computational cost is not the parameter computation cost of the first expert feedforward network itself, but rather represents the total number of word-expert computation pairs to be executed within the corresponding statistical range. One word is processed by one first expert feedforward network, forming one word-expert computation pair; one word is processed by three first expert feedforward networks, forming three word-expert computation pairs.

[0132] After determining the target expert computational load, the overall computational budget can be converted into the target load of each first expert feedforward network based on the number of first expert feedforward networks. Therefore, the target average number of experts set from the lexical dimension can be converted into the planned number of lexical units that each first expert feedforward network can process at the expert dimension, thus obtaining the target load.

[0133] In this implementation, the target expert computational load is determined based on the number of multiple lexical units and the target average number of experts corresponding to multiple lexical units. Then, the target load is obtained based on the target expert computational load and the number of multiple first expert feedforward networks. This ensures that the total computational load of all lexical units is limited to the overall budget. This resource allocation method, which controls the computational load of each first expert feedforward network from the lexical unit dimension, allows the target expert computational load and target load to change dynamically when the number of lexical units changes, thereby adapting to the processing of text sequences of different lengths.

[0134] For example, suppose the hybrid expert model includes 64 first-expert feedforward networks, the input text sequence corresponds to 2048 words, and the target average number of experts per word is 8. Then the total number of target word-to-expert computation pairs can be set as: 2048 × 8 = 16384; with each first-expert feedforward network having the same target load, the target load of each first-expert feedforward network can be set as: 16384 ÷ 64 = 256.

[0135] Assuming a first-expert feedforward network After filtering by routing score threshold, 310 initial tokens were obtained, and the first expert feedforward network... It was not occupied by other lexical units before the current allocation. At this time, the first expert feedforward network... The current load of 310 is greater than the target load of 256, thus triggering capacity pruning. Based on this, the initial 310 tokens are used with the first expert feedforward network. The routing scores are sorted from highest to lowest, due to the first expert feedforward network. If the word was not occupied by other words before the current allocation, its remaining load M is 256. The first 256 words in the sorting results are determined as the first expert feedforward network. The target lexical units, and the remaining 54 initial lexical units are not assigned to the first expert feedforward network. Through the above processing, the first expert feedforward network The actual number of target words received was reduced from 310 to 256, not exceeding its target load. The 256 target words retained were those from the initial 310 words that were matched with the first expert feedforward network. The initial terms with relatively high routing scores.

[0136] Using the above implementation method, for each first expert feedforward network, if the current load of the first expert feedforward network is greater than the target load, not all initial words exceeding the processing capacity will be allocated to the first expert feedforward network. Instead, based on the routing ranking result, the first M initial words will be determined as the target words to be allocated to the first expert feedforward network. This method prioritizes the retention of initial words with higher routing scores within the available capacity, so that limited expert computing resources are prioritized for words with a high degree of matching with the first expert feedforward network. This achieves dynamic adjustment of expert allocation, avoids each first expert feedforward network from processing words exceeding its load capacity, and ensures load balance among the first expert feedforward networks.

[0137] Optionally, for each first expert feedforward network, the target load is determined based on a capacity factor, which includes at least one of the following: the historical load of the first expert feedforward network, the hardware resources of the hybrid expert model, the importance of the first expert feedforward network, and the expert category of each first expert feedforward network.

[0138] The historical load of the first expert feedforward network can include the number of tokens received by the first expert feedforward network in multiple historical input batches, multiple inference requests, or preset historical time windows. Based on the historical load, the load change trend of the first expert feedforward network can be determined, and the capacity factor can be determined based on the load change trend, thereby determining the target load.

[0139] The hardware resources for a hybrid expert model can include processor computing power, number of processor cores, available storage capacity, storage bandwidth, inter-device communication bandwidth, device power consumption budget, and current device utilization. When different first-expert feedforward networks are deployed on different electronic devices, the capacity factor can be determined based on the maximum number of planning terms that each processor can handle, thereby determining the target load.

[0140] The importance of the first expert feedforward network (FAB) indicates the degree to which its output affects the model's inference results. Importance can be determined based on factors such as the frequency of expert activation, the contribution of expert output to the model's loss, and the change in model inference accuracy after removing the expert. For example, each FAB can be disabled on the validation dataset during model training, and the magnitude of the performance drop can be statistically analyzed. FABs that cause a significant performance drop after being disabled can be considered more important, while those that cause a smaller performance change can be considered less important.

[0141] It should be understood that for first-expert feedforward networks with higher importance, a larger capacity factor can be set to ensure that more matching terms are retained during candidate load settling. For first-expert feedforward networks with lower importance, a smaller capacity factor can be set to prioritize the allocation of computational and storage resources to other first-expert feedforward networks.

[0142] The expert category in a first-expert feedforward network can be determined based on the network structure, parameter size, training data, and processing task. For example, a first-expert feedforward network can include general semantic experts, code experts, mathematical reasoning experts, multilingual experts, and domain experts. The activation frequency and computational cost of different expert categories may differ, thus different capacity factors can be set.

[0143] For example, if the capacity factor is set to 1.25 and the target load is 256, then the target load for each first expert feedforward network can also be set to: 1.25 × 256 = 320. With this target load setting, if the initial number of tokens is 310, that is, no more than the first expert feedforward network... With a target payload of 320, all initial tokens can be designated as target tokens. Therefore, the capacity factor can be configured to adjust the balance between expert computational load, capacity overflow probability, and model inference quality.

[0144] By adopting the above implementation method, the target load is determined by a capacity factor composed of one or more factors, so that the target load of each first expert feedforward network can be dynamically changed based on the historical load of the first expert feedforward network, the hardware resources of the hybrid expert model, the importance of the first expert feedforward network, and at least one of the expert categories of each first expert feedforward network. This makes the setting dimensions of the target load more diversified and improves the processing capability of the first expert feedforward network.

[0145] Step 330: The initial lexical unit is determined as the target lexical unit, and the corresponding target lexical unit is allocated to the first expert feedforward network.

[0146] In this embodiment of the application, after determining the initial lexical units of the first expert feedforward network, the initial lexical units are determined as the target lexical units of the first expert feedforward network to complete the allocation of target lexical units.

[0147] Optionally, determining the initial lexical as the target lexical of the first expert feedforward network may include establishing a mapping relationship between the target lexical identifier and the first expert feedforward network identifier, updating the routing mask, generating an expert input index, or writing the hidden state of the target lexical into the input buffer of the corresponding first expert feedforward network.

[0148] Step 340: The assigned target lexical units are processed through each first expert feedforward network to obtain the inference result.

[0149] In this embodiment of the application, for each first expert feedforward network, the combination of the hidden states of its corresponding target lexical unit can be used as input. For example, as Figure 4 As shown, the combination of the hidden states of words T3, T4, and T5 is used as the first expert feedforward network. The input is the combination of the hidden states of word units T1, T4, and T6, which is used as the first expert feedforward network. The input. It should be understood that the first expert feedforward network... After the calculation is completed, the first expert feedforward networks corresponding to tokens T3, T4, and T5 are obtained respectively. The output results; First expert feedforward network After the calculation is completed, the first expert feedforward networks corresponding to tokens T1, T4, and T6 are obtained respectively. The output results; First expert feedforward network After the calculation is completed, the first expert feedforward networks corresponding to tokens T2, T4, and T6 are obtained respectively. The output results; First expert feedforward network After the calculation is completed, the first expert feedforward networks corresponding to lexical units T3 and T4 are obtained respectively. The output result.

[0150] Optionally, for a lexical unit processed by only one first expert feedforward network, the output of that first expert feedforward network can be used as the expert processing result for the corresponding target lexical unit. For a lexical unit processed by multiple first expert feedforward networks, the fusion weights can be determined according to the corresponding routing scores, and the outputs of the corresponding first expert feedforward networks can be fused according to the fusion weights to obtain the expert processing result.

[0151] Other implementations of step 340 can be found in step 130 above, and will not be repeated here.

[0152] As can be seen, by implementing the above embodiments, for each first expert feedforward network, the tokens with routing scores greater than the corresponding routing score threshold can be determined as the initial tokens of the first expert feedforward network, and the initial tokens can be determined as the target tokens. Since the routing score represents the matching degree between each first expert feedforward network and each token, taking the tokens with routing scores greater than the corresponding routing score threshold as the initial tokens means that the tokens with a high matching degree are assigned to the corresponding first expert feedforward network, which effectively improves the rationality of expert allocation.

[0153] In some embodiments, after assigning target lexical units to each first expert feedforward network, the routing score threshold can also be updated. This example will be described in detail below with reference to other accompanying figures. See also... Figure 5 , Figure 5 This is a flowchart illustrating another task reasoning method based on a hybrid expert model disclosed in an embodiment of this application, as shown below. Figure 5 The method shown may include the following steps: Step 510: For each first expert feedforward network, update the routing score threshold based on the current load and target load of the first expert feedforward network.

[0154] In this embodiment, the routing score threshold is updated to ensure that the current load is equal to the target load, and that the number of first expert feedforward networks corresponding to each term is equal to the preset number of expert feedforward networks. Here, the current load indicates the number of target terms allocated to the first expert feedforward network, and the target load indicates the number of planned terms that the first expert feedforward network can process.

[0155] It should be noted that during the training of the hybrid expert model, the routing score threshold can be updated based on the current load and target load of the first expert feedforward network after each allocation. This updated routing score threshold can then be used in the next training process of the hybrid expert model or during task inference after the hybrid expert model has been trained, thereby improving the rationality of the allocation results and the accuracy of the model inference results.

[0156] In some implementations, updating the routing score threshold based on the current load and target load of the first expert feedforward network includes: increasing the routing score threshold if the current load is greater than the target load; and decreasing the routing score threshold if the current load is less than the target load.

[0157] It should be understood that the higher the routing score threshold, the fewer routing scores can exceed the threshold when the routing score remains constant. This results in fewer terms being allocated to the corresponding first expert feedforward network, thus reducing the number of terms for the first expert feedforward network and consequently reducing the computational load on the expert network. Conversely, the lower the routing score threshold, the more routing scores can exceed the threshold, resulting in more terms being allocated to the corresponding first expert feedforward network. This increases the number of terms for the first expert feedforward network, allowing it to process more terms and improve the accuracy of the inference results of the hybrid expert model after training. This effectively balances the computational load on the expert network and the inference performance of the model.

[0158] For example, suppose for the first expert feedforward network If the current load allocated to it is greater than the target load, then the first expert feedforward network is added accordingly. The routing score threshold; assuming for the first expert feedforward network If the current load allocated to it is less than the target load, the first expert feedforward network can be reduced accordingly. The routing score threshold.

[0159] It should be noted that the increase and decrease of the routing score threshold in this embodiment are not limited to increasing or decreasing by the same value each time. The change in the routing score threshold can be a fixed value or dynamically determined based on the difference between the current load and the target load. For example, if the routing score threshold before the update is 0.40 and the increase is 0.02, then the updated routing score threshold is 0.42. As another example, if the routing score threshold before the update is 0.40 and the decrease is 0.01, then the updated routing score threshold is 0.39.

[0160] By adopting the above implementation method, the method of updating the routing score threshold can be determined according to the load status of the first expert feedforward network. When the first expert feedforward network is overloaded, the routing score threshold is increased; when the first expert feedforward network is underloaded, the routing score threshold is decreased. This update method allows the change of the routing score threshold to be adjusted based on the actual current load, which can avoid allocating too many or too few terms to the first expert feedforward network, thus optimizing the allocation result and effectively balancing the expert computation and model inference performance.

[0161] In hybrid expert models, updating the routing score threshold typically requires balancing two different levels of control objectives. The first objective is to ensure that the total number of first-expert feedforward networks activated by all tokens is close to the preset computational budget, avoiding excessively high or low overall computational load caused by dynamic allocation of experts. The second objective is to ensure that the current load of each first-expert feedforward network is close to its corresponding target load, preventing tokens from being concentrated in a few individual first-expert feedforward networks.

[0162] If the routing score thresholds are updated separately based on the current and target loads of each first-expert feedforward network, the adjustments to the routing score thresholds of multiple first-expert feedforward networks may simultaneously increase or decrease, thus altering the overall expert computational cost of the hybrid expert model. For example, when most first-expert feedforward networks are underloaded (i.e., the current load is less than the target load), reducing the routing score thresholds of multiple first-expert feedforward networks individually may rapidly increase the number of computational pairs formed by the total tokens and the first-expert feedforward networks.

[0163] In some embodiments, the routing score threshold can be set to include a global threshold and a local threshold. Implementations of step 510 above can be found in [reference needed]. Figure 6 For steps 511 to 514 shown, please refer to [link / reference]. Figure 6 , Figure 6 This is a schematic diagram of a process for updating a routing score threshold disclosed in an embodiment of this application. The method shown in Figure 6 may include the following steps: Step 511: Based on the number of multiple word units and the number of first expert feedforward networks corresponding to each word unit, obtain the current average number of experts corresponding to multiple word units.

[0164] In this embodiment, the electronic device can acquire the number of multiple lexical units and the number of first expert feedforward networks corresponding to each lexical unit; then, it calculates the average number of first expert feedforward networks corresponding to each lexical unit to obtain the current average number of experts corresponding to multiple lexical units. That is, the current average number of experts is calculated by averaging the number of first expert feedforward networks corresponding to each lexical unit.

[0165] For example, such as Figure 4 As shown, there are a total of 6 lexical units. The corresponding first expert feedforward network has 1 element. The corresponding first expert feedforward network has 1 element. The corresponding first-level expert feedforward network has 2 nodes, and the number of nodes is 2. The corresponding first-level expert feedforward network has 4 nodes, and the number of nodes is 4. The corresponding first expert feedforward network has 1 element. The corresponding first expert feedforward network consists of two elements, and the word units can be obtained through calculation. , , , , , The corresponding current average number of experts is approximately 1.7.

[0166] Step 512: Update the global threshold based on the current average number of experts and the target average number of experts corresponding to multiple words, and obtain the updated global threshold. The global threshold is negatively correlated with the total number of first expert feedforward networks activated by multiple words.

[0167] It should be understood that by comparing the current average number of experts with the target average number of experts, the number deviation of the first expert feedforward network corresponding to each word is obtained. After updating the global threshold based on this number deviation, the number of the first expert feedforward network corresponding to each word can be changed, so that the current average number of experts for each word approaches the target average number of experts. This affects the total number of first expert feedforward networks activated by multiple words, so that the total number of word-expert computation pairs also changes. In other words, the update of the global threshold controls the overall expert computation of the hybrid expert model by controlling the number of first expert feedforward networks activated in the overall hybrid expert model.

[0168] In some implementations, the global threshold is updated based on the current average number of experts and the target average number of experts corresponding to multiple terms, including: increasing the global threshold if the current average number of experts is greater than the target average number of experts, or decreasing the global threshold if the current average number of experts is less than the target average number of experts.

[0169] It should be understood that increasing the global threshold leads to an increase in the routing score threshold, which in turn reduces the number of assigned terms, resulting in a corresponding decrease in the number of activated first-expert feedforward networks. Conversely, decreasing the global threshold leads to a decrease in the routing score threshold, which in turn increases the number of assigned terms, resulting in a corresponding increase in the number of activated first-expert feedforward networks. Therefore, the global threshold can be updated in a direction that is negatively correlated with the current average number of experts corresponding to multiple terms.

[0170] When the current average number of experts for multiple words exceeds the target average number of experts, it indicates that each word is currently assigned a large number of experts, causing the total number of word and expert computation pairs to exceed the overall computation budget. In this case, the total number of activated first expert feedforward networks needs to be reduced, and the global threshold is increased. After increasing the global threshold, the routing score threshold of the first expert feedforward network also increases accordingly. Conversely, when the current average number of experts for multiple words is lower than the target average number of experts, it indicates that each word is currently assigned a small number of experts, causing the total number of word and expert computation pairs to be lower than the overall computation budget. In this case, the total number of activated first expert feedforward networks can be increased, and the global threshold is decreased. After decreasing the global threshold, the routing score threshold of the first expert feedforward network also decreases accordingly.

[0171] By adopting the above implementation method, and by controlling the increase or decrease of the global threshold, the number of expert activations can be suppressed as a whole when the number of activations in the first expert feedforward network exceeds the computational budget, and the expert computing power can be released as a whole when the number of activations is insufficient, thereby improving the utilization rate of expert computing resources.

[0172] Step 513: Update the local threshold based on the current load and the target load to obtain the updated local threshold. The local threshold is negatively correlated with the number of target words allocated to each first expert feedforward network.

[0173] It should be understood that the local threshold is updated based on the load of a single first expert feedforward network and is used to adjust the load distribution of each first expert feedforward network. Therefore, when a first expert feedforward network is overloaded, its local threshold can be increased to reduce the number of tokens allocated to that first expert feedforward network.

[0174] In some implementations, updating the local threshold based on the current load and the target load includes: increasing the local threshold if the current load is greater than the target load, or decreasing the local threshold if the current load is less than the target load.

[0175] It should be understood that since increasing the routing score threshold reduces the number of terms allocated to the first expert feedforward network, and decreasing the routing score threshold increases the number of terms allocated to the first expert feedforward network, the local thresholds can be updated in a direction negatively correlated with the load of the first expert feedforward network.

[0176] When the current load of a first expert feedforward network exceeds the target load, the number of target words allocated to that first expert feedforward network needs to be reduced. This is achieved by increasing the local threshold corresponding to that first expert feedforward network. As the local threshold increases, the routing score threshold of that first expert feedforward network also increases, thereby increasing the number of target words allocated to it. Conversely, when the current load of a first expert feedforward network is lower than the target load, the number of target words allocated to it needs to be increased. This is achieved by decreasing the local threshold corresponding to that first expert feedforward network. As the local threshold decreases, the routing score threshold of that first expert feedforward network also decreases, thereby reducing the number of target words allocated to it.

[0177] By adopting the above implementation method, the load difference between each first expert feedforward network can be reduced by controlling the increase or decrease of the local threshold, and the computational load of each first expert feedforward network can be effectively balanced.

[0178] Step 514: Update the routing score threshold based on the updated global threshold and the updated local threshold.

[0179] After obtaining the updated global threshold and the updated local threshold respectively, the routing score threshold used by each first expert feedforward network in the next allocation cycle is determined based on the updated global threshold and the updated local threshold.

[0180] Using the embodiments described in steps 511 to 514 above, the global threshold is updated based on the current average number of experts corresponding to multiple lexical units and the target average number of experts corresponding to multiple lexical units, thereby achieving the purpose of adjusting the total number of first expert feedforward networks activated by lexical units. This allows for overall adjustment of the computational load of the first expert feedforward network. Simultaneously, the local threshold is updated based on the current load and target load of each first expert feedforward network, enabling the number of target lexical units allocated to each first expert feedforward network to be adjusted independently, thereby controlling the load balance of each first expert feedforward network. Based on this, the use of global and local two-level threshold control not only avoids the situation where the overall computational load deviates from the budget when only local adjustment is performed, but also avoids the problem of not being able to handle the load differences between each first expert feedforward network when only global adjustment is performed. This effectively improves the fine-grainedness of computational resource allocation and achieves a balance between computational load and inference performance in the hybrid expert model.

[0181] Step 520: Assign target lexical units to each first expert feedforward network based on the routing score between each lexical unit and each first expert feedforward network and the updated routing score threshold corresponding to each first expert feedforward network.

[0182] In this embodiment, a target word is assigned to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the updated routing score threshold corresponding to each first expert feedforward network. This can be referred to in the aforementioned implementation method of assigning a target word to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network. The details will not be repeated here.

[0183] Step 530: The assigned target lexical units are processed through each first expert feedforward network to obtain the inference result.

[0184] The implementation methods for steps 520 to 530 can be referred to the content of steps 120 to 130 above, and will not be repeated here.

[0185] As can be seen, by implementing the above embodiments, the routing score threshold is updated based on the deviation between the current load and the target load of the first expert feedforward network. By changing the routing score threshold, the number of terms subsequently allocated to each first expert feedforward network can be adjusted, so that the current load approaches the target load, and the number of first expert feedforward networks corresponding to each term approaches the preset number of expert feedforward networks. This achieves the purpose of balancing the load of each first expert feedforward network and also balances the computational load of the first expert feedforward network. In other words, the allocation result can simultaneously satisfy the expert load constraint and the computational budget constraint, thereby improving the stability of the hybrid expert model in performing inference tasks.

[0186] In some embodiments, if the target lexical unit is assigned to multiple first expert feedforward networks, the outputs of the corresponding first expert feedforward networks can be fused. This example will be described in detail below with reference to other accompanying figures. Please refer to... Figure 7 , Figure 7 This is a flowchart illustrating another task reasoning method based on a hybrid expert model disclosed in an embodiment of this application, as shown below. Figure 7 The method shown may include the following steps: Step 710: The text sequence is segmented to obtain multiple word units.

[0187] Step 720: Based on the routing score between each term and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network, assign a target term to each first expert feedforward network. The target term is at least one of multiple terms.

[0188] The implementation methods for steps 710 to 720 can be referred to the content of steps 110 to 120 above, and will not be repeated here.

[0189] Step 730: Process the assigned target word through each first expert feedforward network to obtain the output result of each first expert feedforward network for each target word.

[0190] In this embodiment of the application, a single target word can be assigned to multiple first expert feedforward networks, and each first expert feedforward network can also be assigned multiple target words. Therefore, the assigned target words can be processed by each first expert feedforward network to obtain the output result of each first expert feedforward network for each target word.

[0191] Step 740: For each target word, fuse the output of the corresponding first expert feedforward network to obtain the fusion result.

[0192] In this embodiment of the application, for each target word, if the target word is assigned to multiple first expert feedforward networks, the output results of the corresponding first expert feedforward networks can be fused to obtain a fusion result.

[0193] Optionally, the fusion process can be performed by weighted summation of the outputs of each first expert feedforward network.

[0194] For example, please see Figure 8 , Figure 8 This is a schematic diagram of an expert feedforward network inference process disclosed in an embodiment of this application. Figure 8 As shown, word units can be... Assigned to the first expert feedforward network (Expert 2) performs the processing to obtain the first expert feedforward network. The output result; lexical units Assigned to the first expert feedforward network (Expert 3) performs the processing to obtain the first expert feedforward network. The output result; lexical units They were respectively assigned to the first expert feedforward network (Expert 1) and First Expert Feedforward Network (Expert 4) performs the processing to obtain the first expert feedforward network. and the first expert feedforward network The output results are then fused; the word units are... They were respectively assigned to the first expert feedforward network (Expert 1) (Expert 2) (Expert 3) and (Expert 4) performs the processing to obtain the first expert feedforward network. , , and The output results are then fused; the word units are... Assigned to the first expert feedforward network (Expert 1) Obtain the first expert feedforward network The output result; lexical units They were respectively assigned to the first expert feedforward network (Expert 2) and First Expert Feedforward Network (Expert 3) performs the processing to obtain the first expert feedforward network. and the first expert feedforward network The output results are then fused together; finally, the output results are mapped to the positions of each word in the original text sequence.

[0195] Step 750: Aggregate the fusion results according to the aggregation matrix to obtain the inference results.

[0196] Before the first expert feedforward network performs the calculation, the assigned target words need to be processed according to the allocation relationship between the words and the first expert feedforward network. After the first expert feedforward network performs the calculation, the output results of multiple first expert feedforward networks need to be restored to the position of each target word in the text sequence in order to obtain the inference result.

[0197] In related technologies, the output of the first expert feedforward network is mainly written back to the position of each target word in the text sequence through index accumulation or scatter accumulation. When a word corresponds to multiple expert outputs, and multiple outputs need to be written to the same word position, problems such as irregular storage access, write conflicts, or atomic accumulation will arise.

[0198] To improve the adaptability of the expert output aggregation process to hardware resources, this embodiment constructs a selection matrix based on lexical units and expert calculations, and performs a transpose transformation on the selection matrix to obtain an aggregation matrix. Then, the output of the first expert feedforward network is mapped to the position of each target lexical unit in the text sequence through matrix multiplication.

[0199] In this embodiment, the aggregation matrix is ​​obtained by transposing the selection matrix constructed from multiple word pairs and multiple first expert feedforward networks. The selection matrix encodes the expert input selection relationship and the expert output position mapping relationship; that is, the selection matrix is ​​used to indicate the position of the target word corresponding to each computation pair in the text sequence. Transposing the selection matrix to obtain the aggregation matrix allows the mapping from the expert output to the original word position to be directly obtained from the inverse linear relationship of the selection process, without the need to construct a write-back index that is inconsistent with the input selection relationship.

[0200] It should be noted that the aggregation matrix is ​​obtained by transposing the selection matrix. The selection matrix selects and copies each word from the hidden state of the original word and the input required for the expert calculation pair. The aggregation matrix performs the mapping in the opposite direction, returning the expert output results arranged according to the calculation pair to the original word position.

[0201] Optionally, the selection matrix and aggregation matrix can be explicitly stored as dense matrices, or as sparse matrices, block sparse matrices, implicit index matrices, permutation matrices, compile-time generated fixed-layout matrices, or equivalent operators, etc.

[0202] For example, please see Figure 9 , Figure 9 This is a schematic diagram illustrating an aggregation process disclosed in an embodiment of this application to obtain a reasoning result. For example... Figure 9 As shown on the left, the method of processing expert input and expert output by index accumulation is illustrated. According to the allocation result, the corresponding selected target word is read from multiple word words, and the expert input sequence composed of target word words is input into the first expert feedforward network for expert processing. After the first expert feedforward network completes its processing, the expert output sequence of the first expert feedforward network is written into the position of each target word word in the text sequence by index accumulation. The right side illustrates the implementation of processing based on the aggregation matrix in this embodiment. First, a selection matrix is ​​constructed according to the index corresponding to the position of each target word in the text sequence. The matrix of the expert input sequence corresponding to the selected target word is obtained by matrix multiplication between the matrix of the hidden state corresponding to the model input (1×2048×1536) and the selection matrix (1×256×2048). Then, after the first expert feedforward network has finished processing, the matrix corresponding to the expert output sequence of the first expert feedforward network (1×256×1536) is written back to the position of each target word in the text sequence through the transpose of the selection matrix (i.e., the aggregation matrix, 1×2048×256), that is, the matrix corresponding to the expert output (1×2048×1536) is obtained by aggregation. Based on the position of each target word in the text sequence indicated in the matrix corresponding to the expert output obtained by aggregation, the output of the model is finally obtained.

[0203] It should be noted that if the target word is assigned to multiple first-expert feedforward networks, the fusion results are aggregated using an aggregation matrix to obtain the inference result; if the target word is assigned to a single first-expert feedforward network, the expert's output results are aggregated using an aggregation matrix for each target word to obtain the inference result.

[0204] As can be seen, by implementing the above embodiments, the aggregation matrix obtained by the transpose transformation of the constructed selection matrix is ​​aggregated based on the computation of multiple word units and multiple first expert feedforward networks. The aggregation matrix can aggregate the fusion results of the first expert feedforward networks corresponding to each target word unit to the position of the same target word unit in the text sequence. This replaces the traditional method of index accumulation or scatter accumulation with linear operations of regular matrix multiplication, thereby avoiding problems such as irregular storage access, write conflicts, or atomic accumulation. Moreover, by using the aggregation matrix to realize the writing of the hidden state of word units and the writing back of expert output results, it can be adapted to hybrid expert models that do not support complex index writing and writing back, thus improving the applicability of the model in handling inference tasks.

[0205] It should be understood that although the steps in the above flowcharts are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the above flowcharts may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps. In addition, the above embodiments can be implemented independently or in combination with each other, and different implementation methods in the above embodiments can also be combined with each other, without limitation.

[0206] Based on the foregoing embodiments, this application provides a task reasoning device based on a hybrid expert model. The device includes various modules and units included in each module, which can be implemented by a processor; of course, it can also be implemented by specific logic circuits. In the implementation process, the processor can be a central processing unit (CPU), microprocessor (MPU), digital signal processor (DSP), or field programmable gate array (FPGA), etc.

[0207] Please see Figure 10 , Figure 10 This is a schematic diagram of the structure of a task reasoning device based on a hybrid expert model disclosed in an embodiment of this application. The hybrid expert model includes multiple first expert feedforward networks, such as... Figure 10 The device shown includes a processing module 1010, an allocation module 1020, and an inference module 1030.

[0208] Processing module 1010 is used to perform word segmentation on the text sequence to obtain multiple word units. The text sequence is the problem description text input to the hybrid expert model. The allocation module 1020 is used to allocate a target word to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network. The target word is at least one of multiple words. The reasoning module 1030 is used to process the assigned target lexical units through each first expert feedforward network to obtain the reasoning result, which is the response description text corresponding to the question description text.

[0209] In some embodiments, the allocation module 1020 is specifically used for: For each first expert feedforward network, the tokens in the routing score that are greater than the corresponding routing score threshold are determined as the initial tokens of the first expert feedforward network; The initial lexical units are determined as target lexical units, and the corresponding target lexical units are allocated to the first expert feedforward network.

[0210] In some embodiments, the allocation module 1020 is further specifically used for: For each first expert feedforward network, if the current load of the first expert feedforward network is greater than the target load, the routing scores between the first expert feedforward network and the corresponding initial token are sorted from high to low to obtain the routing sorting result of the first expert feedforward network. The current load is used to indicate the number of target tokens allocated to the first expert feedforward network, and the target load is used to indicate the number of planned tokens that the first expert feedforward network can process. The first M initial terms in the routing sorting results are determined as the target terms of the first expert feedforward network. The value of M is the remaining load of the first expert feedforward network, and M is an integer greater than or equal to 1.

[0211] In some embodiments, the task reasoning apparatus based on a hybrid expert model further includes an update module; The update module is used to, after allocating target tokens to each first expert feedforward network, update the routing score threshold for each first expert feedforward network based on the current load and target load of the first expert feedforward network, so that the current load is equal to the target load, and the number of first expert feedforward networks corresponding to each token is equal to the preset number of expert feedforward networks; wherein, the current load is used to indicate the number of target tokens allocated to the first expert feedforward network, and the target load is used to indicate the number of planned tokens that the first expert feedforward network can process.

[0212] In some embodiments, the update module is specifically used for: If the current load is greater than the target load, increase the routing score threshold; If the current load is less than the target load, reduce the routing score threshold.

[0213] In some embodiments, the routing score threshold includes a global threshold and a local threshold; The update module is also specifically used for: Based on the number of multiple terms and the number of first-expert feedforward networks corresponding to each term, the current average number of experts corresponding to multiple terms is obtained. Based on the current average number of experts and the target average number of experts, the global threshold is updated to obtain the updated global threshold. The global threshold is negatively correlated with the total number of first-expert feedforward networks activated by multiple terms. Based on the current load and the target load, the local threshold is updated to obtain the updated local threshold. The local threshold is negatively correlated with the number of target terms allocated to each first-expert feedforward network. Based on the updated global threshold and the updated local threshold, the routing score threshold is updated.

[0214] In some embodiments, the update module is further specifically used for: If the current average number of experts is greater than the target average number of experts, increase the global threshold; or if the current average number of experts is less than the target average number of experts, decrease the global threshold. The update module is also specifically used for: If the current load is greater than the target load, increase the local threshold; or if the current load is less than the target load, decrease the local threshold.

[0215] In some embodiments, the task reasoning apparatus based on a hybrid expert model further includes a computing module; The calculation module is used to obtain the target expert computational load corresponding to processing multiple words based on the number of multiple words and the target average number of experts corresponding to processing multiple words. The target expert computational load is used to indicate the total number of computation pairs formed by multiple words and multiple first expert feedforward networks. The target load is obtained based on the target expert computational load and the number of multiple first expert feedforward networks.

[0216] In some embodiments, for each first expert feedforward network, the target load is determined based on a capacity factor, which includes at least one of the following: the historical load of the first expert feedforward network, the hardware resources of the hybrid expert model, the importance of the first expert feedforward network, and the expert category of each first expert feedforward network.

[0217] In some embodiments, the inference module 1030 is specifically used for: Each first expert feedforward network processes the assigned target word, resulting in the output of each first expert feedforward network for each target word. For each target word, the output of the corresponding first expert feedforward network is fused to obtain the fusion result; The fusion results are aggregated based on the aggregation matrix to obtain the inference results. The aggregation matrix is ​​obtained by transposing the selection matrix constructed from multiple word pairs and multiple first expert feedforward networks. The selection matrix is ​​used to indicate the position of the target word corresponding to each word pair in the text sequence.

[0218] In some embodiments, the hybrid expert model further includes multiple second expert feedforward networks; Inference module 1030 is also specifically used for: Each word is processed by each second expert feedforward network to obtain the inference result corresponding to each second expert feedforward network; For each word, the inference results corresponding to the first expert feedforward network and the inference results corresponding to the second expert feedforward network are fused to obtain the initial inference result; The initial inference results of each word are fused together to obtain the target inference result of the hybrid expert model.

[0219] In some embodiments, the hybrid expert model further includes a routing module, and the task reasoning device based on the hybrid expert model further includes an acquisition module; The acquisition module is used to acquire the hidden state of each word element, and the hidden state is used to characterize the features of each word element; The processing module 1010 is also used to process the hidden state of each word using a preset routing calculation function through the routing module to obtain the initial routing score between each word and each first expert feedforward network; adjust the initial routing score according to the inference difficulty of each word to obtain the routing score between each word and each first expert feedforward network, and the inference difficulty is positively correlated with the number of first expert feedforward networks corresponding to each word.

[0220] In some embodiments, the hybrid expert model consists of multiple hybrid expert layers; Processing module 1010 is also configured to divide multiple hybrid expert layers into at least one routing group, each routing group including a target hybrid expert layer and at least one other hybrid expert layer; The allocation module 1020 is also configured to, for each routing group, perform the step of allocating a target word to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold of each first expert feedforward network through the target hybrid expert layer; The inference module 1030 is also used for each other hybrid expert layer to allocate target words to each first expert feedforward network according to the allocation result of the target hybrid expert layer, and to perform the step of processing the allocated target words through each first expert feedforward network.

[0221] It should be noted that, in the embodiments of this application... Figure 10 The module division shown in the task reasoning device based on a hybrid expert model is illustrative and only represents a logical functional division. In actual implementation, there may be other division methods.

[0222] Please refer to Figure 11 , Figure 11 This is a schematic diagram of the frame structure of an electronic device disclosed in an embodiment of this application. For example... Figure 11 As shown, the electronic device includes a memory 1110 and a processor 1120, with the memory 1110 storing executable program code.

[0223] The memory 1110 is coupled to the processor 1120; The processor 1120 calls the executable program code stored in the memory 1110 to execute any of the task reasoning methods based on the hybrid expert model in the above method embodiments.

[0224] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of any of the task reasoning methods based on hybrid expert models provided in the above embodiments.

[0225] This application provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the task reasoning methods based on a hybrid expert model provided in the above embodiments.

[0226] Those skilled in the art will understand that Figure 11 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0227] It should be noted that the descriptions of the above embodiments of the apparatus, electronic devices, computer-readable storage media, and computer program products are similar to the descriptions of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the embodiments of the apparatus, electronic devices, computer-readable storage media, and computer program products of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0228] It should be understood that the phrases "one embodiment," "an embodiment," or "some embodiments" mentioned throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment," "in one embodiment," or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The descriptions of the various embodiments above tend to emphasize the differences between the various embodiments; their similarities or commonalities can be referred to mutually, and for the sake of brevity, they will not be repeated here.

[0229] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three kinds of relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist simultaneously, and object B exists alone.

[0230] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0231] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules above is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, and can be electrical, mechanical, or other forms.

[0232] 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 includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.

[0233] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0234] The features disclosed in the several device embodiments provided in this application can be arbitrarily combined without conflict to obtain new device embodiments.

[0235] The above description is merely an 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 scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A task reasoning method based on a hybrid expert model, characterized in that, The hybrid expert model includes multiple first expert feedforward networks, and the method includes: The text sequence is segmented into multiple word units, and the text sequence is the problem description text input to the hybrid expert model. Based on the routing score between each lexical unit and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network, a target lexical unit is assigned to each first expert feedforward network, wherein the target lexical unit is at least one of the plurality of lexical units; The assigned target lexical units are processed by each of the first expert feedforward networks to obtain an inference result, which is the response description text corresponding to the question description text.

2. The method according to claim 1, characterized in that, The step of allocating target words to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network includes: For each of the first expert feedforward networks, the tokens in the routing scores that are greater than the corresponding routing score threshold are determined as the initial tokens of the first expert feedforward network; The initial lexical unit is determined as the target lexical unit, and the corresponding target lexical unit is allocated to the first expert feedforward network.

3. The method according to claim 1 or 2, characterized in that, After assigning target lexical units to each of the first expert feedforward networks, the method further includes: For each of the first expert feedforward networks, the routing score threshold is updated based on the current load and target load of the first expert feedforward network, so that the current load is equal to the target load, and the number of the first expert feedforward networks corresponding to each term is equal to the preset number of expert feedforward networks. The current load is used to indicate the number of target lexical units allocated to the first expert feedforward network, and the target load is used to indicate the number of planned lexical units that the first expert feedforward network can process.

4. The method according to claim 3, characterized in that, The step of updating the routing score threshold based on the current load and target load of the first expert feedforward network includes: If the current load is greater than the target load, increase the routing score threshold; If the current load is less than the target load, decrease the routing score threshold.

5. The method according to claim 3, characterized in that, The routing score threshold includes a global threshold and a local threshold. Updating the routing score threshold based on the current load and target load of the first expert feedforward network includes: The current average number of experts corresponding to the plurality of lexical units is obtained based on the number of the plurality of lexical units and the number of the first expert feedforward networks corresponding to each lexical unit; Based on the current average number of experts and the target average number of experts corresponding to the plurality of lexical units, the global threshold is updated to obtain the updated global threshold. The global threshold is negatively correlated with the total number of the first expert feedforward network activated by the plurality of lexical units. Based on the current load and the target load, the local threshold is updated to obtain the updated local threshold, which is negatively correlated with the number of target lexical units allocated to each of the first expert feedforward networks; The routing score threshold is updated based on the updated global threshold and the updated local threshold.

6. The method according to claim 5, characterized in that, The step of updating the global threshold based on the current average number of experts and the target average number of experts corresponding to the multiple lexical units includes: If the current average number of experts is greater than the target average number of experts, increase the global threshold; or if the current average number of experts is less than the target average number of experts, decrease the global threshold. The step of updating the local threshold based on the current load and the target load includes: If the current load is greater than the target load, increase the local threshold; or if the current load is less than the target load, decrease the local threshold.

7. The method according to claim 3, characterized in that, The method further includes: Based on the number of the plurality of lexical units and the target average number of experts corresponding to the plurality of lexical units, the computational cost of the target experts corresponding to the plurality of lexical units is obtained. The computational cost of the target experts is used to indicate the total number of computation pairs formed by the plurality of lexical units and the plurality of first expert feedforward networks. The target load is obtained based on the target expert computational load and the number of the plurality of first expert feedforward networks.

8. The method according to claim 1 or 2, characterized in that, The process of processing the assigned target lexical units through each of the first expert feedforward networks to obtain the inference result includes: The first expert feedforward network processes the assigned target word, and the output result of each first expert feedforward network for each target word is obtained. For each target word, the output of the corresponding first expert feedforward network is fused to obtain a fusion result; The fusion result is aggregated according to the aggregation matrix to obtain the inference result. The aggregation matrix is ​​obtained by transposing the selection matrix constructed by the computation pairs consisting of the multiple lexical units and the multiple first expert feedforward networks. The selection matrix is ​​used to indicate the position of the target lexical unit corresponding to each computation pair in the text sequence.

9. The method according to claim 1 or 2, characterized in that, The hybrid expert model further includes a routing module. After the text sequence is segmented into multiple tokens, the method further includes: Obtain the hidden state of each lexical element, wherein the hidden state is used to characterize the features of each lexical element; The routing module processes the hidden state of each word using a preset routing calculation function to obtain the initial routing score between each word and each of the first expert feedforward networks. The initial routing score is adjusted according to the inference difficulty of each term to obtain the routing score between each term and each first expert feedforward network, wherein the inference difficulty is positively correlated with the number of first expert feedforward networks corresponding to each term.

10. The method according to claim 1 or 2, characterized in that, The hybrid expert model consists of multiple hybrid expert layers, and the method further includes: The plurality of hybrid expert layers are divided into at least one routing group, and each routing group includes a target hybrid expert layer and at least one other hybrid expert layer; For each of the routing groups, the target hybrid expert layer performs the step of assigning a target word to each first expert feedforward network based on the routing score between each word and each first expert feedforward network and the routing score threshold corresponding to each first expert feedforward network; Each of the other hybrid expert layers assigns the target word to each of the first expert feedforward networks according to the allocation result of the target hybrid expert layer, and performs the step of processing the allocated target word through each of the first expert feedforward networks.