Model quantification strategy determination method and device, model quantification method and device, medium and equipment

By automatically selecting and optimizing the model quantification strategy, the problem of complex model quantification operations and difficult adaptation in the existing technology is solved, and the efficient and stable deployment of the model in different hardware environments is achieved.

CN118690871APending Publication Date: 2024-09-24HANGZHOU NETEASE ZHIQI TECH CO LTD
View PDF 0 Cites 9 Cited by

Patent Information

Application Number
CN202410584724.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-11
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Existing model quantification technology is complex to operate and relies on the experience of professionals. It is difficult to ensure the optimal adaptation of the quantification effect to the deployment environment, which limits the rapid deployment ability of quantitative models in new environments.

Method used

Provides a method for determining the model quantization strategy, by automatically selecting an appropriate quantization strategy from a preset quantization strategy set, and continuously iteratively optimizing according to the hardware resources and model performance requirements of the device to be deployed until the optimal solution meets the dual constraints of hardware and performance. Best strategy.

Benefits of technology

It realizes the automatic selection and optimization of model quantification strategies, reduces dependence on the experience of professionals, improves the efficiency and accuracy of the quantification process, and ensures that the model can run efficiently and stably on the equipment to be deployed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690871A
    Figure CN118690871A
Patent Text Reader

Abstract

The embodiment of the invention provides a model quantization strategy determination method, a model quantization strategy determination device, a model quantization method, a model quantization strategy determination device, a model quantization method, a model quantization strategy determination device, a medium and equipment. According to the method, the optimal quantification strategy which simultaneously meets the hardware resource condition and the performance constraint condition of the to-be-deployed equipment is found, so that automatic selection and optimization of the model quantification strategy in a specific deployment environment are realized, and the tedious process of manual adjustment and selection and human intervention are greatly reduced; the hardware resource condition of the to-be-deployed equipment and the performance constraint condition of the quantized model are comprehensively considered, and the efficiency and the accuracy of determining the model quantification strategy are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure relate to the field of data processing technology. More specifically, the embodiments of the present disclosure relate to model quantization strategy determination and model quantization methods, devices, media and equipment. Background Art

[0002] This section is intended to provide a background or context to the embodiments of the disclosure that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.

[0003] With the continuous development of deep learning, the expansion of model scale has led to an increasing demand for model computing resources, which has limited the widespread deployment and application of models. Based on this, model quantization technology has emerged, which reduces the model parameters and calculation accuracy, reduces the model's demand for hardware memory, and enables the model to run in an environment with limited resources.

[0004] In the related technologies, the application of quantization technology in complex neural network structures such as transformer models has made significant progress. For example, a quantization strategy is proposed to quantize the weights of the attention layer and feedforward layer of the transformer model to the int8 (8-bit Integer, 8-bit signed integer) format, which halved the model's video memory requirements without causing significant loss of accuracy. In addition, for the GPT (Generative Pre-trained Transformer) model, it is proposed to use approximate second-order information to achieve a deeper quantization process, which can quantize the model weights to 3 bits or 4 bits, further reducing the storage and computing costs of the model.

[0005] However, existing quantitative techniques still have certain limitations. The quantitative process usually requires complex manual selection and adjustment based on the experience and judgment of professionals. The operation is complex and time-consuming, making it difficult to ensure the optimal adaptation of the quantitative effect to the deployment environment, and limiting the ability of quantitative models to be quickly deployed in new environments. Summary of the invention

[0006] In view of this, in order to solve the above problems, the embodiments of the present disclosure are expected to provide a model quantization strategy determination method and a model quantization method, as well as a device, a medium and a computing device corresponding to the method. Specifically, the present disclosure is implemented through the following technical solutions:

[0007] In a first aspect of the embodiments of the present disclosure, a method for determining a model quantization strategy is provided, the method comprising:

[0008] Obtaining a first quantization strategy for a target model from a preset quantization strategy set;

[0009] Determine the hardware resource requirements of the target model under the first quantization strategy, and obtain a performance evaluation result of the target model after quantization using the first quantization strategy;

[0010] When the hardware resource requirement does not match the hardware resource condition of the device to be deployed, or the performance evaluation result does not meet the preset performance constraint condition, update the first quantization strategy using other quantization strategies in the quantization strategy set except the first quantization strategy until both the hardware resource condition and the performance constraint condition are met;

[0011] The first quantization strategy is determined as the model quantization strategy when the target model is deployed to the device to be deployed.

[0012] Optionally, after determining the hardware resource requirement, the method further includes:

[0013] Compare the hardware resource requirement with the hardware resource condition of the device to be deployed, and generate a matching result between the hardware resource requirement and the hardware resource condition;

[0014] The obtaining a performance evaluation result of the target model after quantization using the first quantization strategy includes:

[0015] When the hardware resource requirement matches the hardware resource condition, quantizing the target model according to the first quantization strategy;

[0016] Obtain the performance evaluation results of the quantized target model.

[0017] Optionally, the hardware resource condition includes resource thresholds of different hardware resources; the hardware resource requirement includes requirement values ​​for the different hardware resources; and comparing the hardware resource requirement with the hardware resource condition of the device to be deployed to generate a matching result between the hardware resource requirement and the hardware resource condition includes:

[0018] Comparing the demand value of the same hardware resource with the corresponding resource threshold;

[0019] In a case where each requirement value is less than or equal to the corresponding resource threshold, it is determined that the hardware resource requirement matches the hardware resource condition.

[0020] Optionally, before determining that the hardware resource requirement matches the hardware resource condition, the method further includes:

[0021] When each requirement value is less than or equal to the corresponding resource threshold, obtaining the hardware resource requirement of each layer of the target model;

[0022] Determine the maximum demand value of each hardware resource according to the hardware resource demand of each layer of the network, and compare the maximum demand value with the corresponding resource threshold;

[0023] When the maximum demand value of each hardware volunteer is less than or equal to the corresponding resource threshold, it is determined that the hardware resource demand matches the hardware resource condition.

[0024] Optionally, when the hardware resource requirement does not match the hardware resource condition of the device to be deployed, the updating of the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy includes:

[0025] Determining resource types that do not match the hardware resource condition;

[0026] Determining a candidate quantization strategy from the quantization strategy set according to the degree of influence of the quantization strategy on the hardware resources of the resource type;

[0027] According to the parameter combination of the first quantization strategy, a second quantization strategy is determined from the candidate quantization strategies to update the first quantization strategy.

[0028] Optionally, when the hardware resource requirement matches the hardware resource condition and the performance evaluation result does not meet the performance constraint condition, updating the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy includes:

[0029] The performance evaluation result and the first quantization strategy are used as inputs of a preset optimization algorithm to obtain a third quantization strategy for iterative search by the optimization algorithm; and the first quantization strategy is updated according to the third quantization strategy.

[0030] Optionally, when the hardware resource requirement matches the hardware resource condition and the performance evaluation result does not meet the performance constraint condition, updating the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy includes:

[0031] According to the performance evaluation result and the parameter combination of the first quantization strategy, a quantization strategy parameter combination that meets the performance constraint condition is determined; according to the quantization strategy parameter combination, a quantization strategy with the highest matching degree in the quantization strategy set is determined to update the first quantization strategy.

[0032] Optionally, the updating the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy until the hardware resource condition and the performance constraint condition are simultaneously satisfied includes:

[0033] If the preset policy update stop condition is not met,

[0034] If other quantization strategies are searched to update the first quantization strategy, continue to update the first quantization strategy until both the hardware resource condition and the performance constraint condition are satisfied;

[0035] If no other quantitative strategies are found, then the updating of the first quantitative strategy is stopped; the strategy update stopping condition includes at least one of the longest strategy update time and the maximum strategy update rounds;

[0036] When the policy update stopping condition is met, the updating of the first quantization policy is stopped, and prompt information is controlled to be displayed on the quantization interaction interface, so that the user can perform adjustment operations according to the prompt information.

[0037] Optionally, the method further comprises:

[0038] Receive the model information of the target model, the hardware resource conditions of the device to be deployed, and the performance constraint conditions input by the user on the quantization interaction page;

[0039] In response to receiving the start indication information from the quantization interaction page, the target model is loaded from a predefined model library according to the model information, and the first quantization strategy is obtained from a preset quantization strategy set.

[0040] Optionally, the method further comprises:

[0041] Receive the verification data set uploaded by the user on the quantitative interaction page;

[0042] The obtaining a performance evaluation result of the target model after quantization using the first quantization strategy includes:

[0043] Obtain a performance evaluation result of the target model quantized by the first quantization strategy on the validation data set.

[0044] Optionally, the method further comprises:

[0045] According to the validation data set, obtaining an unquantized performance result of the target model that has not been quantified;

[0046] In the case of receiving a performance constraint condition input by a user, in response to the performance constraint condition being higher than the unquantified performance result, controlling the display of the unquantified performance result on the quantified interaction page, and instructing the user to adjust the performance constraint condition;

[0047] In a case where the performance constraint condition input by the user is not received, the performance constraint condition is determined according to the unquantified performance result.

[0048] Optionally, the performance constraint condition includes at least one performance indicator threshold; the performance indicator threshold is determined according to the unquantified performance result; after obtaining the performance evaluation result of the target model after quantization using the first quantization strategy, the method further includes:

[0049] Determine the difference between each performance indicator in the performance evaluation result and the corresponding performance indicator threshold;

[0050] When the difference amount of each performance indicator satisfies the set difference range, it is determined that the performance evaluation result meets the performance constraint condition.

[0051] Optionally, the quantization strategy set includes at least one of bit width quantization strategies for different quantization bit widths, linear quantization strategies and nonlinear quantization strategies, and object quantization strategies for different quantization objects.

[0052] In a second aspect of the embodiments of the present disclosure, a model quantization method is provided, the method comprising:

[0053] Determine a target quantization strategy for a target model used by the device to be deployed, wherein the target quantization strategy is determined using the above-mentioned model quantization strategy determination method;

[0054] The target model is quantified according to the target quantization strategy, and the quantified target model is deployed to the device to be deployed to provide corresponding services.

[0055] In a third aspect of the embodiments of the present disclosure, a device for determining a model quantization strategy is provided, the device comprising:

[0056] An initialization module, used for obtaining a first quantization strategy of a target model from a preset quantization strategy set;

[0057] A resource requirement and performance evaluation module, used to determine the hardware resource requirements of the target model under the first quantization strategy, and obtain a performance evaluation result of the target model after quantization using the first quantization strategy;

[0058] A policy updating module, configured to update the first quantization policy by using other quantization policies in the quantization policy set except the first quantization policy, when the hardware resource requirement does not match the hardware resource condition of the device to be deployed, or the performance evaluation result does not meet the preset performance constraint condition, until both the hardware resource condition and the performance constraint condition are met;

