Instruction data processing method and device in processor, storage medium and electronic equipment

CN122884542APending Publication Date: 2026-10-09KUNWANG (SHANGHAI) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611039781.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-13
Publication Date
2026-10-09

AI Technical Summary

Technical Problem

该方式精度受限于表容量,受片上面积约束,表无法无限扩大,非采样点插值误差较大

Benefits of technology

[0010]本公开以乘加运算指令这一芯片通用指令完成了误差函数的高精度拟合,在未增加额外硬件开销的条件下兼顾了推理精度与芯片面积效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122884542A_ABST
    Figure CN122884542A_ABST
Patent Text Reader

Abstract

The present disclosure provides a method for processing instruction data in a processor, and relates to the fields of chips, processor instructions and deep learning. The method comprises: reading a pre-activation value output by a linear transformation for a current word element from a register, and reading a preset segmentation threshold from a memory; the preset segmentation threshold is determined based on a pre-activation value distribution corresponding to a sample word element, an expected fitting accuracy of an error function, and hardware resource consumption generated by fitting the error function; determining a change rate feature of the error function based on the pre-activation value and the preset segmentation threshold; the change rate feature is used to represent that the error function is in a saturation state or a growth state; taking two polynomial coefficient arrays in the memory as operands of a multiplication-addition operation instruction in the processor, fitting the error function in the saturation state or the growth state respectively to obtain a fitting value of the error function; and generating an activation feature of the current word element based on the fitting value of the error function. The present disclosure realizes high-precision fitting of the error function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This relates to the field of artificial intelligence technology, particularly to technologies such as chips, processor instructions, and deep learning. Specifically, it relates to a method, apparatus, electronic device, readable storage medium, and program product for processing instruction data in a processor. Background Technology

[0002] GELU (Gaussian Error Linear Unit) is an activation function widely used in natural language processing models such as the Transformer. GELU is defined as follows: Its calculation involves an error function. Since the error function is a transcendental function, its computational complexity is high, and AI chips typically do not design dedicated hardware units for it in order to save area.

[0003] In related technologies, lookup tables or function approximation methods are generally used to approximate the error function. The lookup table method involves pre-storing discrete sampling points in the chip's memory, and then looking up the table during online computation, supplemented by linear interpolation. The accuracy of this method is limited by the table capacity and on-chip area constraints, preventing the table from being infinitely expanded, and the interpolation error for non-sampling points is relatively large. The function approximation method typically uses the hyperbolic tangent function to approximate the error function. Although it can reuse special function units in the chip, it differs from the standard error function by approximately 10%. -4 The approximation error at this level is insufficient to meet the activation accuracy requirements of natural language processing models. Summary of the Invention

[0004] This disclosure provides a method, apparatus, electronic device, readable storage medium, and program product for processing instruction data in a processor.

[0005] According to one aspect of this disclosure, a method for instruction data processing in a processor is provided, the method comprising: The pre-activation value of the linear transformation output for the current word is read from the register, and a preset segmentation threshold is read from the memory; wherein, the preset segmentation threshold is determined based on the distribution of pre-activation values ​​corresponding to the sample word, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function; Based on the pre-activation value and the preset segmentation threshold, the rate of change characteristic of the error function is determined; wherein, the rate of change characteristic is used to characterize whether the error function is in a saturated state or a growing state; Using two sets of polynomial coefficients in memory as operands of multiply-accumulate instructions in the processor, the error function in the saturated state or the growing state is fitted to obtain the fitted value of the error function. Based on the fitted value of the error function, the activation features of the current word are generated.

[0006] According to another aspect of this disclosure, an instruction data processing apparatus in a processor is provided, the apparatus comprising: The data reading module is used to read the pre-activation value of the linear transformation output for the current word from the register, and to read the preset segmentation threshold from the memory; wherein, the preset segmentation threshold is determined based on the distribution of the pre-activation values ​​corresponding to the sample word, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function; The feature determination module is used to determine the rate of change feature of the error function based on the pre-activation value and the preset segmentation threshold; wherein the rate of change feature is used to characterize whether the error function is in a saturated state or a growing state; The function fitting module is used to use two sets of polynomial coefficients in memory as operands of multiply-accumulate instructions in the processor to fit the error function in the saturation state or the growth state respectively, and obtain the fitted value of the error function. The result determination module is used to generate the activation features of the current word based on the fitted value of the error function.

[0007] According to another aspect of this disclosure, an electronic device is provided, the electronic device comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the instruction-data processing method in the processor according to any embodiment of this disclosure.

[0008] According to another aspect of this disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to perform the instruction data processing method in a processor according to any embodiment of this disclosure.

[0009] According to another aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the instruction-data processing method in a processor according to any embodiment of this disclosure.

[0010] This disclosure achieves high-precision fitting of the error function using the multiply-accumulate instruction, a common chip instruction, balancing inference accuracy and chip area efficiency without increasing additional hardware overhead.

[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0012] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein: Figure 1 This is a flowchart of an instruction-data processing method in a processor according to an embodiment of the present disclosure; Figure 2 This is a flowchart of another instruction-data processing method in a processor according to an embodiment of the present disclosure; Figure 3 This is a flowchart of another instruction-data processing method in a processor according to an embodiment of the present disclosure; Figure 4 This is a flowchart of another instruction-data processing method in a processor according to an embodiment of the present disclosure; Figure 5 This is a schematic diagram of the structure of an instruction and data processing device in a processor according to an embodiment of the present disclosure; Figure 6 A block diagram of an electronic device used to implement an instruction data processing method in a processor according to an embodiment of the present disclosure. Detailed Implementation

[0013] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0014] Figure 1 This is a flowchart illustrating an instruction-data processing method in a processor according to an embodiment of the present disclosure. This embodiment is applicable to implementing high-precision calculation of the GELU activation function on AI chips lacking dedicated error function hardware units. The method can be executed by an instruction-data processing device in a processor, which can be implemented in hardware and / or software and can be configured in an electronic device. Reference Figure 1 The method specifically includes the following: S101. Read the pre-activation value of the linear transformation output for the current word from the register, and read the preset segmentation threshold from the memory; wherein, the preset segmentation threshold is determined based on the distribution of pre-activation values ​​corresponding to the sample word, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function.

[0015] S102. Based on the pre-activation value and the preset segmentation threshold, determine the rate of change characteristic of the error function; wherein, the rate of change characteristic is used to characterize whether the error function is in a saturated state or a growing state.

[0016] S103. Using the two sets of polynomial coefficients in the memory as operands of the multiply-accumulate operation instruction in the processor, the error function in the saturation state or the growth state is fitted respectively to obtain the fitted value of the error function.

[0017] S104. Based on the fitted value of the error function, generate the activation feature of the current word.

[0018] Here, the current term refers to the term being processed by the processor during the online inference stage. It flows sequentially through each processing sub-layer of the transformer model. In each sub-layer, it undergoes a linear transformation to output a pre-activation value, which is then processed by an activation function to generate activation features, which are then passed to the next sub-layer. A term is the smallest input unit obtained by the transformer model after segmenting the input text; one input text corresponds to one term sequence.

[0019] Pre-activation values ​​refer to the floating-point values ​​output by the linear transformation of the previous sub-layer in the transformer model that have not yet been processed by the activation function. They represent the intermediate feature representation of the current word in the current processing sub-layer. Activation features are the feature representations obtained after the current word undergoes a nonlinear transformation using the GELU activation function. These activation features will serve as the input to the linear transformation of the next sub-layer and continue to participate in the forward propagation calculation of the transformer model.

[0020] The pre-activation value is stored in the chip's register. After the processor reads the pre-activation value of the current term from the register, it scales the pre-activation value using a scaling factor to obtain the scaled result. The scaling factor is the normalized coefficient of the independent variable of the error function in the GELU function definition. Its function is to adjust the numerical range of the pre-activation value to fit the domain of the error function.

[0021] Simultaneously, the processor reads a preset segmentation threshold from memory. This preset segmentation threshold is a numerical boundary point jointly determined and stored in constant memory based on the pre-activation value distribution of sample words, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function. Specifically, the preset segmentation threshold is a numerical boundary point jointly determined offline and stored in memory based on the pre-activation value distribution of sample words, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function. The pre-activation value distribution of sample words refers to the probability density distribution formed by inputting sample words into the trained transformer model for forward propagation in the offline stage, collecting the pre-activation values ​​of the linear transformation outputs in each processing layer, and statistically analyzing the probability of their occurrence in each numerical interval within the effective domain. This distribution reflects the frequency of different numerical intervals in actual inference. Sample words are the words used to collect the pre-activation value distribution, and they originate from representative text segmentation results.

[0022] The expected fitting accuracy of the error function refers to the maximum allowable approximation error between the fitted value obtained by the processor using a polynomial coefficient set to fit the error function in the offline stage and the standard value of the error function. This accuracy requirement stems from the converter model's need for accuracy in calculating activation features and serves as a threshold value for determining whether the fitting error meets the requirements. The hardware resource consumption generated by fitting the error function refers to the amount of hardware resources consumed in the processor when fitting the error function in the saturated or growing state using a polynomial coefficient set, including instruction types, the total number of each type of instruction, and the execution cycle of each type of instruction. This hardware resource consumption is combined with the pre-activated value distribution when determining the preset segmentation threshold as the basis for selecting the optimal boundary point.

