Memory scheduling method and device, electronic device and storage medium
By obtaining the amount of memory and the occupancy of intermediate calculation results in real time, and dynamically scheduling the storage of intermediate calculation results, the problem of excessive memory usage in artificial intelligence model training is solved, and memory utilization and training efficiency are improved.
Patent Information
- Application Number
- CN202211280037.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-19
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2042-10-19
AI Technical Summary
During the training process of the artificial intelligence model, due to the increase in data size and model size, the memory usage is too large, resulting in long training time. The existing memory scheduling strategy relies on the developer's experience and is fixed, and cannot guarantee memory utilization efficiency and efficiency. Training efficiency.
By obtaining the current available memory amount and the memory usage of intermediate calculation results in real time, it can dynamically decide whether to keep the intermediate calculation results in the memory, realize adaptive memory scheduling, and improve memory utilization efficiency and model training efficiency.
It realizes dynamic memory scheduling during model training, improves memory utilization efficiency and training efficiency, reduces recalculation, avoids memory overflow, and improves computing performance.
Smart Images

Figure CN115688893B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, in particular to the field of deep learning and distributed computing technology, and specifically to a memory scheduling method and device, an electronic device, a computer-readable storage medium, and a computer program product. Background Art
[0002] Artificial intelligence is a discipline that studies how to use computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0003] With the development of artificial intelligence technology, the scale of data and models involved in artificial intelligence is getting larger and larger. The dual challenges of big data and big models make the training of artificial intelligence models take a long time.
[0004] The methods described in this section are not necessarily methods that have been previously conceived or employed. Unless otherwise indicated, it should not be assumed that any method described in this section is considered to be prior art simply because it is included in this section. Similarly, unless otherwise indicated, the issues mentioned in this section should not be considered to have been recognized in any prior art. Summary of the invention
[0005] The present disclosure provides a memory scheduling method and device, an electronic device, a computer-readable storage medium, and a computer program product.
[0006] According to one aspect of the present disclosure, a memory scheduling method is provided, comprising: obtaining a first model to be trained, wherein the first model includes a plurality of forward operators; before executing any one of the plurality of forward operators, obtaining a current amount of available memory and a memory occupancy of an intermediate calculation result output by the forward operator; and determining whether to retain the intermediate calculation result in memory based on the available memory and the memory occupancy.
[0007] According to one aspect of the present disclosure, a memory scheduling device is provided, comprising: a first acquisition module, configured to acquire a first model to be trained, wherein the first model comprises a plurality of forward operators; a second acquisition module, configured to acquire a current amount of available memory and a memory occupancy of an intermediate calculation result output by the forward operator before executing any of the plurality of forward operators; and a determination module, configured to determine whether to retain the intermediate calculation result in the memory based on the amount of available memory and the memory occupancy.
[0008] According to one aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor, the memory storing instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute the memory scheduling method.
[0009] According to one aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the above-mentioned memory scheduling method.
[0010] According to one aspect of the present disclosure, a computer program product is provided, including a computer program, which implements the above memory scheduling method when executed by a processor.
[0011] According to one or more embodiments of the present disclosure, dynamic and adaptive scheduling of memory during model training can be achieved, thereby improving memory utilization efficiency and model training efficiency.
[0012] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings exemplarily illustrate the embodiments and constitute a part of the specification, and together with the text description of the specification, are used to explain the exemplary implementation of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. In all drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0014] Figure 1 A flowchart of a memory scheduling method according to some embodiments of the present disclosure is shown;
[0015] Figure 2 A schematic diagram of a pipeline parallel model training mode according to some embodiments of the present disclosure is shown;
[0016] Figure 3A schematic diagram showing a 1F1B pipeline parallel computing process and its memory usage according to some embodiments of the present disclosure;
[0017] Figure 4 A schematic diagram of a model training process according to some embodiments of the present disclosure is shown;
[0018] Figure 5 A structural block diagram of a memory scheduling device according to some embodiments of the present disclosure is shown; and
[0019] Figure 6 A structural block diagram of an exemplary electronic device that can be used to implement some embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0020] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0021] In the present disclosure, unless otherwise specified, the use of the terms "first", "second", etc. to describe various elements is not intended to limit the positional relationship, timing relationship, or importance relationship of these elements, and such terms are only used to distinguish one element from another element. In some examples, the first element and the second element may refer to the same instance of the element, and in some cases, based on the description of the context, they may also refer to different instances.
[0022] The terms used in the description of various examples in this disclosure are only for the purpose of describing specific examples and are not intended to be limiting. Unless the context clearly indicates otherwise, if the number of elements is not specifically limited, the element can be one or more. In addition, the term "and / or" used in this disclosure covers any one of the listed items and all possible combinations.
[0023] A training iteration of an AI model consists of three steps:
[0024] 1. Forward calculation: execute the forward operator to obtain the intermediate calculation results (i.e., intermediate hidden variables, Variable);
[0025] 2. Reverse calculation: Execute the reverse operator to calculate the gradient of the model parameter (Parameter);
[0026] 3. Optimization update: Apply optimization algorithms to update the values of model parameters.
[0027] During the forward calculation process, the forward operator will output a large number of intermediate calculation results. Some of the intermediate calculation results are input to the reverse operator, and these intermediate calculation results need to be stored in memory until the corresponding reverse operator is calculated. When the model is large in scale and has many layers, the number of intermediate calculation results that need to be stored can reach tens of thousands, occupying a large amount of memory.
[0028] The idea of Forward Re-computation Backpropagation (FRB) is that in the forward calculation, except for a small number of intermediate calculation results that must be stored in memory, all other intermediate calculation results will be deleted; in the reverse calculation, the forward operator is first recalculated to obtain the deleted intermediate calculation results, and then the reverse operator is run. In short, FRB calculates the forward operator one more time compared to ordinary training iterations.
[0029] In the related art, whether the intermediate calculation results of each forward operator are deleted from the memory (i.e., whether the forward operator is recalculated) is manually set by the developer. This memory scheduling strategy depends on the developer's experience and is fixed once set. The memory utilization efficiency and model training efficiency cannot be guaranteed.
[0030] To this end, an embodiment of the present disclosure provides a memory scheduling method that can achieve dynamic and adaptive scheduling of memory during model training, thereby improving memory utilization efficiency and model training efficiency.
[0031] The embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.
[0032] Figure 1 FIG. 1 is a flowchart of a memory scheduling method 100 according to some embodiments of the present disclosure. Figure 1 As shown, the method 100 includes S110 - S130 .
[0033] In step S110, a first model to be trained is obtained, where the first model includes a plurality of forward operators.
[0034] In step S120, before executing any forward operator among the multiple forward operators, the current available memory amount and the memory usage of the intermediate calculation result output by the forward operator are obtained.
[0035] In step S130 , based on the available memory amount and the memory occupancy, it is determined whether to retain the intermediate calculation results in the memory.
[0036] According to an embodiment of the present disclosure, during the training process of the model, the current amount of available memory is obtained in real time to determine whether the intermediate calculation results output by the next forward operator need to be retained in the memory, thereby enabling dynamic and adaptive scheduling of memory and improving memory utilization efficiency and model training efficiency.
[0037] The execution subject of method 100 can be any computing device that can be used for model training, such as CPU (Central Processing Unit), GPU (Graphics Processing Unit), TPU (Tensor Processing Unit), NPU (Neural network Processing Unit), DPU (Deep learning Processing Unit), etc.
[0038] The following is a detailed description of each step of method 100.
[0039] In step S110, a first model to be trained is obtained, where the first training model includes a plurality of forward operators.
[0040] According to some embodiments, the first model may be a complete model for processing a certain task (eg, image classification, speech recognition, sentence generation, etc.).
[0041] According to some embodiments, the first model may also be a part of a complete model for processing a certain task. For example, the complete model for processing a certain task is recorded as the second model. By segmenting the second model to be trained, multiple sub-models of the second model may be obtained. The first model may be any sub-model of the multiple sub-models.
[0042] The forward operator may be, for example, a convolution operator, a pooling operator, an activation operator, etc.
[0043] According to some embodiments, when the first model is a sub-model of the second model, method 100 can be applied to a pipeline parallel training mode. In the pipeline parallel training mode, the second model to be trained can be split into multiple sub-models. Multiple sub-models are placed in multiple different computing devices respectively, each computing device executes the calculation process of the corresponding sub-model, and multiple computing devices form a pipeline to realize the training of the second model. In the pipeline parallel training mode, each computing device can serve as the execution subject of method 100 of the embodiment of the present disclosure, and the sub-model trained by the computing device is the first model to be trained.
[0044] Figure 2FIG. 1 shows a schematic diagram of a pipeline parallel training mode. Figure 2 As shown, the second model 200 includes processing layers 201-209, which are divided into three sub-models 210, 220, and 230. Sub-model 210 includes processing layers 201-203, sub-model 220 includes processing layers 204-205, and sub-model 230 includes processing layers 206-209. Sub-models 210, 220, and 230 are respectively assigned to computing devices 240, 250, and 260. Computing device 240 can execute method 100 of an embodiment of the present disclosure to implement memory scheduling during the training process of sub-model 210 (i.e., the first model). Computing device 250 can execute method 100 of an embodiment of the present disclosure to implement memory scheduling during the training process of sub-model 220 (i.e., the first model). Computing device 260 can execute method 100 of an embodiment of the present disclosure to implement memory scheduling during the training process of sub-model 230 (i.e., the first model).
[0045] The overall training process of the second model 200 is as follows: In the forward calculation process, the computing device 240 processes the input data based on the sub-model 210, obtains the first intermediate result and transmits it to the computing device 250. The computing device 250 processes the first intermediate result based on the sub-model 220, obtains the second intermediate result and transmits it to the computing device 260. The computing device 260 processes the second intermediate result based on the sub-model 230 to obtain the forward calculation result. The reverse calculation process is similar to the forward calculation process. Finally, the computing devices 240-260 use the gradients calculated by the reverse calculation process to update the parameters of the second model 200.
[0046] According to some embodiments, when a pipeline parallel training mode is adopted, during the training process of the first model, forward calculation and reverse calculation can be performed alternately, that is, a 1F1B (1Forward1Backward) pipeline parallel mode is adopted. In this way, unnecessary intermediate calculation results can be released in time, saving memory.
[0047] Figure 3 A schematic diagram of the 1F1B pipeline parallel computing process and its memory usage according to some embodiments of the present disclosure is shown. Figure 3 In the illustrated embodiment, computing devices 1-3 form a pipeline for model training. ij represents the forward calculation of training data j by computing device i, B ij Represents the reverse calculation of training data j by computing device i (in Figure 3 Since the forward calculation needs to record the intermediate calculation results, the memory usage increases; after the reverse calculation, the corresponding intermediate calculation results can be released, so the memory usage decreases. Figure 3It can be seen that in pipeline parallelism, the memory usage of different computing devices is uneven, among which computing device 1 occupies the most memory. Moreover, the memory usage of the same computing device will also change in different time periods. If the memory scheduling policy of each computing device is manually set, it may result in the memory of a single computing device not being fully utilized, the computing performance being reduced, and the training progress between the computing devices not matching (some computing devices may need to wait for other computing devices to complete the calculation). Based on the method 100 of the embodiment of the present disclosure, the memory of each computing device in the pipeline parallel can be dynamically and adaptively scheduled to achieve effective use of memory and improve the training efficiency of the model.
[0048] It should be noted that although this specification uses the 1F1B pipeline parallel training mode as an example to illustrate method 100, it should be understood that the method 100 of the embodiment of the present disclosure can be applied to any model training mode, including single-machine training, data parallelism, F-then-B (previous forward calculation, then reverse calculation) pipeline parallelism, etc. The method 100 of the embodiment of the present disclosure can realize dynamic memory scheduling of computing devices during the model training process of any training mode.
[0049] In step S120, for the forward calculation process of the first model, before executing any forward operator among the multiple forward operators, the current available memory amount and the memory occupancy of the intermediate calculation result output by the forward operator are obtained.
[0050] The memory usage of the intermediate calculation results output by the forward operator can be determined according to the size of the training data and the properties of the forward operator itself (such as the size and number of convolution kernels).
[0051] According to some embodiments, in order to reduce the amount of calculation in the model training process and improve the model training efficiency, the memory usage of the intermediate calculation results output by each forward operator can be calculated before training the first model. Accordingly, in step S120, the pre-calculated memory usage can be directly obtained. The available memory needs to be obtained in real time based on the current memory usage.
[0052] In step S130, based on the available memory amount and the memory occupancy amount obtained in step S120, it is determined whether to retain the intermediate calculation results in the memory.
[0053] According to some embodiments, in response to the amount of available memory being greater than or equal to the amount of memory occupied, the intermediate calculation result of the forward operator is retained in the memory. Accordingly, during the reverse calculation process, the intermediate calculation result can be directly obtained from the memory without recalculation. According to this embodiment, recalculation can be minimized under the condition of satisfying memory constraints, thereby improving calculation efficiency and speed, and reducing the time consumption of model training.
[0054] According to some embodiments, in response to the available memory being less than the memory usage, the intermediate calculation result of the forward operator is deleted from the memory. Accordingly, during the reverse calculation process, the forward operator needs to be recalculated to obtain its intermediate calculation result. According to this embodiment, memory overflow can be avoided during model training.
[0055] According to some embodiments, in response to the available memory amount being less than the memory usage, after determining that the forward operator needs to adopt a recalculation strategy (i.e., the forward operator needs to be recalculated during the reverse calculation process), the forward operator can be further marked. Thus, during the reverse calculation process, it is possible to quickly determine whether the forward operator needs to be recalculated based on the set mark, thereby improving calculation efficiency.
[0056] It can be understood that the first model also includes multiple reverse operators. Accordingly, the method 100 also includes: before any reverse operator among the multiple reverse operators, in response to the absence of a target intermediate calculation result required for executing the reverse operator in the memory, obtaining a checkpoint calculation result, wherein the checkpoint calculation result is the latest intermediate calculation result before the target intermediate calculation result; and performing forward recalculation based on the checkpoint calculation result to obtain the target intermediate calculation result.
[0057] It can be understood that the training process of the first model includes multiple iterations.
[0058] According to some embodiments, the method 100 may be executed in each iteration of multiple iterations, thereby dynamically and adaptively scheduling memory for each iteration, and has good versatility.
[0059] According to other embodiments, method 100 may be performed in the first iteration and the change iteration in multiple iterations. The change iteration is an iteration in which the amount of training data (batchsize) changes. According to this embodiment, method 100 is performed only when the amount of training data changes, and the memory scheduling strategy is re-determined. When the amount of training data does not change compared to the previous iteration, the memory scheduling result of the previous iteration can be directly reused, thereby avoiding unnecessary calculations and improving calculation efficiency.
[0060] Figure 4 FIG. 4 is a schematic diagram showing a model training process 400 according to an embodiment of the present disclosure. Figure 4 As shown, process 400 includes steps S410-S490.
[0061] In step S410, the model M to be trained is divided into N sub-models M_1, M_2, ..., M_N, and the sub-models M_1, M_2, ..., M_N are respectively assigned to computing devices D_1, D_2, ..., D_N. The model M is equivalent to the second model described above, and the sub-models M_i (i = 1, 2, ..., N) are equivalent to the first model described above.
[0062] In step S420, the memory usage K of the intermediate calculation results output by each forward operator of each sub-model M_i is calculated.
[0063] In step S430, the model M is trained according to the pipeline parallel 1F1B scheduling method.
[0064] In step S440, for each computing device D_i (i=1, 2, ..., N), before executing each forward operator, the current available memory amount P is obtained.
[0065] In step S450, determine whether P≥K. Step S450 is used to determine whether the forward operator needs to adopt a recalculation strategy (that is, whether it needs to be recalculated during the reverse calculation process). If the judgment result of step S450 is no, it means that the current memory cannot meet the storage requirements of the intermediate calculation results of the forward operator, and it is necessary to execute step S460 to determine whether the recalculation strategy is adopted for the forward operator and mark the forward operator so that it can be recalculated during the reverse calculation process. If the judgment result of step S450 is yes, it means that the current memory can meet the storage requirements of the intermediate calculation results of the forward operator, so there is no need to adopt a recalculation strategy for the forward operator, that is, there is no need to mark the forward operator.
[0066] In step S470, the forward operator is executed to obtain the intermediate calculation result output by the forward operator. If the forward operator is marked as adopting the recalculation strategy, the intermediate calculation result is deleted from the memory; if the forward operator is not marked, it does not need to adopt the recalculation strategy, and the intermediate calculation result is retained in the memory.
[0067] In step S480, the reverse operator is executed based on the 1F1B scheduling strategy.
[0068] Steps S430-S480 may be executed repeatedly until one iteration is completed, and then step S490 is executed to call the optimizer to update the parameters of the model M.
[0069] According to an embodiment of the present disclosure, a memory scheduling device is also provided. Figure 5 FIG. 5 shows a structural block diagram of a memory scheduling device 500 according to some embodiments of the present disclosure. Figure 5As shown, the apparatus 500 includes a first acquisition module 510 , a second acquisition module 520 and a determination module 530 .
[0070] The first acquisition module 510 is configured to acquire a first model to be trained, wherein the first model includes a plurality of forward operators.
[0071] The second acquisition module 520 is configured to acquire the current available memory amount and the memory usage of the intermediate calculation result output by any forward operator before executing any forward operator among the multiple forward operators.
[0072] The determination module 530 is configured to determine whether to retain the intermediate calculation result in the memory based on the available memory amount and the memory occupancy amount.
[0073] According to an embodiment of the present disclosure, during the training process of the model, the current amount of available memory is obtained in real time to determine whether the intermediate calculation results output by the next forward operator need to be retained in the memory, thereby enabling dynamic and adaptive scheduling of memory and improving memory utilization efficiency and model training efficiency.
[0074] According to some embodiments, the determination module 530 is further configured to: in response to the available memory amount being greater than or equal to the memory occupancy amount, retain the intermediate calculation result in the memory.
[0075] According to some embodiments, the determination module 530 is further configured to: in response to the available memory amount being smaller than the memory occupancy amount, delete the intermediate calculation result from the memory.
[0076] According to some embodiments, the first model also includes multiple reverse operators; the device 500 also includes: a third acquisition module, configured to, before executing any of the multiple reverse operators, in response to the absence of a target intermediate calculation result required to execute the reverse operator in the memory, obtain a checkpoint calculation result, wherein the checkpoint calculation result is the latest intermediate calculation result located before the target intermediate calculation result; and a recalculation module, configured to perform forward recalculation based on the checkpoint calculation result to obtain the target intermediate calculation result.
[0077] According to some embodiments, the first model is any sub-model of a plurality of sub-models, and the plurality of sub-models are obtained by segmenting a second model to be trained. During the training process of the first model, forward calculation and reverse calculation are performed alternately.
[0078] It should be understood that Figure 5 The various modules of the apparatus 500 shown in FIG. Figure 1The steps in the method 100 described above correspond to each other. Therefore, the operations, features and advantages described above for the method 100 are also applicable to the device 500 and the modules included therein. For the sake of brevity, some operations, features and advantages are not repeated here.
[0079] Although specific functions are discussed above with reference to specific modules, it should be noted that the functions of the various modules discussed herein can be divided into multiple modules, and / or at least some functions of multiple modules can be combined into a single module. For example, the second acquisition module 520 and the determination module 530 described above can be combined into a single module in some embodiments.
[0080] It should also be understood that various techniques may be described herein in the general context of software hardware elements or program modules. Figure 5 The various modules described can be implemented in hardware or in hardware in combination with software and / or firmware. For example, these modules can be implemented as computer program codes / instructions, which are configured to be executed in one or more processors and stored in a computer-readable storage medium. Alternatively, these modules can be implemented as hardware logic / circuits. For example, in some embodiments, one or more of modules 510-530 can be implemented together in a system on chip (System on Chip, SoC). SoC may include an integrated circuit chip (which includes a processor (e.g., a central processing unit (CPU), a microcontroller, a microprocessor, a digital signal processor (DSP), etc.), a memory, one or more communication interfaces, and / or one or more components in other circuits), and may optionally execute the received program code and / or include embedded firmware to perform functions.
[0081] According to an embodiment of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor, the memory storing instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute the memory scheduling method according to an embodiment of the present disclosure.
[0082] According to one aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided. The computer instructions are used to enable a computer to execute a memory scheduling method according to an embodiment of the present disclosure.
[0083] According to one aspect of the present disclosure, a computer program product is provided, including a computer program, which implements the memory scheduling method according to an embodiment of the present disclosure when executed by a processor.
[0084] refer to Figure 6 , a block diagram of an electronic device 600 that can be used as a server or client of the present disclosure will now be described, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0085] like Figure 6 As shown, the electronic device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0086] Multiple components in the electronic device 600 are connected to the I / O interface 605, including: an input unit 606, an output unit 607, a storage unit 608 and a communication unit 609. The input unit 606 can be any type of device that can input information to the device 600. The input unit 606 can receive input digital or character information, and generate key signal input related to user settings and / or function control of the electronic device, and can include but is not limited to a mouse, a keyboard, a touch screen, a trackpad, a trackball, a joystick, a microphone and / or a remote control. The output unit 607 can be any type of device that can present information, and can include but is not limited to a display, a speaker, a video / audio output terminal, a vibrator and / or a printer. The storage unit 608 can include but is not limited to a disk, an optical disk. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and can include but is not limited to a modem, a network card, an infrared communication device, a wireless communication transceiver and / or a chipset, such as Bluetooth TM devices, 802.11 devices, Wi-Fi devices, WiMAX devices, cellular communication devices, and / or the like.
[0087] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as method 100. For example, in some embodiments, the method 100 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the method 100 described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the method 100 in any other appropriate manner (e.g., by means of firmware).
[0088] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0089] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0090] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0091] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0092] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0093] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0094] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0095] Although the embodiments or examples of the present disclosure have been described with reference to the accompanying drawings, it should be understood that the above-mentioned methods, systems and devices are merely exemplary embodiments or examples, and the scope of the present invention is not limited by these embodiments or examples, but only by the claims after authorization and their equivalent scope. Various elements in the embodiments or examples can be omitted or replaced by their equivalent elements. In addition, each step can be performed in an order different from that described in the present disclosure. Further, the various elements in the embodiments or examples can be combined in various ways. It is important that with the evolution of technology, many elements described herein can be replaced by equivalent elements that appear after the present disclosure.
Claims
1. A memory scheduling method, comprising: Obtaining a first model to be trained, wherein the first model includes a plurality of forward operators; Before executing any forward operator among the plurality of forward operators, obtaining a current amount of available memory and a memory usage of an intermediate calculation result output by the forward operator; In response to the available memory amount being less than the memory usage, determining to adopt a recalculation strategy for the forward operator, and marking the forward operator; In response to the available memory amount being greater than or equal to the memory usage, determining not to adopt a recalculation strategy for the forward operator and not marking the forward operator; Execute the forward operator to obtain an intermediate calculation result output by the forward operator; In response to the forward operator being marked as adopting a recalculation strategy, deleting the intermediate calculation result from the memory, and recalculating the forward operator during the reverse calculation process to obtain the intermediate calculation result; and In response to the forward operator not being marked, the intermediate calculation result is retained in the memory, and during the reverse calculation process, the intermediate calculation result is directly obtained from the memory without recalculating the forward operator.
2. The method according to claim 1, wherein: The first model also includes a plurality of reverse operators; The method further comprises: Before executing any reverse operator among the plurality of reverse operators, in response to the absence of a target intermediate calculation result required for executing the reverse operator in the memory, obtaining a checkpoint calculation result, wherein the checkpoint calculation result is a latest intermediate calculation result located before the target intermediate calculation result; and Forward recalculation is performed based on the checkpoint calculation result to obtain the target intermediate calculation result.
3. The method according to claim 1 or 2, wherein: The first model is any sub-model of a plurality of sub-models, and the plurality of sub-models are obtained by segmenting the second model to be trained. During the training process of the first model, forward calculation and reverse calculation are performed alternately.
4. The method according to claim 1, wherein: The training process of the first model includes multiple iterations, and the method is performed in each iteration of the multiple iterations.
5. The method according to claim 1, wherein: The training process of the first model includes multiple iterations, and the method is performed in a first iteration and a change iteration of the multiple iterations, and the change iteration is an iteration in which the amount of training data changes.
6. A memory scheduling device, comprising: A first acquisition module is configured to acquire a first model to be trained, wherein the first model includes a plurality of forward operators; A second acquisition module is configured to acquire a current available memory amount and a memory occupancy amount of an intermediate calculation result output by any forward operator among the plurality of forward operators before executing the forward operators; Determine the module, which is configured as: In response to the available memory amount being less than the memory usage, determining to adopt a recalculation strategy for the forward operator and marking the forward operator; and In response to the available memory amount being greater than or equal to the memory usage, determining not to adopt a recalculation strategy for the forward operator and not marking the forward operator; An execution module, configured to execute the forward operator to obtain an intermediate calculation result output by the forward operator; The recalculation module is configured as follows: In response to the forward operator being marked as adopting a recalculation strategy, deleting the intermediate calculation result from the memory, and recalculating the forward operator during the reverse calculation process to obtain the intermediate calculation result; and In response to the forward operator not being marked, the intermediate calculation result is retained in the memory, and during the reverse calculation process, the intermediate calculation result is directly obtained from the memory without recalculating the forward operator.
7. The device according to claim 6, wherein: The first model also includes a plurality of reverse operators; The device also includes: The third acquisition module is configured to, before executing any reverse operator of the plurality of reverse operators, in response to the absence of a target intermediate calculation result required for executing the reverse operator in the memory, acquire a checkpoint calculation result, wherein the checkpoint calculation result is the latest intermediate calculation result located before the target intermediate calculation result, The recalculation module is further configured to perform forward recalculation based on the checkpoint calculation result to obtain the target intermediate calculation result.
8. The device according to claim 6 or 7, wherein: The first model is any sub-model of a plurality of sub-models, and the plurality of sub-models are obtained by segmenting the second model to be trained. During the training process of the first model, forward calculation and reverse calculation are performed alternately.
9. An electronic device, comprising: at least one processor; as well as a memory communicatively coupled to the at least one processor; in The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 5.
10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to make a computer execute the method according to any one of claims 1-5.
