A federated learning training method based on mixed precision quantization and simulated annealing pruning

By using mixed-precision quantization and simulated annealing pruning technology in federated learning, the bit width is dynamically adjusted and pruned according to the characteristics of the network layer, which solves the problem of low communication efficiency in federated learning and achieves more efficient data transmission and more accurate Industrial product testing.

CN118364897BActive Publication Date: 2024-09-03XIANGJIANG LAB
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410765183.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-03
Estimated Expiration
2044-06-14

AI Technical Summary

Technical Problem

Frequent communication exchanges in federated learning result in limited device uplink bandwidth, which becomes a performance bottleneck. Existing quantification methods ignore the characteristics of different network layers and the model pruning search space is too large, making it difficult to effectively reduce communication overhead and improve transmission efficiency.

Method used

A federated learning training method based on mixed-precision quantization and simulated annealing pruning is used to quantify different network layers through multi-scale bit widths, and an enhanced simulated annealing search algorithm is used to solve the layer pruning rate, reduce model parameters and improve communication and data transmission efficiency.

Benefits of technology

It significantly reduces the amount of data and communication costs, improves the overall communication and data transmission efficiency of federated learning, and improves the accuracy of surface defect detection of industrial products.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118364897B
    Figure CN118364897B
Patent Text Reader

Abstract

The present invention provides a federated learning training method based on mixed precision quantization and simulated annealing pruning. The original global model is initialized and quantized by a central server, and then sent to multiple local industrial devices for dequantization processing together with the training task, and trained through local industrial product images to obtain a local model; mixed precision quantization and pruning are performed on the local model in each local industrial device to obtain a quantization loss function and a pruned loss function; each local industrial device calculates the comprehensive loss according to the quantization loss function and the pruned loss function, iteratively updates the local model, and then uploads it to the central server for dequantization processing and aggregation to obtain a global model to determine whether the preset training conditions are met; if so, the training ends; otherwise, the global model is used as the original global model, and returns to execute initialization and quantization processing; the overall communication and data transmission efficiency of federated learning is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of federated learning technology, and in particular to a federated learning training method based on mixed precision quantization and simulated annealing pruning. Background Art

[0002] Federated learning is a decentralized machine learning method that supports multiple clients to collaboratively train machine learning models while saving all data on local devices without uploading original data. This technology effectively protects user data privacy while ensuring the efficiency of model transmission and aggregation. Although federated learning has the above advantages and broad application prospects, it still has some key challenges. For example, federated learning requires the server to communicate with multiple clients. The overhead caused by these frequent communication exchanges is quite large, and the device uplink bandwidth is limited, which becomes a bottleneck for the performance of the federated learning system. However, challenges such as lightweight federated learning network solutions that balance communication efficiency and performance assurance have not yet been explored. Therefore, reducing communication overhead and improving transmission efficiency are crucial for federated learning.

[0003] Research shows that appropriately reducing neural network parameters will not significantly reduce the accuracy of the model, but it can significantly reduce the size of the model and reduce resource consumption. Driven by these theories and research, federated learning has introduced model compression methods to simplify the model and reduce communication transmission costs. At present, the existing scheme mainly achieves a trade-off between model computation and accuracy by reducing parameter redundancy in the neural network, while compressing the model network structure to reduce resource usage while causing relatively little impact on model detection accuracy. Weight compression acceleration mainly includes methods such as model pruning and model quantization. Model pruning mainly removes unimportant weights to achieve weight sparsity to reduce the complexity and computational burden of the model; weight quantization mainly refers to the expression of the weights of the neural network model in a low-precision manner. Compared with the floating-point numbers commonly used in general models to express data types, quantization adjusts them to low-order fixed-point integers, thereby reducing the size of the overall model parameters and improving the inference speed.

[0004] Although these methods have made some progress in reducing the communication cost of federated learning, they still have certain limitations. For example, existing quantization methods usually only consider fixed bit width strategies and ignore the characteristics of different network layers, and model pruning has the problem of too large a search space.

[0005] At present, federated learning is also widely used in detection in industrial scenarios. For example, in factory environments, cameras and sensors are used to detect production links. These devices have certain computing capabilities, but the computing capabilities are weak. How to use the computing power of these devices through federated learning to detect surface defects of products on the production line, thereby effectively improving the yield rate, remains to be explored. Summary of the invention

[0006] The present invention provides a federated learning training method based on mixed precision quantization and simulated annealing pruning, the purpose of which is to perform mixed precision quantization on different network layers in a local model through multi-scale bit widths, thereby improving the overall communication and data transmission efficiency of federated learning, thereby improving the surface defect detection accuracy of products on the production line.

