Model reasoning method and device based on mixed experts

By combining attention hybrid experts and neural network hybrid experts in a large model, decomposing feature vectors and performing feature decomposition, the problem of large models failing to fully utilize input and expert information is solved, and inference accuracy and performance are improved.

CN118657218APending Publication Date: 2024-09-17SHANGHAI BIREN TECH CO LTD
View PDF 0 Cites 6 Cited by

Patent Information

Application Number
CN202410775207.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

Existing large models fail to make full use of input vectors and expert information during the inference process, resulting in poor inference results.

Method used

Using a model inference method based on hybrid experts, the feature vector is input into the attention hybrid expert module for decomposition and attention calculation. Combined with the neural network hybrid expert module, the feature decomposition and hybrid experts are combined to enrich the relationship between feature subunits and experts. Combinations to make full use of input information.

Benefits of technology

It improves the reasoning accuracy and performance of large models, avoids information redundancy and loss, and improves the reasoning effect of the entire large model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118657218A
    Figure CN118657218A
Patent Text Reader

Abstract

The invention provides a model reasoning method and device based on hybrid experts, and relates to the technical field of artificial intelligence, and the method comprises the steps: inputting a feature vector into an attention hybrid expert module, enabling the attention hybrid expert module to decompose the feature vector into a plurality of feature sub-vectors, determining a corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation to obtain a first vector output by each attention head; inputting the first vector into a neural network hybrid expert module to obtain a second vector output by each neural network; and based on the second vector, determining a model reasoning result corresponding to the feature vector. According to the method and the device provided by the invention, the information in the input feature vector and the information in each expert are fully utilized, and the reasoning effect of the large model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a model reasoning method and device based on hybrid experts. Background Art

[0002] In the field of artificial intelligence technology, a large model refers to a machine learning model with a large parameter scale and complex model structure. Large models can capture and learn complex patterns and relationships in data and perform well in a variety of tasks, such as language translation, image recognition, natural language understanding and generation, etc.

[0003] The hybrid expert architecture is a special large model architecture that aims to improve efficiency and flexibility by decomposing a large model into multiple smaller sub-models (i.e., experts). Although large models using the hybrid expert architecture can reduce the consumption of computing resources to a certain extent, the input vectors and expert information are not fully utilized, resulting in poor reasoning effects of large models.

[0004] Therefore, how to improve the reasoning effect of large models has become a technical problem that needs to be solved urgently in the industry. Summary of the invention

[0005] The present application provides a model reasoning method and device based on hybrid experts, which are used to solve the technical problem of how to improve the reasoning effect of large models.

[0006] This application provides a model reasoning method based on mixed experts, including: Input the feature vector into the attention hybrid expert module, which decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, so as to obtain the first vector output by each attention head; Inputting the first vector into a neural network hybrid expert module to obtain a second vector output by each neural network; Based on the second vector, a model inference result corresponding to the feature vector is determined.

[0007] In some embodiments, the attention blending expert module is used to: Based on the feature vector, determine the key vector and value vector corresponding to each attention head in the attention hybrid expert module; perform dimension decomposition on the feature vector to obtain multiple feature sub-vectors; Perform a first expert routing selection on each feature sub-vector to determine the query vector projection matrix corresponding to each feature sub-vector; determine the first vector output by each attention head based on the query vector projection matrix corresponding to each feature sub-vector, and the key vector and value vector corresponding to each attention head.

[0008] In some embodiments, the neural network hybrid expert module is used to: Perform a second expert routing selection on the first vectors output by each attention head to determine the neural network corresponding to each first vector; input the first vectors into the corresponding neural network to obtain the second vectors output by each neural network.

[0009] In some embodiments, the neural network is a feed-forward neural network.

[0010] In some embodiments, the feedforward neural network includes multiple fully connected layers; the weight size in the fully connected layer is determined based on the dimension size of the feature sub-vector.

[0011] In some embodiments, determining the model inference result corresponding to the feature vector based on the second vector includes: Perform dimension fusion on the second vectors output by each neural network to obtain a third vector; The third vector is determined as the model inference result corresponding to the feature vector.