[0059] A quantization strategy determination module is used to determine the first quantization strategy as the model quantization strategy when the target model is deployed to the device to be deployed.

[0060] Optionally, after determining the hardware resource requirement, the apparatus may further include: a hardware resource matching detection module, configured to compare the hardware resource requirement with the hardware resource condition of the device to be deployed, and generate a matching result between the hardware resource requirement and the hardware resource condition;

[0061] The resource demand and performance evaluation module is specifically used for:

[0062] When the hardware resource requirement matches the hardware resource condition, the target model is quantized according to the first quantization strategy; and a performance evaluation result of the quantized target model is obtained.

[0063] Optionally, the hardware resource condition includes resource thresholds of different hardware resources; the hardware resource requirement includes requirement values ​​for the different hardware resources; and the hardware resource matching detection module is specifically used to:

[0064] Comparing the demand value of the same hardware resource with the corresponding resource threshold;

[0065] In a case where each requirement value is less than or equal to the corresponding resource threshold, it is determined that the hardware resource requirement matches the hardware resource condition.

[0066] Optionally, when each demand value is less than or equal to a corresponding resource threshold, before determining that the hardware resource demand matches the hardware resource condition, the apparatus further includes:

[0067] When each requirement value is less than or equal to the corresponding resource threshold, obtaining the hardware resource requirement of each layer of the target model;

[0068] Determine the maximum demand value of each hardware resource according to the hardware resource demand of each layer of the network, and compare the maximum demand value with the corresponding resource threshold;

[0069] When the maximum demand value of each hardware volunteer is less than or equal to the corresponding resource threshold, it is determined that the hardware resource demand matches the hardware resource condition.

[0070] Optionally, when the hardware resource requirement does not match the hardware resource condition of the device to be deployed, the policy updating module is specifically configured to:

[0071] Determining resource types that do not match the hardware resource condition;

[0072] Determining a candidate quantization strategy from the quantization strategy set according to the degree of influence of the quantization strategy on the hardware resources of the resource type;

[0073] According to the parameter combination of the first quantization strategy, a second quantization strategy is determined from the candidate quantization strategies to update the first quantization strategy.

[0074] Optionally, when the hardware resource requirement matches the hardware resource condition and the performance evaluation result does not meet the performance constraint condition, the policy updating module is specifically configured to:

[0075] Using the performance evaluation result and the first quantization strategy as inputs of a preset optimization algorithm, obtaining a third quantization strategy for iterative search by the optimization algorithm; updating the first quantization strategy according to the third quantization strategy;

[0076] Alternatively, based on the performance evaluation result and the parameter combination of the first quantization strategy, a quantization strategy parameter combination that meets the performance constraint condition is determined; based on the quantization strategy parameter combination, the quantization strategy with the highest matching degree in the quantization strategy set is determined to update the first quantization strategy.

[0077] In an optional implementation manner, the policy update module is specifically used to:

[0078] In the case where the preset policy update stop condition is not met, if other quantization policies are searched to update the first quantization policy, the first quantization policy is continued to be updated until the hardware resource condition and the performance constraint condition are simultaneously met; if no other quantization policies are searched, the first quantization policy is stopped from being updated; the policy update stop condition includes at least one of the longest policy update time and the maximum policy update rounds;

[0079] When the policy update stopping condition is met, the updating of the first quantization policy is stopped, and prompt information is controlled to be displayed on the quantization interaction interface, so that the user can perform adjustment operations according to the prompt information.

[0080] In an optional embodiment, the device further comprises:

[0081] Receive the model information of the target model, the hardware resource conditions of the device to be deployed, and the performance constraint conditions input by the user on the quantization interaction page;

[0082] In response to receiving the start indication information from the quantization interaction page, the target model is loaded from a predefined model library according to the model information, and the first quantization strategy is obtained from a preset quantization strategy set.

[0083] In an optional embodiment, the device further comprises:

[0084] Receive the verification data set uploaded by the user on the quantitative interaction page;

[0085] The obtaining a performance evaluation result of the target model after quantization using the first quantization strategy includes:

[0086] Obtain a performance evaluation result of the target model quantized by the first quantization strategy on the validation data set.

[0087] Optionally, the device further comprises: obtaining, according to the verification data set, an unquantized performance result of the target model that has not been quantified;

[0088] In the case of receiving a performance constraint condition input by a user, in response to the performance constraint condition being higher than the unquantified performance result, controlling the display of the unquantified performance result on the quantified interaction page, and instructing the user to adjust the performance constraint condition;

[0089] In a case where the performance constraint condition input by the user is not received, the performance constraint condition is determined according to the unquantified performance result.

[0090] Optionally, the performance constraint condition includes at least one performance indicator threshold; the performance indicator threshold is determined according to the unquantified performance result; after obtaining the performance evaluation result of the target model after quantization using the first quantization strategy, the device further includes:

[0091] Determine the difference between each performance indicator in the performance evaluation result and the corresponding performance indicator threshold; when the difference of each performance indicator satisfies the set difference range, determine that the performance evaluation result meets the performance constraint condition.

[0092] Optionally, the quantization strategy set includes at least one of bit width quantization strategies for different quantization bit widths, linear quantization strategies and nonlinear quantization strategies, and object quantization strategies for different quantization objects.

[0093] In a fourth aspect of the embodiments of the present disclosure, a model quantization device is provided, the device comprising:

[0094] A model quantization strategy determination module is used to determine the quantization strategy of the target model used by the device to be deployed, wherein the quantization strategy is determined using the above-mentioned model quantization strategy determination method;

[0095] The quantization deployment module is used to quantize the target model according to the quantization strategy, and deploy the quantized target model to the to-be-deployed device to provide corresponding services.

[0096] In a fifth aspect of the embodiments of the present disclosure, a readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned model quantization strategy determination method or model quantization method is implemented.

[0097] In a sixth aspect of an embodiment of the present disclosure, a computing device is provided, comprising: a processor and a memory; the memory is used to store a computer program; the processor is used to execute the above-mentioned model quantization strategy determination method or model quantization method by calling the computer program.

[0098] According to the model quantization strategy determination method of the embodiment of the present disclosure, a suitable quantization strategy is automatically selected for the target model from a preset quantization strategy set, and the selected strategy is continuously iteratively optimized according to the hardware resources and model performance requirements of the device to be deployed, so as to find the best strategy that meets the dual constraints of hardware and performance. Therefore, when the target model is deployed to the device to be deployed, the best strategy is used as the model quantization strategy to ensure that the model can be efficiently and stably operated on the device to be deployed, thereby realizing automatic selection and optimization of the model quantization strategy, reducing reliance on the experience of professionals and manual intervention processes, being able to quickly adapt to different hardware resources and performance accuracy requirements, and improving the efficiency and accuracy of the quantization process. BRIEF DESCRIPTION OF THE DRAWINGS

[0099] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present disclosure are shown in an exemplary and non-limiting manner, in which:

[0100] Figure 1 A flowchart of a method for determining a model quantization strategy according to an embodiment of the present disclosure is schematically shown;

[0101] Figure 2 The schematic diagram of the hardware resource and performance evaluation process of a model under the first quantization strategy in an embodiment of the present disclosure is schematically shown;

[0102] Figure 3A A schematic diagram of a process of matching hardware resource requirements of a detection model under a first quantization strategy with hardware resource conditions in an embodiment of the present disclosure is schematically shown;

[0103] Figure 3B A schematic diagram of a process of matching hardware resource requirements of another detection model under a first quantization strategy according to an embodiment of the present disclosure with hardware resource conditions is shown;

[0104] Figure 4 A schematic diagram of a quantitative strategy update process when a hardware resource requirement does not match a hardware resource condition according to an embodiment of the present disclosure is schematically shown;

[0105] Figure 5 A schematic diagram of a first quantization strategy iterative update process with a pre-set strategy update stop condition in an embodiment of the present disclosure is shown schematically;

[0106] Figure 6 A schematic diagram of an interaction process based on a quantitative interaction page according to an embodiment of the present disclosure is schematically shown;

[0107] Figure 7 A schematic diagram of a model quantization method process according to an embodiment of the present disclosure is shown schematically;

[0108] Figure 8 The inventive concept block diagram of a method for determining a model quantization strategy according to an embodiment of the present disclosure is schematically shown;

[0109] Fig. 9 A block diagram of a model quantization strategy determination device according to an embodiment of the present disclosure is schematically shown;

[0110] Fig.10 A block diagram of a model quantization device according to an embodiment of the present disclosure is schematically shown;

[0111] Fig.11 A schematic diagram schematically illustrates a medium according to an embodiment of the present disclosure;

[0112] Fig.12 A schematic diagram of a computing device according to an embodiment of the present disclosure is schematically shown.

[0113] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION

[0114] The principles and spirit of the present disclosure will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present disclosure, and are not intended to limit the scope of the present disclosure in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0115] Those skilled in the art will appreciate that the embodiments of the present disclosure may be implemented as a system, device, apparatus, method or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.

[0116] According to an embodiment of the present disclosure, a model quantization strategy determination method and a model quantization method, and a device, a medium and a computing device corresponding to the method are proposed.

[0117] It should be understood herein that any number of elements in the drawings is for illustration rather than limitation, and any naming is only for distinction rather than having any limiting meaning.

[0118] The principle and spirit of the present disclosure are explained in detail below with reference to several representative embodiments of the present disclosure.

[0119] In the field of artificial intelligence and machine learning, as the scale and complexity of models continue to increase, the demand for computing resources and storage space is also increasing. Resource limitations have become a major bottleneck for the widespread deployment and application of models. For example, some models rely on high-performance GPU (Graphics Processing Unit) resources during the inference phase. The GPU resources of the device limit and affect the deployment of the model. Due to the lack of sufficient GPU resources, it may not be able to fully exert its performance during actual deployment, and it may also limit its real-time performance and efficiency in certain scenarios.

[0120] Therefore, the development of quantization technology has become the key to improving model availability. Quantization technology is a technology that compresses machine learning models. By converting model weights and activation values ​​into low-bit fixed-point representations, such as converting weights originally represented by 32-bit floating-point numbers into 8-bit integer representations, the model's demand for video memory can be reduced and computing efficiency can be improved, allowing large models to run in resource-limited environments.

[0121] At present, research on model quantization has made progress. For example, by quantizing the weights of the attention layer and feedforward layer of the transformer model to int8 format, the model memory requirement is halved without causing a significant loss in accuracy; it is also proposed to use a method of approximating second-order information to perform a deeper quantization of the GPT model, which can quantize the model's weight parameters to 3 bits or 4 bits, further reducing the model's storage and computing requirements while maintaining accuracy. Some studies have proposed an activation-aware weight quantization method, which determines the optimal quantization ratio by observing the distribution of activation values, protecting the model effect while achieving model compression. In addition, it is proposed to quantize both the model's weights and activation values ​​to 8 bits, and use equivalent mathematical transformations to handle the quantization of abnormal points in the activation values, thereby achieving model activation value quantization.

