Compatible processing method and device for machine learning

Through detection and dynamic selection of the backend, model and data preprocessing optimization is carried out, and multi-threading technology is used to solve the compatibility and performance problems of machine learning models in JavaScript environment, achieving efficient and stable operation in different environments.

CN119227830APending Publication Date: 2024-12-31SHENZHEN DIANMAO TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411102412.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

In the JavaScript environment, the machine learning model has compatibility problems due to differences in browser version and device hardware, which affects the efficiency and stability of development and application, and the existing technology has not been effectively solved.

Method used

By detecting whether the current device and environment support the set backend, dynamically select the optimal backend, and pre-processing and optimization of model and data based on the selected backend characteristics, the model is trained using multi-threading and background threading technology to ensure that the model is different Compatibility and performance for running in an environment.

Benefits of technology

It significantly improves the compatibility and operation efficiency of the machine learning model in different browser versions and hardware environments, provides an efficient and stable solution on the browser side, and enhances the developer experience and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119227830A_ABST
    Figure CN119227830A_ABST
Patent Text Reader

Abstract

The invention discloses a compatible processing method and device for machine learning. The method comprises the following steps: when a machine learning model is initialized, detecting whether a current device and a current environment support a set back end, and under the condition that the current device and the current environment do not support the set back end, reselecting a new back end as a selected back end according to the current device and the current environment; under the condition that the current equipment and the current environment support the set back end, taking the set back end as a selected back end; performing preprocessing optimization on the machine learning model and training data for training the machine learning model based on the characteristics of the selected back end; and training the machine learning model in a background thread by using the training data by utilizing multiple threads and a tool for supporting a task to run in the background thread. The technical problem of poor compatibility during machine learning is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence, and more specifically, to a compatible processing method and device for machine learning. Background Art

[0002] Machine learning plays an important role in modern computing and is widely used in image recognition, natural language processing and other fields. In recent years, with the widespread use of JavaScript in the Web front-end, JavaScript-based machine learning frameworks (such as TensorFlow.js) have been developed, making it possible to perform machine learning in the browser. However, due to differences in different browser versions and device hardware, machine learning in the JavaScript environment has compatibility issues, such as different backend support and large performance differences. This poses a great challenge to developers and is also a problem that needs to be solved in practical applications.

[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0004] The embodiments of the present application provide a compatible processing method and device for machine learning, so as to at least solve the technical problem of poor compatibility in machine learning.

[0005] According to one aspect of an embodiment of the present application, a compatible processing method for machine learning is provided, including: when initializing a machine learning model, detecting whether a current device and a current environment support a set backend, and if the current device and the current environment do not support the set backend, reselecting a new backend as the selected backend according to the current device and the current environment; if the current device and the current environment support the set backend, using the set backend as the selected backend; based on the characteristics of the selected backend, preprocessing and optimizing the machine learning model and the training data used to train the machine learning model; and using multi-threading and tools that support tasks running in background threads to train the machine learning model using the training data in the background thread.

[0006] According to another aspect of an embodiment of the present application, a compatible processing device for machine learning is also provided, including: a compatible processing module, configured to: when initializing the machine learning model, detect whether the current device and the current environment support the set backend, and if the current device and the current environment do not support the set backend, reselect a new backend as the selected backend according to the current device and the current environment; if the current device and the current environment support the set backend, use the set backend as the selected backend; an optimization module, configured to pre-process and optimize the machine learning model and the training data used to train the machine learning model based on the characteristics of the selected backend; a training module, configured to use multi-threading and a tool (Web Worker) that supports tasks running in background threads to train the machine learning model using the training data in the background thread.