[0012] The present application provides a model reasoning device based on hybrid experts, comprising: A first hybrid expert unit is used to input the feature vector into an attention hybrid expert module, and the attention hybrid expert module decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, so as to obtain a first vector output by each attention head; A second hybrid expert unit, used for inputting the first vector into a neural network hybrid expert module to obtain a second vector output by each neural network; A result output unit is used to determine the model inference result corresponding to the feature vector based on the second vector.

[0013] 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 processor implements the hybrid expert-based model reasoning method when executing the computer program.

[0014] The present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the hybrid expert-based model reasoning method is implemented.

[0015] The present application provides a computer program product, including a computer program, which implements the hybrid expert-based model reasoning method when executed by a processor.

[0016] The model reasoning method based on hybrid experts provided in the present application inputs a feature vector into an attention hybrid expert module, which decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, thereby obtaining a first vector output by each attention head; inputs the first vector into a neural network hybrid expert module to obtain a second vector output by each neural network; based on the second vector, determines the model reasoning result corresponding to the feature vector; on the one hand, a combination of attention hybrid experts and neural network hybrid experts is adopted in the large model architecture, and on the other hand, the feature vector is decomposed into smaller and fine-grained feature sub-units, and the combination of feature decomposition and hybrid experts is enriched to enrich the combination between feature sub-units and experts, fully utilize the information in the input feature vector and the information in each expert, avoid information redundancy and loss, improve the accuracy of the large model reasoning result, and improve the reasoning effect and model performance of the entire large model. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] 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.

[0018] 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.

[0019] Figure 1 This is one of the flow charts of the model reasoning method based on hybrid experts provided in this application.

[0020] Figure 2 This is the second flowchart of the model reasoning method based on hybrid experts provided in this application.

[0021] Figure 3 It is a structural diagram of the model reasoning device based on hybrid experts provided in this application.

[0022] Figure 4 It is a structural schematic diagram of the electronic device provided by this application. DETAILED DESCRIPTION

[0023] In order to enable those skilled in the art to better understand the present application, the technical solutions 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 this application.

[0024] 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 or modules need not be limited to those steps or units or modules clearly listed, but may include other steps or units or modules that are not clearly listed or inherent to these processes, methods, products or equipment.

[0025] In related technologies, large language models (LLMs), also known as large models, usually use a hybrid expert architecture for reasoning. Each expert specializes in processing a specific type of input or task, and a gating network is responsible for dynamically selecting and weighting the outputs of these experts based on the input data. This approach allows the model to only activate relevant experts when processing different types of data, thereby reducing the consumption of computing resources and improving the degree of specialization of the model.

[0026] When a large model is inferred, it is usually mainly for attention calculation and feedforward neural network (FNN) calculation. In feedforward neural network calculation, multiple feedforward neural networks are used as expert modules, and some feedforward neural network experts are selected for calculation. This method is also called Mixture of Experts (MoE) implementation method.

[0027] In attention calculation, multiple attention heads or query vectors are used as expert modules, and some attention heads or query vectors are selected as expert modules for calculation. This method is also called Mixture of Attention (MoA) implementation method.

[0028] Whether it is MoE or MoA, when selecting expert modules, they are selected based on the activation of the complete hidden layer dimension. These activations of the complete hidden layer dimension generally represent feature units (tokens), but the same feature unit also contains different meanings in different contexts. If the selection is based on the complete hidden layer activation, the same expert will be selected for activation each time, and the input feature units and expert information will not be fully utilized, resulting in poor model reasoning effect.

[0029] In order to solve the shortcomings of related technologies, Figure 1 This is one of the flow charts of the model reasoning method based on hybrid experts provided in this application, such as Figure 1 As shown, the method includes step 110 , step 120 and step 130 .

[0030] Step 110: Input the feature vector into the attention hybrid expert module, which decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, and obtains the first vector output by each attention head.

[0031] Specifically, the hybrid expert-based model reasoning method provided in the embodiment of the present application is applicable to a large neural network model including an attention module and a feedforward neural network module. The neural network model may include a Transformer model and a BERT (Bidirectional Encoder Representations from Transformers) model, etc.

