Memory reuse method, memory reuse apparatus, device and storage medium

By utilizing memory reuse technology in artificial intelligence model training and controlling operators to transfer data between the first memory and the second memory, the problems of low memory utilization and data transmission efficiency in artificial intelligence model training are solved, and a more efficient implementation is achieved. High memory efficiency and training performance.

WO2024217506A1PCT designated stage expired Publication Date: 2024-10-24HUAWEI TECH CO LTD

Patent Information

Application Number
PCT/CN2024/088624
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-20
Filing Date
2024-04-18
Publication Date
2024-10-24

AI Technical Summary

Technical Problem

In the process of artificial intelligence model training, as the size of model parameters increases, training costs and memory requirements increase, resulting in low high-bandwidth memory utilization, affecting training performance, and the data transmission efficiency of traditional solutions is low, causing calculations to wait for data transmission and The computing efficiency of the host side CPU is not high.

Method used

By determining which data can be transferred from the first memory with high access speed to the second memory with low access speed before starting the first stage of artificial intelligence model training, and storing the data that needs to be used in the first memory, the control algorithm is used to Sub-implement data swap-in and swap-out, optimize memory reuse, improve high-bandwidth memory utilization, and reduce the impact on training performance.

Benefits of technology

Training AI models with larger parameter sizes in predetermined storage space improves high-bandwidth memory utilization, reduces the impact on training performance, and speeds up data processing efficiency and speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024088624_24102024_PF_FP_ABST
    Figure CN2024088624_24102024_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of artificial intelligence and provides a memory reuse method, a memory reuse apparatus, a device and a storage medium. The method comprises: before the start of a first stage in an artificial intelligence model training process, determining whether first data corresponding to a second stage in the artificial intelligence model training process has been transferred from a first memory of a computer to a second memory of the computer, the access speed of the first memory being higher than that of the second memory, and the first data being data which is not used in the first stage. The method further comprises: if it is determined that the first data has been transferred to the second memory, storing second data that needs to be used in the first stage into a storage area in the first memory for storing the first data. The embodiments of the present application can train in predetermined storage spaces artificial intelligence models having larger scales of parameters, thereby improving bandwidth memory utilization rates, and reducing effects on training performance.
Need to check novelty before this filing date? Find Prior Art

Description

Memory reuse method, memory reuse device, equipment and storage medium

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS

[0002] This application claims priority to the Chinese invention patent application with application number 202310463945.6, entitled "Memory reuse method, memory reuse device, equipment and storage medium" and filing date April 20, 2023, and incorporates the entire application into this document by reference. Technical Field

[0003] The embodiments of the present application primarily relate to the field of artificial intelligence. More specifically, the embodiments of the present application relate to a memory reuse method, a memory reuse apparatus, a device, and a storage medium. Background Art

[0004] With advances in computer technology, machine learning models, particularly artificial intelligence (AI) models, have rapidly developed. Machine learning models are now increasingly being applied to a wide range of fields to process complex information. For example, in the field of artificial intelligence (AI), AI models have gradually become the primary means of processing information.

[0005] With the development of AI model technology, the amount of data that needs to be processed is increasing, and the types of data are becoming increasingly complex, causing the structure of current AI models to evolve rapidly. In addition, as AI models grow in size, the scale of their parameters increases, and the training cost also increases. Therefore, there are still many problems that need to be solved in the calculation process of AI models.

[0006] Summary of the Invention

[0007] An embodiment of the present application provides a memory reuse solution.

[0008] According to a first aspect of the present application, a memory reuse method is provided. The method includes determining, before the start of the first stage in the artificial intelligence model training process, whether first data corresponding to the second stage in the artificial intelligence model training process has been transferred from a first memory of a computer to a second memory of the computer, where the access speed of the first memory is higher than the access speed of the second memory, and the first data is data that will not be used in the first stage. The method also includes, if it is determined that the first data has been transferred to the second memory, storing the second data required for the first stage in a storage area in the first memory used to store the first data.

[0009] In this way, data for the AI ​​model is swapped in and out between the first memory (with a high access speed) and the second memory (with a lower access speed) to reuse the storage area in the first memory, allowing the first memory to store as much data as possible. This allows AI models with larger parameter sizes to be trained within the reserved storage space, improving high-bandwidth memory utilization and minimizing the impact on training performance.

[0010] In some embodiments, where the first data is an optimizer parameter of a parameter optimizer used for training an AI model, and the second data is a tensor in the AI ​​model, the optimizer parameter is not used in the second phase where the tensor is used. This approach allows for rapid sharing of storage space between the optimizer parameter and the tensor, improving memory utilization.

[0011] In some embodiments, the method further includes modifying the storage area for storing optimizer parameters from static memory to dynamic memory. In this way, the state of the parameter storage area can be changed, thereby achieving memory reuse between parameters and tensors.

[0012] In some embodiments, the first data and the second data are tensors used at different stages in the artificial intelligence model training process. In this way, memory reuse between tensors can be achieved.

[0013] In some embodiments, determining whether the first data corresponding to the second stage of the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer includes: determining whether the first data corresponding to the second stage of the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer based on a memory reuse relationship between the first data and the second data, wherein the memory reuse relationship indicates that both the first data and the second data can use a storage area in the first memory. In this way, the reuse relationship can be used to quickly and accurately determine the transfer timing of the first data and the second data.

[0014] In some embodiments, the method further includes: determining a computational graph of the artificial intelligence model; and determining, based on the computational graph, a memory reuse relationship between the first data and the second data. In this way, the reuse relationship of data related to the model can be quickly and accurately determined.

[0015] In some embodiments, the method further includes: adding a plurality of control operators to the artificial intelligence model, wherein the plurality of control operators are used to control the transfer of data for the artificial intelligence model between the first memory and the second memory. In this way, the added control operators can accurately achieve data transfer.

[0016] In some embodiments, determining whether first data corresponding to the second stage of the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer includes: determining whether the first data is transferred from the first memory to the second memory at a first control operator among the plurality of control operators before the start of the first stage. In this way, the control operator can be used to achieve a complete transfer of the first data, thereby preventing the generation of dirty data for the first data.

[0017] In some embodiments, the method further includes: generating, at a second control operator among the plurality of control operators before the start of the first phase, first transfer information for transferring the first data from the first memory to the second memory; and storing the first transfer information as a queue element in a swap-out queue. In this manner, the swapping out of the first data can be accelerated.

[0018] In some embodiments, the method further includes: if a queue element including the first transfer information exists in the swap-out queue, transferring the first data from the first memory to the second memory based on the first transfer information. In this way, data transfer can be achieved quickly and accurately through queue processing.

[0019] In some embodiments, the method further includes: if the transfer of the first data to the second memory is not completed, waiting at the first control operator for completion of the transfer of the first data. In this way, the integrity of the data transfer can be guaranteed.