[0007] In order to achieve the above object, the present invention provides a federated learning training method based on mixed precision quantization and simulated annealing pruning, comprising:

[0008] Step 1: The central server initializes the model parameters of the original global model to obtain the initialized global model, and then quantizes the initialized global model and sends it to multiple local industrial devices together with the training task.

[0009] Step 2: for each local industrial device, the local industrial device performs dequantization processing on the quantized initialized global model, and trains the dequantized initialized global model through the local industrial product images collected by the local industrial device to obtain a local model;

[0010] Step 3: In each local industrial device, a multi-scale bit width is selected according to the sensitivity characteristics of the model parameters of the local model, and mixed precision quantization is performed on different network layers in the local model through the multi-scale bit width to obtain a quantization loss function;

[0011] Step 4: In each local industrial device, the layer pruning rate of the local model is solved by an enhanced simulated annealing search algorithm, and the local model is pruned using the layer pruning rate to obtain a pruned loss function;

[0012] Step 5: Each local industrial device calculates the comprehensive loss based on the quantized loss function and the pruned loss function, and uses the comprehensive loss to iteratively update the local model to obtain a local sparse model and upload it to the central server;

[0013] Step 6: The central server performs dequantization processing on all local sparse models respectively, and aggregates all the dequantized local sparse models to obtain a global model;

[0014] Step 7, determine whether the global model meets the preset training conditions; if so, the training is completed and a global model for surface defect detection of industrial products is obtained; otherwise, the global model is used as the original global model in step 1, and return to execute step 1.

[0015] More specifically, the model parameters include:

[0016] Model structure parameters, network initial parameters, hyperparameters, regularization parameters and loss functions.

[0017] More specifically, step 3 includes:

[0018] In each local industrial device, the quantization bit width is automatically selected by comparing the standard deviation of the weight value of each network layer in the local model with the quartile of the series composed of the standard deviation of the weights of all network layers in the local model;

[0019] Calculate the quantization scaling factor by the quantization bit width;

[0020] Calculate the zero reference value by using the model parameters and the quantization scaling factor of the local model;

[0021] The model parameters of the quantized local model are obtained by solving the quantized scaling factor and the zero reference value;

[0022] The quantized local model is dequantized using the model parameters, zero reference value, and quantization scaling factor of the quantized local model to obtain a quantization loss function.

[0023] To further explain, the value of the quantization bit width is:

[0024]

[0025] in, Indicates The quantization bit width of each network layer is , Indicates The standard deviation of the weight values ​​of the network layers, Represents the sequence composed of the standard deviation of all network layer weights, Representing a sequence The lower quartile of Representing a sequence The upper quartile of Both represent the scale of quantization bit width.

[0026] Furthermore, by quantizing the bit width Calculate quantization scaling factor The expression is:

[0027]

[0028] Model parameters via local model , quantization scaling factor Calculating Zero Reference Value The expression is:

[0029]

[0030] By quantizing the scaling factor and zero reference value Solve to obtain the model parameters of the quantized local model The expression is:

[0031]

[0032] Using the model parameters of the quantized local model , quantization scaling factor , zero reference value The expression for dequantizing the quantized local model is:

[0033]

[0034] Calculate the quantization loss function The expression is:

[0035]

[0036] in, It is an intermediate expression and has no specific meaning. , represents the quantization scaling factor, represents the zero reference value, represents the maximum value of the model parameter, represents the truncation function, represents the minimum value of the model parameter, represents the final quantized integer model parameters, represents the model parameters of the quantized local model after dequantization, represents the original loss function of the local model, represents the quantization error, represents the weight factor, represents the adjustment factor, represents the L1 regularization term.

[0037] More specifically, step 4 includes:

[0038] Initialize the layer pruning rate of the local model;

[0039] Generate a new layer pruning rate by adding disturbance to the initialized layer pruning rate, and constrain the new layer pruning rate so that the new layer pruning rate is less than or equal to the total pruning rate of the local model;

[0040] The model accuracy of the local model pruned and quantified by the new layer pruning rate is used as the fitness evaluation indicator;

[0041] According to the rules of the simulated annealing search algorithm and the fitness evaluation index, the new layer pruning rate is accepted or rejected until the current round of search is completed, and the layer pruning rate that meets the preset requirements under the current total pruning rate is output;

[0042] The local model is pruned using a layer pruning rate that meets the preset requirements to obtain the pruned loss function.