[0032] When a large model is used for image processing, a token may refer to an area or feature in an image. For example, an image block obtained by segmenting an image can be used as a feature unit. When a large model is used for speech processing, a token may refer to a segment or feature in a speech signal. For example, an audio frame obtained by segmenting a speech signal. When a large model is used for natural language understanding or text generation, the input of the large model may be an input text, and the above-mentioned model inference method may be used to obtain the corresponding output text. A token may refer to the smallest semantic unit in a text.

[0033] In the embodiment of the present application, the feature vector may be obtained by encoding a feature unit (token).

[0034] Structurally, the large model can at least include an attention hybrid expert module, a neural network hybrid expert module, and an inference result output module.

[0035] The attention hybrid expert module is an expert module that adopts a multi-head attention mechanism (Multi-Head Attention), including multiple attention heads.

[0036] After the feature vector is input into the attention hybrid expert module, the attention hybrid expert module can calculate the key vector (k) and the value vector (v) according to the current feature input vector; on the other hand, before calculating the query vector (q), the feature vector can be linearly transformed (linear) and dimensionally decomposed to obtain multiple feature sub-vectors, so as to convert the feature vector with larger dimensions into multiple feature sub-vectors with smaller dimensions, and the corresponding query vector projection matrix (wq) is selected according to each feature sub-vector for attention calculation, so as to obtain the first vector output by each attention head. The first vector is the result of attention calculation.

[0037] Step 120: Input the first vector into the neural network hybrid expert module to obtain the second vector output by each neural network.

[0038] Specifically, after the attention hybrid expert module performs attention calculation, the first vector output by each attention head in parallel is obtained. Different from the related art, in the model inference method provided in the embodiment of the present application, the first vector output by each attention head in parallel is not spliced ​​and fused. Instead, the first vector output by each attention head is input into the neural network hybrid expert module after normalization calculation, and the corresponding neural network is selected as the expert in the neural network hybrid expert module according to the first vector. The first vector is input into the corresponding expert (neural network) for calculation to obtain the second vector output by each neural network. The second vector is the result of the neural network calculation.

[0039] Step 130: Based on the second vector, determine the model inference result corresponding to the feature vector.

[0040] Specifically, after obtaining the second vectors output by each neural network, these second vectors can be linearly transformed (linear) and dimensionally fused to obtain the model inference result corresponding to the feature vector. The model inference result is in vector form, and its dimension size is the same as that of the feature vector.

[0041] The model reasoning method based on hybrid experts provided in the embodiment of the present application inputs a feature vector into an attention hybrid expert module, which decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation to obtain a first vector output by each attention head; inputs the first vector into a neural network hybrid expert module to obtain a second vector output by each neural network; based on the second vector, determines the model reasoning result corresponding to the feature vector; on the one hand, a combination of attention hybrid experts and neural network hybrid experts is adopted in the large model architecture, and on the other hand, the feature vector is decomposed into smaller and fine-grained feature sub-units, and the combination of feature decomposition and hybrid experts is enriched to enrich the combination between feature sub-units and experts, and fully utilizes the information in the input feature vector and the information in each expert, avoiding information redundancy and loss, improving the accuracy of the large model reasoning result, and improving the reasoning effect and model performance of the entire large model.

[0042] 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.

[0043] In some embodiments, the attention mixture expert module is used to: Based on the feature vector, determine the key vector and value vector corresponding to each attention head in the attention hybrid expert module; Decompose the feature vector into multiple feature sub-vectors; Perform a first expert routing selection on each feature sub-vector to determine the query vector projection matrix corresponding to each feature sub-vector; determine the first vector output by each attention head based on the query vector projection matrix corresponding to each feature sub-vector, and the key vector and value vector corresponding to each attention head.

[0044] Specifically, the feature unit (token) can be encoded to obtain a feature vector, and the feature vector is used as an input vector of the large model and input into the attention hybrid expert module in the large model.