[0020] In some embodiments, the method further includes: determining, at a third control operator among the plurality of control operators after the first stage, whether the first data to be used has been transferred from the second memory to a storage area of ​​the first memory; and if the first data has been transferred to the storage area, using the first data to participate in training the artificial intelligence model. In this way, data can be quickly and accurately transferred to the first memory before use, avoiding data errors.

[0021] In some embodiments, the method further comprises: if the transfer of the first data to the storage area is not completed, waiting for the completion of the transfer of the first data. In this way, the complete transfer of data can be achieved and the accuracy of the data can be guaranteed.

[0022] In some embodiments, the method further includes: generating, at a fourth control operator among the plurality of control operators after the first stage, second transfer information for transferring the first data from the second memory to a storage area in the first memory; and storing the second transfer information as a queue element in an incoming queue. In this manner, incoming data can be processed in advance, thereby increasing data processing efficiency and speed.

[0023] In some embodiments, the method further includes: if a queue element including the second transfer information exists in the swap-in queue, transferring the first data from the second memory to the storage area based on the second transfer information. In this way, the data transfer process can be accelerated by queuing.

[0024] In some embodiments, the method is performed on a dedicated computing device, thereby speeding up the processing of the artificial intelligence model.

[0025] According to a second aspect of the present application, a memory reuse device is provided. The device includes: a data transfer determination unit configured to determine, before the start of the first stage in the artificial intelligence model training process, whether first data corresponding to the second stage in the artificial intelligence model training process has been transferred from a first memory of the computer to a second memory of the computer, where the access speed of the first memory is higher than the access speed of the second memory, and the first data is data that will not be used in the first stage; and a data transfer unit configured to, if it is determined that the first data has been transferred to the second memory, store the second data required for the first stage in a storage area in the first memory used to store the first data.

[0026] In some embodiments, where the first data is an optimizer parameter of a parameter optimizer used for training an artificial intelligence model, and the second data is a tensor in the artificial intelligence model, the optimizer parameter will not be used in the second stage where the tensor is used.

[0027] In some embodiments, the memory multiplexing device further includes: a parameter adjustment unit configured to modify the storage area for storing optimizer parameters from static memory to dynamic memory.

[0028] In some embodiments, the first data and the second data are tensors used in different stages of the artificial intelligence model training process.

[0029] In some embodiments, the data transfer determination unit includes: a transfer determination unit based on a reuse relationship, configured to determine whether the first data corresponding to the second stage of the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer based on the memory reuse relationship between the first data and the second data, wherein the memory reuse relationship indicates that both the first data and the second data can use the storage area in the first memory.

[0030] In some embodiments, the memory reuse device also includes: a computation graph determination unit, configured to determine the computation graph of the artificial intelligence model; and a memory reuse relationship determination unit, configured to determine the memory reuse relationship between the first data and the second data based on the computation graph.

[0031] In some embodiments, the memory multiplexing device also includes: an operator adding unit, configured to add multiple control operators to the artificial intelligence model, and the multiple control operators are used to control the transfer of data for the artificial intelligence model between the first memory and the second memory.

[0032] In some embodiments, the data transfer determination unit includes: a data transfer judgment unit configured to determine whether the first data is transferred from the first memory to the second memory at a first control operator among the plurality of control operators before the start of the first stage.

[0033] In some embodiments, the memory multiplexing device further includes: a first transfer information generation unit, configured to generate first transfer information for transferring the first data from the first memory to the second memory at a second control operator among multiple control operators before the start of the first stage; and a first storage unit, configured to store the first transfer information as a queue element in a swap-out queue.

[0034] In some embodiments, the memory multiplexing device further includes: a first execution unit configured to execute a transfer of the first data from the first memory to the second memory based on the first transfer information if a queue element including the first transfer information exists in the swap-out queue.

[0035] In some embodiments, the memory multiplexing device further includes: a first waiting unit configured to wait for completion of the transfer of the first data at the first control operator if the transfer of the first data to the second memory is not completed.

[0036] In some embodiments, the memory multiplexing device also includes: a transfer completion determination unit, configured to determine whether the first data to be used has been transferred from the second memory to the storage area of ​​the first memory at the third control operator among multiple control operators after the end of the first stage; and a using unit, configured to use the first data to participate in the training of the artificial intelligence model if the first data has been transferred to the storage area.

[0037] In some embodiments, the memory multiplexing device further includes: a second waiting unit configured to wait for completion of the transfer of the first data to the storage area if the transfer of the first data to the storage area is not completed.

[0038] In some embodiments, the memory multiplexing device further includes: a second transfer information generation unit, configured to generate second transfer information for transferring the first data from the second memory to a storage area in the first memory at a fourth control operator among the multiple control operators after the first stage ends; and a second storage unit, configured to store the second transfer information as a queue element in the swap-in queue.

[0039] In some embodiments, the memory multiplexing device further includes: a second execution unit configured to execute transfer of the first data from the second memory to the storage area based on the second transfer information if a queue element including the second transfer information exists in the swap-in queue.

[0040] In some embodiments, the memory multiplexing apparatus is in a dedicated computing device.

[0041] According to the third aspect of the present application, an electronic device is also provided, comprising: at least one computing unit; and at least one memory, wherein the at least one memory is coupled to the at least one computing unit and stores instructions for execution by the at least one computing unit, wherein the instructions, when executed by the at least one computing unit, enable the device to execute the method described in the first aspect of the present application.

[0042] According to a fourth aspect of the present application, a computer-readable storage medium is further provided, on which a computer program is stored. When the program is executed by a processor, the method according to the first aspect of the present application is implemented.

[0043] According to a fifth aspect of the present application, a computer program product is further provided, comprising computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, implement the method according to the first aspect of the present application.

[0044] It is understandable that the apparatus of the second aspect, the electronic device of the third aspect, the computer storage medium of the fourth aspect, or the computer program product of the fifth aspect provided above is used to execute the method provided in the first aspect. Therefore, the explanation or description of the first aspect also applies to the second, third, fourth, and fifth aspects. In addition, the beneficial effects that can be achieved in the second, third, fourth, and fifth aspects can be referred to the beneficial effects of the corresponding methods and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The above and other features, advantages and aspects of the embodiments of the present application will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0046] FIG1 is a schematic diagram illustrating an example environment in which various embodiments of the present application can be implemented;

[0047] FIG2 shows a schematic diagram of a hardware architecture diagram according to some embodiments of the present application;

[0048] FIG3 shows a schematic flow chart of a memory reuse method according to some embodiments of the present application;

[0049] FIG4 shows a schematic flow chart of an example implementation of a memory reuse method according to some embodiments of the present application;

[0050] FIG5 is a schematic diagram showing an example of a parameter and tensor multiplexing process according to some embodiments of the present application;

[0051] FIG6 shows a schematic diagram of an example range of a controlled tensor according to some embodiments of the present application;

