Data processing method, processor, and electronic device

By converting the format of model parameters during the inference process of a large language model, the reuse of model parameters between NPU and PIM is achieved, solving the problem of wasted memory capacity and improving the performance and efficiency of model inference.

WO2026242908A1PCT designated stage Publication Date: 2026-11-26HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2026/096922
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2025-05-19
Filing Date
2026-05-14
Publication Date
2026-11-26

AI Technical Summary

Technical Problem

During the inference process of large language models, the different data storage formats of the model parameters used by the NPU and PIM require two copies of the model parameters to be loaded into the memory of electronic devices, resulting in wasted memory capacity and performance impact.

Method used

The first processor converts the model parameters in the first storage format to obtain the model parameters in the second storage format, making them suitable for the needs of the second processor. This enables the reuse of model parameters, allowing the storage of only one set of model parameters to meet the needs of different inference stages.

Benefits of technology

It reduces storage space usage, improves model inference performance, provides more free space for storing intermediate data, and enhances processor read and write efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2026096922_26112026_PF_FP_ABST
    Figure CN2026096922_26112026_PF_FP_ABST
Patent Text Reader

Abstract

A data processing method, a processor, and an electronic device, relating to the technical field of computers. The electronic device comprises a first processor and a second processor, wherein the first processor is configured to use model parameters in a second storage format to execute a first inference stage of a neural network model, and the second processor is configured to use model parameters in a first storage format to execute a second inference stage of the neural network model. A storage medium of the electronic device stores the model parameters in the first storage format. The first processor performs format conversion on the model parameters in the first storage format read from the storage medium to obtain the model parameters in the second storage format, thereby enabling model parameter reuse, such that only model parameters in one storage format need to be stored in the storage medium to meet different requirements of the two processors, without storing model parameters in two storage formats. Therefore, storage space occupied by the model parameters during model inference can be reduced, the storage space can be saved, and model inference performance can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

A data processing method, processor, and electronic device

[0001] Cross-references to related applications

[0002] This application claims priority to Chinese Patent Application No. 202510645823.8, filed on May 19, 2025, entitled "A Data Processing Method, Processor and Electronic Device", the entire contents of which are incorporated herein by reference. Technical Field

[0003] This application relates to the field of computer technology, and more particularly to a data processing method, processor, and electronic device. Background Technology

[0004] With the development of artificial intelligence (AI) technology, large language models (LLMs) are being used more and more widely in people's daily work and life. The inference process of LLM mainly includes two stages: the prefill stage and the decoder stage. The two stages have different requirements for the computing power and memory access of electronic devices. In the prefill stage, a large amount of input data needs to be calculated, which requires high computing power and can be executed in the neural network processing unit (NPU). In the decoder stage, the loading process of the LLM model parameters is time-consuming. In order to reduce the time spent on loading model parameters, the decoder stage can be executed in the in-memory process (PIM) unit.

[0005] During LLM inference, the NPU and PIM use the same model parameter values, but their data storage formats differ. Therefore, two sets of model parameters need to be loaded into the electronic device's memory to meet the different requirements of the NPU and PIM. However, loading two sets of LLM model parameters into the electronic device's memory leads to a waste of memory capacity. Summary of the Invention

[0006] This application provides a data processing method, processor, and electronic device that can save storage space during the inference process of a neural network model.

[0007] In a first aspect, this application provides an electronic device comprising a first processor and a second processor. The electronic device's storage medium stores model parameters of a neural network model in a first storage format, the first storage format being suitable for the second processor. The first processor can be used to read the model parameters in the first storage format from the storage medium, convert the model parameters in the first storage format to a second storage format, and execute a first inference stage of the neural network model based on the model parameters in the second storage format. The second processor is used to execute a second inference stage of the neural network model based on the model parameters in the first storage format. The aforementioned storage medium can be any memory in the electronic device, such as RAM, hard disk, or magnetic disk.

[0008] Considering that the model parameters used in the first and second inference stages of executing a neural network model have the same numerical values, but the data storage formats used by the first and second processors are different, the electronic device provided in this application can convert the model parameters in the first storage format to the model parameters in the second storage format through the first processor. This enables the reuse of model parameters between the first and second processors, so that storing one set of model parameters in the storage medium can meet the needs of the first and second processors in executing different model inference stages, without having to store two sets of model parameters in the storage medium. Therefore, it can reduce the storage space occupied by model parameters during model inference and save storage space in the storage medium.

[0009] Furthermore, when the space occupancy rate of the storage medium decreases, more free space can be provided to store intermediate data generated during the model inference process, so that the processor can read and write this intermediate data faster, which is beneficial to improving the performance of model inference.

[0010] In one alternative implementation, the model parameters of the first storage format include an input matrix of A rows and B columns, the input matrix includes C×D submatrices, and each of the C×D submatrices includes E rows and F columns of elements; the model parameters of the second storage format include an output matrix of G rows and H columns, where A = C×E, B = D×F, G = C×D, and H = E×F.

[0011] In one optional implementation, the order of the G rows in the output matrix is ​​determined based on the arrangement order of the C×D submatrices in the input matrix. The elements in any row of the output matrix are obtained by expanding the corresponding submatrices of the input matrix row by row, from row to row. For example, the input matrix may include C rows of submatrices, where each row may include D submatrices; adjacent elements in the G rows of the output matrix are either two adjacent submatrices in the same row, or the last submatric in the first row and the first submatric in the second row; the first and second rows are two adjacent rows in the C rows. Expanding the E rows and F columns of elements in a submatrice row by row means that the elements in every adjacent pair of rows in the E rows and F columns are joined end-to-end. In some embodiments, A can be 64, B can be 16, C can be 16, D can be 4, E can be 4, F can be 4, G can be 64, and H can be 16. In the above embodiments, the number of columns H of the output matrix is ​​equal to the number of columns B of the input matrix. In other embodiments, the number of columns H of the output matrix can also be greater than the number of columns B of the input matrix, and elements in the output matrix that do not belong to the input matrix can be filled with 0.

[0012] In one optional implementation, the second processor can be an in-memory computation PIM unit. The PIM unit may include a storage medium. For example, the storage medium can be memory. The PIM unit possesses both computational and storage functions, making data retrieval during computation more convenient. During the second inference stage of the neural network model, it can reduce data access latency and bandwidth consumption. Furthermore, the first processor may include a cache. The value of H mentioned above is determined based on the number of cache columns; the values ​​of E and F mentioned above are determined based on the access granularity of the storage medium, where the access granularity of the storage medium refers to the amount of data that a computational unit in the second processor can read from the storage medium each time.

[0013] In one alternative implementation, the first processor can perform a first row-column axis transformation on the model parameters in the first storage format to obtain model parameters in an intermediate storage format, and then perform a second row-column axis transformation on the model parameters in the intermediate storage format to obtain model parameters in the second storage format. By performing two row-column axis transformations, the first processor can quickly convert the model parameters in the first storage format into model parameters in the second storage format.

[0014] In one optional implementation, when the first processor performs the first row-column axis transformation on the model parameters of the first storage format, it may repeat the first step E times to obtain the model parameters of the intermediate storage format, wherein the model parameters of the intermediate storage format include E B-row C-column matrices; the first step may include: the first processor sequentially selecting C-row B-column elements from the elements in the input matrix that have not undergone row-column axis transformation, wherein the distance between two adjacent rows in the C-row in the input matrix is ​​E; the first processor performs row-column axis transformation on the selected C-row B-column elements to obtain a B-row C-column matrix.

[0015] In one optional implementation, when the first processor performs the second row-column axis transformation on the model parameters of the intermediate storage format, it can repeat the second step D times to obtain the model parameters of the second storage format. The model parameters of the second storage format include D elements of C rows and E × F columns; where D × C rows = G rows, and the elements of two adjacent rows in G rows are obtained by performing the second step twice in D times. The second step may include: the first processor sequentially selecting E matrices of F rows and C columns from the elements of the model parameters of the intermediate storage format that have not undergone row-column axis transformation; the F rows are consecutive F rows, and the spacing between two adjacent F row C column matrices is B; the first processor performs row-column axis transformation on the elements of the E F row C column matrices to obtain C rows and E × F column elements; the E × F elements of each row in the C rows are obtained by expanding the E rows and F columns of the corresponding submatrix in the input matrix row by row, and the spacing between two adjacent rows in the C rows is D.

[0016] Through the above process, the model parameters in the first storage format can be converted into model parameters in the second storage format, so that the first processor can execute the first inference stage of the neural network model based on the model parameters in the second storage format.

