Model reasoning method, device, storage medium and program product

By pre-configuring the memory space of the maximum input data dimension in the AI ​​model and dynamically adjusting the output dimension, the problem of memory reallocation caused by changes in input dimensions during AI model inference is solved, and inference efficiency and latency are improved.

CN116757284BActive Publication Date: 2024-10-29HONOR DEVICE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211172258.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-26
Publication Date
2024-10-29
Estimated Expiration
2042-09-26

AI Technical Summary

Technical Problem

During the AI ​​model inference process, when the input dimensions change dynamically, the existing technology needs to reallocate the memory space of each operator, resulting in long inference delays and low efficiency.

Method used

By configuring the initialization memory space of each operator in advance according to the maximum input data dimension of the model to be processed, and determining the output dimension of the operator according to the dimension of the input data, it is ensured that the memory space is adapted to the maximum input data dimension allowed by the model, so as to There is no need to reallocate memory when input data dimensions change.

Benefits of technology

It reduces model inference latency, improves inference efficiency, and avoids memory reallocation problems caused by changes in input data dimensions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116757284B_ABST
    Figure CN116757284B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a model reasoning method, device, storage medium and program product, the method comprising: obtaining a model to be processed and input data, wherein each operator of the model to be processed is configured with an initialized memory space, and the initialized memory space is adapted to the maximum input data dimension allowed by the model to be processed; according to the data dimension of the input data and the maximum input data dimension, the output dimension of each operator of the model to be processed is determined; based on the input data, the output dimension of each operator and the initialized memory space, the model to be processed is reasoned, and the model reasoning result is output. The present application can reduce the model reasoning delay and improve the model reasoning efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a model reasoning method, device, storage medium and program product. Background Art

[0002] Artificial Intelligence (AI) is the study of the basic theories, methods and technologies of how to use computer hardware and software to simulate certain intelligent behaviors of humans. With the development of computer technology, the application of AI models is becoming more and more common. Artificial Neural Networks (ANNs) is an algorithmic mathematical model that imitates the behavioral characteristics of animal neural networks and performs distributed parallel information processing. The artificial neural network model is a common AI model and is widely used in various scenarios, such as natural language models, image recognition models, etc.

[0003] In actual scenarios, the trained AI model needs to be deployed on a server or end-side product to implement the model application through the model inference process. During the AI ​​model inference, in the initialization phase, the inference framework needs to allocate memory space that matches the input dimension for each operator of the model in order to realize the inference of the input data.

[0004] However, when the input dimension of the AI ​​model changes dynamically, if the above method is still used to allocate corresponding memory space for each operator, the memory space required by all operators in the model needs to be reallocated each time the input data changes, resulting in excessively long model inference delays and low inference efficiency. Summary of the invention

[0005] The embodiments of the present application provide a model reasoning method, device, storage medium and program product, which can reduce model reasoning delay and improve model reasoning efficiency.

[0006] In a first aspect, an embodiment of the present application provides a model inference method, comprising: obtaining a model to be processed and input data, wherein each operator of the model to be processed is configured with an initialized memory space, and the initialized memory space is adapted to the maximum input data dimension allowed by the model to be processed; determining the output dimension of each operator of the model to be processed according to the data dimension of the input data and the maximum input data dimension; reasoning the model to be processed based on the input data, the output dimension of each operator and the initialized memory space, and outputting a model inference result.

[0007] In one embodiment, before determining the output dimension of each operator of the model to be processed based on the data dimension of the input data, it also includes: obtaining the maximum input data dimension allowed by the model to be processed; and configuring the initialization memory space for each operator of the model to be processed based on the maximum input data dimension, wherein the initialization memory space is adapted to the maximum input data dimension.

[0008] In one embodiment, the initialization memory space is configured for each operator of the model to be processed according to the maximum input data dimension, and the initialization memory space is adapted to the maximum input data dimension, including: determining the memory resource occupancy of each operator according to the maximum input data dimension and the parameter configuration of each operator; and configuring the initialization memory space for each operator based on the memory resource occupancy, wherein, for each operator, the resource amount of the initialization memory space is greater than or equal to the memory resource occupancy.

[0009] In one embodiment, determining the output dimension of each operator of the model to be processed based on the data dimension of the input data and the maximum input data dimension includes: judging whether the data dimension of the input data is greater than the maximum input data dimension; if the data dimension of the input data is greater than the maximum input data dimension, determining the output dimension of each operator in the model to be processed based on the maximum input data dimension.

[0010] In one embodiment, determining the output dimension of each operator of the model to be processed based on the data dimension of the input data and the maximum input data dimension also includes: if the data dimension of the input data is less than or equal to the maximum input data dimension, determining the output dimension of each operator in the model to be processed based on the data dimension of the input data.

[0011] In one embodiment, the model to be processed is inferred based on the input data, the output dimension of each operator and the initialized memory space, and the model inference result is output, including: during the model inference process, detecting whether the current operator is configured with a preset attribute; if the current operator is configured with the preset attribute, updating the output dimension of the current operator based on the data received by the current operator and the parameter configuration of the current operator; based on the updated output dimension of the current operator and the input data, reasoning the current operator on the initialized memory space corresponding to the current operator to obtain the inference result of the current operator; determining the inference result of the model to be processed according to the inference results of all operators in the model to be processed.

