Expert selection method and device, electronic equipment and storage medium
By selecting the expert query vector of the attention head based on the model weight and input vector in the hybrid expert model, the problem of insufficient reasoning effect and computational efficiency of the hybrid expert model in the attention mechanism network is solved, and more efficient model performance and computing are achieved. Resource utilization.
Patent Information
- Application Number
- CN202410695200.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-24
AI Technical Summary
There is a lack of research on the application of hybrid expert models in attention mechanism networks and expert selection methods in the existing technology, resulting in insufficient model reasoning effects and computational efficiency.
Fine-grainedness is achieved by determining the attention head's selection score for the expert query vector based on the model weight and the input vector of the hybrid expert module, sorting and selecting the target expert query vector, and inputting it into the attention head to generate the output result of the hybrid expert module. Expert selection and computational effort are reduced.
It improves the reasoning effect and performance of the hybrid expert model, avoids redundancy and lack of knowledge, makes the expert combination richer, can flexibly perform different tasks, and reduces the calculation amount of the attention part.
Smart Images

Figure CN118690782A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to an expert selection method, device, electronic device and storage medium. Background Art
[0002] In the field of artificial intelligence technology, in order to make the machine learning model achieve better reasoning effect, it is often necessary to increase the model size. However, the increase in model size means higher computing costs. In order to achieve better results while reducing the amount of calculation, a hybrid expert implementation can be used, that is, only some parameters are selected for calculation.
[0003] The relevant technology is limited to building a hybrid expert model through multiple feedforward neural networks (FNN) and selecting some experts for model reasoning; there is a lack of research on hybrid expert models based on attention mechanisms and expert selection methods. Summary of the invention
[0004] The present application provides an expert selection method, device, electronic device and storage medium for implementing the application of a hybrid expert model in an attention mechanism network.
[0005] This application provides an expert selection method, comprising:
[0006] Based on the model weights and the input vector of the hybrid expert module, determine the selection score of each attention head for each expert query vector;
[0007] Sorting the selection scores, and selecting and determining a target expert query vector corresponding to each of the attention heads from each of the expert query vectors based on the sorting result;
[0008] Inputting the target expert query vector into the corresponding attention head to determine the first output result of each attention head;
[0009] Based on the first output result, a second output result of the hybrid expert module is determined.
[0010] In some embodiments, determining the selection score of each attention head for each expert query vector based on the model weight and the input vector of the hybrid expert module includes:
[0011] Based on the product of the model weight and the input vector of the hybrid expert module, a selection score of each attention head for each expert query vector is determined.
[0012] In some embodiments, the model weights are obtained after training a neural network including the hybrid expert module.
[0013] In some embodiments, the sorting of the selection scores and selecting and determining the target expert query vector corresponding to each of the attention heads from each of the expert query vectors based on the sorting result include:
[0014] Convert the selection score of each attention head for each expert query vector into the selection probability of each attention head for each expert query vector;
[0015] Based on the selection probability of each expert query vector by any attention head, each expert query vector is arranged in descending order to obtain an expert query vector sequence corresponding to any attention head;
[0016] A preset number of expert query vectors are selected from the expert query vector sequence in a front-to-back order as target expert query vectors corresponding to any one of the attention heads.
[0017] In some embodiments, the number of target expert query vectors corresponding to each attention head in the hybrid expert module is the same.
[0018] In some embodiments, determining a second output result of the hybrid expert module based on the first output result includes:
[0019] The first output results of each attention head are added together to obtain the second output result of the hybrid expert module.
[0020] The present application provides an expert selection device, comprising:
[0021] A calculation unit, used to determine the selection score of each attention head for each expert query vector based on the model weight and the input vector of the hybrid expert module;
[0022] A selection unit, configured to sort the selection scores, and select a target expert query vector corresponding to each of the attention heads from among the expert query vectors based on the sorting result;
[0023] An input unit, used to input the target expert query vector into a corresponding attention head, and determine a first output result of each attention head;
[0024] An output unit is used for determining a second output result of the hybrid expert module based on the first output result.
[0025] The present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the expert selection method is implemented when the processor executes the program.
[0026] The present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, and the computer program implements the expert selection method when executed by a processor.
[0027] The present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, the expert selection method is implemented.
[0028] The expert selection method, device, electronic device and storage medium provided in the present application determine the selection score of each attention head for each expert query vector based on the model weight in the hybrid expert module and the input vector of the hybrid expert module; sort the selection scores, and select and determine the target expert query vector corresponding to each attention head from each expert query vector based on the sorting result; input the target expert query vector into the corresponding attention head to determine the first output result of each attention head; determine the second output result of the hybrid expert module based on the first output result of each attention head; since some expert query vectors are selected from each expert query vector and input into each attention head for calculation, these selected expert query vectors are determined according to the model weight, so that for each attention head, the expert query vector can be selected in a more fine-grained manner, different tasks can be performed, and the features of different dimensions in the input vector can be paid attention to, so as to make full use of the attention information of each attention head, avoid knowledge redundancy and loss, make the expert combination of the entire hybrid expert module richer, and different tasks can be performed more flexibly, while reducing the calculation amount of the attention part, the reasoning effect and model performance of the entire model are improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0030] In order to more clearly illustrate the technical solutions in the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0031] Figure 1 It is one of the flowcharts of the expert selection method provided in this application;
[0032] Figure 2 This is the second flow chart of the expert selection method provided by this application;
[0033] Figure 3 It is a schematic diagram of the results of the expert selection provided by this application;
[0034] Figure 4 is a schematic diagram of the structure of the expert selection device provided by the present application;
[0035] Figure 5 It is a structural schematic diagram of the electronic device provided by this application. DETAILED DESCRIPTION
[0036] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0037] It should be noted that the terms "first", "second" etc. in the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable in appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, the process, method, system, product or equipment comprising a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0038] Model size is one of the key factors in improving the performance of machine learning models. In order to achieve better model performance of machine learning models, it is often necessary to increase the model size. However, the increase in model size means that more computing resources are needed, which increases the training and reasoning costs of the model. The hybrid expert model only selects some parameters for calculation. Compared with the dense model, the hybrid expert model can achieve the same model performance faster under limited computing resources.
[0039] Related technologies have achieved replacing the feedforward neural network layer in the Transformer model with a mixture of experts (MoE). The mixed expert model includes a gating network and a number of expert models. Each expert model can be a feedforward neural network. In the Transformer model, the mixed expert model selects some expert models for model reasoning through the gating network. The introduction of the mixed expert model makes it possible to train models with hundreds of billions or even trillions of parameters, and has been applied in the fields of natural language processing and computer vision.
[0040] However, how to apply the hybrid expert model in the attention mechanism network and how to select experts are still technical problems that need to be solved urgently in the industry.
[0041] To this end, this application proposes an expert selection method that can implement fine-grained expert selection in the attention mechanism network and reduce the amount of computation in the attention part. This method can be called the Mixture of Attention (MoA) model.
[0042] Figure 1 This is one of the flow charts of the expert selection method provided by this application, such as Figure 1 As shown, the method includes step 110 , step 120 , step 130 and step 140 .
[0043] Step 110: Determine the selection score of each attention head for each expert query vector based on the model weight and the input vector of the hybrid expert module.
[0044] Specifically, in the attention mechanism, the query vector represents the question or query asked by the current position or entity when calculating the attention. The number of query vectors represents the diversity of tasks. Increasing the number of query vectors can represent the diversity of tasks that the model needs to handle simultaneously. Each query vector can be regarded as corresponding to a task or a focus, so increasing the number of query vectors can make the model more flexible to handle multiple related but different tasks or focuses. Each attention head can focus on different aspects or features of the input vector. By increasing the number of query vectors, the model can focus on more different information at the same time, which improves the performance and applicability of the model.
[0045] The hybrid expert module in the embodiment of the present application is an expert module using a multi-head attention mechanism (Multi-HeadAttention), including multiple attention heads (attention head) and multiple expert query vectors (query). The hybrid expert module can be embedded in a neural network model as part of the model. The neural network model can include a Transformer model and a BERT (Bidirectional Encoder Representations from Transformers) model, etc.
[0046] When a large model is used for image processing, a token may refer to a region or feature in an image. For example, an image block obtained by segmenting an image may be used as a token.
[0047] When a large model is used for speech processing, a token may refer to a segment or feature in a speech signal, such as an audio frame obtained by segmenting a speech signal.
[0048] When the large model is used for natural language understanding or text generation, the input of the large model can be an input text, and the corresponding output text is obtained by using the above model calculation method. The feature unit (token) can refer to the smallest semantic unit in the text. The input vector of the large model can be obtained by encoding the feature unit (token) in the text.
[0049] Expert query vectors correspond to different tasks or focus points. Inputting different expert query vectors into the attention head can make the attention head focus on different aspects of the input vector. For example, the hybrid expert module can include 16 attention heads (head), which can be expressed as {head0, head1, ..., head15}. For each attention head, there are 8 expert query vectors (q). The expert query vector corresponding to any attention head can be expressed as {q0, q1, ..., q7}.
[0050] The larger the selection score, the more suitable the attention head is for inputting the corresponding expert query vector and performing the corresponding task. The selection score can be determined based on the product of the model weight and the input vector of the hybrid expert module.
[0051] The model weight is used to represent the correlation between each attention head and each expert query vector.
[0052] Step 120: sort the selection scores, and select and determine the target expert query vector corresponding to each attention head from each expert query vector based on the sorting result.
[0053] Specifically, the selection scores of each attention head for each expert query vector can be sorted in descending order according to their selection scores, and some expert query vectors can be selected from the descending order as the target expert query vectors corresponding to each attention head.
[0054] Taking any attention head corresponding to 8 expert query vectors as an example, the selection scores of the attention head for the 8 expert query vectors can be arranged in descending order, and the expert query vectors corresponding to the first two selection scores can be selected from the sorting results in order from front to back as the target expert query vectors corresponding to the attention head.
[0055] For each attention head, the number of target expert query vectors can be determined as needed. In the embodiment of the present application, only two are used for illustration, which should not be understood as limiting the number of target expert query vectors.
[0056] Step 130: Input the target expert query vector into the corresponding attention head to determine the first output result of each attention head.
[0057] Specifically, the target expert query vector is input into the corresponding attention head and calculated according to the attention mechanism to obtain the first output result of each attention head.
[0058] wq is the query vector projection matrix, wk is the key vector projection matrix, and wv is the value vector projection matrix. These projection matrices are used to change the input vector of the attention head to obtain the corresponding query vector (q), key vector (k), and value vector (v).
[0059] For example, for each attention head, there are 8 expert query vectors (q), 1 key vector (k) and 1 value vector (v). The key vector (k) and the value vector (v) are usually stored in a key-value matrix (KVcache). By sorting the selection scores of the 8 expert query vectors corresponding to any attention head, the first expert query vector and the fourth expert query vector are determined as the target query expert vectors. Then, the target expert query vector can be input into the attention head respectively, and calculated with the key vector (k) and the value vector (v) according to the calculation principle of the attention mechanism. After adding the output results, it is determined as the first output result of the attention head.
[0060] Step 140: Determine the second output result of the hybrid expert module based on the first output results of each attention head.
[0061] Specifically, the first output results of each attention head can be added together to serve as the second output result of the entire hybrid expert module.
[0062] The expert selection method provided in the embodiment of the present application determines the selection score of each attention head for each expert query vector based on the model weight in the hybrid expert module and the input vector of the hybrid expert module; sorts the selection scores, and selects and determines the target expert query vector corresponding to each attention head from each expert query vector based on the sorting result; inputs the target expert query vector into the corresponding attention head to determine the first output result of each attention head; determines the second output result of the hybrid expert module based on the first output result of each attention head; since some expert query vectors are selected from each expert query vector and input into each attention head for calculation, these selected expert query vectors are determined according to the model weight, so that for each attention head, the expert query vector can be selected in a more fine-grained manner, different tasks can be performed, and the features of different dimensions in the input vector can be paid attention to, so as to make full use of the attention information of each attention head, avoid knowledge redundancy and loss, make the expert combination of the entire hybrid expert module richer, can perform different tasks more flexibly, and improve the reasoning effect and model performance of the entire model while reducing the calculation amount of the attention part.
[0063] It should be noted that each implementation method of the present application can be freely combined, the order can be changed, or it can be executed separately, and does not need to rely on or depend on a fixed execution order.
[0064] In some embodiments, based on the model weight and the input vector of the hybrid expert module, determining the selection score of each attention head for each expert query vector includes:
[0065] Based on the product of the model weight and each expert query vector, a selection score of each attention head for each expert query vector is determined.
[0066] Specifically, the model weight is multiplied by the input vector of the hybrid expert module, and the product is used as the selection score of each attention head for each expert query vector. The larger the selection score, the more suitable the attention head is for inputting the corresponding expert query vector and performing the corresponding task.
[0067] The expert selection method provided in the embodiment of the present application determines the product of the model weight and the input vector of the hybrid expert module as the selection score of each attention head for each expert query vector, which is easy to calculate and is conducive to selecting the target expert query vector from each expert query vector.
[0068] In some embodiments, the model weights are obtained by training a neural network including a mixture of experts module.
[0069] Specifically, the model weights can be obtained through model training.
[0070] An initial value can be set for the model weight in the neural network including the hybrid expert module. Then the neural network including the hybrid expert module is trained, and during the training process, the size of the model weight is continuously adjusted by optimizing the loss function of the neural network to obtain the final model weight.
[0071] The expert selection method provided in the embodiment of the present application obtains model weights by training a neural network including a hybrid expert module, so that the hybrid expert module can adaptively select the best combination of attention heads and expert query vectors.
[0072] In some embodiments, sorting the selection scores, and selecting and determining the target expert query vector corresponding to each attention head from each expert query vector based on the sorting result, includes:
[0073] Convert the selection score of each attention head for each expert query vector into the selection probability of each attention head for each expert query vector;
[0074] Based on the selection probability of each expert query vector by any attention head, each expert query vector is sorted in descending order to obtain the expert query vector sequence corresponding to any attention head;
[0075] A preset number of expert query vectors are selected from the expert query vector sequence in order from front to back as the target expert query vectors corresponding to any attention head.
[0076] Specifically, in order to facilitate the comparison of the selection scores of each attention head for each expert query vector, the selection scores of each attention head for each expert query vector can be normalized. The Softmax function is a commonly used activation function, which is mainly used to convert a set of real numbers into a probability distribution. The function of the Softmax function is to normalize the input so that the value of each element is between 0 and 1, and the sum of all elements is equal to 1.
[0077] The Softmax function can be used to transform the selection score of each attention head for each expert query vector to obtain the probability representation of the selection score, that is, the selection probability of each attention head for each expert query vector.
[0078] Taking any attention head as an example, each expert query vector can be sorted in descending order according to the selection probability of each expert query vector by the attention head to obtain the expert query vector sequence corresponding to the attention head. In the expert query vector sequence, a preset number of expert query vectors can be selected as the target expert query vectors corresponding to the attention head. The preset number represents the number of target expert query vectors, which can be determined as needed, for example, it can be 2.
[0079] The above process can be implemented by the Top-k algorithm. The Top-k algorithm is an algorithm for selecting the top k largest or smallest elements in a data set. In an embodiment of the present application, the Softmax function and the Top-k algorithm can be combined to determine the target expert query vector corresponding to each attention head.
[0080] Figure 2 This is the second flow chart of the expert selection method provided by this application, such as Figure 2 As shown in Figure 1, the hybrid expert module contains 16 attention heads, each of which has 8 expert query vectors (q) to be selected.
[0081] The input vector of the hybrid expert module can be represented as activation. In a neural network containing a hybrid expert module, the input vector is the output result of other network layers of the neural network. The model weight between each attention head and the 8 expert query vectors to be selected corresponding to each attention head can be represented by a vector weight, which includes 128 model weights.
[0082] Multiplying the input vector activation by the vector weight yields vector X. This vector represents 128 selection scores. These 128 selection scores can be divided into 16 groups, corresponding to 16 attention heads; each group has 8 values, corresponding to the selection scores of each attention head for 8 expert query vectors.
[0083] By using the Softmax function and the Top-k (k=2) algorithm, the two largest values in each group of 8 values can be determined, and the expert query vectors corresponding to these two values are determined as the target expert query vectors corresponding to the attention head corresponding to the group.
[0084] Through the above process, the two target expert query vectors corresponding to each attention head can be determined respectively.
[0085] Figure 3 This is a schematic diagram of the results of expert selection provided by this application, such as Figure 3 As shown, the dotted box represents the combination of each attention head and each expert query vector, and the solid box represents the combination of the selected attention head and the target expert query vector.
[0086] In this embodiment, a total of 128 expert query vectors are input into 16 attention heads respectively, and each attention head selects 2 expert query vectors from the corresponding 8 expert query vectors to be selected for calculation, so that for each attention head, the expert query vector can be selected more finely, different tasks can be performed, and attention can be paid to the features of different dimensions in the input vector, so that the attention information of each attention head can be fully utilized, knowledge redundancy and loss can be avoided, different tasks can be performed more flexibly, and the reasoning effect and model performance of the whole model can be improved while reducing the calculation amount of the attention part.
[0087] In some embodiments, the number of target expert query vectors corresponding to each attention head in the hybrid expert module is the same.
[0088] Specifically, in the hybrid expert module, the number of target expert query vectors corresponding to each attention head can be set to the same value. For example, in the above embodiment, each attention head can select 2 target expert query vectors.
[0089] The number of target expert query vectors corresponding to each attention head in the hybrid expert module can be selected according to actual needs, such as 4 or 6. It can be understood that the more target expert query vectors are selected, the stronger the performance of the model will be. Correspondingly, the greater the computational complexity of the model will be, and the higher the training and inference costs will be.
[0090] In some embodiments, based on the first output result, determining a second output result of the hybrid expert module includes:
[0091] The first output results of each attention head are added together to obtain the second output result of the hybrid expert module.
[0092] Specifically, the first output results of each attention head can be added together as the second output result of the hybrid expert module.
[0093] For each attention head, due to the fine-grained selection of expert query vectors, it can focus on the features of different dimensions in the input vector, making full use of the attention information of each attention head and avoiding knowledge redundancy and loss. Although not all combinations of attention heads and expert query vectors participate in the final calculation, the selected combination of attention heads and expert query vectors can more effectively focus on the features in the input vector, making the output results of the hybrid expert module more accurate and reliable.
[0094] The device provided in the embodiment of the present application is described below. The device described below and the method described above can be referenced to each other.
[0095] Figure 4is a schematic diagram of the structure of the expert selection device provided by this application, such as Figure 4 As shown, the device comprises:
[0096] A calculation unit 410 is used to determine the selection score of each attention head for each expert query vector based on the model weight and the input vector of the hybrid expert module;
[0097] A selection unit 420 is used to sort the selection scores and select a target expert query vector corresponding to each attention head from each expert query vector based on the sorting result;
[0098] An input unit 430, configured to input the target expert query vector into a corresponding attention head and determine a first output result of each attention head;
[0099] The output unit 440 is used to determine the second output result of the hybrid expert module based on the first output result.
[0100] The expert selection device provided in the embodiment of the present application determines the selection score of each attention head for each expert query vector based on the model weight in the hybrid expert module and the input vector of the hybrid expert module; sorts the selection scores, and selects and determines the target expert query vector corresponding to each attention head from each expert query vector based on the sorting result; inputs the target expert query vector into the corresponding attention head to determine the first output result of each attention head; determines the second output result of the hybrid expert module based on the first output result of each attention head; since some expert query vectors are selected from each expert query vector and input into each attention head for calculation, these selected expert query vectors are determined according to the model weight, so that for each attention head, the expert query vector can be selected in a more fine-grained manner, different tasks can be performed, and the features of different dimensions in the input vector can be paid attention to, so as to make full use of the attention information of each attention head, avoid knowledge redundancy and loss, make the expert combination of the entire hybrid expert module richer, can perform different tasks more flexibly, and improve the reasoning effect and model performance of the entire model while reducing the calculation amount of the attention part.
[0101] In some embodiments, the computing unit is specifically configured to:
[0102] Based on the product of the model weight and the input vector of the hybrid expert module, the selection score of each attention head for each expert query vector is determined.
[0103] In some embodiments, the model weights are obtained by training a neural network including a hybrid expert module.
[0104] In some embodiments, the selection unit is specifically configured to:
[0105] Convert the selection score of each attention head for each expert query vector into the selection probability of each attention head for each expert query vector;
[0106] Based on the selection probability of each expert query vector by any attention head, each expert query vector is sorted in descending order to obtain the expert query vector sequence corresponding to any attention head;
[0107] A preset number of expert query vectors are selected from the expert query vector sequence in order from front to back as the target expert query vectors corresponding to any attention head.
[0108] In some embodiments, the number of target expert query vectors corresponding to each attention head in the hybrid expert module is the same.
[0109] In some embodiments, the output unit is specifically used to:
[0110] The first output results of each attention head are added together to obtain the second output result of the hybrid expert module.
[0111] Figure 5 is a schematic diagram of the structure of the electronic device provided by this application, such as Figure 5 As shown, the electronic device may include: a processor (Processor) 510, a communication interface (Communications Interface) 520, a memory (Memory) 530 and a communication bus (Communications Bus) 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic command in the memory 530 to execute the method described in the above embodiment, for example:
[0112] Based on the model weights and the input vector of the hybrid expert module, the selection score of each attention head for each expert query vector is determined; the selection scores are sorted, and the target expert query vector corresponding to each attention head is selected from the expert query vectors based on the sorting results; the target expert query vector is input into the corresponding attention head to determine the first output result of each attention head; based on the first output result, the second output result of the hybrid expert module is determined.
[0113] In addition, the logic commands in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several commands to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.
[0114] The processor in the electronic device provided in the embodiment of the present application can call the logic instructions in the memory to implement the above method. Its specific implementation method is consistent with the implementation method of the aforementioned method and can achieve the same beneficial effects, which will not be repeated here.
[0115] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the methods provided in the above embodiments are implemented.
[0116] Its specific implementation is consistent with the aforementioned method implementation and can achieve the same beneficial effects, so it will not be repeated here.
[0117] An embodiment of the present application provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0118] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0119] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0120] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An expert selection method, characterized in that: include: Based on the model weights and the input vector of the hybrid expert module, determine the selection score of each attention head for each expert query vector; Sorting the selection scores, and selecting and determining a target expert query vector corresponding to each of the attention heads from each of the expert query vectors based on the sorting result; Input the target expert query vector into the corresponding attention head to determine the first output result of each attention head; Based on the first output result, a second output result of the hybrid expert module is determined.
2. The expert selection method according to claim 1, characterized in that: The step of determining the selection score of each attention head for each expert query vector based on the model weight and the input vector of the hybrid expert module includes: Based on the product of the model weight and the input vector of the hybrid expert module, a selection score of each attention head for each expert query vector is determined.
3. The expert selection method according to claim 1, characterized in that: The model weights are obtained after training a neural network including the hybrid expert module.
4. The expert selection method according to claim 1, characterized in that: The step of sorting the selection scores and selecting and determining a target expert query vector corresponding to each of the attention heads from each of the expert query vectors based on the sorting result includes: Convert the selection score of each attention head for each expert query vector into the selection probability of each attention head for each expert query vector; Based on the selection probability of each expert query vector by any attention head, each expert query vector is arranged in descending order to obtain an expert query vector sequence corresponding to any attention head; A preset number of expert query vectors are selected from the expert query vector sequence in a front-to-back order as target expert query vectors corresponding to any one of the attention heads.
5. The expert selection method according to claim 4, characterized in that: The number of target expert query vectors corresponding to each attention head in the hybrid expert module is the same.
6. The expert selection method according to claim 1, characterized in that: The determining, based on the first output result, a second output result of the hybrid expert module comprises: The first output results of each attention head are added together to obtain the second output result of the hybrid expert module.
7. An expert selection device, characterized in that: include: A calculation unit, used to determine the selection score of each attention head for each expert query vector based on the model weight and the input vector of the hybrid expert module; A selection unit, configured to sort the selection scores, and select a target expert query vector corresponding to each of the attention heads from among the expert query vectors based on the sorting result; An input unit, used to input the target expert query vector into a corresponding attention head, and determine a first output result of each attention head; An output unit is used to determine a second output result of the hybrid expert module based on the first output result.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the expert selection method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the expert selection method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the expert selection method according to any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Battery RUL prediction method based on SMOE model and EIS
CN118917225A
Optimization method and device of hybrid expert system, computer equipment and readable storage medium
CN120449952A
Hierarchical hybrid expert model-based reasoning method and system, and storage medium
CN120471184A
Reasoning methods, systems, and storage media based on hierarchical hybrid expert models
CN120471184B
