Operator precision adaptive allocation method based on multi-dimensional state perception and related equipment

By constructing precision-aware semantic information and multi-dimensional state awareness methods, the operator precision allocation in the neural network model is dynamically adjusted, solving the problem that the operator precision allocation strategy in the existing technology cannot be dynamically adjusted, thus improving the accuracy of neural network inference and hardware execution efficiency.

CN123140107APending Publication Date: 2026-11-20SHENZHEN SMARTCITY TECH DEV GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611648122.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-23
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In existing neural network inference processes, the operator precision allocation strategy cannot be dynamically adjusted, resulting in excessive demands on computing resources and storage bandwidth, as well as poor generalization ability.

Method used

By acquiring the computational graph of the neural network model, we construct precision-aware semantic information, combine data features, computational features, and hardware state features to generate multi-dimensional state information, perform precision evaluation and constraint determination, and dynamically adjust the operator precision allocation strategy.

Benefits of technology

It achieves adaptive allocation of operator precision during neural network inference, improving accuracy and hardware execution efficiency while reducing computational and storage overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123140107A_ABST
    Figure CN123140107A_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose an operator precision adaptive allocation method based on multi-dimensional state perception and related equipment, which can include devices and electronic equipment. The method analyzes a to-be-executed neural network model to obtain a computation graph. Precision perception semantic information is constructed for operator nodes in the computation graph to obtain a precision perception computation graph. Data features, computation features, and hardware state features generated in a previous execution process of the to-be-executed neural network model are obtained to construct multi-dimensional state information of the operator nodes. Based on the precision perception computation graph, the multi-dimensional state information, and preset constraint information, precision evaluation and constraint determination are performed on the operator nodes and node chains in the computation graph to generate a precision allocation strategy. The precision perception computation graph is reconstructed in precision according to the precision allocation strategy, and a target execution computation graph is generated for model inference calculation, thereby improving the accuracy of operator precision adaptive allocation in the neural network inference process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of neural network inference technology, specifically to a method and related equipment for adaptive allocation of operator precision based on multi-dimensional state awareness. The related equipment may include an adaptive allocation device and electronic equipment based on multi-dimensional state awareness of operator precision. Background Technology

[0002] In recent years, deep neural network models have achieved remarkable results in various artificial intelligence tasks. However, with the continuous increase in model size, the demand for computing resources and storage bandwidth in the neural network inference process is growing exponentially. To reduce inference overhead, mixed-precision inference techniques have been widely adopted—by assigning different bit-width data types (such as FP32, FP16, BF16, INT8, etc.) to different operators, the computational load, storage footprint, and data transfer overhead are reduced while maintaining model accuracy as much as possible.

[0003] Currently, mainstream operator hybrid precision assignment strategies mainly include manual experience-based assignment, automatic assignment based on fixed rules, and automatic assignment based on offline search. Manual experience-based assignment relies on experts' understanding of the model structure and hardware characteristics, manually assigning precision to each layer, which is inefficient and difficult to adapt to different input distributions. Automatic assignment based on fixed rules (such as uniformly setting reduction operators to FP32 and others to FP16) reduces the manual burden, but its rules are static and cannot be dynamically adjusted according to the actual data distribution and hardware status at runtime. Automatic assignment based on offline search (such as using reinforcement learning or genetic algorithms to search for the optimal precision combination) can find relatively good static strategies, but the search process is time-consuming, and the obtained strategies are usually only applicable to specific models and fixed input sizes, resulting in poor generalization ability. Summary of the Invention

[0004] This application provides a method and related equipment for adaptive allocation of operator precision based on multi-dimensional state awareness. The related equipment may include an adaptive allocation device and an electronic device for operator precision based on multi-dimensional state awareness, which can improve the accuracy of adaptive allocation of operator precision during neural network inference.

[0005] An operator precision adaptive allocation method based on multi-dimensional state awareness includes: Obtain the neural network model to be executed, and parse the neural network model to be executed to obtain the computation graph corresponding to the neural network model to be executed; Accuracy-aware semantic information is constructed for the operator nodes in the computation graph, and the accuracy-aware semantic information is added to the computation graph to obtain an accuracy-aware computation graph. The accuracy-aware semantic information is used to characterize the numerical behavior features of the operator nodes under different accuracy conditions. The data features, computational features, and hardware state features generated during the prior execution of the neural network model to be executed are obtained to construct the multidimensional state information of the operator node; Based on the precision-aware computation graph, the multi-dimensional state information, and the preset constraint information, the operator nodes and node chains in the computation graph are evaluated for precision and constrained to generate a precision allocation strategy. The precision allocation strategy includes the computation precision, accumulation precision, and storage precision configured for each operator node. Based on the precision allocation strategy, the precision-aware computation graph is reconstructed to generate a target execution computation graph, and the inference computation of the neural network model to be executed is performed based on the target execution computation graph.

[0006] Accordingly, embodiments of this application provide an operator precision adaptive allocation device based on multi-dimensional state awareness, comprising: The acquisition unit is used to acquire the neural network model to be executed and parse the neural network model to be executed to obtain the computation graph corresponding to the neural network model to be executed. A perception unit is used to construct precision-aware semantic information for the operator nodes in the computation graph, and add the precision-aware semantic information to the computation graph to obtain a precision-aware computation graph. The precision-aware semantic information is used to characterize the numerical behavior features of the operator nodes under different precision conditions. The construction unit is used to acquire the data features, computational features and hardware state features generated during the prior execution of the neural network model to be executed, so as to construct the multidimensional state information of the operator node; The generation unit is used to perform precision evaluation and constraint determination on the operator nodes and node chains in the precision-aware computation graph based on the precision-aware computation graph, the multi-dimensional state information and the preset constraint information, so as to generate a precision allocation strategy. The precision allocation strategy includes the computation precision, accumulation precision and storage precision configured for each operator node. The reconstruction unit is used to reconstruct the precision-aware computation graph based on the precision allocation strategy, generate a target execution computation graph, and perform inference computation of the neural network model to be executed based on the target execution computation graph.

[0007] In some embodiments, the construction unit may be specifically used to collect tensor value distribution information of the operator node and the node chain to obtain data features, wherein the tensor value distribution information includes at least the maximum value, minimum value, mean, and variance of the input tensor; calculate the computational behavior information of the operator node to obtain computational features, wherein the computational behavior information includes at least computational load, node execution latency, cumulative path length, and node execution count; collect the execution environment information of the target execution backend where the operator node is located to obtain hardware state features, wherein the execution environment information includes at least computing unit utilization, memory bandwidth utilization, on-chip cache hit rate, data movement overhead, and precision conversion overhead; and fuse and encode the data features, the computational features, and the hardware state features to obtain multidimensional state information of the operator node.

[0008] In some embodiments, the generation unit may specifically be used to identify the operator type of the operator node from the precision-aware computation graph, and detect the numerical behavior threshold corresponding to the operator type from the preset constraint information; for each operator node, compare the data features and computational features in the multidimensional state information of the operator node with the numerical behavior threshold to obtain operator-level precision constraint results; identify multiple node chains, node chain types, and operator nodes contained in the node chains from the precision-aware computation graph, and detect the chain-level linkage constraint rules corresponding to the node chain type from the preset constraint information; for each node chain, obtain chain-level precision constraint results based on the connection relationship between the operator nodes in the node chain, the multidimensional state information of the operator nodes, and the chain-level linkage constraint rules; compare the hardware state features in the multidimensional state information of the operator nodes with the hardware performance constraint rules in the preset constraint information to obtain hardware-level precision constraint results; and fuse the operator-level precision constraint results, the chain-level precision constraint results, and the hardware-level precision constraint results to obtain a precision allocation strategy.

[0009] In some embodiments, the generation unit may specifically be used to determine the accumulation precision based on the operator-level precision constraint results and the chain-level precision constraint results, wherein the accumulation precision refers to the accumulation data type used by the operator node when generating intermediate results by performing reduction or multiply-add operations; determine the computational precision based on the operator-level precision constraint results, the chain-level precision constraint results, and the hardware-level precision constraint results, wherein the computational precision refers to the computational data type used by the operator node when performing internal operations; and determine the storage precision based on the chain-level precision constraint results and the hardware-level precision constraint results, wherein the storage precision refers to the storage data type used by the operator node when caching data.

[0010] In some embodiments, the reconstruction unit may be specifically used to configure the operator precision of each operator node in the precision-aware computation graph according to the precision allocation strategy, and write the computation precision, accumulation precision and storage precision corresponding to each operator node into the attributes of the operator node; to perform consistency adjustment on the precision of adjacent operator nodes with the same node type in the node chain to obtain an intermediate precision reconstruction computation graph; to calculate the data type conversion overhead of the intermediate precision reconstruction computation graph, and to adjust the intermediate precision reconstruction computation graph based on the data type conversion overhead to obtain a target execution computation graph, wherein the data type conversion overhead refers to the overhead generated by data type conversion between adjacent operator nodes with different precisions; and to map the target execution computation graph to the target execution backend to execute the inference computation of the neural network model to be executed.

[0011] In some embodiments, the reconstruction unit may be specifically used to identify the connection edges between adjacent operator nodes with different precisions from the intermediate precision reconstruction computation graph to obtain a precision switching edge set; calculate the switching cost of each precision switching edge in the precision switching edge set to obtain the data type conversion cost of the intermediate precision reconstruction computation graph; and reduce the size of the precision switching edge set or the data type conversion cost by local merging and position rearrangement with the conversion number and conversion position as optimization objectives to obtain the target execution computation graph.

[0012] In some embodiments, the apparatus further includes an update unit, specifically configured to collect output data and performance data generated during the execution of the target execution computation graph. The output data is used to characterize the numerical state information of the output tensor, and the performance data is used to characterize the performance state information of the inference execution. The output data is compared with preset numerical anomaly conditions, and the performance data is compared with preset performance optimization conditions to obtain a comparison result. The precision allocation strategy is updated based on the comparison result to obtain an updated precision allocation strategy, and the computation graph is reconstructed based on the updated precision allocation strategy.

[0013] In some embodiments, the precision-aware semantic information includes: operator category identifier, numerical range change identifier, accumulation path structure identifier, precision sensitivity identifier, and node chain position identifier; wherein, the operator category identifier is used to distinguish the operator type of the operator node; the numerical range change identifier is used to describe the relationship between the operator node and the input tensor numerical range; the accumulation path structure identifier is used to describe the accumulation depth within the operator node or across operators; the precision sensitivity identifier is used to indicate the sensitivity of the operator node to low-precision errors; and the node chain position identifier is used to indicate the node chain type of the node chain in which the operator node is located.