[0007] In an embodiment of the present application, when initializing a machine learning model, it is detected whether the current device and the current environment support the set backend. If the current device and the current environment do not support the set backend, a new backend is reselected as the selected backend according to the current device and the current environment; if the current device and the current environment support the set backend, the set backend is used as the selected backend; based on the characteristics of the selected backend, the machine learning model and the training data used to train the machine learning model are preprocessed and optimized; and the training data is used in the background thread to train the machine learning model using multithreading and tools that support tasks running in background threads. The above scheme solves the technical problem of poor compatibility in machine learning. BRIEF DESCRIPTION OF THE DRAWINGS

[0008] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0009] Figure 1 is a flowchart of a compatible processing method for machine learning according to an embodiment of the present application;

[0010] Figure 2 It is a flowchart of a compatibility processing method for performing machine learning in a JavaScript environment according to an embodiment of the present application;

[0011] Figure 3 is a flowchart of another compatibility processing method for performing machine learning in a JavaScript environment according to an embodiment of the present application;

[0012] Figure 4 is a flowchart of a different backend optimization method according to an embodiment of the present application;

[0013] Figure 5 is a structural schematic diagram of a machine learning compatible processing device according to an embodiment of the present application;

[0014] Figure 6 is a schematic structural diagram of another machine learning compatible processing device according to an embodiment of the present application;

[0015] Figure 7 A schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0016] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0017] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0018] According to an embodiment of the present application, a method embodiment of a compatible processing method for machine learning is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0019] Figure 1 is a compatible processing method of machine learning according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:

[0020] Step S102, when initializing the machine learning model, detect whether the current device and the current environment support the set backend. If the current device and the current environment do not support the set backend, reselect a new backend as the selected backend according to the current device and the current environment; if the current device and the current environment support the set backend, use the set backend as the selected backend.

[0021] Automatically detect the current device and the environment, and select an optimal backend according to the current device and the current environment; in the case where it is detected that the optimal backend is modified by the provided option of manually setting the backend, use the modified optimal backend as the set backend, otherwise, use the optimal backend as the set backend.

[0022] If the current device and the current environment do not support the set backend, fall back to a suboptimal backend of the set backend according to the current device and the current environment; detect whether the current device and the current environment support the suboptimal backend, and if the current device and the current environment do not support the suboptimal backend, fall back to the CPU backend according to the current device and the current environment, and use the CPU backend as the selected backend.

[0023] Step S104, preprocessing and optimizing the machine learning model and the training data used to train the machine learning model based on the characteristics of the selected backend;

[0024] Selecting a corresponding preprocessing strategy based on the selected backend, wherein selecting a corresponding preprocessing strategy based on the selected backend includes: for the WebGL backend, utilizing the parallel computing of the GPU for batch processing; for the WASM backend, performing mathematical operation optimization; and based on the characteristics of the selected backend, performing quantization processing and cropping operations on the machine learning model and the training data used to train the machine learning model.

[0025] Step S106, using multi-threading and tools that support tasks running in background threads to train the machine learning model using the training data in the background thread.

[0026] When the selected backend is a CPU backend or a WASM backend, use multithreading and tools that support tasks running in background threads to train the machine learning model using the training data on the selected backend; for browsers that support multithreaded drawing (OffscreenCanvas), run WebGL backend multithreading optimization in tools that support tasks running in background threads.

[0027] After using the training data to train the machine learning model, use a detection tool to analyze the hardware characteristics and software environment of the current device; based on the analysis results of the hardware characteristics and software environment, dynamically adjust the operation strategy of the machine learning model.

[0028] Through the above steps, this application solves the compatibility and performance issues of different browser versions and different hardware devices when performing machine learning in a JavaScript environment, and provides a feasible solution for efficiently and stably running machine learning models on the browser side.

[0029] The present application also provides a compatibility processing method for performing machine learning in a JavaScript environment, such as Figure 2 As shown, the processing method includes the following steps:

[0030] Step S202: priority setting.

[0031] The machine learning framework supports multiple backends (such as WebGL, WASM, CPU) in different hardware environments. The execution efficiency and compatibility of the backend will significantly affect the running effect of the model. When the model is initialized, it automatically selects the optimal backend according to the current device and browser environment, and provides the option of manually setting the backend to ensure compatibility and stability in various environments.