[0012] In one embodiment, the model to be processed is inferred based on the input data, the output dimension of each operator and the initialized memory space, and the model inference result is output, which also includes: if the current operator is not configured with the preset attribute, based on the output dimension of the current operator and the input data, the current operator is inferred on the initialized memory space corresponding to the current operator to obtain the inference result of the current operator; according to the inference results of all operators in the model to be processed, the inference result of the model to be processed is determined.

[0013] In one embodiment, determining the inference result of the model to be processed based on the inference results of all operators in the model to be processed includes: passing the inference result of the current operator to the next operator, continuing model inference, until each operator of the model to be processed is traversed to obtain the model inference result.

[0014] In one embodiment, during the model reasoning process, before detecting whether the current operator is configured with preset attributes, it also includes: creating a topological structure of the model to be processed, configuring preset attributes for the target operator in the model to be processed, and transmitting the preset attributes in the topological structure.

[0015] In a second aspect, an embodiment of the present application provides a model reasoning device, including:

[0016] A first acquisition module is used to acquire a model to be processed and input data, wherein each operator of the model to be processed is configured with an initialized memory space, and the initialized memory space is adapted to a maximum input data dimension allowed by the model to be processed;

[0017] A determination module, used to determine the output dimension of each operator of the model to be processed according to the data dimension of the input data and the maximum input data dimension;

[0018] An inference module is used to infer the model to be processed based on the input data, the output dimension of each operator and the initialized memory space, and output a model inference result.

[0019] In one embodiment, it also includes: a second acquisition module, used to obtain the maximum input data dimension allowed by the model to be processed before determining the output dimension of each operator of the model to be processed based on the data dimension of the input data; a configuration module, used to configure the initialization memory space for each operator of the model to be processed according to the maximum input data dimension, and the initialization memory space is adapted to the maximum input data dimension.

[0020] In one embodiment, the configuration module is used to determine the memory resource occupancy of each operator based on the maximum input data dimension and the parameter configuration of each operator; and configure the initialized memory space for each operator based on the memory resource occupancy, wherein, for each operator, the resource amount of the initialized memory space is greater than or equal to the memory resource occupancy.

[0021] In one embodiment, the determination module is used to determine whether the data dimension of the input data is greater than the maximum input data dimension; if the data dimension of the input data is greater than the maximum input data dimension, then the output dimension of each operator in the model to be processed is determined according to the maximum input data dimension.

[0022] In one embodiment, the determination module is further used to determine the output dimension of each operator in the model to be processed according to the data dimension of the input data if the data dimension of the input data is less than or equal to the maximum input data dimension.

[0023] In one embodiment, the reasoning module is used to detect whether the current operator is configured with preset attributes during the model reasoning process; if the current operator is configured with the preset attributes, the output dimension of the current operator is updated based on the data received by the current operator and the parameter configuration of the current operator; based on the updated output dimension of the current operator and the input data, the current operator is reasoned on the initialized memory space corresponding to the current operator to obtain the reasoning result of the current operator; and the reasoning result of the model to be processed is determined based on the reasoning results of all operators in the model to be processed.

[0024] In one embodiment, the reasoning module is also used to, if the current operator is not configured with the preset attribute, perform reasoning on the current operator in the initialized memory space corresponding to the current operator based on the output dimension of the current operator and the input data to obtain the reasoning result of the current operator; and determine the reasoning result of the model to be processed based on the reasoning results of all operators in the model to be processed.

[0025] In one embodiment, the reasoning module is further used to pass the reasoning result of the current operator to the next operator, and continue model reasoning until each operator of the model to be processed is traversed to obtain the model reasoning result.

[0026] In one embodiment, it also includes: a creation module, which is used to create a topological structure of the model to be processed before detecting whether the current operator is configured with preset attributes during the model reasoning process, configure preset attributes for the target operator in the model to be processed, and pass the preset attributes in the topological structure.

[0027] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory, the memory being used to store code instructions, and the processor being used to run the code instructions to execute the method described in the first aspect of the embodiment of the present application or any possible implementation of the first aspect.

[0028] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program or instructions are stored. When the computer program or instructions are run on a computer, the computer executes the method described in the first aspect of the embodiment of the present application or any possible implementation of the first aspect.

[0029] In the fifth aspect, an embodiment of the present application provides a computer program product including a computer program. When the computer program runs on a computer, the computer executes the model reasoning method described in the first aspect of the embodiment of the present application or any possible implementation method of the first aspect.

[0030] The present application provides a model reasoning method, device, storage medium and program product. By pre-configuring a matching initialization memory space for each operator based on the preset maximum input data dimension of the model to be processed, during the model reasoning process, the output dimension of each operator can be directly determined according to the data dimension of the input data and the maximum input data dimension allowed by the model, and then the reasoning is completed based on the operator output dimension, input data and initialization memory space. In this way, the initialization memory space of the operator is adapted to the maximum input data dimension allowed by the model to be processed, so that no matter how the data dimension of the input data changes, the configured initialization memory space can meet the model reasoning requirements, and there is no need to reallocate memory for the operator, thereby reducing the model reasoning delay and improving the model reasoning efficiency.

[0031] It should be understood that the contents described in the above summary of the invention are not intended to limit the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0033] Figure 1 An architecture diagram of an electronic device provided in one embodiment of the present application;

[0034] Figure 2A software structure block diagram of an electronic device provided in an embodiment of the present application;

[0035] Figure 3 A schematic diagram of an application scenario of model reasoning provided in an embodiment of the present application;

[0036] Figure 4 A flowchart of a model reasoning method provided in one embodiment of the present application;