[0014] Furthermore, embodiments of this application also provide an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the operator precision adaptive allocation method based on multi-dimensional state awareness provided in embodiments of this application.

[0015] Furthermore, embodiments of this application also provide a computer-readable storage medium storing a computer program adapted for loading by a processor to execute steps in any of the multi-dimensional state-aware operator precision adaptive allocation methods provided in embodiments of this application.

[0016] Furthermore, embodiments of this application also provide a computer program product, including a computer program that, when executed by a processor, implements the steps in the multi-dimensional state-aware operator precision adaptive allocation method provided in embodiments of this application.

[0017] This application embodiment obtains the neural network model to be executed and parses it to obtain the computation graph corresponding to the neural network model to be executed; it constructs precision-aware semantic information for the operator nodes in the computation graph and adds the precision-aware semantic information to the computation graph to obtain a precision-aware computation graph. The precision-aware semantic information is used to characterize the numerical behavior features of the operator nodes under different precision conditions; it obtains the data features, computation features, and hardware state features generated by the neural network model to be executed during the initial execution process to construct the multi-dimensional state information of the operator nodes; based on the precision-aware computation graph, the multi-dimensional state information, and the preset constraint information, it performs precision evaluation and constraint determination on the operator nodes and node chains in the computation graph to generate a precision allocation strategy. The precision allocation strategy includes the computation precision, accumulation precision, and storage precision configured for each operator node; it reconstructs the precision-aware computation graph based on the precision allocation strategy to generate a target execution computation graph, and executes the inference computation of the neural network model to be executed based on the target execution computation graph.

[0018] Because this scheme can accurately characterize the numerical sensitivity of each operator node at different precisions based on precision-aware semantic information, and combine the data features, computational features and hardware state features dynamically collected during the inference process, it can perform joint constraint judgment from three dimensions: operator level, node chain level and hardware state level, thereby generating a precision allocation strategy that is highly adapted to the current model structure, input data and hardware environment. At the same time, it supports dynamic updates based on execution feedback. Therefore, it can improve the accuracy of operator precision adaptive allocation based on multi-dimensional state awareness, and maximize hardware execution efficiency while ensuring the numerical stability of model inference. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a schematic diagram of a scenario for the operator precision adaptive allocation method based on multi-dimensional state awareness provided in an embodiment of this application. Figure 2 This is a flowchart illustrating the operator precision adaptive allocation method based on multi-dimensional state awareness provided in the embodiments of this application; Figure 3 This is a schematic diagram of operator-level precision control provided in an embodiment of this application; Figure 4 This is a schematic diagram of node chain-level precision control and feedback update provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of the operator precision adaptive allocation device based on multi-dimensional state awareness provided in the embodiments of this application; Figure 6 This is another structural schematic diagram of the operator precision adaptive allocation device based on multi-dimensional state awareness provided in the embodiments of this application; Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0021] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0022] This application provides a method and related equipment for adaptive allocation of operator precision based on multi-dimensional state awareness. The related equipment may include a device for adaptive allocation of operator precision based on multi-dimensional state awareness, an electronic device, a computer program product, and a computer-readable storage medium. The device for adaptive allocation of operator precision based on multi-dimensional state awareness can be integrated into an electronic device, which may be a server or a terminal, etc.

[0023] The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network (CDN), and big data and artificial intelligence platforms. The terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, smart TV, smart glasses, smart home device, or other smart terminal, but is not limited to these. The terminal and server can be connected directly or indirectly via wired or wireless communication, which is not limited herein.

[0024] For example, see Figure 1 Taking the integration of a multi-dimensional state-aware operator precision adaptive allocation device into an electronic device as an example, the electronic device can acquire the neural network model to be executed and parse it to obtain the computation graph corresponding to the neural network model to be executed; construct precision-aware semantic information for the operator nodes in the computation graph and add the precision-aware semantic information to the computation graph to obtain a precision-aware computation graph; acquire the data features, computation features and hardware state features generated by the neural network model to be executed during the initial execution process to construct the multi-dimensional state information of the operator nodes; based on the precision-aware computation graph, multi-dimensional state information and preset constraint information, perform precision evaluation and constraint determination on the operator nodes and node chains in the computation graph to generate a precision allocation strategy; reconstruct the precision of the computation graph based on the precision allocation strategy to generate a target execution computation graph, and execute the inference computation of the neural network model to be executed based on the target execution computation graph, thereby improving the accuracy of the multi-dimensional state-aware operator precision adaptive allocation.

[0025] The following sections provide detailed descriptions of each example. It should be noted that the order in which the embodiments are described is not intended to limit the preferred order of the embodiments.

[0026] This embodiment will be described from the perspective of an operator precision adaptive allocation device based on multi-dimensional state awareness. Specifically, the operator precision adaptive allocation device based on multi-dimensional state awareness can be integrated into an electronic device, which can be a server or a terminal, etc. The terminal can include tablet computers, laptops, personal computers (PCs), wearable devices, virtual reality devices, or other smart devices that can perform operator precision adaptive allocation based on multi-dimensional state awareness.

[0027] like Figure 2 As shown, Figure 2This is an optional flowchart illustrating an operator precision adaptive allocation method based on multi-dimensional state awareness provided in an embodiment of this disclosure. This operator precision adaptive allocation method based on multi-dimensional state awareness can be executed by a server or a terminal alone, or it can be executed by a terminal and a server in cooperation.

[0028] This application's embodiments can be applied to the inference process of neural network models, and are particularly suitable for large language models running in the ggml / llama.cpp inference framework, GGUF model loading environment, or NPU inference backend. It collects runtime state information during the computation graph execution phase, and combines this with operator numerical behavior, tensor distribution characteristics, computational load, and hardware resource status to determine and allocate precision for operator nodes or node chain structures in the computation graph. Based on this, it generates a target execution computation graph and execution configuration adapted to the target execution backend, thereby achieving dynamic adjustment of precision during model inference.

[0029] An operator precision adaptive allocation method based on multi-dimensional state awareness can be described in the following steps: 101. Obtain the neural network model to be executed and parse it to obtain the computation graph corresponding to the neural network model to be executed.

[0030] In computation graphs, a directed graph data structure is used to represent the computation process of neural networks. In a computation graph, nodes represent operators or operations (such as convolution, matrix multiplication, normalization, activation functions, etc.) in the neural network, and edges represent data tensors passed between operators and their flow. Each operator node receives zero or more input tensors, executes the corresponding computational logic, and produces zero or more output tensors. Input and output tensors are connected to other operator nodes through edges, thus forming explicit data dependencies and execution order.

[0031] For example, for a simple neural network sublayer “input tensor → matrix multiplication (MatMul) → bias addition (Add) → activation function (ReLU) → output tensor”, the parsed computation graph contains three operator nodes: MatMul node, Add node, and ReLU node. The output tensor of the MatMul node is connected to the input port of the Add node through an edge, and the output tensor of the Add node is connected to the input port of the ReLU node through another edge, thus clearly expressing the computational path of data flowing from MatMul to Add and then to ReLU.

[0032] In this embodiment, obtaining the neural network model to be executed may include: obtaining the neural network model file to be deployed from the local device memory. The format of the model file may be ONNX (Open Neural Network Exchange), TensorFlow's PB (Protocol Buffer) format, PyTorch's TorchScript format, Caffe model format, or any other model format that can represent the neural network structure.

[0033] Parsing the neural network model to be executed may include: reading the network structure definition and parameter information in the model file, extracting the type identifier of each operator in the model, the shape and data type of the input and output tensors, the operator attribute parameters (such as convolution kernel size, stride, padding method, etc.), and the topological connection relationship between operators; based on the extracted information, constructing a computation graph data structure in memory, in which each operator is instantiated as a node object in the graph, and the node object records attribute information such as operator type, input and output specifications, and initial precision, and the data dependencies between operators are instantiated as edge objects connecting the corresponding node objects.

[0034] 102. Construct precision-aware semantic information for the operator nodes in the computation graph, and add the precision-aware semantic information to the computation graph to obtain the precision-aware computation graph.

[0035] Among them, precision-aware semantic information is used to characterize the numerical behavior features of operator nodes under different precision conditions, providing a semantic basis for subsequent precision evaluation and constraint determination.

[0036] Precision-aware semantic information includes: operator category identifier, numerical range change identifier, accumulation path structure identifier, precision sensitivity identifier, and node chain position identifier.

[0037] The operator category identifier is used to distinguish the operator type of the operator node. Based on the operation properties, operators are divided into different categories, such as exponential operation type (e.g., Softmax, Exp), reduction type (e.g., ReduceSum, ReduceMean), linear operation type (e.g., matrix multiplication, convolution), and element-wise operation type (e.g., Add, ReLU).

[0038] The numerical range variation identifier is used to describe the propagation characteristics of the operator node to the numerical range of the input tensor. Specifically, it characterizes the relationship of amplification, scaling or preservation of the input numerical range when the operator performs calculations, and is used to assess the risk of numerical overflow or underflow of the operator under low precision conditions.

[0039] The accumulation path structure identifier is used to describe the accumulation depth within or across operator nodes, i.e., the number of elements involved in the accumulation operation or the size of the reduction dimension. The greater the accumulation depth, the more significant the error accumulation during low-precision accumulation. This identifier provides a structural basis for configuring the accumulation precision.

[0040] The precision sensitivity flag is used to indicate how sensitive an operator node is to quantization errors introduced by low-precision calculations. It can be determined based on the mathematical operation characteristics of the operator or historical inference statistics. Operator nodes with higher sensitivity are more likely to produce numerical anomalies when executed with low precision, and therefore need to be configured with higher calculation precision or accumulation precision.

[0041] The node chain position identifier is used to indicate the type of node chain in the computation graph where the operator node is located and its relative position within the chain. The node chain type includes attention node chain, reduction node chain, residual node chain, or quantization node chain, etc. This identifier is used to support the consistency of accuracy of low-sensitivity nodes within the same node chain and the limitation of high-precision regions in subsequent steps.

[0042] Examples of operator nodes included in various node chains are as follows: Attention node chains include: MatMul(Q,K^T) node for matrix multiplication of query and key, Scale node, Softmax node for attention weight normalization, and MatMul(·,V) node for matrix multiplication of value and attention weight matrix. This type of node chain is sensitive to the range of input values, and exponential operation nodes such as Softmax are prone to overflow. The reduction node chain includes: ReduceSum node, mean calculation node, variance calculation node, normalization node, etc. This type of node chain involves accumulation operations across channels or across sequence dimensions, with a large accumulation depth, and is sensitive to low-precision accumulation errors. Linear transformation node chains include matrix multiplication nodes MatMul, addition nodes Add, multiplication nodes Mul, or residual connection nodes, etc. These types of node chains are usually composed of continuous linear or element-wise operations. The internal nodes are relatively less sensitive to precision and are suitable for precision uniform optimization. The quantization node chain includes: quantization operator nodes, intermediate computation operator nodes, and dequantization operator nodes, etc.