[0052] FIG7 shows a schematic diagram of an example of parameter and tensor reuse according to some embodiments of the present application;

[0053] FIG8 is a schematic diagram showing an example of tensors and tensor reuse according to some embodiments of the present application;

[0054] FIG9 is a schematic diagram showing a tensor existence period according to some embodiments of the present application;

[0055] FIG10 shows a block diagram of an apparatus according to some embodiments of the present application; and

[0056] FIG11 illustrates a block diagram of a computing device capable of implementing various embodiments of the present application. DETAILED DESCRIPTION

[0057] The following describes embodiments of the present application in more detail with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are for illustrative purposes only and are not intended to limit the scope of protection of the present application.

[0058] In the description of the embodiments of this application, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to." The term "based on" should be understood as "based at least in part on." The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment." The terms "first," "second," etc. can refer to different or the same objects. Other explicit and implicit definitions may also be included below.

[0059] As mentioned above, with the evolution of artificial intelligence models, the parameters of artificial intelligence models are getting larger and larger. This makes how to use limited hardware resources to train models with larger parameter scales a current research focus. Currently, when training artificial intelligence models, tensors of artificial intelligence models and state parameters of optimizers used to optimize the parameters of artificial intelligence models are usually stored in high-bandwidth memories in dedicated computing devices, such as graphics processing units (GPUs) and neural network processors (NPUs). However, as artificial intelligence models become more and more complex, for example, the storage space of high-bandwidth memories used to store tensors and optimizer parameters is getting larger and larger. When the number of dedicated computing devices is limited, there is a situation where memory is insufficient in the training of large AI models. If the number of dedicated computing devices is increased, the cost and resource consumption will increase.

[0060] To address the above issues, some traditional solutions have proposed an offloading technique. In this technique, model training is divided into two processes: forward and backward propagation, which have high time complexity, and parameter update, which has low time complexity. The high-complexity forward and backward propagation calculations are retained on a dedicated computing device, while the low-complexity parameter update calculations are offloaded to the host's central processing unit (CPU). After completing forward and backward propagation, the dedicated computing device sends the calculated gradients to the CPU. The CPU uses the received gradients to update the model parameters and sends the updated parameters to the dedicated computing device. After receiving the new parameters, the dedicated computing device proceeds to the next iteration. Using mixed-precision training, the dedicated computing device can significantly reduce the storage overhead of the dedicated computing device and the communication time between the dedicated computing device and the CPU. However, even with this traditional solution, even with mixed-precision training, only low-precision data is transmitted between the host and the dedicated computing device. However, the efficiency of data transmission is still far lower than the computational efficiency of the dedicated computing device. This results in computation waiting for data transmission. Furthermore, while only the parameter update modules with low computational complexity are run on the host CPU, the CPU's computational efficiency is far lower than that of dedicated computing devices. This results in the dedicated computing devices waiting for the host CPU's calculation results. Furthermore, running parameter update calculations on the host CPU can affect the normal operation of other applications on the host.

[0061] In order to solve at least some of the above problems and other potential problems, in an embodiment of the present application, before the first stage of the artificial intelligence model training process begins, the computing device first determines whether the first data corresponding to the second stage of the artificial intelligence model training process has been transferred from the first memory of the computing device to the second memory of the computer. The access speed of the first memory is higher than the access speed of the second memory, and the first data is data that will not be used in the first stage. If it is determined that the first data has been transferred to the second memory, the computing device stores the second data needed for the first stage in the storage area of ​​the first memory used to store the first data. In this way, the storage area in the first memory is reused by swapping in or out data for the artificial intelligence model between the first memory with a high access speed and the second memory with a low access speed, so that as much data currently needed as possible is stored in the first memory. Therefore, when training the artificial intelligence model, an artificial intelligence model with a larger parameter scale can be trained in the predetermined storage space, which improves the utilization of high-bandwidth memory and reduces the impact on training performance.

[0062] FIG1 shows a schematic diagram of an example environment 100 in which multiple embodiments of the present application can be implemented. As shown in FIG1 , the example environment 100 includes a computing device 102. In some embodiments, the computing device 102 is a dedicated computing device that can be used to train an artificial intelligence model, such as an NPU device or a GPU device. In some embodiments, the computing device 104 is a host device that includes an NPU device or a GPU device. In some embodiments, the computing device 104 includes, but is not limited to, an in-vehicle computing device, a personal computer, a server, a handheld or laptop device, a mobile device, a multi-processor system, a consumer electronic product, a minicomputer, a mainframe computer, a distributed computing environment including any of the above systems or devices, and the like.

[0063] As shown in Figure 1, computing device 102 includes a processor 104, memory 106, and memory 112. For ease of description, memory 106 is also referred to as the first memory, and memory 112 is also referred to as the second memory. The access speed of first memory 106 is higher than the access speed of second memory 112, or the data bandwidth of first memory 106 is higher than the data bandwidth of second memory 112. For example, the first memory is high-bandwidth memory (HBM), and the second memory is low-bandwidth memory, such as double data rate synchronous dynamic random access memory (DDR SDRAM). In one example, when computing device 102 is a dedicated computing device, first memory 106 and second memory 112 are both located on the dedicated computing device. In another example, when computing device 102 is a host device including a dedicated computing device, the first memory can be located on the dedicated computing device, and the second memory can be located on the dedicated computing device or the host device. The above examples are merely used to illustrate the present disclosure and are not specific limitations of the present disclosure. Those skilled in the art can arrange the first memory and the second memory as needed.

[0064] According to the method disclosed herein, some control operators are typically inserted into the AI ​​model to be trained. These control operators are used to control tensors of the AI ​​model or state parameters of a parameter optimizer of the AI ​​model, and perform swapping operations between the first memory 106 and the second memory 112 to facilitate memory reuse.

[0065] When using computing device 102 to train an AI model with added control operators, for example, training an AI model with added control operators, computing device 102 compiles the AI ​​model according to a static graph AI framework. After compilation, computing device 102 analyzes the AI ​​model's computational graph to obtain the execution timing of all operators in the AI ​​model and the lifetime or lifecycle of all tensors during execution. Based on the operator execution timing, the lifetime or lifecycle of tensors or state parameters, and the size of the tensors or state parameters, it is possible to determine which tensors or state parameters can reuse the same storage area of ​​the first memory. For example, the reuse relationship between state parameters and tensors and / or between tensors can be determined. As shown in Figure 1, computing device 102 determines that first data 114 and second data 110 for the AI ​​model have a reuse relationship and can share the same storage area 108 when training the AI ​​model. The first data 114 has a long lifetime, but is not used by the AI ​​model during a subperiod of the lifetime, while the second data is used by the AI ​​model during that subperiod. Therefore, the first data 114 only needs to be transferred to the second memory 112 before the second data is used, so that the storage area 108 in the first memory used to store the first data can be used to store the second data. Then, after the second data is used, it can be transferred from the second memory to the storage area 108 in the first memory before the first data 114 is used, so that the calculation of the artificial intelligence model can be realized by reusing the memory.