[0017] In one alternative implementation, the first processor saves the model parameters of the first storage format read from the storage medium to a first region in the cache of the first processor, and saves the model parameters of the second storage format obtained by format conversion to a second region in the cache of the first processor.

[0018] In the above implementation, after converting the model parameters in the first storage format to model parameters in the second storage format, the first processor can save the model parameters in the second storage format to the cache of the first processor without saving them back to the storage medium. In embodiments where the storage medium is memory, since the memory is located outside the first processor and the cache of the first processor is located inside the first processor, saving the model parameters in the second storage format to the cache of the first processor, and then reading the model parameters in the second storage format from the cache to perform calculations during the first inference stage of the neural network model, can significantly improve execution efficiency compared to reading the model parameters in the second storage format from memory to perform calculations.

[0019] In one optional implementation, the cache of the first processor may further include a third region and a fourth region. The first region stores a first set of model parameters, and the second region stores a second set of model parameters. The first set of model parameters is the model parameters of a first storage format read from the storage medium for the first time, and the second set of model parameters is the model parameters of a second storage format obtained from the first format conversion. The third region stores a third set of model parameters, and the fourth region stores a fourth set of model parameters. The third set of model parameters is the model parameters of the first storage format read from the storage medium for the second time, and the fourth set of model parameters is the model parameters of the second storage format obtained from the second format conversion.

[0020] For example, during the inference process of a neural network model, the first processor can read model parameters from the storage medium multiple times for processing, and the model parameters read each time can be different. When reading model parameters in a first storage format from memory twice consecutively, the first processor can save the model parameters in the first storage format read from the storage medium the first time to a first region in the cache. The first computing unit in the first processor can obtain the model parameters in the first storage format from the first region and perform a format conversion on the model parameters in the first storage format to obtain model parameters in a second storage format after the first format conversion. Then, the model parameters in the second storage format obtained from the first format conversion are saved to a second region in the cache. While the first computing unit retrieves model parameters in a first storage format from the first region and performs format conversion on these parameters, the first processor can simultaneously read model parameters in the first storage format from the storage medium a second time. This second set of model parameters read from memory is saved to the third region of the cache. Once the first computing unit completes the format conversion process for the first set of model parameters read from memory, it can retrieve the model parameters in the first storage format from the third region and perform a second format conversion to obtain model parameters in the second storage format. These second-formatted model parameters are then saved to the fourth region of the cache. Therefore, the two batches of reading and converting model parameters from memory in the first storage format can be executed in parallel, thereby improving the efficiency of model parameter conversion.

[0021] In one alternative implementation, the first processor and the second processor are heterogeneous processors. Heterogeneous processors refer to two processors that have different requirements for data storage formats or computational characteristics when processing data. For example, the first processor can be an NPU or a SoC chip, and the second processor can be a PIM.

[0022] In one alternative implementation, the first inference phase is a pre-filling phase, and the second inference phase is a decoding phase.

[0023] Secondly, this application provides a processor, which may be the first processor described above. The processor may include a first computing unit and a second computing unit.

[0024] The first computing unit is used to convert the model parameters in the first storage format to obtain the model parameters in the second storage format; the model parameters in the first storage format are model parameters of the neural network model read from the storage medium; the first storage format is suitable for the second processor; the second processor is used to execute the second inference stage of the neural network model.

[0025] The second computing unit is used to perform the first inference phase of the neural network model based on the model parameters in the second storage format.

[0026] In one alternative implementation, the first processor is a neural network processing unit (NPU), and the second processor is an in-memory computing (PIM) unit.

[0027] In one alternative implementation, the first computation unit may include a vector unit, and the second computation unit may include a cube unit.

[0028] In one alternative implementation, the model parameters of the first storage format include an input matrix of A rows and B columns, the input matrix includes C×D submatrices, and each of the C×D submatrices includes E rows and F columns of elements; the model parameters of the second storage format include an output matrix of G rows and H columns, where A = C×E, B = D×F, G = C×D, and H = E×F.

[0029] In one alternative implementation, the order of the G rows in the output matrix is ​​determined based on the arrangement order of the C×D submatrices in the input matrix. The elements in any row of the output matrix are obtained by expanding the corresponding submatrices of the input matrix row by row (E rows, F columns). For example, the input matrix may include C rows of submatrices, where each row may include D submatrices; adjacent elements in the G rows of the output matrix are either two adjacent submatrices in the same row, or the last submatric in the first row and the first submatric in the second row; the first and second rows are two adjacent rows in the C rows. Expanding the E rows, F columns of elements in a submatrice row by row means that the elements in each adjacent row of the E rows, F columns are joined end-to-end.

[0030] In one alternative implementation, the first computational unit can specifically be used for:

[0031] The model parameters in the first storage format are transformed along the first row and column axes to obtain the model parameters in the intermediate storage format;

[0032] The model parameters in the intermediate storage format are transformed by the second row and column axes to obtain the model parameters in the second storage format.

[0033] In one optional implementation, when the first processor performs the first row-column axis transformation on the model parameters of the first storage format, it may repeat the first step E times to obtain the model parameters of the intermediate storage format, wherein the model parameters of the intermediate storage format include E B-row C-column matrices; the first step may include: the first processor sequentially selecting C-row B-column elements from the elements in the input matrix that have not undergone row-column axis transformation, wherein the distance between two adjacent rows in the C-row in the input matrix is ​​E; the first processor performs row-column axis transformation on the selected C-row B-column elements to obtain a B-row C-column matrix.

[0034] In one optional implementation, when the first processor performs the second row-column axis transformation on the model parameters of the intermediate storage format, it can repeat the second step D times to obtain the model parameters of the second storage format. The model parameters of the second storage format include D elements of C rows and E × F columns; where D × C rows = G rows, and the elements of two adjacent rows in G rows are obtained by performing the second step twice in D times. The second step may include: the first processor sequentially selecting E matrices of F rows and C columns from the elements of the model parameters of the intermediate storage format that have not undergone row-column axis transformation; the F rows are consecutive F rows, and the spacing between two adjacent F row C column matrices is B; the first processor performs row-column axis transformation on the elements of the E F row C column matrices to obtain C rows and E × F column elements; the E × F elements of each row in the C rows are obtained by expanding the E rows and F columns of the corresponding submatrix in the input matrix row by row, and the spacing between two adjacent rows in the C rows is D.

[0035] In one alternative implementation, the first processor may further include a cache; the cache is used to store: model parameters of a first storage format read from the storage medium, and model parameters of a second storage format obtained by format conversion.

[0036] In one alternative implementation, the cache of the first processor may include a first region, a second region, a third region, and a fourth region.

[0037] The first area is used to store the first part of the model parameters, and the second area is used to store the second part of the model parameters; the first part of the model parameters are the model parameters in the first storage format read from the storage medium for the first time; the second part of the model parameters are the model parameters in the second storage format obtained from the first format conversion.

[0038] The third area is used to store the third part of the model parameters, and the fourth area is used to store the fourth part of the model parameters; the third part of the model parameters are the model parameters of the first storage format read from the storage medium for the second time; the fourth part of the model parameters are the model parameters of the second storage format obtained from the second format conversion.

[0039] In one alternative implementation, the first computing unit and the second computing unit adopt a coupled architecture. In another alternative implementation, the first computing unit and the second computing unit adopt an independent architecture.

[0040] Thirdly, this application provides a data processing method, which can be executed by a first processor in an electronic device; the data processing method includes:

[0041] Model parameters in a first storage format are read from a storage medium, the first storage format being suitable for a second processor in an electronic device; the second processor is used to execute the second inference stage of the neural network model;

[0042] The model parameters in the first storage format are converted to obtain the model parameters in the second storage format, which is suitable for the first processor.

[0043] The first inference phase of the neural network model is executed based on the model parameters in the second storage format.

[0044] In one alternative implementation, the model parameters of the first storage format include an input matrix of A rows and B columns, the input matrix includes C×D submatrices, and each of the C×D submatrices includes E rows and F columns of elements; the model parameters of the second storage format include an output matrix of G rows and H columns, where A = C×E, B = D×F, G = C×D, and H = E×F.

[0045] In one alternative implementation, the order of the G rows in the output matrix is ​​determined based on the arrangement order of the C×D submatrices in the input matrix. The elements in any row of the output matrix are obtained by expanding the corresponding submatrices of the input matrix row by row (E rows, F columns). For example, the input matrix may include C rows of submatrices, where each row may include D submatrices; adjacent elements in the G rows of the output matrix are either two adjacent submatrices in the same row, or the last submatric in the first row and the first submatric in the second row; the first and second rows are two adjacent rows in the C rows. Expanding the E rows, F columns of elements in a submatrice row by row means that the elements in each adjacent row of the E rows, F columns are joined end-to-end.