[0023] The scaling results of the preset segmentation threshold and the pre-activated value jointly determine the rate of change characteristic of the error function. The preset segmentation threshold is used to divide the scaling result into two numerical intervals, corresponding to the saturation state and the growth state of the error function, respectively. The rate of change characteristic refers to the two different trends exhibited by the first derivative of the error function within the numerical interval of the scaling result: when the absolute value of the scaling result is less than the preset segmentation threshold, the error function starts from the origin, and the function value increases significantly with the input, the derivative is large and changes steadily, this state is defined as the growth state; when the absolute value of the scaling result is greater than or equal to the preset segmentation threshold, the error function has approached its asymptote ±1, the derivative approaches zero, the function value tends to saturate, this state is defined as the saturation state.

[0024] The standard mathematical form of the error function is: The definition indicates that when the input value is small, the error function grows approximately linearly; when the input value is large, the error function rapidly approaches saturation. This difference in the rate of change makes it difficult for a single polynomial to achieve high-precision fitting across the entire domain. Two sets of polynomial coefficients are stored simultaneously in memory, used to fit the error function in either the saturated or growing state to obtain the fitted value. In the growing state, the function value increases significantly with the input, making it suitable to directly approximate the error function with a polynomial. In the saturated state, the function value has approached its asymptote, making it difficult to achieve high precision by directly fitting the error function with a polynomial. Instead, the decay characteristics of the complementary error function are utilized; the complementary error function is approximated with a polynomial and then converted back into the error function, effectively ensuring the approximation accuracy across the entire domain.

[0025] Both sets of polynomial coefficients are optimized and determined offline and stored in memory. During online inference, the processor directly selects the appropriate coefficients based on the rate of change characteristics, enabling the multiply-accumulate instruction to complete the fitting with the optimal coefficients in both states without the need for online coefficient adjustment, thus ensuring the determinism and low latency of the calculation process.

[0026] Both sets of polynomial coefficients were obtained through numerical optimization search in the offline stage and are stored in constant memory. During online inference, they are selected by the comparator as fixed operands of the multiply-accumulate instructions in the processor. The determination of the fitted value of the error function relies solely on the existing multiply-accumulate instructions and other general instructions in the processor.

[0027] After the fitted value of the error function is determined, the following definition of the GELU activation function is used: By processing the fitted value of the error function, the activation features of the current word can be obtained.

[0028] in, The fitted value of the corresponding error function needs to be added by a constant 1, multiplied by 0.5, and then multiplied by the pre-activation value of the current word to obtain the activation feature of the current word. The fitted value of the error function already meets the preset fitting accuracy. After the above combined calculation, the final output of the GELU activation function can meet the preset fitting accuracy in the entire domain, providing a reliable feature representation for the semantic calculation of subsequent layers of the transformer model.

[0029] This disclosed technical solution divides the pre-activated value into two intervals—the growth state and the saturation state—corresponding to the error function by setting a preset segmentation threshold. This allows the processor to dynamically select one of the two polynomial coefficient sets in memory as the operand for the multiply-accumulate instruction based on the rate of change characteristics. The preset segmentation threshold is determined offline based on the distribution of pre-activated values ​​corresponding to sample words, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function. It comprehensively considers the distribution density of pre-activated values ​​and hardware resource consumption, providing a reliable boundary basis for selecting the appropriate polynomial coefficient set during online inference. This ensures that each interval can be fitted with the most suitable polynomial coefficient set, thereby achieving high-precision fitting of the error function across the entire domain, ensuring that the fitted value of the error function meets the expected fitting accuracy. The two polynomial coefficient sets are fixed in memory, and the fitting process only relies on the existing multiply-accumulate unit and other general instruction execution units in the processor. There is no need to configure a dedicated error function hardware unit, and it does not occupy on-chip static memory to build a lookup table. It balances inference accuracy and chip area efficiency with only a constant level increase in storage overhead.

[0030] In an optional embodiment, two sets of polynomial coefficients in memory are used as operands of multiply-accumulate instructions in the processor to fit the error function in either the saturated state or the growing state, respectively, to obtain the fitted value of the error function. This includes: if the error function is in the saturated state, processing the pre-activated value using a first set of pre-stored polynomial coefficients in memory as an operand of the multiply-accumulate instructions in the processor to obtain the fitted value of a gradually changing function; the gradually changing function is obtained by taking the logarithm of the complementary error function; for the fitted value of the gradually changing function, exponential operation instructions and bit operation instructions in the processor are executed sequentially to convert the fitted value of the gradually changing function into a fitted value of each point to be fitted with respect to the error function; if the error function is in the growing state, processing the pre-activated value using a second set of pre-stored polynomial coefficients in memory as an operand of the multiply-accumulate instructions in the processor to obtain the fitted value of the error function.

[0031] The two polynomial coefficient sets differ in their fitting targets and polynomial degrees. For ease of description, the polynomial coefficient set used to fit the saturated state is called the first polynomial coefficient set, and the one used to fit the growing state is called the second polynomial coefficient set. The number of terms in both polynomial coefficient sets is predetermined based on the expected fitting accuracy and the upper limit of the hardware multiplication-accumulation degree.

[0032] The first set of polynomial coefficients is a set of polynomial coefficients obtained and solidified in the offline stage using a fully qualified coefficient search to fit the slowly varying function (logarithmically transformed from the complementary error function). The complementary error function, defined as erfc(x) = 1 - erf(x), is a complementary form of the error function. In a saturated state, the error function's growth is almost stagnant, making direct fitting difficult to achieve high accuracy. Instead, the exponential decay and numerical concentration of the complementary error function in the fractional part are utilized. By fitting the slowly varying function after its logarithmic transformation using fully qualified coefficients, its non-odd / even characteristic is adapted, ensuring that all effective accuracy is preserved in the decimal places. Then, exponential operations are performed to restore the complementary error function and attach a sign, thus guaranteeing fitting accuracy across the entire domain. The slowly varying function is... .

[0033] The transformation processor uses the coefficient set of the first polynomial as the operand of a multiply-accumulate instruction. a × b + c The operation involves a fusion of multiply-accumulate instructions, where operands refer to the input data involved in the multiplication and addition operations. The multiply-accumulate instruction performs multiplication and addition operations on the pre-activated value to obtain the fitted value of the gradually varying function. Then, exponentiation and bitwise operation instructions are executed sequentially to convert the fitted value of the gradually varying function into a fitted value of the error function for each point to be fitted. Specifically, the exponentiation instruction refers to a hardware instruction in the processor that calculates powers to base 2, used to restore the fitted value of the gradually varying function to the fitted value of the complementary error function; the bitwise operation instructions refer to bitwise AND and bitwise OR instructions in the processor, used to extract the sign bit from the pre-activated value and restore it to the fitted result, obtaining the fitted value of the signed error function.

[0034] The second polynomial coefficient set refers to the set of polynomial coefficients obtained and fixed in the offline stage by searching for odd-degree coefficients with the error function itself as the fitting target. In the growing state, the error function has a regular odd-degree function shape, and the odd-degree coefficients are adapted to its odd-degree function characteristics. Since the odd-degree coefficients only contain odd-degree terms, the number of coefficients is halved, improving computational efficiency. The processor uses the second polynomial coefficient set as an operand for multiply-accumulate instructions, directly executing multiply-accumulate instructions on the pre-activated values ​​to obtain the fitted value of the error function.

[0035] The above technical solution addresses the difference in the rate of change of the error function between saturation and growth states by employing different fitting strategies: In the saturation state, a slowly varying function constructed by taking the logarithm of the complementary error function is used to convert the exponential decay into a gradually changing form. This allows the processor to perform high-precision polynomial fitting on the pre-activated value using the first set of polynomial coefficients as operands for multiply-accumulate instructions, followed by exponentiation and bit manipulation instructions to restore the fitted value of the error function. In the growth state, the fitted value of the error function is obtained by directly using the second set of polynomial coefficients as operands for multiply-accumulate instructions on the pre-activated value. Thus, the fitting accuracy of the error function across the entire domain is guaranteed by two sets of polynomial coefficients. The entire fitting process relies solely on the processor's existing multiply-accumulate, exponentiation, and bit manipulation instructions, eliminating the need for dedicated error function hardware units or lookup tables. By requiring only two sets of polynomial coefficients to be pre-stored in memory, both computational accuracy and chip area efficiency are achieved.

[0036] In an optional embodiment, the current word and the sample word are input units obtained by the transformer model from word segmentation of the input text. The current word is output as the pre-activation value after linear transformation in the transformer model, and the sample word is used to collect the distribution of pre-activation values ​​through forward propagation of the transformer model.

[0037] Transformer models are neural network models based on self-attention mechanisms, used to perform natural language processing tasks such as machine translation, text summarization, question answering systems, or sentiment analysis. Transformer models typically contain multiple stacked encoding and decoding layers, with each layer performing feature mapping on the input sequence through linear transformations.

[0038] During online inference, the transformer model receives the input text and segments it into a sequence of tokens. The current token refers to the input unit currently being processed by the processor within that token sequence. The processor needs to extract features from this input unit to determine its semantic representation within the input text. The processor reads the pre-activation value of the current token after linear transformation from the register. After the activation features of the current token are determined, they are passed to subsequent sub-layers for further processing and participation in the forward propagation.