[0122] However, existing quantization technology still has certain limitations. Its quantization process usually needs to rely on the experience and judgment of professionals to make manual selections and adjustments. Not only is the operation complex and time-consuming, but it is also difficult to ensure that the global optimal quantization strategy is found. It is also impossible to quickly adapt to different hardware resources and performance accuracy requirements, which increases the difficulty of rapid deployment of quantization models in new environments.

[0123] To solve the above technical problems, the present disclosure proposes a method for determining a model quantization strategy, which automatically selects a suitable quantization strategy from a preset quantization strategy set, and continuously iterates and optimizes the selected strategy according to the hardware resources and model performance requirements of the device to be deployed, so as to find the optimal strategy that meets the dual constraints of hardware and performance. When the target model is deployed to the device to be deployed, the optimal strategy is used as the model quantization strategy to ensure that the model can be efficiently and stably operated on the device to be deployed, reduce dependence on the experience of professionals and manual intervention process, can quickly adapt to different hardware resources and performance accuracy requirements, and improve the efficiency and accuracy of the quantization process.

[0124] Based on the above-mentioned model quantization strategy determination method, the present disclosure also provides a model quantization method. When the target model is deployed to the device to be deployed, the quantization strategy of the target model is determined by the above-mentioned model quantization strategy determination method according to the hardware resources of the device to be deployed and the requirements for the accuracy of the model running performance. After the target model is quantized by using the quantization strategy, it is deployed to the device to be deployed, thereby realizing model quantization and deployment that is quickly adapted to the running environment, and ensuring the stable operation of the model on the device to be deployed.

[0125] After introducing the basic principles of the present disclosure, various non-limiting embodiments of the present disclosure are described in detail below.

[0126] Exemplary Methods

[0127] The present disclosure provides a method for determining a model quantization strategy. This method is not only applicable to large language models with high storage or resource requirements, but also to various types of complex models such as computer vision models, generation models, and other models that support quantization processing. This method can determine a quantization strategy suitable for the environment to be deployed for the applicable model.

[0128] Figure 1 A method for determining a model quantization strategy according to an embodiment of the present disclosure is schematically shown. The method can be executed by various electronic devices, including but not limited to computers, servers, cloud computing platforms, and edge computing devices. Figure 1 As shown, the method may include the following steps:

[0129] S101, obtaining a first quantization strategy of a target model from a preset quantization strategy set;

[0130] The quantization strategy set integrates multiple quantization strategies, each of which can define different parameter combinations, such as different scaling factors, truncation thresholds, etc. The strategy and parameters can be stored in the form of structured data, such as described in JSON, YAML, etc. The quantization strategy set may include but is not limited to bit width quantization strategies with different quantization bit widths, linear quantization strategies and nonlinear quantization strategies, and object quantization strategies for different quantization objects. The quantization strategy can act on the model independently, or multiple quantization strategies can be combined to act on the model to achieve better quantization effects, for example, combining linear and nonlinear quantization strategies with different bit widths.

[0131] Among them, the bit width quantization strategy achieves compression of model parameters and activation values ​​by adjusting the quantization bit width. For example, the bit width quantization strategy can include 8-bit integer quantization, 8-bit floating point quantization, 4-bit integer-based adaptive weight quantization, gradient-based precision customized 4-bit integer quantization and other strategies; the linear quantization strategy maintains the linear relationship between the original data and the quantized data. Correspondingly, the nonlinear quantization strategy allows a complex nonlinear relationship between the original data and the quantized data, which can better capture the characteristics of the data; the object quantization strategy refers to the different strategies used when quantizing different types of objects in the model, such as weights, activation values, etc., such as weight quantization, activation value quantization, gradient quantization, inter-layer quantization, etc., which can be selected according to the nature and characteristics of the quantized object to maximize the performance and accuracy of the model.

[0132] The target model is a specific model that needs to be quantized, which can be determined based on context information or user / system input. For example, the user can specify the model to be quantized as the target model through a command line, a graphical user interface, or an API call, or, for determining the model quantization strategy as part of an automated process, the target model can be determined based on the information passed in the previous step.

[0133] The above-mentioned first quantization strategy is an initial quantization strategy selected based on experience and general rules without specific performance feedback or in-depth analysis of model characteristics, and serves as the basis for iterative updates of subsequent quantization strategies.

[0134] In this embodiment, in response to receiving a first request for indicating the determination of a quantization strategy for a target model, the target model may be determined from information carried in the first request, and a first quantization strategy for the target model may be selected from the quantization strategy set. The selection of the first quantization strategy may be implemented in any of the following ways:

[0135] The first quantization strategy of each model can be uniformly set to the same quantization strategy. For example, based on the weight-only 8-bit integer quantization strategy, which only focuses on the quantization of weights and can maintain relatively good model performance, it is convenient to gradually introduce more complex quantization strategies, and is suitable as an improvement basis for iterative optimization. Then, the initial quantization strategy of each model can be selected as the weight-only 8-bit integer quantization strategy, and the weight-only 8-bit integer quantization strategy can be used as the starting point for iterative optimization.

[0136] Alternatively, based on static information such as the type and complexity of each model, combined with a set of quantization strategies, a quantization strategy is pre-selected for each model as the first quantization strategy, and a mapping relationship between the model and the first quantization strategy is constructed, so that when the target model is determined, its corresponding first quantization strategy is determined according to the mapping relationship.

[0137] Alternatively, the quantization strategies used by each model under different hardware resource conditions and performance constraints can be pre-stored based on prior data, and the correspondence between the three can be constructed. When selecting the first quantization strategy from the quantization strategy set, the hardware resource conditions and performance constraints corresponding to the current target model can be matched with the correspondence, and a quantization strategy with a high degree of matching can be determined as the first quantization strategy. Furthermore, when the iterative optimization of the first quantization strategy for the target model is completed and the final quantization strategy of the target model is determined, the correspondence between the above three can be updated according to the hardware resource conditions, performance constraints, and final quantization strategy of the target model.

[0138] Alternatively, the first quantization strategy may be input by the user through a graphical interactive interface, that is, the user may manually specify the first quantization strategy of the target model through the interactive interface according to model requirements or personal experience.

[0139] S102, determining the hardware resource requirements of the target model under the first quantization strategy, and obtaining a performance evaluation result of the target model after quantization using the first quantization strategy;

[0140] Hardware resource requirements refer to the physical hardware equipment and performance standards required for model operation, including but not limited to computing resources, storage resources, network resources and other related hardware requirements. In this embodiment, the hardware resource requirements may at least include the computational complexity of the operation and the video memory space. Based on this, the determination of the hardware resource requirements of the target model under the first quantization strategy may include:

[0141] The computational complexity of each layer of the target model under the first quantization strategy is calculated respectively to determine the computational complexity of the target model; and the required video memory space is determined according to the input length, output length and model concurrency requirements of the target model.

[0142] Among them, the input length of the model refers to the length or dimension of the input data received by the model, and the output length refers to the length or dimension of the result data output by the model. Model concurrency refers to the ability to process multiple input data simultaneously, which is used to describe the number of input data that the model can process simultaneously during the reasoning process.

[0143] The computational complexity of the target model can be calculated by analyzing each layer of the target model. For each layer of the target model, the number of operations required for the computational operation is estimated according to the bit width, data dimension and computational operation used by the layer, such as matrix calculation or convolution calculation, under the first quantization strategy, to obtain the computational complexity of the layer. Finally, the computational complexity of all layers is added together to obtain the computational complexity of the target model. For concurrent model processing, the number of input data processed simultaneously needs to be considered to determine the overall computational complexity during concurrent calculation.

[0144] The video memory space required by the target model under the first quantization strategy can be obtained by adding the video memory space required by each part of the model, such as the model weight, activation and KV (Key-Value) cache. According to the quantization bit width, input data and key-value cache size of the first quantization strategy, the video memory space occupied by the weight matrix, activation matrix and KV cache can be determined respectively.

[0145] In order to accurately evaluate the hardware resource requirements of the target model under the first quantization strategy, special tools or libraries can be used for estimation, for example, tools such as TensorFlow Profiler and PyTorch Profiler can be used; alternatively, other existing algorithms or methods can be used to calculate the hardware resource requirements of the target model under the first quantization strategy, which is not limited in the present disclosure.

[0146] Performance evaluation is used to ensure that the quantized model can reduce computational complexity and storage space requirements while maintaining a certain degree of accuracy. The above performance evaluation results refer to the values ​​of various performance indicators obtained by using a set verification data set to perform performance testing on the quantized model after applying the first quantization strategy to the target model for quantization processing, and may include at least one indicator of accuracy, inference delay, inference speed, quantization accuracy loss, and hardware resource utilization.

[0147] In the above steps, the two steps of determining the hardware resource requirements and obtaining the performance evaluation results can be performed simultaneously, or after determining the hardware resource requirements and ensuring that the hardware resource requirements match the hardware resource conditions of the device to be deployed, the target model can be quantized using the first quantization strategy and the performance evaluation results of the quantized model can be obtained.

[0148] S103, when the hardware resource requirement does not match the hardware resource condition of the device to be deployed, or the performance evaluation result does not meet the preset performance constraint condition, update the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy until both the hardware resource condition and the performance constraint condition are met;

[0149] The hardware resource conditions are used to describe the physical characteristics and working capabilities of the equipment to be deployed, such as computing power, memory size, storage capacity, etc. The hardware data type of the hardware resource conditions is the same as the hardware resource type in the hardware resource requirements determined in step S102.

[0150] The hardware resource conditions may be obtained in any of the following ways, and the specific obtaining method is determined according to the actual setting and the user input: the hardware resource conditions may be determined according to the user input information, for example, the user may input the hardware resources supported by the device to be deployed through a graphical user interface or an API interface to receive the user input to determine the hardware resource conditions; or, a device database may be established in advance to store the hardware resource information of various devices, and the user may enter the corresponding device model to obtain the hardware resource conditions by querying the database according to the user input; or, when the above-mentioned model quantization strategy determination method provided in the present disclosure is run by the device to be deployed, the hardware resources of the device may be obtained by using the API or tools provided by the operating system.

[0151] For the currently selected first quantization strategy, the hardware resource requirement does not match the hardware resource condition of the device to be deployed, which may mean that at least one hardware resource required for the target model to run under the first quantization strategy exceeds the hardware resource limit provided by the device to be deployed. For example, assuming that the device to be deployed includes 512MB of memory and a basic CPU, the hardware resource conditions set by the user include that the memory does not exceed 500MB and the CPU usage does not exceed 80%. If the CPU usage or storage requirement of the target model under the first quantization strategy has at least one item that does not match the hardware resource condition (for example, 600MB of storage space is required), then the hardware resource requirement of the target model under the first quantization strategy does not match the hardware resource condition. On the contrary, when each hardware resource meets the hardware resource condition, it is determined that the hardware resource requirement matches the hardware resource condition.

