Error compensation method and device in optical computing, electronic equipment and medium
Patent Information
- Application Number
- CN202510338102.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-20
- Publication Date
- 2026-09-29
AI Technical Summary
[0004]本申请提供一种光计算中的误差补偿方法、装置、电子设备及介质,旨在解决在将光计算应用于神经网络模型的过程中,如何有效提高该模型输出精度的问题
[0013]本申请提供一种光计算中的误差补偿方法、装置、电子设备及介质,在将光计算应用于神经网络模型的过程中,首先针对神经网络模型的每一层,获取该层的权重值和激活值,然后基于该层模型分别对权重值和激活值执行量化处理操作,得到量化后的权重值和量化后的激活值。接着,针对模型中的各个算子,分别利用量化后的权重值和量化后的激活值进行光计算,并进行反量化操作得到光计算结果,将光计算结果与理论计算结果进行对比,从而得出该算子在光计算中产生的偏差量。最后,依据这个偏差量对算子进行补偿调整,以提高模型输出精度。
Smart Images

Figure CN122837578A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to an error compensation method, apparatus, electronic device and medium in optical computing. Background Technology
[0002] In the field of artificial intelligence, as the demand for computing resources from various models continues to rise, the limitations of traditional electronic chips in terms of power consumption and speed are becoming increasingly apparent. In contrast, optical computing chips, which utilize photons for data processing, exhibit significant advantages such as low power consumption and low latency.
[0003] However, current optical computing chips face some challenges in practical applications: on the one hand, data storage in optical computing chips still relies on electrical methods, which inevitably involves multiple stages such as analog-to-digital, digital-to-analog, and photoelectric conversion; on the other hand, the analog and optical components in optical computing chips contain errors. These factors combined result in a certain gap in output accuracy between optical computing and traditional electrical chips. Summary of the Invention
[0004] This application provides an error compensation method, apparatus, electronic device, and medium for optical computing, aiming to solve the problem of how to effectively improve the output accuracy of a neural network model when applying optical computing to such a model.
[0005] In a first aspect, this application provides an error compensation method for optical computing, comprising:
[0006] For each layer in the neural network model, obtain the weight values and activation values of that layer; and based on the neural network model of that layer, perform a quantization operation on the obtained weight values and activation values to obtain quantized weight values and activation values.
[0007] For each operator in the neural network model, optical computation is performed on the quantized weight values and quantized activation values, and dequantization is performed to obtain the optical computation results. The optical computation results are compared with the theoretical calculation results to obtain the deviation of the operator in optical computation, and the operator is compensated and adjusted according to the deviation.
[0008] Secondly, this application also provides an error compensation device for optical computing, comprising:
[0009] The data acquisition module is used to acquire the weight values and activation values of each layer in the neural network model; and based on the neural network model of that layer, to perform quantization processing on the acquired weight values and activation values to obtain quantized weight values and activation values.
[0010] The compensation module is used to perform optical calculations on the quantized weight values and quantized activation values for each operator in the neural network model, and to perform inverse quantization to obtain the optical calculation results. The optical calculation results are compared with the theoretical calculation results to obtain the deviation amount generated by the operator in the optical calculation, and the operator is compensated and adjusted according to the deviation amount.
[0011] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the steps of the error compensation method in optical computing as described in any of the first aspects.
[0012] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the error compensation method in optical computing as described in any of the first aspects.
[0013] This application provides an error compensation method, apparatus, electronic device, and medium for optical computing. In applying optical computing to a neural network model, firstly, for each layer of the neural network model, the weight values and activation values of that layer are obtained. Then, based on the model for that layer, quantization operations are performed on the weight values and activation values to obtain quantized weight values and quantized activation values. Next, for each operator in the model, optical computing is performed using the quantized weight values and quantized activation values, and inverse quantization is performed to obtain the optical computing results. The optical computing results are compared with the theoretical calculation results to determine the deviation generated by that operator in the optical computing. Finally, the operator is compensated and adjusted based on this deviation to improve the model output accuracy.
[0014] Therefore, this application, on the one hand, quantifies the weights and activation values of each layer of the neural network model, making the data format more suitable for optical computing, reducing computational complexity while improving computational efficiency. On the other hand, by comparing the optical computing results with the theoretical calculation results for each operator and performing deviation compensation adjustments, errors generated during the optical computing process can be accurately corrected, significantly improving the model output accuracy. This approach balances computational efficiency and accuracy improvement, enhancing the feasibility and reliability of optical computing in neural network model applications. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a flowchart of the error compensation method in optical computing provided in this application;
[0017] Figure 2 This is a schematic diagram of the neural network computing architecture provided in this application;
[0018] Figure 3 This is a flowchart of the computation of the FC operator provided in this application;
[0019] Figure 4 This is a flowchart of the computation process of the conv2d operator provided in this application;
[0020] Figure 5 This is a flowchart of the operator compensation provided in this application;
[0021] Figure 6 This is a schematic diagram of the error compensation device in optical computing provided in this application. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions 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, 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.
[0023] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein.
[0024] With the rapid development of artificial intelligence (AI) technology, AI models are being applied more and more widely and deeply in many fields such as deep learning and big data analysis, leading to an exponential increase in the demand for computing power. Against this backdrop, traditional electronic chips are facing increasingly severe challenges, primarily in terms of power consumption and speed—two key performance indicators. As the complexity and volume of computing tasks continue to rise, electronic chips are consuming significantly more power to meet computational demands. Simultaneously, limitations in signal transmission speed in dielectric materials and circuit delays are pushing the processing speed of electronic chips closer to their physical limits, making it difficult to meet the urgent computational needs of AI models.
[0025] Optical computing chips, as an emerging computing technology, utilize photons instead of electrons for data processing based on unique physical principles. Photons offer numerous advantages, including high speed, low energy consumption, and strong anti-interference capabilities, theoretically providing a possibility for overcoming the performance bottlenecks of traditional electrical chips. However, at the current stage of technological development, optical computing chips still face some pressing issues in practical applications. Regarding data storage, optical computing chips currently rely primarily on electrical storage methods, which inevitably requires data to undergo multiple stages during processing, including analog-to-digital conversion, digital-to-analog conversion, and photoelectric conversion.
[0026] Furthermore, optical computing chips integrate a large number of analog and photonic devices. Due to limitations in manufacturing processes and the influence of physical characteristics, these devices inevitably have a certain degree of inherent error. For example, differences in the operational precision of oMAC (Optical Multiply-Accumulator), transmission losses in optical waveguides, and nonlinearities in analog signal processing circuits can all lead to signal distortion and error accumulation during optical computing.
[0027] Based on this, this application provides an error compensation method, apparatus, electronic device, and medium for optical computing. By implementing a bias compensation strategy at the model operator level, it aims to minimize the impact of output bias during optical computing. Specifically, a bias compensation operation is performed for each operator in the neural network model to prevent bias from propagating to the next layer of the network and to prevent the accumulation and diffusion of errors between network layers. This error compensation method is applicable to the model quantization fine-tuning stage and can be performed offline to ensure that no additional computational load is added during inference, effectively guaranteeing the efficiency of inference.
[0028] The following is a detailed description in conjunction with the accompanying drawings.
[0029] Please refer to Figure 1 , Figure 1 This is a flowchart of an error compensation method for optical computing provided in this application. An error compensation method for optical computing, the method comprising:
[0030] S110: For each layer in the neural network model, obtain the weight value and activation value of that layer; and based on the neural network model of that layer, perform a quantization operation on the obtained weight value and activation value to obtain the quantized weight value and activation value.
[0031] Specifically, this step focuses on each layer of the neural network model. First, weight values and activation values are obtained from each layer. Weight values determine the strength of connections between neural networks; different weight configurations affect how information is transmitted and processed within the network. Activation values are the initial input values received by the neural network, reflecting the input data state of that layer. Next, the obtained weight values and activation values are quantized. Quantization maps the originally continuous range of values to a finite set of discrete values according to specific rules, ultimately obtaining quantized weight values and quantized activation values. Quantization reduces the space required for data storage and lowers the computational resource consumption. Simultaneously, the quantized numerical form provides a more suitable data type for optical computing, helping to improve computational efficiency and reduce accuracy loss during computation, ensuring the efficiency and stability of the entire neural network model processing flow.
[0032] S120: For each operator in the neural network model, perform optical calculations on the quantized weight values and quantized activation values respectively, and perform dequantization to obtain the optical calculation results. Compare the optical calculation results with the theoretical calculation results to obtain the deviation amount generated by the operator in the optical calculation, and compensate and adjust the operator according to the deviation amount.
[0033] Specifically, step S120 focuses on each operator in the neural network model. Optical computation is performed on each operator for the quantized weights and activations. Optical computation utilizes optical principles for data processing, offering advantages such as high speed and low energy consumption. After completing the optical computation and performing inverse quantization, the optical computation result is obtained. This result is compared with the theoretical calculation result obtained through traditional theoretical calculation methods. This comparison identifies the deviation generated by the operator during the optical computation process, i.e., the difference between the optical computation result and the theoretical calculation result. Finally, based on this deviation, the operator is adjusted accordingly to correct the deviation occurring during the optical computation process, making the operator's calculation result closer to the theoretical value.
[0034] This step aims to improve the accuracy and reliability of optical computing in neural network models. By comparing and compensating for the optical computation results of each operator with the theoretical calculation results, deviations caused during optical computation can be effectively reduced, ensuring that the neural network model can output more accurate results when using optical computing for data processing. This is of great significance for improving the performance and effectiveness of the entire neural network model in practical applications and helps promote the widespread application and development of optical computing technology in the field of neural networks.
[0035] Please refer to Figure 2 , Figure 2This is a schematic diagram of the neural network computing architecture provided in this application. The model layer defines the overall architecture and function of the neural network, and selects an appropriate model for different types of data and tasks, such as the CNN model (Convolutional Neural Network model) for processing image data, and the LLM model (Large Language Model) for natural language processing tasks.
[0036] Operator layers are the actual executors of model computations; each layer's computation is performed by a corresponding operator. When a layer in the model needs to perform a computation, the corresponding operator is invoked. For example, in the convolutional layer computation of a CNN model, the conv2d (Convolution2d, 2D convolution) operator is called. The conv2d operator performs convolution operations on the input data according to its defined parameters (such as kernel size, stride, padding, etc.). For input image data, the conv2d operator slides the convolution kernel across the image, performing multiplication and accumulation operations at each position to generate feature maps. Operators process data sequentially according to the model's architecture. For example, data processed by the conv2d operator is passed to pooling operators (such as max pooling or average pooling) for downsampling to reduce data dimensionality while preserving key features. Afterward, the data is passed to the fully connected layer, where the FC (Fully Connected Layer) operator is called for fully connected computation. The fully connected (FC) operator performs matrix multiplication on the feature vector output from the previous layer and the weight matrix to obtain the final classification result or other task-related output. In some complex calculations, the GEMM (General Matrix Multiply) operator is also involved to efficiently perform general matrix multiplication operations and accelerate the computation process of neural networks.
[0037] The hardware layer provides physical support for operator computation, with different hardware devices executing operator computations in their unique ways. Devices in the hardware layer, such as oMAC, need to be adapted to the computational requirements of the operator layer. oMAC utilizes optical principles to perform multiplication and accumulation operations, making it suitable for handling the large number of matrix multiplications and accumulations in neural networks. The hardware device is configured accordingly based on the operator's instructions and data format. When the operator layer issues a computation command, the hardware device begins executing the computation task. Taking oMAC as an example, it receives the input weight values and activation values (data processed by the operator layer), quickly performs multiplication and accumulation operations using optical means, and returns the computation results to the operator layer. The parallel computing capabilities and high-speed processing characteristics of the hardware devices can significantly accelerate the computation process of the neural network and improve the overall system efficiency.
[0038] Therefore, the model layer determines the logic and order of computation and sends computation requests to the operator layer. The operator layer calls appropriate operators to perform specific calculations according to the model's requirements and passes the calculation results between different operators. The hardware layer responds to the computational needs of the operator layer, performs computational tasks using its own physical characteristics, and feeds the results back to the operator layer. This multi-layered collaboration enables neural networks to efficiently process various data and tasks, realizing a complete process from abstract model design to specific hardware computation, from input data to final output results.
[0039] Understandably, during model inference, the oMAC engine acts as the hardware executing MAC (Multiply-Accumulate operation). The root cause of computational errors lies in the hardware-level oMAC engine. After calibration, the deviation in the oMAC engine's output error is relatively small; at this point, the error is mainly dominated by noise. This makes the distribution of oMAC's output error highly random, specifically manifested in the irregular distribution of the difference between the oMAC output and the true value output. Therefore, it is difficult to eliminate the bias generated by oMAC through simple difference compensation methods.
[0040] Given the difficulty of directly compensating for oMAC bias at the hardware level, this application implements a bias compensation strategy at the model operator level. This strategy has significant advantages, as detailed below:
[0041] First, once hardware is designed and manufactured, its structure and characteristics are essentially fixed. Modifying the hardware to achieve deviation compensation is not only costly but also time-consuming. In stark contrast, at the model operator level, deviation compensation strategies can be flexibly adjusted and optimized based on the specific requirements of the task, the hardware characteristics of oMAC, and the results of error analysis. More importantly, it allows for more accurate and efficient deviation compensation for different types of AI models, such as convolutional neural networks (CNNs) and recurrent neural networks (RNNs), as well as various operators within those models.
[0042] Secondly, implementing a bias compensation strategy at the model operator level has good scalability, enabling the compensation mechanism to be applied to new models and operators without requiring large-scale hardware modifications and adjustments, thus effectively reducing the difficulty and cost of technology upgrades.
[0043] Furthermore, oMAC hardware from different manufacturers often varies in performance, accuracy, and error characteristics. The bias compensation strategy proposed in this application at the model operator level effectively masks these hardware differences, creating a unified and relatively stable computing environment for the upper-level model. This allows model developers to focus on model design and optimization without excessive concern for the specific models and characteristics of the underlying hardware, significantly improving development efficiency and enhancing model portability, enabling stable operation across different hardware environments.
[0044] In some embodiments, the neural network model includes multiple model layers, wherein the computational tasks of each model layer are performed by one or more operators; some of the computational operations involved by the operators are completed in an optical multiplier-accumulator; and each operator is compensated and adjusted for the deviation generated by the operation of each operator in the optical multiplier-accumulator.
[0045] Specifically, a neural network model can consist of multiple model layers, with each layer's computational tasks performed by one or more operators. This means that the model's complex calculations are decomposed into operators across different model layers to perform functions such as information processing and feature extraction. In these operations, some operations (such as linear operators) are performed in oMAC, which provides hardware support for these operations. However, these operators introduce biases during oMAC computation. To improve the accuracy and reliability of the neural network model, it is necessary to compensate and adjust each operator for the biases generated during oMAC computation. This corrects the computational results and reduces the impact of biases on model performance.
[0046] In some embodiments, when the operation corresponding to a certain operator in the model is a large-scale matrix multiplication operation, and the optical multiplication accumulator is only capable of handling smaller-scale matrix multiplication operations, the operator corresponding to the large-scale matrix multiplication operation is divided into multiple small-scale matrix multiplication operators, and the small-scale matrix multiplication operators are loaded into the optical multiplication accumulator for calculation. After the calculation is completed, the calculation result is passed according to the following process: first, it is fed back to the operator layer, and the operator layer performs an accumulation operation on the received calculation result; then, the accumulated result is fed back to the model layer; finally, the model layer passes the received result to the next layer, thereby advancing the operation of the entire neural network model; for each small-scale matrix multiplication operator calculated in the optical multiplication accumulator, the small-scale matrix multiplication operator is compensated and adjusted according to the deviation.
[0047] Specifically, during the computation process of a neural network model, when an operator in the model is responsible for a large-scale matrix multiplication operation, such as a 512×512 matrix multiplication, oMAC, due to its hardware limitations, can only handle smaller-scale matrix multiplication operations, such as 8×8 matrix multiplication. To ensure that the neural network model's computation can proceed smoothly and uninterruptedly, the operator corresponding to the large-scale matrix multiplication operation is divided into multiple smaller-scale matrix multiplication operators; that is, the 512×512 large-scale matrix multiplication is broken down into multiple 8×8 small-scale matrix multiplications. Subsequently, these divided small-scale matrix multiplication operators are loaded into oMAC for computation. After all small-scale matrix multiplications are calculated in oMAC, the result transmission process is as follows: First, the result is fed back to the operator layer. At this layer, the operator layer performs an accumulation operation on the received results, integrating the results of multiple small-scale matrix multiplications into a single comprehensive value. Next, the accumulated result is fed back to the model layer. Finally, the model layer passes this integrated result to the next layer. Through this transmission method, the operation of the entire neural network model can continue to advance, and the data flow and computation between various model layers can be carried out in an orderly manner. Simultaneously, to maximize the computational accuracy of the neural network model, for each small-scale matrix multiplication operator calculated in oMAC, the system compensates and adjusts these operators based on the deviation generated during the calculation process. By implementing a deviation compensation strategy at the model operator level, the inherent limitations of oMAC's processing capabilities are effectively overcome, enabling large-scale matrix multiplication operations to be performed smoothly in the neural network model.
[0048] In some embodiments, the operator layer includes a combination of one or more of the following operations:
[0049] Activation value transcoding: This operation converts the result of a convolution operation into a computational form suitable for matrix multiplication. This operation aims to adjust the format of the convolution result using a specific algorithm to meet the data format requirements of matrix multiplication, thus facilitating subsequent matrix multiplication operations. For example, using the accelerated computation strategy img2col (image transcoding), the convolution operation can be transformed into GEMM (Generalized Matrix Multiplication), mathematically expressed as C = A × B, thereby maximizing the reduction of convolution computation time.
[0050] Padding operation: This operation fills the width and height of the input data with preset values. It's used to adjust the size of the input data. For example, in convolution operations, when the input and output shapes are expected to satisfy a specific relationship (such as having the same shape), padding the boundaries of the input data with specific values (such as 0) appropriately enlarges the input data, ensuring the convolution operation performs as expected and obtains the desired output result. For instance, if the input vector or weights are a 63×63 matrix, padding can be used to make it a 64×64 matrix to meet specific operational requirements.
[0051] Tiling operation: This operation segments the input vector or weights to transform them into a form suitable for oMAC to perform matrix multiplication. Given the size limitations of oMAC when handling matrix multiplication, this operation segments larger input vectors or weights into multiple sub-matrices according to specific rules, based on the matrix size that oMAC can handle. This allows oMAC to perform matrix multiplication efficiently. For example, if oMAC performs 32×32 matrix multiplication, and the input vector / weights are 64×64, then the input vector / weights need to be segmented into multiple 32×32 matrices to fit oMAC's matrix multiplication requirements.
[0052] Accu_sum operation: Performs an accumulation calculation. This operation is responsible for accumulating a series of data. For example, in some calculations, it is necessary to accumulate multiple intermediate results to obtain the final comprehensive result. This operation uses specific calculation logic to achieve element-by-element accumulation of input data or accumulation according to a specific dimension.
[0053] Reshape operation: Transforms the shape of a vector from one form to another. Based on specific computational needs, a particular algorithm rearranges the dimensional information of the vector, changing its shape to adapt it to different subsequent data processing procedures.
[0054] The Permute operation allows for the free adjustment of the dimension order of a tensor. As a multidimensional data structure, the dimension order of a tensor may need to be flexibly adjusted in different computational scenarios. This operation allows the various dimensions of a tensor to be rearranged according to specific algorithmic requirements and computational logic to optimize computational efficiency or meet specific computational needs.
[0055] Please refer to Figure 3 , Figure 3This is a flowchart of the computation process of the FC operator provided in this application. The raw input data enters the quantization module. After quantization, the quantized input data (input_q) is output. The quantized input data (input_q) then enters the padding and tiling module. The padding operation adds preset values (e.g., the preset value is 0) to specific dimensions of the data to adjust its size to meet the requirements of subsequent calculations. The tiling operation divides a large data block into multiple appropriately sized sub-blocks based on the processing capabilities of oMAC. Simultaneously, the quantized weight data (weight_q) is also input into the padding and tiling module for the same processing to match its size and structure with the quantized input data, facilitating subsequent calculations in oMAC.
[0056] The quantized input data (input_q) and quantized weight data (weight_q), after being processed by padding and splitting, are both input into oMAC. oMAC, a computational unit specifically designed for efficient matrix multiplication and accumulation operations, can accurately and quickly perform multiplication operations on the input data and weights, and then accumulate the resulting products. In this process, oMAC performs corresponding calculations on the preprocessed input data and weights according to predetermined computational logic, ultimately outputting the accumulated result (accu_sum, representing the sum).
[0057] While oMAC's computation process is highly efficient, it is limited by inherent hardware implementation characteristics and unavoidable approximations during numerical calculations, which may introduce certain computational errors. Therefore, after oMAC outputs the accumulated result (accu_sum), a compensation module is needed to adjust it. This module directly corrects the errors generated during oMAC's computation, ensuring that the accumulated result received by the subsequent dequantization module is more accurate. This not only helps reduce the propagation and accumulation of errors throughout the computation process but also significantly improves the accuracy of the final output.
[0058] After error compensation, the accumulated result (accu_sum') then enters the dequatization module. Dequatization, as the inverse operation of quantization, transforms the quantized accumulated result back into a representation closer to the precision of the original data, thus obtaining the final output. This output is the final output produced by the FC after the above series of calculations, and it carries the information after the fully connected layer has processed the input data.
[0059] Please refer to Figure 4 , Figure 4 This is a flowchart of the computation of the conv2d operator provided in this application. The original input data (input) enters the quantization module. After quantization, the quantized input data (input_q) is output. The quantized input data (input_q) then enters the image transpilation (img2col) module. img2col is a technique that converts two-dimensional convolution operations into matrix multiplication. For example, it can rearrange the input image data into column vector form for subsequent matrix multiplication with weights. This transformation helps accelerate computation using efficient matrix multiplication algorithms. The data transformed by the img2col module enters the padding and tiling module. The padding operation adds preset values (e.g., a preset value of 0) to specific dimensions of the data to adjust the data size to meet subsequent computational requirements. The tiling operation divides large data blocks into multiple appropriately sized sub-blocks based on the processing capabilities of oMAC. Meanwhile, the quantized weight data (weight_q) first enters the Reshape module. The Reshape operation changes the shape of the weight data so that its dimensions match those of subsequent operations. After reshaping, the weight data enters the padding & tiling module, matching the structure and size of the input data processed by img2col and padding & tiling, facilitating computation in oMAC.
[0060] After padding and splitting, the quantized input data and quantized weight data are input into oMAC. oMAC can efficiently perform multiplication operations on the input data and weights and accumulate the results. That is, oMAC performs corresponding calculations on the processed input and weights and outputs the accumulated result (accu_sum, representing the accumulated sum).
[0061] Due to limitations in hardware implementation or numerical computation, oMAC's calculation process may introduce computational errors. Therefore, after oMAC outputs the accumulated result (accu_sum), the compensation module adjusts it to obtain a compensated accumulated result (accu_sum'). The compensated accumulated result (accu_sum') then enters the dimension adjustment and reshaping (permute & reshape) module. The dimension adjustment (Permute) operation rearranges the dimensions of the data to meet the dimensionality requirements of subsequent calculations; the reshaping (Reshape) operation changes the shape of the data again to conform to the input format of the dequantization module. The rearranged and reshaped data then enters the dequantization module. Dequantization is the reverse process of quantization; it converts the quantized accumulated result back to a representation closer to the precision of the original data to obtain the final output, which is the final output generated by conv2d after a series of calculations.
[0062] In some embodiments, in step S120 above, for each operator in the neural network model, optical computation is performed on the quantized weight values and quantized activation values, and an inverse quantization operation is performed to obtain the optical computation result. The optical computation result is compared with the theoretical calculation result to obtain the deviation amount generated by the operator in the optical computation, and the operator is compensated and adjusted according to the deviation amount, including:
[0063] S121, obtain the input tensor of each operator as well as the shape and value of the convolution kernel.
[0064] S122 uses an optical multiplier-accumulator to perform operator operations, followed by inverse quantization to obtain the optical computation result; then, the same operator operations as the optical computation are performed on the digital chip to obtain the theoretical computation result. The digital chip can be any one of a CPU (Central Processing Unit), GPU (Graphics Processing Unit), TPU (Tensor Processing Unit), NPU (Neural Network Processing Unit), or FPGA (Field-Programmable Gate Array).
[0065] S123 calculates the difference between the optical calculation result and the theoretical calculation result to obtain the deviation of the operator in optical calculation.
[0066] Specifically, the process of obtaining the deviation generated by the operator in optical computation is as follows: A preset number of samples (e.g., images) are selected, and the corresponding activation and weight values are input into the digital chip for theoretical calculation to obtain the theoretical calculation result. Simultaneously, optical computation is performed on the selected samples' activation and weight values on oMAC, followed by inverse quantization to obtain the optical computation result. For each operator calling oMAC, the deviation of its computation result in oMAC is calculated as follows: Starting with the first sample, the optical computation result is subtracted from the theoretical calculation result to obtain the first difference. For subsequent samples, the sum of all the differences calculated for the previous samples is subtracted from the optical computation result, and then the theoretical calculation result for that sample is subtracted to obtain the corresponding difference. Finally, the differences corresponding to all samples are summed, and the sum is rounded to obtain the final deviation.
[0067] S124. Determine the corresponding compensation amount for each operator based on the deviation amount in optical calculation, add the compensation amount of each operator to the bias of the operator, and update the bias parameters in the model to complete the compensation adjustment of the operator.
[0068] Specifically, when compensating and adjusting the operator based on the deviation, the specific operations are as follows: First, the dimensions of the operator are appropriately padded and / or cut to adapt to the operational requirements of oMAC, ensuring smooth optical computation. Then, operator operations are performed using oMAC and the digital chip respectively to obtain a difference tensor. This difference tensor is reshaped and reduced to obtain a one-dimensional tensor. The dimension of this one-dimensional tensor is closely related to the number of operator channels. Next, based on this one-dimensional tensor, the deviation of the operator is rounded to meet the computational requirements of the quantization model. Finally, different processing is performed depending on whether the operator has a bias: if the operator has a bias and the deviation has the same dimension as the bias, then during the model deployment stage, the rounded deviation is superimposed on the quantized bias to effectively compensate for the operator's bias; if the operator does not have a bias, then during the operation, integer vector addition operations are added to compensate for the operator's bias.
[0069] It should be noted that neural network models can contain various types of operators, including linear operators, convolution operators, and fully connected operators. The above-mentioned compensation and adjustment methods are applicable to all types of operators to ensure the accuracy and stability of the entire neural network model in an optical computing environment.
[0070] The following is a detailed description through an example.
[0071] Please refer to Figure 5 , Figure 5This is a flowchart of the operator compensation provided in this application. This application focuses on bias compensation at the operator layer, and compensation operations can be performed for each operator executed by oMAC. ln-op represents linear optical computation, and nln-op represents nonlinear fiber computation. The compensation operation can be performed in the linear optical computation part of each layer of the neural network model. Specifically, for layer_0 of the model, the input is an image j (where the value of j is in the range of {0,1,2}), and the linear optical computation (ln-op) of this layer corresponds to a bias offset_0_j. For layer_i of the model, its linear optical computation (ln-op) also corresponds to a bias offset_i_j. Similarly, for layer_n of the model, the linear optical computation (ln-op) of this layer corresponds to a bias offset_n_j, and the output result after calculation by this layer is output. This demonstrates that each layer of the model's linear optical calculation has a corresponding offset: layer_0 corresponds to offset_0_j, layer_i to offset_i_j, and layer_n to offset_n_j. It also shows the final output flow: starting with the input image (e.g., picture j in layer_0), the calculations go through a series of layers (layer_0, layer_i, ..., layer_n), each layer generating a corresponding offset, and finally, the result is output from layer_n. This illustrates the entire data flow from input to output.
[0072] The following example uses an image recognition application scenario. When performing bias compensation, m images (e.g., 3 images) are selected. First, the calculation results are obtained through both theoretical calculations and inference on oMAC. The theoretical calculations are performed on a digital chip (such as a CPU, GPU, or FPGA). During the m inference operations on oMAC, for each linear operator called on oMAC, the final bias offset is obtained according to the following steps:
[0073] For image number 0:
[0074] Calculate offset_0 = out_0 - golden_out_0. Here, golden_out is the theoretical calculation result, which does not consider errors or mistakes caused by computing system or other hardware factors; out_0 is the result obtained in the actual optical computing system, i.e., the optical calculation result. offset_0 represents the deviation between the result obtained from the actual optical computing system for the first image and the theoretical calculation result. This deviation reflects the difference between the actual optical computing system's processing of the first image and the theoretically accurate calculation result, for example, due to the characteristics of oMAC itself, hardware errors, etc.
[0075] For the first image:
[0076] Calculate offset_1 = (out_1 - offset_0) - golden_out_1.
[0077] `out_1` is the result obtained by the actual optical computing system for the first image, and `golden_out_1` is the theoretical calculation result for the first image. Here, `out_1 - offset_0` removes the influence of the already calculated deviation `offset_0` from the actual output of the first image, and then subtracts the theoretical value `golden_out_1` to obtain the new deviation `offset_1` between the first image and the theoretical value after removing the influence of the first image's deviation. This calculation method helps to gradually accumulate and separate the deviation characteristics of different images in the optical computing system.
[0078] For the m-th image:
[0079] Calculate offset_m=(out_m-offset_m-1-...-offset_0)-golden_out_m.
[0080] For the m-th image, out_m is its output in the actual optical computing system, and golden_outm is the theoretical calculation result. The part out_m - offset_m-1 - ... - offset_0 involves successively removing the calculated biases from the previous m-1 images from the actual output of the m-th image, and then subtracting the theoretical value golden_out_m, thus obtaining the offset_m of the m-th image after removing the biases from all previous images. This iterative approach allows for a more accurate calculation of the bias for each image in the optical computing system.
[0081] Finally, offset = round(offset_m + ... + offset_1 + offset_0) is calculated.
[0082] The deviations calculated from offset_0 to offset_m for all m images are summed to obtain the total deviation. Since linear operators in the quantization model perform integer operations, the sum is rounded to the nearest integer to match the model's computational characteristics, ultimately yielding the offset used for compensation. This offset is used for subsequent deviation compensation of the linear operators to reduce the impact of optical computing system output deviations on the overall neural network model output.
[0083] It's important to note that while `offset_i` performs bias compensation at the operator level, it doesn't directly compensate for the operator's output. The specific compensation method is as follows: Assume that a single matrix-vector multiplication operation of oMAC can be performed in the form [m,m]@[m,1]. In practical applications, linear operators can ultimately be transformed into matrix multiplication in the form [B,M,N]@[N,K]. Here, B represents the batch size, which is the number of samples selected in a single training iteration. To adapt the matrix operations of linear operators to oMAC's computational capabilities, padding is performed on M and N in the matrix, ensuring that M and N are divisible by m. This better connects the matrix multiplication operations of linear operators with the computational form of oMAC, laying the foundation for subsequent bias compensation operations based on oMAC.
[0084] Let's take the convolution operator conv2d as an example to explain in detail: Assume the input tensor shape is [b,c_in,h_in,w_in], the convolution kernel shape is [c_out,c_in,k,k], and the output tensor shape is [b,c_out,h_out,w_out]. After the img2col operation, the input tensor becomes [b,c_in*k*k,h_out*w_out], and after the transpose operation, it becomes [b,h_out*w_out,c_in*k*k]. The convolution kernel becomes [out_c,c_in*k*k] after the reshape operation, and after the transpose, it becomes [c_in*k*k,out_c]. At this point, the convolution operation is transformed into multiplying two tensors: [b, h_out * w_out, c_in * k * k] @ [c_in * k * k, out_c], resulting in [b, h_out * w_out, out_c]. After Permute & Reshape operations, the output tensor [b, c_out, h_out, w_out] is obtained. Here, b represents the number of samples selected in one training iteration, such as the number of images; h represents the height of the sample (e.g., the image), i.e., the number of pixels in the height direction; w represents the width of the sample (e.g., the image), i.e., the number of pixels in the width direction; and c represents the number of channels of the sample (e.g., the image), for example, c equals 3 for RGB images.
[0085] Let's take the fully connected layer operator (FC) as an example again: Suppose the input shape is [b, c_in], the weights are [c_out, cin], and the weights are transposed to become [c_in, c_out]. By performing the operation [b, c_in]@[c_in, c_out], the result is [b, c_out].
[0086] The operation [B,M,N]@[N,K] yields [B,M,K]. Assume the FC operator, using oMAC, yields [B_o,M_o,K_o], and using a digital chip (such as a CPU, GPU, or FPGA), yields [B_d,M_d,K_d]. The difference tensor between these two is [B_offsets,M_offsets,K_offsets]. After reshaping this difference tensor, it becomes [B_offsets*M_offsets,K_offsets]. Then, reduction and summation are performed on the first dimension, resulting in a one-dimensional tensor whose size is equal to the number of channels of the linear operator.
[0087] After obtaining the bias values of each operator executed on oMAC across m images, the m bias values of each operator are summed to obtain the offset of each operator. For the quantized model, linear operators perform integer operations, so the offset needs to be rounded. For linear operators, the dimension of offset is the same as that of bias. When deploying the model, the offset is directly added to the quantized bias. In this way, during subsequent model inference, no modifications to the software or hardware are required, significantly reducing the impact of oMAC output bias on the overall neural network model output.
[0088] For Conv2d convolution operations, the process involves multiplying the kernel by the corresponding positions of the scanned region and summing the results. After convolution, a bias is added. If the kernel is divided into sub-kernels on multiple channels for convolution operations, the results of each sub-operation must be summed and then the bias added. Specific parameters are as follows:
[0089] Kernel: [c_out,c_in,k,k], bias: [c_out];
[0090] Input: [b,c_in,h_in,w_in];
[0091] After transformation in conv2d, the input becomes [b,c_in,h_in',w_in']+bias. After bias compensation, the bias stored in the model becomes bias', and bias' = bias + offset.
[0092] The following description uses offline compensation on a ResNet50 model based on the ImageNet dataset as an example. oMAC supports matrix multiplication of size 8×8 and includes the following steps:
[0093] S1: Fine-tuning of a quantized model with 4-bit activation values and weights (W4A4) was performed on a GPU using Quantization-Aware Training (QAT). The first 7×7 convolution operation and the last fully connected layer operation in the model were quantized using 8-bit quantization.
[0094] S2: Randomly select several images (e.g., three) from the ImageNet training set or other image data for bias compensation.
[0095] S3: In the ResNet50 model, there are 52 convolution operators that require bias compensation. Taking the second convolution operator that needs compensation as an example, the compensation process will be explained in detail. The compensation process for the remaining 51 convolution operators is similar.
[0096] S31: The shape of the input tensor is [1,3,56,56], the shape of the convolution kernel is [64,3,3,3], and the shape of the output tensor is [1,64,56,56].
[0097] S32: The transformation process of the input tensor is as follows: First, through the im2col operation, the shape becomes [1,576,3136], and then after the permute operation, it becomes [1,3136,576].
[0098] S33: The transformation process of the convolution kernel is as follows: first, through the reshape operation, the shape becomes [64,576], and then after the transpose operation, it becomes [576,64].
[0099] S34: Use oMAC to perform matrix multiplication [1,3136,576]@[576,64], and get the result out_0, which has the shape [1,3136,64].
[0100] S35: Perform the same matrix multiplication operation on the CPU to get the result golden_out_0, which has the same shape [1,3136,64].
[0101] S36: Calculate offset_0 = out_0 - golden_out_0.
[0102] S4: Repeat steps S31-S35 to obtain out_1 and golden_out_1, and calculate offset_1 = (out_1 - offset_0) - golden_out_1.
[0103] S5: Repeat steps S31-S35 again to obtain out_2 and golden_out_2, and calculate offset_2 = (out_2 - offset_1 - offset_0) - golden_out_2.
[0104] S6: Calculate offset = offset_0 + offset_1 + offset_2. Perform a reshape operation on the offset in S5 to make its dimensions [3116, 64]. Then, reduce and sum the dimensions of the output channels to obtain the offset vector with a shape of
[64] , denoted as offset.
[0105] S7: Round off the offset to obtain the final compensation amount of the convolution operator.
[0106] S8: Perform the same operation on the other 51 convolution operations to obtain the corresponding compensation amount.
[0107] S9: Add the compensation values of 52 convolution operations to the bias of the convolution operator (which needs to be quantized into integers).
[0108] Understandably, bias compensation operations are performed on all 52 convolution operators in ResNet50 throughout the entire process. The compensation process was explained in detail above using the second convolution operator as an example. This series of operations revolves around the convolution operators, so bias compensation is performed at the operator level. For example, from the shape transformation of the input tensor and the convolution kernel (S31-S33), to performing matrix multiplication using oMAC (S34) and performing the same operation on the CPU (S35), and then to calculating the offset at different stages (S36, S4, S5), these steps are all specifically designed to handle the bias in the convolution operator calculation process. The goal is to find an appropriate compensation amount to correct the possible biases in the operator calculation and ensure that the operator calculation is more accurate. This demonstrates bias compensation performed at the operator level.
[0109] However, from the calculation process, the calculated bias (offset_i) is not directly added to the output after the convolution operator produces the final output. Instead, a series of intermediate steps are used: different offset values are calculated at different stages (such as S36, S4, and S5), and these offset values are then accumulated (S6), subjected to dimensionality transformation, reduction, and summation to obtain a bias vector (denoted as offset). This vector is then rounded (S7) to obtain the final compensation amount. This final compensation amount is not directly added to the operator's output, but rather superimposed on the convolution operator's bias (a Boolean value that needs to be quantized to an integer) (S9). In this way, the calculation process of the operator is indirectly affected, thereby compensating for the bias, rather than directly changing the operator's output.
[0110] In summary, this application employs operator-level bias compensation to suppress computational interference, providing precise compensation for each operator executed by oMAC. By performing bias compensation at each layer of linear optical computation, it prevents bias from accumulating in the neural network, ensuring the accuracy and stability of the model output. For biased models, the compensation amount can be directly superimposed on the quantized bias, reducing the impact of oMAC output bias on the model output without software or hardware modifications. Direct integer compensation is significant for oMAC or other analog computing chips that only support integer operations, avoiding the increased computational complexity caused by multiplying by the quantization factor. This application is not only applicable to optical computing but also to other analog computing scenarios, demonstrating broad versatility and scalability. Furthermore, for unbiased linear operators, only a single integer vector addition operation with minimal impact on speed and power consumption is added, ensuring the system's high efficiency and low power consumption when processing such operators.
[0111] The error compensation device for optical computing provided in this application is described below. The error compensation device for optical computing described below can be referred to in correspondence with the error compensation method for optical computing described above.
[0112] Please refer to Figure 6 , Figure 6 This is a schematic diagram of the structure of the error compensation device in optical computing provided in this application. An error compensation device 600 in optical computing includes a data acquisition module 610 and a compensation module 620.
[0113] For example, the data acquisition module 610 is used to acquire the weight values and activation values of each layer in the neural network model; and based on the neural network model of that layer, to perform a quantization operation on the acquired weight values and activation values to obtain quantized weight values and activation values.
[0114] For example, the compensation module 620 is used to perform optical calculations on the quantized weight values and quantized activation values for each operator in the neural network model, and perform dequantization to obtain the optical calculation results. The optical calculation results are compared with the theoretical calculation results to obtain the deviation amount generated by the operator in the optical calculation, and the operator is compensated and adjusted according to the deviation amount.
[0115] Understandably, when applying optical computing to neural network models, to improve the model's output accuracy, the error compensation device in this optical computing uses a data acquisition module to obtain weight and activation values for each layer of the neural network model. Based on this layer, it performs quantization processing to obtain quantized weight and activation values. Subsequently, the compensation module performs optical computing on each operator in the model using these quantized weight and activation values. The optical computing results are then compared with theoretical calculation results to determine the deviation generated by the optical computing for that operator. Based on this deviation, the operator is then adjusted for compensation. In this way, the error compensation device in optical computing can effectively identify and correct deviations generated during the optical computing process, thus solving the problem of insufficient accuracy when optical computing is applied to neural network models. Its advantages lie in achieving refined processing of each part of the model through layered data acquisition and quantization, and deviation calculation and compensation for each operator, effectively improving the model's output accuracy and ensuring the model's accuracy and stability in an optical computing environment.
[0116] In some embodiments, this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the steps of an error compensation method in optical computing.
[0117] Specifically, the electronic device provided in this application includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor. When the processor executes this computer program, it operates according to the steps of the error compensation method in optical computing. The processor executes the program to obtain weight and activation values for each layer of the neural network model, performs quantization, then performs optical computing on each operator, compares the results to derive the deviation, and performs compensation adjustments. This approach solves the problem of insufficient accuracy when optical computing is applied to neural network models. Its advantage lies in the fact that this electronic device integrates the hardware and software required for error compensation in an integrated manner, exhibiting good system stability and reliability. By executing a specific program through the processor, the error compensation process can be completed efficiently and accurately, providing reliable hardware support for improving the model's output accuracy. It can be widely applied to various scenarios requiring the combination of optical computing and neural network models, improving the performance of related systems.
[0118] In some embodiments, a non-transitory computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of an error compensation method in optical computing.
[0119] Specifically, the non-transitory computer-readable storage medium of this application stores a computer program that, when executed by a processor, implements the steps of an error compensation method in optical computing. This means that as long as a suitable processor reads and runs the program on this storage medium, the error generated by the neural network model during optical computing can be processed according to the error compensation method. For example, the weights and activation values of each layer of the model are acquired and quantified, optical computing is performed on the operators, and the deviation is compared to achieve compensation. This approach effectively solves the problem of difficulty in improving accuracy when optical computing is applied to neural network models. Its advantages lie in the good portability and storage persistence of the non-transitory computer-readable storage medium. It can be easily transferred between different devices, and as long as the device has a processor capable of executing the program, the error compensation function can be implemented, greatly improving the versatility and flexibility of the error compensation method. Moreover, the data storage is stable and can preserve the error compensation program for a long time, providing a reliable software foundation for the combined application of optical computing and neural network models.
[0120] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. An error compensation method in optical computing, characterized in that, The method includes: For each layer in the neural network model, obtain the weight values and activation values of that layer; and based on the neural network model of that layer, perform a quantization operation on the obtained weight values and activation values to obtain quantized weight values and activation values. For each operator in the neural network model, optical computation is performed on the quantized weight values and quantized activation values, and dequantization is performed to obtain the optical computation results. The optical computation results are compared with the theoretical calculation results to obtain the deviation of the operator in optical computation, and the operator is compensated and adjusted according to the deviation.
2. The error compensation method in optical computing according to claim 1, characterized in that, The neural network model includes multiple model layers, where the computational tasks of each model layer are performed by one or more operators; some of the computational operations involved by the operators are completed in an optical multiplier-accumulator; and each operator is compensated and adjusted to compensate for the deviation generated by the operation of each operator in the optical multiplier-accumulator.
3. The error compensation method in optical computing according to claim 1, characterized in that, When the operation corresponding to a certain operator in the model is a large-scale matrix multiplication operation, and the optical multiplication accumulator only has the ability to handle small-scale matrix multiplication operations, the operator corresponding to the large-scale matrix multiplication operation is divided into multiple small-scale matrix multiplication operators, and the small-scale matrix multiplication operators are loaded into the optical multiplication accumulator for calculation. After the calculation is completed, the transmission of the calculation result follows the following process: First, it is fed back to the operator layer, and the operator layer performs an accumulation operation on the received calculation result; Then, the accumulated result is fed back to the model layer; finally, the model layer passes the received result to the next layer, thereby advancing the operation of the entire neural network model. For each small-scale matrix multiplication operator that is computed in the optical multiplication accumulator, the small-scale matrix multiplication operator is compensated and adjusted according to the deviation.
4. The error compensation method in optical computing according to claim 3, characterized in that, The operator layer includes a combination of one or more of the following operations: Activation value transposition operation: Transforms the result of the convolution operation into a computational form suitable for matrix multiplication; Fill operation: Fill the input data with pre-defined values in the width and height directions; Segmentation operation: Segment the input vector or weights to transform them into a form suitable for matrix multiplication operations performed by the optical multiplication accumulator; Accumulation operation: Performs an accumulation calculation operation; Reshaping operation: Changes the shape of a vector from one form to another; Dimension adjustment operation: Adjusts the order of dimensions of a tensor.
5. The error compensation method in optical computing according to claim 2, characterized in that, The process involves performing optical computation on the quantized weight values and quantized activation values for each operator in the neural network model, followed by dequantization to obtain the optical computation results. These results are then compared with theoretical calculations to determine the deviation generated by the operator in the optical computation. Compensation and adjustment of the operator based on this deviation include: Obtain the input tensor of each operator, as well as the shape and value of the convolution kernel; The optical multiplier-accumulator is used to perform operator operations, followed by inverse quantization, to obtain the optical calculation result; and the same operator operations as the optical calculation are performed on the digital chip to obtain the theoretical calculation result. The difference between the optical calculation result and the theoretical calculation result is calculated to obtain the deviation of the operator in optical calculation; The compensation amount is determined based on the deviation of each operator in optical computation. The compensation amount of each operator is then added to the bias of that operator, and the bias parameters in the model are updated to complete the compensation adjustment of that operator.
6. The error compensation method in optical computing according to claim 5, characterized in that, The digital chip can be any one of CPU, GPU, TPU, NPU, and FPGA.
7. The error compensation method in optical computing according to claim 1, characterized in that, For each operator in the neural network model, optical computation is performed on the quantized weight values and quantized activation values, and then dequantization is performed to obtain the optical computation results. The optical computation results are compared with the theoretical calculation results to obtain the deviation generated by the operator in the optical computation, including: A preset number of samples are selected, and the activation value and weight value corresponding to the sample are input into the digital chip for theoretical calculation to obtain the theoretical calculation result; then optical calculation is performed on the selected sample's activation value and weight value on the optical multiplier accumulator, and then inverse quantization is performed to obtain the optical calculation result. For each operator that calls the optical multiplier-accumulator, the deviation of its calculation result in the optical multiplier-accumulator is calculated. Specifically, starting from the first sample, the optical calculation result is subtracted from the theoretical calculation result to obtain the first difference. For subsequent samples, the sum of the differences obtained from all previous samples is subtracted from the optical calculation result, and then the theoretical calculation result of the sample is subtracted to obtain the difference corresponding to the sample. Add up the differences between all the samples and round the sum to get the final deviation.
8. The error compensation method in optical computing according to claim 7, characterized in that, The sample is an image.
9. The error compensation method in optical computing according to claim 1, characterized in that, The compensation adjustment of the operator based on the deviation includes: The operator is padded and / or cut in the dimension to fit the operational requirements of the optical multiply-accumulate; Operator operations are performed using an optical multiplier-accumulator and a digital chip respectively to obtain a difference tensor; the difference tensor is then reshaped and reduced to obtain a one-dimensional tensor; wherein, the dimension of the one-dimensional tensor is related to the number of operator channels; Based on the one-dimensional tensor, the operator's deviation is rounded down. If the operator has a bias and the bias amount is consistent with the dimension of the bias, then during the model deployment phase, the rounded bias amount is superimposed on the quantized bias to compensate for the bias of the operator. If the operator has no bias, then the bias of the operator is compensated by adding vector addition operations of integer type during the operation.
10. The error compensation method in optical computing according to claim 1, characterized in that, The neural network model contains different types of operators, including linear operators, convolution operators, and fully connected operators.
11. An error compensation device for optical computing, characterized in that, The device includes: The data acquisition module is used to acquire the weight values and activation values of each layer in the neural network model; and based on the neural network model of that layer, to perform quantization processing on the acquired weight values and activation values to obtain quantized weight values and activation values. The compensation module is used to perform optical calculations on the quantized weight values and quantized activation values for each operator in the neural network model, and to perform dequantization to obtain the optical calculation results. The optical calculation results are compared with the theoretical calculation results to obtain the deviation amount generated by the operator in the optical calculation, and the operator is compensated and adjusted according to the deviation amount.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the error compensation method in optical computing as described in any one of claims 1 to 10.
13. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the error compensation method in optical computing as described in any one of claims 1 to 10.