[0039] Sample words are input units obtained by segmenting representative text of a task in the offline stage when performing natural language processing tasks. The processor inputs sample words into the trained transformer model to perform forward propagation, collects the pre-activation values ​​of the output of each linear transformer sub-layer, and statistically analyzes their numerical distribution, i.e., the pre-activation value distribution, which is used to determine the preset segmentation threshold and two sets of polynomial coefficients in the offline stage.

[0040] The above technical solution defines the current lexical unit and sample lexical units as input units obtained by the transformer model from word segmentation of the input text. This directly links the generation of pre-activation values ​​and the acquisition of their distribution to the linear transformation and forward propagation of the transformer model. By determining the preset segmentation threshold and polynomial coefficient set based on the pre-activation value distribution, the activation features generated by the processor meet the preset fitting accuracy requirements. This effectively suppresses the accumulation of activation value errors between multiple encoding and decoding layers, ensuring the accuracy of lexical semantic representation. Therefore, it meets the accuracy requirements of the transformer model in natural language processing tasks and improves the processing quality of downstream tasks.

[0041] Figure 2 This is a flowchart of another instruction data processing method in a processor according to an embodiment of the present disclosure; this embodiment is an optional solution proposed based on the above embodiments, specifically, it provides a scheme for determining a preset segmentation threshold.

[0042] See Figure 2 The instruction data processing method in the processor provided in this embodiment includes: S201. Traverse the candidate segmentation thresholds and determine the growth range and saturation range of the error function based on the pre-activation value corresponding to the sample word and the current segmentation threshold.

[0043] Among them, the candidate segment threshold refers to a number of boundary values ​​to be filtered, generated at a fixed step size within a preset numerical range. The growth interval refers to the numerical range where the absolute value of the pre-activated value is less than the current segment threshold, and the error function changes significantly with the input growth within the growth interval, indicating an increasing state. The saturation interval refers to the numerical range where the absolute value of the pre-activated value is greater than or equal to the current segment threshold, and the error function has approached its asymptote within the saturation interval, indicating a saturated state.

[0044] The lower bound of the preset numerical range is the minimum feasible threshold determined by the constraint that the saturation interval should not be too wide, preventing the first polynomial coefficient set from failing to meet the expected fitting accuracy, given that the number of terms in the polynomial coefficient set is predetermined. The upper bound is the maximum effective threshold determined by the constraint that the error function saturates outside this boundary and the pre-activated values ​​are almost zero outside this interval. Therefore, the preset numerical range is defined by both accuracy feasibility and distribution coverage after the number of terms in the polynomial coefficient set is determined, ensuring that subsequent traversal searches have sufficient breadth to cover the optimal solution while avoiding wasted computational overhead in invalid intervals. Optionally, when the number of terms in the polynomial coefficient set is 13, the preset numerical range is set to [0.5, 3.0]. This is because 0.5 is the minimum feasible threshold that prevents the starting point of the saturation interval from being too low, resulting in an excessively wide saturation interval that would prevent the first polynomial coefficient set from meeting the expected fitting accuracy in this interval, given that the number of terms in the polynomial coefficient set is predetermined to be 13. 3.0 is the critical point where the error function has entered deep saturation, the function value approaches ±1 and hardly changes anymore, and at the same time, the proportion of samples with absolute values ​​greater than 3.0 in the pre-activation value distribution is extremely low. Continuing to search outside this boundary has no practical engineering value.

[0045] S202. Solve the first polynomial coefficient set in the saturation interval using the complementary error function as the fitting object and store it in the memory; and solve the second polynomial coefficient set in the growth interval using the error function as the fitting object and store it in the memory; wherein the number of terms in the polynomial coefficient set is predetermined based on the expected fitting accuracy and the upper limit of the number of hardware multiplication and addition operations.

[0046] The number of terms in the polynomial coefficient set is predetermined based on the expected fitting accuracy and the upper limit of the hardware multiply-accumulate instruction count. The upper limit of the hardware multiply-accumulate instruction count refers to the maximum number of times the processor executes multiply-accumulate instructions, which is determined by the chip's hardware resources. After the number of terms is predetermined, the first polynomial coefficient set is solved in the saturation interval using the complementary error function as the fitting object. The complementary error function decays exponentially in the saturation state, and its values ​​are concentrated in the fractional part. After constructing a slowly varying function by taking its logarithm, the asymptotic expansion coefficients of the slowly varying function are used as the search starting point. The first polynomial coefficient set is obtained through numerical optimization iteration and stored in memory. The first polynomial coefficient set uses full-degree coefficients to perform polynomial fitting on the pre-activated values ​​in the saturation state during online inference. In the growth interval, the second polynomial coefficient set is solved using the error function as the fitting object. Taking advantage of the property that the error function is an odd function, the Taylor expansion coefficients of the error function at the origin are used as the search starting point. The second polynomial coefficient set is obtained through numerical optimization iteration and stored in memory. The second polynomial coefficient set uses odd-degree coefficients, with half the number of coefficients compared to all-degree coefficients. It is used to perform polynomial fitting on pre-activated values ​​that are in a growing state during online inference. The fitting object refers to the objective function that the polynomial approximation approximates; the search starting point refers to the initial values ​​of the coefficients in the numerical optimization iteration.

[0047] S203. If the fitting errors corresponding to the first polynomial coefficient group and the second polynomial coefficient group both meet the expected fitting accuracy, then the current segmentation threshold is determined as the effective segmentation threshold.

[0048] Fitting error refers to the maximum absolute deviation between the fitted value of the polynomial coefficient set and the standard function value in the corresponding interval. If the fitting errors corresponding to the first and second polynomial coefficient sets both meet the expected fitting accuracy, it means that the current segmentation threshold, under the condition that the number of terms is fixed in advance, can make the polynomial approximation accuracy in both the saturation interval and the growth interval simultaneously reach the preset threshold requirement. This means that the current segmentation threshold is an effective dividing point and can be determined as an effective segmentation threshold.

[0049] S204. Based on the distribution of pre-activation values ​​corresponding to the sample lexical units and the hardware resource consumption generated by fitting the error function, determine the preset segmentation threshold from the effective segmentation threshold and store it in the memory.

[0050] The activation value distribution reflects the probability of pre-activated values ​​appearing in the saturation and growth intervals. If the growth interval defined by a certain effective segmentation threshold covers most of the pre-activated values, more data will be fitted through the second polynomial coefficient set with fewer multiply-accumulate instructions during online inference, resulting in higher overall computational efficiency. Hardware resource consumption reflects the instruction overhead generated by the processor when executing the multiply-accumulate instruction sequences of the first and second polynomial coefficient sets respectively. The instruction sequence lengths and instruction types differ between the saturation and growth intervals, leading to differences in resource consumption. Therefore, the process of determining the preset segmentation threshold from the effective segmentation thresholds is based on two dimensions: data distribution matching efficiency and instruction execution overhead differences. On the one hand, priority is given to selecting the boundary point that allows high-frequency data to fall into the interval with lower resource consumption; on the other hand, the total instruction overhead of each effective segmentation threshold in the two intervals is comprehensively compared. Finally, the effective segmentation threshold with the minimum hardware resource consumption under a given pre-activated value distribution is selected as the preset segmentation threshold. The preset segmentation threshold is then stored in memory for direct retrieval during online inference.

[0051] The technical solution disclosed herein integrates the determination of the segmented threshold, the solution of the polynomial coefficient set, and the hardware resource consumption into a unified search process. This ensures that the preset segmented threshold can match the data distribution and instruction overhead during actual inference of the processor, while meeting the fitting accuracy of the entire domain. Thus, a balance between accuracy and efficiency is achieved within the constraints of hardware resources.

[0052] In an optional embodiment, determining the growth range and saturation range of the error function based on the pre-activation value corresponding to the sample word and the current segmentation threshold includes: determining an effective domain for the pre-activation value corresponding to the sample word, and using the current segmentation threshold as a boundary, determining the portion of the effective domain whose absolute value is greater than or equal to the current segmentation threshold as the saturation range; and using the current segmentation threshold as a boundary, determining the portion of the effective domain whose absolute value is less than the current segmentation threshold as the growth range.

[0053] The effective domain refers to the range of values ​​for which the pre-activation values ​​corresponding to the sample words have practical significance in terms of numerical statistics. Pre-activation values ​​outside this range are either rarely seen or already in the deep saturation region of the error function and therefore do not make a substantial contribution to the parameter determination.

[0054] The current segment threshold refers to the boundary value being traversed and tested in the candidate segment threshold sequence. Using the current segment threshold as the boundary, the effective domain is divided into a saturation interval and a growth interval: the saturation interval refers to the range of values ​​in the effective domain where the absolute value of the pre-activated value is greater than or equal to the current segment threshold. Within this range, the rate of change of the error function approaches zero, and the function value has approached its asymptote, thus entering a saturation state. The growth interval refers to the range of values ​​in the effective domain where the absolute value of the pre-activated value is less than the current segment threshold. Within this range, the error function changes significantly with the increase of the input, thus entering a growth state.