[0066] This approach leverages the identified data reuse relationship to swap machine model data between the high-access-speed first memory and the low-access-speed second memory, allowing the first memory to store as much of the currently needed data as possible. This allows AI models with larger parameter sizes to be trained within the reserved storage space, improving high-bandwidth memory utilization and minimizing the impact on training performance.

[0067] The above, in conjunction with Figure 1, describes a schematic diagram of an example environment 100 in which an embodiment of the present application can be implemented. The following, in conjunction with Figure 2, describes a schematic diagram of a hardware architecture diagram according to some embodiments of the present application. The present invention can be used in all static graph mode training scenarios, including but not limited to Tensorflow, Pytorch, and MindSpore training frameworks. Figure 2 shows the corresponding hardware architecture. As shown in Figure 2, the example 200 of the hardware architecture includes a device 202 and a host 204.

[0068] Device 202 is a dedicated computing device, which in Figure 2 is an NPU device, used for training and inference of artificial intelligence models. Device 202 includes a device operating system 210 for controlling the operation of device 202. Device 202 also includes an NPU 206 and an NPU driver 208. NPU 206 includes NPU firmware. For example, NPU 206 can be an AI processor that connects to host 204 via a fast Peripheral Component Interconnect Express (PCIe) interface to provide neural network (NN) computing capabilities to the host. For example, host 204 can be an X86 server or ARM server equipped with an AI processor (NPU), which uses the NN computing capabilities provided by the AI ​​processor to complete business operations; host 204 is used to provide artificial intelligence models for training to device 202. Host 204 includes a host operating system 218 and an NPU driver 216. Furthermore, host 204 includes a first module 212 for managing AI models and a second module 214 for managing AI models. The first module 212 includes an AI model, an AI framework, and a Compute Architecture for Neural Networks (CANN). The AI ​​model uses the application programming interface (API) provided by the AI ​​framework to build an AI model, such as ResNet and BERT. The AI ​​framework provides an interface for building the AI ​​model and automatically trains the AI ​​model (performing reverse derivation and approximating the optimal value) to obtain the AI ​​model parameters. The second module 214 is a virtual container used to provide AI model training using the virtual container.

[0069] A schematic diagram of a hardware architecture diagram of an embodiment of the present application is described above in conjunction with FIG2 . A schematic flow chart of an example 300 of a memory reuse method according to some embodiments of the present application is described below in conjunction with FIG3 . Process 300 can be executed at computing device 102 in FIG1 or any other suitable computing device.

[0070] At block 302, before the start of the first stage in the artificial intelligence model training process, it is determined whether first data corresponding to the second stage in the artificial intelligence model training process has been transferred from a first memory of a computer to a second memory of the computer. The first memory has an access speed higher than an access speed of the second memory, and the first data is data that will not be used in the first stage. When training the artificial intelligence model, if the first data used in the second stage in the artificial intelligence model training process is no longer used in the first stage in the artificial intelligence model training process, in order to reuse the memory, it is necessary to determine whether the first data has been transferred from the first memory of the computer to the second memory of the computer before the start of the first stage.

[0071] In some embodiments, the first data is an optimizer parameter of a parameter optimizer used for training an artificial intelligence model, and the second data is a tensor in the artificial intelligence model. The optimizer parameter will not be used in the second phase in which the tensor is used. For example, in each round of training during the artificial intelligence model training process, since the optimizer parameter is only used when updating the parameters of the artificial intelligence model after the calculation of the artificial intelligence model in that round is completed, the tensor of the artificial intelligence model is used during the calculation of the artificial intelligence model. Therefore, the optimizer parameter and the tensor of the artificial intelligence model can reuse the storage space of the first memory. In each round of training of the artificial intelligence model, the optimizer parameter is transferred from the first memory to the second memory before the tensor is used.

[0072] In some embodiments, in order to allow the optimizer parameters to reuse memory with tensors, the storage area used to store the optimizer parameters is usually modified from static memory to dynamic memory. Since the optimizer parameters will be used during the entire training process of the artificial intelligence model, static memory space is usually allocated for them when allocating storage space for the optimizer parameters. However, if static memory space is allocated, it will not be able to share memory space with tensors. In order to achieve this shared memory space between the optimizer parameters and tensors, the storage space of the optimizer parameters needs to be modified from static memory to dynamic memory.

[0073] In some embodiments, the first data and the second data are tensors used in different stages of the artificial intelligence model training process. Since the tensors in the artificial intelligence model have different existence periods, the tensors in the artificial intelligence model can be memory reused. When the first data as a tensor is not used in the first stage, it can be transferred to the second memory to be used by the second data as a tensor in the first stage.

[0074] In some embodiments, the computing device determines whether the first data corresponding to the second stage of the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer based on the memory reuse relationship between the first data and the second data. The memory reuse relationship indicates that both the first data and the second data can use the storage area in the first memory. In order to reuse memory, it is necessary to first determine the reuse relationship between the data related to the artificial intelligence model. For example, determine the reuse relationship between the state parameters of the optimizer used to optimize the parameters of the artificial intelligence model and the tensors of the artificial intelligence model, and / or determine the reuse relationship between the tensors of the artificial intelligence model.

[0075] In some embodiments, when determining the reuse relationship, the computing device analyzes the artificial intelligence model to determine the computational graph of the artificial intelligence model. Then, the computing device determines the memory reuse relationship of different data based on the computational graph. For example, based on the computational graph, the computing device can determine the existence period of data related to the artificial intelligence model, such as the existence period of tensors and optimizer parameters, that is, the time period in which the tensors and optimizer parameters are used or between which operators in the ordered operator are used. Then, the computing device further determines the reuse relationship between the first data and the second data based on the existence period of multiple data and the size of multiple data. In one example, the computing device uses a commonly used memory management algorithm to implement memory arrangement based on the existence period of multiple data and the size of multiple data, thereby determining the reuse pairs between the data. For example, a PT reuse pair between a state parameter (P) and a tensor (T) is determined, or a TT reuse pair between a tensor (T) and a tensor (T). In some embodiments, the computing device can determine the reuse relationship between the data used for the artificial intelligence model in any suitable manner based on needs.

[0076] At block 304, if it is determined that the first data has been transferred to the second memory, the second data required for use in the first phase is stored in the storage area of ​​the first memory used to store the first data. For example, if the computing device 102 determines that the first data in the storage area of ​​the first memory has been transferred to the second memory, the second data in the first phase of the artificial intelligence model can be stored in the storage area of ​​the first memory to ensure training of the artificial intelligence model.

