A method and apparatus for inference of large language models including nonlinear operators

By decomposing the nonlinear operators of a large language model into multiply-accumulate data streams adapted to the PE computing array, and combining Chebyshev approximation and Horner rules, the problem of low efficiency in nonlinear operator processing of edge-side accelerators is solved, achieving efficient reuse of hardware resources and reduction of inference latency.

CN123158281APending Publication Date: 2026-11-24INST OF COMPUTING TECH CHINESE ACAD OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611107760.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-24
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing edge-side large language model accelerators are inefficient when processing nonlinear operators and cannot support diverse nonlinear operations under the same hardware and control framework, resulting in low hardware resource utilization and high inference latency.

Method used

The nonlinear operators in the large language model are decomposed into affine primitives, reduction primitives and pointwise primitives, and transformed into a multiply-accumulate data stream form adapted to the PE computing array. Through Chebyshev approximation and Horner rules, it is uniformly transformed into a standardized multiply-accumulate data stream, which is then executed with a configurable reduction network and a dual PE mantissa splitting engine.

Benefits of technology

It achieves efficient and unified execution of nonlinear operators, reduces hardware resource fragmentation and power consumption, improves hardware resource reuse and inference throughput, and shortens end-to-end inference latency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123158281A_ABST
    Figure CN123158281A_ABST
Patent Text Reader

Abstract

The application provides a reasoning method and device for a large language model containing a nonlinear operator, which are used for completing large language model reasoning by using a computing device containing a PE computing array and a configurable reduction network, and the method comprises the following steps: S1, obtaining a computation graph of a large language model to be reasoned, wherein the computation graph comprises linear operators and nonlinear operators; S2, decomposing each nonlinear operator in the computation graph into a directed acyclic graph composed of affine primitives, reduction primitives and pointwise primitives; S3, converting each pointwise primitive in each directed acyclic graph into a multiply-accumulate data stream form suitable for a PE computing array, wherein the pointwise primitive contains exponential operation, division operation, inverse square root operation, trigonometric function operation and high-order polynomial operation; and S4, executing computation according to the linear operators and the directed acyclic graph obtained by converting the pointwise primitive into the multiply-accumulate data stream form to complete large language model reasoning by using the computing device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer architecture, more specifically to the field of accelerating reasoning for large language models, and more specifically to a reasoning method and apparatus for large language models containing nonlinear operators. Background Technology

[0002] With the widespread deployment of Large Language Models (LLMs) in intelligent question answering, code generation, mathematical reasoning, edge intelligence, and privacy-sensitive applications, migrating LLMs from cloud servers to edge devices has become a significant trend. However, existing edge LLM accelerators are typically optimized around linear operators such as General Matrix Multiplication (GEMM) or General Matrix-Vector Multiplication (GEMV), concentrating computational resources in arrays of Processing Elements (PEs) or Multiply-Accumulate (MAC) arrays. While this architecture can adequately support matrix computations in linear layers, attention projection layers, and feedforward networks, it lacks sufficient support for the numerous nonlinear operators present in LLMs.

[0003] Nonlinear operators in LLMs include, but are not limited to, Softmax, LayerNorm, RMSNorm, GeLU, SiLU, and Rotary Position Embedding (RoPE). These operators internally encompass various computational modes such as exponentiation, division, reciprocal square root, sine, cosine, summation, maximization, mean, and variance. Although these nonlinear operators typically account for a smaller percentage of theoretical floating-point operations than matrix operators, they reside on the critical path of model inference and appear frequently in different layers and modules of the model. Inefficient execution of nonlinear operators can significantly amplify end-to-end inference latency.

[0004] There are two main types of existing nonlinear operator execution methods. The first type offloads the nonlinear operator to the Central Processing Unit (CPU) or other general-purpose control cores for execution. While simple to implement, this method requires frequent data movement between the accelerator, on-chip memory, off-chip memory, and the CPU, introducing synchronization and scheduling overhead, which can easily disrupt on-chip data residency and data flow execution during the main computation process. The second type involves setting up Special Function Units (SFUs), Vector Processing Units (VPUs), or other dedicated components within the accelerator to perform operations such as exponentiation, division, and reciprocal square root. This method avoids some CPU offloading overhead, but is limited by edge chip area and power consumption budgets, resulting in a limited number of dedicated components and throughput. Furthermore, it is typically customized for one or a few types of nonlinear functions, making it difficult to cover the ever-expanding set of nonlinear operators in LLMs.

[0005] In summary, existing hardware acceleration solutions for nonlinear operators in large language model inference systems typically optimize for single operators or functions. While these solutions can improve the performance of specific operators, they lack a unified abstraction across operators and cannot support diverse nonlinear operations in LLM within a single hardware and control framework. As model structures evolve, the types and combinations of nonlinear operators also change, making it difficult for dedicated designs for single operators to maintain good versatility and scalability. Therefore, there is an urgent need for a nonlinear operator dataflow primitive abstraction method and device for LLM inference that can establish a unified dataflow abstraction representation for diverse nonlinear operators, transform nonlinear functions that are difficult to directly map to computational arrays into computationally array-friendly dataflow forms, and achieve high-throughput support for various nonlinear computations within a unified execution framework through lightweight hardware extensions.

[0006] It should be noted that the background information presented here is only for illustrating relevant information about the present invention to aid in understanding the technical solution of the present invention, and does not imply that the relevant information is necessarily prior art. The relevant information was submitted and disclosed together with the present invention, and should not be considered prior art unless there is evidence that the relevant information was disclosed before the filing date of the present invention. Summary of the Invention

[0007] Therefore, the purpose of this invention is to overcome the shortcomings of the prior art and provide a reasoning method and apparatus for large language models containing nonlinear operators.