[0055] The above technical solution, by determining the effective domain for the pre-activated value and dividing the effective domain into a saturation interval and a growth interval using the current segmentation threshold as the boundary, clearly separates the numerical range of the error function under two different rate-of-change characteristics. This division directly corresponds to the mathematical characteristics of the error function: in the growth interval with small absolute values, the function value increases significantly with the input, making it suitable for direct polynomial fitting; in the saturation interval with large absolute values, the function value has approached the asymptote, requiring a different fitting strategy. Therefore, when solving the polynomial coefficient set subsequently, the coefficients can be optimized separately for each interval, avoiding the difficulty of a single polynomial simultaneously achieving the expected fitting accuracy in different intervals. This ensures that both intervals achieve the expected fitting accuracy, providing a reliable basis for the final selection of the preset segmentation threshold.

[0056] In an optional embodiment, determining the preset segmentation threshold and storing it in the memory based on the distribution of pre-activation values ​​corresponding to the sample words and the hardware resource consumption generated by fitting the error function among the effective segmentation thresholds includes: for each effective segmentation threshold, determining a first probability that the pre-activation value corresponding to the sample word falls into the saturation interval and a second probability that the pre-activation value falls into the growth interval based on the numerical distribution of the pre-activation values ​​corresponding to the sample words; determining a first resource consumption generated by executing instructions in the saturation interval and a second resource consumption generated by executing instructions in the growth interval based on the total number of instructions of each type corresponding to the saturation interval and the execution cycle of each type of instruction; weighting the first resource consumption and the second resource consumption with the first probability and the second probability respectively to obtain the total resource consumption of the effective segmentation threshold; selecting the effective segmentation threshold with the smallest total resource consumption as the preset segmentation threshold and storing it in the memory.

[0057] The effective segmentation threshold refers to the candidate segmentation threshold that, during the traversal of candidate segmentation thresholds, is found to have fitting errors that meet the expected fitting accuracy for both the saturation and growth intervals. The effective segmentation threshold only guarantees that the fitting accuracy meets the standard for two intervals, but different effective segmentation thresholds result in different ranges for the saturation and growth intervals, leading to different probabilities of pre-activated values ​​falling into each interval. This, in turn, results in different total resource consumption by the processor during online inference. Therefore, a further evaluation of the effective segmentation threshold is needed based on the distribution of pre-activated values ​​corresponding to sample words and the hardware resource consumption generated by the fitting error function.

[0058] The pre-activation value distribution refers to the probability distribution formed by inputting sample words into a trained transformer model for forward propagation during the offline phase, collecting each pre-activation value, and statistically analyzing its frequency of occurrence in each numerical interval within the effective domain. Based on the pre-activation value distribution, the first probability of a sample word's corresponding pre-activation value falling into the saturation interval and the second probability of it falling into the growth interval can be determined. The first probability refers to the probability of a pre-activation value appearing in the saturation interval, and the second probability refers to the probability of a pre-activation value appearing in the growth interval; both together reflect the data distribution density in these two states.

[0059] Instruction type refers to different types of instructions in a processor, such as multiply-accumulate instructions, exponentiation instructions, and bit manipulation instructions. It also includes basic arithmetic instructions like addition and subtraction instructions that accompany the actual execution of the instruction sequence. The total number of instructions refers to the number of each type of instruction in the instruction sequence corresponding to the saturation or growth interval. The execution cycle of each instruction refers to the number of clock cycles required for each instruction to complete one operation on the processor. In a processor, the execution cycles of different instruction types differ: multiply-accumulate instructions are typically completed in one or several cycles; exponentiation instructions, due to their more complex hardware calculation logic, usually have execution cycles several times longer than multiply-accumulate instructions, and are the main source of incremental resource consumption in the saturation interval; the execution cycles of basic arithmetic instructions such as addition, subtraction, and bit manipulation instructions are usually comparable to or shorter than those of multiply-accumulate instructions. The first resource consumption generated by executing instructions in the saturation interval and the second resource consumption generated by executing instructions in the growth interval are determined separately. The first resource consumption refers to the total amount of hardware resources consumed by the processor when executing the corresponding instruction sequence to process the pre-activated value in a saturated state using the first polynomial coefficient set; the second resource consumption refers to the total amount of hardware resources consumed by the processor when executing the corresponding instruction sequence to process the pre-activated value in an increasing state using the second polynomial coefficient set.

[0060] Using the first probability and the second probability as weights, the first resource consumption and the second resource consumption are weighted and summed respectively to obtain the total resource consumption of the effective segmentation threshold. The total resource consumption refers to the average hardware overhead corresponding to the effective segmentation threshold after considering the distribution probability of the pre-activated value in the two states and their respective hardware resource consumption.

[0061] Select the effective segmentation threshold with the minimum total resource consumption as the preset segmentation threshold and store it in the memory.

[0062] The above technical solution introduces the distribution of pre-activated values ​​and hardware resource consumption as screening dimensions. It quantifies the data distribution density in two states by calculating the first probability of a pre-activated value falling into the saturation interval and the second probability of it falling into the growth interval. Simultaneously, it determines the first and second resource consumption based on the instruction type, the total number of instructions of each type, and the execution cycle of each instruction for each interval. The resource consumption of the two intervals is weighted and summed using probability as the weight to obtain the total resource consumption. Finally, the effective segmentation threshold with the minimum total resource consumption is selected as the preset segmentation threshold. This ensures that the preset segmentation threshold not only meets the fitting accuracy requirements of the entire domain but also matches the distribution characteristics of pre-activated values ​​and the hardware overhead of each instruction sequence during actual inference. This ensures that high-frequency data is processed through intervals with lower resource consumption as much as possible, thereby minimizing the average instruction overhead under accuracy constraints, while balancing inference efficiency and chip area utilization.

[0063] In an optional embodiment, the number of terms in the polynomial coefficient set is determined as follows: based on the distribution of pre-activation values ​​corresponding to the sample lexical units and the saturation characteristics of the error function, a first test interval and a second test interval are determined; starting from the initial multiply-accumulate count, the count is increased, and the first polynomial coefficient set and the second polynomial coefficient set are solved in the first test range and the second test interval respectively to check the fitting error under the current multiply-accumulate count; if the fitting error under the current multiply-accumulate count meets the expected fitting accuracy, and the current multiply-accumulate count does not exceed the upper limit of the hardware multiply-accumulate count, then the number of terms in the polynomial coefficient set is determined based on the current multiply-accumulate count and fixed.

[0064] The first and second test intervals are two fixed numerical ranges predetermined in the offline phase, independent of candidate segmentation thresholds. The first test interval is used to verify whether the maximum fitting error of the polynomial to the growth state of the error function under a given multiplication-accumulation degree meets the expected fitting accuracy. Its range is determined based on the main coverage area of ​​the growth state in the pre-activated value distribution. Optionally, the first test interval is selected based on the saturation characteristic that the error function approaches the asymptote ±1 when the absolute value of the independent variable is greater than 3.0, and the statistical result that almost all scaling results in the pre-activated value distribution fall within 2.0. This ensures that the growth intervals divided by any candidate segmentation threshold in the subsequent threshold search all fall within this test interval.

[0065] The second test interval is used to verify whether the maximum fitting error of the polynomial to the saturation state of the error function under a given multiplication-accumulation degree meets the expected fitting accuracy. Its range is determined based on the saturation characteristics of the error function and the distribution range of the pre-activation values ​​in the saturation state. Optionally, the starting point of the second test interval follows the ending point of the first test interval, 3.0. The ending point is set in the interval [3.0, 8.0] based on the characteristic that the complementary error function is below the minimum representable precision of the processor when the absolute value of the independent variable is greater than 8.0, and is practically equivalent to zero in hardware. This ensures that the saturation intervals divided by any candidate segment threshold in the subsequent threshold search all fall within this test interval.

[0066] The initial multiply-accumulate count refers to the minimum number of multiply-accumulate instructions executed at the start of the offline search, usually starting from 1. The current multiply-accumulate count refers to the multiply-accumulate count value being checked during the progressively increasing search process.

[0067] Starting with an initial number of multiplications and additions, the number of multiplications and additions is increased sequentially. At the current number of multiplications and additions, the first and second polynomial coefficient sets are solved in the first and second test intervals, respectively. Solving for the polynomial coefficient sets here refers to searching for the optimal coefficients through numerical optimization iterations, starting with the corresponding Taylor expansion coefficients or asymptotic expansion coefficients, under a fixed multiplication and addition constraint, and verifying whether the optimized fitting error meets the expected fitting accuracy.

[0068] If the fitting errors of the two test intervals under the current number of multiplications and additions both meet the expected fitting accuracy, and the current number of multiplications and additions does not exceed the upper limit of the hardware number of multiplications and additions, then the number of terms of the polynomial coefficient group is determined and fixed based on the current number of multiplications and additions.

[0069] It's important to note that the purpose of solving the polynomial coefficient set here differs from the purpose of solving and fixing the polynomial coefficient set when determining the preset segmentation threshold: In the term number determination stage, solving the polynomial coefficient set is only used to verify whether the polynomial under the current multiplication-accumulation degree constraint has the ability to achieve the expected fitting accuracy across the entire domain. The searched coefficients are discarded after the verification and do not participate in subsequent fixing. However, in the subsequent process of traversing candidate segmentation thresholds and finally determining the preset segmentation threshold, the first and second polynomial coefficient sets solved and stored in memory are the final coefficients obtained by re-optimizing for specific segmentation intervals under the condition that the number of terms is fixed. These will be used by the processor as fixed operands during online inference. The difference lies in that the former serves to verify the feasibility of the number of terms, while the latter serves to fix the final parameters.