[0043] By classifying node chain types and defining node composition as described above, we can accurately identify continuous node sequences with specific numerical behavior characteristics in the computation graph, thereby providing a structural basis for subsequent precision constraint determination at the node chain level, precision merging of low-sensitivity nodes, and high-precision region restrictions.

[0044] This embodiment constructs precision-aware semantic information for each node by traversing each operator node in the computation graph, and adds this information to the attributes of the corresponding node in the computation graph, thereby obtaining a precision-aware computation graph, which provides a semantic basis for subsequent precision evaluation and constraint determination.

[0045] 103. Obtain the data features, computational features, and hardware state features generated during the prior execution of the neural network model to be executed, in order to construct the multidimensional state information of the operator nodes.

[0046] Among them, data features are used to characterize the numerical distribution and statistical properties of the input and output tensors involved in the processing of operator nodes, and reflect the changes in the dynamic range of data of different operators.

[0047] Computational features are used to describe the computational behavior of operators, that is, to characterize the computational load, execution efficiency and accumulation path structure of operator nodes during the computation process, and to reflect the actual computational overhead of operators under the current precision configuration.

[0048] Hardware status features are used to characterize the hardware resource usage, data transfer efficiency, and precision conversion overhead of the inference backend when executing operator nodes, reflecting the real-time load status of the current operating environment.

[0049] In this embodiment, the process of constructing the multidimensional state information of the operator node may include: 103-1. Collect the tensor numerical distribution information of operator nodes and node chains to obtain data characteristics.

[0050] Specifically, during the prior execution of the neural network model to be executed (such as in the previous batch, within a preset time window, or during offline trial run), the numerical distribution information of the input and output tensors involved in each operator node and node chain in its computation graph can be collected and used as data features. These data features include at least the maximum, minimum, mean, and variance of the input tensors, and may further include quantiles, activation value distribution features, and attention weight distribution features, etc.

[0051] The focus of data collection differs depending on the node type or node chain type: For the attention node chain containing the Softmax operator, the focus is on collecting the maximum, minimum, and distribution range of the Softmax operator's input tensor to assess the overflow risk of exponential operations. For example, during inference execution, the input tensor of the Softmax node is acquired in real time, and its numerical distribution is statistically analyzed: Suppose that in a certain inference batch, the maximum value of the Softmax input tensor is 65.0, the minimum value is -12.5, and the dynamic range width reaches 77.5. Since the exponential function e... x It is highly sensitive to input values; when the input value is greater than approximately 88.0 (the maximum exponential range that FP16 can represent), e xExceeding the representation limit of FP16 will result in Inf overflow (Infinity, representing infinity); even if it does not overflow directly, an excessively large dynamic range will lead to concentrated numerical distribution and loss of significant bits at low precision. By collecting the maximum, minimum, and distribution range of this value, it can be determined that the Softmax node has a high risk of overflow, and thus, in subsequent precision determination, it can be assigned FP32 calculation precision or necessary type conversion protection can be inserted.

[0052] For the residual node chain containing the Add operator, the key is to collect the magnitude ratio of the two input tensors to determine whether low-precision element-wise operations will cause a small amount of information loss. For example, in the residual connection scenario, one input of the Add operator comes from the MatMul output of the main branch (with a large numerical range), and the other input comes from the original input of the skip connection (with a small numerical range). The average values ​​of the two input tensors are 1024.0 and 0.8, respectively, with a magnitude ratio of 1280:1. If FP16 (with approximately 3-4 decimal digits) is used for low-precision element-wise addition, the smaller magnitude input will have its significant digits masked by the rounding of the larger magnitude input (i.e., "small information loss"), resulting in the ineffective transmission of fine-grained features in the residual connection. By collecting the magnitude ratio of the two input tensors, the risk of information loss under low precision can be quantitatively assessed, thereby determining whether the Add node needs to maintain high computational precision or adopt a mixed precision strategy.

[0053] For LayerNorm operators or normalization-related operator nodes, the focus is on collecting the distribution range of the tensors involved in the mean, variance, or normalization calculations. For example, the LayerNorm operator requires calculating the mean and variance of the input tensor along the feature dimension during the calculation process, involving reduction and summation operations on multiple elements. Collecting the distribution range of the input tensors involved in this calculation is crucial. For instance, in a certain inference, the numerical range of the LayerNorm input tensor might be between [-50.0, 50.0], and the feature dimension length might be relatively large (e.g., 1024 or 4096). If FP16 is used for cumulative calculation of the mean and variance, due to the long accumulation path and large dynamic range, low-precision accumulation errors will accumulate continuously during the reduction process, causing the calculated mean to deviate from the true value and the variance to become distorted, thus shifting the normalization result and affecting the model output quality. By collecting the numerical range and distribution characteristics of this tensor, it can be determined that high precision such as FP32 needs to be assigned to the accumulation operation of the LayerNorm node to ensure the numerical stability of the normalization calculation.

[0054] Therefore, through targeted data collection, data features can accurately reflect the numerical behavior of different operator nodes under the sample data input in the current inference batch, providing a quantitative basis for subsequent accuracy improvement and deterioration determination. Here, sample data refers to the data actually input into the model during the current inference process, such as a single text, a single image, or a batch of data.

[0055] 103-2. Calculate the computational behavior information of the operator nodes to obtain computational features.

[0056] In this step, by analyzing the computational logic and execution records of the operator nodes, information characterizing their computational load and execution efficiency can be extracted to obtain computational features. The computational behavior information includes at least the operator computational load, node execution latency, cumulative path length, and the number of times the node is executed.

[0057] Operator computational load refers to the total number of arithmetic operations required for an operator node to perform one forward computation, usually measured in floating-point operations (FLOPs) or cumulative multiply-accumulate operations (MACs). Computational load reflects the computational intensity of the operator: operators with higher loads (such as large matrix multiplication and deep convolution) have a larger proportion of computation in their execution time, and the performance gains from lower precision acceleration are more significant; conversely, operators with low computational loads (such as element-wise Add and ReLU) have their execution time more dominated by memory access or scheduling overhead, and the acceleration effect from simply reducing computational precision is limited. By collecting operator computational load data, a quantitative basis can be provided for subsequently determining "which operators are suitable for precision reduction to improve performance."

[0058] Node execution latency refers to the actual elapsed time (usually measured in microseconds or milliseconds) experienced by an operator node from receiving input data to generating output data. Unlike computational load, execution latency is a measured value determined by multiple factors, including hardware platform, current precision configuration, and data transfer efficiency, directly reflecting the operator's performance in the current operating environment. By collecting node execution latency data, performance bottleneck nodes (i.e., "hot spots") in the computation graph can be identified, and the impact of precision adjustments (such as reducing from FP32 to FP16) on actual execution speed can be evaluated.

[0059] The accumulation path length refers to the number of elements or the size of the reduction dimension involved in the accumulation operation within or across operator nodes. For reduction operators (such as ReduceSum), the accumulation path length is the number of elements involved in the summation; for linear operators (such as MatMul), the accumulation path length is the length of the inner product dimension (shrinkage dimension), representing the depth of the multiply-accumulate chain. The accumulation path length directly determines the degree of accumulation of low-precision accumulation errors: the longer the path, the more significant the accumulation of rounding errors introduced by multiple low-precision additions, and the greater the deviation of the final output from the true value. By collecting the accumulation path length, a key basis can be provided for configuring accumulation precision—nodes with long accumulation paths should be preferentially assigned to high-precision accumulation (such as FP32) to avoid error accumulation.

[0060] Node execution count refers to the total number of times an operator node is actually invoked within a single inference process or statistical window. In models involving control flow, loops, or dynamic sequence lengths, the same operator node may be executed multiple times (e.g., the loop body in a recurrent neural network, or the token generation step in autoregressive decoding). Node execution count amplifies the overhead and error of a single execution: a node with low single-execution latency but extremely high execution count may account for a significant proportion of the total inference time; similarly, a node with small single-execution accuracy error but extremely high execution count can have a significant cumulative error effect. By collecting node execution counts, high-frequency execution nodes can be identified and given higher weight in accuracy allocation.

[0061] 103-3. Collect the execution environment information of the target execution backend where the operator node is located to obtain hardware status characteristics.

[0062] In this step, real-time status data of the current execution environment can be obtained from the target inference engine or hardware driver interface to obtain hardware status characteristics. Among them, the execution environment information includes at least the computing unit utilization, memory bandwidth utilization, on-chip cache hit rate (or on-chip cache access pressure), data movement overhead, and precision conversion overhead.

[0063] Computational unit utilization refers to the proportion of time during inference when hardware computing units (such as CPU cores, GPU / NPU ALUs, matrix computing units, etc.) are in an effective working state, reflecting the busyness of computing resources. Higher utilization indicates more saturated computing resources, and reducing computational precision can alleviate some computational pressure. Conversely, low utilization may indicate that the bottleneck is in storage or bandwidth, and reducing precision will have limited effect on improving overall performance.

[0064] Memory bandwidth utilization refers to the proportion of the actual bandwidth used by the current inference task on the memory system (such as DDR, HBM) relative to the peak bandwidth. Mixed-precision computing changes the amount of data read and write (lower precision reduces the amount of data), thus affecting bandwidth utilization. Under high bandwidth utilization, using a lower-precision storage format can effectively alleviate bandwidth pressure.

[0065] On-chip cache hit rate (or on-chip cache access pressure) refers to the percentage of data access requests that are directly hit in the on-chip cache (such as L1 / L2 cache, NPU SRAM). Access pressure refers to the degree of cache occupancy or access conflicts. A low hit rate or high access pressure indicates low data reuse or insufficient cache capacity. In this case, adjusting the precision strategy (such as increasing the precision of some operators to reduce data movement frequency) may improve cache behavior.

[0066] Data movement overhead refers to the additional time and energy consumed in moving data from one end of the storage hierarchy to the other (such as loading data from off-chip memory to on-chip cache, or transferring data between the CPU and NPU). This overhead is related to the data volume, bus width, and transmission protocol. During precision reconfiguration, the additional overhead caused by data rearrangement or redundant movement due to precision switching needs to be evaluated.

[0067] Precision conversion overhead refers to the additional computational cost and latency introduced when performing conversion operations between different data types (such as FP32→FP16, INT8→FP32). This overhead depends on the amount of data being converted, whether the hardware supports dedicated conversion instructions, and where the conversion occurs.