[0032] Step S204: compatibility determination and fallback mechanism.

[0033] Before running the machine learning model, check whether the current environment supports the set backend (such as WebGL). If it is detected that the current environment does not support the set backend, it is necessary to fall back to the suboptimal backend (such as WASM) in time; if even the suboptimal backend is not supported, it will eventually fall back to the CPU backend. Finally, provide a compatibility report that records in detail the reasons for each fallback and the final backend used to help developers optimize the model's operating environment.

[0034] Step S206: model and data preprocessing optimization.

[0035] Based on different backend features, preprocess and optimize the model and data (such as quantization, cropping, etc.) to improve the efficiency of backend execution. Choose different preprocessing strategies based on different backends. For example, for the WebGL backend, you can use the parallel computing advantages of the GPU for batch processing; for the WASM backend, you can perform appropriate mathematical operation optimization.

[0036] Step S208: multi-threading and Web Worker support.

[0037] Under the CPU and WASM backend, multithreading and Web Worker technology are used to enable model training and reasoning to be performed in background threads, avoiding blocking the main thread and improving the responsiveness of the user interface. For browsers that support OffscreenCanvas, the WebGL backend is allowed to run in Web Worker, further improving parallel computing capabilities.

[0038] Step S210, analyzing the differences between the front-end device and the environment.

[0039] Use detection tools to analyze the hardware characteristics of the current device (such as GPU type, number of CPU cores and frequency, memory size, etc.) and software environment (such as browser version, operating system type, etc.). Dynamically adjust the model operation strategy based on the characteristics analysis results. For example, select lightweight models and optimized algorithms on low-performance devices to ensure the running speed and stability of the model.

[0040] Through the above technical solutions, this application achieves the following technical effects: 1) Significantly improve compatibility: By dynamically selecting the backend and fallback mechanism, ensure that the machine learning model can run stably and efficiently under different hardware environments and browser versions. 2) Improve operation efficiency: Perform preprocessing optimization and multi-threading support based on the characteristics of different backends to greatly improve the model's operation efficiency and user experience. 3) Refined device support: Dynamically adjust the model operation strategy according to device and environmental differences to achieve refined support for various front-end hardware devices. 4) Enhance developer experience: Provide compatibility reports and optimization suggestions to help developers quickly locate and solve compatibility issues and improve development efficiency.

[0041] The present application embodiment also provides another compatibility processing method for performing machine learning in a JavaScript environment, such as Figure 3 As shown, the method includes:

[0042] Step S302: priority setting.

[0043] During the initialization phase of the machine learning model, the system automatically selects the optimal backend based on the environmental characteristics of the current device and browser. Typically, different hardware environments support different backends, such as WebGL, WebAssembly (WASM), and CPU. Since these backends have significant differences in execution efficiency and compatibility in different environments, it is critical to select the backend that best suits the current device and browser environment when initializing the model. To this end, the system automatically detects the hardware configuration of the current device, such as GPU model, CPU performance, and related features of the browser, and automatically selects the optimal backend based on this information. In addition, to provide greater flexibility, users can also manually set the priority of the backend to meet specific needs or resolve compatibility issues in special environments.

[0044] Step S304: roll back when incompatible.

[0045] Before the machine learning model runs, the system will first detect whether the current environment supports the set backend, such as WebGL. If the detection result shows that the current environment does not support the preset optimal backend, the system will start the fallback mechanism and try to use the suboptimal backend, such as WASM. If the suboptimal backend also cannot support the current environment, the system will eventually fall back to the CPU backend to ensure that the model can continue to run.

[0046] This compatibility judgment and fallback mechanism ensures that the model can run normally in any environment, avoiding model execution failures due to environmental incompatibility. The specific reasons for each fallback operation and the final backend selected will be recorded in detail in the compatibility report.