[0152] The performance constraint condition is used to indicate the performance requirements of the model after quantization processing of the target model using the first quantization strategy to ensure that the quantized model can meet the requirements of effective operation and provide reliable results. The performance indicator in the performance constraint condition is the same as the performance indicator type in the performance evaluation result determined in step S102.

[0153] The performance constraint condition may be pre-set with a default performance indicator value. If the user does not indicate the performance constraint condition, the default performance indicator value is automatically used as the performance constraint condition. The default performance indicator value may be determined based on the performance result of the target model when it is not quantified. For example, a loss range for each performance indicator is pre-set, and the performance result of the quantized model is set as the performance constraint condition based on the performance result of the unquantified target model combined with the corresponding loss range. Alternatively, the user may set the performance constraint condition according to their own needs by inputting specific performance indicator values, or a performance constraint configuration file, or other format data. In response to receiving the performance constraint condition input by the user, the performance constraint condition is set according to the user input.

[0154] The performance evaluation result does not meet the preset performance constraint condition means that at least one performance indicator in the performance evaluation result does not meet the performance standard of the performance constraint condition. For example, the performance constraint condition sets thresholds for different performance indicators respectively, and if there is at least one performance indicator evaluation value in the performance evaluation result that is lower than the corresponding threshold, it is determined that the performance evaluation result does not meet the performance constraint condition.

[0155] Under the first quantization strategy, the hardware resource requirements and performance evaluation results of the target model are compared with the corresponding hardware resource conditions and performance constraints respectively. If any of the hardware resource conditions and performance constraints are not met, the quantization strategy update process can be started, that is, the current first quantization strategy is updated using a strategy that has not been selected in the quantization strategy set, and the hardware resource requirements and performance evaluation results of the target model under the updated first quantization strategy are obtained, and re-compared with the corresponding hardware resource conditions and performance constraints until a quantization strategy that can meet both the hardware resource conditions and performance indicator conditions is found.

[0156] When the first quantization strategy is updated by using other quantization strategies in the quantization strategy set, the current first quantization strategy is used as the search basis, and according to the deficiencies of the first quantization strategy in hardware resource conditions and performance constraints, a heuristic algorithm or other preset retrieval algorithm can be used to determine at least one suitable other quantization strategy from the quantization strategy set, and the selected other quantization strategy is merged with the first quantization strategy, or the first quantization strategy is adjusted according to the other quantization strategy to optimize and improve the quantization strategy. Among them, different implementations of fusion or adjustment can be adopted, for example, the quantization accuracy of different quantization strategies can be tried to be combined, or the pruning or activation function approximation method of other quantization strategies can be applied on the basis of the first quantization strategy.

[0157] S104: Determine the first quantization strategy as the model quantization strategy when the target model is deployed to the device to be deployed.

[0158] In the above steps, a comprehensive analysis and test are conducted on the hardware resource requirements and performance evaluation results of the target model under different quantization strategies, and the first quantization strategy is iteratively updated according to the hardware resource conditions and performance constraints until a quantization strategy that satisfies both conditions is found, that is, the hardware resource requirements of the target model under the final first quantization strategy match the above hardware resource conditions, and the performance evaluation results of the quantized target model meet the performance constraints. The first quantization strategy can make full use of the hardware resources of the device to be deployed and ensure the performance of the target model in actual operation. Therefore, the first strategy is used as the model quantization strategy when the target model is deployed to the device to be deployed, so that when the target model is actually deployed to the device to be deployed, the first quantization strategy will be used to quantize and deploy the target model to ensure that the model runs stably under limited hardware resource conditions and achieves the expected performance.

[0159] In the disclosed embodiment, for the target model that needs to be quantized, according to the preset quantization strategy set, the influence of different quantization strategies on the hardware resource requirements and performance of the target model is automatically obtained and evaluated. Through the iterative update of the quantization strategy, the optimal quantization strategy that satisfies both the hardware resource conditions and performance constraints of the device to be deployed is found. Based on the quantization strategy set and automatic evaluation iteration, the automatic selection and optimization of the model quantization strategy is realized, which greatly reduces the tedious process of manual adjustment and selection and human intervention, comprehensively considers the hardware resource conditions of the device to be deployed and the performance constraints of the quantized model, and improves the efficiency and accuracy of the model quantization strategy determination. In addition, this method is applicable to different target models and devices to be deployed. The hardware and performance conditions can be adjusted according to the actual deployment situation to quickly determine the appropriate quantization strategy, which improves the compatibility and rapid deployment capability of the model on different hardware platforms.

[0160] In an optional implementation, for the aforementioned step S102, after determining the hardware resource requirements, the method may further include the steps of:

[0161] Compare the hardware resource requirement with the hardware resource condition of the device to be deployed, and generate a matching result between the hardware resource requirement and the hardware resource condition;

[0162] And when the matching result indicates that the hardware resource requirement matches the hardware resource condition, obtaining the performance evaluation result of the target model after quantization using the first quantization strategy, may include: when the hardware resource requirement matches the hardware resource condition, quantizing the target model according to the first quantization strategy; and obtaining the performance evaluation result of the quantized target model.

[0163] Combine the following Figure 2 This embodiment will be described. Figure 2 A schematic diagram of a hardware resource and performance evaluation process of a model under a first quantization strategy is shown. After determining the hardware resource requirements of the target model under the first quantization strategy in step S201, the method may include a hardware resource matching detection step S202:

[0164] S202, matching and judging the hardware resource requirement with the hardware resource condition of the device to be deployed to determine whether the resource limit of the device to be deployed is exceeded, and generating a matching result between the hardware resource requirement and the hardware resource condition;

[0165] If the result of step S202 is no, step S206 is executed to start the first quantization strategy update operation, that is, the first quantization strategy is updated by using other quantization strategies according to step S103 of the above embodiment, and step S201 and subsequent steps are returned to the updated first quantization strategy;

[0166] If the result of step S202 is yes, that is, the hardware resource requirement matches the hardware resource condition, the following steps are performed in sequence:

[0167] S203, performing quantization processing on the target model according to the first quantization strategy to obtain a performance evaluation result of the quantized target model;

[0168] S204, comparing the performance evaluation result with the preset performance constraint condition to determine whether the performance requirement is met;

[0169] If the judgment result of step S204 is yes, that is, the performance evaluation result meets the performance constraint condition, execute step S205: determine the quantization strategy when the target model is deployed to the device to be deployed; conversely, if the judgment result of step S204 is no, execute step S206 to start the first quantization strategy update operation.

[0170] Among them, the quantization processing of the target model can be differentiated according to the model type. For the target model that requires offline quantization, the model parameters such as weights and activation values ​​are quantized, and the quantized model parameters are converted into a quantization format suitable for the inference stage, including the model's structural information, quantization parameters, quantized weights and activation values, etc., so as to be loaded and used in the inference stage; for the target model that supports dynamic quantization, the corresponding quantization configuration parameters are generated according to the first quantization strategy, and the weights and activation values ​​of the target model are dynamically quantized according to the quantization configuration parameters during the inference process.

[0171] In the disclosed embodiment, the hardware resource requirements of the target model are first obtained and compared with the actual hardware resource conditions of the device to be deployed. While ensuring that the selected first quantization strategy does not exceed the resource limitations of the device, the performance of the quantized model is further evaluated and compared with the preset performance constraints to verify whether the model meets the performance requirements. If the conditions are not met in any link, the update process of the quantization strategy will be triggered. The pre-emptive hardware matching detection avoids invalid calculations and resource consumption of subsequent performance evaluation results, saves a lot of time and resources, and improves the efficiency of quantization strategy updates.

[0172] In an optional implementation, the hardware resource condition of the device to be deployed may include pre-set resource thresholds for different hardware resources; accordingly, the hardware resource requirements of the target model under the first quantization strategy include the required values ​​for the different hardware resources; based on this, Figure 3A As shown, it is a flow chart of matching the hardware resource requirements of a detection model under the first quantization strategy in an embodiment of the present disclosure with the hardware resource conditions. Through this embodiment, it can be determined whether the hardware resource requirements match the hardware resource conditions:

[0173] S301, obtaining the required values ​​of different hardware resources of the target model under the first quantization strategy;

[0174] S302, comparing the demand value of the same hardware resource with the corresponding resource threshold to determine whether the demand values ​​of all hardware resources are less than or equal to the corresponding resource threshold;

[0175] The demand value of each hardware resource is less than or equal to the resource threshold, indicating that the demand value of each hardware resource required for the target model to run under the first quantization strategy does not exceed the maximum resource limit supported by the device to be deployed, and the hardware conditions required by the model can be met on the device to be deployed, and there will be no shortage of resources or exceeding the device capacity. It can be determined that the hardware resource requirements of the target model under the first quantization strategy match the hardware resource conditions. On the contrary, if there is at least one hardware resource demand value greater than the resource threshold, indicating that part of the hardware requirements of the target model under this quantization strategy have exceeded the device's tolerance, the model's operation on the device to be deployed will be subject to resource restrictions, which may result in performance degradation or failure to operate normally, and it is determined that the hardware resource requirements of the target model do not match the hardware resource conditions.

[0176] Based on this, if the judgment result in step S302 is yes, that is, each requirement value is less than or equal to the corresponding resource threshold, step S303 is executed to generate a matching result that the hardware resource requirement matches the hardware resource condition;

[0177] On the contrary, if the judgment result in step S302 is no, that is, there is at least one hardware resource requirement value greater than the corresponding resource threshold, step S304 is executed to generate a matching result that the hardware resource requirement does not match the hardware resource item.

[0178] In the embodiments of the present disclosure, hardware resource matching in the model quantization process is achieved by comparing pre-set resource thresholds with the hardware resource requirement values ​​of the model under a specific quantization strategy item by item. This can accurately determine the resource usage of the model on the device to be deployed, reduce deployment failures and repeated work caused by single resource mismatches, and improve the efficiency and stability of the model deployment process.

[0179] In an optional implementation, during the process of model quantization and deployment, when the overall hardware resource requirements of the target model meet the resource threshold, some network layers in the model may consume a large amount of hardware resources, thereby causing performance bottlenecks or resource conflicts when the model is running. This embodiment provides a more accurate hardware resource matching method. In the case where each requirement value of the above embodiment is less than or equal to the corresponding resource threshold, before determining that the hardware resource requirements match the hardware resource conditions, such as Figure 3B As shown, it is a flowchart of another detection model of whether the hardware resource requirements of the first quantization strategy match the hardware resource conditions according to an embodiment of the present disclosure. In this embodiment, when the judgment result of step S302 of the above embodiment is yes, before executing step S303, the following steps can be combined to implement further hardware resource matching judgment:

[0180] S3021, obtaining the hardware resource requirements of each layer of the target model;

[0181] That is, first, obtain the hardware resource requirements of each layer of the target model, which can include the demand values ​​of different hardware resources such as CPU, GPU, memory, etc., to clarify the specific consumption of hardware resources by each layer of the model.

[0182] S3022, determining the maximum requirement value of each hardware resource according to the hardware resource requirement of each layer of the network;

[0183] S3023, comparing the maximum demand value of each hardware resource with the corresponding resource threshold to determine whether the maximum demand values ​​of all hardware resources are less than or equal to the corresponding resource threshold;

[0184] During the model operation, the actual consumption of a certain hardware resource may reach a peak value, that is, the maximum demand value, as the network level advances. The maximum demand value of each hardware resource can be determined based on the hardware resource requirements of each layer of the network to ensure that the device can support the highest consumption. Finally, the maximum demand value is compared with the corresponding resource threshold. If the maximum demand value of each hardware resource does not exceed the corresponding resource threshold, it can be considered that when the model is running on the device to be deployed, each layer of the model can obtain sufficient hardware resource support to avoid failure to run due to excessive resource consumption of a certain layer. In this way, when the overall hardware resource demand value of the target model meets the resource threshold and each layer of the model can obtain sufficient resource support, it is determined that the hardware resource demand matches the hardware resource condition.

[0185] Therefore, if the judgment result of step S3023 is yes, that is, the maximum demand value of each hardware volunteer is less than or equal to the corresponding resource threshold, then the aforementioned step S303 is executed to generate a matching result that the hardware resource demand matches the hardware resource condition;

[0186] On the contrary, if the result of the judgment in step S3023 is no, that is, at least one hardware resource has a maximum demand value greater than the corresponding resource threshold, then the aforementioned step S304 is executed to generate a matching result that the hardware resource demand does not match the hardware resource bar.

[0187] In the disclosed embodiment, by comprehensively considering the overall resource requirement threshold of the model and the resource requirement threshold of each layer of the model, the carrying capacity of the device is evaluated more accurately, so that when the overall hardware resource requirement of the model is supported by the resources of the device to be deployed, each layer in the model can also obtain resource support during operation, thereby improving the success rate of model deployment and the stability of operation.

[0188] In an alternative embodiment, see Figure 4As shown, it is a schematic diagram of a quantitative strategy update process when the hardware resource requirement does not match the hardware resource condition, that is, when the performance evaluation result meets or does not meet the performance constraint condition, if the hardware resource requirement does not match the hardware resource condition of the device to be deployed, the aforementioned step S103 of updating the first quantitative strategy by using other quantitative strategies in the quantitative strategy set except the first quantitative strategy can be implemented by the following steps:

[0189] S401, determining a resource type that does not match the hardware resource condition;

[0190] S402, determining a candidate quantization strategy from the quantization strategy set according to the degree of influence of the quantization strategy on the hardware resources of the resource type;

[0191] S403: Determine a second quantization strategy from the candidate quantization strategies according to the parameter combination of the first quantization strategy to update the first quantization strategy.

[0192] Among the pre-integrated multiple quantization strategies, each quantization strategy has different impacts on the requirements of different hardware resources of the model. Some quantization strategies are used to reduce the model size to reduce memory usage, and some quantization strategies can improve computing efficiency to reduce CPU or GPU usage.

[0193] Based on this, when the hardware resource requirements of the target model exceed the hardware resource limits provided by the device support, a new quantization strategy can be determined based on the excess of the hardware resource requirements. The resource types that exceed the resource limits can be specifically analyzed first, and then the first quantization strategy can be used to determine suitable quantization strategies other than the first quantization strategy based on the resource type and the first quantization strategy, and the first quantization strategy can be updated. For example, if the memory usage exceeds the resource limit, a quantization strategy that can reduce the model size can be selected as a candidate quantization strategy, for example, by reducing the number of bits of the parameter to reduce the memory requirement; if multiple resources exceed the resource limit at the same time, a quantization strategy that can comprehensively consider multiple aspects of resource optimization can be selected as a candidate quantization strategy, or a combination of multiple strategies can be used to achieve a balanced effect.

[0194] In the disclosed embodiment, based on the different impacts of multiple pre-integrated quantization strategies on the model's hardware resource requirements and in combination with the resource types that exceed the hardware resource conditions, appropriate quantization strategies are selected or used in combination to update the first quantization strategy, thereby dynamically selecting quantization strategies for policy iteration based on hardware resource condition mismatches, reducing the number of policy iterations and improving processing efficiency.

[0195] In an optional implementation manner, when the hardware resource requirement matches the hardware resource condition and the performance evaluation result does not meet the performance constraint condition, the updating of the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy in the aforementioned step S103 can be implemented by any of the following methods:

[0196] The performance evaluation result and the first quantization strategy are used as inputs of a preset optimization algorithm to obtain a third quantization strategy for iterative search by the optimization algorithm; and the first quantization strategy is updated according to the third quantization strategy.

[0197] Or, based on the performance evaluation result and the parameter combination of the first quantization strategy, determine a quantization strategy parameter combination that meets the performance constraint condition; based on the quantization strategy parameter combination, determine the quantization strategy with the highest matching degree in the quantization strategy set to update the first quantization strategy.

[0198] Among them, the above-mentioned preset optimization algorithm is used to search for a possibly better quantization strategy in the quantization strategy set based on the input performance evaluation results and the information of the first quantization strategy. The algorithm may at least include a heuristic algorithm, a pre-trained machine learning algorithm, or other optimization algorithms customized according to preset selection rules. Among them, the machine learning algorithm can predict and select a quantization strategy that meets the needs by analyzing and learning the historical performance data of different quantization strategies under different conditions. The machine learning algorithm can be based on various models such as neural networks, decision trees, etc., and optimize the prediction ability through historical data training.

[0199] In this embodiment, the performance evaluation result of the current first quantization strategy and the first quantization strategy can be used as inputs of a preset optimization algorithm. The input information can provide a search basis and direction for the optimization algorithm. After receiving the input, the optimization algorithm searches for a possibly better quantization strategy as a third quantization strategy from the quantization strategy set through an iterative search based on the performance evaluation result and the characteristics of the first quantization strategy, and updates the first quantization strategy according to the third quantization strategy to optimize the performance of the target model after quantization.

[0200] Alternatively, based on the analysis of the parameter combination of the first quantization strategy and the performance evaluation result of the target model under the current first quantization strategy, the parameter combination of the quantization strategy can be adjusted in the hope that the performance of the target model can be improved under the new parameter combination and the performance constraint can be met or exceeded. After determining the new quantization strategy parameter combination, the quantization strategy parameter combination can be compared and calculated with the parameters of each quantization strategy in the quantization strategy set, and the matching degree of each quantization strategy with the target parameter combination can be evaluated by calculating the similarity or distance between the parameters, so as to update the first quantization strategy according to the quantization strategy with the highest matching degree.

[0201] In the embodiment of the present disclosure, by taking the performance evaluation results and the first quantization strategy as the basis for updating the quantization strategy, the first quantization strategy can be updated and optimized through iterative search of the optimization algorithm or adjustment of parameter combinations combined with two different optimization paths of matching evaluation, thereby maintaining the flexibility and efficiency of the optimization process and reducing resource waste.

[0202] In addition, the above two optimization paths can also be combined with other optimization methods and technologies to form a more complete model optimization process. For example, these two solutions can be combined with other quantization technologies such as model pruning and knowledge distillation to achieve better performance improvement.

[0203] In an optional implementation, based on the embodiment of the present disclosure, the update of the first quantization strategy can be an iterative search. In order to prevent infinite loops and excessive resource consumption, some policy update stop conditions are preset before starting the iterative search. The policy update stop conditions may include any one of the maximum policy update time and the maximum policy update rounds; wherein, the maximum policy update time refers to the maximum update time allowed for the update of the first quantization strategy. After the update process of the first quantization strategy exceeds the maximum update time, the search will be stopped regardless of whether a quantization strategy that meets both the hardware resource and performance constraints is found; the maximum policy update rounds refers to the maximum number of updates allowed for the first quantization strategy. If the number of updates to the first quantization strategy reaches the maximum number of updates, the search will be stopped.

[0204] See also Figure 5 As shown, it is a schematic diagram of a first quantization strategy iterative update process with a preset strategy update stop condition. Based on the preset strategy update stop condition, in the aforementioned step S103, when the hardware resource requirement does not match the hardware resource condition, or the performance evaluation result does not meet the performance constraint condition, the first quantization strategy is updated using other quantization strategies in the quantization strategy set except the first quantization strategy until both the hardware resource condition and the performance constraint condition are met, which may include the following steps:

[0205] In the case where the preset policy update stop condition is not met, if other quantization strategies are searched to update the first quantization strategy, then the first quantization strategy is continued to be updated until the hardware resource condition and the performance constraint condition are simultaneously met; if no other quantization strategy is searched, then the updating of the first quantization strategy is stopped;

[0206] When the policy update stopping condition is met, the updating of the first quantization policy is stopped, and prompt information is controlled to be displayed on the quantization interaction interface, so that the user can perform adjustment operations according to the prompt information.

[0207] Combination Figure 5 As shown in the flowchart, when the hardware resource requirements of the first quantization strategy do not match the hardware resource conditions, or the performance evaluation results do not meet the performance constraint conditions, triggering the update of the first quantization strategy, step S501 is first executed to detect whether the current update state meets the above-mentioned strategy update stop condition:

[0208] If satisfied, then jump to step S506: stop updating the first quantization strategy;

[0209] If not, step S502 is executed to search for other quantization strategies except the first quantization strategy from the preset quantization strategy set, and different operations are performed according to different judgment results of whether other suitable quantization strategies are found:

[0210] If the judgment result of step S502 is no, then jump to step S506;

[0211] If the judgment result of step S502 is yes, then execute step S503: update the current first quantization strategy using the searched quantization strategy, and continue to execute step S504: re-evaluate the hardware resource requirements and performance evaluation results of the target model under the updated first quantization strategy, and determine whether both the hardware resource conditions and the performance constraints are met:

[0212] If the judgment result of step S504 is yes (the hardware resource and performance constraints are met at the same time), step S505 is executed to determine the quantization strategy of the target model;

[0213] If the judgment result of step S504 is no (the hardware resource and performance constraints cannot be met at the same time), return to continue executing the above step S501 and the process steps after step S501;

[0214] For the above-mentioned stop update situations other than those that meet both the hardware resource conditions and the performance constraint conditions in steps S504-S505, step S507 may be continued to be executed after step S506 is executed, so as to control the display of prompt information on the quantization interaction interface to inform the user of the current quantization strategy update status, for example, whether a quantization strategy that meets the conditions is found, the reason for stopping the update, etc., and corresponding adjustment suggestions may be provided according to the content of the prompt information to help the user make adjustment operations according to the prompt information.