[0045] The attention hybrid expert module can multiply the feature vector with the key vector projection matrix (wk) and the value vector projection matrix (wv) respectively to obtain the key vector (k) and value vector (v) corresponding to each attention head. The key vector (k) and value vector (v) can be stored in the key-value matrix (KVcache).

[0046] When calculating the query vector, the attention hybrid expert module can decompose the feature vector by linear transformation to obtain multiple feature sub-vectors. For each feature sub-vector, the first expert router selection is performed to determine the query vector projection matrix (wq) corresponding to each feature sub-vector.

[0047] The attention hybrid expert module can select the corresponding query vector projection matrix (wq) according to each feature sub-vector for calculation to obtain the query vector corresponding to each attention head; according to the query vector, key vector and value vector corresponding to each attention head, the first vector output by each attention head is determined. For example, a feature sub-vector may select 2 query vector projection matrices (wq) from M query vector projection matrices (wq) as experts.

[0048] The implementation method of the first expert routing selection can adopt the Mixture of Attention (MoA) implementation method. For example, the Mixture of Attention expert module can include a first routing submodule, which executes the following method: determine the selection score of each query vector projection matrix (wq) according to the product of the model weight (weight) and each feature subvector; sort the selection scores, and select a preset number of query vector projection matrices (wq) from each query vector projection matrix (wq) as experts in the order of the selection scores from high to low. Among them, the model weight (weight) is used to represent the correlation between each attention head and each query vector projection matrix (wq), which can be obtained through model training.

[0049] The model reasoning method based on hybrid experts provided in the embodiment of the present application enriches the combination between feature sub-units and experts in the attention hybrid expert module by combining feature decomposition and attention hybrid experts, makes full use of the information in the input feature vector and the information in each expert, avoids information redundancy and loss, and improves the accuracy of large model reasoning results.

[0050] In some embodiments, the neural network hybrid expert module is used to: Perform a second expert routing selection on the first vectors output by each attention head to determine the neural network corresponding to each first vector; input the first vectors into the corresponding neural network to obtain the second vectors output by each neural network.

[0051] Specifically, the first vectors outputted in parallel by each attention head are not concatenated, but are normalized and then inputted into the neural network hybrid expert module. The neural network hybrid expert module may include multiple neural networks.

[0052] The neural network hybrid expert module performs a second expert router selection on the first vectors output by each attention head, thereby determining the expert (neural network) corresponding to each first vector; each first vector is input into the corresponding expert (neural network), and each neural network calculates and outputs the second vector.

[0053] The implementation method of the second expert routing selection can adopt a mixture of experts (MoE) implementation method. For example, the neural network mixture expert module can include a second routing submodule, which executes the following method: according to the product of the model weight (weight) and each first vector, the selection score of each neural network is determined, the selection score is sorted, and a preset number of neural networks are selected from each neural network as experts in the order of the selection score from high to low. Among them, the model weight (weight) is used to represent the correlation between each first vector and each expert (neural network).

[0054] The hybrid expert-based model reasoning method provided in the embodiment of the present application enriches the combination of the first vector and the neural network hybrid expert module by combining the first vector and the neural network hybrid expert, makes full use of the information in the first vector and the information in each expert, avoids information redundancy and loss, and improves the accuracy of large model reasoning results.

[0055] In some embodiments, the neural network is a feed-forward neural network.

[0056] Specifically, the neural network in the neural network hybrid expert module may be a feedforward neural network.

[0057] Feedforward neural networks are usually used as important modules in encoders or decoders in large models. They can further extract features based on the attention mechanism, thereby enhancing the expressiveness of the model. For example, when using a large model for semantic understanding, a feedforward neural network can capture the dependencies between words, thereby enhancing the semantic expressiveness of the large model.

[0058] In some embodiments, the feedforward neural network includes multiple fully connected layers; the weight size in the fully connected layer is determined based on the dimension size of the feature sub-vector.

[0059] Specifically, a feedforward neural network can include multiple fully connected layers (FC). Each neuron in the current layer of the fully connected layer is connected to all neurons in the previous layer to achieve feature combination and conversion and generate new feature representations. In a feedforward neural network, the fully connected layer can be used to extract higher-level abstract features and improve the expressiveness of the model.