[0037] Figure 5 A flowchart of a model reasoning method provided in one embodiment of the present application;

[0038] Figure 6 A schematic diagram of the relationship between operators in a model provided in an embodiment of the present application;

[0039] Figure 7 A schematic diagram of the structure of a model reasoning device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0040] In the embodiments of the present application, words such as "first" and "second" are used to distinguish the same or similar items with substantially the same functions and effects. For example, the first chip and the second chip are only used to distinguish different chips, and their order is not limited. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.

[0041] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0042] In the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, c can be single or multiple.

[0043] In order to clearly describe the solution of the embodiment of the present application, the terms involved are first defined:

[0044] AI: Artificial Intelligence.

[0045] ASR: Automatic Speech Recognition, refers to automatic speech recognition technology, which is a technology that converts human speech into text.

[0046] TTS: Text To Speech, or "from text to speech", is a part of human-computer dialogue that enables machines to speak. It can convert files stored in the computer, such as help files or web pages, into natural speech output.

[0047] Operator: It is a mapping O: X→X from a function space to a function space. In a broad sense, operators can be extended to any space, such as inner product space. Deep learning algorithms are composed of computing units, which can be called operators (OP for short). In the network model, the operator corresponds to the computing logic in the layer, for example, the convolution layer is an operator. The weight summation process in the fully-connected layer (FC layer) is an operator.

[0048] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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 are within the scope of protection of this application.

[0049] Figure 1 A schematic structural diagram of an electronic device 100 is shown.

[0050] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0051] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0052] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0053] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0054] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0055] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0056] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface, thereby realizing the touch function of the electronic device 100.

[0057] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to achieve communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 via the I2S interface to achieve the function of answering a call through a Bluetooth headset.

[0058] The PCM interface can also be used for audio communication, sampling, quantizing and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface to realize the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.

[0059] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.

[0060] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to implement the shooting function of the electronic device 100. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the electronic device 100.

[0061] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.

[0062] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and a peripheral device. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other electronic devices, such as AR devices, etc.

[0063] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present invention is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0064] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device through the power management module 141.

[0065] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the display screen 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.

[0066] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0067] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0068] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.

[0069] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0070] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0071] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. GNSS may include the global positioning system (GPS), the global navigation satellite system (GLONASS), the Beidou navigation satellite system (BDS), the quasi-zenith satellite system (QZSS) and / or the satellite based augmentation system (SBAS).

[0072] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0073] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0074] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.

[0075] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.

[0076] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0077] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0078] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0079] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0080] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0081] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the electronic device 100 by running instructions stored in the internal memory 121, and / or instructions stored in a memory provided in the processor.

[0082] The processor 110 can call the computer program stored in the memory 121 to execute any method provided in the embodiments of the present application according to the obtained executable instructions.

[0083] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0084] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.

[0085] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.

[0086] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.

[0087] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to microphone 170C to input the sound signal into microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify the sound source, realize directional recording function, etc.

[0088] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0089] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.

[0090] The gyro sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyro sensor 180B. The gyro sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyro sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyro sensor 180B can also be used for navigation and somatosensory game scenes.

[0091] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.

[0092] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. Then, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, the flip cover can be automatically unlocked.

[0093] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in all directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.

[0094] The distance sensor 180F is used to measure the distance. The electronic device 100 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 100 can use the distance sensor 180F to measure the distance to achieve fast focusing.

[0095] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device 100 emits infrared light outward through the light emitting diode. The electronic device 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100. The electronic device 100 can use the proximity light sensor 180G to detect that the user holds the electronic device 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used in leather case mode and pocket mode to automatically unlock and lock the screen.

[0096] The ambient light sensor 180L is used to sense the ambient light brightness. The electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.

[0097] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.

[0098] The temperature sensor 180J is used to detect temperature. In some embodiments, the electronic device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the electronic device 100 reduces the performance of a processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to avoid abnormal shutdown of the electronic device 100 due to low temperature. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 performs a boost on the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperature.

[0099] The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.

[0100] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone block of the vocal part of the human body. The bone conduction sensor 180M can also contact the human pulse to receive a blood pressure beat signal. In some embodiments, the bone conduction sensor 180M can also be set in an earphone and combined into a bone conduction earphone. The audio module 170 can parse out a voice signal based on the vibration signal of the vibrating bone block of the vocal part obtained by the bone conduction sensor 180M to realize a voice function. The application processor can parse the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 180M to realize a heart rate detection function.

[0101] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.

[0102] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.

[0103] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.

[0104] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.

[0105] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present invention, the Android system of the layered architecture is taken as an example to exemplify the software structure of the electronic device 100.

[0106] Figure 2 1 is a software structure block diagram of the electronic device 100 according to an embodiment of the present invention.

[0107] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.

[0108] The application layer can include a series of application packages.

[0109] like Figure 2 As shown, the application package may include phone, email, calendar, camera, gallery, map, navigation, WLAN (Wireless Local Area Network), Bluetooth, music, video, short message and other applications.

[0110] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0111] like Figure 2As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0112] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0113] Content providers are used to store and retrieve data and make it accessible to applications. The data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0114] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0115] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).

[0116] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0117] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0118] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.

[0119] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.

[0120] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0121] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0122] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0123] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0124] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0125] A 2D graphics engine is a drawing engine for 2D drawings.

[0126] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0127] The following is an illustrative description of the workflow of the software and hardware of the electronic device 100 in conjunction with capturing a photo scene.