[0046] In one alternative implementation, the first processor can perform a first row-column axis transformation on the model parameters in the first storage format to obtain model parameters in an intermediate storage format, and then perform a second row-column axis transformation on the model parameters in the intermediate storage format to obtain model parameters in the second storage format. By performing two row-column axis transformations, the first processor can quickly convert the model parameters in the first storage format into model parameters in the second storage format.

[0047] In one optional implementation, when the first processor performs the first row-column axis transformation on the model parameters of the first storage format, it may repeat the first step E times to obtain the model parameters of the intermediate storage format, wherein the model parameters of the intermediate storage format include E B-row C-column matrices; the first step may include: the first processor sequentially selecting C-row B-column elements from the elements in the input matrix that have not undergone row-column axis transformation, wherein the distance between two adjacent rows in the C-row in the input matrix is ​​E; the first processor performs row-column axis transformation on the selected C-row B-column elements to obtain a B-row C-column matrix.

[0048] In one optional implementation, when the first processor performs the second row-column axis transformation on the model parameters of the intermediate storage format, it can repeat the second step D times to obtain the model parameters of the second storage format. The model parameters of the second storage format include D elements of C rows and E × F columns; where D × C rows = G rows, and the elements of two adjacent rows in G rows are obtained by performing the second step twice in D times. The second step may include: the first processor sequentially selecting E matrices of F rows and C columns from the elements of the model parameters of the intermediate storage format that have not undergone row-column axis transformation; the F rows are consecutive F rows, and the spacing between two adjacent F row C column matrices is B; the first processor performs row-column axis transformation on the elements of the E F row C column matrices to obtain C rows and E × F column elements; the E × F elements of each row in the C rows are obtained by expanding the E rows and F columns of the corresponding submatrix in the input matrix row by row, and the spacing between two adjacent rows in the C rows is D.

[0049] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which are used to cause a computer to perform any of the data processing methods provided in the first aspect above.

[0050] Fifthly, embodiments of this application provide a computer program product comprising computer-executable instructions, the computer-executable instructions being used to cause a computer to perform any of the data processing methods provided in the first aspect above.

[0051] The technical effects that can be achieved by any of the second to fifth aspects mentioned above can be referred to the description of the beneficial effects in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0052] Figure 1 is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0053] Figure 2 is an interaction diagram between processors during a model inference process provided in an embodiment of this application;

[0054] Figure 3 is a schematic diagram of model parameters in a first storage format provided in an embodiment of this application;

[0055] Figure 4 is a schematic diagram of model parameters for a second storage format provided in an embodiment of this application;

[0056] Figure 5 is a schematic diagram of a first row and column axis transformation provided in an embodiment of this application;

[0057] Figure 6 is a schematic diagram of a second row and column axis transformation provided in an embodiment of this application;

[0058] Figure 7 is a schematic diagram of the structure of a processor provided in an embodiment of this application;

[0059] Figure 8 is a schematic diagram of a cache structure provided in an embodiment of this application;

[0060] Figure 9 is a schematic diagram of another processor provided in an embodiment of this application. Detailed Implementation

[0061] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the embodiments of this application will be described in detail below with reference to the accompanying drawings. The terminology used in the implementation section of this application is only for explaining specific embodiments of this application and is not intended to limit this application.

[0062] Before introducing the specific solutions provided in the embodiments of this application, some terms used in this application will be explained to facilitate understanding by those skilled in the art, but the terms used in this application are not limited.

[0063] (1) Memory interleaving is a technique used to improve memory performance in electronic devices. This technique divides memory into multiple independent memory modules or storage units and interleaves the allocation of data addresses across these modules or storage units, thereby achieving parallel access to memory and higher bandwidth utilization. The independent memory modules or storage units can be created by dividing memory into multiple matrix storage units, each of which can function as an independent memory module or storage unit. In some embodiments, the memory in an electronic device may include multiple memory modules (DIMMs) inserted into slots on the motherboard. Each memory module may include two or more memory ranks, each rank including multiple memory chips, and each chip including multiple storage banks. Each bank can function as an independent memory module or storage unit. Each independent memory module or storage unit may include multiple storage cells for storing data.

[0064] Memory interleaving technology distributes contiguous memory addresses across different memory modules, achieving address interleaving. For example, suppose there are four memory modules: memory module 0, memory module 1, memory module 2, and memory module 3. Address 0 can be assigned to memory module 0, address 1 to memory module 1, address 2 to memory module 2, address 3 to memory module 3, address 4 to memory module 0, and so on, forming a circular allocation. When the processor accesses data from contiguous addresses in memory, it can access multiple memory modules in parallel, allowing multiple memory modules to respond simultaneously, reducing waiting time caused by memory latency (such as precharge and row activation).

[0065] In some applications, low-order interleaving can be used to implement memory interleaving. This involves selecting memory modules using the least significant bits of the address (e.g., the last few bits), ensuring that contiguous addresses are distributed across different memory modules. This method is suitable for sequential access scenarios, such as array traversal. In other applications, high-order interleaving can be used to implement memory interleaving. This involves selecting memory modules using the most significant bits of the address (e.g., the first few bits), allowing adjacent addresses to potentially reside in the same memory module. This method is suitable for specific non-contiguous access patterns.

[0066] (2) System on Chip (SoC): SoC is a chip that integrates multiple processing units. The processing units integrated on the SoC chip may include one or more of the following: central processing unit (CPU), graphics processing unit (GPU), NPU, application processor (AP), microprocessor (MP), or digital signal processor (DSP).

[0067] (3) PIM: PIM is a chip that has both computing and storage functions, and can also be described as a memory chip with computing units. Since data calculation and processing can be performed in memory, the latency and bandwidth consumption of data access can be reduced compared with the processor reading data from memory and then processing the data.

[0068] In this application embodiment, "multiple" refers to two or more. Therefore, in this application embodiment, "multiple" can also be understood as "at least two". "At least one" can be understood as one or more, such as one, two, or more. For example, "including at least one" means including one, two, or more, and it does not limit which ones are included. For example, including at least one of A, B, and C, then it could include A, B, C, A and B, A and C, B and C, or A and B and C. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / ", unless otherwise specified, generally indicates that the preceding and following related objects have an "or" relationship.

[0069] Unless otherwise stated, the ordinal numbers such as "first" and "second" mentioned in the embodiments of this application are used to distinguish multiple objects, and are not used to limit the order, sequence, priority or importance of multiple objects.

[0070] The data processing method provided in this application embodiment can be applied to the electronic device shown in Figure 1. This electronic device can be a computer, a server (such as a general-purpose computing server, a general-purpose storage server, or a data center server), or a terminal device (such as a home appliance, laptop, or mobile phone). This electronic device can be applied in scenarios such as satellite communication, data centers, storage, terminals, and intelligent vehicles. As shown in Figure 1, the electronic device 100 may include a central processing unit 110, a first processor 120, a second processor 130, and a power module 140. The power module 140 can supply power to the central processing unit 110, the first processor 120, and the second processor 130. The power module 140, the central processing unit 110, the first processor 120, and the second processor 130 can be connected via a bus. The central processing unit 110, the first processor 120, and the second processor 130 can all be mounted on the motherboard of the electronic device 100.

[0071] The central processing unit 110 is the computing and control core of the electronic device 100, used to execute computer instructions and control the first processor 120 and the second processor 130 to execute the LLM inference process. The first processor 120 can be an NPU or a GPU, used to cooperate with the second processor 130 to execute the LLM inference process. It should be noted that the central processing unit 110 can also be replaced by chips that can execute computer instructions, such as controllers, MP, and DSPs.

[0072] In some embodiments, the central processing unit 110 and the first processor 120 can be configured independently, and other processing units, such as an application processor (AP), an application processor (MP), and a DSP, may also be configured on the electronic device 100. In other embodiments, the central processing unit 110 and the first processor 120 may be configured on the same chip, such as on a SoC chip. In addition to the central processing unit 110 and the first processor 120, the SoC chip may also include, but is not limited to, one or more of a GPU, an application processor (AP), an application processor (MP), a DSP, or a memory controller.

[0073] The second processor 130 may be a PIM. The second processor 130 is provided with a computing unit 121 and a memory 122. The memory 122 is a storage medium. The first processor 120 can directly exchange data with the memory 122 and can read and write data to the memory 122 at any time, serving as a temporary data storage for the operating system or other running applications running on the first processor.