[0060] Each connection in the fully connected layer corresponds to a weight parameter. The weight parameters are optimized and learned through the back-propagation algorithm. The neural network uses these parameters to fit the training data, allowing the model to better predict and generalize.

[0061] The weight size refers to the size of the weight matrix composed of the weight parameters of all connections in the fully connected layer. Compared with the related art, the input of the model inference method provided in the embodiment of the present application is a plurality of feature sub-vectors with smaller dimensions obtained by decomposing the feature vector, and accordingly, the dimension size of each first vector in the neural network hybrid expert module is also reduced, and further, the weight size in the fully connected layer is also reduced.

[0062] For example, the feedforward neural network includes a first fully connected layer (FC1), a second fully connected layer (FC2) and a third fully connected layer (FC3). The weight size of the first fully connected layer (FC1) can be 2048*(β1*2048), the weight size of the second fully connected layer (FC2) can be 2048*(β1*2048), and the weight size of the third fully connected layer (FC3) can be (β1*2048)*2048. In an embodiment of the present application, since the dimensional size of each first vector in the neural network hybrid expert module is reduced, the weight size in the fully connected layer is also reduced accordingly, the weight size of the first fully connected layer (FC1) can be 128*(β2*128), the weight size of the second fully connected layer (FC2) can be 128*(β2*128), and the weight size of the third fully connected layer (FC3) can be (β2*128)*128. Among them, β1 and β2 are weight size coefficients. If the number of parameters is to be kept constant and the number of experts remains unchanged, β2 will be much larger than β1.

[0063] Taking into account that a larger number of experts will lead to more possible expert combinations, and a larger weight size may cause information redundancy, the embodiment of the present application scales the weight size of the fully connected layer in the feedforward neural network in proportion, and increases the number of experts accordingly. For example, the weight size of the first fully connected layer (FC1) can be 128*(β1*128), the weight size of the second fully connected layer (FC2) can be 128*(β1*128), and the weight size of the third fully connected layer (FC3) can be (β1*128)*128. While ensuring that the parameter quantity is consistent, the number of experts can be increased by 256 times, and the same treatment can be done on the attention hybrid expert module to increase the number of experts.

[0064] In the model reasoning method based on hybrid experts provided in the embodiment of the present application, the weight size in the fully connected layer is determined based on the dimensional size of the feature sub-vector. Compared with the prior art, at the same parameter scale, the size of the expert weight can be reduced, the number of experts can be increased, expert information redundancy can be prevented, and the possibility of expert combination can be increased.

[0065] In some embodiments, determining a model inference result corresponding to the feature vector based on the second vector includes: Perform dimension fusion on the second vectors output by each neural network to obtain a third vector; The third vector is determined as the model inference result corresponding to the feature vector.

[0066] Specifically, the second vectors output by each neural network can be dimensionally fused through linear transformation to obtain a third vector, which can be used as the model inference result corresponding to the feature vector. The dimension of the third vector can be the same as the dimension of the feature vector.

[0067] The model inference method based on hybrid experts provided in the embodiment of the present application obtains the model inference result corresponding to the feature vector by dimensional fusion of the second vectors output by each neural network, and performs feature fusion after attention hybrid expert selection and neural network hybrid expert selection, thereby making full use of the information in the input feature vector and the information in each expert, avoiding information redundancy and loss, and improving the accuracy of large model inference results.

[0068] Figure 2 This is the second flow chart of the model reasoning method based on hybrid experts provided in this application, such as Figure 2 As shown, the large model includes an attention hybrid expert module and a feedforward neural network expert hybrid module. There are 16 attention heads in the attention hybrid expert module, and the dimension size of each attention head is 128. The dimension size of the input vector is 2018 (128*16). There are M experts in both the attention hybrid expert module and the feedforward neural network expert hybrid module. The method includes: Step 210: When performing single-feature unit (token) reasoning, the dimension size of the input vector is 1*2048.