[0068] The focus of data collection varies depending on the inference backend: for the NPU backend, it may also include operator kernel usage, on-chip cache access pressure, and execution unit utilization for different data types; for the ggml / llama.cpp backend, it may also include thread usage, tensor cache usage, execution time for different tensor types, and data movement overhead between CPU / GPU / NPU backends.

[0069] Hardware status characteristics reflect the current hardware resource load and data transfer efficiency, providing environmental feedback for adaptively adjusting precision allocation strategies under different operating environments. For example, under high bandwidth pressure, storage precision can be reduced first, or computational precision can be increased when computing units are idle to improve numerical stability.

[0070] 103-4. The data features, computational features and hardware status features are fused and encoded to obtain the multidimensional status information of the operator node.

[0071] In this step, the three types of features collected in the previous steps are integrated and encoded to construct the multidimensional state information corresponding to each operator node. Specifically, for each operator node, its data features, computational features, and hardware state features can be combined into a state vector according to preset encoding rules (such as normalization, vectorization, or embedding representation). This state vector is the multidimensional state information of the node.

[0072] In one optional implementation, runtime state information can be maintained using a sliding window approach: the sliding window records tensor range, node time consumption, hardware utilization, and abnormal value information in the most recent inference processes. The current multidimensional state information is generated by statistical values ​​(such as mean, maximum value, and number of anomalies) within the sliding window, thereby reflecting the dynamic trend of recent inference processes.

[0073] In another alternative implementation, some state information can come from offline profiling results (such as the numerical distribution under typical input), and some state information can come from online sampling statistics. The combination of the two can improve the accuracy and real-time performance of the state information.

[0074] 104. Based on the precision-aware computation graph, multi-dimensional state information, and preset constraint information, the precision of operator nodes and node chains in the computation graph is evaluated and the constraints are determined to generate a precision allocation strategy.

[0075] The precision allocation strategy includes configuring computational precision, accumulation precision, and storage precision for each operator node. Computational precision refers to the data type of computation used by the operator node when performing internal operations; accumulation precision refers to the data type of accumulation used by the operator node when generating intermediate results through reduction or multiply-add operations; and storage precision refers to the data type of storage used by the operator node when caching data.

[0076] In this embodiment, the generation process of the precision allocation strategy mainly includes three parallel constraint determination processes: operator-level constraint determination, node chain-level constraint determination, and hardware state constraint determination.

[0077] 104-1. During the operator-level constraint determination process, the operator type of the operator node can be identified from the precision-aware computation graph, and the numerical behavior threshold corresponding to the operator type can be detected from the preset constraint information. For each operator node, the data features and computation features in the multidimensional state information of the operator node are compared with the numerical behavior threshold to obtain the operator-level precision constraint result.

[0078] This operator-level constraint determination process aims to independently determine the preliminary precision constraints of each operator node based on its static semantic attributes and dynamic runtime state, combined with preset numerical behavior thresholds. Specifically, the process includes: First, the precision-aware computation graph is traversed to identify the operator type of each operator node (such as exponential operations, reduction operations, linear operations, element-wise operations, etc.), and the numerical behavior thresholds corresponding to the operator type are detected from the preset constraint information. These thresholds can be safety boundary values ​​set in advance through offline analysis or experience, such as the overflow threshold for exponential operations, the upper limit of error tolerance for accumulation path length, and the loss tolerance ratio for magnitude ratios.

[0079] Secondly, for each operator node, data features (such as the range of input tensor values, the proportion of outliers, and the magnitude ratio) and computational features (such as the cumulative path length, computational load, and node execution latency) are extracted from the multidimensional state information. These feature values, which are actually collected or statistically obtained, are then compared with the corresponding numerical behavior thresholds in the preset constraint information.

[0080] Finally, based on the comparison results, operator-level precision constraint results are generated, that is, the recommended precision level (such as the specific data type of computational precision, cumulative precision, and storage precision) that the operator node should adopt in the current state is determined, and whether there are numerical risks or performance optimization space is marked.

[0081] For example, consider exponential operators (such as Softmax): These operators involve exponential operations and normalized division, making them highly sensitive to the range of input values. When the input tensor range is too large, the low-precision format lacks sufficient significant bits, easily leading to Inf overflow or underflow in exponential operations, thus distorting the normalized denominator. Therefore, in operator-level determination, data features such as the maximum, minimum, and dynamic range of the input tensor of the Softmax node can be extracted and compared with a preset exponential overflow threshold (such as the safe range of input values ​​in FP16). If the input range exceeds the threshold, the calculation precision of the node is constrained to high precision (such as FP32), and type conversion protection can be inserted at its entry point if necessary.

[0082] For reduction operators (such as ReduceSum): These operators involve accumulating multiple data points along a specific dimension, and the accumulation path length directly determines the degree of accumulation of low-precision rounding errors. During the determination, the accumulation path length (i.e., the number of elements in the reduction dimension) and the input tensor distribution characteristics (such as variance) of the node can be extracted and compared with a preset accumulation error threshold. When the accumulation path length exceeds the preset threshold, or the input variance exceeds the allowable range, the accumulation precision is constrained to high precision (such as FP32) to control the impact of error accumulation on subsequent statistical calculations.

[0083] For linear computation operators (such as MatMul): These operators typically have high computational density and are the main source of inference time consumption. When making a decision, the range of the input tensor, the length of the inner product dimension (accumulation path length), and the data types supported by the hardware can be comprehensively considered. Provided that the input range meets safety constraints and the accumulation stability meets the requirements, a combined strategy of "low-precision computation + high-precision accumulation" can be adopted: that is, the computation input uses low-precision formats such as FP16, BF16, or INT8, while the intermediate accumulation process uses FP32 or higher precision. This configuration can significantly reduce computational overhead while ensuring numerical stability.

[0084] For element-wise operators (such as Add): If the two input tensors of this type of operator have a significant difference in magnitude, the smaller magnitude input information may be masked by the larger magnitude input under low precision. When determining this, the magnitude ratio of the two input tensors can be extracted as a key data feature and compared with a preset magnitude ratio threshold. When the magnitude ratio is within a safe range (i.e., the two input magnitudes are close), low-precision element-wise operations can be used; when the magnitude difference exceeds a preset range (e.g., the magnitudes of the main branch and minor branches in a residual connection are vastly different), the computational precision of that node should be increased, or the overall precision level of the node chain it belongs to should be increased to avoid the loss of small amounts of information.

[0085] Through the above operator-level constraint determination, a preliminary precision constraint suggestion based on its own numerical behavior and computational characteristics can be generated for each operator node in the computation graph, providing a basis for subsequent joint determination with node chain level and hardware state level.

[0086] For example, please refer to Figure 3 , Figure 3 This is a schematic diagram of operator-level precision control provided in an embodiment of this application. For example... Figure 3 As shown, the operator-level precision of the Softmax operator can be determined based on the input range constraint of the Softmax operator in the preset constraint information, resulting in a configuration of FP32 computational precision; the operator-level precision of the MatMul operator can be determined based on the accumulation length constraint of the MatMul operator in the preset constraint information, resulting in a configuration of FP16 / BF16 computational precision and FP32 accumulation precision; the operator-level precision of the ReduceSum operator can be determined based on the accumulation length constraint of the ReduceSum operator in the preset constraint information, resulting in a configuration of FP32 accumulation precision; and the operator-level precision of the Add operator can be determined based on the magnitude ratio constraint of the Add operator in the preset constraint information, resulting in a configuration of FP16 / BF16 computational precision. The precision determination results of each operator node are then summarized to obtain a precision allocation result, which includes the computational precision, accumulation precision, and storage precision configured for each operator node, used for precision reconstruction of the computation graph.

[0087] 104-2. During the node chain-level constraint determination process, multiple node chains, node chain types, and operator nodes contained in the node chains can be identified from the precision-aware computation graph. The chain-level linkage constraint rules corresponding to the node chain type can be detected from the preset constraint information. For each node chain, the chain-level precision constraint results are obtained based on the connection relationship between operator nodes in the node chain, the multi-dimensional state information of operator nodes, and the chain-level linkage constraint rules.

[0088] In the node chain-level constraint determination process, multiple node chains, their node chain types, and the operator nodes contained in each node chain are first identified from the precision-aware computation graph. The identification of node chains can be based on the "node chain position identifier" attribute of the operator nodes, which was constructed in step 102 and is used to mark the chain type to which the node belongs and its position within the chain. Node chain types include, but are not limited to, attention node chains, reduction node chains, linear transformation node chains, and quantization node chains. Simultaneously, chain-level linkage constraint rules corresponding to the current node chain type are detected from the preset constraint information. These rules define the linkage relationships or consistency requirements that operator nodes within the same node chain should follow in terms of precision configuration.

[0089] For each identified node chain, a comprehensive judgment is made based on the connection relationships between operator nodes in the chain (i.e., data dependency direction), the multi-dimensional state information of each operator node (including data characteristics, computational characteristics, and hardware state characteristics), and the aforementioned chain-level linkage constraint rules. Specifically, it analyzes whether the precision switching of adjacent nodes within the chain will lead to numerical risks or performance losses, determines whether there are precision-sensitive "critical nodes" (such as exponential operations and reduction operations) within the chain, and determines how the precision of other nodes within the chain should be coordinated according to the linkage rules. For example, if the chain-level rule requires that "the nodes before and after the critical node must maintain the same computational precision as it," then even if an adjacent node itself is not precision-sensitive, its precision needs to be increased to match the critical node, thereby avoiding insertion type conversion or reducing conversion overhead.

[0090] Finally, chain-level precision constraint results are generated. These results may adjust or supplement the preliminary precision suggestions obtained in the operator-level constraint determination, ensuring that the entire node chain reduces unnecessary precision switching while satisfying numerical stability.

[0091] For example, regarding attention node chains: such chains typically include nodes for query-key matrix multiplication, scaling, attention weight normalization (e.g., Softmax), and value-weight matrix multiplication. The chain-level linkage constraint rule can be set as follows: apply precision linkage to nodes before and after the Softmax node to keep the input value range and output distribution of Softmax within a controllable range. Specifically, when multidimensional state information indicates a large dynamic range of the Softmax input tensor, not only does the Softmax node itself need to be configured for high-precision computation, but the output precision of its direct predecessor node (e.g., the Scale node) also needs to match it (e.g., both using FP32) to avoid abnormally amplified input range due to low-precision quantization at the predecessor node; simultaneously, if the successor node of Softmax (e.g., matrix multiplication with V) receives FP32 input, its computational precision also needs to be correspondingly improved. Through this linkage constraint, the high-precision region is limited to the smallest subgraph containing Softmax, ensuring numerical stability while avoiding performance loss caused by indiscriminate high precision across the entire chain.