[0070] The above technical solution determines a fixed first and second test interval based on the distribution of pre-activation values ​​corresponding to sample words and the saturation characteristics of the error function. This makes the item number search independent of the traversal of candidate segmentation thresholds, ensuring that the determined item number is applicable to all possible candidate segmentation thresholds. Starting from the initial multiply-accumulate count, the number of items is increased sequentially, and the polynomial coefficient set is solved in both test intervals to check the fitting error under the current multiply-accumulate count. This ensures that the final determined item number is the minimum multiply-accumulate count that simultaneously satisfies the expected fitting accuracy and does not exceed the hardware multiply-accumulate count limit. Thus, while ensuring fitting accuracy across the entire domain, the number of items in the polynomial coefficient set is compressed to the minimum necessary size within the hardware constraints. This avoids resource waste caused by excessive multiply-accumulate counts and prevents inadequate accuracy caused by insufficient multiply-accumulate counts, achieving a balance between accuracy and hardware efficiency.

[0071] Figure 3 This is a flowchart of another instruction data processing method in a processor according to an embodiment of the present disclosure; this embodiment is an optional solution proposed based on the above embodiments.

[0072] See Figure 3 The instruction data processing method in the processor provided in this embodiment includes: S301. Traverse the candidate segmentation thresholds and determine the growth range and saturation range of the error function based on the pre-activation value corresponding to the sample word and the current segmentation threshold.

[0073] S302. Take the logarithm of the complementary error function to construct a slowly varying function, and perform an asymptotic expansion of the slowly varying function to obtain the coefficients of all terms.

[0074] The complementary error function exhibits exponential decay and its values ​​concentrate in the decimal part within the saturation region, making it difficult to achieve high accuracy through direct polynomial fitting. A slowly varying function is the function obtained by taking the logarithm of the complementary error function. This transformation converts the exponential decay of the complementary error function into a more gradual form, allowing the polynomial to be fitted with higher accuracy. Asymptotic expansion refers to performing a series expansion on the asymptotic behavior of the slowly varying function as the independent variable approaches infinity to obtain the initial coefficients for polynomial approximation. Total degree coefficients refer to the complete set of polynomial coefficients, including constant terms and coefficients of all powers. Because slowly varying functions are neither odd nor even, they cannot be simplified to a form containing only odd or even degree terms; therefore, total degree coefficients are used for fitting.

[0075] S303. Using the total coefficients of the polynomials as the starting point for the search, generate multiple candidate polynomial coefficient sets. Optionally, a preset floating range is applied to the coefficients of each term, centered on the search starting point, and multiple candidate polynomial coefficient sets are generated within the floating range according to a preset step size.

[0076] S304. Traverse each candidate polynomial coefficient set, and use the current polynomial coefficient set as the operand of the multiply-accumulate operation instruction in the processor to perform multiply-accumulate operation on the points to be fitted in the saturation interval to obtain the fitted value of each point to be fitted with respect to the slowly varying function.

[0077] The points to be fitted refer to the sampling points obtained from the saturation interval, used to test the fitting accuracy of the current polynomial coefficient set. When traversing each candidate polynomial coefficient set, the current polynomial coefficient set is used as the operand of the multiply-accumulate instruction in the processor, and multiply-accumulate operations are performed on the points to be fitted in the saturation interval. The fitted values ​​of each point to be fitted with respect to the slowly varying function are obtained through the multiply-accumulate operations.

[0078] S305. For the fitted value of the slowly varying function, execute the exponential operation instruction and bit operation instruction in the processor in sequence to convert the fitted value of the slowly varying function into the fitted value of each point to be fitted with respect to the error function, and calculate the fitting error corresponding to the current polynomial coefficient set.

[0079] For the fitted values ​​of the slowly varying function, the exponential operation instructions and bit operation instructions in the processor are executed in sequence to convert the fitted values ​​of the complementary error function into fitted values ​​of each point to be fitted with respect to the error function.

[0080] S306. Based on the expected fitting accuracy and the fitting error corresponding to each candidate polynomial coefficient group, determine the first polynomial coefficient group and store it in the memory.

[0081] Calculate the fitting error corresponding to the current polynomial coefficient set, select the candidate polynomial coefficient set whose fitting error meets the expected fitting accuracy and has the smallest fitting error as the first polynomial coefficient set, and store it in the memory.

[0082] S307. Solve the second polynomial coefficient set in the growth interval using the error function as the fitting object and store it in the memory; wherein the number of terms in the polynomial coefficient set is predetermined based on the expected fitting accuracy and the upper limit of the number of hardware multiplication and addition operations.

[0083] S308. If the fitting errors corresponding to the first polynomial coefficient group and the second polynomial coefficient group both meet the expected fitting accuracy, then the current segmentation threshold is determined as the effective segmentation threshold.

[0084] S309. Based on the distribution of pre-activation values ​​corresponding to the sample lexical units and the hardware resource consumption generated by fitting the error function, determine the preset segmentation threshold from the effective segmentation threshold and store it in the memory.

[0085] This disclosed technical solution constructs a slowly varying function by taking the logarithm of the complementary error function, transforming the exponential decay in the saturation interval into a gradual change, enabling multiply-accumulate instructions to achieve high-precision fitting. A candidate polynomial coefficient set is generated using the coefficients of all terms obtained from asymptotic expansion as the search starting point, ensuring the search starting point closely matches the function shape of the saturation interval. After the candidate polynomial coefficient set is used as the operand for multiply-accumulate instructions to complete the fitting, it is converted into the fitted value of the error function via exponential and bitwise operation instructions. The conversion path relies solely on existing general-purpose instructions in the processor. A first polynomial coefficient set is selected based on the expected fitting accuracy and stored in memory, allowing the processor to directly read the first polynomial coefficient set during online inference to complete high-precision fitting of the saturation interval, balancing accuracy and hardware overhead.

[0086] In an optional embodiment, the step of using the current polynomial coefficient set as an operand of a multiply-accumulate instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the saturation interval to obtain the fitted value of each point to be fitted with respect to the slowly varying function includes: using the current polynomial coefficient set as an operand of a multiply-accumulate instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the saturation interval. t Perform the following operations: Calculate ;for i =1 to K Execute the following in sequence i The multiply-add operation instruction obtains the point to be fitted in the saturation interval. t Regarding the fitted value of the error function: in, The multiplier coefficient, The addend coefficient, K The number of times the multiplication-addition operation instruction is executed is determined by the number of terms in the polynomial coefficient set; u Points to be fitted t Regarding the fitted values ​​of the slowly varying function;u The function form is ; The complementary error function 。

[0087] Taking a polynomial coefficient system of order 13 as an example, the above scheme is explained as follows: At this point, the number of times the multiply-add instruction is executed... K =6, the saturation interval uses a full-degree polynomial, and the current polynomial coefficient set consists of multiplier coefficients. a i Additive coefficients b i Together they form the total set of coefficients, consisting of 12 coefficients, each corresponding to a different term. arrive The point t to be fitted is the scaling value obtained by upsampling the saturation interval. .

[0088] The processor first calculates the absolute value of the point to be fitted using absolute value instructions. Since the input in the saturation region is already non-negative, v This refers to the point to be fitted itself. Subsequently, the processor executes six multiply-accumulate operations sequentially using multiply-accumulate instructions: First multiply-add instruction: ; Second multiplication-addition instruction: ; The third multiply-add instruction: ; 4th multiply-add instruction: ; 5th multiply-add instruction: ; 6th multiply-accumulate instruction: ; Of the six multiply-add instructions mentioned above, arrive The coefficients are full-order polynomials with no odd or even terms, obtained through asymptotic expansion and numerical optimization of the slowly varying function in the offline stage. After the above 6 multiply-accumulate instructions are completed, the intermediate accumulated result r6 is obtained. Then, v is negativeed by a negation instruction to obtain -v, and then u=r6×(-v)+(-v) is executed by the 7th multiply-accumulate instruction to obtain the fitted value of the slowly varying function. Afterwards, the processor calculates 2 using exponential operation instructions. u The approximate value of the complementary error function is recovered, and then the result is obtained by subtraction. uThe process extracts the sign bit from the original pre-activated value using a bitwise AND instruction, and restores the sign bit to the result using a bitwise OR instruction, ultimately obtaining the signed error function fitting value. The entire process requires 7 multiplication-addition instructions, 1 absolute value instruction, 1 negation instruction, 1 exponentiation instruction, 1 subtraction instruction, and 2 bit manipulation instructions, all of which are completed on the processor's existing general-purpose execution unit without the need for dedicated hardware.

[0089] The above technical solution uses the current polynomial coefficient set composed of multiplier and adder coefficients as the operands of the multiplication-addition operation instructions. It completes the fitting of the slowly varying function by using a fixed sequence of multiplication-addition instructions in conjunction with the final stage negation operation. Then, it is converted into the error function fitting value by the exponential operation instruction. The complex function calculation in the saturation interval is mapped to the processor's existing general instructions. High-precision fitting is achieved by using the slowly varying function transformation. The instruction sequence is fixed and there is no additional hardware overhead.