[0077] In some embodiments, before determining the reuse relationship between the data of the artificial intelligence model, the computing device adds multiple control operators to the artificial intelligence model during the artificial intelligence model editing stage. For example, the control operator is an operator Swapmarker, ParaSwapmarker, etc. that swaps in or out tensors and state parameters (Parameters) of the optimizer. The above examples are only used to describe the present disclosure, not to specifically limit the present disclosure. The control operator can be set to any suitable form. Each of the multiple control operators is used to control the transfer of data for the artificial intelligence model between the first memory and the second memory.

[0078] In some embodiments, when determining whether the first data corresponding to the second stage of the artificial intelligence model training process has been transferred from the first memory of the computer to the second memory of the computer, the computing device generally uses the first control operator among the multiple control operators inserted into the artificial intelligence model to determine whether the first data has been transferred to the second memory. This operator is the last control operator before the start of the first stage. If the transfer of the first data to the second memory is not completed, the control operator waits for the completion of the transfer of the first data. This ensures that before the second data is generated, the first data in the storage area used by it has been completely transferred to the second memory.

[0079] Furthermore, before the start of the first phase, the computing device generates, at a second control operator among the plurality of control operators, first transfer information for transferring the first data from the storage area to the second memory. The computing device then stores the first transfer information as a queue element in a swap-out queue. In one example, the second control operator and the first control operator can be the same control operator. For example, if there is only one control operator before the start of the first phase, the control operator needs to place the first transfer information for transferring the first data from the storage area to the second memory in the swap-out queue for execution and also needs to control the completion of the transfer of the first data. In another example, the second control operator and the first control operator can be different control operators. For example, if there are at least two control operators before the start of the first phase, the control operator closest to the start of the first phase controls the completion of the transfer of the first data, while the operator preceding the control operator can preemptively place the first transfer information for transferring the first data from the storage area to the second memory in the swap-out queue for execution. Alternatively, or in addition, the priority of the first transfer information in the swap-out queue can be dynamically adjusted at the first control operator before the start of the first phase to expedite processing of the first transfer information. For example, if the information in the corresponding output queue at the last operator before the start of the first phase has not been processed, the priority of the corresponding output information in the output queue can be increased to ensure that the output of the first data is processed in a timely manner. The above examples are only used to illustrate the present disclosure and are not intended to limit the present disclosure.

[0080] In some embodiments, a swap-in / swap-out process in a computing device checks whether a swap-out queue contains a queue element with transfer information that needs to be processed. If a queue element containing the first transfer information exists in the swap-out queue, the process executes a transfer of the first data from the storage area to the second memory according to the first transfer information. Furthermore, the elements in the swap-out queue may have priorities and be sorted based on the priorities.

[0081] If the transfer of the first data to the second memory is not completed, wait for the completion of the transfer of the first data. If the first data has been transferred to the second memory, store the second data in the storage area of ​​the first memory after the first stage starts, so as to use the second data in the subsequent training of the artificial intelligence model during the process of the artificial intelligence model.

[0082] In some embodiments, after the first stage ends, at a third control operator among the plurality of control operators, the computing device determines whether the first data to be used has been transferred from the second memory to the storage area. If the first data has been transferred to the storage area, the first data is used to participate in training the artificial intelligence model.

[0083] In some embodiments, at a fourth control operator among multiple control operators after the first stage, the computing device may generate second transfer information for transferring the first data from the second memory to the storage area, and then store the second transfer information as a queue element in the swap-in queue. In one example, the third and fourth control operators are identical. For example, if there is only one control operator after the first stage and before the first data is used, that control operator must at least execute the operation of storing the second transfer information as a queue element in the swap-in queue and also determine whether the first data to be used has been transferred from the second memory to the storage area. In another example, the third and fourth control operators are different, for example, the fourth operator precedes the third operator. Therefore, the second transfer information can be placed in the swap-in queue in advance for swap-in processing. Similar to the swap-out queue, the swap-in queue can also be adjusted based on priority. Therefore, at the last operator before the first data to be swapped in, the priority of the second transfer information for that first data can be dynamically adjusted to ensure timely processing of the first data.

[0084] In some embodiments, the swap-in / swap-out process in the computing device checks whether there is a queue element including the transfer information in the swap-in queue. If there is a queue element including the second transfer information in the swap-in queue, the computing device performs the transfer of the first data from the second memory to the storage area using the second transfer information.

[0085] Alternatively or additionally, the method may be executed in a dedicated computing device, such as an NPU device or a GPU device.

[0086] In this way, data for the AI ​​model is swapped in and out between the first memory (with a high access speed) and the second memory (with a lower access speed) to reuse the storage area in the first memory, allowing the first memory to store as much data as possible. This allows AI models with larger parameter sizes to be trained within the reserved storage space, improving high-bandwidth memory utilization and minimizing the impact on training performance.

[0087] A schematic flowchart of a memory reuse method according to some embodiments of the present application is described above in conjunction with FIG3 . A schematic flowchart of an example implementation of a memory reuse method according to some embodiments of the present application is described below in conjunction with FIG4 . Process 400 can be performed at computing device 102 in FIG1 or any other suitable computing device.

[0088] At block 402 , a model training script is provided that introduces control operators for controlling state parameters of tensors and optimizers, such as SwapMarker and ParamSwapMarker operators for tensor transfer and optimizer parameter transfer, respectively.

[0089] At block 404, specifically, model training is started in a child thread, graph compilation and optimization are performed, and the memory reuse relationship between tensors and tensors, as well as between tensors and state parameters, is calculated based on the tensor lifecycle in the static graph and the execution order of control operators such as SwapMarker and ParamSwapMarker. This memory reuse and swap-in and swap-out metadata information is copied to the NPU. For example, the metadata information includes the reuse mapping relationship between state parameters and tensors, or between tensors and tensors, as well as information such as the existence period or lifecycle of tensors or parameters. Specifically, the operation of block 404 includes: at block 410, AI model graph compilation and optimization are performed. At block 412, the TT reuse and PT reuse relationship is calculated based on the operator lifecycle in the entire graph. At block 414, the PT reuse and TT reuse metadata information is copied to the NPU memory. At block 416, graph execution is performed (looped multiple times). Then, at block 418, training ends. In addition, after the AI ​​model graph is compiled and optimized, it is necessary to start the memory swap-in and swap-out threads in the training script at box 408, and loop to extract tensors or state parameters from the swap-in / swap-out queue to perform memory swap-in / swap-out operations. Specifically, at box 420, the automatic memory swap swap-in / swap-out graph (thread or process) is started, and then at box 422, the memory swap-in / swap-out is looped. At box 424, the training ends and exits. This process also requires the use of the swap-out queue 438 and the swap-in queue 440. The memory swap-in and swap-out loop in box 422 includes executing a swap-out action or a swap-in action at box 444 based on the check results in the swap-out queue and the swap-in queue 440. Then, at box 446, a direct memory access (DMA) data copy operation is performed. After the data is transferred, at box 442, it is confirmed whether the training is complete. If not, the swap-in queue and the swap-out queue are further checked. If the training is complete, the swap-in / swap-out process is terminated. For the graph execution in box 416, whenever a control operator is executed, such as the SwapMarker operator inserted during forward propagation of tensors, the SwapMarkerGrad operator inserted during backward propagation, and the ParamSwapMarker operator inserted for parameter updates, it places the tensors or state parameters to be swapped in and out into the swap-in and swap-out queues based on the reused metadata information; and waits until the subsequent tensors to be shared memory have been swapped out, and then waits for the swapped-out data to complete the swap-in operation. Specifically, the process includes, at box 426, executing other operators. At box 428, executing control operators, such as SwapMarker, SwapMarkerGrad, and ParamSwapMarker operators. Then, at box 430, the tensor and parameter metadata information that needs to be unloaded by each control operator is loaded (executed when the first control operator is executed). At box 432, the tensors and parameter information that need to be swapped in / out are placed in the swap-in / swap-out queue.At block 434 , a check is performed to see if the tensors or parameters required by subsequent operators to share memory have been swapped in or out. At block 436 , other operators are executed.