[0092] For reduction node chains: These chains include nodes performing operations such as reduction summation, mean calculation, variance calculation, and normalization. Their chain-level linkage constraint rules can be set as follows: apply high-precision accumulation constraints to all nodes within the chain involved in accumulation or statistical calculations. For example, when the accumulation path length of the ReduceSum node exceeds a threshold, not only should this node use FP32 accumulation, but its predecessor nodes providing the accumulation data (such as tensor deformation or element-wise operation nodes) should also maintain high output precision to prevent the input data from being truncated due to low precision, thus amplifying subsequent accumulation errors. Similarly, the intermediate results of the mean and variance calculation nodes need to maintain high precision to ensure the normalization effect of the Normalize node. Through chain-level linkage, the numerical precision of the entire reduction operation chain is ensured.

[0093] For linear transformation node chains: These chains include nodes for matrix multiplication, addition, multiplication, and residual connections. The chain-level linkage constraint rules can be set as follows: based on the connection relationships and data characteristics of nodes within the chain, the precision of consecutive low-sensitivity nodes is unified to reduce data type switching boundaries. For example, if the MatMul node outputs FP16, and the two input magnitudes of the subsequent Add node are close (data characteristics show the magnitude ratio is within a safe range), then the Add node can also be configured for FP16 computation, thereby eliminating the precision switching boundary between MatMul and Add. If a node within the chain requires high precision (such as certain activation functions), necessary type conversions are inserted before and after it, but the majority of nodes within the chain are kept to the same low precision to achieve performance optimization.

[0094] For quantization node chains: This type of node chain includes nodes such as quantization operators, intermediate computation operators, and dequantization operators. Its chain-level linkage constraint rules can be set as follows: based on the quantization parameters and the data type relationships between nodes, determine whether to preserve low-precision paths or restore the precision of critical nodes. For example, when input data is converted to INT8 by a quantization operator, if subsequent computation nodes (such as convolution or matrix multiplication) support INT8 acceleration, then the INT8 computation path should be preserved as much as possible; however, if multidimensional state information indicates that a certain computation node is sensitive to accumulation error (e.g., the accumulation path is long), then a dequantization operation can be inserted before that node to restore FP16 / FP32 computation, and then quantized back to INT8. Through chain-level linkage, a balance between precision and performance is achieved in the quantization node chain.

[0095] Therefore, by using the above node chain-level constraint determination, the precision dependencies between operators can be captured at the graph structure level, generating more global and reasonable precision constraint results than single-node determination.

[0096] 104-3. During the hardware state constraint determination process, the hardware state features in the multidimensional state information of the operator node can be compared with the hardware performance constraint rules in the preset constraint information to obtain the hardware-level precision constraint results.

[0097] In the process of determining hardware state constraints, hardware state features are mainly extracted from the multi-dimensional state information of operator nodes. At the same time, performance constraint rules related to hardware state are obtained from the preset constraint information. These rules define the allowable or recommended precision adjustment strategies under different hardware load conditions, such as bandwidth occupancy threshold, computing unit utilization threshold, and comparison criteria between conversion overhead and benefits.

[0098] For each operator node or the global execution environment, hardware state characteristics are compared with performance constraint rules. Specifically, it is determined whether the current hardware state meets the triggering condition of a certain rule. If it does, a corresponding hardware-level precision constraint result is generated. This result may suggest adjusting the computational precision, accumulation precision, or storage precision of a specific node, or implementing precision consistency processing for adjacent nodes to reduce data transfer volume, reduce conversion overhead, or balance the load. During the comparison process, if there is a conflict between hardware state characteristics and node chain-level or operator-level numerical stability constraints, the numerical stability constraints take precedence to ensure that precision adjustments do not lead to numerical anomalies.

[0099] For example, regarding storage precision optimization under high bandwidth usage: when hardware status characteristics show that memory bandwidth utilization exceeds a preset threshold (e.g., consistently above 80%), it indicates that the current inference process is limited by a storage bandwidth bottleneck. In this case, hardware performance constraint rules can trigger a storage precision degradation strategy, which prioritizes reducing the storage precision of low-sensitivity nodes in the computation graph (e.g., from FP32 to FP16 or INT8) to reduce the total amount of tensor data moved between storage levels, thereby alleviating bandwidth pressure. However, before degradation, the numerical sensitivity of the node must be verified; if it participates in reduction or exponential operations, the original precision is maintained.

[0100] For adjusting computational precision when computational unit utilization is insufficient: When the computational unit utilization is lower than a preset target value (e.g., below 50%), it indicates that computational resources are not being fully utilized, and there may be room for further reduction in computational precision. In this case, the rule can instruct that computational precision be reduced (e.g., from FP32 to FP16) for operators with high computational load (such as large-size MatMul, convolution) to explore whether reducing the computational load can shorten the single-step latency. Since the computational units were originally idle, reducing precision will not trigger resource contention. However, if the numerical stability does not meet the constraints after reducing precision, it will revert to the original precision.

[0101] Regarding the evaluation of data type conversion overhead and benefits: When the precision conversion overhead in hardware state characteristics (such as the additional latency caused by frequent type conversions) exceeds the expected performance benefits of low-precision computation, the rule triggers precision consistency processing, that is, unifying the precision of adjacent nodes. For example, if a conversion operation needs to be inserted between two adjacent nodes due to different precision, and the calculated conversion overhead is greater than the computation time saved by reducing one of the nodes to a lower precision, then the two nodes are forced to be configured with the same precision, eliminating the conversion boundary and thus reducing the total execution overhead.

[0102] Arbitration for numerical stability and performance constraints: In the determination of hardware state constraints, if the accuracy degradation suggested by the performance optimization rules (such as reducing the computational accuracy of a certain node) conflicts with the numerical stability constraints at the operator level or node chain level (such as the node being Softmax and the input range exceeding the threshold), the hardware-level constraint result will obey the numerical stability constraint, abandon the degradation, and even suggest improving the accuracy in reverse, so as to ensure that the mixed accuracy allocation always takes the numerical correctness of the model output as the bottom line.

[0103] By using the above hardware state constraint determination, real-time hardware load can be incorporated into the accuracy decision closed loop, so that the generated accuracy allocation strategy can not only adapt to the model structure, but also dynamically adapt to the resource status of the execution environment, thereby maximizing the model inference efficiency.

[0104] 104-4. The operator-level precision constraint results, chain-level precision constraint results, and hardware-level precision constraint results are fused to obtain the precision allocation strategy.

[0105] For example, the accumulation precision can be determined based on the operator-level precision constraint results and the chain-level precision constraint results; the computational precision can be determined based on the operator-level precision constraint results, the chain-level precision constraint results, and the hardware-level precision constraint results; and the storage precision can be determined based on the chain-level precision constraint results and the hardware-level precision constraint results.

[0106] Among these, the accumulation precision directly affects the error accumulation in operations such as reduction and inner product, and has the most critical impact on numerical stability. Therefore, it is mainly determined by the operator-level and chain-level results that reflect the characteristics of numerical behavior, rather than being directly affected by hardware performance. During fusion, the higher precision suggested by the operator-level and chain-level can be taken as the accumulation precision of that node. For example, if the operator-level suggestion is FP32 accumulation, FP32 should be used even if the chain-level suggestion is not explicitly required; if the chain-level suggestion requires a node to use FP32 accumulation in conjunction with a key node, the chain-level requirement must be followed even if its own accumulation path is short.

[0107] Determining computational precision requires a comprehensive balance between numerical stability (operator-level and chain-level) and hardware execution efficiency (hardware-level). It is a core aspect of maximizing performance while ensuring correctness. During fusion, the "minimum safe precision" determined at the operator and chain levels can be used as a baseline. If a lower precision suggested by the hardware level does not exceed this baseline (i.e., numerical stability is still satisfied), the hardware-level suggestion is adopted to improve performance. If the hardware-level suggestion conflicts with the baseline, the baseline prevails. For example, for a MatMul operator, the operator level determines its input range is safe and supports FP16, the chain level determines its chain can be uniformly set to FP16, and the hardware level further suggests trying INT8 (because the computation unit is idle and supports INT8 acceleration). Therefore, the final computational precision can be set to INT8. However, if the hardware level suggests INT4 while the operator level determines INT4 will cause overflow, then INT8 or FP16 is maintained.

[0108] Storage precision primarily affects data transfer volume and precision switching boundaries, with a relatively small impact on direct numerical computation errors (because storage format typically only determines the representation range during read / write operations, converting it to computational precision during computation). Therefore, it is mainly determined by the chain level (boundary optimization) and hardware level (bandwidth / cache pressure), with operator-level numerical characteristics having a relatively weak impact. During fusion, priority should be given to meeting chain-level boundary consistency requirements (i.e., adjacent nodes should have similar storage precision as much as possible). Based on this, the specific precision value can be adjusted according to hardware-level feedback. For example, for a certain element-wise operation node, the chain level requires it to maintain the same storage precision as its predecessor (e.g., FP16). Due to high bandwidth pressure at the hardware level, it is recommended to further reduce it to INT8. However, reducing it to INT8 would increase the boundary conversion overhead with the predecessor (because the predecessor can only output FP16), so FP16 storage should be maintained to meet the chain-level goal of reducing boundaries.

[0109] Thus, through the above fusion and arbitration, a triplet configuration containing computational precision, cumulative precision, and storage precision can be generated for each operator node in the computation graph, and the configuration set of all nodes constitutes the precision allocation strategy.

[0110] 105. Based on the precision allocation strategy, the precision-aware computation graph is reconstructed to generate the target execution computation graph, and the inference computation of the neural network model to be executed is performed based on the target execution computation graph.

[0111] Specifically, the process of reconstructing the precision of the computation graph based on the precision allocation strategy may include: 105-1. Based on the precision allocation strategy, configure the operator precision for each operator node in the precision-aware computation graph, and write the computation precision, accumulation precision and storage precision corresponding to each operator node into the attributes of the operator node.

[0112] For example, each operator node in the precision-aware computation graph can be traversed, and the precision triple corresponding to that node (i.e., the final result obtained from the fusion in step 104-4) can be queried from the precision allocation strategy. This triple is then written into the internal attribute fields of the operator node: the computation precision attribute determines the data type used when the node performs core operations (e.g., FP16, INT8); the accumulation precision attribute determines the data type of the intermediate accumulator in operations such as reduction and inner product (e.g., FP32); and the storage precision attribute determines the storage format of the node's output tensor in memory (e.g., FP16, INT8). After writing, each node carries a clear precision label, providing a static basis for subsequent reconstruction.

[0113] 105-2. Adjust the precision of adjacent operator nodes with the same node type in the node chain to obtain the intermediate precision reconstruction computation graph.