[0090] Figure 4 This is a flowchart of another instruction data processing method in a processor according to an embodiment of the present disclosure; this embodiment is an optional solution proposed based on the above embodiments.

[0091] See Figure 4 The instruction data processing method in the processor provided in this embodiment includes: S401. Traverse the candidate segmentation thresholds and determine the growth range and saturation range of the error function based on the pre-activation value corresponding to the sample word and the current segmentation threshold.

[0092] S402. Solve the first polynomial coefficient set in the saturation interval using the complementary error function as the fitting object and store it in the memory.

[0093] S403. Perform a Taylor expansion on the error function at the origin to obtain the coefficients of the odd-order terms.

[0094] Taylor expansion at the origin refers to expanding the error function into an infinite series where the independent variable is zero, and taking the first few terms to obtain the coefficients of the polynomial approximation. Since the error function is an odd function, its Taylor expansion contains only odd-power terms, excluding even-power terms and constant terms. Therefore, the odd-power coefficients are the set of coefficients containing only odd-power terms. Constructing a polynomial using odd-power coefficients reduces the number of coefficients by about half compared to a polynomial with all powers, allowing for coverage of higher polynomial orders with the same number of multiplication and addition operations.

[0095] S404. Using the odd-degree term coefficients as the starting point for the search, generate multiple candidate polynomial coefficient sets. Centered on the search starting point, a preset floating range is applied to it, and multiple candidate polynomial coefficient sets are generated within the floating range according to a preset step size.

[0096] S405. Traverse each candidate polynomial coefficient set, use the current polynomial coefficient set as the operand of the multiply-accumulate operation instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the growth interval, obtain the fitting value of each point to be fitted with respect to the error function, and calculate the fitting error corresponding to the current polynomial coefficient set.

[0097] When traversing each candidate polynomial coefficient set, the current polynomial coefficient set is used as the operand of a multiply-accumulate instruction in the processor, and multiply-accumulate operations are performed on the points to be fitted within the growth interval. The fitted values ​​of each point to be fitted with respect to the error function are obtained through the multiply-accumulate operations, and the fitting error corresponding to the current polynomial coefficient set is calculated.

[0098] S406. Based on the expected fitting accuracy and the fitting error corresponding to each candidate polynomial coefficient group, determine the second polynomial coefficient group and store it in the memory.

[0099] Optionally, a set of candidate polynomial coefficients that meets the expected fitting accuracy and has the smallest fitting error is selected as the second polynomial coefficient set and stored in memory. The number of terms in the polynomial coefficient set is predetermined based on the expected fitting accuracy and the upper limit of the hardware multiplication and addition operations.

[0100] S407. If the fitting errors corresponding to the first polynomial coefficient group and the second polynomial coefficient group both meet the expected fitting accuracy, then the current segmentation threshold is determined as the effective segmentation threshold.

[0101] S408. Based on the distribution of pre-activation values ​​corresponding to the sample lexical units and the hardware resource consumption generated by fitting the error function, determine the preset segmentation threshold from the effective segmentation threshold and store it in the memory.

[0102] This disclosed technical solution utilizes the characteristic that the error function is an odd function. It uses the odd-degree coefficients obtained from the Taylor expansion at the origin as the starting point to generate candidate polynomial coefficient sets. The number of coefficients is halved compared to full-degree polynomials, covering higher orders with the same number of multiply-accumulate instructions. Each candidate polynomial coefficient set is used as an operand in a multiply-accumulate instruction to perform multiply-accumulate operations on the point to be fitted, obtaining the fitted value of the error function. The fitting process relies solely on the processor's existing multiply-accumulate instructions. A second polynomial coefficient set is selected based on the expected fitting accuracy and stored in memory. This allows the processor to directly read this coefficient set during online inference to complete high-precision fitting of the growth interval, balancing accuracy and instruction efficiency.