[0047] Step S306: data preprocessing.

[0048] According to the characteristics of the selected backend, the system will perform corresponding preprocessing optimization on the model and data to improve the execution efficiency of the backend. Different backends have different characteristics when processing models and data. For example, the WebGL backend can use the parallel computing power of the GPU to batch process large amounts of data, while the WASM backend can improve performance through mathematical operation optimization. The system will use different preprocessing strategies, such as quantization and clipping operations, based on the currently selected backend to further improve the execution efficiency and overall performance of the model. By optimizing the characteristics of different backends, the system can ensure that the model's operating efficiency is optimal in different environments.

[0049] In order to ensure the efficient operation of the model on different backends, the embodiment of the present application proposes a method for optimizing the model and data preprocessing according to the backend characteristics. Through this method, the system can perform corresponding preprocessing optimization on the model and data according to the selected backend characteristics to improve the execution efficiency of the backend, thereby ensuring the best performance of the model in different environments.

[0050] First, during the model loading and initialization process, the system will automatically identify the parts that need to be preprocessed based on the selected backend characteristics. These preprocessing operations include but are not limited to data quantization, model pruning, feature standardization, and dimensionality reduction. Each backend has its own unique computing characteristics, so the optimization strategies for different backends are also different. Figure 4 As shown, the method comprises the following steps:

[0051] Step S3062: data quantization processing.

[0052] The quantized data is calculated based on the minimum and maximum values ​​of the original data and the number of quantized bits; the number of quantized bits is dynamically updated based on the variance of the quantized data, the entropy of the quantized data and the balance factor to obtain the optimal number of quantized bits; and new quantized data is regenerated based on the optimal number of quantized bits.

[0053] Specifically, when using WebGL as the backend, the system will prioritize quantizing the input data. The purpose of quantization is to compress floating-point data into a lower-precision integer form, such as compressing a 32-bit floating-point number into a 16-bit or 8-bit integer. Quantization can be expressed as the following formula:

[0054]

[0055] Among them, Q(x) represents the quantized data, x is the original data, b is the number of quantized bits (for example, 8 bits or 16 bits), and min(x) and max(x) are the minimum and maximum values ​​of the original data, respectively. In this way, the computational burden of the GPU can be significantly reduced, and memory usage can be reduced, thereby improving data transmission efficiency and overall computing speed. However, the quantization process may result in a certain loss of precision, so the present application provides another adaptive quantization algorithm. The algorithm calculates the variance and entropy of the quantized data, and automatically adjusts the number of quantization bits according to the dynamic range and distribution of the quantized data to find the best balance between compression efficiency and calculation accuracy. The formula is as follows:

[0056] b opt =argmin b {Var(Q(x))+λ×H(Q(x))}

[0057] Among them, bopt is the optimal number of quantization bits, Var(Q(x)) is the variance of the quantized data, H(Q(x)) is the entropy of the quantized data, and λ is the balance factor. This improvement can maximize the execution efficiency while ensuring accuracy. Substitute the optimal number of quantization bits into the above quantization formula and recalculate the new quantized data.

[0058] Step S3064: model cutting operation.

[0059] In the preprocessing stage of the model, the system will also use the sensitivity analysis function to prune the model according to the computing power of the backend. Taking the WebGL backend as an example, the system will analyze the redundant nodes and weight matrices in the model, and use the pruning algorithm to remove the parts that have little impact on the final output, thereby reducing the amount of calculation of the model. The pruning operation can be represented by the sensitivity analysis function S(w):

[0060]

[0061] Among them, S(wi) is the sensitivity of weight wi, and L is the loss function of the model. When S(wi) is less than a certain threshold, weight wi is considered to have little effect on the model output and can be pruned. In addition, the pruned model is iteratively optimized to gradually improve its operating efficiency while maintaining accuracy.

[0062] Assume that f(x) is a multivariable function about x = (x1, x2, ..., xm), and its Taylor expansion at x = a = (a1, a2, ..., am) can be expressed as:

[0063]

[0064] In some other embodiments, it can also be expressed as:

[0065]

[0066] Among them, α is a multi-index, |α|=α1+α2+…+αm|, and Dαf(a) represents the higher-order partial derivative of f at a, defined as:

[0067]

[0068] And (xa)α represents the following product: (xa) α =(x1-a1) α1 (x2-a2) α2 …(x m -a m ) αm

[0069] Among them, Tn(x) is the nth-order Taylor expansion of f(x) at point a, which is used to approximate the value of f(x); f(a) is the function value of function f(x) at point a. It is the partial derivative of the function f(x) with respect to the i-th variable at point a, that is, the first-order partial derivative. It is the second-order partial derivative of the function f(x) at point a with respect to the i-th and j-th variables, that is, the second-order partial derivative. It is the nth-order mixed partial derivative of the function f(x) with respect to n variables at point a. is a product term, representing the variable deviation of each term in the n-th order Taylor expansion, α is a multi-index, used to represent multiple variables in higher-order derivatives and expansion terms. i and j represent the different dimensions of the variables, and m is the number of dimensions of the function fff. |α| represents the total order of the index α. f(a)D α is the high-order difference term of variable x relative to point a, expressed as the power product of the difference of each component, that is, α! is the factorial of the multiple exponent α, calculated as the product of the factorials of each component, i.e. m! α1! × α2! × … × α m ! .

[0070] Through this expansion, Taylor expansion can more accurately approximate high-order polynomial functions, especially in function optimization problems in multi-dimensional space, which can significantly simplify calculations and improve the ability to express complex functions. The above formula can be used to describe the optimization of mathematical operations in the WASM backend, replacing high-order complex functions with their low-order approximations during the pruning process, thereby reducing the amount of calculations and improving execution efficiency.

[0071] In some other embodiments, for the WASM backend, the pruning operation focuses on simplifying complex mathematical operations, such as replacing a high-order polynomial function f(x) with a low-order approximation Tn(x) of its Taylor expansion:

[0072]

[0073] Or a lookup table is used to reduce the complexity of real-time calculation. In other embodiments, the expression of Tn(x) can be expanded to consider multi-dimensional situations.

[0074] Step S3066: feature standardization

[0075] For the WASM backend, the system also performs feature normalization and dimensionality reduction. These operations can reduce the impact of numerical instability and redundant information during the calculation process, thereby improving the operating efficiency of the model. Feature normalization can be performed using the following formula:

[0076]

[0077] Among them, x′ is the standardized feature, x is the original data, μ and σ are the mean and standard deviation of the features of the original data x, respectively.

[0078] Step S3068, dimensionality reduction processing.

[0079] Dimensionality reduction can be achieved through principal component analysis (PCA) to extract the most representative features of the data. The mathematical expression of PCA is as follows:

[0080] Z=XW

[0081] Among them, Z is the data matrix after dimensionality reduction, X is the original data matrix, and W is the eigenvector matrix. Through dimensionality reduction processing, the system can significantly reduce the dimension of the data, thereby reducing the computational complexity of the model.

[0082] Step S3069, parallel computing optimization.

[0083] For the WebGL backend, the system will make full use of the parallel computing capabilities of the GPU and optimize the execution efficiency of the model through batch processing technology. The system will transfer the input data to the GPU in batches and use parallel matrix operations and convolution operations to maximize the utilization of GPU resources. Parallel matrix operations can be expressed as:

[0084] C=A×B

[0085] Among them, A and B are input matrices, and C is the result matrix. In order to reduce the data transmission overhead between the CPU and the GPU, the system will also use memory mapping technology to directly load the data into the GPU's memory to achieve efficient data processing.