[0090] In this way, data for the AI ​​model is swapped in and out between the first memory (with a high access speed) and the second memory (with a lower access speed) to reuse the storage area in the first memory, allowing the first memory to store as much data as possible. This allows AI models with larger parameter sizes to be trained within the reserved storage space, improving high-bandwidth memory utilization and minimizing the impact on training performance.

[0091] The above is a schematic flow chart of an example implementation of a memory reuse method according to some embodiments of the present application, described in conjunction with Figure 4. The following describes an example of parameter and tensor reuse in conjunction with Figures 5, 6, and 7. Specifically, Figure 5 shows a schematic diagram of an example of a parameter and tensor reuse process according to some embodiments of the present application; Figure 6 shows a schematic diagram of an example range of controlled tensors according to some embodiments of the present application; and Figure 7 shows a schematic diagram of an example of parameter and tensor reuse according to some embodiments of the present application. The artificial intelligence model can be a neural network model.

[0092] For example, large AI models can usually be trained using optimizers, such as the Adam optimizer. In addition to the weight parameters in the network, the optimizer also needs to save many state parameters, such as Adam_m and Adam_v of the Adam optimizer. The number of these parameters is twice that of the weight parameters. Like the weight parameters, the state parameters in the optimizer are also iterative parameters. The update of the state parameters of the current step will use the state parameters of the previous step. Therefore, the state parameters in the optimizer have a global life cycle from the beginning to the end of training. The current mainstream AI training framework will allocate an exclusive memory area for it. As shown in Figure 5, at box 502, memory allocation is first performed. Then, at box 504, the optimizer state parameters are swapped in / out. At box 506, the parameters are updated. Specifically, to achieve memory reuse between optimizer state parameters and normal tensors, at block 508, the storage area for the optimizer state parameters is modified from static memory to dynamic memory. Specifically, the static memory area of ​​each data-exclusive memory is adjusted to a dynamic memory area, allowing the optimizer state parameters to be reused with the normal tensors used in the neural network forward propagation in the dynamic memory. Then, at block 510, the memory reuse relationship is calculated: based on information such as the lifecycle of the optimizer state parameters and the tensor data generated by the neural network forward / backward propagation, the memory reuse relationship between the data is calculated. Specifically, the reuse relationship between the optimizer state parameters and normal tensors is calculated based on the actual lifecycle of the optimizer state parameters in a step, the lifecycle of normal tensors in the neural network, and the control range of the inserted swap-in / swap-out operators. As shown in Figure 6, the control operator marker0 is the first swap-out operator inserted during the neural network forward propagation, and the control operator marker_grad0 is the last swap-in operator inserted during the neural network backward propagation. Tensors with a lifecycle between these two operators are considered to be within the control range. Furthermore, the optimizer state parameters are only used during the parameter update phase, and their actual lifecycle in a step does not overlap with the tensors within the control range. Therefore, the optimizer state parameters can implement memory reuse with these controlled tensors, with swapping in / out. Finally, memory arrangement is performed based on the reuse relationship between the optimizer state parameters and normal tensors and their data size. After memory arrangement, the optimizer state parameters and normal tensors with memory overlap are treated as PT reuse pairs, and data swapping in and out is subsequently managed based on the PT reuse pairs.

[0093] Returning to Figure 5 , the optimizer parameter swapping operation is described. Based on the determined PT reuse pairs, the optimizer state parameter's actual lifetime in each step and the lifetime of the reused tensor are used to manage swapping in / out parameters. In block 512 , this parameter swapping operation includes swapping out the optimizer state parameter: during the neural network forward propagation, before the first tensor reused by a particular optimizer state parameter is generated, the optimizer state parameter is swapped out.

[0094] As shown in Figure 7, state parameter P1 reuses the memory of tensors T1 and T2. P1's lifecycle is 2687–2689, T1's lifecycle is 225–1457, and T2's lifecycle is 350–1602. Before each neural network step, the optimizer state parameters from the previous step remain in memory and are used during the parameter update phase of the current step. Therefore, their data must be protected from contamination. For P1, T1 is generated first among the tensors it reuses, and this tensor will be generated at the 225th operator node in the neural network. Therefore, P1 must be swapped out of memory before this operator node. Specifically, marker 1, the last control operator before the 225th operator node, must be used to check whether P1 has been swapped out. If not, wait for its completion. To improve execution efficiency, if there are control operators before the one that has been checked for swapping out, the parameter will be swapped out starting at the control operator immediately preceding the one that has been checked for swapping out. This means that P1 will be placed in the swap-out queue by marker 0 and begin swapping out.

[0095] Returning to Figure 5 for further description, the optimizer parameter swapping in / out operation also includes swapping in optimizer state parameters in block 514: During the neural network backpropagation, after the last tensor reused by a particular optimizer state parameter is used, this optimizer parameter is swapped in, ensuring that swapping in is completed before the parameter is updated. Specifically, during the parameter update phase, the optimizer state parameter will be used, so it must be completely swapped into memory before it is used. To prevent data from being trampled on tensors that reuse memory with it, it must be swapped into memory only after all tensors that reuse memory with it have been used. For P1, T2 is the last of the tensors reused with it to be used. This tensor will be used by the 1602th operator node in the neural network. Therefore, P1 must be swapped into memory after this operator node, meaning that P1 can only be swapped into the control operator node after the 1602th operator node. To improve execution efficiency, P1 should be placed in the swap-in queue as early as possible, meaning that the swap-in operation for P1 should begin with the first control operator marker_grad1 after the 1602th operator node. To ensure the integrity of the optimizer's state parameters during the parameter update phase, the last control operator before the parameter update, marker_grad0, must check whether P1 has been swapped in. If not, wait for its completion. The reuse relationship between P2 and T3 and T4 is the same as the reuse relationship between P1 and T1 and T2. P2 is swapped out to the secondary memory before T3 is generated and swapped into the primary memory after T3 completes.