[0043] Furthermore, the expression of the loss function after pruning is:

[0044]

[0045] in, represents the regularization term, represents the model parameters of the pruned local model, Indicates convolution kernels, Indicates the number of network layers, Indicates The number of convolution kernels in each network layer, represents the regularization coefficient.

[0046] More specifically, step 6 includes:

[0047] The central server performs dequantization processing on all local sparse models respectively to obtain the model parameters of the local sparse models after dequantization processing. The expression is as follows:

[0048]

[0049] All the local sparse models after dequantization are processed by FedAvg method Perform average aggregation to obtain the global model. The expression of average aggregation is:

[0050]

[0051] in, Represents the model parameters of each local sparse model after the server-side dequantization process; Indicates that the server has received the local model parameters uploaded by the client; Represents the aggregated global model, i.e., the initial global model parameters for the next round of federated learning; Express The average aggregation is performed on the clients for federated learning.

[0052] The above scheme of the present invention has the following beneficial effects:

[0053] The present invention initializes the model parameters of the original global model through a central server to obtain an initialized global model, and quantizes the initialized global model and sends it to multiple local industrial devices simultaneously with the training task; each local industrial device dequantizes the quantized initialized global model, and trains the dequantized initialized global model through local industrial product images to obtain a local model; in each local industrial device, multi-scale bit widths are selected according to the sensitive characteristics of the model parameters of the local model to perform mixed precision quantization on the local model to obtain a quantization loss function; in each local industrial device, the layer pruning rate is solved by an enhanced simulated annealing search algorithm, and the local model is pruned using the layer pruning rate to obtain a pruned loss function; each local industrial device calculates a comprehensive loss based on the quantization loss function and the pruned loss function, and iteratively updates the local model using the comprehensive loss to obtain a local sparse model and upload it to the central server; the central The server performs inverse quantization processing on all local sparse models respectively, and aggregates all the local sparse models after the inverse quantization processing to obtain a global model; determines whether the global model meets the preset training conditions; if so, the training is terminated to obtain a global model for surface defect detection of industrial products; otherwise, the global model is used as the original global model in step 1, and returns to execute step 1; compared with the prior art, the present invention selects multi-scale bit widths according to the sensitive characteristics of the model parameters of the local model to perform mixed precision quantization on the local model, which significantly reduces the amount of data in the aggregation process and achieves the effect of accelerated aggregation, and solves the layer pruning rate through the enhanced simulated annealing search algorithm, and uses the layer pruning rate to prune the local model to obtain a local sparse model, only updates key and valid data, and effectively improves the overall communication and data transmission efficiency of federated learning, and performs industrial product surface defect detection through the global model, which also improves the product surface defect detection accuracy of the production line.

[0054] Other beneficial effects of the present invention will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] Figure 1 A schematic diagram of a flow chart of an embodiment of the present invention;

[0056] Figure 2 It is a schematic diagram of the framework of an embodiment of the present invention. DETAILED DESCRIPTION

[0057] In order to make the technical problems, technical solutions and advantages to be solved by the present invention clearer, the following will be described in detail with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0058] In the description of the present invention, it should be noted that the terms “first”, “second” and “third” are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.

[0059] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installation", "connection" and "connection" should be understood in a broad sense, for example, it can be a locking connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0060] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0061] In view of the existing problems, the present invention provides a federated learning training method based on mixed precision quantization and simulated annealing pruning.

[0062] In an embodiment of the present invention, the framework of federated learning includes: a central server and multiple local clients;

[0063] The global model is a deep convolutional neural network Resnet-50, which is commonly used for image detection and classification tasks.

[0064] The federated learning process is as follows:

[0065] The local industrial equipment is used as the local client in the federated learning. In the embodiment of the present invention, the local industrial equipment can be a visual device in the production workshop, such as a camera or sensor on the production line, which is used to collect industrial product images as a local data set. The products can be steel, puppet toys, etc. The local industrial product images are used to train the quantized initialized global model sent by the central server to obtain a local model;

[0066] In the embodiment of the present invention, the central server in the federated learning can be a computing device such as a desktop computer, a notebook, a PDA, a server, a server cluster, and a cloud server, which is used to construct the original global model, initialize and quantize the original global model, and perform dequantization on the local sparse models uploaded by multiple local industrial devices and then aggregate them to obtain the global model;

[0067] Finally, the global model is used to perform surface defect detection on the image data of the industrial product to be inspected. For example, when the global model performs surface defect detection on the steel image, the detection result is whether the steel has dents, cracks, etc. When the global model performs surface defect detection on the puppet toy image, the detection result is whether the puppet toy has exposed fillings, etc.