[0008] The objective of this invention is achieved through the following technical solution:

[0009] According to a first aspect of the present invention, a reasoning method for a large language model containing nonlinear operators is provided, for performing large language model reasoning using a computing device including a PE computation array and a reduction and summation tree, the method comprising: S1, obtaining a computation graph of the large language model to be reasoned, the computation graph including linear operators and nonlinear operators; S2, decomposing each nonlinear operator in the computation graph into a directed acyclic graph composed of affine primitives, reduction primitives and pointwise primitives; S3, converting each pointwise primitive in each directed acyclic graph into a multiply-accumulate data stream form adapted to the PE computation array, wherein the pointwise primitives include exponential operations, division operations, reciprocal square root operations, trigonometric function operations and higher-order polynomial operations; S4, using a computing device to perform computation according to the linear operators and the directed acyclic graph after converting the pointwise primitives into a multiply-accumulate data stream form to complete the large language model reasoning.

[0010] This solution can achieve at least the following beneficial technical effects:

[0011] This solution decomposes all nonlinear operators of the large language model into three types of standardized primitives and uniformly converts them into multiply-accumulate data streams adapted to the PE computing array for execution. There is no need to configure additional SFU dedicated function units. Linear operators and nonlinear operators can reuse the same set of PE computing array hardware, which improves the defects of traditional accelerator hardware fragmentation and idle waste of dedicated computing units, improves hardware resource reuse rate, reduces chip area and power consumption, and avoids scheduling and migration delays caused by cross-device data interaction, shortening the end-to-end inference time of the model.

[0012] Optionally, in S3, the exponentiation operation is converted into a multiply-accumulate data stream format as follows: the exponentiation operation is converted into a power operation with base 2; the exponent of the power operation is split into an integer and a decimal sum, thus converting the power operation into... ,in, This represents the scaling factor for exponential operations. Indicates the nonlinear part, and These represent the integer and decimal results obtained by splitting the exponent in the exponentiation operation, respectively. The range of values ​​for the decimal is 1. The nonlinear part is fitted into a low-order polynomial using the Chebyshev approximation method; the product of the low-order polynomial and the scaling factor is transformed based on Horner's rule to obtain the multiply-accumulate data stream form of exponential operation.

[0013] This solution can achieve at least the following beneficial technical effects:

[0014] This scheme achieves the narrowing of the input range for exponential operations by base conversion and exponential integer-decimal splitting. It only requires Chebyshev low-order polynomial fitting for nonlinear terms in the narrow interval [0,1), reducing the polynomial order and Horner iteration computation. The scaling factor is implemented by shift operation, and the complete exponential operation can be converted into a standard multiply-accumulate data stream. No dedicated hardware for exponential operations is required, and it is compatible with PE computing array pipeline execution, reducing the latency of exponential nonlinear operations.

[0015] Optionally, in S3, the division operation is converted into a multiply-accumulate data stream format as follows: the divisor of the division operation is converted into a floating-point number, and the division operation is converted into... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is The nonlinear term is fitted to a low-order polynomial using the Chebyshev approximation method; the product of the low-order polynomial and the scaling factor is transformed based on Horner's rule to obtain the multiply-accumulate data stream form of the division operation.

[0016] This solution can achieve at least the following beneficial technical effects:

[0017] This scheme relies on the floating-point exponent-mantissa splitting mechanism to constrain the nonlinear terms corresponding to division to a fixed narrow interval [1,2). After obtaining the low-order polynomial through Chebyshev approximation, it is transformed into a continuous multiplication and accumulation operation through Horner's rule. The division operation does not require independent divider hardware, and the native multiplication and accumulation path of the PE computing array is fully reused. The hardware execution data flow of division and linear operation of the main matrix is ​​unified, simplifying the hardware architecture.

[0018] Optionally, in S3, the reciprocal square root operation is converted into a multiply-accumulate data stream format as follows: the original data of the reciprocal square root operation is converted into floating-point form; when the exponent of the floating-point number is even, the reciprocal square root operation is converted into... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is When the exponent of a floating-point number is odd, convert the reciprocal square root operation to... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is The nonlinear term is fitted into a low-order polynomial using the Chebyshev approximation method; the product of the low-order polynomial and the scaling factor is transformed based on Horner's rule to obtain the multiplicative data stream form of the reciprocal square root operation.

[0019] This solution can achieve at least the following beneficial technical effects:

[0020] This scheme uses exponent parity correction to uniformly normalize the mantissa of the reciprocal square root operation to a fixed interval [1,4). Only one set of Chebyshev polynomial coefficients needs to be stored to cover all floating-point inputs, reducing on-chip coefficient storage overhead. The overall operation is decomposed into interval polynomial approximation and exponent scaling and shifting, all of which are converted into multiply-accumulate data streams that can be executed by the PE computing array. No separate dedicated reciprocal square root operation unit is required, reducing the number of hardware modules.

[0021] Optionally, in S3, trigonometric function operations are converted into a multiply-accumulate data stream format as follows: the input data for trigonometric function operations is periodically reduced to map the input data to... The interval is defined, and the sign factor of the trigonometric function operations is recorded. The mapped input data is substituted into the original trigonometric function operations and the sign factor is combined with the recorded sign factor to complete the sign correction. The Chebyshev approximation method is used to fit the sign-corrected trigonometric function operations into a low-order polynomial. Based on Horner's rule, the fitted low-order polynomial is transformed to obtain the multiply-accumulate data stream form of the trigonometric function operations.

[0022] This solution can achieve at least the following beneficial technical effects:

[0023] This scheme performs periodic reduction on the trigonometric function input and provides sign factor correction, compressing the global input to a fixed narrow interval [−π / 2, π / 2] before Chebyshev fitting, reducing the order of polynomial fitting and the number of Horner iterations; sign correction and polynomial operations are integrated into a unified multiply-accumulate data stream, eliminating the need for dedicated computing hardware for trigonometric functions, and can be fully integrated into the PE computing array pipeline, thus controlling hardware costs while ensuring the accuracy of trigonometric function calculations.

[0024] Optionally, in S3, higher-order polynomial operations are converted into a multiply-accumulate data stream based on Horner's rule.

[0025] According to a second aspect of the present invention, a large language model inference apparatus for implementing the large language model inference method described in the first aspect of the present invention is proposed. The apparatus includes a pointwise primitive preprocessing unit, a PE computation array, a configurable reduction network, an on-chip cache, a DMA engine, and a control unit. The pointwise primitive preprocessing unit is used to decompose each nonlinear computation operator subgraph of the computation graph of the large language model into a directed acyclic graph composed of affine primitives, reduction primitives, and pointwise primitives, and to convert each pointwise primitive of the directed acyclic graph into a multiply-accumulate data stream format adapted to the PE computation array. The pointwise primitives include exponential operations, division operations, reciprocal square root operations, trigonometric function operations, and higher-order polynomial operations. The PE computation array is used to execute linear operators and affine primitives in the directed acyclic graph. The PE computing array is configured with a normal operating mode and a point-by-point primitive operating mode, and switches between operating modes in response to control signals from the control unit. In the normal operating mode, each processing unit independently executes linear operator operations and affine primitive operations. In the point-by-point primitive operating mode, two adjacent PEs form a mantissa splitting engine, and point-by-point primitives are executed using the mantissa splitting engine as the execution unit. A configurable reduction network is used to execute reduction primitives in directed acyclic graphs. An on-chip cache is used to store intermediate data and parameters generated during the large language model inference process. A DMA engine is responsible for data transfer between off-chip storage and on-chip cache. The control unit is used to send control signals to the PE computing array to control the switching of the PE computing array's operating state, and to control the timing of each hardware module.

[0026] This solution can achieve at least the following beneficial technical effects:

[0027] This solution relies on a unified primitive processing unit to complete the data flow conversion of all nonlinear operators, eliminating the need for independent SFU hardware and alleviating hardware fragmentation issues. The PE computing array supports dynamic switching between normal and point-by-point modes. In normal mode, it ensures the throughput of linear operations on the backbone matrix, while in point-by-point mode, it uses two PEs to form a mantissa splitting engine for parallel computation, suppressing the accumulated accuracy error of Horner iteration with low hardware overhead. Combined with an independent configurable reduction network to process various aggregation reduction primitives, the entire device achieves end-to-end unified pipelined inference for linear, reduction, and nonlinear operators, effectively reducing overall inference latency.

[0028] Optionally, the configurable reduction network is constructed using a binary tree topology, wherein each intermediate node is configured with an addition calculation unit, a maximum value calculation unit, and a minimum value calculation unit, and each intermediate node selects the corresponding calculation unit for calculation according to the reduction primitive; the root node is configured with a lightweight scalar unit to implement the arithmetic combination operations required for complex reduction operations such as mean and variance.

[0029] This solution can achieve at least the following beneficial technical effects:

[0030] This solution uses a binary tree topology to construct a configurable reduction network. Intermediate nodes can switch between addition, maximum value retrieval, and minimum value retrieval operations as needed. A single network can be compatible with all basic aggregation calculations of large language models. The root node integrates a lightweight scalar unit to complete arithmetic operations for complex reductions such as mean and variance, without the need for additional independent scalar calculation hardware, thus improving the versatility of the reduction module and reducing the number of chip hardware modules.

[0031] Optionally, in the point-to-point primitive working mode, the PE computing array splits the multiply-accumulate data stream into high-order bits and low-order bits, and assigns the split high-order bits and low-order bits to the two PEs of the mantissa splitting engine for parallel computing.

[0032] This solution can achieve at least the following beneficial technical effects:

[0033] In point-by-point primitive mode, this solution splits the intermediate result of high-precision multiplication and accumulation into two parts, high-order and low-order, and assigns them to two PEs of the mantissa splitting engine to perform multiplication and accumulation operations in parallel, virtually achieving the effect of wide-precision floating-point operation. It can alleviate the mantissa truncation error caused by multi-layer Horner iteration by relying only on the standard BF16 PE computing array, without replacing the full FP32 high-precision processing unit. It ensures the calculation accuracy of various nonlinear operators without significantly increasing the chip area and power consumption.

[0034] Compared with the prior art, the advantages of the present invention are as follows:

[0035] This invention achieves a unified mapping of linear operators, reduction operators, and various pointwise nonlinear operators to the PE computing array multiply-accumulate pipeline, reducing dependence on dedicated SFU computing units, improving hardware fragmentation, and significantly increasing hardware resource reuse. For exponential, division, reciprocal square root, and trigonometric functions, interval shrinkage strategies are designed, combined with Chebyshev low-order polynomial fitting and Horner transform, reducing iterative computation and on-chip coefficient storage overhead. Relying on a dual PE mantissa splitting engine, it suppresses polynomial iteration accuracy accumulation errors at low cost, and with a configurable binary tree reduction network compatible with various aggregation computation requirements, it reduces nonlinear operator execution latency without significantly increasing chip area and power consumption, improving end-to-end inference throughput for large language models and adapting to low-power inference scenarios on edge devices. Attached Figure Description

[0036] The embodiments of the present invention will be further described below with reference to the accompanying drawings, wherein:

[0037] Figure 1 This is a schematic diagram illustrating the steps of a reasoning method for a large language model containing nonlinear operators according to an embodiment of the present invention.