[0114] Among them, the node chain precision consistency adjustment is used to optimize the precision switching relationship between consecutive nodes within the same node chain. Its core processing principles include: on the one hand, maintaining a uniform precision level for low-sensitivity operator nodes within the same node chain to avoid introducing redundant data type conversion boundaries due to unnecessary precision differences in individual nodes; on the other hand, converging and limiting the high-precision computation region to the minimum subgraph formed by numerically sensitive nodes such as Softmax, ReduceSum, and LayerNorm and their necessary adjacent nodes, thereby maximizing the coverage of low-precision computation while ensuring numerical stability.

[0115] Specifically, each node chain identified in the precision-aware computation graph can be traversed. For adjacent operator nodes of the same type within a chain (e.g., consecutive element-wise addition nodes or multiple matrix multiplication nodes), the computational precision and storage precision configured in step 105-1 are extracted. If there are inconsistencies in precision among these adjacent nodes of the same type, consistency adjustments are made according to the above processing principles: Precision unification for low-sensitivity nodes: If all adjacent nodes of the same type in a group are low-sensitivity nodes (i.e., non-numerical sensitive nodes, such as ordinary element-wise operations, linear transformations on non-critical paths, etc.), then their precision is unified to the low-precision format used by most nodes in the chain (such as unified to FP16 or INT8) to eliminate the type conversion overhead between adjacent nodes and achieve precision consistency in the low-sensitivity region within the chain.

[0116] Convergence of high-precision regions and matching of adjacent nodes: If the adjacent nodes of the same type in this group are near numerically sensitive nodes in the chain (such as Softmax, ReduceSum, LayerNorm, etc.), then according to the chain-level linkage constraints determined in step 104-2, the precision of the necessary adjacent nodes is increased to a high precision (such as FP32) that matches the sensitive nodes, forming a controlled high-precision subgraph; while the remaining non-adjacent low-sensitivity nodes in the chain remain low-precision to avoid disorderly diffusion of high-precision regions.

[0117] After the above adjustments, an intermediate precision reconstruction computation graph is generated. At this point, the precision distribution within the node chain has been optimized, and redundant precision switching boundaries have been significantly reduced, laying the foundation for subsequent global conversion overhead optimization.

[0118] 105-3. Calculate the data type conversion overhead of the intermediate precision reconstruction computation graph, and adjust the intermediate precision reconstruction computation graph based on the data type conversion overhead to obtain the target execution computation graph. The data type conversion overhead refers to the overhead incurred by converting the data types between adjacent operator nodes with different precisions.

[0119] Despite the 10⁵-2 consistency adjustment, the computational graph may still contain necessary transformations due to precision differences between node chains or different types of nodes. This sub-step further optimizes the graph structure by quantifying the performance cost of these transformations. This process may include: Identify the connection edges between adjacent operator nodes with different precisions from the intermediate precision reconstruction computation graph to obtain the precision switching edge set; calculate the switching cost of each precision switching edge in the precision switching edge set to obtain the data type conversion cost of the intermediate precision reconstruction computation graph; with the conversion number and conversion position as optimization objectives, reduce the size of the precision switching edge set or reduce the data type conversion cost through local merging and position rearrangement to obtain the target execution computation graph.

[0120] First, identify precision switching boundaries (connection edge identification). Traverse the topological connections between operator nodes in the intermediate precision reconstructed computation graph, identifying the connection edges between adjacent operator nodes with different precisions, thus obtaining a set of precision switching edges. Each connection edge represents a potential data type conversion requirement; this process corresponds to the connection edge identification step in data type conversion boundary processing, clarifying the precision switching locations that need to be addressed.

[0121] Secondly, the data type conversion overhead is calculated. For each precision switching edge in the precision switching edge set, the switching overhead (including additional computation and latency) is calculated based on the source node's output precision, the target node's input precision, the size of the tensor to be transmitted, and the data type conversion instruction time of the target hardware backend. The overhead of all switching edges is summed to obtain the total data type conversion overhead of the intermediate precision reconstruction computation graph. This overhead quantifies the additional performance cost caused by precision inconsistencies in the current graph structure, providing a quantitative basis for subsequent determination of conversion locations and optimization.

[0122] Finally, with the number of transformations and their positions as optimization objectives, the size of the precision switching edge set or the overhead of data type conversion is reduced through local merging and position rearrangement to obtain the target execution computation graph. This optimization process can include the following three optimization strategies: (1) Local merging (for consecutive low-sensitivity nodes): For consecutive low-sensitivity nodes in the intermediate precision reconstruction computation graph, under the premise of satisfying the numerical stability constraint (i.e., the precision constraint condition determined in step 104), the precision of these consecutive low-sensitivity nodes is merged into the same precision for execution, thereby eliminating the precision switching edges between them. For example, if two adjacent element-wise operation nodes are both determined to be low-sensitivity and allow FP16 computation, they are unified as FP16, removing the type conversion boundaries that may originally exist between them and reducing the number of conversions.

[0123] (2) Necessary Transformation Insertion and Position Determination (for nodes requiring high-precision calculations): For nodes requiring high-precision calculations (such as numerically sensitive nodes like Softmax, ReduceSum, LayerNorm), based on the aforementioned calculation conversion overhead, necessary data type conversion nodes are inserted at their entry or exit positions. Specifically, if the predecessor node is low-precision while the current sensitive node requires high precision, an up-precision conversion (e.g., FP16→FP32) is inserted after the predecessor's output and before the sensitive node's entry; if the sensitive node outputs high precision while the successor node can accept low precision, a down-precision conversion is inserted after the sensitive node's exit. The determination of the conversion position needs to comprehensively consider the conversion overhead and computational benefits, and the conversion operation should be placed at the boundary where the data volume is small or the computational density is low, in order to minimize the impact on the critical path.

[0124] (3) Redundant conversion merging and position reordering (for node chains with multiple consecutive conversions): For node chains with multiple consecutive conversions (e.g., node A outputs FP16, node B requires FP32, and node C also requires FP16, resulting in two consecutive conversions A→B and B→C), analyze the conversion path and merge or remove redundant conversions. For example, if the computational characteristics of node B allow execution under FP16 (or can be downgraded according to constraints), then A, B, and C are directly unified to FP16, completely eliminating the two conversions; if B must maintain FP32, then it is possible to evaluate whether to reorder the conversion position, such as moving the A→B conversion to an earlier node or postponing it to after C, to reduce memory access overhead and scheduling overhead. By reordering the position, the conversion operation is moved to the execution position with the least impact on the overall execution latency, or it is merged with adjacent computing nodes for execution.

[0125] After the above local merging, necessary transformation insertion, and redundant transformation processing, the scale of the precision switching edge of the computation graph is minimized, and the overhead of the remaining transformation operations is controlled at a low level. This computation graph serves as the target execution computation graph for subsequent hardware backend mapping and inference execution.

[0126] 105-4. Map the target execution computation graph to the target execution backend to perform inference computation of the neural network model to be executed.

[0127] The target execution backend refers to specific hardware acceleration devices (such as NPUs, GPUs, CPUs, etc.) and their corresponding inference engines or compilers. The mapping process includes: translating each operator node in the computation graph and its precision attributes into kernel launches or operator implementations recognizable by the backend, based on the instruction sets and data types supported by the backend; allocating corresponding memory buffers for tensors of different precisions; and scheduling the execution order. For example, for an NPU backend, FP16 matrix multiplication might be mapped to NPU-specific matrix computation unit instructions, and FP32 accumulation might be mapped to a high-precision accumulation mode.

[0128] After mapping is complete, load the weight data of the neural network model to be executed (which has been quantized or converted according to storage precision requirements), input the inference data, execute each operator in sequence according to the topology defined by the target execution computation graph, complete the forward inference, and output the final result.

[0129] In one implementation, the target execution computation graph can be continuously updated within the same inference session, or the target execution computation graph can be updated by batch, by time window, or by long sequence inference phase.

[0130] After performing inference computation on the neural network model to be executed based on the target execution computation graph, the following steps are also included: The system collects output and performance data generated during the execution of the target computation graph; compares the output data with preset numerical anomaly conditions and the performance data with preset performance optimization conditions to obtain comparison results; updates the precision allocation strategy based on the comparison results to obtain the updated precision allocation strategy, and reconstructs the computation graph based on the updated precision allocation strategy.

[0131] The output data is used to characterize the numerical state information of the output tensor. In one optional implementation, the numerical characteristics of the output tensor include, but are not limited to: the numerical range of the output tensor (such as maximum value, minimum value, and dynamic range), the proportion of outliers (the percentage of tensor elements exceeding the preset safe numerical range), the NaN / Inf detection results (whether non-numerical or infinite values ​​appear), and stability indicators (such as the variance or distribution offset of the output tensor between consecutive inference batches). These characteristics directly reflect the numerical correctness of the model inference execution process under the current accuracy configuration (such as a batch, within a preset time window, or offline trial run).

[0132] Performance data is used to characterize the performance status information of inference execution. In one optional implementation, performance metrics include, but are not limited to: single-step inference latency, node execution time of each operator node, overall throughput (such as the number of inference requests processed per second or the number of tokens generated), and hardware resource utilization (such as computing unit utilization, memory bandwidth utilization, on-chip cache hit rate, etc.). These metrics quantify the execution efficiency of the current precision configuration on the actual hardware platform.

[0133] Preset numerical anomaly conditions are used to determine whether numerical instability occurs in the current inference process. For example, when the output tensor value range exceeds a preset safety threshold, the proportion of outliers increases, or NaN / Inf is detected, it is determined that the numerical anomaly condition is met.

[0134] Preset performance optimization conditions are used to determine whether there is room for further reduction in accuracy and improvement in performance in the current hardware resources. For example, when the hardware resource utilization (such as the computing unit utilization) is lower than a preset threshold, and all current numerical stability constraints are met (i.e., the output data does not trigger numerical anomalies), it is determined that the performance optimization conditions are met.