[0068] like Figure 1 , Figure 2 As shown, an embodiment of the present invention provides a federated learning training method based on mixed precision quantization and simulated annealing pruning, including:

[0069] Step 1: The central server initializes the model parameters of the original global model to obtain the initialized global model, and then quantizes the initialized global model and sends it to multiple local industrial devices together with the training task.

[0070] Step 2: for each local industrial device, the local industrial device performs dequantization processing on the quantized initialized global model, and trains the dequantized initialized global model through the local industrial product images collected by the local industrial device to obtain a local model;

[0071] Step 3: In each local industrial device, a multi-scale bit width is selected according to the sensitivity characteristics of the model parameters of the local model, and mixed precision quantization is performed on different network layers in the local model through the multi-scale bit width to obtain a quantization loss function;

[0072] Step 4: In each local industrial device, the layer pruning rate of the local model is solved by an enhanced simulated annealing search algorithm, and the local model is pruned using the layer pruning rate to obtain a pruned loss function;

[0073] Step 5: Each local industrial device calculates the comprehensive loss based on the quantized loss function and the pruned loss function, and uses the comprehensive loss to iteratively update the local model to obtain a local sparse model and upload it to the central server.

[0074] Step 6: The central server performs dequantization processing on all local sparse models respectively, and aggregates all the dequantized local sparse models to obtain a global model;

[0075] Step 7, determine whether the global model meets the preset training conditions; if so, the training is completed and a global model for surface defect detection of industrial products is obtained; otherwise, the global model is used as the original global model in step 1, and return to execute step 1.

[0076] Specifically, in step 1, the central server initializes the model parameters of the original global model, including model structure parameters, network initial parameters, hyperparameters, regularization parameters, and loss functions. The central server also needs to initialize other settings including data privacy and security policies, client selection and management, communication policies, client training configuration, resource allocation and scheduling. The central server first quantizes the initialized global model, and then selects local industrial devices participating in this round of iteration, and broadcast the quantized initialized global model to them And this round of training tasks, the quantized initialized global model is sent to each local industrial device.

[0077] Specifically, step 2 includes:

[0078] After receiving the quantized initialized global model, each local industrial device will first dequantize it to obtain the model parameters of the quantized initialized global model. ;

[0079] Secondly, each participating local industrial equipment uses the collected local data, that is, the visual inspection data in the industrial scene, such as industrial product images under normal and abnormal conditions, sensor data collected on each production line, quality control data, and machine operation status data, to train a local model on the local industrial equipment. .

[0080] Specifically, step 3 includes:

[0081] In each local industrial device, the quantization bit width is automatically selected by comparing the standard deviation of the weight value of each network layer in the local model with the quartile of the series composed of the standard deviation of the weights of all network layers in the local model;

[0082] Calculate the quantization scaling factor by the quantization bit width;

[0083] Calculate the zero reference value by using the model parameters and the quantization scaling factor of the local model;

[0084] The model parameters of the quantized local model are obtained by solving the quantized scaling factor and the zero reference value;

[0085] The quantized local model is dequantized using the model parameters, zero reference value, and quantization scaling factor of the quantized local model to obtain a quantization loss function.

[0086] The process of solving the quantization loss function is as follows:

[0087] Quantization is to optimize the parameter type of the entire local model. The storage type of the model parameters is generally float32, which can be converted into low-precision formats such as int16 and int8. Therefore, the use of quantization processing can significantly reduce the amount of data to be transmitted, which helps to reduce communication costs. The embodiment of the present invention selects a logarithmic-based mixed precision quantization scheme to quantize the local model, which is as follows:

[0088] By setting the bit width and the model parameters of the local model Determine the parameter mapping factors as:

[0089]

[0090] in, It is an intermediate expression and has no specific meaning. , represents the quantization scaling factor, The mapping relationship between the input parameter data distribution and the quantized tensor is established by scaling the parameter range. In order to further achieve the transformation, the zero reference value needs to be determined. , which depends on the location and distance distribution of the model parameter extreme values;

[0091] The quantization scaling factor is The model parameters of the quantized local model are obtained by solving the reference value for:

[0092]

[0093]

[0094] in, represents the maximum value of the model parameter, represents the truncation function, represents the minimum value of the model parameter, represents the final quantized integer model parameters, Represents the rounding function.