[0069] When calculating the key and value, we directly calculate and get the key values ​​of 16 attention heads. For example, we multiply the input vector with the key vector projection matrix (wk) and the value vector projection matrix (wv) to get the key vector and value vector corresponding to each attention head. The key vector can be expressed as {kh0, kh1, ..., kh15}, and the value vector can be expressed as {vh0, vh1, ..., vh15}.

[0070] When calculating the query, combined with MoA, the input vector is first calculated through linear transformation (w) to obtain 16 1*128 sub-vectors. Each 1x128 sub-vector is selected for routing (router), and the query vector projection matrix (wq) is selected as the expert calculation and mixed and added to obtain the query vector (q) of 1 attention head (head), and finally the query vector (q) of 16 attention heads (head) is obtained. When performing routing selection, assuming that the number of experts selected is 2, for each sub-vector, 2 query vector projection matrices need to be selected from M query vector projection matrices {wq0, wq1, ..., wqM} as experts. For example, the expert corresponding to a sub-vector is {wq0, wq2}.

[0071] In step 220, the 16 attention heads perform their own attention calculations respectively, and the attention calculation results of the 16 attention heads are obtained, which are then input into the feedforward neural network expert mixture module for calculation.

[0072] Step 230, the feedforward neural network expert hybrid module input is 16 1*128 vectors (attention calculation results of 16 attention heads), each 1*128 activation is routed (router) selected, there are 16 routing calculation results, each 1*128 vector enters the expert through MoE, and a 1*128 result is obtained by feedforward neural network calculation, and finally 16 1*128 vectors are obtained. When performing routing selection, assuming that the number of experts selected is 2, for each 1*128 vector, it is necessary to select 2 query vector projection matrices from M query vector projection matrices {FFN0, FFN 1, ..., FFN M} as experts, for example, the expert corresponding to a 1*128 vector is {FFN0, FFN2}.

[0073] Step 240: Calculate the linear transformation (w) of the 16 1*128 vectors to obtain a 1*2048 vector output.

[0074] 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.

[0075] Figure 3 is a schematic diagram of the structure of the model reasoning device based on hybrid experts provided in this application, such as Figure 3 As shown, the device comprises: The first hybrid expert unit 310 is used to input the feature vector into the attention hybrid expert module, and the attention hybrid expert module decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, so as to obtain the first vector output by each attention head; A second hybrid expert unit 320, used to input the first vector into the neural network hybrid expert module to obtain a second vector output by each neural network; The result output unit 330 is used to determine the model inference result corresponding to the feature vector based on the second vector.

[0076] The model reasoning device based on hybrid experts provided in the embodiment of the present application inputs the feature vector into the attention hybrid expert module, which decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, so as to obtain the first vector output by each attention head; inputs the first vector into the neural network hybrid expert module to obtain the second vector output by each neural network; based on the second vector, determines the model reasoning result corresponding to the feature vector; on the one hand, a combination of attention hybrid experts and neural network hybrid experts is adopted in the large model architecture, and on the other hand, the feature vector is decomposed into smaller and fine-grained feature sub-units, and the combination of feature decomposition and hybrid experts is enriched, and the information in the input feature vector and the information in each expert are fully utilized, so as to avoid information redundancy and loss, improve the accuracy of the large model reasoning result, and improve the reasoning effect and model performance of the entire large model.

[0077] In some embodiments, the attention mixture expert module is used to: Based on the feature vector, determine the key vector and value vector corresponding to each attention head in the attention hybrid expert module; Decompose the feature vector into multiple feature sub-vectors; Perform a first expert routing selection on each feature sub-vector to determine the query vector projection matrix corresponding to each feature sub-vector; determine the first vector output by each attention head based on the query vector projection matrix corresponding to each feature sub-vector, and the key vector and value vector corresponding to each attention head.

[0078] In some embodiments, the neural network hybrid expert module is used to: Perform a second expert routing selection on the first vectors output by each attention head to determine the neural network corresponding to each first vector; input the first vectors into the corresponding neural network to obtain the second vectors output by each neural network.

[0079] In some embodiments, the neural network is a feed-forward neural network.