[0135] By comparing the output data with preset numerical anomaly conditions and the performance data with preset performance optimization conditions, comparison results are obtained. Based on these results, the precision allocation strategy is updated. Specific update rules may include: Numerical anomaly-driven accuracy improvement: When comparison results show that the output data meets preset numerical anomaly conditions (such as a sharp increase in the dynamic range of a certain layer's output, or the detection of NaN / Inf), the relevant operator nodes or node chains causing the anomaly are located, and their computational accuracy and / or accumulation accuracy are improved. For example, the Softmax node originally configured as FP16 is upgraded to FP32 computation, or the accumulation accuracy of the relevant reduction node chains is uniformly upgraded to FP32 to restore numerical stability. This process strictly follows the principle of prioritizing numerical stability, and any performance optimization must not violate this principle.

[0136] Performance margin-driven precision reduction: When comparison results show that performance data meets preset performance optimization conditions (such as persistently low computing unit utilization and normal numerical status), the computational precision or storage precision of low-sensitivity operators in the computation graph can be further reduced while ensuring numerical stability. For example, some element-wise operation nodes can be reduced from FP16 to INT8, or the storage precision of nodes on non-critical paths can be reduced to further reduce computational load or data transfer load and tap the potential of hardware performance.

[0137] Thus, after obtaining the updated precision allocation strategy, we can return to the precision reconstruction step (i.e., step 105) based on the updated precision allocation strategy, reconstruct the precision of the computation graph, generate a new target execution computation graph, and use it for subsequent inference computation iterations.

[0138] In one optional implementation, the feedback update process can be executed according to a time window (e.g., performing global monitoring and policy updates at fixed intervals) or according to inference batches (e.g., triggering a feedback comparison and update after each or several inference batches are completed). For specific application scenarios, dedicated triggering and adaptation mechanisms can also be set up. In long sequence inference scenarios: As the sequence length increases, the KV Cache is updated, or the attention score distribution changes, the model's numerical dynamic range and computational load will change significantly. Therefore, when the sequence length exceeds a preset node, the number of KV Cache reads and writes suddenly increases, or the attention score distribution shifts, a precision strategy re-evaluation can be proactively triggered to adjust the precision configuration of the attention node chain and other related structures in a timely manner.

[0139] Multi-task concurrency scenarios: When the system runs multiple neural network models or processes multiple concurrent tasks simultaneously, the accuracy strategies for different models or tasks can be maintained and updated independently based on the overall system load (such as comprehensive hardware resource utilization). That is, each task has an independent accuracy allocation strategy instance and feedback monitoring channel, ensuring that each task can maintain its own numerical stability while sharing hardware resources, and can dynamically adjust accuracy as needed to adapt to changes in the overall system load.

[0140] Through the aforementioned feedback update mechanism, the hybrid precision adaptive allocation method of operators in this application can achieve dynamic optimization at runtime, effectively address the problems of model input changes, hardware state fluctuations, and numerical drift in long sequence inference, and continuously improve inference efficiency and stability.

[0141] For example, refer to Figure 4 , Figure 4 This is a schematic diagram of node chain-level precision control and feedback update provided in an embodiment of this application. For example... Figure 4 As shown, in the node chain-level precision control section, it is assumed that there are attention node chains and reduction node chains. The attention node chain contains MatMul(Q,K^T) operator nodes, Softmax operator nodes, and MatMul(·,V) operator nodes connected in sequence; the reduction node chain contains ReduceSum operator nodes and Normalize operator nodes connected in sequence.

[0142] Node links are controlled by precision consistency constraints and error propagation constraints. Precision consistency constraints ensure consistent precision configuration across operator nodes within the same node chain; error propagation constraints limit the propagation of errors within the node chain, such as preventing numerical overflow or rounding errors from spreading along attention or reduction node chains. Specifically, in the node chain-level constraint determination (step 104 above), precision linkage rules are implemented for attention and reduction node chains, converging high-precision regions within the range of numerically sensitive nodes and their necessary adjacent nodes, preventing exponential overflow, cumulative rounding, and other errors from spreading along the node chain; and during precision reconstruction (step 105 above), node chain precision consistency processing ensures uniform precision for low-sensitivity nodes, further blocking error propagation paths introduced by precision switching.

[0143] In the closed-loop execution feedback and strategy update part, based on the running data generated by inference execution, output value monitoring and performance index monitoring are performed, and the precision allocation strategy is dynamically adjusted accordingly. Then, the updated strategy is fed back to the node chain-level precision control part to adaptively update the precision configuration of attention node chain and reduction node chain, thereby realizing closed-loop optimization of precision control.

[0144] In one optional implementation, the operator precision adaptive allocation method provided in this application allows for flexible configuration of the precision control granularity as at least one of the following: operator-level, node chain-level, hierarchical, tensor-level, or batch-level. Different granularities correspond to different precision decision units and control ranges to adapt to diverse model structures and hardware execution environments. The specific meanings and application scenarios of each granularity are as follows: (1) Operator-level granularity: This refers to using a single operator node in the computation graph as the smallest control unit, which is used to independently configure its computational precision, accumulation precision, and storage precision. For example, different precision levels can be set for operators such as Softmax, ReduceSum, MatMul, and Add, so that numerically sensitive operators (such as exponential operations and reduction operations) can obtain high precision guarantees, while computationally intensive, low-sensitivity operators (such as large matrix multiplication) can preferentially use low precision to improve performance. This granularity directly corresponds to the operator-level constraint determination in step 104-1 and is the basis for realizing refined numerical stability control.

[0145] (2) Node chain level granularity: Using the node chain identified in step 102 as the basic unit, linkage precision control is implemented for multiple operator nodes within the same chain. For example, the precision level of nodes within the chain can be uniformly configured for attention node chains, reduction node chains, linear transformation node chains, or quantization node chains, or consistency adjustments can be made according to chain-level constraint rules (such as precision matching before and after key nodes, and uniform precision for low-sensitivity nodes). This granularity can effectively reduce redundant data type conversion boundaries within the chain, converge high-precision regions within the minimum necessary subgraph range, and is compatible with the optimization logic of steps 104-2 and 105-2.

[0146] (3) Layer granularity: Using the macroscopic structural layer of the neural network model as the control unit, a uniform precision strategy is applied to all operator nodes in the entire layer in batches. For example, preset layer precision templates (such as "FP16 is used in all layers except Softmax in the Block") can be directly loaded for Transformer Block, Attention sub-layer or FFN (feedforward network) layer, thereby greatly reducing the complexity of strategy generation and making it suitable for scenarios that are extremely sensitive to inference latency and have a regular model structure.

[0147] (4) Tensor-level granularity: Precision control is refined to the input and output tensor dimensions of operator nodes, that is, different data types are configured for different input tensors, output tensors, or weight tensors of the same operator. For example, for the MatMul operator, its weight tensor can be configured as INT8 while the activation value tensor remains FP16; for the Add operator, different precisions can be configured for the two input tensors according to their magnitude differences. This granularity achieves the finest resource allocation, which can maximize the compression of storage and computational overhead of non-critical data while ensuring the numerical accuracy of critical data paths.

[0148] (5) Batch-level granularity: Dynamic precision adjustment is performed on a batch or time window basis. That is, based on the characteristics of the input data of the current batch (such as sequence length and numerical distribution) or the system load status, a suitable precision allocation strategy is dynamically loaded or generated for different batches. For example, in long sequence inference, when the KV Cache read and write pressure increases as the sequence length increases, the storage precision of non-critical nodes can be automatically reduced for subsequent batches; in multi-task concurrent scenarios, independent precision strategies can be maintained for different task instances of different batches. This granularity is closely integrated with the above feedback update mechanism, enabling precision control to have runtime adaptive capabilities.

[0149] Through the flexible combination of the above multi-granularity controls, this application can achieve an optimal balance between "global performance optimization" and "local numerical stability" based on model complexity, hardware resource availability, and real-time inference requirements. For example, in post-training quantization (PTQ) deployment scenarios, an initial strategy can be quickly generated using hierarchical and operator-level granularity; in dynamic inference scenarios, it switches to batch-level and tensor-level granularity to achieve real-time adaptive adjustment.

[0150] This application reconstructs the computation graph execution process by introducing multi-dimensional state modeling and operator-level and node-chain-level precision allocation mechanisms during neural network inference, resulting in the following overall technical effects in terms of numerical stability, execution efficiency, and resource utilization: (1) Improve the numerical stability of key operators. By applying high-precision calculation or high-precision accumulation constraints to operators such as Softmax, ReduceSum, and LayerNorm, the risks of exponential overflow, normalization distortion, and accumulation error propagation are reduced.

[0151] (2) Reduce overall computational overhead. By configuring operators such as MatMul and Add with lower computational precision under the condition of satisfying constraints, unnecessary high-precision calculations are reduced.

[0152] (3) Reduce data movement and type conversion overhead. By handling node chain precision consistency and adjusting data type conversion boundaries, reduce frequent conversions between different data types such as FP16, FP32, and INT8.

[0153] (4) Improve hardware resource utilization. By combining the utilization of computing units, memory bandwidth usage and data transfer overhead to adjust the precision strategy, the operator precision configuration is matched with the hardware status of the target execution backend.

[0154] (5) Improve the adaptability of the reasoning process. By implementing feedback and policy correction mechanisms, the accuracy policy can be adjusted according to changes in input data distribution, sequence length, hardware load, and output stability.

[0155] To better implement the above methods, this application also provides an operator precision adaptive allocation device based on multi-dimensional state awareness. This operator precision adaptive allocation device based on multi-dimensional state awareness can be integrated into electronic devices, such as servers or terminals. The terminal may include tablet computers, laptops, and / or personal computers.

[0156] For example, such as Figure 5 As shown, the operator precision adaptive allocation device based on multi-dimensional state awareness may include: The acquisition unit 301 is used to acquire the neural network model to be executed and parse the neural network model to be executed to obtain the computation graph corresponding to the neural network model to be executed. The sensing unit 302 is used to construct precision-aware semantic information for the operator nodes in the computation graph and add the precision-aware semantic information to the computation graph to obtain a precision-aware computation graph. The precision-aware semantic information is used to characterize the numerical behavior features of the operator nodes under different precision conditions. The construction unit 303 is used to acquire the data features, computational features and hardware state features generated during the prior execution of the neural network model to be executed, so as to construct the multi-dimensional state information of the operator node; The generation unit 304 is used to perform precision evaluation and constraint determination on the operator nodes and node chains in the computation graph based on the precision-aware computation graph, multi-dimensional state information and preset constraint information, so as to generate a precision allocation strategy. The precision allocation strategy includes the computation precision, accumulation precision and storage precision configured for each operator node. The reconstruction unit 305 is used to reconstruct the precision-aware computation graph based on the precision allocation strategy, generate the target execution computation graph, and perform inference computation of the neural network model to be executed based on the target execution computation graph.

[0157] For example, such as Figure 6 As shown, the operator precision adaptive allocation device based on multi-dimensional state awareness may further include: an update unit 306, used to collect output data and performance data generated during the execution of the target execution computation graph, wherein the output data is used to characterize the numerical state information of the output tensor, and the performance data is used to characterize the performance state information of the inference execution; the output data is compared with preset numerical anomaly conditions, and the performance data is compared with preset performance optimization conditions to obtain comparison results; the precision allocation strategy is updated based on the comparison results to obtain the updated precision allocation strategy, and the computation graph is reconstructed based on the updated precision allocation strategy.

[0158] The specific functions and signal flow relationships of each module correspond one-to-one with the steps described above, and will not be repeated here.

[0159] This application also provides an electronic device, such as... Figure 7 As shown, it illustrates a structural schematic diagram of the electronic device involved in the embodiments of this application, specifically: The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, an input module 404, and a communication module 405. Those skilled in the art will understand that... Figure 7The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein: The processor 401 is the control center of the electronic device, connecting various parts of the device via various interfaces and lines. It executes software programs and / or modules stored in the memory 402, and calls data stored in the memory 402, to perform various functions and process data. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 401.

[0160] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0161] The electronic device also includes a power supply 403 that supplies power to the various components. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 403 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0162] The electronic device may also include an input module 404, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0163] The electronic device may also include a communication module 405. In some embodiments, the communication module 405 may include a wireless module, through which the electronic device can perform short-range wireless transmission, thereby providing users with wireless broadband internet access. For example, the communication module 405 can be used to help users send and receive emails, browse web pages, and access streaming media.