[0074] Memory 122 may include volatile memory, such as random access memory (RAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR-SDRAM), and low power double data rate synchronous dynamic random access memory (LPDDR-SDRAM). DDR-SDRAM can be abbreviated as DDR, and LPDDR-SDRAM can be abbreviated as LPDDR. Memory 122 may also include non-volatile memory, such as storage class memory (SCM), or a combination of volatile and non-volatile memory. DRAM is a semiconductor memory, and like most RAM, it is a type of volatile memory device. SCM is a composite storage technology that combines the characteristics of traditional storage devices and memory. Storage class memory can provide faster read and write speeds than hard drives, but its access speed is slower than DRAM, and it is also cheaper than DRAM.

[0075] DRAM, SDRAM, DDR, LPDDR and SCM are merely illustrative examples in this embodiment. Memory 122 may also include other random access memories, such as read-only memory (ROM), for example, programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), etc.

[0076] In some embodiments, in addition to the memory 122 provided in the second processor 130, the electronic device 100 may also include other memory disposed outside the second processor 130. The number of memory modules can be one or more, and the multiple memory modules can be of different types. This application embodiment does not limit the number or type of memory. Furthermore, the user can configure the memory to have a power-saving function. A power-saving function means that when the system experiences a power outage and is then powered on again, the data stored in the memory will not be lost. Memory with a power-saving function is called non-volatile memory.

[0077] The computing unit 121 can be used to perform calculations based on the data stored in the memory 122. The memory 122 can be used to temporarily store the computational data in the central processing unit 110, the first processor 120 and the second processor 130, as well as exchange data with external storage devices such as disks.

[0078] The electronic device 100 shown in Figure 1 can be used for inference based on an LLM model. The LLM model can include the Transformer model, a neural network model based on a self-attention mechanism, primarily used for processing sequential data. The Transformer model has wide applications in natural language processing, including but not limited to machine translation, text generation, text classification, and question answering systems. The following uses the Transformer model as an example to illustrate its inference process. The Transformer model can include two parts: an encoder and a decoder. The encoder consists of multiple identical network layers, each consisting of two sub-layers: a self-attention layer and a feed-forward neural network (FFN) layer. The decoder also consists of multiple identical layers; similar to the encoder, each layer in the decoder contains a self-attention layer and an FFN layer. However, unlike the encoder, each layer in the decoder also includes an additional encoder-decoder attention layer. The encoder-decoder attention layer is used to calculate the correlation between the decoder's current representation and the encoder output, so that relevant information in the input sequence can be considered when generating the output sequence.

[0079] The self-attention mechanism of the Transformer model assigns an attention weight to each position in the input sequence, where the attention weight represents the importance of that position to other positions. Each position's vector is multiplied by its attention weight, resulting in a product for each position. These products are then summed to obtain a weighted sum vector. A linear transformation is performed on this weighted sum vector to obtain the final output vector. The attention weights in the Transformer model are pre-trained model parameters. In addition to the attention weights, the Transformer model's parameters can also include parameters from other positions.

[0080] When performing inference tasks using the Transformer model, the performance of the inference task depends on both the inherent characteristics of the inference task and the performance metrics of the electronic device. The electronic device's performance metrics can include computing power and bandwidth. Computing power is the peak floating-point operations per second (peak flops / sec), and bandwidth is the peak memory bandwidth per second (peak memory accesses), measured in bytes / sec. The inherent characteristics of the inference task can include computational load (in flops) and memory access load (in bytes). The performance of the inference task can be visualized using a Roofline model. The Roofline model visualizes the performance of the inference task by plotting the functional relationship between floating-point performance and the machine's peak performance (peak bandwidth) and computational intensity. The resulting curve includes two performance upper limits specific to the electronic device: one from the upper limit of memory bandwidth, and one from the peak performance of the electronic device's processor.

[0081] The performance of inference tasks described by the Roofline model has two bottleneck regions: compute-bound and memory-bound. Compute-bound: Regardless of the computational intensity of the Transformer model, its theoretical performance can only be equal to the computing power (i.e., computational intensity) of the electronic device's processor. When the computational intensity of the Transformer model exceeds the upper limit of the electronic device's processor, the Transformer model is in a compute-bound state, meaning its theoretical performance is limited by the electronic device's computing power. From the perspective of the electronic device's computing power, the Transformer model has already utilized all of the processor's computing power. Therefore, the higher the computing power of the electronic device, the greater the theoretical performance of the Transformer model after entering the compute-bound region. Bandwidth-bound: When the computational intensity of the Transformer model is less than the upper limit of the electronic device's processor, the theoretical performance of the Transformer model is entirely determined by the upper limit of the electronic device's memory bandwidth and the Transformer model's own computational intensity. In this case, the Transformer model is in a bandwidth-bound state. It is evident that, under the premise of being within the bandwidth bottleneck range, the greater the memory bandwidth of the electronic device, or the greater the computational intensity of the Transformer model, the more linearly the theoretical performance of the Transformer model can increase.

[0082] Transformer models typically consist of training and inference processes. The training process, which demands extremely high computing power and storage, is usually completed on the server side. After training, the trained model parameters can be deployed on cloud-side devices such as computing centers, or on edge devices such as personal computers, laptops, and mobile phones to respond to user needs and execute the inference process.

[0083] The inference process of the Transformer model mainly includes two stages: the pre-filling stage and the decoding stage. These two stages have different requirements for the computing power and memory access of the electronic device. In the pre-filling stage, a large amount of input data needs to be calculated, which places high demands on computing power and is a computational bottleneck. In the decoding stage, the loading process of the LLM model parameters is time-consuming and is a memory access bottleneck. To improve the computational speed of the Transformer model's inference process, reduce energy consumption, and improve cost-effectiveness, the electronic device 100 shown in Figure 1 can be used to execute the Transformer model's inference process, with different stages executed on different processors. Since the pre-filling stage is a computational bottleneck, it can be executed on the first processor 120, which has higher computing power. The decoding stage, being a memory access bottleneck due to the time-consuming loading process of model parameters, can be executed on the second processor 130 using a PIM (Programmable Memory Injection) approach.

[0084] In the inference process of the Transformer model, to improve bandwidth utilization during computation, the first processor 120 and the second processor 130 can use memory interleaving to access memory and perform data access. Because the memory interleaving schemes used by the first processor 120 and the second processor 130 differ, although the model parameters of the Transformer model used by the first processor 120 and the second processor 130 have the same numerical values, their data storage formats are different, making direct reuse difficult. Typically, during the inference process of the Transformer model, two copies of the model parameters need to be loaded into the electronic device's memory to meet the different needs of the first processor 120 and the second processor 130. However, since the number of model parameters in a Transformer model is usually large, repeatedly loading two copies of the Transformer model's model parameters into the electronic device's memory, and storing two copies of the Transformer model's model parameters in memory, not only wastes memory capacity but also affects the performance of model inference.

[0085] To achieve model parameter reuse, this application provides a data processing method that can be executed by the first processor 120 in FIG1. ​​The data processing method may include: during the execution of the first inference stage of a neural network model, the first processor reads model parameters in a first storage format from a storage medium, wherein the model parameters are the model parameters of the aforementioned neural network model, the first storage format is suitable for a second processor, and the second processor is used to execute the second inference stage of the neural network model. The first processor performs format conversion on the model parameters in the first storage format to obtain model parameters in a second storage format, and the first processor executes the first inference stage based on the model parameters in the second storage format. Since the model parameters used in the first and second inference stages have the same values, but the data storage formats used by the first and second processors are different, the above process enables the reuse of model parameters between the first and second processors. This allows the storage medium to store only one copy of the model parameters, which is sufficient to meet the needs of the first and second processors in executing the model inference process, without needing to store two copies of the model parameters. This reduces the storage space occupied by the model parameters during the model inference process. When the storage medium's space occupancy rate decreases, more free space can be provided to store intermediate data generated during the model inference process, allowing the processor to read and write this intermediate data more quickly, which is beneficial to improving the performance of model inference.

[0086] The following uses the memory of an electronic device as an example to specifically describe the data processing method provided in the embodiments of this application. Figure 2 exemplarily illustrates the interaction flowchart between various processors during the execution of the data processing method provided in the embodiments of this application by an electronic device. As shown in Figure 2, the method may include the following steps:

[0087] S201, the central processing unit receives a model inference request and loads the model parameters of the neural network model into memory. The model parameters in memory adopt the first storage format.