[0095] Since a single-bit-width quantization method is used, there is a problem of ignoring the different sensitivities of different network layers to the quantization bit width, resulting in a certain quantization loss. To this end, the embodiment of the present invention uses a weighted mixed-precision quantization strategy based on the data standard deviation, and uses bit widths of different scales to improve the logarithmic quantization effect by taking advantage of the different sensitivities of different bit widths. In the embodiment of the present invention, taking the convolutional layer in the deep convolutional neural network Resnet-50 as an example, by comparing the standard deviation of the weight value of each convolutional layer with the quartiles of the series composed of the standard deviations of the weights of all convolutional layers in the convolutional neural network Resnet-50, the number of quantization bits is automatically selected, so that the model can dynamically quantize the parameter values ​​according to the data distribution characteristics of different convolutional layers, thereby obtaining a better model quantization effect; for example, for the first The standard deviation of the data of the convolutional layer is , is a sequence of standard deviations of all convolutional layers, Representing a sequence The lower quartile of Representing a sequence The upper quartile of quantization bit width The value of is:

[0096]

[0097] in, Both represent the scale of quantization bit width.

[0098] After determining the quantization bit width, Calculate quantization scaling factor The expression is:

[0099]

[0100] Model parameters via local model , quantization scaling factor Calculating Zero Reference Value The expression is:

[0101]

[0102] By quantizing the scaling factor and zero reference value Solve to obtain the model parameters of the quantized local model The expression is:

[0103]

[0104] After quantization, it is usually necessary to restore the model parameters by dequantization to evaluate the quantization error. Therefore, the model parameters of the quantized local model are used. , quantization scaling factor , zero reference value The expression for dequantizing the quantized local model is:

[0105]

[0106] Calculate the quantization loss function , quantization loss function It consists of quantization error and regularization term, and the expression is:

[0107]

[0108] in, represents the model parameters of the quantized local model after dequantization, represents the quantization error, that is, the difference between the original data and the dequantized data, represents the weight factor used to balance the importance of original loss and quantization error, Represents the adjustment factor, which is used to control the influence of the regularization term. represents the L1 regularization term, which is the sum of the absolute values ​​of all parameters, used to promote the sparsity of parameters. The quantization loss function is adjusted by and to find the best balance between quantization error, model performance and parameter sparsity. Represents the original loss function of the global model, which refers to the loss function used to train the model before quantizing the model. The choice of this loss function depends on the specific federated learning task and model type. In the embodiment of the present invention, the cross entropy loss is used as the original loss function for training the deep convolutional neural network Resnet-50. For a single sample, the cross entropy loss function The expression is:

[0109]

[0110] in, represents the total number of categories, represents the one-hot encoding of the true label, Represents the probability distribution predicted by the model, obtained through the softmax function, The one-hot encoding of the true label elements, Indicates the model prediction The probability of a class.

[0111] Specifically, step 4 includes:

[0112] Initialize the layer pruning rate of the local model;

[0113] Generate a new layer pruning rate by adding perturbation to the initialized layer pruning rate, and constrain the new layer pruning rate so that the new layer pruning rate is less than or equal to the total pruning rate of the local model;

[0114] The model accuracy of the local model pruned and quantified by the new layer pruning rate is used as the fitness evaluation indicator;

[0115] According to the rules of the simulated annealing search algorithm and the fitness evaluation index, the new layer pruning rate is accepted or rejected until the current round of search is completed, and the layer pruning rate that meets the preset requirements under the current total pruning rate is output;

[0116] The local model is pruned using a layer pruning rate that meets the preset requirements to obtain the pruned loss function.

[0117] The parameters after the above-mentioned L1 regularization are more sparse and can better adapt to the subsequent pruning. In view of the different redundancy levels of different network layers, the embodiment of the present invention calculates the sum of the absolute weights of the filters through local industrial equipment and sorts them, and uses the enhanced simulated annealing search algorithm (ESA, Enhanced Simulated Annealing), which mainly includes two parts: filter pruning and adaptive layer pruning rate solution; the filter pruning method is to select less useful filters from the above-mentioned quantized local model for pruning, while considering quantization and pruning losses to improve computational efficiency and minimize the decline in accuracy; the pruning rate of each layer of the model is an important factor affecting the pruning effect. If the pruning ratio in any layer is too low, the compression degree is insufficient, and if it is too high, it will make it difficult to restore the accuracy. For this reason, an enhanced simulated annealing algorithm is introduced in pruning to adaptively determine the optimal layer pruning rate distribution of the entire model and search for the current total pruning rate. The optimal layer pruning rate under (initial value is 0.1) .