[0128] When the touch sensor 180K receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into a raw input event (including touch coordinates, timestamp of the touch operation, and other information). The raw input event is stored in the kernel layer. The application framework layer obtains the raw input event from the kernel layer and identifies the control corresponding to the input event. For example, if the touch operation is a touch single-click operation and the control corresponding to the single-click operation is the control of the camera application icon, the camera application calls the interface of the application framework layer to start the camera application, and then starts the camera driver by calling the kernel layer to capture static images or videos through the camera 193.

[0129] The model reasoning method of the embodiment of the present application is described in detail below through specific embodiments. The following embodiments can be combined with each other or implemented independently, and the same or similar concepts or processes may not be repeated in some embodiments.

[0130] With the development of computer technology, the application of AI models is becoming more and more common. Artificial neural network model is a common AI model, which is widely used in various scenarios, such as ASR model, TTS model, and various image recognition models.

[0131] In actual scenarios, the AI ​​model must first go through the model training stage, and then the trained AI model needs to be deployed on a server or terminal, and the model reasoning process is performed on the server or terminal to output the model reasoning results, thereby realizing the application of the model. The server can be a cloud server or a local server. The terminal can be a mobile device such as a mobile phone or a tablet computer, or a device such as a desktop computer. The above-mentioned server and terminal can be implemented by the aforementioned electronic device 100.

[0132] like Figure 3 As shown, it is a schematic diagram of a scenario architecture of model reasoning provided in an embodiment of the present application. The model reasoning architecture mainly includes two stages: model initialization and reasoning output, wherein:

[0133] In the model initialization phase, it is necessary to parse the model file of the model to be processed, then create the model topology structure, and then perform operator initialization, calculation dimension reasoning and other processes.

[0134] In the inference output stage, after the initialization stage is completed, the user only needs to provide input data, and then the model can be inferred based on the input data, and then the model output can be obtained to complete the entire process of model inference.

[0135] Among them, during the model initialization phase, the inference framework needs to allocate memory space that matches the input dimension for each operator of the model in order to implement the subsequent model inference process.

[0136] However, the above reasoning process is applicable to the case where the data dimension of the input data remains unchanged. In actual scenarios, the memory space required for each operator is related to the dimension of the input data. When the input dimension of the AI ​​model changes dynamically, if the above method is still used to allocate corresponding memory space to each operator, then the memory space required for all operators in the model needs to be reallocated each time the input data changes, resulting in excessively long model reasoning delays and low reasoning efficiency.

[0137] In response to the above problems, an embodiment of the present application provides a model reasoning solution, by pre-configuring a matching initialization memory space for each operator based on the preset maximum input data dimension of the model to be processed. During the model reasoning process, the output dimension of each operator can be directly determined according to the data dimension of the input data and the maximum input data dimension allowed by the model, and then the reasoning is completed based on the operator output dimension, input data and initialization memory space. In this way, the initialization memory space of the operator is adapted to the maximum input data dimension allowed by the model to be processed, so that no matter how the data dimension of the input data changes, the configured initialization memory space can meet the model reasoning requirements, and there is no need to reallocate memory for the operator, thereby reducing the model reasoning delay and improving the model reasoning efficiency.

[0138] like Figure 4 As shown, the embodiment of the present application provides a model reasoning method, which can be executed by the above electronic device 100 and can be applied to Figure 3 In the application scenario of model reasoning shown in , the model reasoning delay is reduced and the model reasoning efficiency is improved. The method includes the following steps:

[0139] Step 401: Obtain a model to be processed and input data, wherein each operator of the model to be processed is configured with an initialized memory space, and the initialized memory space is adapted to the maximum input data dimension allowed by the model to be processed.

[0140] In this step, the model to be processed can be an algorithm model based on a neural network, such as an ASR model, a TTS model, and various cv (computer version, computer vision) models. The model file of the model to be processed can be directly read from the local database, or the model file of the model to be processed can be uploaded by the user through the client, or the model file of the model to be processed can be directly input through an external input device. Among them, the model to be processed includes one or more operators, and each operator is pre-configured with an initialized memory space to complete the data calculation of each operator during model reasoning. And the initialized memory space is adapted to the maximum input data dimension allowed by the model to be processed, so as to ensure that when the dimension of the input data changes, only the dimension of the model operator needs to be updated to ensure that the model reasoning process proceeds smoothly.

[0141] In one embodiment, before step 401, the method may include: obtaining the maximum input data dimension allowed by the model to be processed. According to the maximum input data dimension, initializing memory space for each operator of the model to be processed, and the initializing memory space is adapted to the maximum input data dimension.

[0142] In this embodiment, before model inference is performed, the model may be initialized. In the model initialization stage, the maximum input data dimension allowed by the model to be processed may be read from the model file. Then, the initialization memory space of each operator is determined based on the maximum input data dimension preset by the model to be processed, so that the initialization memory space of each operator is adapted to the maximum input data dimension.