[0088] When a user needs to perform inference using a neural network model, they can input a model inference request through the electronic device's human-computer interaction interface. Upon receiving the request, the electronic device's central processing unit (CPU) can read the neural network model's parameters from a hard disk, disk, or other storage device, or download the parameters from a network and load them into the electronic device's memory. The neural network model can be an LLM model or a Transformer model. In some embodiments, the model parameters can be first saved to the ROM region of memory, and then loaded from the ROM region into the DDR region or LPDDR region.

[0089] The model parameters of the neural network model stored in the memory of the electronic device adopt a first storage format. The first storage format is suitable for the second processor of the electronic device. That is, the first storage format satisfies the data arrangement of the memory interleaving scheme adopted by the second processor, and the second processor can directly use the data in the first storage format for calculation.

[0090] S202, the central processing unit sends a model inference request for the pre-filling stage to the first processor.

[0091] S203, the central processing unit sends a model inference request for the decoding stage to the second processor.

[0092] The instruction identifiers in the model inference requests during the pre-filling phase and the decoding phase are different. After receiving a model inference request, the CPU can determine whether the received request is from the pre-filling or decoding phase based on the instruction identifiers carried in the request. If the request is from the pre-filling phase, the CPU can route it to the first processor, i.e., send the pre-filling model inference request to the first processor. If the request is from the decoding phase, the CPU can route it to the second processor, i.e., send the decoding model inference request to the second processor. The pre-filling phase can be referred to as the first inference phase, and the decoding phase as the second inference phase. The first and second processors differ in their data storage format requirements or computational characteristics during data processing; therefore, they can be considered heterogeneous processors.

[0093] S204, the first processor reads the model parameters in the first storage format from memory, performs format conversion on the model parameters in the first storage format, and obtains the model parameters in the second storage format.

[0094] The second storage format is applicable to the first processor, meaning the first processor can directly use data in the second storage format for calculations.

[0095] For example, the model parameters of the first storage format can be as shown in Figure 3. The model parameters of the first storage format can include an input matrix of A rows and B columns. The input matrix of A rows and B columns can include C×D sub-matrices, and each of the C×D sub-matrices can include E rows and F columns of elements. The model parameters of the second storage format can be as shown in Figure 4. The model parameters of the second storage format can include an output matrix of G rows and H columns, where A = C×E, B = D×F, G = C×D, and H = E×F. The order of G rows in the output matrix is ​​determined based on the arrangement order of the C×D sub-matrices in the input matrix. The elements of any row in the output matrix of G rows and H columns are obtained by expanding the E rows and F columns of the corresponding sub-matrices in the input matrix row by row. In the embodiments shown in Figures 3 and 4, A in the input matrix of A rows and B columns is 64 and B is 16. C in the C×D sub-matrices included in the input matrix is ​​16 and D is 4. E in the E rows and F columns of each sub-matrice is 4 and F is 4. In the output matrix with G rows and H columns, G is 64 and H is 16. The order of the G rows in the output matrix is ​​determined by the arrangement order of the C×D submatrices in the input matrix. This can be understood as follows: adjacent elements in the G rows of the output matrix are either the last submatrix in the same row or the first submatrix in the (n+1)th row. For example, in the output matrix shown in Figure 4, the 2nd and 3rd rows are the 2nd and 3rd submatrices in the first row of the input matrix shown in Figure 3, respectively; the 4th and 5th rows are the 4th submatrix in the first row and the 1st submatrix in the second row of the input matrix shown in Figure 3, respectively.

[0096] The model parameters in the second storage format can include a G-row, H-column output matrix. The elements of any row in the G-row, H-column output matrix are obtained by expanding the elements of one of the C×D submatrices of the input matrix row by row. This can be understood as: the elements of any row in the G-row, H-column output matrix are obtained by expanding the elements of every two adjacent rows of the corresponding submatrices in the input matrix by concatenating the first and last elements. Taking the first row of the 64-row, 16-column output matrix in Figure 4 as an example, the 16 elements 'a' in the first row... 1,1 a 1,2 a 1,3 , ...a 1,16 It is obtained by expanding the 16 elements (4 rows and 4 columns) of the first submatrix of the first row of the input matrix in Figure 3 in row-major order. The first row of the 4 rows includes 4 elements 'a'. 1,1 a 1,2 a 1,3 a 1,4 The second line contains 4 elements a. 1,5 a 1,6 a 1,7 a 1,8The third line contains 4 elements a. 1,9 a 1,10 a 1,11 a 1,12 The fourth line contains 4 elements a. 1,13 a 1,14 a 1,15 a 1,16 The elements of the four rows are concatenated end to end to obtain the 16 elements 'a' in the first row of the output matrix. 1,1 a 1,2 a 1,3 , ...a 1,16 .

[0097] In the above embodiment, the A-row, B-column input matrix has A = 64 and B = 16. The input matrix comprises C×D submatrices, where C = 16 and D = 4. Each submatrix includes E-row, F-column elements, where E = 4 and F = 4. The output matrix has G-row, H-column elements, where G = 64 and H = 16. In other embodiments, A, B, C, D, E, F, G, and H can be other values. For example, A can be 128 and B can be 32. The input matrix comprises C×D submatrices, where C = 32 and D = 4. Each submatrix includes E-row, F-column elements, where E = 4 and F = 8. The output matrix has G-row, H-column elements, where G = 128 and H = 32. In the above embodiment, the number of columns H of the output matrix is ​​equal to the number of columns B of the input matrix. In other embodiments, the number of columns H of the output matrix can also be greater than the number of columns B of the input matrix. Elements in the output matrix that do not belong to the input matrix can be filled with 0. In this context, the value of H is determined based on the number of columns in the cache of the first processor, which refers to the cache used to store model parameters of the second storage format. The number of columns in the cache is the number of storage units contained in each row of the cache. The values ​​of E and F are determined based on the memory access granularity, which refers to the amount of data that a computing unit in the second processor can read from memory at a time. This amount of data is related to the capacity of the columns in the memory storage array. The value of E is determined based on the parallelism of the computing unit reading data in the second processor, i.e., the number of lanes through which the computing unit reads data from memory. The value of F is the ratio of the column capacity to the number of lanes. The value of D is the ratio of the granularity of the memory storage array to the granularity of the column. The value of C is determined based on the interleaving parallelism of memory interleaving, which refers to the number of storage arrays that a computing unit in the second processor can access at a time when reading data from memory.

[0098] The electronic device's memory stores many model parameters of the neural network model in a first storage format. The first processor can read some model parameters of the neural network model from the memory based on the received model inference request in the pre-filling stage and process the read model parameters.

[0099] In some embodiments, the first processor can perform a first row-column axis transformation on the model parameters in the first storage format to obtain model parameters in the intermediate storage format, and then perform a second row-column axis transformation on the model parameters in the intermediate storage format to obtain model parameters in the second storage format. Both the first and second row-column axis transformations are generalized row-column axis transformations, which can be quickly implemented using the `vnchwconv` command. For example, the first row-column axis transformation process may include the following steps: sequentially selecting elements in rows C and columns B from the elements in the input matrix that have not undergone row-column axis transformation, where the distance between adjacent rows in row C is E rows in the input matrix; performing a row-column axis transformation on the elements in rows C and columns B to obtain elements in rows B and columns C; storing the elements in rows B and columns C contiguously to obtain a matrix of rows B and columns C; repeating the above steps E times, resulting in model parameters in the intermediate storage format comprising E matrices of rows B and columns C. For example, as shown in Figure 5, during the first execution, elements in rows 16 and 16 columns (row 1, row 5, row 9, etc.) can be selected from the input matrix. The spacing between adjacent rows in these 16 rows is 4, such as the spacing between the first and fifth rows in the input matrix. After performing row and column transformations on these 16 rows and 16 columns, they are stored consecutively, resulting in a 16-row, 16-column matrix. During the second execution, elements from the input matrix that have not undergone row and column transformations are selected sequentially. Since the first row has already undergone row and column transformation, elements in rows 16 and 16 columns (row 2, row 6, row 10, etc.) can be selected starting from the second row, and row and column transformations are performed. This process is repeated four times to complete the row and column transformations for all elements in the input matrix, resulting in four 16-row, 16-column matrices (64 rows and 16 columns), which are the model parameters in the intermediate storage format.