[0086] Through the above-mentioned preprocessing process and improvement measures, the system can adopt the most appropriate optimization strategy according to the currently selected back-end characteristics. This not only improves the execution efficiency of the back-end, but also ensures the stability and accuracy of the model under different environments. In particular, by introducing adaptive quantization algorithms and improved pruning techniques, the embodiments of the present application can effectively cope with the model operation challenges under various hardware conditions, thereby providing users with a better machine learning experience. These improvement measures not only enhance the overall performance of the system, but also provide strong support for the cross-platform compatibility of the model. During the review process, the relevant preprocessing methods and improvement measures can help demonstrate the innovation and practicality of the invention, thereby increasing the possibility of patent authorization.

[0087] Step S308: multi-thread support.

[0088] In order to improve the execution efficiency of the model, especially under the CPU and WASM backend, the system introduces multithreading and WebWorker technologies. These technologies allow the model training and reasoning process to be performed in the background thread, thereby avoiding blocking the main thread and improving the responsiveness of the user interface. This is especially important for Web applications that require real-time response. In addition, for browsers that support OffscreenCanvas, the system also allows the WebGL backend to run in Web Worker, thereby further improving parallel computing capabilities and enhancing overall operating performance.

[0089] Step S310, dynamically adjust the strategy.

[0090] In order to ensure that the model runs efficiently on different devices and environments, the system uses detection tools to perform a detailed analysis of the hardware characteristics and software environment of the current device. These characteristics include the device's GPU type, number of CPU cores and frequency, memory size, browser version, and operating system type. Based on these analysis results, the system can dynamically adjust the model's operating strategy to adapt to the performance of different devices. For example, on low-performance devices, the system may choose a lighter model or use an optimized algorithm to ensure that the model can run at a higher speed and stability. Through this dynamic adjustment strategy, the system can adapt to the differences between various devices and environments, ensuring that the model runs efficiently and stably in a variety of scenarios.

[0091] The present application also provides a machine learning compatible processing device, such as Figure 5 As shown, it includes: a compatibility processing module 52, which is configured to: when initializing the machine learning model, detect whether the current device and the current environment support the set backend, and when the current device and the current environment do not support the set backend, reselect a new backend as the selected backend according to the current device and the current environment; when the current device and the current environment support the set backend, use the set backend as the selected backend; an optimization module 54, which is configured to pre-process and optimize the machine learning model and the training data used to train the machine learning model based on the characteristics of the selected backend; a training module 56, which is configured to use multi-threading and tools that support tasks running in background threads to train the machine learning model using the training data in the background thread.

[0092] The present application also provides another machine learning compatible processing system, such as Figure 6As shown, it includes a backend selection module 62 for selecting the optimal backend according to the device and browser environment during initialization, and provides a manual backend setting option. The compatibility judgment module 64 is used to detect whether the current environment supports the set backend, and executes a fallback mechanism if it does not support it. The preprocessing optimization module 66 is used to preprocess and optimize the model and data according to the backend characteristics. The multi-threading support module 68 is used to improve the model operation efficiency through Web Worker technology under the CPU and WASM backends. The environment analysis module 69 is used to analyze the hardware characteristics and software environment of the front-end device, and adjust the model operation strategy according to the analysis results.

[0093] It should be noted that the compatible processing device for machine learning provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the compatible processing device for machine learning provided in the above embodiment and the compatible processing method embodiment for machine learning belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0094] Figure 7 FIG. 1 shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present disclosure. It should be noted that: Figure 7 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0095] like Figure 7 As shown, the electronic device includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage part 1008 into a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for system operation are also stored. The CPU 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.

[0096] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage section 1008 as needed.

[0097] In particular, according to an embodiment of the present disclosure, the process described below with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1009, and / or installed from the removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, various functions defined in the method and apparatus of the present application are executed. In some embodiments, the electronic device may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0098] It should be noted that the computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-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 computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer 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. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0099] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0100] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, and the units described may also be arranged in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.

[0101] As another aspect, the present application further provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device.