[0143] The maximum input data dimension here is the maximum input data dimension that the model to be processed can process during the inference process. Each model to be processed corresponds to its own usage scenario. Different usage scenarios may have different output requirements for the model. In actual scenarios, it is always hoped that the model can play the best performance in specific usage scenarios. Therefore, when deploying the AI ​​model, some restriction parameters will be configured for the model, such as configuring the maximum input data dimension allowed by the model to be processed, and generating the corresponding model according to the maximum input data dimension, thereby avoiding the phenomenon that the model cannot be effectively calculated due to unlimited input data. For example, for the TTS model, its input data is generally text containing words. Assuming that the TTS model is pre-configured with the maximum input data dimension allowed for one data including 30 words, then in the subsequent TTS model inference process, the maximum input data dimension that can be processed in one inference is 30 words. Even if the user provides 100 words of input data, the model will only cut the 100 words in sequence, for example, it can be cut into 3 data including 30 words and one data including 10 words. When processing, the first 30 characters are processed in order, and then the subsequent characters are processed in units of 30 characters. This avoids unnecessary pressure on computing resources caused by a sudden increase in model calculations due to excessive input text.

[0144] The above-mentioned cropping process of the input data can be pre-processed on other devices or on a local device.

[0145] Since each operator in the model to be processed is related to the input data, the larger the data dimension of the input data, the larger the memory space required for the corresponding operator during calculation. The initialization memory space of each operator is adapted to the maximum input data dimension, which means that the initialization memory space of each operator can meet the memory resource requirements when the model to be processed is input with the maximum input data dimension. Therefore, as long as the initialization memory space is adapted to the maximum input data dimension, in the subsequent reasoning process, regardless of whether the data dimension of the input data changes, there is no need to reallocate memory for the operator, which reduces the model reasoning delay and improves the model reasoning efficiency.

[0146] In one embodiment, the above-mentioned initializing memory space for each operator of the model to be processed according to the maximum input data dimension, and the initializing memory space is adapted to the maximum input data dimension, including: determining the memory resource occupancy of each operator according to the maximum input data dimension and the parameter configuration of each operator. Initializing memory space for each operator is configured based on the memory resource occupancy, wherein for each operator, the resource amount of the initializing memory space is greater than or equal to the memory resource occupancy.

[0147] In this embodiment, the model to be processed can be converted and parsed to obtain the maximum input data dimension and the parameter configuration of each operator. Each operator of the model to be processed will have a specific parameter configuration. For example, for an operator of convolution calculation, its parameter configuration may include: the number of convolution kernels, the size of the convolution kernel, etc. The parameter configuration of the operator is different, and the memory space resources required will also be different. Therefore, in the actual scenario, the model to be processed can be converted and parsed to obtain the maximum input data dimension of the model to be processed and the parameter configuration of each operator itself to determine the specific memory resource occupancy required by the operator, and then allocate the initialization memory space to the corresponding operator based on the specific required memory resource occupancy. In order to ensure that when the model to be processed is input with the maximum input data dimension, the model inference calculation can be carried out smoothly, and the resource amount of the initialization memory space is greater than or equal to the memory resource occupancy. In this way, it can be ensured that each operator has sufficient memory, and there is no need to reallocate memory, which reduces latency.

[0148] Step 402: Determine the output dimension of each operator of the model to be processed according to the data dimension of the input data and the maximum input data dimension.

[0149] In this step, the data dimension of the input data is used to characterize the size of the input data. For example, for a TTS model, the input data is text, and the data dimension of the input data may include the number of bytes of an input text. For an image recognition model, the input data is generally a picture, and the data dimension of the input data may include: the width, height, and color channel of an input picture.

[0150] The output dimensions of multiple operators in the model to be processed are related to the data actually processed by the model. Therefore, it is necessary to determine the output dimension of each operator of the model to be processed based on the data dimension of the input data and the maximum input data dimension to ensure smooth model reasoning. In this way, when dynamic data is input into the model, it is only necessary to update the output dimension of the model operator according to the data dimension of the new input data, without reallocating memory, to achieve one-time initialization and continuous reasoning of dynamic input data.

[0151] Step 403: Based on the input data, the output dimension of each operator and the initialized memory space, the model to be processed is inferred, and the model inference result is output.

[0152] In this step, after determining the output dimension of each operator in the model to be processed, the input data can be inferred on the initialized memory space corresponding to each operator, and then the model inference result is obtained and output for users to view in time.

[0153] The above-mentioned model reasoning method pre-configures a matching initialized memory space for each operator based on the preset maximum input data dimension of the model to be processed. During the model reasoning process, the output dimension of each operator can be directly determined according to the data dimension of the input data and the maximum input data dimension allowed by the model, and then the reasoning is completed based on the operator output dimension, input data and initialized memory space. In this way, the memory space required by the operator is less than or equal to the memory space allocated for the model to be processed, so that when the data dimension of the input data changes, the configured memory space can meet the model reasoning requirements, and there is no need to reallocate memory for the operator, thereby reducing the model reasoning delay and improving the model reasoning efficiency.

[0154] like Figure 5 As shown, the embodiment of the present application provides a model reasoning method, which can be executed by the above electronic device 100 and can be applied to Figure 3 In the application scenario of model reasoning shown in , the model reasoning delay is reduced and the model reasoning efficiency is improved. The method includes the following steps:

[0155] Step 501: Obtain the model to be processed and the maximum input data dimension allowed by the model to be processed. For details, refer to the description of step 401 in the above embodiment.

[0156] Step 502: According to the maximum input data dimension, an initial memory space is configured for each operator of the model to be processed, and the initial memory space is adapted to the maximum input data dimension. For details, refer to the description of step 401 in the above embodiment.

[0157] Step 503: Obtain input data. For details, refer to the description of step 401 in the above embodiment.

[0158] Step 504: Determine whether the data dimension of the input data is greater than the maximum input data dimension. If so, proceed to step 505, otherwise proceed to step 506.