[0100] The second row-column axis transformation process may include the following steps: Select E F-row, C-column matrices sequentially from the untransformed elements of the model parameters in the intermediate storage format. Here, F rows are consecutive, and the spacing between any two adjacent F-row, C-column matrices is B rows. Perform row-column axis transformation on the E F-row, C-column elements to obtain C-row, E×F-column elements. In this case, the E×F elements in each row of the C-row are stored consecutively, and the spacing between any two adjacent rows in the C-row is D rows. Repeat this process D times, interleaving the resulting D C-row, E×F-column elements to obtain the model parameters in the second storage format. For example, as shown in Figure 6, during the first execution, four 4-row, 16-column elements can be selected from the model parameters in the intermediate storage format. Each 4-row, 16-column element consists of four consecutive rows, and the spacing between any two adjacent 4-row, 16-column elements is 16. For example, the first 4x16 element set represents rows 1 to 4, and the second 4x16 element set represents rows 17 to 20, with a spacing of 16 between them. Performing a row-column axis transformation on the four 4x16 elements results in a 16x16 element set, where the 16 elements in each row are stored consecutively, with a spacing of 4 between adjacent rows, as shown in the first and fifth rows of the output matrix. During the second execution, elements in the model parameters of the intermediate storage format that have not undergone row and column axis transformation are selected sequentially. Since the row and column axis transformation has already been performed on the first to fourth rows, four 4-row, 16-column elements can be selected starting from the fifth row. The first 4-row, 16-column element is from the fifth to the eighth row, and the second 4-row, 16-column element is from the twenty-first to the twenty-fourth row, with a spacing of 16 between them. The row and column axis transformation is performed on the four selected 4-row, 16-column elements. This process is repeated four times to complete the row and column axis transformation of all elements in the model parameters of the intermediate storage format, resulting in four 16-row, 16-column elements. These four 16-row, 16-column elements are then stored in a row-interleaved manner to obtain a 64-row, 16-column output matrix, which is the model parameters of the second storage format.

[0101] S205, the first processor performs the pre-filling stage of the neural network model based on the model parameters in the second storage format.

[0102] The second storage format is applicable to the first processor of an electronic device. That is, the second storage format satisfies the data arrangement of the memory interleaving scheme adopted by the first processor, allowing the first processor to directly use data in the second storage format for computation. For example, the first processor can be an NPU or a GPU. The memory interleaving scheme adopted by the first processor requires that a consecutive row of data (i.e., any row of data in the second storage format) be stored in multiple independent memory modules during storage. For example, the first row of 16 data points 'a' in the second storage format... 1,1 a 1,2 a 1,3 , ...a 1,16It can be stored in 4 independent memory modules, a 1,1 a 1,2 a 1,3 a 1,4 Stored in the first memory module, a 1,5 a 1,6 a 1,7 a 1,8 Stored in the second memory module, a 1,9 a 1,10 a 1,11 a 1,12 Stored in the third memory module, a 1,13 a 1,14 a 1,15 a 1,16 It is stored in the fourth memory module.

[0103] After obtaining the model parameters in the second storage format, the first processor can perform the pre-filling stage of the neural network model based on the model parameters in the second storage format.

[0104] S206, the second processor performs the decoding phase of the neural network model based on the model parameters of the first storage format.

[0105] The first storage format is suitable for the second processor; that is, the first storage format satisfies the data arrangement of the memory interleaving scheme adopted by the second processor, and the second processor can directly use the data in the first storage format for calculation. For example, the memory interleaving scheme adopted by the second processor requires multiple consecutive data points to be stored in an independent memory module in order to perform calculations on multiple data points. For instance, 16 consecutive data points 'a' in the first storage format... 1,1 a 1,2 a 1,3 , ...a 1,16 It can be divided into 4 rows and 4 columns and stored in the same memory module. The first row includes 4 data 'a's. 1,1 a 1,2 a 1,3 a 1,4 The second line contains four data points, a. 1,5 a 1,6 a 1,7 a 1,8 The third line contains four data points, a. 1,9 a 1,10 a 1,11 a 1,12 The fourth line contains four data points, a. 1,13 a 1,14 a 1,15 a 1,16The second processor can perform the decoding phase of the neural network model based on the model parameters in the first storage format stored in memory. The memory can be located within the second processor.

[0106] In some embodiments, the second processor of the electronic device may be a PIM (Personal Information Modeling Unit), which may include a computing unit and the aforementioned memory. The memory stores model parameters in a first storage format. The computing unit can retrieve the model parameters in the first storage format from the memory and perform the decoding phase of the neural network model based on the model parameters in the first storage format.

[0107] The data processing method provided in this application can be applied to electronic devices containing at least two heterogeneous computing units. Since the model parameters used in the first and second inference stages have the same values, but the data storage formats used by the first and second processors are different, the above process enables model parameter reuse between the first and second processors. This allows only one copy of the model parameters to be stored in the storage medium, meeting the needs of the first and second processors in executing the model inference process, without needing to store two copies of the model parameters. This reduces the storage space occupied by the model parameters during model inference and improves the performance of model inference. This application fully utilizes the hardware capabilities and characteristics of the first and second processors, thereby ensuring the performance of the model inference process while achieving model parameter reuse between the first and second processors.

[0108] This application also provides a processor, which can be the first processor described above. The first processor may include a first computing unit and a second computing unit. The first computing unit can be used to convert model parameters in a first storage format to obtain model parameters in a second storage format, and the second computing unit can be used to execute the first inference stage of the neural network model based on the model parameters in the second storage format.

[0109] In some embodiments, the first computing unit and the second computing unit may be software modules, for example, the first computing unit and the second computing unit may be computer programs executed by the NPU; in other embodiments, the first computing unit and the second computing unit may be hardware modules, for example, the first computing unit and the second computing unit may be computing chips.

[0110] In an optional embodiment, the structure of the first processor can be as shown in FIG7. The first processor 700 may include a first computing unit 711 and a second computing unit 712. For example, the first computing unit may be a vector unit, which is used to perform vector calculations; the second computing unit may be a cube unit, which is used to perform matrix multiplication calculations. In addition to including the first computing unit 711 and the second computing unit 712, the first processor 700 may also include a cache. Exemplarily, the cache may include a layer 1 buffer (L1 buffer) 721, a unified buffer (UB) 722, and a layer 2 buffer (L2 buffer) 723, wherein the layer 2 buffer 723 is a cache space shared by the first computing unit 711 and the second computing unit 712, the unified buffer 722 is the cache space corresponding to the first computing unit 711, and the layer 1 buffer 721 is the cache space corresponding to the second computing unit 712. The first computing unit 711, the second computing unit 712, the layer 1 cache 721, the unified cache 722, and the layer 2 cache 723 are connected via data transmission lines. These data transmission lines are used to transfer data between the units and can also be called data transfer units. In Figure 7, the first computing unit 711 and the second computing unit 712 adopt a coupled architecture. The first computing unit 711 and the second computing unit 712 have a high-speed memory path. The first computing unit 711 can access the layer 1 cache 721 corresponding to the second computing unit 712, and the second computing unit 712 can also access the unified cache 722 corresponding to the first computing unit 711.

[0111] The first processor 700 can be used to execute the pre-filling stage of the neural network model. Upon receiving a model inference request for the pre-filling stage, the first processor 700 can read partial model parameters of the neural network model from the memory of the electronic device based on the pre-filling stage model inference request and process the read partial model parameters. The model parameters stored in memory are stored in a first storage format. The first processor 700 can save the read model parameters in the first storage format to a unified cache 722, or the first processor 700 can first save the read model parameters in the first storage format to a layer 2 cache 723, and then the layer 2 cache 723 saves them to the unified cache 722. The first computing unit 711 can obtain the model parameters in the first storage format from the unified cache 722, convert the model parameters in the first storage format to a second storage format, and then save the converted model parameters in the unified cache 722, and then the unified cache 722 saves them to a layer 1 cache 721. The second computing unit 712 can read the model parameters in the second storage format from the layer 1 cache 721 and execute the pre-filling stage of the neural network model based on the model parameters in the second storage format. The second computing unit 712 reads model parameters in the second storage format from the layer 1 cache 721. Compared with reading model parameters in the second storage format from other storage media in the first processor 700, it is faster and has lower latency, which can improve the execution efficiency of model inference.

[0112] In the first processor, where the first computing unit 711 and the second computing unit 712 adopt a coupled architecture, the loading path of the model parameters includes: loading the model parameters in a first storage format from memory into the L2 cache of the first processor 700, and then saving them from the L2 cache of the first processor 700 into a unified cache 722. The first computing unit 711 can obtain the model parameters in the first storage format from the unified cache 722, perform format conversion on the model parameters in the first storage format, save the converted model parameters in the second storage format back into the unified cache 722, and then save them from the unified cache 722 into the layer 1 cache 721. The second computing unit 712 can read the model parameters in the second storage format from the layer 1 cache 721 and perform the pre-filling stage of the neural network model based on the model parameters in the second storage format (i.e., memory -> L2 -> UB -> vector unit -> UB -> L1 -> cube unit).

