Model quantization method and communication device
By smoothing and adjusting the weights of the expert layer and routing layer of the MoE model, the problem of outlier activation values during the quantization process of the MoE model is solved, improving the accuracy and efficiency of quantization while maintaining the inference accuracy of the model and the utilization rate of the expert layer.
Patent Information
- Application Number
- CN202510685222.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-25
- Publication Date
- 2026-11-27
AI Technical Summary
Existing hybrid expert models (MoE) face significant challenges in quantization due to outliers in activation values, and inconsistent activation value distributions across different expert layers affect the accuracy and efficiency of model quantization.
By aggregating the smoothing vectors of multiple expert layers, a unified smoothing vector is generated for activation value processing. Combined with the scaling vector of the routing layer, a first smoothing vector is determined to suppress outliers. At the same time, the weights of the routing layer are adjusted to maintain routing consistency before and after quantization. Incremental sampling calibration is performed on expert layers with insufficient coverage.
It effectively reduces the difficulty of model quantization, improves the accuracy and efficiency of model quantization, and maintains the precision of model inference and the utilization rate of the expert layer.
Smart Images

Figure CN123180233A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence (AI), and more specifically, to a model quantization method and a communication device. Background Technology
[0002] Mixture of experts (MoE) is a widely used architecture in machine learning and deep learning. MoE consists of many expert layers (or sub-models), but only a few expert layers are activated during each input processing, while others remain idle. This helps reduce computational cost and improve efficiency. To reduce the size of MoE and accelerate its inference speed, post-training quantization (PTQ) can be used to quantize it. The activation values of each expert layer in MoE may exhibit extremely large or small values (which we can refer to as outliers in this application). If quantized directly, these outliers will occupy most of the quantization interval, causing non-outliers to be compressed into a very small quantization interval, thus reducing the accuracy of non-outliers. Furthermore, since MoE includes many expert layers, the outliers of activation values from different expert layers exhibit different distributions, further increasing the difficulty of model quantization. Currently, quantizing MoE is quite challenging. Summary of the Invention
[0003] This application provides a model compression method and a communication device that can aggregate the smoothing vectors of multiple expert layers to obtain a unified smoothing vector. Using this unified smoothing vector to smooth the activation values of multiple expert layers can significantly suppress outliers in the activation values and reduce the difficulty of quantization.
[0004] Firstly, a model quantization method is provided, executed by a communication device or a module for the communication device (e.g., a processor, chip, circuit, AI entity, or a logic module, hardware, and / or software capable of implementing all or part of the functions of the communication device), wherein the communication device can be a network device or a terminal device. The method includes: obtaining a first model, the first model comprising multiple expert layers, each of the multiple expert layers corresponding to a smoothing vector, the smoothing vector being used to smooth the activation values of the corresponding expert layer; determining a first smoothing vector based on the smoothing vector corresponding to each of the multiple expert layers; and quantizing the first model based on the first smoothing vector.
[0005] Based on the above scheme, by aggregating the smoothed vectors of each expert layer of the first model, the outliers of the activation values of each expert layer of the first model can be effectively reduced, thereby reducing the overall model quantization difficulty.
[0006] In conjunction with the first aspect, in some implementations of the first aspect, the first model further includes a routing layer, which is used to select a target expert layer from the plurality of expert layers for processing the current task. The determination of the first smoothing vector based on the smoothing vector corresponding to each of the plurality of expert layers includes: determining the first smoothing vector based on the smoothing vector corresponding to each of the plurality of expert layers and the scaling vector of the routing layer. The scaling vector of the routing layer is related to the weight of the routing layer.
[0007] Based on the above scheme, the scaling vector of the routing layer can also participate in determining the unified smoothing vector, which aggregates the scaling requirements of the expert layer and the routing layer, and can increase the accuracy of the quantization of the first model.
[0008] Secondly, a model quantization method is provided, executed by a communication device or a module for the communication device (e.g., a processor, chip, circuit, AI entity, or a logic module, hardware, and / or software capable of implementing all or part of the functions of the communication device), wherein the communication device can be a network device or a terminal device. The method includes: acquiring a first model, the first model including a routing layer and multiple expert layers, the routing layer being used to select a target expert layer from the multiple expert layers for processing the current task; determining a first weight of the routing layer based on a first evaluation parameter, the first evaluation parameter being used to measure the difference between the probability distribution of the selection of the multiple expert layers before the first model quantization and the estimated probability distribution of the selection of the multiple expert layers after the first model quantization; and quantizing the first model based on the first weight of the routing layer.
[0009] Based on the above scheme, the consistency of expert selection can be maintained by aligning the probability distribution of the selection of multiple expert layers before and after quantization, thereby reducing the impact of quantization on model accuracy.
[0010] In conjunction with the second aspect, in some implementations of the second aspect, determining the first weight of the routing layer based on the first evaluation parameter includes: traversing the weights in the weight range of the routing layer to determine the first weight of the routing layer, wherein the first evaluation parameter corresponding to the first weight is the lowest.
[0011] In conjunction with the second aspect, in some implementations of the second aspect, determining the first weight of the routing layer based on the first evaluation parameter includes: determining the first weight of the routing layer based on the first evaluation parameter and the second evaluation parameter, wherein the second evaluation parameter is used to measure the difference between the output of the first model before quantization and the estimated output of the first model after quantization.
[0012] Based on the above scheme, the accuracy of model inference can be further maintained by aligning the output differences before and after quantization.
[0013] In conjunction with the second aspect, in some implementations of the second aspect, determining the first weight of the routing layer based on the first evaluation parameter and the second evaluation parameter includes: traversing the weights in the weight range of the routing layer to determine the first weight of the routing layer, wherein the sum of the first evaluation parameter and the second evaluation parameter corresponding to the first weight is the lowest.
[0014] Thirdly, a calibration method is provided, executed by a communication device or a module for the communication device (e.g., a processor, chip, circuit, AI entity, etc., or a logic module, hardware, and / or software capable of implementing all or part of the functions of the communication device), wherein the communication device can be a network device or a terminal device. The method includes: obtaining a first model comprising multiple expert layers, each expert layer being used to process subtasks of a current task, each task comprising multiple subtasks; constructing a first dataset for the first expert layer if the number of subtasks processed by the first expert layer is less than a first threshold, wherein the number of subtasks processed by the first expert layer in the first dataset is greater than or equal to the first threshold; and calibrating the weights of the first expert layer based on the first dataset.
[0015] Based on the above scheme, by incrementally sampling the expert layer with less calibration data coverage, the problem of excessive quantization error caused by insufficient calibration data coverage after quantization calibration can be alleviated.
[0016] In conjunction with the third aspect, in some implementations of the third aspect, the above method further includes: obtaining a basic dataset, which includes subtasks that can be processed by the above-mentioned multiple expert layers; constructing the first dataset of the first expert layer includes: constructing the first dataset of the first expert layer based on the above-mentioned basic dataset; calibrating the weights of the first expert layer based on the above-mentioned first dataset includes: calibrating the weights of the first expert layer based on the above-mentioned basic dataset and the above-mentioned first dataset.
[0017] Based on the above scheme, further introducing a basic dataset to calibrate the expert layer where calibration data coverage is insufficient can improve the calibration effect.
[0018] Fourthly, a communication device is provided, the communication device having the function of implementing the method of the first aspect, or any possible implementation of the first aspect. The function can be implemented by hardware, by software, or by hardware executing corresponding software. The hardware or software includes one or more units corresponding to the above-described function.
[0019] Fifthly, a communication device is provided, the communication device having the function of implementing the method of the second aspect, or any possible implementation of the second aspect. The function can be implemented by hardware, by software, or by hardware executing corresponding software. The hardware or software includes one or more units corresponding to the above-described function.
[0020] Sixthly, a communication device is provided, the communication device having the function of implementing the method of the third aspect, or any possible implementation of the third aspect. The function can be implemented by hardware, by software, or by hardware executing corresponding software. The hardware or software includes one or more units corresponding to the above-described function.
[0021] A seventh aspect provides a communication device including at least one processor configured to cause the communication device to perform methods of the first aspect to the third aspect, or any possible implementation thereof. Optionally, the at least one processor is coupled to at least one memory for storing computer programs or instructions, and the at least one processor is configured to call and execute the computer program or instructions from the at least one memory, causing the communication device to perform the methods of the first aspect or any possible implementation thereof; or perform the methods of the second aspect or any possible implementation thereof; or perform the methods of the third aspect or any possible implementation thereof. Optionally, the at least one processor may be included in the communication device or configured externally to the communication device. Optionally, the communication device further includes the at least one memory. Optionally, the communication device further includes a communication interface.
[0022] Eighthly, a communication device is provided, comprising a communication circuit and a processing circuit. The communication circuit is configured to receive a signal to be processed and transmit the signal to the processing circuit. The processing circuit is configured to process the signal to perform a method as described in the first aspect or any possible implementation thereof; or to perform a method as described in the second aspect or any possible implementation thereof; or to perform a method as described in the third aspect or any possible implementation thereof. Optionally, the communication circuit is further configured to output the processed signal. As an example, the communication circuit may be a transceiver, hardware circuit, bus, module, pin, or other type of communication interface. The signal includes information and / or data. Optionally, the communication device may be a chip or a chip system.
[0023] A ninth aspect provides a computer-readable storage medium storing computer program code or instructions that, when executed on a computer, cause the method of the first aspect or any possible implementation thereof to be implemented; or the method of the second aspect or any possible implementation thereof to be implemented; or the method of the third aspect or any possible implementation thereof to be implemented.
[0024] In a tenth aspect, a computer program product is provided, the computer program product comprising computer program code or instructions, which, when executed on a computer, cause the method in the first aspect or any possible implementation thereof to be implemented; or, as in the second aspect or any possible implementation thereof, the method to be implemented; or, as in the third aspect or any possible implementation thereof, the method to be implemented. Attached Figure Description
[0025] Figure 1 This is a schematic diagram of a model quantization method 100 provided in an embodiment of this application.
[0026] Figure 2 This is a schematic diagram of another model quantization method 200 provided in the embodiments of this application.
[0027] Figure 3 This is a schematic flowchart of a calibration method 300 provided in an embodiment of this application.
[0028] Figure 4 A schematic block diagram of the communication device 400 provided in this application.
[0029] Figure 5 A schematic block diagram of another communication device 500 provided in this application.
[0030] Figure 6 A schematic structural diagram of the chip provided in this application. Detailed Implementation
[0031] The technical solutions in this application will now be described with reference to the accompanying drawings.
[0032] Before introducing the scheme of this application, the following points should be noted.
[0033] (1) In this application, the expression " / " is used to indicate that the objects before and after are in an "or" relationship; for example, A / B can mean: A or B. The expression "and / or" is used to indicate that the objects before and after are in a relationship of either "and" or "or"; for example, A and / or B can mean the following: A exists alone, B exists alone, A and B exist simultaneously, where A and B can be single or multiple. "At least one of the following" or similar expressions are used to indicate any combination of the listed items; for example, at least one of A, B and / or C can mean the following: A exists alone, B exists alone, C exists alone, A and B exist simultaneously, B and C exist simultaneously, A and C exist simultaneously, A, B and C exist simultaneously, where A, B, and C can be single or multiple.
[0034] (2) In the various embodiments of this application, unless otherwise specified or logically conflicting, the terms and / or descriptions of different embodiments are consistent and can be referenced by each other. The technical features of different embodiments can be combined to form new embodiments according to their inherent logical relationship.
[0035] (3) In this application, “first” and “second” are used only for the convenience of description and to distinguish objects, and are not used to limit the scope of the embodiments of this application.
[0036] (4) In this application, the words “exemplary,” “for example,” etc., are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as an “example” in this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word “example” is intended to present the concept in a specific manner. In the embodiments of this application, “of,” “corresponding, relevant,” and “corresponding” may sometimes be used interchangeably, and it should be noted that their intended meanings are consistent unless their distinction is emphasized.
[0037] The following section introduces some related technologies involved in the technical solution of this application.
[0038] I. Mixture of Experts (MoE)
[0039] MoE is a widely used architecture in machine learning and deep learning. A MoE consists of many expert layers (or sub-models), but only a few expert layers (e.g., two) are activated each time input is processed, while the others remain idle. MoE achieves this by dividing the task among multiple expert layers, each handling a different sub-task. Its design theory is based on the following fundamental principles:
[0040] 1) Definition of Expert Layer (or Expert): In the MoE architecture, an "expert layer" refers to an independent model that learns and optimizes specifically for different subspaces of the dataset. Each expert layer may focus on solving a certain type of problem or processing a specific type of data, which allows each expert layer to perform better on local data;
[0041] 2) Gating Mechanism: The MoE architecture includes a routing layer (or gating network), which determines which expert layers should process a given input (or which expert layers to route it to), or the contribution of each expert layer to the final output. The routing layer dynamically allocates weights to different expert layers based on the characteristics of the input data, thus enabling adaptive processing of the input.
[0042] Generally, the routing layer selects the k most suitable expert layers from all expert layers as target expert layers to process the input. The specific selection steps are as follows: the routing layer generates a routing score for each expert layer based on the input; based on the routing scores of each expert layer, the routing layer selects the k expert layers with the highest scores (for example, 2), and the remaining expert layers are masked; the selected k expert layers process the input to obtain k outputs, and the k outputs are weighted and summed to obtain the final output.
[0043] 3) Sparsity Principle: MoE leverages the sparsity of knowledge, meaning that not all expert layers need to participate in processing every input. In practice, only a few expert layers are activated, which helps reduce computation and improve efficiency. This conditional computation allows the model to scale to very large sizes without sacrificing performance;
[0044] 4) Learning and Optimization: The learning process of the MoE model involves joint optimization by the expert layer and the routing layer. The expert layer is typically updated using traditional gradient descent methods, while the routing layer needs to learn how to correctly allocate inputs to the expert layer. The loss function of the entire system considers the outputs of all expert layers and the decisions of the routing layer.
[0045] 5) Scalability and Flexibility: Another advantage of the MoE architecture is its scalability and flexibility. The complexity and expressiveness of the model can be enhanced by adding more expert layers, while keeping the computational cost within a controllable range.
[0046] For example, the MoE architecture can be OLMoE-7B-1B, DeepSeekMoE-16B-3B, or Mixtral-8x7B, etc.
[0047] II. Post-training quantization (PTQ)
[0048] PTQ refers to quantizing the model directly after training, without needing to retrain, which is simpler and faster than quantizing during training.
[0049] PTQ is a technique used after a model has been trained to convert its weights and / or activation values from floating-point (FP) numbers (e.g., FP32) to low-precision values.
[0050] Model quantization can also be understood as model compression. By quantizing the model, we can reduce its size and speed up its inference, but it may also reduce the accuracy of the model's inference.
[0051] III. Activation Value
[0052] Activation values include activation values for the routing layer and activation values for the expert layer.
[0053] The activation value of the routing layer can be understood as the routing score generated by the routing layer for each expert layer based on the input x; the activation value of the expert layer can be understood as the feature representation calculated by the selected expert layer for the input x, or the mapping of the input x in the feature space of the selected expert layer.
[0054] The activation values of each expert layer in MoE may be extremely large or small (which we can refer to as outliers in the activation values). If directly quantized, these outliers will occupy most of the quantization interval, causing non-outliers to be compressed into an extremely small quantization interval, thus reducing the accuracy of non-outliers. Furthermore, MoE includes many expert layers, and the outliers of activation values in different expert layers exhibit different distributions, which further increases the difficulty of model quantization.
[0055] Based on this, this application proposes a model quantization method 100, which can aggregate the smoothing vectors of multiple expert layers to obtain a smoothing vector, and use a smoothing vector to perform unified smoothing on the activation values of multiple expert layers, thereby eliminating outliers in the activation values and stabilizing the quantization.
[0056] The model quantization method 100 provided in this application includes the following steps:
[0057] S101, Obtain the first model, which includes multiple expert layers, each of which corresponds to a smoothing vector, which is used to smooth the activation values of the corresponding expert layer.
[0058] For example, the first model described above can be MoE.
[0059] It should be understood that the purpose of the above smoothing process is to make the distribution of activation values of the corresponding expert layer more gradual and stable.
[0060] If there are outliers in the activation values of a certain expert layer, the smoothing vector corresponding to that expert layer is used to eliminate the outliers in the activation values of that expert layer, so that the activation values of that expert layer are evenly distributed in a range; if there are no outliers in the activation values of a certain expert layer (that is, all the activation values of that expert layer are normal values), then the smoothing vector corresponding to that expert layer does not need to process the activation values of that expert layer.
[0061] For example, common smoothing methods include standardization, activation function adjustment, and low-pass filtering. Standardization refers to standardizing the activation values of an expert layer so that they follow a distribution with a mean of 0 and a variance of 1. Activation function adjustment refers to replacing non-smooth activation functions (e.g., ReLU) with smooth activation functions (e.g., Swish, GELU) to reduce abrupt changes in activation values. Low-pass filtering refers to applying Gaussian filtering to activation values to suppress high-frequency noise.
[0062] For example, each of the multiple expert layers corresponds to a smoothing vector, which can be obtained by the following formula 1:
[0063]
[0064] In Formula 1, n represents the number of expert layers, i represents the i-th expert layer, x represents the input vector, token vector, or activation value, and w i Let α represent the weight of the i-th expert layer, and let α represent the maximum scaling ratio. This represents the smoothing vector corresponding to the i-th expert layer.
[0065] S102, determine the first smoothing vector based on the smoothing vector corresponding to each expert layer in the multiple expert layers.
[0066] In one possible implementation, the first model described above may further include a routing layer, which is used to select a target expert layer from the plurality of expert layers for processing the current task. S202 may be replaced by: determining the first smoothing vector based on the smoothing vector corresponding to each of the plurality of expert layers and the scaling vector of the routing layer.
[0067] The scaling vector of the routing layer mentioned above is related to the weight of the routing layer.
[0068] For example, the weight of the routing layer Let d represent the set of real numbers, and let d represent the dimension of the output of multiple expert layers.
[0069] For example, the scaling vector corresponding to this routing layer can be obtained using the following formula 2:
[0070]
[0071] In Formula 2, x represents the input vector, token vector, or activation value, and W... gate This represents the weight of the routing layer, where α is a coefficient, and s gate This represents the scaling vector of the routing layer.
[0072] One possible implementation involves determining a first smoothing vector based on the smoothing vector corresponding to each of the multiple expert layers and the scaling vector of the routing layer. Formula 3 can be satisfied:
[0073]
[0074] It can be seen that this implementation determines the first smoothing vector using the weights of multiple expert layers, or it determines the first smoothing vector using the weights of multiple expert layers and the weights of the routing layer. Alternatively, it can be understood that this implementation obtains the first smoothing vector by aggregating the maximum scaling of the weights of multiple expert layers, or by aggregating the maximum scaling of the weights of multiple expert layers and the maximum scaling of the weights of the routing layer.
[0075] Another possible implementation is to use the expert frequencies of multiple expert layers to determine the first smoothing vector.
[0076] Another possible implementation is to use the output of the routing layer (router_logits) to determine the first smoothing vector.
[0077] S103, quantize the first model based on the first smoothing vector.
[0078] For example, the method for quantizing the first model can be PTQ.
[0079] For example, the activation values of the expert layer of the first model can be smoothed first and / or the activation values of the routing layer of the first model can be smoothed first.
[0080] For example, multiple expert layers can be equivalently transformed using Equation 4:
[0081]
[0082] Among them, in formula 4 above This refers to the smoothed input vector, token vector, or activation value. The weights of the i-th expert layer after smoothing are given.
[0083] Formula 4 above can reduce the dynamic range of the activation values of the expert layer, that is, suppress the outliers of the activation values of the expert layer.
[0084] For example, the routing layer can be equivalently transformed using Equation 5:
[0085]
[0086] Formula 5 above can reduce the dynamic range of the activation value of the routing layer, that is, suppress the abnormal value of the activation value of the routing layer.
[0087] Among them, in formula 5 above The weights of the routing layer after smoothing.
[0088] Alternatively, the first smoothing vector described above can be fused into a normalization layer (RMSNorm / LayerNorm). For example, this fusion can be performed using the following formula 6:
[0089]
[0090] In Formula 6 above, γ represents the scaling factor, which is a parameter that can be used for machine learning or deep learning.
[0091] By aggregating the smoothed vectors of each expert layer of the first model using the aforementioned model quantization method 100, outliers in the activation values of each expert layer of the first model can be effectively reduced, thereby lowering the overall model quantization difficulty.
[0092] Inconsistencies may occur in the routing layer before and after model quantization. For example, the target expert selected may be different when processing the same task before and after model quantization. This indicates that quantization leads to a decrease in model accuracy.
[0093] Based on this, this application proposes a model quantization method 200, which can maintain the consistency of the routing before and after model quantization and ensure the accuracy of the model.
[0094] The model quantization method 200 provided in this application includes the following steps:
[0095] S201, Obtain the first model, which includes a routing layer and multiple expert layers.
[0096] Specifically, the routing layer is used to select the target expert layer from the multiple expert layers mentioned above to handle the current task.
[0097] For example, the first model described above can be MoE.
[0098] S202, determine the first weight of the routing layer based on the first evaluation parameters.
[0099] Specifically, the first evaluation parameter is used to measure the difference between the probability distribution of the selection of the multiple expert layers before the first model quantization and the estimated probability distribution of the selection of the multiple expert layers after the first model quantization.
[0100] For example, the first evaluation parameter can be the Kullback-Leibler divergence (or KL divergence), which can be denoted as D. KL .
[0101] For example, the probability distribution of the selection of the above-mentioned multiple expert layers before the first model quantization can be obtained through Equation 7:
[0102]
[0103] Among them, in formula 7 It can be obtained based on the equivalent transformation of Formula 5.
[0104] For example, the probability distribution of the selection of the above-mentioned multiple expert layers after the estimation of the first model quantization can be obtained through Equation 8:
[0105]
[0106] Among them, in formula 8 For one independent variable is The function.
[0107] For example, the weights in the weight range of the routing layer are traversed to determine the first weight of the routing layer, which corresponds to the lowest first evaluation parameter. That is, the weight corresponding to the lowest first evaluation parameter is selected as the first weight, and the weight corresponding to the lowest first evaluation parameter is traversed.
[0108] For example, the weight range of the routing layer can be predefined or preconfigured. Each weight in the weight range of the routing layer corresponds to a truncation ratio. For example, the truncation ratio of the routing layer weights can be (0,1). It should be understood that determining the first weight of the routing layer by traversing the weights in the weight range of the routing layer can be done by traversing the truncation ratio of the weights in the weight range of the routing layer and determining the optimal truncation ratio for the first weight.
[0109] One possible implementation is to determine the first weight of the routing layer based on the first and second evaluation parameters mentioned above.
[0110] Specifically, the second evaluation parameter mentioned above is used to measure the difference between the output of the first model before quantization and the estimated output of the first model after quantization.
[0111] For example, the second evaluation parameter can be the mean squared error loss (MSE) (or reconstruction error).
[0112] For example, the weights within the weight range of the routing layer are traversed to determine the first weight of the routing layer, which corresponds to the weight with the lowest sum of the first evaluation parameter and the second evaluation parameter. That is, the weight range of the routing layer is traversed, each weight corresponds to a value of a first evaluation parameter and a value of a second evaluation parameter, and the weight corresponding to the lowest sum of the first evaluation parameter and the second evaluation parameter is selected as the first weight.
[0113] For example, the weight corresponding to the minimum sum of the first evaluation parameter and the second evaluation parameter can be determined using Formula 9:
[0114]
[0115] In Formula 9 θ represents the Euclidean distance; θ represents the relevant parameters used for model quantization, such as the scaling factor and / or zero point; +· in Equation 9 can represent a custom operation, such as addition.
[0116] S203 quantizes the first model based on the first weight of the routing layer.
[0117] For example, the first quantization parameter s can be determined using Formula 10:
[0118]
[0119] In Formula 10, max(r) represents the maximum value in the range of routing layer weights, min(r) represents the minimum value in the range of routing layer weights, r1 represents the truncation ratio of the first weight, and b represents the number of bits after quantization.
[0120] Furthermore, the first model can be quantized using the aforementioned first quantization parameter.
[0121] The model quantization method 200 described above can maintain the consistency of expert selection by aligning the probability distributions of multiple expert layers selected before and after quantization, and can also maintain the accuracy of model inference by aligning the output differences before and after quantization.
[0122] Due to the sparsity principle of MoE, which means that not all expert layers need to participate in the processing of every input, the calibration data coverage of the few selected expert layers is insufficient, resulting in a decrease in the utilization rate of expert layers in MoE.
[0123] Based on this, this application proposes a calibration method 300, which can improve the coverage of calibration data of the rarely selected expert layer, improve the utilization rate of the expert layer of the model, and to a certain extent reduce the impact of model quantization on model accuracy.
[0124] The calibration method 300 provided in this application includes the following steps:
[0125] S301, Obtain the first model, which includes multiple expert layers.
[0126] Specifically, the expert layer is used to process sub-tasks (tokens) of a task, and each task includes multiple sub-tasks (tokens).
[0127] For example, the first model described above can be MoE.
[0128] S302, if the number of subtasks processed by the first expert layer among multiple expert layers is less than a first threshold, construct a first dataset of the first expert layer, wherein the number of subtasks processed by the first expert layer in the first dataset is greater than or equal to the first threshold.
[0129] The statement that the number of subtasks processed by the first expert layer in the aforementioned multiple expert layers is less than the first threshold can also be understood as the number of subtasks input to the first expert layer being less than the first threshold. Alternatively, the statement that the number of subtasks processed by the first expert layer in the multiple expert layers is less than the first threshold can also be understood as the number of subtasks input to the first expert layer being less than the first threshold.
[0130] For example, the first threshold can be set arbitrarily according to actual needs.
[0131] It should be understood that for a first expert layer with fewer types of input subtasks, more types of subtasks can be collected for the first expert layer until the types of input subtasks of the first expert layer meet the requirements, for example, the types of input subtasks of the first expert layer exceed a first threshold.
[0132] One possible implementation is to construct the first dataset of the first expert layer based on the basic dataset.
[0133] Specifically, the aforementioned basic dataset includes multiple sub-tasks that can be handled by multiple expert layers. For example, the basic dataset D can be constructed by sampling a portion of data from commonly used open-source general-purpose datasets (WikiText2 or C4). baseFor example, a dataset D can be constructed by sampling 128 sequences of length 4096, and then the dataset D can be input into the first model to collect the inputs of each expert layer of the first model to construct the basic dataset.
[0134] If the number of subtasks processed by the first expert layer is less than a first threshold, then new batches of data can be sampled from commonly used open-source general data (WikiText2 or C4) to construct the first dataset for the first expert layer. For example, the newly collected batches of data can be input into the first model, and the inputs of the first expert layer can be collected to construct the first dataset, until the first dataset contains more than the first threshold of inputs from the first expert layer.
[0135] S303, calibrate the weights of the first expert layer based on the first dataset.
[0136] One possible implementation is to calibrate the weights of the first expert layer based on the base dataset and the first dataset.
[0137] By using the above calibration method 300, incremental sampling can be performed on the expert layer with less calibration data coverage, which can eliminate the problem of low utilization of the expert layer caused by less calibration data coverage and reduce the impact of model quantization on model accuracy to a certain extent.
[0138] The method provided in this application has been described in detail above. The corresponding communication device is described below.
[0139] Figure 4 A schematic block diagram of the communication device 400 provided in this application. Figure 4 The communication device 400 may include a processing module 401 and a communication module 402. The communication device 400 may be a terminal device, or a communication device applied to or used in conjunction with a terminal device to achieve the corresponding functions of the terminal device, such as a processor, chip, circuit, or AI entity. Alternatively, the communication device 400 may be a network device, or a communication device applied to or used in conjunction with a network device to achieve the corresponding functions of the network device, such as a processor, chip, circuit, or AI entity.
[0140] The communication module can also be called a transceiver module, transceiver, transceiver unit, or transceiver device. The processing module can also be called a processor, processing board, processing unit, or processing device. Optionally, the communication module is used to perform the sending and receiving operations in the above method. The device in the communication module that implements the receiving function can be considered a receiving unit, and the device in the communication module that implements the sending function can be considered a sending unit; that is, the communication module includes a receiving unit and a sending unit. The processing module 401 of the communication device 400 can be used to implement... Figures 1-3The processing functions in each embodiment, the communication module 402 can be used to implement Figures 1-3 The transmitting and receiving functions in various embodiments. For example, the communication module 402 can be used to acquire the first model; the processing module 401 can be used to: determine the first smoothing vector, determine the first weight of the routing layer, construct the first dataset of the first expert layer, quantize the first model, etc.
[0141] Furthermore, it should be noted that the aforementioned communication module and / or processing module can be implemented through virtual modules. For example, the processing module can be implemented through software functional units or virtual devices, and the communication module can be implemented through software functions or virtual devices. Alternatively, the processing module or communication module can also be implemented through physical devices. For example, if the device is implemented using a chip / chip circuit, the communication module can be an input / output circuit and / or a communication interface to perform input and output operations; the processing module can be an integrated processor, microprocessor, or integrated circuit.
[0142] The module division in this application is illustrative and represents only one logical functional division. In actual implementation, other division methods are possible. Furthermore, the functional modules in the various examples of this application can be integrated into a single processor, exist as separate physical entities, or be integrated into a single module. The integrated modules described above can be implemented in hardware, as software functional modules, or a combination of hardware and software.
[0143] Figure 5 This is a schematic block diagram of another communication device 500 provided in this application. Optionally, the communication device 500 may be a chip or a chip system. Optionally, in this application, the chip system may be composed of chips or may include chips and other discrete components.
[0144] The communication device 500 may include at least one processor 510. Optionally, the processor 510 is coupled to a memory, which may be located within the communication device 500, integrated with the processor, or located outside the communication device 500. As an example, the communication device 500 may also include at least one memory 520. The memory 520 stores the necessary computer programs (or computer instructions) and / or data for implementing any of the above method embodiments; the processor 510 may execute the computer programs stored in the memory 520 to complete the methods implemented in any of the above method embodiments.
[0145] The communication device 500 may also include a communication interface 530, through which the communication device 500 can interact with other devices. For example, the communication interface 530 may be a transceiver, circuit, bus, module, pin, or other type of communication interface. When the communication device 500 is a chip-based device or circuit, the communication interface 530 in the device 500 may also be an input / output circuit, capable of inputting information (or receiving information) and outputting information (or sending information). The processor may be an integrated processor, a microprocessor, an integrated circuit, or a logic circuit, and the processor can determine the output information based on the input information.
[0146] The coupling in this application refers to indirect coupling or communication connection between devices, units, or modules, which can be electrical, mechanical, or other forms, used for information exchange between devices, units, or modules. The processor 510 may operate in conjunction with the memory 520 and the communication interface 530. This application does not limit the specific connection medium between the processor 510, the memory 520, and the communication interface 530.
[0147] Figure 6 This is a schematic structural diagram of the chip provided in this application. Chip 30 includes a processing circuit 31 and a communication circuit 32. The processing circuit 31 can be a logic circuit, integrated circuit, etc., and the communication circuit 32 can be an input / output circuit, input / output interface, interface circuit, etc., which can input information (or receive information) or output information (or send information). Chip 30 can execute the methods executed in the various embodiments of this application. The processing circuit 31 can be one or more processors, or all or part of the circuitry in one or more processors used for control or processing.
[0148] In addition, this application also provides a computer-readable storage medium storing computer instructions that, when executed on a computer, cause operations and / or processes performed by a communication device in the various method embodiments of this application to be executed.
[0149] This application also provides a computer program product, which includes computer program code or instructions. When the computer program code or instructions are run on a computer, the operations and / or processes performed by the first device in the various method embodiments of this application are executed.
[0150] This application also provides a chip including a processor, and a memory for storing a computer program disposed independently of the chip. The processor is used to execute the computer program stored in the memory, such that operations and / or processes performed by a communication device in any method embodiment are executed. Further, the chip may also include a communication interface. The communication interface may be an input / output interface or an interface circuit, etc. Further, the chip may also include a memory.
[0151] This application also provides a chip, which may include circuitry and an input / output interface. The circuitry may be logic circuitry, integrated circuits, etc., and exemplaryly, the circuitry may be one or more processors, or all or part of the circuitry in one or more processors used to implement one or more processing, control, or computing functions. The input / output interface may also be an input / output circuit, or an interface circuit, capable of inputting information (or receiving information) and / or outputting information (or sending information). The chip may include a chip system. Optionally, the chip system may be composed of chips or may include chips and other discrete devices. The chip can be used to execute the methods implemented by the communication device in the various embodiments of this application. Optionally, the chip may be a baseband chip, also known as a modem.
[0152] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0153] The processor in this application embodiment has signal processing capabilities and can be a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in this application can be directly implemented by the hardware processor, or implemented by a combination of hardware and software modules within the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above methods.
[0154] In the embodiments of this application, memory is any other medium capable of carrying or storing desired program code in the form of instructions or data structures, and accessible by a computer, but is not limited thereto. The memory in this application can also be a circuit or any other means capable of implementing a storage function for storing computer programs and / or data; or, it can also be a circuit or any other means capable of implementing a storage function for storing computer programs and / or data. As an example, memory can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which serves as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM). It should be noted that the memory used in the systems and methods described herein is intended to include, but is not limited to, the types described above or any other suitable types of memory.
[0155] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the 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 model quantization method, characterized in that, The method includes: Obtain a first model, which includes multiple expert layers. Each expert layer corresponds to a smoothing vector, which is used to smooth the activation values of the corresponding expert layer. Based on the smoothing vector corresponding to each of the plurality of expert layers, a first smoothing vector is determined; The first model is quantized based on the first smoothing vector.
2. The method according to claim 1, characterized in that, The first model further includes a routing layer, which is used to select a target expert layer from the plurality of expert layers to process the current task. The step of determining the first smoothing vector based on the smoothing vector corresponding to each of the plurality of expert layers includes: determining the first smoothing vector based on the smoothing vector corresponding to each of the plurality of expert layers and the scaling vector of the routing layer, wherein the scaling vector of the routing layer is related to the weight of the routing layer.
3. A model quantization method, characterized in that, The method includes: A first model is obtained, the first model including a routing layer and multiple expert layers, the routing layer being used to select a target expert layer from the multiple expert layers for processing the current task; The first weight of the routing layer is determined based on the first evaluation parameter, which is used to measure the difference between the probability distribution of the selection of the plurality of expert layers before the first model quantization and the estimated probability distribution of the selection of the plurality of expert layers after the first model quantization. The first model is quantized based on the first weight of the routing layer.
4. The method according to claim 3, characterized in that, The determination of the first weight of the routing layer based on the first evaluation parameter includes: The weights in the weight range of the routing layer are traversed to determine the first weight of the routing layer, and the first evaluation parameter corresponding to the first weight is the lowest.
5. The method according to claim 3 or 4, characterized in that, Determining the first weight of the routing layer based on the first evaluation parameter includes: determining the first weight of the routing layer based on the first evaluation parameter and the second evaluation parameter. The second evaluation parameter is used to measure the difference between the output of the first model before quantization and the estimated output of the first model after quantization.
6. The method according to claim 5, characterized in that, The determination of the first weight of the routing layer based on the first evaluation parameter and the second evaluation parameter includes: The weights in the weight range of the routing layer are traversed to determine the first weight of the routing layer, and the sum of the first evaluation parameter and the second evaluation parameter corresponding to the first weight is the lowest.
7. A calibration method, characterized in that, The method includes: Obtain a first model, which includes multiple expert layers, each of which is used to process sub-tasks of a task, and each task includes multiple sub-tasks. If the number of subtasks processed by the first expert layer in the plurality of expert layers is less than a first threshold, a first dataset of the first expert layer is constructed, wherein the number of subtasks processed by the first expert layer included in the first dataset is greater than or equal to the first threshold. The weights of the first expert layer are calibrated based on the first dataset.
8. The method according to claim 7, characterized in that, The construction of the first dataset of the first expert layer includes: obtaining a basic dataset, wherein the basic dataset includes sub-tasks that can be processed by the multiple expert layers; The construction of the first dataset of the first expert layer includes: constructing the first dataset of the first expert layer based on the basic dataset; The step of calibrating the weights of the first expert layer based on the first dataset includes: calibrating the weights of the first expert layer based on the basic dataset and the first dataset.
9. A communication device, characterized in that, Includes modules or units for performing the method according to any one of claims 1 to 8.
10. A communication device, characterized in that, Includes a processor for executing a computer program or instructions in a memory to cause the apparatus to perform the method of any one of claims 1 to 8.
11. The apparatus according to claim 10, characterized in that, The device further includes the memory and / or a communication interface, the communication interface being coupled to the processor. The communication interface is used for inputting and / or outputting information.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program or instructions that, when executed on a communication device, cause the communication device to perform the method as described in any one of claims 1 to 8.
13. A computer program product, characterized in that, The computer program product includes a computer program or instructions for performing the method as described in any one of claims 1 to 8.