[0038] Figure 2 This is a schematic diagram of nonlinear operator decomposition according to an embodiment of the present invention;

[0039] Figure 3 This is a schematic diagram of an inference device for a large language model containing nonlinear operators according to an embodiment of the present invention.

[0040] Figure 4 This is a schematic diagram of a tail number splitting engine according to an embodiment of the present invention;

[0041] Figure 5 This is a schematic diagram of a configurable protocol network according to an embodiment of the present invention. Detailed Implementation

[0042] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are merely illustrative and are not intended to limit the invention.

[0043] As mentioned in the background section, nonlinear operators such as Softmax, RMSnorm, and RoPE in large language models are located on the critical path of inference and are frequently called. They contain various computational logics such as exponential, trigonometric functions, mean and variance. Even though their overall computational load is lower than that of matrix operators, the inefficient execution method will still significantly increase the high-end to end inference latency. Currently, both mainstream implementation schemes have defects. Delegating nonlinear operators to the CPU will cause a large amount of cross-end data transfer and scheduling synchronization overhead, which will disrupt the continuous data flow of the accelerator and on-chip data residency. While integrating dedicated computing units such as SFU and VPU inside the chip can avoid cross-device interaction losses, it is limited by the area and power consumption of edge chips and has a throughput bottleneck. Moreover, dedicated components are mostly customized for single functions, with poor versatility and difficulty in covering the rich and diverse nonlinear operators of LLM. The utilization rate of hardware resources is low, and it is impossible to meet the requirements of full operator coverage, low-latency operation and hardware cost constraints.

[0044] To address the aforementioned issues, this invention proposes a three-layer collaborative framework for accelerating large language model inference: First, it constructs a unified primitive-level data flow abstraction mechanism oriented towards operators, unifying and standardizing the hardware mapping logic of various operators to solve the problem of fragmented hardware operator design in traditional systems; second, it employs a processing method combining range contraction with Chebyshev approximation and Horner rule transformation to uniformly convert irregular pointwise nonlinear operations into standardized multiply-accumulate data flows; finally, it builds a hardware execution architecture with dual PE mantissa splitting capability, relying on dynamic bit-width reconstruction to achieve low-cost, high-precision nonlinear acceleration, thus improving the shortcomings of existing accelerators such as low hardware resource utilization and insufficient inference throughput.

[0045] According to one embodiment of the present invention, an inference method for large language models containing nonlinear operators is proposed, see appendix. Figure 1In summary, the method includes steps S1, S2, S3, and S4. To better understand the present invention, each step will be described in detail below with reference to specific embodiments.

[0046] S1. Obtain the computation graph of the large language model to be inferred, which includes linear operators and nonlinear operators.

[0047] According to one embodiment of the present invention, linear operators in the computation graph can be directly scheduled to the PE computation array to perform standard multiply-accumulate operations, while nonlinear operators need to be decomposed into a directed acyclic graph composed of affine primitives, reduction primitives, and pointwise primitives, and the pointwise primitives are converted into multiply-accumulate data streams adapted to the array before being handed over to the hardware to complete the computation.

[0048] S2. Decompose each nonlinear operator in the computation graph into a directed acyclic graph consisting of affine primitives, reduction primitives, and pointwise primitives.