[0102] The computer-readable medium carries one or more programs, and when the one or more programs are executed by an electronic device, the electronic device implements the method described in the following embodiments. For example, the electronic device can implement each step of the method embodiment.

[0103] As another aspect, the present application further provides an electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication. The memory stores a computer program executable by the at least one processor, and the computer program is used to enable the electronic device to perform the method of the embodiment of the present application when executed by the at least one processor.

[0104] As another aspect, the present application further provides a computer program product, including a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to execute the method of the embodiment of the present application.

[0105] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0106] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0107] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0108] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0109] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0110] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.

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

Claims

1. A compatible processing method for machine learning, characterized in that: include: When initializing the machine learning model, detect whether the current device and the current environment support the set backend. If the current device and the current environment do not support the set backend, reselect a new backend as the selected backend according to the current device and the current environment; if the current device and the current environment support the set backend, use the set backend as the selected backend; Preprocessing and optimizing the machine learning model and the training data used to train the machine learning model based on the characteristics of the selected backend; The machine learning model is trained using the training data in a background thread using multithreading and tools that support tasks running in background threads.

2. The method according to claim 1, characterized in that In the case that the current device and the current environment do not support the set backend, reselecting a new backend as the selected backend according to the current device and the current environment includes: If the current device and the current environment do not support the set backend, fall back to a suboptimal backend of the set backend according to the current device and the current environment; Detect whether the current device and the current environment support the suboptimal backend, and if the current device and the current environment do not support the suboptimal backend, fall back to the CPU backend according to the current device and the current environment, and use the CPU backend as the selected backend.

3. The method according to claim 1, characterized in that After training the machine learning model using the training data, the method further includes: Using a detection tool to analyze the hardware characteristics and software environment of the current device; Based on the analysis results of the hardware characteristics and software environment, the operation strategy of the machine learning model is dynamically adjusted.

4. The method according to claim 1, characterized in that Based on the characteristics of the selected backend, preprocessing and optimizing the machine learning model and the training data used to train the machine learning model includes: Selecting a corresponding preprocessing strategy based on the selected backend, wherein selecting a corresponding preprocessing strategy based on the selected backend includes: for a WebGL backend, using parallel computing of a GPU to perform batch processing; for a WASM backend, performing mathematical operation optimization; Based on the characteristics of the selected backend, the machine learning model and the training data used to train the machine learning model are quantized and trimmed.

5. The method according to claim 1, characterized in that Leveraging multithreading and tools that support tasks running in background threads to train the machine learning model using the training data on the selected backend, including: In the case where the selected backend is a CPU backend or a WASM backend, using multithreading and tools that support tasks running in background threads to train the machine learning model using the training data on the selected backend; For browsers that support multithreaded drawing, run the WebGL backend multithreading optimization in tools that support running tasks on background threads.

6. The method according to claim 1, characterized in that Before initializing the machine learning model, the method further includes: Automatically detect the current device and the environment, and select an optimal backend according to the current device and the current environment; In the case where it is detected that the optimal backend is modified by the provided option of manually setting the backend, the modified optimal backend is used as the set backend; otherwise, the optimal backend is used as the set backend.

7. A machine learning compatible processing device, characterized in that: include: The compatible processing module is configured to: when initializing the machine learning model, detect whether the current device and the current environment support the set backend, and if the current device and the current environment do not support the set backend, reselect a new backend as the selected backend according to the current device and the current environment; if the current device and the current environment support the set backend, use the set backend as the selected backend; An optimization module, configured to perform pre-processing optimization on the machine learning model and the training data used to train the machine learning model based on the characteristics of the selected backend; The training module is configured to utilize multi-threading and tools that support tasks running in background threads to train the machine learning model using the training data in the background thread.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 6.

9. A computer device, characterized in that: include: Memory and processor, The memory stores a computer program; The processor is used to execute the computer program stored in the memory, and when the computer program is run, the processor is enabled to execute the method according to any one of claims 1 to 6.

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