[0215] In the disclosed embodiment, by setting the policy update stop condition, it can be ensured that the process of quantization policy update will not fall into an infinite loop, and the update will be automatically stopped when the search reaches the preset time or round limit, avoiding unnecessary waste of computing resources and time, and providing prompt information and adjustment suggestions through the quantization interactive interface for the case where the quantization update is terminated due to the satisfaction of the stop condition, thereby helping the user to make targeted manual adjustments or take other measures, thereby improving the user experience. In addition, by setting different policy update stop conditions and prompt information, the system can adapt to different application scenarios and user needs, and the feedback-based policy selection process can accelerate the search for the best quantization policy that meets the hardware resource conditions and performance constraints, thereby optimizing the performance and efficiency of the model.

[0216] In an optional implementation, during the model quantization process, the user can interact with the system through a graphical user interface, and implement the quantization strategy determination process in combination with the user input in the graphical user interface. In this embodiment, a quantization interaction page can be pre-set, and the quantization interaction page can at least include the target model input, the hardware resource conditions of the device to be deployed, and the performance constraint conditions after the target model is quantized. The user can input them according to their needs. Figure 6 As shown, it is a schematic diagram of an interaction process based on a quantitative interaction page according to an embodiment of the present disclosure. Based on the quantitative interaction page, before the aforementioned step S101, the above-mentioned model quantitative strategy determination method may further include the following steps:

[0217] S601, receiving the model information of the target model, the hardware resource conditions of the device to be deployed, and the performance constraint conditions input by the user on the quantization interaction page;

[0218] The model information may include the name, type, version number, etc. of the model, so as to accurately identify and load the model from a predefined model library.

[0219] For the hardware resource conditions of the equipment to be deployed, the user can manually enter the hardware resource conditions, or can enter the model or device identification of the equipment to be deployed, so as to find the corresponding hardware resource condition information from the preset equipment database, and display the information on the quantitative interaction page, so that the user can confirm or modify the information.

[0220] S602: In response to receiving the start instruction information from the quantization interaction page, the target model is loaded from a predefined model library according to the model information, and a first quantization strategy is selected from a preset quantization strategy set.

[0221] The predefined model library contains a collection of multiple different models and versions, and the corresponding model can be located and loaded through the model identifier in the model information input by the user, such as the model name and version number. When the user completes the input and clicks to send the instruction information, such as clicking the "start quantization" button, in response to receiving the start instruction information, the target model is loaded from the predefined model library, and while loading the target model, the first quantization strategy is obtained from the preset quantization strategy set.

[0222] In the embodiments of the present disclosure, by setting a method for receiving user input on the quantization interaction page, the user can conveniently specify the target model, hardware resource conditions and performance constraints without having to deeply understand the specific implementation details within the system, thereby reducing the need for manual intervention and realizing automatic loading of the model and selection of the quantization strategy based on the information input by the user, thereby improving the efficiency and accuracy of the quantization process.

[0223] In an optional implementation, the above-mentioned quantization interaction page may also include a data set input for users to upload customized data sets. Based on this, the above-mentioned model quantization strategy determination method may also include the steps of: receiving a verification data set uploaded by the user on the quantization interaction page; the verification data set is used to quantize the target model with the first quantization strategy and then obtain a performance evaluation result.

[0224] In the disclosed embodiment, the user flexibly uploads a verification data set through the quantization interaction page, and uses the verification data set to evaluate the performance of the target model after quantization with the first quantization strategy, thereby being able to adapt to different application scenarios and data distributions, enhancing the flexibility and transparency of the model quantization process, and providing users with a better usage experience and optimization guidance.

[0225] In an optional implementation, for the scenario of uploading a verification data set through an interactive quantization page described in the above embodiment, since the performance of the quantized model is equal to or slightly lower than the performance of the unquantized model, the performance constraint condition can be adjusted according to the verification data set, which may include the following steps:

[0226] According to the validation data set, obtaining an unquantized performance result of the target model that has not been quantified;

[0227] In the case of receiving a performance constraint condition input by a user, in response to the performance constraint condition being higher than the unquantified performance result, controlling the display of the unquantified performance result on the quantified interaction page, and instructing the user to adjust the performance constraint condition;

[0228] In a case where the performance constraint condition input by the user is not received, the performance constraint condition is determined according to the unquantified performance result.

[0229] Among them, when the user enters performance constraints through the interactive page, the performance constraints and the unquantified performance results can be compared. If the performance constraints set by the user are higher than the unquantified performance results, it means that the user expects the performance of the quantized model to exceed the unquantified original model. The setting of the performance constraints does not conform to the actual situation. The unquantified performance results can be displayed on the quantization interactive page, and the user can be prompted to adjust his performance constraints to ensure that they are reasonable and feasible.

[0230] In the embodiments of the present disclosure, by comparing the performance constraints input by the user and the unquantified performance results, and providing feedback and guidance for adjustment when the performance constraints set by the user are unreasonable, the user is prevented from setting unrealistic performance expectations, thereby improving the rationality and success rate of the quantification process.

[0231] In an optional implementation, the quantization interaction page may also include a hierarchical quantization setting for the target model. The user may control the quantization strategy for a specified network layer of the target model and implement the quantization processing of the network layer through the interaction page. When the model information of the target model input by the user is received, if there is a hierarchical quantization indication, the target model is loaded and a first quantization strategy for the input specified network layer is obtained, and the hardware resource requirements of the specified network layer under the first quantization strategy are obtained.

[0232] In the disclosed embodiment, a suitable quantization strategy can be selected according to the specific characteristics and requirements of each network layer through hierarchical quantization setting, so that the quantization process of each network layer can be more accurately controlled to adapt to its unique needs, so as to minimize information loss, maintain model performance, and achieve higher quantization efficiency.

[0233] In an optional implementation, the performance constraint may include at least one performance indicator threshold; in the case where no performance constraint input by the user is received, the performance indicator threshold may be automatically determined based on the unquantified performance result. After obtaining the performance evaluation result of the target model after quantization using the first quantization strategy, the method may determine whether the performance constraint is met in the following manner:

[0234] Determine the difference between each performance indicator in the performance evaluation result and the corresponding performance indicator threshold; when the difference of each performance indicator satisfies the set difference range, determine that the performance evaluation result meets the performance constraint condition.

[0235] In the disclosed embodiment, by comparing the performance evaluation result of the quantized model with the performance indicator threshold, it is possible to accurately determine whether the model meets the performance constraint conditions, thereby ensuring the accuracy and effectiveness of the quantization process.

[0236] Based on the above model, the quantitative strategy determination method is as follows: Figure 7 As shown, the embodiment of the present disclosure also provides a flow chart of a model quantization method, which is used to implement the quantization processing of the target model and deploy it to the device to be deployed to meet the requirements of running on limited resources or specific hardware platforms. The method can be executed by various devices that support the implementation of model quantization processing, and includes the following steps:

[0237] S701, determining a target quantization strategy of a target model used by a device to be deployed, wherein the target quantization strategy is determined by using the model quantization strategy determination method described in the above embodiment;

[0238] The devices to be deployed may include hardware platforms that can run machine learning models, such as mobile phones, servers, embedded devices, etc. When deploying the specified target model to the device to be deployed, the target model needs to be quantized based on the hardware resource limitations of the current device to be deployed. First, the target quantization strategy of the target model used by the device to be deployed needs to be determined.

[0239] The target quantization strategy refers to the quantization method or parameter setting selected for the target model based on the hardware resource conditions of the device to be deployed and the corresponding performance requirements of the model after quantization. It can be determined by calling the model quantization strategy determination method recorded in the above example through interface calls and other related methods, and is used to optimize the performance of the model, reduce computing resource consumption or improve operating efficiency.

[0240] S702: quantize the target model according to the target quantization strategy, and deploy the quantized target model to the device to be deployed to provide corresponding services.

[0241] Quantization refers to converting the model's weights, activation values, etc. from floating-point numbers to fixed-point numbers or integers to reduce the storage space required for the model and increase the calculation speed.

[0242] After the quantization process is completed, the quantized target model is deployed to the device to be deployed, so that the deployed target model can provide corresponding services on the device, such as image recognition, speech recognition, recommendation system, etc.

[0243] Users can input the target model and quantization-related information through the graphical user interface. After submitting the quantization request, the model quantization and deployment can be automatically realized through the above-mentioned model quantization method.

[0244] In the embodiments of the present disclosure, through the specific hardware resource limitations of the hardware platform, a quantization strategy suitable for the current deployment environment is adaptively selected, and quantization processing is performed according to the quantization strategy, thereby realizing adaptive quantization of the model, reducing the computing resources and storage space required for the model, and ensuring that the model can be quickly deployed and efficiently run on specific hardware.

[0245] The model quantization strategy determination method and model quantization method provided by the present disclosure have been described in detail in the preceding section. In order to enable those skilled in the art to better understand the present disclosure, the present disclosure will be described below through some relevant embodiments in combination with specific deployment scenario examples.

[0246] Based on the model quantization strategy determination method described in the above embodiments, Figure 8 As shown, it is an inventive concept block diagram of a method for determining a model quantization strategy according to an embodiment of the present disclosure, which as a whole includes a graphical user interface, a search process and an evaluation process.

[0247] The search process is used to search for combined quantization schemes in a predefined search space, i.e., a set of quantization strategies, according to a given model, hardware resources, and performance constraints, and includes at least a search engine module, a hardware resource evaluation module, and a quantization engine module; the evaluation process is used to run the output quantization scheme on a verification data set, and decide to adopt the quantization scheme for model deployment or execute the search process to continue searching for the quantization scheme based on the performance evaluation results, and includes at least a model performance evaluation module and a decision engine module.

[0248] Search space: Integrates multiple quantization strategies, supports searching for the most appropriate quantization scheme based on the characteristics of the model and the limitations of the hardware, and provides quantization schemes for different models and hardware configurations. For example, the quantization strategies in this search space may include:

[0249] Classified by the dimension of quantization bit width, it includes at least 8-bit integer quantization, 8-bit floating point quantization, and 4-bit integer quantization based on adaptive weight quantization.

[0250] Classified by the dimension of quantization algorithm, at least linear quantization strategy and nonlinear quantization strategy can be included. The linear quantization strategy uses a linear function to map weights and activations from floating point numbers to a predetermined integer range, and uses a quantization factor to scale the values ​​to adapt to the target bit width. The nonlinear quantization strategy is used to use nonlinear functions, such as logarithmic or quantile mapping, to reduce quantization errors, etc.;

[0251] Classified by the dimensions of quantizing different objects, it can at least include 8-bit integer quantization that quantizes only model weights, 8-bit integer quantization that quantizes both weights and activation values, and model key-value pair quantization strategies, etc.