[0113] The vector unit can perform a generalized transpose by executing the `vnchwconv` instruction twice, achieving efficient conversion of the data storage format for model parameters to obtain a data storage format suitable for the first processor. Since the `vnchwconv` instruction's conversion method has low computational and bandwidth requirements for the vector unit, and the converted data can be directly loaded into the L1 cache of the cube unit, the additional computational and bandwidth consumption is extremely low. Therefore, the format conversion of neural network model parameters can be completed with virtually no increase in latency, achieving memory savings through model parameter reuse.

[0114] In some embodiments, the cache in the first processor 700 may further include a layer 0 buffer (L0 buffer) corresponding to the second computing unit 712. The model parameters of the second storage format obtained after format conversion may also be saved to the layer 0 buffer. The second computing unit 712 may read the model parameters of the second storage format from the layer 0 buffer and perform the pre-filling stage of the neural network model based on the model parameters of the second storage format.

[0115] In some embodiments, during the pre-filling stage of the neural network model, the first processor 700 may read model parameters in a first storage format from the memory of the computing device multiple times. Each time, a portion of the model parameters stored in memory is read. The model parameters read in different reads may be completely different or partially overlapping; this embodiment does not limit this. The model parameters in the first storage format read in different reads may be stored in different areas of the unified cache 722.

[0116] For example, as shown in FIG8, the unified cache 722 may include a first region, a second region, a third region, and a fourth region, which are four different storage regions. The unified cache 722 may also include more storage regions. Here, the first region, the second region, the third region, and the fourth region are used as an example for illustration. When reading model parameters of the first storage format from memory in two consecutive steps, the first processor 700 can save the model parameters of the first storage format read from memory in the first region of the unified cache 722. The first computing unit 711 can obtain the model parameters of the first storage format from the first region and perform format conversion on the model parameters of the first storage format to obtain the model parameters of the second storage format after the first format conversion. The first computing unit 711 can save the model parameters of the second storage format obtained from the first format conversion to the second region of the unified cache 722. While the first computing unit 711 obtains model parameters in a first storage format from the first region and performs format conversion on these parameters, the first processor 700 can read the model parameters in the first storage format from memory a second time. This second reading of the model parameters in the first storage format is then saved to the third region of the unified cache 722. After the first computing unit 711 completes the format conversion process for the first reading of the model parameters in the first storage format, it can obtain the model parameters in the first storage format from the third region and perform format conversion on them to obtain the model parameters in the second storage format after the second format conversion. The first computing unit 711 can then save the model parameters in the second storage format obtained from the second format conversion to the fourth region of the unified cache 722. Therefore, the processes of reading model parameters in the first storage format from memory and performing format conversion in two batches can be executed in parallel, thereby improving the efficiency of model parameter conversion. In other embodiments, more storage regions can be set in the unified cache 722 to achieve parallel execution of more batches of model parameter format conversion processes.

[0117] In the above embodiments, by setting up multiple different storage areas in the cache to save the model parameters required for different batches of model parameter format conversion and the converted model parameters, the multiple batches of model parameter format conversion processes can be executed in parallel, thereby improving the efficiency of model parameter conversion and model inference.

[0118] In another optional embodiment, the structure of the first processor can be as shown in FIG9. The first processor 900 may include a first computing unit 910 and a second computing unit 920. The first computing unit 910 may include a vector computing unit, also called a vector unit, used for vector calculations; the second computing unit 920 may include a matrix multiplication computing unit, also called a cube unit, used for matrix multiplication calculations. In addition to the first computing unit 910 and the second computing unit 920, the first processor 900 may also include a cache. Exemplarily, the cache may include a layer 1 cache 921, a unified cache 911, and a layer 2 cache 930. The layer 2 cache 930 is a shared cache space between the first computing unit 910 and the second computing unit 920, located outside the first computing unit 910 and the second computing unit 920, and connected to the layer 1 cache 921, the unified cache 911, the cube unit, and the vector unit via data transmission lines. The unified cache 911 is the cache space corresponding to the first computing unit 910, located inside the first computing unit 910, and connected to the vector unit via a data transmission line. Layer 1 cache 921 is the cache space corresponding to the second computing unit 920, located inside the second computing unit 920, and connected to the cube unit via a data transmission line. In Figure 9, the first computing unit 910 and the second computing unit 920 adopt an independent architecture, and both the first computing unit 910 and the second computing unit 920 can access the layer 2 cache 930.

[0119] The first processor 900 can be used to perform the pre-filling stage of the neural network model. Upon receiving a model inference request for the pre-filling stage, the first processor 900 can read partial model parameters of the neural network model from the memory of the electronic device based on the pre-filling stage model inference request, and process the read partial model parameters. The model parameters stored in memory are stored in a first storage format. The first processor 900 can save the read model parameters in the first storage format to a unified cache 911, or the first processor 900 can first save the read model parameters in the first storage format to a layer 2 cache 930, and then the layer 2 cache 930 saves them to the unified cache 911. The first computing unit 910 can perform format conversion on the model parameters in the first storage format in the unified cache 911. In other words, the vector unit in the first computing unit 910 can read the model parameters in the first storage format from the unified cache 911, perform format conversion on the model parameters in the first storage format, and save the converted model parameters in the second storage format back to the unified cache 911. Then, the unified cache 911 saves the parameters to the layer 2 cache 930, and finally to the layer 1 cache 921 of the second computing unit 920. The second computing unit 920 can perform a pre-filling stage of the neural network model based on the model parameters in the second storage format saved in the layer 1 cache 921. In other words, the cube unit of the second computing unit 920 can read the model parameters in the second storage format from the layer 1 cache 921 and perform a pre-filling stage of the neural network model based on the model parameters in the second storage format.

[0120] In a first processor where the first computing unit 910 and the second computing unit 920 employ an independent architecture, the loading path for model parameters includes: loading model parameters in a first storage format from memory into the L2 cache of the first processor 900, and then saving them from the L2 cache of the first processor 900 into a unified cache 911. The vector unit can obtain model parameters in the first storage format from the unified cache 911, perform format conversion on the model parameters in the first storage format, save the converted model parameters in the second storage format back into the unified cache 911, and then save them from the unified cache 911 to the layer 1 cache 921 via the layer 2 cache 930. The cube unit can read model parameters in the second storage format from the layer 1 cache 921 and perform the pre-filling stage of the neural network model based on the model parameters in the second storage format (i.e., memory -> L2 -> UB -> vector unit -> UB -> L2 -> L1 -> cube unit).

[0121] In some embodiments, the cache in the first processor 900 may further include a layer 0 cache corresponding to the second computing unit 920. The layer 0 cache may be located within the second computing unit 920 and connected to the cube unit via a data transmission line. Model parameters in the second storage format obtained after format conversion may also be saved to the layer 0 cache. The second computing unit 920 may perform the pre-filling stage of the neural network model based on the model parameters in the second storage format saved in the layer 0 cache.

[0122] Similarly, during the pre-filling stage of the neural network model, the first processor 900 can read model parameters in the first storage format from the memory of the computing device multiple times. Each time, it reads a portion of the model parameters stored in memory. The model parameters read in different reads can be completely different or partially overlapping; this embodiment does not limit this. The model parameters in the first storage format read in different reads can be stored in different areas of the unified cache 911. The storage area settings within the unified cache 911 can be implemented with reference to the unified cache 722 described above, and will not be repeated here.

[0123] The above embodiments are illustrated by the example of the first processor saving the model parameters of the first storage format to the unified cache of the first processor. In other embodiments, the first processor may also save the model parameters of the first storage format to other caches of the first processor. This application embodiment does not limit this.

[0124] The above embodiments are illustrated by taking the example of a first processor executing the pre-filling stage of the neural network model and a second processor executing the decoding stage of the neural network model. In other embodiments, the first processor may execute the decoding stage of the neural network model and the second processor may execute the pre-filling stage of the neural network model.

[0125] The above embodiments are illustrated using the example of a first processor reading model parameters of a first storage format from memory, that is, memory is used as the storage medium for description. In other embodiments, the storage medium may be other storage devices besides memory, and this application does not limit this.

[0126] This application also provides an electronic device, which may include a first processor and a second processor. The electronic device's storage medium stores model parameters of a neural network model in a first storage format, the first storage format being suitable for the second processor. The first processor is used to read the model parameters in the first storage format from the storage medium, convert the model parameters in the first storage format to obtain model parameters in a second storage format, and execute a first inference stage of the neural network model based on the model parameters in the second storage format. The second processor is used to execute a second inference stage of the neural network model based on the model parameters in the first storage format. This electronic device can be a computer or a server, such as a general-purpose computing server, a general-purpose storage server, or a data center server. It can also be a terminal device, such as a home appliance, a laptop, or a mobile phone. The structure of this electronic device can be as shown in Figure 1, and will not be described in detail here.