[0159] In this step, when determining the output dimension of each operator of the model to be processed, the data dimension of the input data and the size of the maximum input data dimension are comprehensively considered. In order to ensure that the data dimension actually processed by the model at one time does not exceed the preset maximum input data dimension, it is necessary to compare the data dimension of the input data with the maximum input data dimension. If the data dimension of the input data is greater than the maximum input data dimension, go to step 505, otherwise go to step 506.

[0160] Step 505: Determine the output dimension of each operator in the model to be processed according to the maximum input data dimension, and then proceed to step 507.

[0161] In this step, the original input data will generally go through a preprocessing process, and the dimensions of the original input data will be cut into the dimensions required by the model to be processed, and then input into the model to be processed. For example, the maximum input data dimension preset by the model to be processed is that one input data includes 30 words, and the original input data is 100 words, then the original data is cut into: 3 data including 30 words and one data including 10 words. To ensure the smooth progress of the model reasoning process. The data preprocessing process may not be in the same engine as the model reasoning process. However, in actual scenarios, if the data preprocessing process is not accurate enough, it is still possible to encounter a situation where the data dimension of the input data is greater than the maximum input data dimension. At this time, the model to be processed cannot process the input data at one time, and the input data can be cut and processed in batches. Taking the TTS model as an example of the model to be processed, assuming that the corresponding maximum input data dimension is 30 words, and the current input data is 100 words, indicating that the TTS model can only process a maximum of 30 words of input data at a time, then the output dimension of each operator in the TTS model is calculated based on the maximum input data dimension of 30 words. In this way, not only the actual needs of the model to be processed are met, but also the output dimensions of each operator are adapted to the corresponding initialized memory space. The memory space actually required by each operator will not be larger than the initialized memory space, further avoiding memory reallocation and reducing model inference latency.

[0162] In one embodiment, after step 504, the process may further include: if the data dimension of the input data is greater than the maximum input data dimension, returning an error prompt.

[0163] In this embodiment, if the data dimension of the input data is greater than the maximum input data dimension, the inference engine may also return an error prompt to prompt relevant personnel to handle it in a timely manner.

[0164] Step 506: Determine the output dimension of each operator in the model to be processed according to the data dimension of the input data, and then proceed to step 507.

[0165] In this step, if the data dimension of the input data is less than or equal to the maximum input data dimension, it means that the current input data dimension does not exceed the maximum input data dimension corresponding to the model. Take the TTS model as an example of the model to be processed, assuming that its corresponding maximum input data dimension is 30 words, and the current input data is 20 words, which means that the TTS model can process the 20 input words at one time, then the output dimension of each operator in the TTS model can be calculated based on the data dimension of the input data, 20 words. In this way, not only the actual needs of the model to be processed are met, but also the initialization memory space corresponding to the output dimension of each operator is also adapted. The actual memory space required by each operator will not be greater than the initialization memory space, further avoiding memory reallocation and reducing model inference latency.

[0166] Step 507: During the model inference process, check whether the current operator is configured with a preset attribute. If yes, proceed to step 508, otherwise proceed to step 510.

[0167] In this step, the multiple operators in the model to be processed are generally interrelated, and sometimes the parameters of the current operator need to be determined by the output of the previous operator. In this way, after the output dimensions of the operators under global dynamics are determined in step 505 or step 506, during the model reasoning process, the output dimensions of some operators cannot be determined at one time, that is, the dimensions of some operators may depend on the calculation results of the preceding operators. Such some operators can be called target operators with dynamic input conditions.

[0168] For example, taking the ASR model as the model to be processed, there is a situation of local dynamic input. Figure 6 As shown in the figure, it is a schematic diagram of some operator relationships of the ASR model, including: infer_control operator, operator 1, operator 2, operator 3, Slice operator, operator Q and other operators. Here are just examples. The output result of operator 1 will be transmitted to the Slice operator. As one of the parameters of slice, the output result of the Slice operator will be transmitted to the operator Q. In such an operator relationship, when the Slice operator receives dynamic parameters, it will inevitably cause its output dimension to change, thereby causing the dimension of operator Q to change. For example, the Slice operator includes parameters starts, ends, axes, and steps. Under normal circumstances, these are fixed parameters. During the ASR model reasoning process, assuming that the Slice operator receives a dynamic starts parameter, the output dimension of the Slice operator will also change, causing the output dimension of the subsequent operator Q of the Slice operator to be in an uncertain state, which needs to be determined after the Slice operator reasoning is completed. When processing a Slice operator, a preset attribute can be assigned to the Slice operator, such as a dynamic attribute tag, to distinguish the Slice operator, and the dynamic attribute tag can be passed to subsequent operators. In order to enable each operator to successfully complete reasoning, during the actual reasoning process of the ASR model, each operator can be checked for preset attributes, so each operator of the model to be processed can be traversed to determine whether the current operator is configured with preset attributes. If yes, proceed to step 508, otherwise proceed to step 510.

[0169] In one embodiment, before step 507, the following steps may be included: creating a topological structure of the model to be processed, configuring preset attributes for the target operator in the model to be processed, and transferring the preset attributes in the topological structure.

[0170] In this embodiment, the topological structure of the model to be processed can be created in the model initialization stage, and then based on the relationship between the operators in the model to be processed, the target operators with dynamic input situations are found, and preset attributes are configured for these target operators, such as labeling these target operators for identifying the target operators, and the preset attributes can be passed in the topological structure so that the operators can be checked and identified during the model reasoning process.