[0164] Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the electronic device loads the executable files corresponding to the processes of one or more computer programs into the memory 402 according to the following instructions, and the processor 401 runs the computer programs stored in the memory 402 to realize the various functions in the above method steps.

[0165] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0166] Therefore, embodiments of this application provide a computer-readable storage medium storing a computer program that can be loaded by a processor to execute steps in any of the multi-dimensional state-aware operator precision adaptive allocation methods provided in embodiments of this application.

[0167] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0168] Since the computer program stored in the computer-readable storage medium can execute the steps in any of the multi-dimensional state-aware operator precision adaptive allocation methods provided in the embodiments of this application, the beneficial effects that any of the multi-dimensional state-aware operator precision adaptive allocation methods provided in the embodiments of this application can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.

[0169] According to one aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various alternative implementations of the multi-dimensional state-aware operator precision adaptive allocation described above.

[0170] The foregoing describes a method and related apparatus for adaptive allocation of operator precision based on multi-dimensional state awareness, which may include an adaptive allocation device for operator precision based on multi-dimensional state awareness, an electronic device, a computer program product, and a computer-readable storage medium. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and its core ideas. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there may be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method for adaptive allocation of operator precision based on multi-dimensional state awareness, characterized in that, include: Obtain the neural network model to be executed, and parse the neural network model to be executed to obtain the computation graph corresponding to the neural network model to be executed; Accuracy-aware semantic information is constructed for the operator nodes in the computation graph, and the accuracy-aware semantic information is added to the computation graph to obtain an accuracy-aware computation graph. The accuracy-aware semantic information is used to characterize the numerical behavior features of the operator nodes under different accuracy conditions. The data features, computational features, and hardware state features generated during the prior execution of the neural network model to be executed are obtained to construct the multidimensional state information of the operator node; Based on the precision-aware computation graph, the multi-dimensional state information, and the preset constraint information, the operator nodes and node chains in the computation graph are evaluated for precision and constrained to generate a precision allocation strategy. The precision allocation strategy includes the computation precision, accumulation precision, and storage precision configured for each operator node. Based on the precision allocation strategy, the precision-aware computation graph is reconstructed to generate a target execution computation graph, and the inference computation of the neural network model to be executed is performed based on the target execution computation graph.

2. The operator precision adaptive allocation method based on multi-dimensional state awareness according to claim 1, characterized in that, The step of acquiring the data features, computational features, and hardware state features generated during the prior execution of the neural network model to be executed, in order to construct the multidimensional state information of the operator node, includes: Collect the tensor numerical distribution information of the operator nodes and the node chain to obtain data features. The tensor numerical distribution information includes at least the maximum value, minimum value, mean, and variance of the input tensor. The computational behavior information of the operator node is calculated to obtain computational characteristics. The computational behavior information includes at least computational load, node execution latency, cumulative path length, and node execution count. Collect the execution environment information of the target execution backend where the operator node is located to obtain hardware status characteristics. The execution environment information includes at least the computing unit utilization rate, memory bandwidth utilization rate, on-chip cache hit rate, data movement overhead and precision conversion overhead. The data features, computational features, and hardware state features are fused and encoded to obtain the multidimensional state information of the operator node.

3. The operator precision adaptive allocation method based on multi-dimensional state awareness according to claim 1, characterized in that, The process of evaluating the accuracy and determining the constraints of operator nodes and node chains in the computation graph based on the accuracy-aware computation graph, the multi-dimensional state information, and the preset constraint information, in order to generate an accuracy allocation strategy, includes: The operator type of the operator node is identified from the precision-aware computation graph, and the numerical behavior threshold corresponding to the operator type is detected from the preset constraint information; For each operator node, the data features and computational features in the multidimensional state information of the operator node are compared with the numerical behavior threshold to obtain the operator-level precision constraint result; Multiple node chains, node chain types, and operator nodes contained in the node chains are identified from the precision-aware computation graph, and chain-level linkage constraint rules corresponding to the node chain types are detected from the preset constraint information. For each node chain, based on the connection relationship between the operator nodes in the node chain, the multidimensional state information of the operator nodes, and the chain-level linkage constraint rules, the chain-level precision constraint result is obtained; The hardware state features in the multidimensional state information of the operator node are compared with the hardware performance constraint rules in the preset constraint information to obtain hardware-level precision constraint results. The operator-level precision constraint results, the chain-level precision constraint results, and the hardware-level precision constraint results are fused to obtain a precision allocation strategy.

4. The operator precision adaptive allocation method based on multi-dimensional state awareness according to claim 3, characterized in that, The step of fusing the operator-level precision constraint results, the chain-level precision constraint results, and the hardware-level precision constraint results to obtain a precision allocation strategy includes: The cumulative precision is determined based on the operator-level precision constraint results and the chain-level precision constraint results. The cumulative precision refers to the data type of the cumulative data used by the operator node when performing reduction or multiply-add operations to generate intermediate results. The computational precision is determined based on the operator-level precision constraint results, the chain-level precision constraint results, and the hardware-level precision constraint results. The computational precision refers to the data type of computation used by the operator node when performing internal operations. The storage precision is determined based on the chain-level precision constraint results and the hardware-level precision constraint results. The storage precision refers to the data type of storage used when the operator node caches data.

5. The operator precision adaptive allocation method based on multi-dimensional state awareness according to claim 1, characterized in that, The step of reconstructing the precision-aware computation graph based on the precision allocation strategy to generate the target execution computation graph includes: According to the precision allocation strategy, the operator precision is configured for each operator node in the precision-aware computation graph, and the computation precision, accumulation precision and storage precision corresponding to each operator node are written into the attributes of the operator node. The precision of adjacent operator nodes with the same node type in the node chain is adjusted to achieve consistency, resulting in an intermediate precision reconstructed computation graph. Calculate the data type conversion overhead of the intermediate precision reconstruction computation graph, and adjust the intermediate precision reconstruction computation graph based on the data type conversion overhead to obtain the target execution computation graph. The data type conversion overhead refers to the overhead generated by converting data types between adjacent operator nodes with different precisions. The inference computation of the neural network model to be executed based on the target execution computation graph includes: The target execution computation graph is mapped to the target execution backend to perform inference computation of the neural network model to be executed.

6. The operator precision adaptive allocation method based on multi-dimensional state awareness according to claim 5, characterized in that, The process of calculating the data type conversion overhead of the intermediate precision reconstruction computation graph and adjusting the intermediate precision reconstruction computation graph based on the data type conversion overhead to obtain the target execution computation graph includes: From the intermediate precision reconstruction computation graph, the connection edges between adjacent operator nodes with different precisions are identified to obtain a precision switching edge set; Calculate the switching cost of each precision switching edge in the precision switching edge set to obtain the data type conversion cost of the intermediate precision reconstruction computation graph; With the number of conversions and the conversion position as optimization objectives, the size of the precision switching edge set or the data type conversion overhead is reduced by local merging and position rearrangement to obtain the target execution computation graph.

7. The operator precision adaptive allocation method based on multi-dimensional state awareness according to claim 1, characterized in that, After performing the inference computation of the neural network model to be executed based on the target execution computation graph, the method further includes: The output data and performance data generated during the execution of the target execution computation graph are collected. The output data is used to characterize the numerical state information of the output tensor, and the performance data is used to characterize the performance state information of the inference execution. The output data is compared with preset numerical anomaly conditions, and the performance data is compared with preset performance optimization conditions to obtain the comparison results; Based on the comparison results, the precision allocation strategy is updated to obtain the updated precision allocation strategy, and the computation graph is reconstructed based on the updated precision allocation strategy.

8. The operator precision adaptive allocation method based on multi-dimensional state awareness according to claim 1, characterized in that, The precision-aware semantic information includes: operator category identifier, numerical range change identifier, accumulation path structure identifier, precision sensitivity identifier, and node chain position identifier; wherein... The operator category identifier is used to distinguish the operator type of the operator node; The numerical range change identifier is used to describe the relationship between the operator node and the input tensor numerical range, such as scaling, expansion, or preservation. The accumulation path structure identifier is used to describe the accumulation depth within an operator node or across operators; The precision sensitivity flag is used to indicate the sensitivity of the operator node to low-precision errors; The node chain position identifier is used to indicate the node chain type of the node chain in which the operator node is located.

9. An operator precision adaptive allocation device based on multi-dimensional state awareness, characterized in that, include: The acquisition unit is used to acquire the neural network model to be executed and parse the neural network model to be executed to obtain the computation graph corresponding to the neural network model to be executed. A perception unit is used to construct precision-aware semantic information for the operator nodes in the computation graph, and add the precision-aware semantic information to the computation graph to obtain a precision-aware computation graph. The precision-aware semantic information is used to characterize the numerical behavior features of the operator nodes under different precision conditions. The construction unit is used to acquire the data features, computational features and hardware state features generated during the prior execution of the neural network model to be executed, so as to construct the multidimensional state information of the operator node; The generation unit is used to perform precision evaluation and constraint determination on the operator nodes and node chains in the precision-aware computation graph based on the precision-aware computation graph, the multi-dimensional state information and the preset constraint information, so as to generate a precision allocation strategy. The precision allocation strategy includes the computation precision, accumulation precision and storage precision configured for each operator node. The reconstruction unit is used to reconstruct the precision-aware computation graph based on the precision allocation strategy, generate a target execution computation graph, and perform inference computation of the neural network model to be executed based on the target execution computation graph.

10. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a computer program, and the processor running the computer program in the memory to perform the steps in the multi-dimensional state-aware operator precision adaptive allocation method according to any one of claims 1 to 8.