[0252] Search engine module: used to find the best quantization solution in the above search space. This module uses a variety of optimization algorithms, such as genetic algorithm, simulated annealing, particle swarm optimization, ant colony algorithm and Bayesian optimization, etc., to explore possible quantization configurations within a limited number of searches. The search engine module can generate quantization solutions through the following steps:

[0253] (1) in response to receiving the start indication information, selecting an initial quantization strategy from the search space;

[0254] (2) Entering the "hardware resource evaluation module" to evaluate the hardware resource requirements, if the hardware resource condition requirements meet the hardware resource conditions, executing step (3), otherwise, updating the initial quantization strategy based on the hardware resource requirements and the search space, and repeating step (2);

[0255] (3) Perform the evaluation process "model performance evaluation module". If the performance evaluation result meets the performance constraint condition, the whole process is terminated. Otherwise, the initial quantization strategy is updated based on the performance evaluation result and the search space, and steps (2)-(3) are repeated.

[0256] (4) Repeat the above steps until the optimal quantization solution that satisfies both the hardware resource conditions and the performance constraints is produced or the search stop condition (such as the maximum search rounds, the longest search time) is triggered.

[0257] For updating the initial quantization strategy described in the above step, a heuristic algorithm or a machine learning algorithm may be used to search and combine new quantization schemes from the search space.

[0258] Hardware resource evaluation module: used to estimate the computing and storage requirements of the target model based on the initial quantization strategy generated by the search engine. The computing requirement refers to the computational complexity of the inherent matrix calculation, quantization, dequantization and other operations of each layer under the corresponding quantization scheme calculated by the algorithm according to the model input, output length, model concurrency and other requirements specified by the user; the storage requirement refers to the video memory space required for the model weights, activations, j key-value pair cache and other parts under the corresponding quantization scheme calculated by the algorithm according to the model input, output length, model concurrency and other requirements specified by the user.

[0259] Based on the evaluated hardware resource requirements, by comparing the hardware resource condition restrictions such as the computing unit (computing power), video memory size, and video memory bandwidth of the user-specified hardware with the resource requirements, the quantization schemes that are infeasible according to theoretical estimation are filtered out. For example, the model still requires at least 13GB of video memory space under the initial quantization strategy, which is not feasible on a GPU with a hardware resource condition of 11G video memory, and the initial quantization strategy needs to be re-determined.

[0260] Quantization engine module: quantizes the target model according to the current initial quantization strategy and converts the model's weights into a quantized format. For models that require offline quantization, the quantization engine will perform quantization operations and save the quantized model in a specific format suitable for loading and use in the inference phase. For inference engines that support dynamic quantization, the quantization engine will generate corresponding configuration parameters so that the inference phase can perform quantization operations based on the configuration parameters when the model is running.

[0261] Model performance evaluation engine module: used to evaluate the accuracy and performance of the quantized model. Accuracy evaluation measures the impact of quantization by comparing the performance indicators of the quantized model and the unquantized model on open source data sets and business data sets, such as perplexity and accuracy. Performance evaluation can run the quantized model on the target hardware device to test its inference speed, hardware utilization rate and other indicators.

[0262] Decision engine module: Uses the results of the model performance evaluation engine and the accuracy and performance requirements set by the user to determine whether the quantization strategy is feasible. If the evaluation results meet or exceed expectations, the quantization strategy is determined as the model quantization strategy for the target model in the hardware environment of the device to be deployed. Otherwise, it guides the search engine module in the search process to continue iterative search and optimize the quantization solution.

[0263] Graphical User Interface: Users can use this interface to configure resource limits, accuracy performance targets, and the data sets required for the model performance evaluation module, and monitor the search and evaluation process of the quantization scheme in real time according to the prompt information on the interface. The configured data sets can be managed and preprocessed through the data management module to evaluate the data sets required for the quantization strategy, support control of data set versions, preprocessing of data, and efficient loading of data sets, and flexibly adapt to various business scenarios.

[0264] In combination with the method described in the above-mentioned embodiment, this embodiment takes the quantization deployment scenario of a large language model as an example to exemplify the above-mentioned method for determining the model quantization strategy.

[0265] Assume that an A30 graphics card with 24GB of video memory is pre-installed on the device to be deployed, which is used to deploy the model to provide external services. The user has built a chatbot based on a large language model. The large language model used is the Llama13B model. The deployment of the Llama13B model requires at least 26GB of video memory by default, and it cannot be deployed using a single A30 graphics card. Therefore, the model quantization method provided in the present disclosure can be used to quantize the large language model to meet scenario requirements.

[0266] Based on the above scenario, the hardware resource condition of the device to be deployed is that the video memory does not exceed 24GB, and the performance constraint conditions set by the user are: the inference speed is not less than 40 tokens / s, and the perplexity index of the model on the open source data set is not less than 8. The method for determining the model quantization strategy in this scenario can include the following process:

[0267] Receive the model information, hardware resource conditions (graphics card information) and performance constraints (inference speed requirements, inference PPL index requirements) of the large language model input by the user on the graphical user page;

[0268] Receive open source datasets uploaded by users through the graphical user page;

[0269] In response to receiving the quantization request, using an 8-bit integer quantization strategy of only weight quantization in a preset quantization strategy set as a first quantization strategy;

[0270] Determine the video memory occupancy of the large language model under the 8-bit integer quantization strategy of weight quantization only. Assuming that the video memory requirement under the first quantization strategy is 17GB of video memory, and the A30 graphics card supports providing 24GB of video memory, determine whether the hardware resource requirement matches the hardware resource condition; if the video memory occupancy is higher than 24GB, it is necessary to determine other quantization strategies except the first quantization strategy from the preset quantization strategy set to update the first quantization strategy;

[0271] When the hardware resource requirement matches the hardware resource condition, quantizing the weight parameters of the large language model into an 8-bit integer format according to the first quantization strategy;

[0272] Load the quantized large language model and use the open source dataset to test the inference speed and perplexity of the model. Assuming that the inference speed of the quantized model is 50 tokens / s, which meets the inference speed threshold, and the perplexity index is 7.5, which does not meet the perplexity threshold, it is determined that the performance evaluation result does not meet the performance constraint conditions;

[0273] When it is determined that the performance evaluation result does not meet the performance constraint condition, repeat the above steps to iterate the first quantization strategy until a first quantization strategy that satisfies both the hardware resource condition and the performance constraint condition is found, that is, a heuristic algorithm can be used to search for a new quantization strategy in the "search space" to update the first quantization strategy, and the memory occupancy and performance evaluation of the updated first quantization strategy are repeatedly determined;

[0274] For example, the linear quantization strategy in the 8-bit integer quantization strategy of weight quantization only is replaced by a nonlinear quantization strategy using quantile mapping. Through the above steps, when the video memory occupancy is less than 24GB, the inference speed is 45 token / s and the perplexity is 8.1. It is judged that the current first quantization strategy meets the hardware resource and performance constraint requirements, so that the first quantization strategy can be determined as the model quantization strategy for deploying the large language model to the device to be deployed, and then the model deployment is completed according to the model quantization strategy and services are provided to the outside.

[0275] The above embodiment is a process provided by the present invention for adaptively determining a model quantization strategy based on a specific hardware resource environment and performance requirements. After the user sets the constraint information such as the model, hardware resources, and performance requirements, the model quantization strategy that meets the requirements can be automatically generated through iterative updates of the quantization strategy. When there is no suitable quantization solution or the search stop condition is reached, the search can be exited and the user can be prompted that there is no available solution, so that the user can adjust the constraint information to redetermine the quantization strategy or manually determine the quantization strategy.

[0276] Exemplary Devices

[0277] After introducing the method of the exemplary embodiment of the present disclosure, next, refer to Fig. 9 A device according to an exemplary embodiment of the present disclosure is described.

[0278] The implementation process of the functions and effects of each module in the following device is specifically described in the implementation process of the corresponding steps in the above method, which will not be repeated here. For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can be referred to the partial description of the method embodiment.

[0279] Fig. 9 A model quantization strategy determination device according to an embodiment of the present disclosure is schematically shown, the device comprising:

[0280] An initialization module 910 is used to obtain a first quantization strategy of a target model from a preset quantization strategy set;

[0281] A resource requirement and performance evaluation module 920, configured to determine the hardware resource requirements of the target model under the first quantization strategy, and obtain a performance evaluation result of the target model after quantization using the first quantization strategy;

[0282] A policy updating module 930 is configured to update the first quantization policy by using other quantization policies in the quantization policy set except the first quantization policy, when the hardware resource requirement does not match the hardware resource condition of the device to be deployed, or the performance evaluation result does not meet the preset performance constraint condition, until both the hardware resource condition and the performance constraint condition are met;

[0283] The quantization strategy determination module 940 is used to determine the first quantization strategy as the model quantization strategy when the target model is deployed to the device to be deployed.

[0284] In an optional implementation, after determining the hardware resource requirement, the device may further include: a hardware resource matching detection module, configured to compare the hardware resource requirement with the hardware resource condition of the device to be deployed, and generate a matching result between the hardware resource requirement and the hardware resource condition;

[0285] The resource demand and performance evaluation module is specifically used for:

[0286] When the hardware resource requirement matches the hardware resource condition, the target model is quantized according to the first quantization strategy; and a performance evaluation result of the quantized target model is obtained.

[0287] In an optional implementation, the hardware resource condition includes resource thresholds of different hardware resources; the hardware resource requirement includes the requirement values ​​of the different hardware resources; and the hardware resource matching detection module is specifically used for:

[0288] Comparing the demand value of the same hardware resource with the corresponding resource threshold;

[0289] In a case where each requirement value is less than or equal to the corresponding resource threshold, it is determined that the hardware resource requirement matches the hardware resource condition.

[0290] In an optional implementation, when each demand value is less than or equal to the corresponding resource threshold, before determining that the hardware resource demand matches the hardware resource condition, the apparatus further includes:

[0291] When each requirement value is less than or equal to the corresponding resource threshold, obtaining the hardware resource requirement of each layer of the target model;

[0292] Determine the maximum demand value of each hardware resource according to the hardware resource demand of each layer of the network, and compare the maximum demand value with the corresponding resource threshold;

[0293] When the maximum demand value of each hardware volunteer is less than or equal to the corresponding resource threshold, it is determined that the hardware resource demand matches the hardware resource condition.

[0294] In an optional implementation manner, when the hardware resource requirement does not match the hardware resource condition of the device to be deployed, the policy updating module is specifically configured to:

[0295] Determining resource types that do not match the hardware resource condition;

[0296] Determining a candidate quantization strategy from the quantization strategy set according to the degree of influence of the quantization strategy on the hardware resources of the resource type;

[0297] According to the parameter combination of the first quantization strategy, a second quantization strategy is determined from the candidate quantization strategies to update the first quantization strategy.

[0298] In an optional implementation manner, when the hardware resource requirement matches the hardware resource condition and the performance evaluation result does not meet the performance constraint condition, the policy updating module is specifically used to:

[0299] Using the performance evaluation result and the first quantization strategy as inputs of a preset optimization algorithm, obtaining a third quantization strategy for iterative search by the optimization algorithm; updating the first quantization strategy according to the third quantization strategy;

[0300] Alternatively, based on the performance evaluation result and the parameter combination of the first quantization strategy, a quantization strategy parameter combination that meets the performance constraint condition is determined; based on the quantization strategy parameter combination, the quantization strategy with the highest matching degree in the quantization strategy set is determined to update the first quantization strategy.

[0301] In an optional implementation manner, the policy update module is specifically used to:

[0302] In the case where the preset policy update stop condition is not met, if other quantization policies are searched to update the first quantization policy, the first quantization policy is continued to be updated until the hardware resource condition and the performance constraint condition are simultaneously met; if no other quantization policies are searched, the first quantization policy is stopped from being updated; the policy update stop condition includes at least one of the longest policy update time and the maximum policy update rounds;

[0303] When the policy update stopping condition is met, the updating of the first quantization policy is stopped, and prompt information is controlled to be displayed on the quantization interaction interface, so that the user can perform adjustment operations according to the prompt information.

[0304] In an optional embodiment, the device further comprises:

[0305] Receive the model information of the target model, the hardware resource conditions of the device to be deployed, and the performance constraint conditions input by the user on the quantization interaction page;

[0306] In response to receiving the start indication information from the quantization interaction page, the target model is loaded from a predefined model library according to the model information, and the first quantization strategy is obtained from a preset quantization strategy set.

[0307] In an optional embodiment, the device further comprises:

[0308] Receive the verification data set uploaded by the user on the quantitative interaction page;

[0309] The obtaining a performance evaluation result of the target model after quantization using the first quantization strategy includes:

[0310] Obtain a performance evaluation result of the target model quantized by the first quantization strategy on the validation data set.

[0311] In an optional embodiment, the device further comprises:

[0312] According to the validation data set, obtaining an unquantized performance result of the target model that has not been quantified;

[0313] In the case of receiving a performance constraint condition input by a user, in response to the performance constraint condition being higher than the unquantified performance result, controlling the display of the unquantified performance result on the quantified interaction page, and instructing the user to adjust the performance constraint condition;

[0314] In a case where the performance constraint condition input by the user is not received, the performance constraint condition is determined according to the unquantified performance result.

[0315] In an optional implementation, the performance constraint condition includes at least one performance indicator threshold; the performance indicator threshold is determined according to the unquantified performance result; after obtaining the performance evaluation result of the target model after quantization using the first quantization strategy, the device further includes:

[0316] Determine the difference between each performance indicator in the performance evaluation result and the corresponding performance indicator threshold;

[0317] When the difference amount of each performance indicator satisfies the set difference range, it is determined that the performance evaluation result meets the performance constraint condition.

[0318] In an optional implementation, the quantization strategy set includes at least one of bit width quantization strategies for different quantization bit widths, linear quantization strategies and nonlinear quantization strategies, and object quantization strategies for different quantization objects.

[0319] Based on the above-mentioned model quantization strategy determination device, the present disclosure also provides a model quantization device, see Fig.10 As shown, the device comprises:

[0320] A model quantization strategy determination module 1010 is used to determine a quantization strategy of a target model used by a device to be deployed, wherein the quantization strategy is determined using the above-mentioned model quantization strategy determination method;

[0321] The quantization deployment module 1020 is used to quantize the target model according to the quantization strategy, and deploy the quantized target model to the to-be-deployed device to provide corresponding services.

[0322] Exemplary Media

[0323] After introducing the method and apparatus of the exemplary embodiments of the present disclosure, next, reference is made to Fig.11 A readable storage medium according to an exemplary embodiment of the present disclosure is described.

[0324] In this exemplary embodiment, the above method can be implemented by a program product, such as a portable compact disk read-only memory (CD-ROM) and including program code, and can be run on a device, such as a personal computer. However, the program product of the present disclosure is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus, or a device.

[0325] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0326] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0327] The program code contained on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RE, etc., or any suitable combination of the foregoing.

[0328] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as C or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user computing device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).

[0329] Exemplary Computing Devices

[0330] After introducing the method, apparatus and medium of the exemplary embodiments of the present disclosure, next, reference is made to Fig.12 A computing device according to an exemplary embodiment of the present disclosure is described.

[0331] Fig.12 The computing device 1200 shown is merely an example and should not bring any limitation to the functionality and scope of use of the embodiments of the present disclosure.

[0332] like Fig.12 As shown, the computing device 1200 is in the form of a general computing device. The components of the computing device 1200 may include but are not limited to: at least one processing unit 1201, at least one storage unit 1202, and a bus 1203 connecting different system components (including the processing unit 1201 and the storage unit 1202).

[0333] The bus 1203 includes a data bus, a control bus, and an address bus.

[0334] The storage unit 1202 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 12021 and / or a cache memory 12022 , and may further include a readable medium in the form of a non-volatile memory, such as a read-only memory (ROM) 12023 .

[0335] The storage unit 1202 may also include a program / utility 12025 having a set (at least one) of program modules 12024, such program modules 12024 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0336] The computing device 1200 may also communicate with one or more external devices 1204 (eg, a keyboard, pointing device, etc.).

[0337] Such communication may be performed via input / output (I / O) interface 1205. In addition, computing device 1200 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via network adapter 1206. Fig.12 As shown, the network adapter 1206 communicates with other modules of the computing device 1200 via the bus 1203. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the computing device 1200, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0338] It should be noted that although several units / modules or sub-units / modules of the model quantization strategy determination device and the model quantization device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to an embodiment of the present disclosure, the features and functions of two or more units / modules described above may be embodied in one unit / module. Conversely, the features and functions of one unit / module described above may be further divided to be embodied by multiple units / modules.

[0339] In addition, although the operations of the disclosed method are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0340] Although the spirit and principle of the present disclosure have been described with reference to several specific embodiments, it should be understood that the present disclosure is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present disclosure is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the attached claims.

Claims

1. A method for determining a model quantization strategy, characterized in that: The method comprises: Obtaining a first quantization strategy for a target model from a preset quantization strategy set; Determine the hardware resource requirements of the target model under the first quantization strategy, and obtain a performance evaluation result of the target model after quantization using the first quantization strategy; When the hardware resource requirement does not match the hardware resource condition of the device to be deployed, or the performance evaluation result does not meet the preset performance constraint condition, update the first quantization strategy using other quantization strategies in the quantization strategy set except the first quantization strategy until both the hardware resource condition and the performance constraint condition are met; The first quantization strategy is determined as the model quantization strategy when the target model is deployed to the device to be deployed.

2. The method according to claim 1, characterized in that: After determining the hardware resource requirements, the method further includes: Compare the hardware resource requirement with the hardware resource condition of the device to be deployed, and generate a matching result between the hardware resource requirement and the hardware resource condition; The obtaining a performance evaluation result of the target model after quantization using the first quantization strategy includes: When the hardware resource requirement matches the hardware resource condition, quantizing the target model according to the first quantization strategy; Obtain the performance evaluation results of the quantized target model.

3. The method according to claim 2, characterized in that The hardware resource condition includes resource thresholds of different hardware resources; the hardware resource requirement includes the requirement value of the different hardware resources; the comparing the hardware resource requirement with the hardware resource condition of the device to be deployed to generate a matching result between the hardware resource requirement and the hardware resource condition includes: Comparing the demand value of the same hardware resource with the corresponding resource threshold; In a case where each requirement value is less than or equal to the corresponding resource threshold, it is determined that the hardware resource requirement matches the hardware resource condition.

4. The method according to claim 1, characterized in that: In a case where the hardware resource requirement does not match the hardware resource condition of the device to be deployed, the updating of the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy includes: Determining resource types that do not match the hardware resource condition; Determining a candidate quantization strategy from the quantization strategy set according to the degree of influence of the quantization strategy on the hardware resources of the resource type; According to the parameter combination of the first quantization strategy, a second quantization strategy is determined from the candidate quantization strategies to update the first quantization strategy.

5. The method according to claim 1, characterized in that When the hardware resource requirement matches the hardware resource condition and the performance evaluation result does not meet the performance constraint condition, updating the first quantization strategy by using other quantization strategies in the quantization strategy set except the first quantization strategy includes: Using the performance evaluation result and the first quantization strategy as inputs of a preset optimization algorithm, obtaining a third quantization strategy for iterative search by the optimization algorithm; updating the first quantization strategy according to the third quantization strategy; or, According to the performance evaluation result and the parameter combination of the first quantization strategy, a quantization strategy parameter combination that meets the performance constraint condition is determined; according to the quantization strategy parameter combination, a quantization strategy with the highest matching degree in the quantization strategy set is determined to update the first quantization strategy.

6. A model quantization method, characterized in that: The method comprises: Determine a target quantization strategy for a target model used by the device to be deployed, wherein the target quantization strategy is determined using the method described in any one of claims 1 to 5; The target model is quantified according to the target quantization strategy, and the quantified target model is deployed to the device to be deployed to provide corresponding services.

7. A device for determining a model quantization strategy, characterized in that: The device comprises: An initialization module, used for obtaining a first quantization strategy of a target model from a preset quantization strategy set; A resource requirement and performance evaluation module, used to determine the hardware resource requirements of the target model under the first quantization strategy, and obtain a performance evaluation result of the target model after quantization using the first quantization strategy; A policy updating module, configured to update the first quantization policy by using other quantization policies in the quantization policy set except the first quantization policy, when the hardware resource requirement does not match the hardware resource condition of the device to be deployed, or the performance evaluation result does not meet the preset performance constraint condition, until both the hardware resource condition and the performance constraint condition are met; A quantization strategy determination module is used to determine the first quantization strategy as the model quantization strategy when the target model is deployed to the device to be deployed.

8. A model quantization device, characterized in that: The device comprises: A model quantization strategy determination module, used to determine a quantization strategy of a target model used by a device to be deployed, wherein the quantization strategy is determined using a method as described in any one of claims 1 to 5; The quantization deployment module is used to quantize the target model according to the quantization strategy, and deploy the quantized target model to the to-be-deployed device to provide corresponding services.

9. A readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 or claim 6 is implemented.

10. A computing device, characterized in that include: Processor, memory; The memory is used to store computer programs; The processor is used to execute the method according to any one of claims 1 to 5 or claim 6 by calling the computer program.

Citation Information

Cited By

  • Model effect evaluation system and method based on quantitative reasoning

    CN119292892A

  • A model effect evaluation system and method based on quantitative reasoning

    CN119292892B

  • Model compression method deployed on hardware equipment

    CN119808873A

  • Model quantitative perceptual training system on edge device

    CN120745751A

  • Model quantization-aware training system on edge devices

    CN120745751B