[0080] In some embodiments, the feedforward neural network includes multiple fully connected layers; the weight size in the fully connected layer is determined based on the size of the feature subvector.

[0081] In some embodiments, the result output unit is used to: Perform dimension fusion on the second vectors output by each neural network to obtain a third vector; The third vector is determined as the model inference result corresponding to the feature vector.

[0082] Figure 4 is a schematic diagram of the structure of the electronic device provided by this application, such as Figure 4 As shown, the electronic device may include: a processor (Processor) 410, a communication interface (Communications Interface) 420, a memory (Memory) 430 and a communication bus (Communications Bus) 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic command in the memory 430 to execute the method described in the above embodiment, for example: The feature vector is input into the attention hybrid expert module, which decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, and obtains the first vector output by each attention head; the first vector is input into the neural network hybrid expert module to obtain the second vector output by each neural network; based on the second vector, the model inference result corresponding to the feature vector is determined.

[0083] 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.

[0084] 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.

[0085] 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.

[0086] Its specific implementation is consistent with the aforementioned method implementation and can achieve the same beneficial effects, so it will not be repeated here.

[0087] 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.

[0088] 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.

[0089] 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.

[0090] 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. A model reasoning method based on mixed experts, characterized in that: include: Input the feature vector into the attention hybrid expert module, which decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, so as to obtain the first vector output by each attention head; Inputting the first vector into a neural network hybrid expert module to obtain a second vector output by each neural network; Based on the second vector, a model inference result corresponding to the feature vector is determined.

2. The model reasoning method based on hybrid experts according to claim 1, characterized in that: The attention mixture expert module is used to: Based on the feature vector, determine the key vector and value vector corresponding to each attention head in the attention hybrid expert module; perform dimension decomposition on the feature vector to obtain multiple feature sub-vectors; Perform a first expert routing selection on each feature sub-vector to determine the query vector projection matrix corresponding to each feature sub-vector; determine the first vector output by each attention head based on the query vector projection matrix corresponding to each feature sub-vector, and the key vector and value vector corresponding to each attention head.

3. The model reasoning method based on hybrid experts according to claim 1, characterized in that: The neural network hybrid expert module is used to: Perform a second expert routing selection on the first vectors output by each attention head to determine the neural network corresponding to each first vector; input the first vectors into the corresponding neural network to obtain the second vectors output by each neural network.

4. The model reasoning method based on hybrid experts according to claim 3 is characterized in that: The neural network is a feedforward neural network.

5. The model reasoning method based on hybrid experts according to claim 4 is characterized in that: The feedforward neural network includes a plurality of fully connected layers; the weight size in the fully connected layer is determined based on the dimension size of the feature sub-vector.

6. The hybrid expert-based model reasoning method according to any one of claims 1 to 5, characterized in that: The determining, based on the second vector, a model inference result corresponding to the feature vector includes: Perform dimension fusion on the second vectors output by each neural network to obtain a third vector; The third vector is determined as the model inference result corresponding to the feature vector.

7. A model reasoning device based on mixed experts, characterized in that: include: A first hybrid expert unit is used to input the feature vector into an attention hybrid expert module, and the attention hybrid expert module decomposes the feature vector into multiple feature sub-vectors, and determines the corresponding query vector projection matrix based on each feature sub-vector to perform attention calculation, so as to obtain a first vector output by each attention head; A second hybrid expert unit, used for inputting the first vector into a neural network hybrid expert module to obtain a second vector output by each neural network; A result output unit is used to determine the model inference result corresponding to the feature vector based on the second vector.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the model reasoning method based on hybrid experts 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 model reasoning method based on hybrid experts is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the model reasoning method based on hybrid experts is implemented.

Citation Information

Cited By

  • LLM model-based reasoning calculation method and device

    CN118839775A

  • A method and device for reasoning calculation based on LLM model

    CN118839775B

  • Data processing method and device based on deep learning model, and medium

    CN119514631A

  • Charging station load prediction method and system based on hybrid expert model

    CN119760339A

  • A method and system for predicting charging station load based on a hybrid expert model

    CN119760339B