[0103] In an optional embodiment, the step of using the current polynomial coefficient set as an operand of a multiply-accumulate instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the growth interval to obtain the fitted value of each point to be fitted with respect to the error function and to calculate the fitting error corresponding to the current polynomial coefficient set includes: using the current polynomial coefficient set as an operand of a multiply-accumulate instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the growth interval. t Perform the following operations: Calculate ;for to K Execute the following in sequence i The multiply-add operation command yields the point to be fitted. t Regarding the fitted value of the error function: in, The multiplier coefficient, The addend coefficient, K The number of times the multiplication-addition operation instruction is executed is determined by the number of terms in the polynomial coefficient set; r Points to be fitted t Regarding the error function erf( t Fitted values 。

[0104] Taking a polynomial coefficient system of order 13 as an example, the above scheme is explained as follows: At this point, the number of times the multiply-add instruction is executed... K =6. Unlike the saturation interval which uses a full-degree polynomial, the growth interval utilizes the characteristic that the error function is an odd function, employing an odd-degree polynomial with multiplier coefficients. a 1 to a 6 respectively correspond to , , , , and Additive coefficient b 1 to b 6 respectively correspond to , , , , , . Points to be fitted t The scaling value obtained by upsampling the saturation interval .

[0105] The processor first calculates the square of the point to be fitted using multiplication instructions. Then, using the current polynomial coefficient set as the operand of the multiply-accumulate instruction, the multiply-accumulate operation is performed six times in sequence: First multiply-add instruction: ; Second multiplication-addition instruction: ; The third multiply-add instruction: ; 4th multiply-add instruction: ; 5th multiply-add instruction: ; 6th multiply-accumulate instruction: ; In the above 6 multiplication-addition instructions, the coefficients with odd numbers... , , , , and As multiplier coefficients, they correspond to odd-degree term constraints; coefficients with even-numbered indices... , , , , , These are the addend coefficients. The coefficients of this odd-degree polynomial are obtained through Taylor expansion and numerical optimization of the error function at the origin during the offline phase. After six multiply-add operations, the intermediate accumulated result is obtained. r 6. Then, the 7th multiply-accumulate instruction is executed. The point to be fitted is obtained. t Regarding the error function erf( t The fitted value of ). In this final-level operation, r 6 is used as the multiplier coefficient. t Simultaneously serving as both multiplicand and addend, it embodies the principle of factoring common factors in odd-degree polynomials. t Added later t This process restores the complete approximation of the original structure. The entire process requires a total of 7 multiply-accumulate instructions and 1 multiply instruction, all of which are performed on the processor's existing general-purpose execution units without the need for dedicated hardware.

[0106] The above technical solution uses the current polynomial coefficient set composed of multiplier and adder coefficients as the operands of the multiplication-addition operation instructions. By combining a fixed number of multiplication-addition instruction sequences with the final-level multiplication-addition supplementary operation, the error function fitting value is directly obtained. The function calculation in the growth interval is mapped to the processor's existing multiplication and multiplication-addition operation instructions. By utilizing the odd function characteristics of the error function, only odd-degree coefficients are used, achieving high-precision fitting with half the number of coefficients. The instruction sequence is fixed and there is no additional hardware overhead.

[0107] Figure 5This is a schematic diagram of the structure of an instruction-data processing device in a processor according to an embodiment of the present disclosure. This embodiment is applicable to implementing high-precision calculation of the GELU activation function on AI chips lacking dedicated error function hardware units. The device can be implemented using software and / or hardware, and can implement the instruction-data processing method in a processor described in any embodiment of the present disclosure.

[0108] like Figure 5 As shown, the instruction and data processing unit 500 in the processor includes: The data reading module 501 is used to read the pre-activation value of the linear transformation output for the current word from the register, and to read the preset segmentation threshold from the memory; wherein, the preset segmentation threshold is determined based on the distribution of the pre-activation values ​​corresponding to the sample word, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function. The feature determination module 502 is used to determine the rate of change feature of the error function based on the pre-activation value and the preset segmentation threshold; wherein the rate of change feature is used to characterize whether the error function is in a saturated state or a growing state; The function fitting module 503 is used to use two sets of polynomial coefficients in the memory as operands of the multiply-accumulate operation instruction in the processor to fit the error function in the saturation state or the growth state respectively, and obtain the fitted value of the error function. The result determination module 504 is used to generate the activation features of the current word based on the fitted value of the error function.

[0109] This disclosed technical solution divides the pre-activated value into two intervals—the growth state and the saturation state—corresponding to the error function by setting a preset segmentation threshold. This allows the processor to dynamically select one of the two polynomial coefficient sets in memory as the operand for the multiply-accumulate instruction based on the rate of change characteristics. The preset segmentation threshold is determined offline based on the distribution of pre-activated values ​​corresponding to sample words, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function. It comprehensively considers the distribution density of pre-activated values ​​and hardware resource consumption, providing a reliable boundary basis for selecting the appropriate polynomial coefficient set during online inference. This ensures that each interval can be fitted with the most suitable polynomial coefficient set, thereby achieving high-precision fitting of the error function across the entire domain, ensuring that the fitted value of the error function meets the expected fitting accuracy. The two polynomial coefficient sets are fixed in memory, and the fitting process only relies on the existing multiply-accumulate unit and other general instruction execution units in the processor. There is no need to configure a dedicated error function hardware unit, and it does not occupy on-chip static memory to build a lookup table. It balances inference accuracy and chip area efficiency with only a constant level increase in storage overhead.

[0110] Optionally, the device is further configured to determine the preset segmentation threshold; correspondingly, the device further includes: an interval division module, configured to traverse the candidate segmentation thresholds and determine the growth interval and saturation interval of the error function based on the pre-activation value corresponding to the sample word and the current segmentation threshold; a coefficient solving module, configured to solve the first polynomial coefficient set in the saturation interval using the complementary error function as the fitting object and store it in the memory, and solve the second polynomial coefficient set in the growth interval using the error function as the fitting object and store it in the memory; wherein, the number of terms in the polynomial coefficient set is predetermined based on the expected fitting accuracy and the upper limit of the number of hardware multiplication and addition; a valid judgment module, configured to determine the current segmentation threshold as a valid segmentation threshold if the fitting errors corresponding to the first polynomial coefficient set and the second polynomial coefficient set both satisfy the expected fitting accuracy; and a threshold storage module, configured to determine the preset segmentation threshold from the valid segmentation thresholds based on the distribution of the pre-activation value corresponding to the sample word and the hardware resource consumption generated by fitting the error function and store it in the memory.

[0111] Optionally, the interval division module includes: a first division submodule, used to determine an effective domain for the pre-activation value corresponding to the sample word, and using the current segmentation threshold as the boundary, determine the portion of the effective domain whose absolute value is greater than or equal to the current segmentation threshold as the saturation interval; and a second division submodule, used to use the current segmentation threshold as the boundary, determine the portion of the effective domain whose absolute value is less than the current segmentation threshold as the growth interval.

[0112] Optionally, the coefficient solving module includes: an asymptotic expansion submodule, used to construct a slowly varying function by taking the logarithm of the complementary error function, and to perform an asymptotic expansion of the slowly varying function to obtain full-degree term coefficients; a first candidate generation submodule, used to generate multiple candidate polynomial coefficient sets using the full-degree term coefficients as the search starting point; a first multiply-accumulate operation submodule, used to traverse each candidate polynomial coefficient set, and to perform multiply-accumulate operations on the points to be fitted in the saturation interval using the current polynomial coefficient set as the operand of the multiply-accumulate operation instruction in the processor, to obtain the fitted value of each point to be fitted with respect to the slowly varying function; an error calculation submodule, used to sequentially execute exponentiation operation instructions and bit operation instructions in the processor on the fitted value of the slowly varying function to convert the fitted value of the slowly varying function into the fitted value of each point to be fitted with respect to the error function, and to calculate the fitting error corresponding to the current polynomial coefficient set; and a first coefficient storage submodule, used to determine the first polynomial coefficient set based on the expected fitting accuracy and the fitting error corresponding to each candidate polynomial coefficient set and store it in the memory.

[0113] Optionally, the coefficient solving module includes: a Taylor expansion submodule, used to perform a Taylor expansion on the error function at the origin to obtain odd-degree coefficients; a second candidate generation submodule, used to use the odd-degree coefficients as the search starting point to generate multiple candidate polynomial coefficient sets; a second multiply-add operation submodule, used to traverse each candidate polynomial coefficient set, use the current polynomial coefficient set as the operand of the multiply-add operation instruction in the processor to perform multiply-add operations on the points to be fitted in the growth interval, obtain the fitting value of each point to be fitted with respect to the error function, and calculate the fitting error corresponding to the current polynomial coefficient set; and a second coefficient storage submodule, used to determine the second polynomial coefficient set based on the expected fitting accuracy and the fitting error corresponding to each candidate polynomial coefficient set and store it in the memory.

[0114] Optionally, the first multiply-accumulate submodule is specifically used as the operand of the multiply-accumulate instruction in the processor, using the current polynomial coefficient set as the operand, to perform the following operation on the point t to be fitted in the saturation interval: calculate ;for to The i-th multiply-accumulate operation instruction is executed sequentially to obtain the fitting point in the saturation interval. t Regarding the fitted value of the error function: in, The multiplier coefficient, The addend coefficient, K The number of times the multiplication-addition operation instruction is executed is determined by the number of terms in the polynomial coefficient set; u Points to be fitted t Regarding the fitted values ​​of the slowly varying function; u The function form is ; The complementary error function 。

[0115] Optionally, the second multiply-accumulate submodule is specifically used to use the current polynomial coefficient set as the operand of the multiply-accumulate instruction in the processor to fit the point in the growth interval. t Perform the following operations: Calculate ;for to Execute the following in sequence i The multiply-add operation command yields the point to be fitted. t Regarding the fitted value of the error function: in, The multiplier coefficient, The addend coefficient, KThe number of times the multiplication-addition operation instruction is executed is determined by the number of terms in the polynomial coefficient set; r Points to be fitted t Regarding the error function erf( t Fitted values 。

[0116] Optionally, the threshold storage module includes: a probability determination submodule, used to determine, for each effective segmentation threshold, a first probability that the pre-activation value corresponding to the sample word falls into the saturation interval and a second probability that it falls into the growth interval, based on the numerical distribution of the pre-activation value corresponding to the sample word; a consumption determination submodule, used to determine, based on the total number of various instructions of each instruction type corresponding to the saturation interval and the growth interval, the first resource consumption generated by executing instructions in the saturation interval and the second resource consumption generated by executing instructions in the growth interval; a weighted processing submodule, used to perform weighted summation of the first resource consumption and the second resource consumption using the first probability and the second probability as weights, respectively, to obtain the total resource consumption of the effective segmentation threshold; and a threshold storage submodule, used to select the effective segmentation threshold with the smallest total resource consumption as the preset segmentation threshold and store it in the memory.

[0117] Optionally, the number of terms in the polynomial coefficient set is determined as follows: based on the distribution of pre-activation values ​​corresponding to the sample lexical units and the saturation characteristics of the error function, a first test interval and a second test interval are determined; starting from the initial multiplication-accumulation count, the count is increased, and the first polynomial coefficient set and the second polynomial coefficient set are solved in the first test range and the second test interval respectively to check the fitting error under the current multiplication-accumulation count; if the fitting error under the current multiplication-accumulation count meets the expected fitting accuracy, and the current multiplication-accumulation count does not exceed the upper limit of the hardware multiplication-accumulation count, then the number of terms in the polynomial coefficient set is determined based on the current multiplication-accumulation count and fixed.

[0118] Optionally, the function fitting module 503 includes: a gradually varying function fitting submodule, used to process the pre-activated value using a first set of polynomial coefficients pre-stored in memory as the operand of a multiply-accumulate instruction in the processor to obtain a fitted value of the gradually varying function if the error function is in the saturation state; the gradually varying function is obtained by taking the logarithm of the complementary error function; a fitted value conversion submodule, used to sequentially execute an exponential operation instruction and a bit operation instruction in the processor to convert the fitted value of the gradually varying function into a fitted value of each point to be fitted with respect to the error function; and an error function fitting submodule, used to process the pre-activated value using a second set of polynomial coefficients pre-stored in memory as the operand of a multiply-accumulate instruction in the processor to obtain a fitted value of the error function if the error function is in the growth state.

[0119] Optionally, the current word and the sample word are input units obtained by the transformer model from word segmentation of the input text. The current word is output as the pre-activation value after linear transformation in the transformer model, and the sample word is used to collect the distribution of pre-activation values ​​through forward propagation of the transformer model.

[0120] In the technical solutions disclosed herein, the collection, storage, use, processing, transmission, provision, and disclosure of any type of information, such as user personal information, comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0121] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0122] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0123] like Figure 6As shown, device 600 includes a computing unit 601, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 602 or a computer program loaded into random access memory (RAM) 603 from storage unit 608. RAM 603 may also store various programs and data required for the operation of device 600. The computing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.

[0124] Multiple components in device 600 are connected to I / O interface 605, including: input unit 606, such as keyboard, mouse, etc.; output unit 607, such as various types of monitors, speakers, etc.; storage unit 608, such as disk, optical disk, etc.; and communication unit 609, such as network card, modem, wireless transceiver, etc. Communication unit 609 allows device 600 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0125] The computing unit 601 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as the processor instruction data processing method. For example, in some embodiments, the processor instruction data processing method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the processor instruction data processing method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the processor instruction data processing method by any other suitable means (e.g., by means of firmware).

[0126] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0127] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0128] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0129] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0130] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0131] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is established by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service ecosystem that addresses the management difficulties and weak business scalability inherent in traditional physical hosting and VPS services. Servers can also be servers for distributed systems or servers integrated with blockchain technology.

[0132] Artificial intelligence (AI) is the study of enabling computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, and big data processing. AI software technologies mainly include computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graph technologies.

[0133] Cloud computing refers to a technology system that enables access to a shared pool of physical or virtual resources via a network. These resources can include servers, operating systems, networks, software, applications, and storage devices, and can be deployed and managed on demand and in a self-service manner. Cloud computing technology can provide efficient and powerful data processing capabilities for applications such as artificial intelligence and blockchain, as well as for model training.

[0134] It should be understood that the various forms of processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution provided in this disclosure can be achieved, and this is not limited herein.