[0096] The examples of parameter and tensor multiplexing described above in conjunction with Figures 5, 6, and 7 are described. The following examples of TT multiplexing between tensors are described in conjunction with Figures 8 and 9. Specifically, Figure 8 shows a schematic diagram of an example of tensor and tensor multiplexing according to some embodiments of the present application; Figure 9 shows a schematic diagram of a tensor existence period according to some embodiments of the present application.

[0097] In existing training frameworks, tensor memory reuse prevents memory stampede by requiring only tensor data with non-overlapping lifecycles. As shown in Figure 8, T1 and T3 can share memory because T1 has already been used by the time T3 is generated, preventing data stampede. However, T1 and T2 cannot share memory because if they do, T2 will overwrite T1's data when the 160th operator is generated, contaminating T1's data by the time the 200th operator is used.

[0098] For most AI models, especially language models using transformer structures, their forward propagation and back propagation are usually symmetrical. As shown in Figure 9, during forward propagation, the model first generates data T1, and then generates T2 to Tn in sequence; during back propagation, the model will first use Tn, and then use Tn-1 to T1 in sequence. In order to achieve memory reuse between T1, T2 to Tn, the present invention inserts a control operator for data swapping out between the tensors of forward propagation, and automatically inserts a control operator for data swapping in during back propagation based on the inserted control operator.

[0099] As shown in Figure 9, during forward propagation, T1 is generated before the control operator marker1 and is not used again until the control operator marker_grad1. Therefore, the control operator marker1 can be used to swap T1 out of memory. T2, generated after the control operator marker1, can then use the memory occupied by T1. Similarly, T2 through Tn can reuse T1's memory in sequence. During backward propagation, Tn is used up before the control operator marker_grad(n-1). Therefore, the control operator marker_grad(n-1) can be used to swap Tn-1 into the memory occupied by Tn. After Tn-1 is used up, the corresponding control operator marker_grad can be used to swap Tn-2 through T1 into memory in sequence. Therefore, using this swap-in / swap-out strategy enables memory reuse between tensors with overlapping lifecycles.

[0100] FIG10 further shows a block diagram of a memory reuse apparatus 1000 according to an embodiment of the present application. The apparatus 1000 is applied to a computing device and may include multiple modules for executing corresponding steps in the process 300 discussed in FIG3 . As shown in FIG10 , the apparatus 1000 includes: a data transfer determination unit 1002, configured to determine, before the start of the first stage in the artificial intelligence model training process, whether first data corresponding to the second stage in the artificial intelligence model training process has been transferred from the first memory of the computer to the second memory of the computer, where the access speed of the first memory is higher than the access speed of the second memory, and the first data is data that will not be used in the first stage; and a data transfer unit 1004, configured to store the second data needed for the first stage in the storage area in the first memory for storing the first data if it is determined that the first data has been transferred to the second memory.

[0101] In some embodiments, where the first data is an optimizer parameter of a parameter optimizer used for training an artificial intelligence model, and the second data is a tensor in the artificial intelligence model, the optimizer parameter will not be used in the second stage where the tensor is used.

[0102] In some embodiments, the memory multiplexing device further includes: a parameter adjustment unit configured to modify the storage area for storing optimizer parameters from static memory to dynamic memory.

[0103] In some embodiments, the first data and the second data are tensors used in different stages of the artificial intelligence model training process.

[0104] In some embodiments, the data transfer determination unit 1002 includes: a transfer determination unit based on a reuse relationship, configured to determine whether the first data corresponding to the second stage in the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer based on the memory reuse relationship between the first data and the second data, wherein the memory reuse relationship indicates that both the first data and the second data can use the storage area in the first memory.

[0105] In some embodiments, the memory reuse device 1000 also includes: a computation graph determination unit, configured to determine the computation graph of the artificial intelligence model; and a memory reuse relationship determination unit, configured to determine the memory reuse relationship between the first data and the second data based on the computation graph.

[0106] In some embodiments, the memory multiplexing device 1000 further includes: an operator adding unit, configured to add multiple control operators to the artificial intelligence model, and the multiple control operators are used to control the transfer of data for the artificial intelligence model between the first memory and the second memory.

[0107] In some embodiments, the data transfer determination unit 1002 includes: a data transfer determination unit configured to determine whether the first data is transferred from the first memory to the second memory at a first control operator among multiple control operators before the start of the first stage.

[0108] In some embodiments, the memory multiplexing device 1000 further includes: a first transfer information generation unit, configured to generate first transfer information for transferring the first data from the first memory to the second memory at a second control operator among multiple control operators before the start of the first stage; and a first storage unit, configured to store the first transfer information as a queue element in a swap-out queue.

[0109] In some embodiments, the memory multiplexing device 1000 further includes: a first execution unit configured to execute transfer of the first data from the first memory to the second memory based on the first transfer information if a queue element including the first transfer information exists in the swap-out queue.

[0110] In some embodiments, the memory multiplexing apparatus 1000 further includes: a first waiting unit configured to wait for completion of the transfer of the first data at the first control operator if the transfer of the first data to the second memory is not completed.

[0111] In some embodiments, the memory multiplexing device 1000 also includes: a transfer completion determination unit, configured to determine whether the first data to be used has been transferred from the second memory to the storage area of ​​the first memory at the third control operator among multiple control operators after the end of the first stage; and a using unit, configured to use the first data to participate in the training of the artificial intelligence model if the first data has been transferred to the storage area.

[0112] In some embodiments, the memory multiplexing device 1000 further includes: a second waiting unit configured to wait for completion of the transfer of the first data if the transfer of the first data to the storage area is not completed.

[0113] In some embodiments, the memory multiplexing device 1000 further includes: a second transfer information generation unit, configured to generate second transfer information for transferring the first data from the second memory to a storage area in the first memory at a fourth control operator among the multiple control operators after the first stage ends; and a second storage unit, configured to store the second transfer information as a queue element in the swap-in queue.

[0114] In some embodiments, the memory multiplexing device 1000 further includes: a second execution unit configured to execute transfer of the first data from the second memory to the storage area based on the second transfer information if a queue element including the second transfer information exists in the swap-in queue.

[0115] In some embodiments, the memory multiplexing apparatus 1000 is in a dedicated computing device.

[0116] Figure 11 shows a schematic block diagram of an example device 1100 that can be used to implement an embodiment of the present application. For example, the computing device 102 in Figure 1 according to an embodiment of the present application and the device 202 and host 204 in Figure 2 can all be implemented by example device 1100. As shown in the figure, device 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to the computer program instructions stored in a read-only memory (ROM) 1102 or the computer program instructions loaded into a random access memory (RAM) 1103 from a storage unit 1108. In RAM 1103, various programs and data required for the operation of device 1100 can also be stored. CPU 1101, ROM 1102, and RAM 1103 are connected to each other by bus 1104. Input / output (I / O) interface 1105 is also connected to bus 1104.