[0171] Step 508: Based on the data received by the current operator and the parameter configuration of the current operator, update the output dimension of the current operator.

[0172] In this step, if the current operator is configured with preset attributes, it means that the current operator is a target operator with dynamic input. Then, before calculating the current operator, the output dimension of the current operator is updated based on the data received by the current operator and the parameter configuration of the current operator, so that the updated operator output dimension can successfully complete the inference calculation.

[0173] Step 509 : Based on the updated output dimension and input data of the current operator, the current operator is inferred in the initialized memory space corresponding to the current operator to obtain the inference result of the current operator. Then, the process proceeds to step 511 .

[0174] In this step, the updated output dimension of the current operator can make the calculation result of the operator more accurate, and there is no need to reallocate memory space for the operator. The current operator can be directly inferred on the initialized memory space corresponding to the current operator, which can not only obtain accurate inference results of the current operator, but also reduce the operator inference delay, thereby reducing the model inference delay.

[0175] Step 510: Based on the output dimension and input data of the current operator, the current operator is inferred in the initialized memory space corresponding to the current operator to obtain the inference result of the current operator. Then, the process proceeds to step 511.

[0176] In this step, if the current operator is not configured with preset attributes, it means that the current operator is an ordinary operator, and its operator parameters will not depend on the output result of the previous operator. Therefore, the output dimension determined in step 505 or step 506 can be directly used to infer the current operator on the input data in the initialized memory space corresponding to the current operator to obtain the inference result of the current operator.

[0177] Step 511: Determine the inference result of the model to be processed according to the inference results of all operators in the model to be processed.

[0178] In this step, multiple operators may be serial or parallel. After the reasoning of all operators in the model to be processed is completed, the reasoning result of the model to be processed can be output.

[0179] In one embodiment, during the model inference process, step 511 may specifically include: passing the inference result of the current operator to the next operator, continuing the model inference, until each operator of the model to be processed is traversed to obtain the model inference result.

[0180] In this embodiment, among multiple operators in a serial relationship, the reasoning result of the previous operator needs to be passed to the next operator to complete the reasoning of the next operator until the reasoning process of all operators in the serial relationship is completed. All operators in parallel also need to complete the reasoning, and summarize the parallel reasoning results to form the reasoning result of the model to be processed to ensure the integrity of the model reasoning.

[0181] In the above model reasoning method, after the model to be processed completes the global dynamic input, there may be some operators whose dimensions depend on the calculation results of the preceding operators, and the dimensions of the operators cannot be calculated in advance. By adding preset attributes to the operators in the reasoning framework and passing the attributes in the topological structure of the model, the preset attributes of the operators are checked during the reasoning process. When encountering a target operator with preset attributes, the dimensions of the target operator are recalculated during the model reasoning process to achieve real-time dynamic dimension updates without reallocating memory space, thereby reducing the delay of model reasoning and improving the efficiency of model reasoning.

[0182] like Figure 7 As shown, the embodiment of the present application provides a model reasoning device 700, which can be applied to the electronic device 100 shown above, and can be applied to Figure 3 In the application scenario of model reasoning shown in , the model reasoning delay is reduced and the model reasoning efficiency is improved. The device includes: a first acquisition module 701, a determination module 702 and a reasoning module 703, and the functions of each module are as follows:

[0183] The first acquisition module 701 is used to acquire the model to be processed and input data, wherein each operator of the model to be processed is configured with an initialized memory space, and the initialized memory space is adapted to the maximum input data dimension allowed by the model to be processed.

[0184] The determination module 702 is used to determine the output dimension of each operator of the model to be processed according to the data dimension of the input data and the maximum input data dimension.

[0185] The reasoning module 703 is used to reason about the model to be processed based on the input data, the output dimension of each operator and the initialized memory space, and output the model reasoning result.

[0186] In one embodiment, it further includes: a second acquisition module 704, which is used to obtain the maximum input data dimension allowed by the model to be processed before determining the output dimension of each operator of the model to be processed according to the data dimension of the input data. A configuration module 705 is used to configure an initialization memory space for each operator of the model to be processed according to the maximum input data dimension, and the initialization memory space is adapted to the maximum input data dimension.

[0187] In one embodiment, the configuration module 705 is used to determine the memory resource usage of each operator according to the maximum input data dimension and the parameter configuration of each operator. Based on the memory resource usage, an initial memory space is configured for each operator, wherein for each operator, the resource amount of the initial memory space is greater than or equal to the memory resource usage.

[0188] In one embodiment, the determination module 702 is used to determine whether the data dimension of the input data is greater than the maximum input data dimension. If the data dimension of the input data is greater than the maximum input data dimension, the output dimension of each operator in the model to be processed is determined according to the maximum input data dimension.

[0189] In one embodiment, the determination module 702 is used to determine the output dimension of each operator in the model to be processed according to the data dimension of the input data if the data dimension of the input data is less than or equal to the maximum input data dimension.

[0190] In one embodiment, the inference module 703 is used to detect whether the current operator is configured with preset attributes during the model inference process. If the current operator is configured with preset attributes, the output dimension of the current operator is updated based on the data received by the current operator and the parameter configuration of the current operator. Based on the updated output dimension and input data of the current operator, the current operator is inferred on the initialized memory space corresponding to the current operator to obtain the inference result of the current operator. According to the inference results of all operators in the model to be processed, the inference result of the model to be processed is determined.