[0127] This application also provides a computer program product comprising computer-executable instructions. In one embodiment, the computer-executable instructions are used to cause a computer to perform the functions described in the method embodiments above.

[0128] Computer-executable instructions can be stored in a computer-readable storage medium. This application also provides a computer-readable storage medium storing executable instructions. In one embodiment, the computer-executable instructions are used to cause a computer to perform the functions described in the method embodiments above.

[0129] The computer-readable storage medium provided in the embodiments of this application may be random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), register, hard disk, portable hard disk, CD-ROM, or any other form of computer-readable storage medium known in the art.

[0130] Computer-executable instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. For example, the computer program or instructions can be transferred from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The computer-readable storage medium can be any available medium that a computer can access, or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium, such as a floppy disk, hard disk, or magnetic tape; it can also be an optical medium, such as a digital video disc (DVD); or it can be a semiconductor medium, such as a solid-state drive (SSD).

[0131] In the various embodiments of this application, unless otherwise specified or logically conflicting, the terminology and / or descriptions between different embodiments are consistent and can be referenced mutually. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, such as including a series of steps or units. A method, system, product, or device is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.

[0132] Although this application has been described in conjunction with specific features and embodiments, it is obvious that various modifications and combinations can be made thereto without departing from the spirit and scope of this application. Accordingly, this specification and drawings are merely illustrative examples of the solutions defined by the appended claims and are to be considered as covering any and all modifications, variations, combinations, or equivalents within the scope of this application. Obviously, those skilled in the art can make various alterations and modifications to this application without departing from the scope of this application. Thus, if these modifications and modifications to the embodiments of this application fall within the scope of the claims of this application and their equivalents, this application also intends to include these modifications and modifications.

Claims

1. An electronic device, comprising: The electronic device includes a first processor and a second processor; the storage medium of the electronic device stores model parameters of a neural network model in a first storage format; the first storage format is applicable to the second processor; The first processor is configured to read model parameters in the first storage format from the storage medium, convert the model parameters in the first storage format to obtain model parameters in the second storage format, and execute the first inference stage of the neural network model based on the model parameters in the second storage format. The second processor is used to execute the second inference phase of the neural network model based on the model parameters of the first storage format.

2. The electronic device of claim 1, wherein, The model parameters of the first storage format include an input matrix of A rows and B columns, the input matrix includes C×D sub-matrices, and each of the C×D sub-matrices includes E rows and F columns of elements; the model parameters of the second storage format include an output matrix of G rows and H columns, where A = C×E, B = D×F, G = C×D, and H = E×F.

3. The electronic device of claim 2, wherein, The G rows in the output matrix are determined based on the preset arrangement order of the C×D submatrices in the input matrix, and the elements in any row of the output matrix are obtained by expanding the E rows and F columns of the corresponding submatrix of the input matrix row by row.

4. The electronic device of claim 3, wherein, The input matrix includes C rows of submatrices, where each row includes D submatrices; the elements of two adjacent rows in the G rows of the output matrix are two adjacent submatrices in the same row of the input matrix, or the last submatrice in the first row and the first submatrice in the second row; the first row and the second row are two adjacent rows in the C rows.

5. The electronic device of claim 3 or 4, wherein, The term "e-row F-column elements expand row by row" means that the elements in each pair of adjacent rows in the E-row F-column elements are connected end to end.

6. The electronic device according to any one of claims 2 to 5, wherein The second processor is an in-memory computing PIM unit, the PIM unit includes the storage medium, the first processor includes a cache, the value of H is determined based on the number of columns in the cache, and the values ​​of E and F are determined based on the access granularity of the storage medium.

7. The electronic device according to any one of claims 2 to 6, characterized in that, The first processor is specifically used for: The model parameters in the first storage format are transformed by the first row and column axes to obtain the model parameters in the intermediate storage format; The model parameters in the intermediate storage format are transformed by the second row and column axis to obtain the model parameters in the second storage format.

8. The electronic device of claim 7, wherein, The first processor is specifically used for: Repeat the first step E times to obtain the model parameters of the intermediate storage format, which include E B-row C-column matrices. The first step includes: Select the elements in row C and column B from the elements in the input matrix that have not undergone row-column axis transformation; the distance between two adjacent rows in row C in the input matrix is ​​E; Perform a row and column axis transformation on the elements in row C and column B to obtain a matrix in row B and column C.

9. The electronic device of claim 7 or 8, wherein, The first processor is specifically used for: Repeat the second step D times to obtain the model parameters of the second storage format. The model parameters of the second storage format include D elements of C rows and E×F columns; wherein, D×C rows = G rows, and the elements of two adjacent rows in the G rows are obtained by executing the second step twice consecutively in the D times; the second step includes: E F-row, C-column matrices are selected sequentially from the elements in the model parameters of the intermediate storage format that have not undergone row and column axis transformation; the F rows are consecutive F rows, and the spacing between two adjacent F-row, C-column matrices is B; Perform row and column axis transformation on the elements of the E F-row C-column matrices to obtain C-row E×F-column elements; the E×F elements of each row in the C rows are the result of expanding the E-row F-column elements of the corresponding submatrix in the input matrix row by row, and the spacing between adjacent rows in the C rows is D.

10. The electronic device according to any one of claims 1 to 9, wherein The cache of the first processor includes a first region, a second region, a third region, and a fourth region; The first area is used to store a first part of model parameters, and the second area is used to store a second part of model parameters; the first part of model parameters are model parameters in a first storage format that are read from the storage medium for the first time. The second part of the model parameters are the model parameters of the second storage format obtained from the first format conversion; The third region is used to store the third part of the model parameters, and the fourth region is used to store the fourth part of the model parameters. The third part of the model parameters is the model parameters of the first storage format read from the storage medium for the second time; the fourth part of the model parameters is the model parameters of the second storage format obtained from the second format conversion.

11. The electronic device according to any one of claims 1 to 10, wherein The first inference stage is the pre-filling stage, and the second inference stage is the decoding stage.

12. A processor, comprising: The processor is a first processor, which includes a first computing unit and a second computing unit. The first computing unit is used to convert the model parameters in the first storage format to obtain the model parameters in the second storage format; the model parameters in the first storage format are model parameters of a neural network model read from the storage medium; the first storage format is suitable for the second processor. The second processor is used to execute the second inference phase of the neural network model; The second computing unit is used to perform the first inference phase of the neural network model based on the model parameters of the second storage format.

13. The processor according to claim 12, characterized in that, The first computing unit includes a vector unit, and the second computing unit includes a cube unit.

14. The processor of claim 12 or 13, wherein, The model parameters of the first storage format include an input matrix of A rows and B columns, the input matrix includes C×D sub-matrices, and each of the C×D sub-matrices includes E rows and F columns of elements; the model parameters of the second storage format include an output matrix of G rows and H columns, where A = C×E, B = D×F, G = C×D, and H = E×F.

15. The processor of any one of claims 12-14, wherein, The first computing unit is specifically used for: The model parameters in the first storage format are transformed along the first row and column axes to obtain the model parameters in the intermediate storage format. The model parameters in the intermediate storage format are transformed by the second row and column axis to obtain the model parameters in the second storage format.

16. A data processing method, characterized in that, The first processor is applied in an electronic device; the first processor is used to execute a first inference phase of a neural network model; the method includes: Read model parameters in a first storage format from the storage medium; the first storage format is suitable for a second processor in an electronic device; The second processor is used to execute the second inference phase of the neural network model; The model parameters in the first storage format are converted to obtain the model parameters in the second storage format; the second storage format is suitable for the first processor. The first inference phase is executed based on the model parameters in the second storage format.

17. The method of claim 16, wherein, The model parameters of the first storage format include an input matrix of A rows and B columns, the input matrix includes C×D sub-matrices, and each of the C×D sub-matrices includes E rows and F columns of elements; the model parameters of the second storage format include an output matrix of G rows and H columns, where A = C×E, B = D×F, G = C×D, and H = E×F.

18. The method according to claim 16 or 17, characterized in that, The step of converting the model parameters in the first storage format to obtain the model parameters in the second storage format includes: The model parameters in the first storage format are transformed along the first row and column axes to obtain the model parameters in the intermediate storage format. The model parameters in the intermediate storage format are transformed by the second row and column axis to obtain the model parameters in the second storage format.