[0135] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A method for instruction data processing in a processor, the method comprising: The pre-activation value of the linear transformation output for the current word is read from the register, and the preset segmentation threshold is read from the memory; wherein, the preset segmentation threshold is determined based on the distribution of the pre-activation values ​​corresponding to the sample word, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function; Based on the pre-activation value and the preset segmentation threshold, the rate of change characteristic of the error function is determined; wherein, the rate of change characteristic is used to characterize whether the error function is in a saturated state or a growing state; Using two sets of polynomial coefficients in memory as operands of multiply-accumulate instructions in the processor, the error function in the saturated state or the growing state is fitted to obtain the fitted value of the error function. Based on the fitted value of the error function, the activation features of the current word are generated.

2. The method according to claim 1, wherein, The preset segmentation threshold is determined in the following manner: The candidate segmentation thresholds are iterated through, and the growth range and saturation range of the error function are determined based on the pre-activation value corresponding to the sample word and the current segmentation threshold. In the saturation interval, a first polynomial coefficient set is solved using the complementary error function as the fitting object and stored in the memory; in the growth interval, a second polynomial coefficient set is solved using the error function as the fitting object and stored in the memory; wherein, the number of terms in the polynomial coefficient set is predetermined based on the expected fitting accuracy and the upper limit of the number of hardware multiply-accumulate operations; If the fitting errors corresponding to the first polynomial coefficient set and the second polynomial coefficient set both meet the expected fitting accuracy, then the current segmentation threshold is determined as the effective segmentation threshold. Based on the distribution of pre-activation values ​​corresponding to the sample lexical units and the hardware resource consumption generated by fitting the error function, the preset segmentation threshold is determined from the effective segmentation threshold and stored in the memory.

3. The method according to claim 2, wherein, The step of determining the growth range and saturation range of the error function based on the pre-activation value corresponding to the sample word and the current segmentation threshold includes: A valid domain is determined for the pre-activation value corresponding to the sample word, and the portion of the valid domain whose absolute value is greater than or equal to the current segmentation threshold is determined as the saturation interval, using the current segmentation threshold as the boundary. Using the current segmentation threshold as the boundary, the portion of the effective domain whose absolute value is less than the current segmentation threshold is determined as the growth interval.

4. The method according to claim 2, wherein, The step of solving the first polynomial coefficient set in the saturation interval using the complementary error function as the fitting object and storing it in the memory includes: The logarithm of the complementary error function is used to construct a slowly varying function, and the coefficients of all terms are obtained by asymptotic expansion of the slowly varying function. Using the total coefficients as the starting point of the search, multiple candidate polynomial coefficient sets are generated. Traverse each candidate polynomial coefficient set, and use the current polynomial coefficient set as the operand of the multiply-accumulate operation instruction in the processor to perform multiply-accumulate operation on the points to be fitted in the saturation interval to obtain the fitted value of each point to be fitted with respect to the slowly varying function; For the fitted value of the slowly varying function, the exponential operation instruction and bit operation instruction in the processor are executed in sequence to convert the fitted value of the slowly varying function into the fitted value of each point to be fitted with respect to the error function, and the fitting error corresponding to the current polynomial coefficient set is calculated. The first polynomial coefficient set is determined based on the expected fitting accuracy and the fitting error corresponding to each candidate polynomial coefficient set, and then stored in the memory.

5. The method according to claim 2, wherein, The step of solving the second polynomial coefficient set in the growth interval using the error function as the fitting object and storing it in the memory includes: Taylor expansion of the error function at the origin yields the coefficients of the odd-order terms; Using the odd-degree term coefficients as the starting point for the search, multiple candidate polynomial coefficient sets are generated. Traverse each candidate polynomial coefficient set, use the current polynomial coefficient set as the operand of the multiply-accumulate operation instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the growth interval, obtain the fitting value of each point to be fitted with respect to the error function, and calculate the fitting error corresponding to the current polynomial coefficient set. The second polynomial coefficient set is determined based on the expected fitting accuracy and the fitting error corresponding to each candidate polynomial coefficient set, and then stored in the memory.

6. The method according to claim 4, wherein, The step of using the current polynomial coefficient set as an operand of a multiply-accumulate instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the saturation interval to obtain the fitted value of each point to be fitted with respect to the slowly varying function includes: The current set of polynomial coefficients serves as the operand for multiply-accumulate instructions in the processor, for the points to be fitted in the saturation interval. t Perform the following operations: calculate ; for i =1 to K Execute the following in sequence i The multiply-add operation instruction obtains the point to be fitted in the saturation interval. t Regarding the fitted value of the error function: in, The multiplier coefficient, The addend coefficient, K The number of times the multiplication-addition operation instruction is executed is determined by the number of terms in the polynomial coefficient set; u Points to be fitted t Regarding the fitted values ​​of the slowly varying function; u The function form is ; The complementary error function 。 7. The method according to claim 5, wherein, The step of using the current polynomial coefficient set as an operand of a multiply-accumulate instruction in the processor to perform multiply-accumulate operations on the points to be fitted in the growth interval, obtaining the fitted value of each point to be fitted with respect to the error function, and calculating the fitting error corresponding to the current polynomial coefficient set includes: The current set of polynomial coefficients is used as an operand of the multiply-accumulate instruction in the processor to fit the point in the growth interval. t Perform the following operations: calculate ; for to K Execute the following in sequence i The multiply-add operation command yields the point to be fitted. t Regarding the fitted value of the error function: in, The multiplier coefficient, The addend coefficient, K The number of times the multiplication-addition operation instruction is executed is determined by the number of terms in the polynomial coefficient set; r Points to be fitted t Regarding the error function erf( t Fitted values 。 8. The method according to claim 2, wherein, The step of determining the preset segmentation threshold from the effective segmentation threshold and storing it in the memory based on the pre-activation value distribution corresponding to the sample lexical units and the hardware resource consumption generated by fitting the error function includes: For each effective segmentation threshold, based on the numerical distribution of the pre-activation values ​​corresponding to the sample word, the first probability that the pre-activation value corresponding to the sample word falls into the saturation interval and the second probability that it falls into the growth interval are determined. Based on the total number of instructions of each type corresponding to the saturation interval and the growth interval, as well as the execution cycle of each type of instruction, the first resource consumption generated by executing instructions in the saturation interval and the second resource consumption generated by executing instructions in the growth interval are determined respectively. Using the first probability and the second probability as weights, the first resource consumption and the second resource consumption are weighted and summed respectively to obtain the total resource consumption of the effective segmentation threshold; Select the effective segmentation threshold with the minimum total resource consumption as the preset segmentation threshold and store it in the memory.

9. The method according to claim 2, wherein, The number of terms in the polynomial coefficient set is determined as follows: Based on the distribution of pre-activation values ​​corresponding to the sample words and the saturation characteristics of the error function, the first test interval and the second test interval are determined. Starting from the initial number of multiplications and additions, the number of multiplications and additions is increased. Within the first test range and the second test interval, the first polynomial coefficient set and the second polynomial coefficient set are solved to check the fitting error under the current number of multiplications and additions. If the fitting error at the current number of multiplications and additions meets the expected fitting accuracy, and the current number of multiplications and additions does not exceed the upper limit of the hardware number of multiplications and additions, then the number of terms in the polynomial coefficient set is determined and fixed based on the current number of multiplications and additions.

10. The method according to claim 1, wherein, Using two sets of polynomial coefficients in memory as operands for multiply-accumulate instructions in the processor, the error function in either the saturated state or the increasing state is fitted to obtain the fitted value of the error function, including: If the error function is in the saturation state, the pre-activated value is processed using the first set of polynomial coefficients pre-stored in the memory as the operand of the multiply-accumulate operation instruction in the processor to obtain the fitted value of the slowly varying function; the slowly varying function is obtained by taking the logarithm of the complementary error function; For the fitted value of the slowly varying function, the exponential operation instruction and bit operation instruction in the processor are executed in sequence to convert the fitted value of the slowly varying function into the fitted value of each point to be fitted with respect to the error function. If the error function is in the growth state, the pre-activated value is processed using the second polynomial coefficient set pre-stored in the memory as the operand of the multiply-accumulate operation instruction in the processor to obtain the fitted value of the error function.

11. The method according to any one of claims 1 to 10, wherein, The current word and the sample word are input units obtained by the transformer model from word segmentation of the input text. The current word is output as the pre-activation value after linear transformation in the transformer model. The sample word is used to collect the distribution of pre-activation values ​​through forward propagation of the transformer model.

12. An instruction data processing apparatus in a processor, the apparatus comprising: The data reading module is used to read the pre-activation value of the linear transformation output for the current word from the register, and to read the preset segmentation threshold from the memory; wherein, the preset segmentation threshold is determined based on the distribution of the pre-activation values ​​corresponding to the sample word, the expected fitting accuracy of the error function, and the hardware resource consumption generated by fitting the error function; The feature determination module is used to determine the rate of change feature of the error function based on the pre-activation value and the preset segmentation threshold; wherein the rate of change feature is used to characterize whether the error function is in a saturated state or a growing state; The function fitting module is used to use two sets of polynomial coefficients in memory as operands of multiply-accumulate instructions in the processor to fit the error function in the saturation state or the growth state respectively, and obtain the fitted value of the error function. The result determination module is used to generate the activation features of the current word based on the fitted value of the error function.

13. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the instruction data processing method of the processor according to any one of claims 1-11.

14. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to execute the instruction data processing method in the processor according to any one of claims 1-11.

15. A computer program product comprising a computer program that, when executed by a processor, implements the instruction-data processing method in a processor according to any one of claims 1-11.