[0117] Various components in device 1100 are connected to I / O interface 1105, including an input unit 1106, such as a keyboard and mouse; an output unit 1107, such as various types of displays and speakers; a storage unit 1108, such as a magnetic disk and optical disk; and a communication unit 1109, such as a network card, a modem, a wireless communication transceiver, etc. Communication unit 1109 allows device 1100 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0118] The various processes and processing described above, such as methods 300 and 400, may be performed by the processing unit 1101. For example, in some embodiments, methods 300 and 400 may be implemented as a computer software program that is tangibly embodied in a machine-readable medium, such as the storage unit 1108. In some embodiments, part or all of the computer program may be loaded and / or installed onto the device 1100 via the ROM 1102 and / or the communication unit 1109. When the computer program is loaded into the RAM 1103 and executed by the CPU 1101, one or more actions of the methods 300 and 400 described above may be performed.

[0119] The present application may include a method, apparatus, system, chip, and / or computer program product. The chip may include a processing unit and a communication interface, and the processing unit may process program instructions received from the communication interface. The computer program product may include a computer-readable storage medium having computer-readable program instructions for executing various aspects of the present application.

[0120] A computer-readable storage medium can be a tangible device that can hold and store instructions for use by an instruction execution device. A computer-readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination thereof. As used herein, a computer-readable storage medium is not to be construed as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through an electrical wire.

[0121] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions to be stored in the computer-readable storage medium in each computing / processing device.

[0122] The computer program instructions for performing the operation of the present application can be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data or source code or object code written in any combination of one or more programming languages, wherein the programming language includes object-oriented programming languages ​​such as Smalltalk, C++, and conventional procedural programming languages ​​such as "C" language or similar programming languages. Computer-readable program instructions can be executed completely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or executed completely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer by any type of network including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (such as by using an Internet service provider to connect to the Internet). In certain embodiments, by utilizing the state information of computer-readable program instructions to personalize electronic circuits, such as programmable logic circuits, field programmable gate arrays (FPGAs) or programmable logic arrays (PLAs), the electronic circuits can execute computer-readable program instructions, thereby realizing various aspects of the present application.

[0123] Various aspects of the present application are described herein with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present application. It should be understood that each block of the flowcharts and / or block diagrams, and combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.

[0124] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine such that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device is generated that implements the functions / actions specified in one or more blocks in the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium, where these instructions cause the computer, programmable data processing device, and / or other device to operate in a specific manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing various aspects of the functions / actions specified in one or more blocks in the flowchart and / or block diagram.

[0125] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more blocks in the flowchart and / or block diagram.

[0126] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the system, method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and the part of the module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a special hardware-based system that performs the function or action of the specification, or can be implemented by a combination of special hardware and computer instructions.

[0127] The embodiments of the present application have been described above. The above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is selected to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons skilled in the art to understand the embodiments disclosed herein.

Claims

1. A memory reuse method, characterized in that: include: Before the start of the first stage in the artificial intelligence model training process, determine whether first data corresponding to the second stage in the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer, the access speed of the first memory is higher than the access speed of the second memory, and the first data is data that will not be used in the first stage; If it is determined that the first data has been transferred to the second memory, the second data required for the first stage is stored in a storage area in the first memory used for storing the first data.

2. The method according to claim 1, wherein the first data is an optimizer parameter of a parameter optimizer used for training an artificial intelligence model, and the second data is a tensor in the artificial intelligence model, and the optimizer parameter will not be used in the second stage in which the tensor is used.

3. The method according to claim 2, further comprising: The storage area for storing the optimizer parameters is changed from static memory to dynamic memory.

4. The method according to claim 1, wherein the first data and the second data are tensors used in different stages of the artificial intelligence model training process.

5. The method according to claim 1, wherein determining whether the first data corresponding to the second stage in the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer comprises: Based on the memory reuse relationship between the first data and the second data, determine whether the first data corresponding to the second stage in the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer, wherein the memory reuse relationship indicates that both the first data and the second data can use the storage area in the first memory.

6. The method according to claim 5, further comprising: Determining a computational graph of the artificial intelligence model; Based on the computation graph, the memory reuse relationship between the first data and the second data is determined.

7. The method according to claim 1, further comprising: A plurality of control operators are added to the artificial intelligence model, and the plurality of control operators are used to control the transfer of data for the artificial intelligence model between the first memory and the second memory.

8. A memory multiplexing device, characterized in that: The device comprises: A data transfer determination unit is configured to determine, before the first stage in the artificial intelligence model training process begins, whether first data corresponding to a second stage in the artificial intelligence model training process is transferred from a first memory of the computer to a second memory of the computer, the access speed of the first memory is higher than the access speed of the second memory, and the first data is data that will not be used in the first stage; The data transfer unit is configured to store the second data needed for the first stage into a storage area in the first memory for storing the first data if it is determined that the first data has been transferred to the second memory.

9. The memory reuse device according to claim 8, wherein the first data is an optimizer parameter of a parameter optimizer used for training an artificial intelligence model, the second data is a tensor in the artificial intelligence model, and the optimizer parameter will not be used in a second stage in which the tensor is used.

10. The memory reuse device according to claim 9, further comprising: The parameter adjustment unit is configured to change the storage area for storing the optimizer parameters from static memory to dynamic memory.

11. A memory reuse device according to claim 8, wherein the first data and the second data are tensors used in different stages of the artificial intelligence model training process.

12. The memory multiplexing device according to claim 8, wherein the data transfer determination unit comprises: The transfer determination unit based on the reuse relationship is configured to determine whether the first data corresponding to the second stage in the artificial intelligence model training process is transferred from the first memory of the computer to the second memory of the computer based on the memory reuse relationship between the first data and the second data, wherein the memory reuse relationship indicates that the first data and the second data can both use the storage area in the first memory.

13. The memory reuse device according to claim 12, further comprising: a computation graph determining unit, configured to determine a computation graph of the artificial intelligence model; A memory reuse relationship determination unit is configured to determine the memory reuse relationship between the first data and the second data based on the calculation graph.

14. A computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the method according to any one of claims 1 to 7.

15. A computer program product comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method for intelligently detecting C program memory leakage based on machine learning

    CN108804332A

  • Artificial intelligence-based pre-training language model processing method, device and equipment

    CN113688245A

  • Model training optimization method and device, computer equipment and storage medium

    CN114021733A

  • Optimized training of linear machine learning models

    US20160078361A1

Cited By

  • Model training video memory optimization method and device

    CN119205484A

  • Tensor management method, electronic device, storage medium and program product

    CN119718693A