[0049] According to one embodiment of the present invention, each nonlinear operator in the computation graph is systematically decomposed into a directed acyclic graph composed of three basic data flow primitives: affine primitives (A primitives), reduction primitives (R primitives), and pointwise primitives (P primitives). The definitions and mapping relationships of the three types of data flow primitives are as follows: Affine primitives include all element-wise linear transformations, such as scaling, element-wise addition, and subtraction (i.e.,...). These operations, characterized by high data parallelism, can be directly mapped to the MAC units of the PE computation array; reduction primitives include all cross-dimensional statistical operations, such as summation, mean, variance, and maximum, which are fundamental to normalization and numerical stability processing; pointwise primitives include all element-wise nonlinear or transcendental functions, such as exponential functions (exp), reciprocal square root (rsqrt), division (div), sine (sin), cosine (cos), and higher-order polynomial operations (e.g., ... , These operations are the main computational bottlenecks that cannot be naturally mapped to standard PE computing arrays.

[0050] For example, see Appendix Figure 2 , Figure 2 (a) shows an example of how a nonlinear operator such as layer normalization (LayerNorm) decomposes into a directed acyclic graph. Specifically, the formula for calculating layer normalization is... It can be decomposed into the following data flow primitive sequence: (1) Calculate the mean (R primitives); (2) Calculation (A primitive); (3) Calculation (P primitives); (4) Calculate variance (R primitives); (5) Calculation (A primitive); (6) Calculation (P primitives); (7) Calculation (A primitive); (8) Calculation (A original text). Figure 2 (b) demonstrates an example of how nonlinear operators like Softmax can be decomposed into directed acyclic graphs. The formula for calculating Softmax is: It can be decomposed into: (1) Finding the maximum value (R primitives); (2) Subtract the maximum value (A primitive); (3) Calculate the index (P primitives); (4) Summation (R primitives); (5) Division normalization (P primitives). Other nonlinear operators (such as RMSnorm, SiLU, GeLU, RoPE, etc.) can be decomposed into directed acyclic graphs composed of A / R / P primitives in a similar manner. This decomposition transforms the problem of accelerating multiple classes of nonlinear operators into an optimization problem of a finite sequence of primitives.

[0051] S3. Transform each pointwise primitive in each directed acyclic graph into a multiply-accumulate data stream adapted to the PE computation array, wherein the pointwise primitives include exponentiation, division, reciprocal square root, trigonometric function, and higher-order polynomial operations.

[0052] According to one embodiment of the present invention, the efficient execution of pointwise primitives in directed acyclic graphs is a key factor determining the overall end-to-end inference latency of large language models. In this invention, the irregular nonlinear computation of pointwise primitives is transformed into a multiply-accumulate data stream form that can be efficiently executed on a PE computation array. The core of this method is a two-stage computation transformation strategy: first, range shrinkage is performed, and then polynomial approximation is performed. The process of converting four operations—exponential operation, division operation, reciprocal square root operation, trigonometric function operation, and higher-order polynomial operation—into a multiply-accumulate data stream form will be described below.

[0053] (1) Exponentiation

[0054] According to one embodiment of the present invention, the step of converting exponentiation into a multiply-accumulate data stream comprises: converting exponentiation into a power operation with base 2; and splitting the exponent of the power operation into an integer and a decimal sum, thereby converting the power operation into a multiplication-accumulation data stream. ,in, This represents the scaling factor for exponential operations. Indicates the nonlinear part, and These represent the integer and decimal results obtained by splitting the exponent in the exponentiation operation, respectively. The range of values ​​for the decimal is 1. The nonlinear part is fitted into a low-order polynomial using the Chebyshev approximation method; the product of the low-order polynomial and the scaling factor is transformed based on Horner's rule to obtain the multiply-accumulate data stream form of exponential operation.

[0055] For example, exponential operations in Softmax For example, suppose x=2, using the identity... ,in, .available ≈2 × 1.443 = 2.886, where the integer part N = 2 and the fractional part f = 0.886. Therefore, ≈ · The scaling factor is... = =0.25; the nonlinear part is The nonlinear part is approximated using the Chebyshev approximation method, with a result of approximately 0.541. The final output is approximately... ,and The true value is close. This example illustrates that the part of exponential operations that is difficult to calculate directly is restricted to the small interval [0,1), while larger scale changes are determined by the scaling factor. bear.

[0056] (2) Division operation

[0057] According to one embodiment of the present invention, the step of converting a division operation into a multiplication-accumulation data stream format is as follows: converting the divisor of the division operation into a floating-point number form, and converting the division operation into... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is The nonlinear term is fitted to a low-order polynomial using the Chebyshev approximation method; the product of the low-order polynomial and the scaling factor is transformed based on Horner's rule to obtain the multiply-accumulate data stream form of the division operation.

[0058] For example, using division operations For example, suppose the input .because ,therefore, , Based on the above transformation, Where the scaling factor is Nonlinear part The Chebyshev approximation method is used to convert the polynomial to a lower-order polynomial, and Horner's rule is then used to transform the lower-order polynomial to obtain the division operation. The multiply-accumulate data stream, after being processed by the PE computing array, has a nonlinear component. The result is approximately 0.6667. The final output is approximately... ,and The true value is consistent. This example illustrates that the scale part in the division is determined by the scaling factor corresponding to the exponent. The part that truly requires polynomial approximation is restricted to the mantissa interval [1,2).

[0059] (3) Reciprocal square root calculation

[0060] According to one embodiment of the present invention, the step of converting the reciprocal square root operation into a multiply-accumulate data stream format is as follows: converting the original data of the reciprocal square root operation into a floating-point number form; when the exponent of the floating-point number is even, converting the reciprocal square root operation into... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is When the exponent of a floating-point number is odd, the reciprocal square root operation is converted to... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is The nonlinear term is fitted into a low-order polynomial using the Chebyshev approximation method; the product of the low-order polynomial and the scaling factor is transformed based on Horner's rule to obtain the multiplicative data stream form of the reciprocal square root operation.

[0061] (4) Trigonometric function operations

[0062] According to one embodiment of the present invention, the step of converting trigonometric function operations into a multiply-accumulate data stream includes: periodically reducing the input data of the trigonometric function operations to map the input data to... The interval is defined, and the sign factor of the trigonometric function operations is recorded. The mapped input data is substituted into the original trigonometric function operations and the sign factor is combined with the recorded sign factor to complete the sign correction. The Chebyshev approximation method is used to fit the sign-corrected trigonometric function operations into a low-order polynomial. Based on Horner's rule, the fitted low-order polynomial is transformed to obtain the multiply-accumulate data stream form of the trigonometric function operations.

[0063] For example, to calculate For example, suppose the input Radius. First calculate Then calculate ,at this time Already fallen Interval. Because... ,therefore And sign factor The Chebyshev approximation method is used to... The polynomial was fitted to a low-order polynomial, and Horner's rule was used to transform the fitted low-order polynomial into a multiplicative-accumulator data stream. The result, approximately 0.9093, was calculated using a PE computation array. Multiplying by the sign factor +1, the final result was obtained. This example illustrates that the range contraction in the trigonometric function path does not depend on exponential scaling, but rather on the function choice and sign factor determined by q, uniformly mapping any input angle to a smaller angular interval for polynomial approximation.

[0064] (5) Higher-order polynomial operations

[0065] According to one embodiment of the present invention, higher-order polynomial operations are converted into a multiply-accumulate data stream form based on Horner's rule. Specifically, for operations that already have a polynomial form, such as... , Alternatively, polynomial expressions obtained through polynomial approximation such as GeLU and SiLU can be directly represented as... ,coefficient All were generated offline using the Chebyshev approximation method. Horner's rule was used during the online computation phase. Decomposing polynomial evaluation into n consecutive multiplication-accumulation operations naturally maps to the multiplication-accumulation data stream of the PE computing array. Through this transformation, the originally fragmented nonlinear computations are unified into a multiplication-accumulation data stream form isomorphic to matrix multiplication, allowing diverse nonlinear operations to reuse the same set of high-density computing resources.

[0066] It should be noted that the core innovation of this invention regarding range contraction paths does not lie in employing a specific mathematical transformation, but rather in constructing a unified range contraction mechanism for multiple types of nonlinear functions. This mechanism transforms functions of varying forms into a consistent data stream processing format. Specifically, the aforementioned mathematical transformations or numerical representation methods, such as base conversion, integer and decimal splitting, exponent and mantissa representation, and periodic reduction, can all utilize existing technologies. This invention does not consider these individual methods as innovations. Instead, it addresses multiple types of nonlinear operators in large language model inference, abstracting them into pointwise primitives. For different types of pointwise primitives, it selects appropriate range contraction paths or direct polynomial processing paths, generating unified forms of effective input and scaling factors or sign control information. This transforms various nonlinear functions into polynomial approximation problems within fixed intervals, mapping them to a multiply-accumulate data stream on a PE computing array via Horner rules. This forms a unified computational framework of "pointwise primitive identification—range contraction—polynomial approximation—multiply-accumulate execution—scaling recovery," achieving efficient reuse and unified acceleration of multiple types of nonlinear functions on the same hardware architecture.

[0067] S4. A computing device is used to perform calculations on a directed acyclic graph after transforming pointwise primitives into multiply-accumulate data streams using linear operators, in order to complete the large language model inference.

[0068] According to an embodiment of the present invention, a large language model reasoning apparatus for implementing the above-described large language model reasoning method is proposed, see [link to relevant documentation]. Figure 3The device includes a pointwise primitive preprocessing unit, a PE computing array, a configurable reduction network, an on-chip cache, a DMA engine, and a control unit. The pointwise primitive preprocessing unit decomposes each nonlinear computation operator subgraph of the computation graph of a large language model into a directed acyclic graph (DAG) composed of affine primitives, reduction primitives, and pointwise primitives. It then transforms each pointwise primitive in the DAG into a multiply-accumulate data stream adapted to the PE computing array. The pointwise primitives include exponential operations, division operations, reciprocal square root operations, trigonometric function operations, and higher-order polynomial operations. The PE computing array executes linear operators, affine primitives in the DAG, and pointwise primitives. The PE computing array is configured with a normal operating mode and a pointwise primitive operating mode, switching between these modes in response to control signals from the control unit. In the normal operating mode, each processing unit independently executes linear operator operations and affine primitive operations. In the pointwise primitive operating mode, two adjacent PEs form a dual-PE splitting engine. Split-Mantissa (DPSM) executes pointwise primitives using the mantissa splitting engine as the execution unit; a configurable reduction network is used to execute reduction primitives in directed acyclic graphs; an on-chip cache is used to store intermediate data and parameters generated during the inference process of large language models; a DMA engine is responsible for data transfer between off-chip storage and on-chip cache; and a control unit is used to send control signals to the PE computing array to control the switching of the PE computing array's working state, as well as to control the timing of each hardware module.

[0069] According to an embodiment of the present invention, compared with existing large language model inference systems, the present invention mainly has the following three improvements: First, a pointwise primitive preprocessing unit is added to the input side of the PE computing array. This unit includes an integer-to-fractional splitting module and an exponent-to-mantissa splitting module, which are used to perform range shrinking before the pointwise primitives enter the PE computing array, generate the effective input and corresponding scaling factor required for polynomial approximation, thereby converting nonlinear functions such as exponents, division, and reciprocal square roots into rule-based multiplication and accumulation calculations suitable for execution by the PE computing array; Second, the existing PE computing array is improved by using a dual-processing unit... The PE mantissa splitting mechanism is configured as a unified PE computing array, enabling adjacent processing units to dynamically form PE pairs in pointwise primitive mode, constituting a mantissa splitting engine to collaboratively execute high-precision polynomial iterations. Simultaneously, it can still independently execute matrix multiplication and affine primitive calculations in normal mode, thereby improving the resource reuse rate of the PE computing array. Third, the existing reduction tree used for partial summation is expanded into a configurable reduction network. Configurable nodes support different reduction operations such as addition, maximum, and minimum values, and scalar units support division and arithmetic combinations required for complex reduction operations such as mean and variance. Through the above-mentioned new modules and reconfiguration, this invention can uniformly support the execution of affine primitives, pointwise primitives, and reduction primitives without relying on a large number of dedicated function units, improving the execution throughput of nonlinear operators in large language models and reducing the area and power consumption overhead caused by hardware functional fragmentation.

[0070] According to one embodiment of the present invention, see Figure 4 The tail-split engine consists of two adjacent processing units. and Dynamically bound together, both are standard BF16 MAC units, responsible for the calculation of the high and low bits respectively. Directly executing Horner iterations on a standard PE computing array presents a precision mismatch problem: although BF16 MAC accumulates with FP32 precision, the 32-bit intermediate result needs to be truncated back to 16-bit BF16 between iteration steps, resulting in accumulated precision loss; while using all FP32 MAC units would incur approximately 4-5 times the area and power consumption overhead, which is unacceptable on edge devices. This invention solves this problem by utilizing the format alignment characteristic of BF16 and FP32 sharing the same 1 sign bit and 8-bit exponent: it should be noted that the sign bit and 8-bit exponent are not "split" and allocated to the two PEs, but are retained intact in the BF16 number processed by each PE. Since the sign bit and exponent field layouts are completely identical, the 32-bit intermediate result... (in the picture) When splitting, its high 16 bits It just forms a complete BF16 number (Including the original sign bit, the 8-bit exponent, and the highest 7 bits of the mantissa), as The input; the remaining lower-order digits are not directly interpreted as a complete floating-point number, but are instead interpreted according to... Low-bit compensation values ​​are generated through alignment and normalization. As The input is the FP32 mantissa precision. Therefore, each of the two PEs processes a standard BF16 number; what is truly "shared" between the two PEs is only the 23-bit mantissa precision of the FP32, not the sign bit or the exponent field itself. During computation, each Horner iteration step is divided into three stages: input loading, parallel multiplication, and accumulation feedback. At the initial time (Cycle 0), the input is loaded... , Load separately , and the 16-bit valid input obtained after range shrinking (from) Broadcast to two PEs simultaneously, 32-bit coefficients (in the picture) Load The accumulator terminal; in the first cycle (Cycle 1), the two PEs are multiplied in parallel by the multiplier (⊗ in the diagram) to obtain the high- and low-order product. and The second cycle (Cycle 2) will be transmitted via a dedicated data path. Output Routing to The accumulator, after passing through the adder (⊕ in the diagram) and... and coefficient Merging yields a 32-bit result. ( The 32-bit result is then re-split through the feedback path into... and They were sent back separately. , This serves as input for the next Horner iteration. Thus, PE virtualizes an equivalent wide-precision MAC data path without adding full FP32 MAC hardware, achieving high-precision completion. Calculation.

[0071] For example, suppose that a Horner iteration requires computation ,in , , If a single BF16 processing unit is used directly for execution, then It needs to be truncated or rounded to BF16 first, for example, approximately 1.328125, before calculation. The low-order mantissa information is lost. When using the PE pair of this invention for calculation, the splitting logic will... The high portion is sent into ,For example Send the compensation portion corresponding to the lower-order mantissa into ,For example ; calculate , calculate Then, the two products are aligned by their place values ​​and combined to obtain approximately 0.66665, which is then combined with the coefficient. Add them together to get In contrast, the theoretically precise result is... As can be seen, using PE pairs for collaborative computation can retain more low-order mantissa information, thus obtaining computation results closer to FP32 precision. The numerical examples above are only used to illustrate the process of PE pair collaborative computation; in actual hardware... , , and All operations are split, aligned, and combined according to binary bit fields. Therefore, it can be seen that... and Parallel processing of different tail segments of the same FP32 intermediate result can improve the accuracy of polynomial iteration calculations while maintaining low hardware overhead.

[0072] According to one embodiment of the present invention, see appendix. Figure 5 A configurable reduction network is used to execute reduction primitives. A typical PE computation array is followed by an addition tree for accumulating partial sums in matrix multiplication, but this fixed-function data path cannot support reduction primitives. This invention upgrades the addition tree to a configurable reduction network, achieving unified support for various reduction operations through two key enhancements. The first enhancement is the introduction of an input multiplexer, allowing data from the on-chip cache to bypass the MAC unit and be directly fed into the CRN, thus enabling reduction operations on raw tensor data, not just the MAC output. The second enhancement replaces each simple two-input adder with a configurable node (CN), which can perform different operations such as addition, maximum, or minimum values ​​under global control signals. A lightweight scalar unit (SU) is integrated at the tree structure exit to perform division and final arithmetic combination operations (such as division in mean calculation and combination operations in variance calculation). This hierarchical, configurable design achieves unified support for various reduction operations with minimal area overhead.

[0073] For example, taking the Softmax operator as an example, its complete execution process in the nonlinear operator data stream primitive execution device of the present invention is as follows. First, the input vector is sent from the on-chip cache to the configurable reduction network. The configurable nodes in the configurable reduction network are configured to the maximum value comparison mode, and the maximum value reduction is performed on the input vector to obtain the maximum value. Subsequently, the unified PE computation array operates in conventional multiply-accumulate mode, performing affine primitive computations on each element of the input vector, i.e., computation... This is done to achieve numerical stability processing for Softmax; then, the pointwise primitive preprocessing unit processes... Perform integer-to-fraction splitting on the opposite of the number to generate the valid input required for the exponential approximation. and scaling factor The unified PE computation array switches to pointwise primitive mode. Adjacent PEs form PE pairs through the DPSM mechanism, and Horner's rule is used to pair them according to the pre-stored polynomial coefficients. Perform polynomial multiplication and summation calculations, and then combine them with a scaling factor. get The approximate result is then fed back into the configurable reduction network, where the configurable nodes are configured in addition mode for all... Perform the summation reduction to obtain Finally, calculations are performed using the division or reciprocal path of the pointwise primitives. And executed by a unified PE computing array. The affine multiplication yields the final output of Softmax. Thus, the maximum value, subtraction, exponentiation, summation, and division normalization processes in Softmax are collaboratively completed by a configurable reduction network, a unified PE computation array, and a pointwise primitive preprocessing unit, respectively, achieving unified data flow execution of the Softmax operator within the same device.

[0074] In summary, the inference method and system for large language models proposed in this invention eliminate the fragmentation caused by different operators requiring dedicated hardware pathways. The polynomial approximation transformation further converts the irregular nonlinear computation of pointwise primitives into a multiply-accumulate data stream isomorphic to matrix multiplication, allowing it to reuse the high-density computing resources of the PE computing array. The lightweight microarchitecture extension provides high-throughput hardware execution support for the aforementioned three types of primitives. This algorithm-hardware co-design achieves efficient and unified acceleration of nonlinear operators in large language model inference with minimal hardware cost.

[0075] It should be noted that although the steps are described in a specific order above, it does not mean that the steps must be executed in the above specific order. In fact, some of these steps can be executed concurrently or even in a different order, as long as the required function can be achieved.

[0076] This invention can be a system, method, electronic device, computing device, computer-readable medium, and / or computer program product. A computer program product primarily refers to a software product that implements this solution through a computer program.

[0077] The various embodiments of the present invention have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or technical improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A reasoning method for large language models containing nonlinear operators, comprising a computing device including a PE computation array and a reduction and summation tree to perform reasoning on the large language model, characterized in that, The method includes: S1. Obtain the computation graph of the large language model to be reasoned, which includes linear operators and nonlinear operators; S2. Decompose each nonlinear operator in the computation graph into a directed acyclic graph composed of affine primitives, reduction primitives, and pointwise primitives; S3. Transform each point primitive in each directed acyclic graph into a multiply-accumulate data stream format adapted to the PE computation array, wherein the point primitive includes exponentiation operation, division operation, reciprocal square root operation, trigonometric function operation and higher-order polynomial operation. S4. A computing device is used to perform calculations on a directed acyclic graph after the pointwise primitives are transformed into a multiply-accumulate data stream using linear operators, in order to complete the large language model inference.

2. The method according to claim 1, characterized in that, In S3, exponentiation is converted into a multiply-accumulate data stream format as follows: Convert exponentiation to power of 2; To convert the exponent of an exponentiation operation into a sum of integer and decimal parts, the exponentiation operation is transformed into... ,in, This represents the scaling factor for exponential operations. Indicates the nonlinear part, and These represent the integer and decimal results obtained by splitting the exponent in the exponentiation operation, respectively. The range of values ​​for the decimal is 1. ; The nonlinear part is fitted into a low-order polynomial using the Chebyshev approximation method. Based on Horner's rule, the product of a low-order polynomial and a scaling factor is transformed to obtain the multiply-accumulate data stream form of exponential operations.

3. The method according to claim 1, characterized in that, In S3, division operations are converted into a multiply-accumulate data stream format as follows: Convert the divisor of the division operation to floating-point form, and convert the division operation to... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is ; The Chebyshev approximation method is used to fit the nonlinear terms into low-order polynomials. Based on Horner's rule, the product of a low-order polynomial and a scaling factor is transformed to obtain the multiply-accumulate data stream form of the division operation.

4. The method according to claim 1, characterized in that, In S3, the reciprocal square root operation is converted into a multiply-accumulate data stream format as follows: Convert the original data for the reciprocal square root operation into floating-point form; When the exponent of a floating-point number is even, convert the reciprocal square root operation to... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is When the exponent of a floating-point number is odd, convert the reciprocal square root operation to... ,in, It is a nonlinear term. Indicates the scaling factor. The exponent of a floating-point number. Represents the mantissa of a floating-point number. The range of values ​​is ; The Chebyshev approximation method is used to fit the nonlinear terms into low-order polynomials. Based on Horner's rule, the product of a low-order polynomial and a scaling factor is transformed to obtain the multiplicative data stream form of the reciprocal square root operation.

5. The method according to claim 1, characterized in that, In S3, trigonometric function operations are converted into a multiply-accumulate data stream format as follows: Periodic reduction is performed on the input data for trigonometric function operations to map the input data to... The interval is recorded, and the sign factors of trigonometric function operations are also recorded; The mapped input data is substituted into the original trigonometric function operations and the recorded sign factor is combined to complete the sign correction. The Chebyshev approximation method is used to fit the sign-corrected trigonometric function operations into a low-order polynomial. Based on Horner's rule, the fitted low-order polynomial is transformed to obtain the multiplication-accumulation data stream form of trigonometric function operations.

6. The method according to claim 1, characterized in that, In S3, higher-order polynomial operations are converted into a multiply-accumulate data stream based on Horner's rule.

7. A large language model reasoning apparatus for implementing the large language model reasoning method according to any one of claims 1-6, characterized in that, The device includes a pointwise primitive preprocessing unit, a PE computing array, a configurable reduction network, an on-chip cache, a DMA engine, and a control unit, wherein: The pointwise primitive preprocessing unit is used to decompose each nonlinear computation operator subgraph in the computation graph of the large language model into a directed acyclic graph composed of affine primitives, reduction primitives and pointwise primitives, and to transform each pointwise primitive in the directed acyclic graph into a multiply-accumulate data stream form adapted to the PE computation array. The pointwise primitives include exponential operations, division operations, reciprocal square root operations, trigonometric function operations and higher-order polynomial operations. The PE computing array is used to execute linear operators, affine primitives in directed acyclic graphs, and pointwise primitives. The PE computing array is configured with a normal operating mode and a pointwise primitive operating mode, and switches between operating modes in response to the control signal of the control unit. In the normal operating mode, each processing unit independently executes linear operator operations and affine primitive operations. In the pointwise primitive operating mode, two adjacent PEs form a mantissa splitting engine, and pointwise primitives are executed with the mantissa splitting engine as the execution unit. Configurable reduction networks are used to execute reduction primitives in directed acyclic graphs; On-chip cache is used to store intermediate data and parameters generated during the inference process of large language models; The DMA engine is responsible for data transfer between off-chip storage and on-chip cache; The control unit is used to send control signals to the PE computing array to control the switching of the PE computing array's working state, and to control the timing of each hardware module.

8. The apparatus according to claim 7, characterized in that, The configurable reduction network is constructed using a binary tree topology. Each intermediate node is equipped with an addition calculation unit, a maximum value calculation unit, and a minimum value calculation unit. Each intermediate node selects the corresponding calculation unit for calculation according to the reduction primitive. The root node is equipped with a lightweight scalar unit to implement the arithmetic combination operations required for complex reduction operations such as mean and variance.

9. The apparatus according to claim 7, characterized in that, In point-by-point primitive mode, the PE computing array splits the multiply-accumulate data stream into high-order bits and low-order bits, and then assigns the split high-order bits and low-order bits to the two PEs of the mantissa splitting engine for parallel computing.

10. A computer program product, comprising a computer program, characterized in that, The computer program is executed by a processor to implement the steps of the method according to any one of claims 1-6.