[0191] In one embodiment, the inference module 703 is further used to, if the current operator is not configured with preset attributes, perform inference on the current operator in the initialized memory space corresponding to the current operator based on the output dimension and input data of the current operator to obtain the inference result of the current operator. The inference result of the model to be processed is determined according to the inference results of all operators in the model to be processed.

[0192] In one embodiment, the reasoning module 703 is also used to pass the reasoning result of the current operator to the next operator, and continue model reasoning until each operator of the model to be processed is traversed to obtain the model reasoning result.

[0193] In one embodiment, it also includes: a creation module 706, which is used to create a topological structure of the model to be processed before traversing each operator of the model to be processed and determining whether the current operator is configured with preset attributes, configure preset attributes for the target operator in the model to be processed, and transfer the preset attributes in the topological structure.

[0194] It should be noted here that the above-mentioned device provided in the present application can implement all the method steps implemented by the corresponding method embodiment, and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as the method embodiment will not be described in detail here.

[0195] The present application embodiment also provides a computer program product, including one or more computer programs. When the computer program is loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. Computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. For example, the available medium can include magnetic media (e.g., floppy disk, hard disk or tape), optical media (e.g., digital versatile disc (digital versatile disc, DVD)), or semiconductor media (e.g., solid state disk (solid state disk, SSD)), etc.

[0196] The embodiment of the present application also provides a computer-readable storage medium, which stores instructions. When the instructions are executed, the computer performs the method described in any of the above embodiments. The method described in the above embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. The computer-readable medium may include computer storage media and communication media, and may also include any medium that can transfer a computer program from one place to another. The storage medium may be any target medium that can be accessed by a computer.

[0197] As a possible design, the computer readable medium may include a compact disc read-only memory (CD-ROM), RAM, ROM, EEPROM or other optical disc storage. The computer readable medium may include a magnetic disk storage or other magnetic disk storage device. Moreover, any connecting line may also be appropriately referred to as a computer readable medium. For example, if the software is transmitted from a website, server or other remote source using a coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology (such as infrared, radio and microwave), the coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology such as infrared, radio and microwave are included in the definition of medium. Disks and discs as used herein include compact discs (CDs), laser discs, optical discs, digital versatile discs (DVDs), floppy disks and Blu-ray discs, where disks usually reproduce data magnetically, while optical discs reproduce data optically using lasers.

[0198] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processing unit of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

Claims

1. A model reasoning method, characterized in that: include: Get the maximum input data dimension allowed by the model to be processed; The model to be processed is an ASR model or a TTS model; Determine the memory resource usage of each operator according to the maximum input data dimension and the parameter configuration of each operator of the model to be processed; Based on the memory resource occupancy, configure an initialized memory space for each operator, wherein, for each operator, the resource amount of the initialized memory space is greater than or equal to the memory resource occupancy; obtain input data; Determining the output dimension of each operator of the model to be processed according to the data dimension of the input data and the maximum input data dimension; During model inference, check whether the current operator is configured with preset attributes; If the current operator is configured with the preset attribute, updating the output dimension of the current operator based on the data received by the current operator and the parameter configuration of the current operator; Based on the updated output dimension of the current operator and the input data, reasoning the current operator in the initialized memory space corresponding to the current operator to obtain a reasoning result of the current operator; Determining the inference result of the model to be processed according to the inference results of all operators in the model to be processed; In the model reasoning process, before detecting whether the current operator is configured with a preset attribute, the following step is also included: A topological structure of the model to be processed is created, preset attributes are configured for target operators in the model to be processed, and the preset attributes are transferred in the topological structure.

2. The method according to claim 1, characterized in that The step of determining the output dimension of each operator of the model to be processed according to the data dimension of the input data and the maximum input data dimension comprises: Determine whether the data dimension of the input data is greater than the maximum input data dimension; If the data dimension of the input data is greater than the maximum input data dimension, the output dimension of each operator in the model to be processed is determined according to the maximum input data dimension.

3. The method according to claim 2, characterized in that The step of determining the output dimension of each operator of the model to be processed according to the data dimension of the input data and the maximum input data dimension further includes: If the data dimension of the input data is less than or equal to the maximum input data dimension, the output dimension of each operator in the model to be processed is determined according to the data dimension of the input data.

4. The method according to claim 1, characterized in that: Also includes: If the current operator is not configured with the preset attribute, based on the output dimension of the current operator and the input data, the current operator is inferred in the initialized memory space corresponding to the current operator to obtain an inference result of the current operator; The inference result of the model to be processed is determined according to the inference results of all operators in the model to be processed.

5. The method according to claim 1 or 4, characterized in that: Determining the inference result of the model to be processed according to the inference results of all operators in the model to be processed includes: The inference result of the current operator is passed to the next operator, and the model inference is continued until each operator of the model to be processed is traversed to obtain the model inference result.

6. An electronic device, characterized in that: include: A memory and a processor, the memory being used to store a computer program, and the processor being used to execute the computer program to perform the method according to any one of claims 1 to 5.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed, the computer executes the method according to any one of claims 1 to 5.

8. A computer program product, characterized in that The invention comprises a computer program, which, when being executed, enables an electronic device to execute the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Machine learning method and system

    CN106529679A

  • Data processing method, model optimization device and model execution device

    CN112529169A

  • Memory allocation method and device for deep learning end-side reasoning

    CN114138457A