[0118] The embodiment of the present invention introduces ESA in pruning to realize adaptive layer pruning rate solution. ESA takes the simulated annealing algorithm SA as the basic framework. First, the layer pruning rate is initialized. , is the number of convolutional layers of the model, and the pruning rate of new layers is generated by adding perturbations , and constrain it to be less than or equal to the total pruning rate ,Right now:

[0119]

[0120] In the formula, Indicates the current temperature The relevant disturbance variable, Express The resulting new vector is summed up.

[0121] In order to quickly explore the optimal solution for the layer pruning rate, The fitness evaluation of should meet the requirements of fast and accurate. To this end, directly Model accuracy after pruning and quantization As a fitness evaluation to meet the rapidity requirement, and then accept or reject according to the SA rule , until this round of annealing search is completed, and the current total pruning rate is output The optimal layer pruning rate under And the pruned local model ; Then, quickly fine-tune the recovery model accuracy on the validation set, and comprehensively analyze the accuracy and parameter compression ratio and inference acceleration Comprehensively evaluate the pruned local model , called comprehensive evaluation, expressed as:

[0122]

[0123] In the formula, and Respectively represent the parameters of the local model and the current pruned local model, and are the inference time of the two models respectively;

[0124] To maximize the compression of the model, the total pruning rate is increased cyclically And perform ESA until the total pruning rate , output the pruning rate of the layer with the maximum Q value and the pruned local model, and retrain to obtain a pruned local model with high recognition rate, lighter and faster .

[0125] In addition, the filter pruning method in the embodiment of the present invention measures the relative importance of filters in each layer by calculating the sum of the absolute weights of the filters; this value is the expected value of the output feature map magnitude. Compared with other filters in the layer, filters with smaller kernel weights tend to generate feature maps with weaker activation. Therefore, by removing these convolution kernels of the network and their feature maps, the computational cost can be greatly reduced.

[0126] set up Indicates The number of input channels of the convolutional layer is Convolutional layer pruning The specific process of each filter is as follows:

[0127] First, for each filter , calculate the sum of their absolute kernel weights ,for The number of 2D kernels for the channel;

[0128] Secondly, press Sort filters;

[0129] Next, use the smallest sum value and its corresponding feature map to prune filters; the kernel in the next convolutional layer corresponding to the pruned feature map is also deleted;

[0130] Finally, for the Layer and The layer creates a new kernel matrix and copies the remaining kernel weights back into the new model, pruning the first Layer The filter will reduce the Layer and Layer Calculate the cost.

[0131] In summary, the loss function after pruning is From the previous loss function And regularization term, the expression is:

[0132]

[0133] in, represents a regularization term. In the embodiment of the present invention, the L2 norm of the weight is used to penalize large weight values, thereby prompting the network to remain stable during the pruning process. represents the model parameters of the pruned local model, Indicates convolution kernels, Indicates the number of network layers, Indicates The number of convolution kernels in each network layer, Represents the regularization coefficient, which is used to balance the importance between data loss and regularization term.

[0134] The embodiment of the present invention adjusts the pruning ratio according to the performance feedback of the model. If the performance loss is acceptable, a higher pruning ratio can be tried to reduce more weights. If the performance loss is too large, the pruning ratio may need to be reduced. In the above pruning process, some convolution kernels are removed and the corresponding model parameters are also removed from the calculation. The pruned network has exactly the same structure, but with fewer filters and channels; the loss function It will reflect the changes in the structure of the federated learning network and guide the adjustment of network parameters during the training process. At the same time, the loss function can be adjusted by and To balance the data loss caused by quantization and pruning to the model, so as to achieve a balance between performance and accuracy loss of the model.

[0135] Specifically, step 5 includes:

[0136] Each local industrial device calculates the comprehensive loss based on the quantized loss function and the pruned loss;

[0137]

[0138] The comprehensive loss is the loss after joint quantization and pruning , which includes the quantized loss and the regularization term of pruning, and the quantized loss contains the original loss function of the model (such as cross entropy loss, mean square error loss function, etc., depending on the specific federated learning task) and quantized regularization terms;

[0139] Use the comprehensive loss to iteratively update the local model to obtain a local sparse model And upload it to the central server, reducing the resource usage of the model in the federated learning network communication transmission.

[0140] Specifically, step 6 includes:

[0141] The central server receives Local sparse models uploaded by local industrial devices After that, all local sparse models are dequantized respectively, and the model parameters of the local sparse model after dequantization are obtained according to the quantization weight, mapping factor and zero reference value of the local industrial equipment. , the expression is as follows:

[0142]

[0143] In order to make the global model more accurately identify and classify industrial images, have better generalization ability, and be widely used in various industrial production environments to improve the accuracy and efficiency of visual inspection, the embodiment of the present invention uses the FedAvg method to convert all local sparse models after dequantization into Perform average aggregation to obtain the global model. The expression of average aggregation is:

[0144]

[0145] in, Represents the model parameters of each local sparse model after the server-side dequantization process; Indicates that the server has received the local model parameters uploaded by the client; Represents the aggregated global model, i.e., the initial global model parameters for the next round of federated learning; Express The average aggregation of federated learning is performed on the clients.

[0146] To verify the technical effect of the method provided in the embodiment of the present invention and compare it with the existing method: the method provided in the embodiment of the present invention is based on logarithmic quantization, combined with the use of standard deviation-based quantization and standard deviation-based weighted hybrid bit quantization method, taking the Resnet50 network as the specific model, and using cross entropy loss as the original loss function for Resnet-50 training.

[0147] The experimental results are compared and analyzed, and it is concluded that the logarithmic mixed precision quantization method based on standard deviation can basically reduce the Top1 accuracy of the quantized model to less than 1% compared with the original model. At the same time, mixed precision quantization can reduce the model size by about 75%, effectively improving the logarithmic quantization effect of single precision, so that the logarithmic quantization model achieves almost the same model accuracy as the original model. After joint quantization and pruning, the model accuracy of the improved model is basically the same as that of the original model, with the maximum difference of only about 1%, that is, joint quantization and pruning will not significantly reduce the accuracy of surface defect detection of industrial products. At the same time, the compression ratio of the model calculation amount and parameter amount is improved, and reasoning acceleration is achieved, that is, the reasoning time is reduced, and the model scale and the hardware threshold for deployment and application are significantly reduced, which has the advantages of saving communication overhead and hardware costs.

[0148] In summary, the embodiment of the present invention initializes the model parameters of the original global model through the central server to obtain the initialized global model, and quantizes the initialized global model and sends it to multiple local industrial devices simultaneously with the training task; each local industrial device dequantizes the quantized initialized global model, and trains the dequantized initialized global model through local data to obtain a local model; in each local industrial device, multi-scale bit widths are selected according to the sensitive characteristics of the model parameters of the local model to perform mixed precision quantization on the local model to obtain a quantization loss function; in each local industrial device, the layer pruning rate is solved by the enhanced simulated annealing search algorithm, and the local model is pruned by the layer pruning rate to obtain the pruned loss function; each local industrial device calculates the comprehensive loss according to the quantization loss function and the pruned loss, and iteratively updates the local model by using the comprehensive loss to obtain a local sparse model and upload it to the central server; the central The server performs inverse quantization processing on all local sparse models respectively, and aggregates all the local sparse models after the inverse quantization processing to obtain a global model; determines whether the global model meets the preset training conditions; if so, the training is terminated to obtain a global model for surface defect detection of industrial products; otherwise, the global model is used as the original global model in step 1, and returns to execute step 1; compared with the prior art, the embodiment of the present invention selects multi-scale bit widths according to the sensitive characteristics of the model parameters of the local model to perform mixed precision quantization on the local model, which significantly reduces the amount of data in the aggregation process and achieves the effect of accelerated aggregation, and solves the layer pruning rate through the enhanced simulated annealing search algorithm, and uses the layer pruning rate to prune the local model to obtain a local sparse model, only updates key and valid data, and effectively improves the overall communication and data transmission efficiency of federated learning, and performs industrial product surface defect detection through the global model, which also improves the product surface defect detection accuracy of the production line.

[0149] The above is a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A federated learning training method based on mixed precision quantization and simulated annealing pruning, characterized in that: include: Step 1: The central server initializes the model parameters of the original global model to obtain an initialized global model, and quantizes the initialized global model and sends it to multiple local industrial devices together with the training task; Step 2: for each of the local industrial devices, the local industrial device performs a dequantization process on the quantized initialized global model, and trains the dequantized initialized global model through the local industrial product images collected by the local industrial device to obtain a local model; Step 3: In each of the local industrial devices, a multi-scale bit width is selected according to the sensitivity characteristics of the model parameters of the local model, and mixed precision quantization is performed on different network layers in the local model by using the multi-scale bit width to obtain a quantization loss function; The step 3 comprises: In each of the local industrial devices, the quantization bit width is automatically selected by comparing the standard deviation of the weight value of each network layer in the local model with the quartile points of the series composed of the standard deviations of the weights of all network layers in the local model; Calculating a quantization scaling factor using the quantization bit width; Calculate a zero reference value using the model parameters of the local model and the quantization scaling factor; Obtaining the model parameters of the quantized local model by solving the quantization scaling factor and the zero reference value; Dequantizing the quantized local model using the model parameters of the quantized local model, the zero reference value, and the quantization scaling factor to obtain a quantization loss function; Step 4: in each of the local industrial devices, the layer pruning rate of the local model is solved by an enhanced simulated annealing search algorithm, and the local model is pruned using the layer pruning rate to obtain a pruned loss function; Step 5, each of the local industrial devices calculates a comprehensive loss according to the quantized loss function and the pruned loss function, and iteratively updates the local model using the comprehensive loss to obtain a local sparse model and upload it to the central server; Step 6, the central server performs dequantization processing on all local sparse models respectively, and aggregates all the dequantized local sparse models to obtain a global model; Step 7, determine whether the global model meets the preset training conditions; if so, the training is completed and a global model for industrial product surface defect detection is obtained; otherwise, the global model is used as the original global model in step 1, and return to execute step 1.

2. The federated learning training method based on mixed precision quantization and simulated annealing pruning according to claim 1, characterized in that: The model parameters include: Model structure parameters, network initial parameters, hyperparameters, regularization parameters and loss functions.

3. The federated learning training method based on mixed precision quantization and simulated annealing pruning according to claim 1, characterized in that: The value of the quantization bit width is: in, Indicates The quantization bit width of each network layer is Indicates the number of network layers, , Indicates The standard deviation of the weight values ​​of the network layers, Represents the sequence composed of the standard deviation of all network layer weights, Representing a sequence The lower quartile of Representing a sequence The upper quartile of Both represent the scale of quantization bit width.

4. The federated learning training method based on mixed precision quantization and simulated annealing pruning according to claim 3 is characterized in that: By the quantization bit width Calculate quantization scaling factor The expression is: ; The model parameters of the local model are , the quantization scaling factor Calculating Zero Reference Value The expression is: ; The quantization scaling factor is and the zero reference value Solve to obtain the model parameters of the quantized local model The expression is: Using the model parameters of the quantized local model , the quantization scaling factor , the zero reference value The expression for performing dequantization processing on the quantized local model is: Calculate the quantization loss function The expression is: in, It is an intermediate expression and has no specific meaning. , represents the quantization scaling factor, represents the zero reference value, represents the maximum value of the model parameter, represents the truncation function, represents the minimum value of the model parameter, represents the final quantized integer model parameters, represents the model parameters of the quantized local model after dequantization, represents the original loss function of the local model, represents the quantization error, represents the weight factor, represents the adjustment factor, represents the L1 regularization term.

5. The method for federated learning training based on mixed precision quantization and simulated annealing pruning according to claim 4, characterized in that: The step 4 comprises: Initializing a layer pruning rate of the local model; Generate a new layer pruning rate by adding disturbance to the initialized layer pruning rate, and constrain the new layer pruning rate so that the new layer pruning rate is less than or equal to the total pruning rate of the local model; Using the model accuracy of the local model pruned and quantized by the new layer pruning rate as a fitness evaluation indicator; According to the rules of the simulated annealing search algorithm and the fitness evaluation index, the new layer pruning rate is selected to be accepted or rejected until the current round of search is completed, and the layer pruning rate that meets the preset requirements under the current total pruning rate is output; The local model is pruned using the layer pruning rate that meets the preset requirements to obtain a pruned loss function.

6. The federated learning training method based on mixed precision quantization and simulated annealing pruning according to claim 5, characterized in that: The loss function after pruning The expression is: in, represents the regularization term, represents the model parameters of the pruned local model, Indicates convolution kernels, Indicates the number of network layers, Indicates The number of convolution kernels in each network layer, represents the regularization coefficient.

7. The method for federated learning training based on mixed precision quantization and simulated annealing pruning according to claim 6, characterized in that: The step 6 comprises: The central server performs dequantization processing on all local sparse models respectively to obtain the model parameters of the local sparse models after dequantization processing. The expression is as follows: All the local sparse models after dequantization are processed by FedAvg method Perform average aggregation to obtain a global model, where the expression of average aggregation is: in, Represents the model parameters of each local sparse model after the server-side dequantization process; Indicates that the server has received the local model parameters uploaded by the client; Represents the aggregated global model, i.e., the initial global model parameters for the next round of federated learning; Express The average aggregation is performed on the clients for federated learning.