Model awareness methods and systems for training and / or trimming machine learning models
By profiling and assigning tensors to chunks before model training, the problem of memory and communication overhead in distributed training is solved, and efficient parallel training and flexible memory management are achieved.
Patent Information
- Application Number
- CN202410609227.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-05-18
- Filing Date
- 2024-05-16
- Publication Date
- 2024-08-23
AI Technical Summary
Existing machine learning models suffer from localization issues in distributed training and fine-tuning, resulting in large memory or communication overhead, and often requiring model modifications or manual memory configuration.
By implementing model profiling execution before normal model execution, allocating tensors into multiple chunks based on profiling results, and executing model training in parallel on multiple devices, adaptive memory management is used to reduce the need for manual configuration.
It improves the efficiency of parallel training of machine learning models on multiple devices, reduces memory and communication overhead, avoids the need for model modification and manual configuration, and enhances the flexibility and efficiency of the system.
Smart Images

Figure CN118536617A
Abstract
Description
Technical Field
[0001] The embodiments described herein generally relate to training and / or fine-tuning of machine learning models. More specifically, the embodiments described herein relate to methods and systems for training and / or fine-tuning machine learning models in a distributed training and / or fine-tuning system. Background Art
[0002] The training and / or fine-tuning of machine learning models has always been a focus in the field of machine learning. Various types of machine learning parallelism can be used to support the training and / or fine-tuning of machine learning models on multiple devices or graphics processing units at the same time and to improve the throughput of training and / or fine-tuning. Machine learning parallelism may include data parallelism, pipeline parallelism, tensor parallelism, etc., among which data parallelism is widely used due to its simplicity and scalability. Summary of the invention
[0003] Features in the embodiments disclosed herein may support machine learning parallelism, such as data parallelism, without modifying or changing the machine learning model. Features in the embodiments disclosed herein may also take into account locality issues to improve efficiency by, for example, allocating tensors based on their execution sequence. Features in the embodiments disclosed herein may additionally provide adaptive memory management to reduce or eliminate the need for manual configuration.
[0004] The features in the embodiments disclosed herein can address problems with existing solutions to data parallelism, which may require large amounts of memory or communication overhead due to locality issues, require modifications or changes to machine learning models, and / or require a lot of manual configuration for memory offloading, etc.
[0005] In one example embodiment, a method for training a machine learning model on multiple devices in parallel is provided. The method includes performing a model profiling execution before a model normal execution, allocating or assigning tensors of the model into multiple chunks based on profiling results from the model profiling execution, and performing the model normal execution on multiple devices in parallel to train the model.
[0006] In another example embodiment, a machine learning model training system is provided. The system includes at least one processor and a memory storing a machine learning model. The at least one processor is used to perform model profiling execution before normal execution of the model, distribute tensors of the model into chunks based on profiling results from the model profiling execution, and perform normal execution of the model on multiple devices in parallel to train the model.
[0007] In yet another example embodiment, a non-transitory computer-readable medium having computer-executable instructions stored thereon is provided. The instructions, when executed, cause one or more processors to perform operations including performing a model profiling execution prior to a normal execution of the model, allocating tensors of a machine learning model into chunks based on profiling results from the model profiling execution, and performing the normal execution of the model on multiple devices in parallel to train the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] The accompanying drawings illustrate various embodiments of systems, methods, and embodiments of various other aspects of the present disclosure. It will be appreciated by those of ordinary skill in the art that the element boundaries (e.g., boxes, box groups, or other shapes) shown in the figures represent an example of boundaries. In some examples, an element may be designed as multiple elements, or multiple elements may be designed as one element. In some examples, an element shown as an internal component of an element may be implemented as an external component in another element, and vice versa. Non-restrictive and non-exhaustive descriptions are described with reference to the following drawings. The components in the figures are not necessarily drawn to scale, but are focused on the explanation principle. In the detailed description below, the embodiments are described only as illustrations, because various changes and modifications are apparent to those skilled in the art according to the detailed description below.
[0009] Figure 1 is a schematic diagram of an example distributed training and / or fine-tuning system for sharded data parallelism, arranged in accordance with at least some embodiments described herein.
[0010] Figure 2 is a schematic view of an example processing flow of a sharded data-parallel system for optimizing, training, and / or fine-tuning a machine learning model, arranged in accordance with at least some embodiments described herein.
[0011] Figure 3 is a flow chart illustrating an example process flow for implementing operations of a profiling phase and operations of a sharding phase in accordance with at least some embodiments described herein.
[0012] Figure 4 is a schematic block diagram of an example computer system suitable for implementing an electronic device, arranged in accordance with at least some embodiments described herein. DETAILED DESCRIPTION
[0013] In the following detailed description, specific embodiments of the present invention are described herein with reference to the accompanying drawings, which form a part of the description. In this specification and the accompanying drawings, unless the context otherwise dictates, similar reference numerals represent elements that can implement the same, similar or equivalent functions. In addition, unless otherwise specified, the description of each consecutive figure may refer to features from one or more previous figures to provide a clearer context and more substantial explanation of the current example embodiment. Nevertheless, the example embodiments described in the detailed description, the drawings, and the claims are not intended to be limiting. Other embodiments may be utilized and other changes may be made without departing from the spirit or scope of the subject matter presented herein. It will be readily understood that, as shown in the overall description and the accompanying drawings herein, the various aspects of the present disclosure may be arranged, replaced, combined, separated and designed in a variety of different configurations, all of which are clearly contemplated herein.
[0014] It should be understood that the disclosed embodiments are merely examples of the present disclosure, which may be embodied in various forms. Well-known functions or configurations are not described in detail to avoid obscuring the present disclosure with unnecessary detail. Therefore, the specific structural and functional details disclosed herein should not be interpreted as limiting, but merely as a basis for the claims and as a representative basis for teaching those skilled in the art to use the present disclosure in different ways in almost any appropriate detailed structure.
[0015] In addition, the present disclosure may be described in terms of functional block components and various processing steps. It should be understood that these functional blocks may be implemented by any number of hardware and / or software components configured to implement the specified functions.
[0016] The scope of the present disclosure should be determined by the appended claims and their legal equivalents, rather than by the examples given herein. For example, the steps recited in any method claim may be performed in any order and are not limited to the order presented in the claim. In addition, unless specifically described herein as "critical" or "essential", no element is essential to the implementation of the present disclosure.
[0017] As used herein, "machine learning" is a term of art and may refer to a computer or processor-related technology by which decisions and / or actions can be made, learned, and / or trained autonomously, in lieu of human intervention. Machine learning is a branch of artificial intelligence that focuses on using data and algorithms to mimic the way humans learn, gradually improving its accuracy. Machine learning may include software (i.e., algorithms and / or programs), hardware, or firmware, or any combination thereof, that supports machine learning, natural language understanding, natural language processing, speech recognition, computer vision, and the like. Also included within the scope of machine learning functionality and capabilities is the training and / or fine-tuning of machine learning models related to the embodiments disclosed, described, and suggested herein.
[0018] As referred to herein, "model" or "machine learning model" is a term of art and may refer to software (such as algorithms and / or programs), hardware or firmware, or any combination thereof, that supports machine learning, natural language understanding, natural language processing, speech recognition, computer vision, etc. In an example embodiment, the process of training a model includes providing training data to a machine learning algorithm (e.g., a learning algorithm, etc.) to learn, and the machine learning model may refer to a model artifact created by the training process.
[0019] As referred to herein, "parameters" or "model parameters" of a model are terms of art and may refer to configuration variables that are internal to a model and whose values may be estimated based on given data. Model parameters are required by a model when making predictions, and may determine how to transform input data into the desired output. In an example embodiment, "weights" are model parameters that transform input data within a (hidden) layer of a model and / or represent the strength of connections between units or nodes of a model. In an example embodiment, "bias" is a model parameter that represents the amount by which a model prediction differs from a target value compared to the training data.
[0020] As referred to herein, "optimizer" is a term of art and may refer to a function or algorithm that modifies properties or parameters (e.g., weights, learning rates, etc.) of a machine learning process, method, or model. In an example embodiment, an optimizer may help reduce overall loss and improve accuracy, minimize an error function (e.g., a loss function, etc.), and / or maximize production efficiency. As referred to herein, "optimizer state" is a term of art and may refer to a momentum vector or history tracking property of an optimizer. In an example embodiment, the state of an optimizer may include the parameters being optimized, any hyperparameters being used, etc.
[0021] As referred to herein, "gradient" is a term of art and may refer to a generalization of the derivative of a multivariate function. In an example embodiment, a gradient may capture the local slope of a function, allowing prediction of the effect of taking a step in a direction from a point. In machine learning, a gradient may refer to a vector giving the direction of the maximum rate of change of a function. By taking steps in that direction, an optimal solution for the function may be reached.
[0022] As referred to herein, "FP16" is a term of art and may refer to a half-precision binary floating point format or data structure that occupies 16 bits in computer memory. "FP32" is a term of art and may refer to a single-precision binary floating point format or data structure that occupies 32 bits in computer memory.
[0023] As referred to herein, "tensor" is a term of art and may refer to model data of a machine learning model. In an example embodiment, a tensor may refer to model data related to a model state, such as model parameters, gradients, and / or optimizer states, etc., which are associated by a model structure definition. In an example embodiment, model parameters and gradients may be FP16 type data, while optimizer states may be FP32 type data. In an example embodiment, a tensor may have a size of, for example, several thousand bytes. In an example embodiment, a tensor may operate as a finite state machine. It should be understood that a tensor is "executed" when it is used during the execution of a model (using training data or non-training data).
[0024] As referred to herein, "chunk" is a term of art and may refer to a contiguous memory space of a specified size. In an example embodiment, a chunk may have a size of, for example, several hundred megabytes. In an example embodiment, tensors may be allocated, arranged, organized, or otherwise stored in multiple chunks of the same chunk size or different chunk sizes.
[0025] As referred to herein, "forward" propagation, transfer or operation is a term of art and may refer to a function, operation or algorithm that obtains or generates the actual output of a machine learning model. In an example embodiment, in a forward operation, input data may be fed forward to the model, such as by propagating the input data to the input layer, through the hidden layer(s) and the continuous layer(s), measuring the prediction of the model from the output layer, and calculating the model error based on the prediction made by the model. As referred to herein, "backward propagation" or "backward" propagation, transfer or operation is a term of art and may refer to a function, operation or algorithm that traverses the model in a reversed order from the output layer (through the hidden layer(s) and the continuous layer(s)) to the input layer and calculates the gradient relative to the model parameters. In an example embodiment, in a reverse operation, the process is reversed (from a forward operation) by, for example, propagating the error to the output layer until it reaches the input layer through the hidden layer(s). It should be understood that a "training step" or "fine-tuning step" is a term in the art and may refer to a process including at least a forward operation and a reverse operation based on a batch of input data.
[0026] As referred to herein, "model profiling execution" may refer to one or a single training or fine-tuning step of performing training (using training data or non-training data) of a machine learning model, for example, collecting or obtaining required or desired information or data related to the normal training execution of the model, such as state, execution sequence or timestamp, execution phase (e.g., forward operation phase or reverse operation phase, etc.), hook-able attributes of tensors and / or their modules, relationships between tensors and their modules, memory usage of each execution phase, etc. It should be understood that the model profiling execution is to collect or obtain required or desired information or data about the model execution, rather than to optimize, train or fine-tune the model. As referred to herein, "model normal execution" may refer to one or more iterations of training and / or fine-tuning a machine learning model using training data. It should also be understood that the model profiling execution may take, for example, one or several minutes to run to completion, while the model normal execution may take a day, a week, a month, or more to run to completion.
[0027] As used herein, "hook" is a field term and may refer to a function, operation, or algorithm that is executed or triggered when a condition is met. In an example embodiment, a hook may be registered, installed, arranged, or otherwise associated with a module of a tensor or a model containing a tensor. In an example embodiment, a hook may include a pre-forward hook, a post-forward hook, a pre-backward hook, a post-backward hook, and the like. The pre-forward hook may be executed or triggered, for example, immediately before the forward operation is executed, implemented, or called (invoke / call) (e.g., no other function or operation is implemented or executed in the meantime). The post-forward hook may be executed or triggered, for example, immediately after the forward operation is executed, implemented, or called (invoke / call) (e.g., no other function or operation is implemented or executed in the meantime). The pre-reverse hook may be executed or triggered, for example, immediately before the reverse operation is executed, implemented, or called (invoke / call). The post-reverse hook may be executed or triggered, for example, immediately after the reverse operation is executed, implemented, invoked / called. It should be understood that the hook may include a handler (a function, operation, or algorithm in the hook) that can be used to implement a desired or predetermined action, function, or operation (e.g., monitoring and / or recording the state of a tensor and / or its modules, execution sequence / timestamps, execution stages, etc.).
[0028] As used herein, "parallelism" is a term of art and may refer to the process of processing several groups of instructions at the same time, such as reducing the total computing time, etc. Machine learning parallelism may refer to the process of supporting the training of machine learning models on multiple devices (e.g., graphics processing units (GPUs), etc.) and improving the training throughput. Data parallelism is a type of machine learning parallelism for distributing the training of machine learning models on multiple devices or nodes, where each device or node can process different subsets of training data at the same time. It should be understood that data parallelism may be effective for large-scale machine learning tasks, where the amount of training data may be too large to fit into the memory of a single device. It should also be understood that models and training data sets are getting larger and larger, and if a single GPU is used for training, training time may become a problem. Data parallelism is widely used due to its simplicity. In an example embodiment, in model training with data parallelism, the training data set is divided into several parts, each of which is assigned to a device. After the reverse operation, the gradients of the model can be reduced across all devices, for example by performing a reduction (e.g., aggregation such as sum, max, min, average, etc.) on the data across devices and writing the results to a receive buffer on each device, so that the model parameters on different devices can be kept synchronized.
[0029] As referred to herein, "shard" or "sharding" or "distribute" or "distributing" may refer to an action, function, operation, or algorithm for distributing data among multiple machines or devices. In an example embodiment, sharding may include dividing a data set into multiple smaller parts and distributing or deploying the parts across multiple devices. As referred to herein, "sharded" data parallelism or "sharded" data parallelism may refer to data parallelism, such as a memory-efficient distributed training process that partitions the training state(s) of a model (e.g., model parameters, gradients, optimizer state, etc.) among devices (e.g., GPUs, etc.) in a training data parallel device group. It should be understood that "sharding" may also be used as a noun rather than a verb, and may refer to a portion of data (e.g., the state of a model, etc.) that has been divided into multiple smaller parts. It should also be understood that in sharded data parallelism or sharded data parallelism, the training data can be divided into several shards, and each shard is assigned to a device such as a GPU (data parallelism), and the model state (e.g., the training state of the model) can be divided into several shards, each shard is assigned to a device such as a GPU (sharded data parallelism).
[0030] Figure 1 is a schematic diagram of an example distributed training and / or fine-tuning system 100 for sharded data parallelism, arranged in accordance with at least some embodiments described herein.
[0031] System 100 may include devices 110, 120, 130, 140, 150 and network 160. It should be understood that Figure 1 Only illustrative numbers of devices and / or networks are illustrated. The embodiments described herein are not limited to the number of devices and / or networks described. That is, the number of devices and / or networks described herein is provided for descriptive purposes only and is not intended to be limiting.
[0032] According to at least some example embodiments, devices 110, 120, 130, 140, and 150 may be various electronic devices. The various electronic devices may include, but are not limited to, mobile devices such as smartphones, tablet computers, e-book readers, laptop computers, desktop computers, servers, and / or any other suitable electronic devices.
[0033] According to at least some example embodiments, the network 160 may be a medium for providing a communication link between the devices 110, 120, 130, 140, and 150. The network 160 may be the Internet, a local area network (LAN), a wide area network (WAN), a local interconnect network (LIN), a cloud, etc. The network 160 may be implemented by various types of connections, such as a wired communication link, a wireless communication link, an optical cable, etc.
[0034] According to at least some example embodiments, one or more of devices 110, 120, 130, 140, and 150 may be a server that provides various services to users using one or more other devices. The server may be implemented by a distributed server cluster including multiple servers, or may be implemented by a single server.
[0035] Users may interact with each other via network 160 using one or more of devices 110, 120, 130, 140, and 150. Various applications such as social media applications, online shopping services, data set manipulation services, machine learning services, or their localized interfaces may be installed on devices 110, 120, 130, 140, and 150.
[0036] It should be understood that software applications or services according to the embodiments described herein and / or according to services provided by a service provider may be implemented by devices 110, 120, 130, 140, and 150. Therefore, means for software applications and / or services may be arranged in devices 110, 120, 130, 140, and 150.
[0037] It should also be understood that system 100 may not include network 160 , but rather only devices 110 , 120 , 130 , 140 , and / or 150 , when services are not being performed remotely.
[0038] It should also be understood that devices 110, 120, 130, 140, and 150 may each include one or more processors, memory, and a storage device storing one or more programs. Devices 110, 120, 130, 140, and / or 150 may also each include an Ethernet connector, a wireless fidelity receiver, and the like. One or more programs, when executed by one or more processors, may cause one or more processors to implement the method (or methods) described in any of the embodiments described herein. In addition, it should be understood that, according to the embodiments described herein, a computer-readable non-volatile medium may be provided. The computer-readable medium stores a computer program. The computer program, when executed by a processor, is used to implement the method (or methods) described in any of the embodiments described herein.
[0039] It should also be understood that in the embodiments described herein, a device may refer to a computer system (e.g., 110, 120, 130, 140, 150, etc.) including a CPU, a GPU, and / or a combination thereof (see also Figure 4 description).
[0040] Figure 2 is a schematic diagram of an example processing flow 200 of a sharded data-parallel system for optimizing, training, and / or fine-tuning a machine learning model, arranged in accordance with at least some embodiments described herein.
[0041] It should be understood that training a model may refer to learning or determining desired or optimal model parameters (e.g., weights, biases, etc.) based on training data. Fine-tuning a model may refer to a method of transfer learning in which model parameters (e.g., weights, etc.) of a pre-trained model are trained based on new training data. Optimizing a model may refer to training and / or fine-tuning a model.
[0042] It should be understood that the process flow 200 disclosed herein may be executed by one or more processors (e.g., Figure 1 a processor of one or more of devices 110, 120, 130, 140, and 150, Figure 4 405, and / or any other suitable processor), unless otherwise specified.
[0043] It should also be understood that the processing flow 200 may include one or more operations, actions, or functions, such as shown in one or more of blocks 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, and 290. These various operations, functions, or actions may correspond, for example, to software, program code, or program instructions executable by a processor that causes the functions to be implemented. Although illustrated as discrete blocks, obvious modifications may be made, for example, two or more of the blocks may be reordered; additional blocks may be added; and various blocks may be divided into additional blocks, combined into fewer blocks, or eliminated, depending on the desired implementation. It should be understood that prior to the processing flow 200, operations including initialization and the like may be implemented. For example, system parameters and / or application parameters may be initialized.
[0044] In an example embodiment, the sharded data parallel system includes device 1 and device 2. It should also be understood that Figure 2 Only an illustrative number of devices is shown. The embodiments described herein are not limited to the number of devices described. That is, the number of devices described herein is provided for the purpose of description only and is not intended to be limiting. It should be understood that blocks 205, 210, 215, 220, 225, 230, 235, 240, and 245 may be implemented on device 1 by a processor of device 1, including communicating with a processor (or) of other devices (or) . Blocks 250, 255, 260, 265, 270, 275, 280, 285, and 290 may be implemented on device 2 by a processor of device 2, including communicating with a processor (or) of other devices (or) . It should also be understood that the blocks implemented on device 1 may be symmetrical, identical, and / or similar to the blocks implemented on device 2. Therefore, only the blocks implemented on device 1 are described in detail below. Processing flow 200 may start at block 205.
[0045] At block 205 (Profiling), the processor may perform a model profiling execution of the machine learning model. In an example embodiment, the model profiling execution may be a single training or fine-tuning step that performs at least a forward operation (block 225) and a reverse operation (block 235) and / or other operations (e.g., 215, 220, 230, 240, and / or 245). It should be understood that Figure 3Blocks 310, 320, 330, and 340 of FIG. 2 also describe the operation of block 205. It should also be understood that the profiling results of the model profiling execution (described in detail below) may be the same or substantially the same in all devices in the sharded data parallel system. In an example embodiment, rather than performing the model profiling execution on all devices, the model profiling execution may be performed on one device, and the profiling results may be shared, transmitted, and / or sent to other devices. That is, block 250 may be optional for device 1 or device 2.
[0046] It should be understood that the profiling phase (block 205) of the process flow 200 is used to collect or obtain detailed information or data of the model execution. The collected or obtained information or data (e.g., profiling results from the model profiling execution) can be used to guide the configuration of the model's tensors into various blocks and / or guide the placement of the blocks within the GPU memory or CPU memory of the device.
[0047] In an example embodiment, the information or data collected or obtained during the profiling phase may include hookable attributes for each tensor. The hookable attributes of a tensor (and / or its modules) may be hookable attributes or unhookable attributes. It should be understood that none of the existing hooking mechanisms can register, install, arrange, or otherwise associate hooks (one or more) with all tensors or on all tensors. The attributes of a tensor (i.e., hookable attributes) are unhooked, indicating that the hook cannot be registered, installed, arranged, or otherwise associated with a tensor or on a tensor; or even if the hook is registered, installed, arranged, or otherwise associated with a tensor or on a tensor, the execution of the hook may still fail. It should also be understood that if the attributes of a tensor are unhooked, the internal state machine may be interrupted unless action is taken (e.g., manually changing the model definition, etc.). The attribute of a tensor that is hookable indicates that the hook can be registered, installed, arranged, or otherwise associated with a tensor or on a tensor, and the hook can be executed when the trigger condition is met.
[0048] It should be understood that the hookable properties of tensors can be determined or obtained in the forward operation phase (box 225) and the reverse operation phase (box 235) of the processing flow 200 by installing (or registering, arranging, or otherwise associating) various hooks (e.g., front forward hook, back forward hook, front reverse hook, back reverse hook, etc.) on all tensors before performing the operations in these phases.
[0049] In one example embodiment, the information or data collected or obtained during the profiling phase may include the execution status of each tensor. It should be understood that when triggered or executed, the handler of the back-end hook may record or determine whether the tensor has been executed in the model profiling execution. After the model profiling execution, the tensor may have an executed status or a not-executed status. The execution status may include the number of executions of the tensor in the model profiling execution (e.g., once, twice, or multiple times). The not-executed status may indicate that the tensor has not been executed in the model profiling execution.
[0050] In one example embodiment, the information or data collected or obtained during the profiling phase may include GPU memory usage (e.g., increase, etc.) during the forward operation phase and / or during the reverse operation phase. Such information or data may be used to determine memory usage for the execution model (e.g., for normal model execution), and / or determine the amount or number of chunks that may be stored in GPU memory for adaptive memory management.
[0051] In an example embodiment, the information or data collected or obtained during the profiling phase may include the execution sequence (or timestamps) of (executed) tensors in both the forward operation phase and the reverse operation phase of the model profiling execution, and include the execution sequence (or timestamps) of tensors recomputed in the reverse operation phase when the gradient checkpoint mode of the model is "enabled". It should be understood that when triggered or executed, the handler of the former forward hook and / or the handler of the former reverse hook may record or determine the execution order of the tensors. It should also be understood that when the gradient checkpoint mode is enabled, some intermediate results may be discarded, and some tensors may be recomputed in the reverse operation phase (which may be tracked, recorded or determined by, for example, the handler of the former forward hook of the tensor).
[0052] In one example embodiment, the information or data collected or obtained during the profiling phase may include a gradient checkpoint mode of the model. The gradient checkpoint mode may be "enabled" or "disabled". The gradient checkpoint mode may be determined by checking whether the forward hook of the tensor is triggered or executed during the reverse operation phase (e.g., which tensors (e.g., calculated or executed in the forward phase) are recalculated in the reverse phase). If the forward hook of the tensor is triggered or executed during the reverse operation phase, the gradient checkpoint mode may be enabled; otherwise, the gradient checkpoint mode may be disabled. The recalculation or re-execution information or data may be used to determine which tensors may be allocated or assigned to the same set of blocks (e.g., those tensors recalculated in the same phase (e.g., execution phase, execution phase, etc.), for example, in view of their recalculation or re-execution sequence, etc. In an example embodiment, the recalculation or re-execution information or data may be used to determine which tensor may be recalculated first in a certain phase (e.g., execution phase, execution phase, etc.), and hooks may be registered. Such tensors may be registered, installed, arranged, or otherwise associated with or on such tensors. It should be understood that when the gradient checkpoint mode is enabled, GPU memory usage may be reduced.
[0053] In one example embodiment, the information or data collected or obtained during the profiling phase may include the relationship between tensors and their corresponding modules (one or more) in the model. Such information (e.g., which tensors are included in which module, etc.) can be used to register, install, arrange or otherwise associate hook (one or more) with or on the module (instead of and / or in addition to registering, installing, arranging or otherwise associating hook (one or more) with or on the tensor).
[0054] It should be understood that in order to collect or obtain information or data of model execution, hooks (e.g., front forward hooks, rear forward hooks, front reverse hooks, rear reverse hooks, etc.) may need to be registered, installed, arranged, or otherwise associated with or on each of the tensors, and model profiling execution (including both the forward operation phase and the reverse operation phase) needs to be implemented.
[0055] It should also be appreciated that module-based hooks can be used to (1) control the number of hooks that need to be installed (or registered, placed, or otherwise associated with or on a module rather than associated with or on a tensor) to reduce the overhead of processing the hooks, and (2) reduce or eliminate the side effects of introducing memory allocations to change tensor properties.
[0056] It should also be understood that the model profiling execution may be implemented on the GPU of the device instead of the CPU. Implementing the model profiling execution on the CPU may take longer than implementing the model profiling execution on the GPU, and it may be difficult to determine, for example, the memory usage (e.g., increase, etc.) for the forward operation phase and the reverse operation phase of the normal execution of the model. Since the GPU may have a smaller memory capacity than the CPU, a block-based mechanism may be used by grouping tensors into chunks and loading the tensors into the GPU memory chunk by chunk. It should be understood that if some tensors are detachable and the detachable tensor is the first tensor in the chunk, the model profiling execution may fail because some tensors may be located in the CPU memory (e.g., cannot be loaded into the GPU memory). Therefore, a preloading mechanism can be used to solve this type of problem: when the hook of a tensor is triggered or executed, the current chunk of the tensor and its next chunk can be loaded into the GPU memory.
[0057] Figure 3 Blocks 310, 320, 330, and 340 also describe the operation of block 205. It should be understood that training data or non-training data can be used for model profiling execution. Processing can proceed from block 205 to block 210.
[0058] At block 210 (Slicing), the processor may (1) determine an optimal chunk size, and / or (2) assign, allocate, arrange, organize, or otherwise store tensors in different chunks (of the same chunk size) based on the profiling results of the model profiling performed at block 205. The processor may also register, install, arrange, or otherwise associate hooks (e.g., forward hooks, etc.) for selected tensors (and / or modules of selected tensors). It should be understood that Figure 3 Blocks 350, 360, 370, and 380 of FIG. 2 also describe the operation of block 210. It should also be understood that the sharding process (described in detail below) may be the same or substantially the same for all devices in the sharded data parallel system. In an example embodiment, rather than implementing the sharding process on all devices, the sharding process may be implemented on one device, and the results of the sharding process may be shared, transmitted, and / or sent to other devices. That is, block 255 may be optional for device 1 or 2.
[0059] In an exemplary embodiment, the processor may further distribute, shard, or divide the chunk into smaller parts, where the number of parts is the same as the number of devices in the sharded data parallel system. Figure 3 Processing may proceed from block 210 to block 215.
[0060] At block 215 (Model Sharding), a processor (of each device in a sharded data parallel system) may obtain a corresponding portion of the training data, and / or a corresponding shard or portion of a chunk, etc., for normal execution of the model to optimize, train, or fine-tune the model. Processing may proceed from block 215 to block 220.
[0061] At block 220 (All-Gather), the processor (of each device) may perform an "all-gather" operation to collect, obtain, receive, or retrieve other slices or portions of parameters (e.g., model parameters, etc.) from all devices, store the complete parameters in the device, and / or send the complete parameters to other devices. It should be understood that the complete parameters may be required for the normal execution of the model (e.g., for forward and reverse operations). Figure 2 As shown, for each group block, the processor may perform an all-gather operation to collect parameters from all devices in the same process group. Processing may proceed from block 220 to block 225.
[0062] In block 225 (forward), the processor (of each device) may perform a forward operation on the complete tensor (in the complete group block). During or before the forward operation phase, the handler (one or more) of the front forward hook (one or more) registered, installed, arranged or otherwise associated with the tensor and / or its module or on the tensor and / or its module may load the corresponding group block on demand. When triggered or executed, the back forward hook registered, installed, arranged or otherwise associated with the tensor and / or its module or on the tensor and / or its module may register, install and arrange or otherwise associate the front reverse hook with the tensor and / or its module or on the tensor and / or its module. After the forward operation phase, other slices or portions of the group block from other devices (collected tensors or parameters) may be released to save memory, and only the slices or portions of the group block of the device may be retained. Processing may proceed from block 225 to block 230.
[0063] The operations of block 230 may be substantially the same as the operations of block 220. At block 230 (All-Gather), the processor (of each device) may perform an "all-Gather" operation to collect, obtain, receive, or fetch other shards or portions of the chunk from all devices, store the complete chunk in the device, and / or send the complete chunk to other devices. It should be understood that while sharded chunks may save memory on the device, the complete chunk (containing the complete tensor) may be required for normal execution of the model (e.g., forward and reverse operations). Figure 2 As shown, for each group block, the processor may perform an all-gather operation to collect parameters from all devices in the same process group. Processing may proceed from block 230 to block 235.
[0064] In block 235 (Reverse), the processor (of each device) may perform a reverse operation on the complete tensor (in a complete group of blocks). During or before the reverse operation phase, the handler (one or more) that registers, installs, arranges, or otherwise associates with the tensor and / or its modules or the front reverse hook (one or more) on the tensor and / or its modules may load the corresponding group of blocks and save the generated gradients in the back reverse handler. In an example embodiment, when triggered or executed, the handler (one or more) that registers, installs, arranges, or otherwise associates with the tensor and / or its modules or the back reverse hook (one or more) on the tensor and / or its modules may copy the gradients to the same location as the FP16 parameters to save memory. Processing may proceed from block 235 to block 240.
[0065] At block 240 (Reduce-Scatter), the processor (of each device) may perform a "reduce-scatter" operation to (1) collect or obtain gradients from other devices and combine them into a global result through a selected operator (e.g., sum, average, etc.), for example, and (2) distribute or shard the combined gradients from the device to other devices. It should be understood that the combined gradients may be sharded across all devices in the same process group so that each device may update the weights of each local shard accordingly. Processing may proceed from block 240 to block 245.
[0066] At block 245 (Update Weights), the processor (of each device) may update the weights of its local shard (and / or other parameters of the model). One cycle of normal execution of the model may include operations from blocks 205, 210, 215, 220, 225, 230, 235, 240, and 245. Processing may return from block 245 to block 205 for the next cycle of normal execution of the model.
[0067] Figure 3 is a flow chart illustrating an example process flow 300 for implementing operations of the profiling phase (block 205 ) and operations of the sharding phase (block 210 ) in accordance with at least some embodiments described herein.
[0068] It should be understood that the process flow 300 disclosed herein may be executed by one or more processors (e.g., Figure 1 a processor of one or more of the devices 110, 120, 130, 140, and 150, Figure 4 or GPU 405 and / or any other suitable processor), unless otherwise specified.
[0069] It should also be understood that the processing flow 300 may include one or more operations, actions, or functions shown in one or more boxes 310, 320, 330, 340, 350, 360, 370, and 380. These various operations, functions, or actions may, for example, correspond to software, program code, or program instructions that can be executed by a processor, which causes the functions to be implemented. Although illustrated as discrete boxes, obvious modifications may be made, for example, two or more of the boxes may be reordered; additional boxes may be added; and various boxes may be divided into additional boxes, combined into fewer boxes, or eliminated, depending on the desired implementation. It should be understood that prior to the processing flow 300, operations including initialization and the like may be implemented. For example, system parameters and / or application parameters may be initialized. For example, models may be created, training data may be prepared, etc. Boxes 310, 320, 330, and 340 illustrate Figure 2 The operation of block 205 (analysis), blocks 350, 360, 370 and 380 illustrate Figure 2 The process flow 300 may start from block 310 .
[0070] In block 310 (packing tensors), the processor may assign, distribute, arrange, organize, or otherwise store tensors in different chunks (of the same chunk size) for model profiling execution based on, for example, the initialization sequence of the tensors or any other suitable sequence. It should be understood that the initialization sequence of the tensors may be significantly different from the actual execution sequence of the tensors. That is, the actual execution of the model may require constantly jumping from tensors in one chunk to tensors in another chunk, resulting in locality issues and inefficiency. Compared to methods that arrange chunks or tensors based on the execution sequence of chunks or tensors, locality issues may also require loading multiple chunks at the same time, resulting in higher memory overhead. Since the execution sequence can be determined in blocks 330 and 340, block 360 may assign, distribute, arrange, organize, or otherwise store tensors in different chunks (of the same chunk size) based on, for example, the execution sequence of the tensors.
[0071] It should be understood that at block 310, the chunk size may be any size within a range of suitable chunk sizes for model profiling execution (e.g., between a minimum allowed chunk size and a maximum allowed chunk size). An optimal chunk size for normal execution of the model may be determined at block 350. The processor may also preload some chunks into GPU memory. Processing may proceed from block 310 to block 320.
[0072] At block 320 (Arrange Hooks for Profiling), the processor may register, install, arrange, or otherwise associate various hooks (e.g., front forward hook, back forward hook, front reverse hook, back reverse hook, etc.) with or on all tensors.
[0073] It should be understood that the handler of the pre-forward hook, when triggered or executed (e.g., just before the forward operation), can record or determine the corresponding tensor, the module of the tensor, the execution stage of the tensor (e.g., in the forward operation stage or the reverse operation stage), etc. It should also be understood that when the gradient checkpoint mode of the model is enabled, some intermediate results may be discarded and some tensors need to be recalculated in the reverse stage (which can be tracked or recorded by, for example, the handler (one or more) of the pre-forward hook). For the forward operation, the processor can also preload several blocks to avoid training failure when the corresponding tensor (typically the first tensor in the block) is not loaded into the GPU memory. The handler of the pre-reverse hook, when triggered or executed (e.g., immediately before the reverse operation), can record or determine the relationship between the tensor and its module. The handler of the post-reverse hook, when triggered or executed (e.g., immediately after the reverse operation), can (1) record or determine the execution status of the tensor (e.g., whether the tensor is executed), and / or (2) collect or obtain the gradient generated in the reverse operation stage. It should be understood that even if a tensor is executed multiple times, the corresponding back-forward hook can be triggered or executed after the last execution of the tensor. That is, in the back-forward hook handler, the gradient is ready to be saved, obtained, or collected. The handler of the back-forward hook, when triggered or executed (e.g., during a forward operation), can register, install, arrange, or otherwise associate the front-forward hook with or on the tensor and / or its modules. Processing can proceed from block 320 to block 330.
[0074] At block 330 (Execute Model for Profiling), the processor may implement a model profiling execution in which hooks are registered, installed, deployed, or otherwise associated with or on tensors and / or their modules. Processing may proceed from block 330 to block 340.
[0075] At block 340 (Generate Profiling Results), the processor (and / or hooked processors, when triggered or executed) may generate, obtain, record and / or store profiling results from the model profiling execution (see Figure 2 Processing may proceed from block 340 to block 350.
[0076] At block 350 (Determine Chunk Size), the processor may determine the optimal size of the chunks so that the total memory waste of the chunks may be minimized. It should be understood that the processor may assign, allocate, arrange, organize, or otherwise store tensors in different chunks (with the same chunk size). It should also be understood that after tensors are assigned, allocated, arranged, organized, or otherwise stored in chunks, the memory waste of a chunk may represent free or unused space of the chunk.
[0077] It should be understood that the chunk size may have a desired or predetermined range, for example, between a minimum allowable chunk size MIN (e.g., 128 megabytes, etc.) and a desired chunk size greater than the MIN (e.g., a maximum allowable chunk size MAX (e.g., 256 megabytes, etc.)). In order to simplify the process of determining the optimal chunk size, recursive tensors (tensors that are executed once or more than twice) or detachable tensors may be placed in unsharded special chunks (or GPU memory) without affecting the determination of the optimal chunk size, and other tensors may be organized into chunks based on the execution order of their forward operations. Tensors that meet the following conditions may also be placed in the same group block: (1) tensors of the same module of the model, which can be identified or determined by parsing the name of each tensor - for example, tensors with the same module name can be identified as being in the same module, and (2) tensors that are recomputed in the same stage during the reverse operation - by placing these tensors in the same group block, only the forward hook may need to be registered, installed, arranged, or otherwise associated with or on the first tensor in such a group of tensors. It should be understood that when the gradient checkpoint mode of the model is enabled, the forward operation of such tensors may be recomputed during the reverse operation; similarly, setting the forward hook on the first tensor may be sufficient to ensure that all tensors recomputed in the same stage are loaded into GPU memory (e.g., before the tensor is recomputed or re-executed in the reverse operation stage).
[0078] It should also be understood that the optimal chunk size may be larger than the maximum size of each group of tensors that satisfies the above conditions.
[0079] It should also be understood that during the determination process of identifying or determining the optimal chunk size, multiple possible chunk sizes may be obtained. The total waste of each possible chunk size may be calculated or determined, and the chunk size with the least waste may be the optimal chunk size.
[0080] In an exemplary embodiment, the processor may start with the minimum allowed chunk size MIN as the chunk size, and for each cycle of determining the chunk size, increase the chunk size by a predetermined size (e.g., 1k bytes, etc.). For each chunk size in each cycle of determining the chunk size, the processor may check all tensor groups in the tensor group list, where tensors that meet the above conditions (e.g., need to be executed together, etc.) are organized in the same group. If all tensors of the current tensor group list can be packed into the current chunk (with the current possible chunk size), the processor may add all tensors of the tensor group to the current chunk and then update the size of the current chunk; otherwise, the processor may stop or close the current chunk and add all tensors of the tensor group to the next chunk. When stopping or closing the current chunk, the processor may calculate the memory waste of the current chunk. At the end of the chunk size determination process, the processor may select the list of chunks with the smallest waste as the optimal chunk configuration, and select the corresponding chunk size as the optimal chunk size. Processing may proceed from box 350 to box 360.
[0081] At block 360 (Assign Tensors), the processor may assign, allocate, arrange, organize, or otherwise store the tensors in the chunks (with the optimal chunk size) determined at block 350. Figure 2 As discussed in block 350 and / or block 205, for example, based on the hookable property of the tensor, the processor may arrange the chunks accordingly by, for example, placing the hookable tensor at the first or last position of each chunk and / or not placing the unhookable tensor at the first or last position of each chunk, because the processor may install (or register, arrange, or otherwise associate) hooks on the first tensor of each chunk (for the forward operation phase) and the last tensor of each chunk (for the reverse operation phase). If a tensor is defined but never executed during model analysis execution, the processor may not include such a tensor in the chunk, because the tensor may confuse checking whether the chunk needs to be reduced after the reverse operation phase (see Figure 2 The processor may also maintain a mapping between each tensor and its chunks so that the processor can quickly obtain chunks of each tensor during the forward operation phase and the reverse operation phase. Processing may proceed from block 360 to block 370.
[0082] In block 370 (distribute chunks), the processor may distribute or slice each chunk to divide or partition each chunk into smaller slices or parts, wherein the number of slices or parts may be the same as the number of devices in the same process group. Each device may only hold one slice of the chunk (one or more). In an example embodiment, a single program multiple data implementation may be implemented, and all devices may have the same program (e.g., the same machine learning model, etc.). That is, each device may retain its own slice of the chunk (a slice containing tensors or parameters), and, for example, discard slices of other chunks after forward and / or reverse operations. Processing may proceed from block 370 to block 380.
[0083] At block 380 (arranging hooks for normal execution), the processor may register, install, arrange, or otherwise associate the front forward hook and / or the back forward hook with or on the selected tensor and / or its module. It should be understood that at the end of the slicing phase, the processor may register, install, arrange, or otherwise associate some hooks on the selected tensor so that the corresponding group block can be loaded (e.g., loaded into GPU memory), and the front reverse hook can be installed (or registered, arranged, or otherwise associated) in time in the forward operation phase.
[0084] In an exemplary embodiment, the selected tensors on which the hooks may be registered, installed, arranged, or otherwise associated are as follows: (1) the first tensor of each block - by installing (or registering, arranging, or otherwise associating) the hooks on these tensors, the corresponding blocks can be loaded (e.g., loaded into GPU memory) before being accessed in the forward operation phase; (2) the first tensor of each group of tensors that can be recomputed (e.g., in the same phase, etc.) in the reverse operation phase - by installing (or registering, arranging, or otherwise associating) the hook on the first tensor, it is ensured that the corresponding tensor can be loaded into GPU memory before the tensors are recomputed for the model when the gradient checkpoint mode is enabled; and (3) the last tensor of each block - when the gradient checkpoint mode is not enabled (or disabled), installing (or registering, arranging, or otherwise associating) the hook on the last tensor (because it can be accessed first in the reverse operation phase) ensures that the corresponding block can be loaded into GPU memory in the pre-reverse operation (i.e., before the reverse operation) phase. It should be appreciated that by installing (or registering, arranging, or otherwise associating) hooks on selected tensors (and / or allocating or assigning tensors to blocks based on the order in which the tensors are executed or re-executed), memory usage may be reduced, system efficiency and execution speed may be improved, and the need to change model definitions may be reduced or eliminated (e.g., due to unhooked tensors). Processing may proceed from block 380 to, for example, Figure 2 Frame 215.
[0085] The features in the embodiments disclosed herein can effectively utilize network bandwidth, reduce communications, and avoid potential memory fragmentation, thereby improving bandwidth utilization between CPU-GPU and GPU.
[0086] Features in the embodiments disclosed herein can greatly speed up the training of large machine learning models by allowing multiple devices to process different parts of the data in parallel, and can be particularly effective for tasks such as image or speech recognition, natural language processing, and / or recommendation systems.
[0087] Features in the embodiments disclosed herein may introduce a profiling phase before actual or normal model execution to collect details of tensor execution, and introduce a sharding phase to arrange tensors into chunks based on their execution order and properties, thereby overcoming locality issues. Features in the embodiments disclosed herein may handle some decoupled tensors (identified via the profiling phase) separately—these tensors may always be kept in GPU memory, or hidden in the middle of chunks based on their execution order. Features in the embodiments disclosed herein may determine or predict the total memory usage of intermediate results, where such information may allow prediction of total memory usage during forward and reverse operations, and allow some chunks of model state (parameters, optimizer state) to be moved or kept in GPU memory.
[0088] Figure 4 An electronic device (e.g., Figure 1 400 is a schematic block diagram of an example computer system 400 of the device shown in FIG. Figure 4 The computer system shown is for illustration only and is not intended to limit the functionality and applicability of the embodiments described herein.
[0089] As shown, the computer system 400 may include a central processing unit (CPU) or a graphics processing unit (GPU) 405. The CPU or GPU 405 may perform various operations and processes based on a program stored in a read-only memory (ROM) 410 or a program loaded from a storage device 440 to a random access memory (RAM) 415. The RAM 415 may also store various data and programs required for the operation of the system 400. The CPU or GPU 405, the ROM 410, and the RAM 415 may be connected to each other via a bus 420. An input / output (I / O) interface 425 may also be connected to the bus 420.
[0090] Components connected to the input / output interface 425 may also include input devices 430, including keyboards, mice, digital pens, drawing tablets, etc.; output devices 435, including displays such as liquid crystal displays (LCDs), speakers, etc.; storage devices 440 including hard disks, etc.; and communication devices 445 including network interface cards such as LAN cards, modems, etc. The communication device 445 may implement communication processing via networks such as the Internet, WAN, LAN, LIN, clouds, etc. In one embodiment, a drive 450 may also be connected to the I / O interface 425. Removable media 455 such as magnetic disks, optical disks, magneto-optical disks, semiconductor memories, etc. may be installed on the drive 450 as needed, so that a computer program read from the removable media 455 may be installed in the storage device 440.
[0091] It should be understood that reference Figure 3 Flowchart describing the process and / or Figure 2 The described process may be implemented as a computer software program or hardware. A computer program product may include a computer program stored in a computer-readable non-volatile medium. The computer program includes program code for implementing the method shown in the flowchart and / or GUI. In this embodiment, the computer program may be downloaded and installed from a network via a communication device 445, and / or may be installed from a removable medium 455. When executed by a central processing unit (CPU) or a graphics processing unit (GPU) 405, the computer program may implement the above-mentioned functions specified in the method in the embodiments disclosed herein.
[0092] Features in the embodiments disclosed herein can improve optimization, training, or fine-tuning of chunk-based sharded data parallelism, for example, by introducing a profiling phase before normal model execution to collect, obtain, or determine all execution details of tensors, and by using the profiling results of the profiling phase to guide the placement of all tensors into corresponding chunks and guide adaptive memory management.
[0093] Features in embodiments disclosed herein may collect, obtain, or determine all details of model execution during the profiling phase, including (1) which tensors are hookable in forward and reverse operations via installing (or registering, arranging, or otherwise associating) module-based hooks during the profiling phase, (2) which tensors have been executed during the profiling phase via installing (or registering, arranging, or otherwise associating) post-reverse hooks, (3) GPU memory usage (e.g., GPU memory increases during forward operations), (4) the execution order of tensors in forward and reverse operations, including the execution order of tensors recomputed in the reverse operation phase when gradient checkpointing mode is enabled, (5) enabling gradient checkpointing mode by checking whether the pre-forward hook is triggered or executed during the reverse operation phase, and / or (6) the relationship between tensors and their corresponding modules, where such information can be used to install (or register, arrange, or otherwise associate) hooks on the modules.
[0094] Features in the embodiments disclosed herein can organize the tensors of a block for actual training and fine-tuning based on the profiling results before the model is normally executed, wherein (1) tensors are organized in the same order as their execution order, solving the locality problem of the block (and improving throughput) and reducing GPU memory consumption, (2) multiple tensors of the same module are assigned to the same block, (3) tensors recalculated in the same execution stage are assigned to the same block, (4) tensors executed multiple times can be saved in GPU memory (rather than in sharded blocks), and (5) decoupled tensors can be saved in GPU memory or packed in the middle of a block.
[0095] Features in the embodiments disclosed herein may install (or register, arrange, or otherwise associate) module-based hooks on tensors and / or their modules based on the arrangement of blocks, where (1) the first tensor in the block may have a front forward hook installed (or registered, arranged, or otherwise associated), the last tensor in the block may have a front reverse hook installed (or registered, arranged, or otherwise associated), and (2) the first tensor of tensors recomputed in the same stage during a reverse operation may have a front reverse hook installed (or registered, arranged, or otherwise associated), and installing (or registering, arranging, or otherwise associated) selected hooks on selected tensors / modules may significantly reduce the number of hooks and avoid unnecessary overhead in processing hooks.
[0096] Features in the embodiments disclosed herein can predict the number of chunks that can be placed in the GPU based on the profiling results (including their tensors, such as FP32 / FP16 parameters and optimizer states), which can significantly reduce the amount of memory copying between GPU memory and CPU memory, and can further improve optimization by using existing optimizers. Features in the embodiments disclosed herein can calculate the potential memory increase for normal execution (mainly for storing intermediate results) and the available remaining GPU memory, and then calculate the volume of the chunks to be stored in the GPU memory for adaptive memory management. It should be understood that compared with existing mechanisms, the adaptive memory management disclosed herein can reduce memory consumption by offloading part of the data and calculations from the GPU to the CPU, while taking into account the available GPU memory usage, retaining as much data and calculations as possible in the GPU to reduce the amount of memory copying between the GPU memory and the CPU memory, maximizing the utility of the GPU to improve performance, reducing the specific configuration of the chunks retained in the GPU memory (e.g., by using the profiling results to predict GPU memory usage, etc.), to avoid insufficient memory problems caused by incorrect configuration of the remaining chunks in the GPU memory, and achieve optimal throughput.
[0097] It should be understood that the disclosure and other solutions, examples, embodiments, modules and functional operations described in this document may be implemented in digital electronic circuit devices, or in computer software, firmware or hardware, including the structures disclosed in this document and their structural equivalents, or in a combination of one or more of them. The disclosed and other embodiments may be implemented as one or more computer program products, i.e., one or more modules of computer program instructions encoded on a computer-readable medium, for execution by a data processing device or for controlling the operation of the data processing device. The computer-readable medium may be a machine-readable storage device, a machine-readable storage substrate, a memory device, a material combination that implements a machine-readable propagation signal, or a combination of one or more of them. The term "data processing device" covers all devices, equipment and machines for processing data, including, for example, a programmable processor, a computer or multiple processors or computers. In addition to hardware, the device may include code that creates an execution environment for the computer program in question, for example, code that constitutes processor firmware, a protocol stack, a database management system, an operating system, or a combination of one or more of them.
[0098] A computer program (also referred to as a program, software, software application, script, or code) may be written in any form of programming language, including compiled or interpreted languages, and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for a computing environment. A computer program does not necessarily correspond to a file in a file system. A program may be stored in a portion of a file that holds other programs or data (e.g., one or more scripts stored in a markup language document), in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or portions of code). A computer program may be deployed to execute on one computer or multiple computers located at one location or distributed across multiple locations and interconnected by a communications network.
[0099] The processes and logic flows described in this document may be implemented by one or more programmable processors executing one or more computer programs to perform functions by operating on input data and generating output. The processes and logic flows may also be implemented by special purpose logic circuit devices, and the devices may also be implemented as special purpose logic circuit devices, such as field programmable gate arrays, application specific integrated circuits, etc.
[0100] Processors suitable for executing computer programs include, for example, general and special purpose microprocessors, and any one or more processors of any type of digital computer. In general, the processor will receive instructions and data from a read-only memory or a random access memory or both. The basic elements of a computer are a processor for implementing instructions and one or more memory devices for storing instructions and data. In general, the computer will also include or be operably coupled to one or more mass storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, to receive data from or transfer data to them, or both. However, the computer does not need to have such devices. Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and memory devices, including, for example, semiconductor memory devices, such as erasable programmable read-only memory, electrically erasable programmable read-only memory, and flash memory devices; magnetic disks, such as internal hard disks or removable disks; magneto-optical disks; and digital video disk read-only memory disks. The processor and memory may be supplemented by or incorporated into a dedicated logic circuit device.
[0101] It should be understood that various features, variations, and multiple different embodiments have been shown and described in various details. What is described in this application according to specific embodiments is for illustrative purposes only and is not intended to limit or imply that only one specific embodiment or multiple specific embodiments are envisioned. It should be understood that the present disclosure is not limited to any single specific embodiment or the variations listed. Many modifications, variations, and other embodiments will occur to those skilled in the art, and these modifications, variations, and other embodiments are intended to and are in fact covered by the present disclosure. The scope of the present disclosure is actually intended to be determined by the appropriate legal description and interpretation of the present disclosure, including equivalents, as understood by those skilled in the art based on the complete disclosure presented at the time of submission.
[0102] aspect:
[0103] It should be understood that any aspects may be combined with each other.
[0104] Aspect 1. A method for training a machine learning model on multiple devices in parallel, the method comprising: implementing a model profiling execution before normal execution of the model; allocating the model's tensors into multiple blocks based on profiling results from the model profiling execution; and implementing normal execution of the model on multiple devices in parallel to train the model.
[0105] Aspect 2. A method according to Aspect 1, wherein the implementation of model profiling execution includes executing the model to determine the hookable properties of tensors; determining the execution state of the tensors; determining the memory usage of the model profiling execution; determining the execution sequence of the tensors; determining the gradient checkpoint mode of the model; and determining the module of the model of the tensors.
[0106] Aspect 3. A method according to Aspect 2, wherein allocating tensors of a model to groups based on profiling results includes: arranging tensors in the same sequence as the execution sequence; allocating tensors in the same module to the same group block; allocating tensors recalculated in the same stage to the same group block; allocating tensors with multiple execution states in GPU memory; and allocating tensors with hookable attributes as detachable in GPU memory or in the middle of a group block.
[0107] Aspect 4. The method according to any one of Aspects 2 or 3 further comprises: determining the location of the block of normal execution of the model based on the memory usage of the model profiling execution.
[0108] Aspect 5. A method according to any one of Aspects 1-4, wherein the implementation of normal execution of the model on multiple devices in parallel includes: distributing training data among multiple devices; collecting parameters from multiple devices; implementing a forward operation based on the collected parameters; and releasing the collected parameters after the implementation of the forward operation.
[0109] Aspect 6. A method according to any one of Aspects 1-5, wherein the implementation of normal execution of the model on multiple devices in parallel includes: distributing training data among multiple devices; collecting parameters from multiple devices; implementing a reverse operation based on the collected parameters; and releasing the collected parameters after the implementation of the reverse operation.
[0110] Aspect 7. The method according to any one of aspects 1-6, wherein the implementation of normal execution of the model on multiple devices in parallel includes: distributing gradients among the multiple devices; and updating parameters of the model.
[0111] Aspect 8. The method according to any one of aspects 1-7, further comprising: distributing the chunks among a plurality of devices.
[0112] Aspect 9. The method according to aspect 8, wherein the implementation of the normal execution of the model includes: executing the model on each of the plurality of devices based on the distributed blocks.
[0113] Aspect 10. The method according to any one of aspects 1-9, further comprising: placing a hook on a portion of the tensor in the chunk based on the allocation of the tensor.
[0114] Aspect 11. A method according to Aspect 10, wherein the arrangement of hooks includes: arranging a front forward hook on the first tensor in the group block; arranging a front reverse hook on the last tensor in the group block; and arranging a front reverse hook on the first tensor of tensors recalculated in the same stage.
[0115] Aspect 12. The method according to any one of aspects 1-11, wherein the implementation of normal execution of the model on multiple devices in parallel includes: implementing normal execution of the model based on profiling results from pattern profiling execution and tensor allocation.
[0116] Aspect 13. The method according to any one of aspects 1-12, further comprising: distributing the chunks having the allocated tensors among a plurality of devices.
[0117] Aspect 14. A machine learning model training system, the system comprising: a memory for storing a machine learning model; at least one processor for: performing model profiling execution before normal execution of the model; allocating the model's tensors into blocks based on profiling results from the model profiling execution; and performing normal execution of the model on multiple devices in parallel to train the model.
[0118] Aspect 15. A system according to Aspect 14, wherein at least one processor further executes the model to determine the hookable properties of a tensor; determine the execution state of the tensor; determine the memory usage of the model profiling execution; determine the execution sequence of the tensor; determine the gradient checkpoint mode of the model; and determine the module of the model of the tensor.
[0119] Aspect 16. A system according to Aspect 15, wherein at least one processor additionally: arranges tensors in the same sequence as the execution sequence; allocates tensors in the same module to the same group block; allocates tensors recomputed in the same stage to the same group block; allocates tensors with multiple execution states in GPU memory; and allocates tensors with hookable properties as unhookable in GPU memory or in the middle of a group block.
[0120] Aspect 17. The system according to aspect 15 or aspect 16, wherein the at least one processor further: determines the location of the chunks of the normal execution of the model based on the memory usage of the model profiling execution.
[0121] Aspect 18. The system according to any one of aspects 14-17, wherein the at least one processor is further configured to: place a hook on a portion of the tensor in the chunk based on the allocation of the tensor.
[0122] Aspect 19. A system according to Aspect 18, wherein at least one processor is further used to: place a forward hook on the first tensor in the group block; place a forward reverse hook on the last tensor in the group block; and place a forward reverse hook on the first tensor of tensors recomputed in the same stage.
[0123] Aspect 20. A non-temporary computer-readable medium having computer-executable instructions stored thereon, which when executed cause one or more processors to perform operations, the operations comprising: performing a model profiling execution before normal execution of the model; allocating tensors of a machine learning model into blocks based on profiling results from the model profiling execution; and performing normal execution of the model on multiple devices in parallel to train the model.
[0124] Aspect 21. A computer-readable medium according to Aspect 20, wherein the implementation of the model profiling execution includes executing the model to determine the hookable properties of tensors; determining the execution state of the tensors; determining the memory usage of the model profiling execution; determining the execution sequence of the tensors; determining the gradient checkpoint mode of the model; and determining the module of the model of the tensors.
[0125] Aspect 22. A computer-readable medium according to Aspect 21, wherein allocating tensors of a machine learning model to blocks based on the profiling results includes: arranging tensors in the same sequence as the execution sequence; allocating tensors in the same module to the same block; allocating tensors recalculated in the same stage to the same block; allocating tensors with multiple execution states in GPU memory; and allocating tensors with hookable properties as detachable in GPU memory or in the middle of a block.
[0126] Aspect 23. The computer-readable medium of aspect 21 or aspect 22, wherein the operation further comprises: determining the location of the chunks of the normal execution of the model based on the memory usage of the model profiling execution.
[0127] Aspect 24. The computer-readable medium of any one of aspects 20-23, the operations further comprising: placing hooks on a portion of the tensor in the chunk based on the allocation of the tensor.
[0128] Aspect 25. A computer-readable medium according to Aspect 24, wherein the arrangement of hooks includes: arranging a front forward hook on the first tensor in the group block; arranging a front reverse hook on the last tensor in the group block; and arranging a front reverse hook on the first tensor of tensors recomputed in the same stage.
[0129] The terms used in this specification are intended to describe specific embodiments and are not intended to be limiting. The terms "a / an" and "the" also include plural forms unless otherwise expressly indicated. When used in this specification, the terms "comprises" and / or "comprising" specify the presence of stated features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements and / or components.
[0130] With respect to the foregoing description, it should be understood that modifications may be made to the details, particularly the shapes, sizes and arrangements of the construction materials and components employed, without departing from the scope of the invention. This specification and the embodiments described are exemplary only, with the true scope and spirit of the disclosure being indicated by the appended claims.
Claims
1. A method for training a machine learning model in parallel on multiple devices, the method include: Implement model profiling execution before normal model execution; Distributing tensors of the model into a plurality of chunks based on profiling results from an execution of the profiling of the model; as well as The normal execution of the model is performed on the multiple devices in parallel to train the model.
2. The method of claim 1 , wherein the performing of the model profiling execution comprises executing the model to: determining hookable properties of the tensor; determining an execution state of the tensor; determining memory usage of the model profiling execution; determining an execution sequence of the tensor; determining a gradient checkpointing mode for the model; as well as A module of the model is determined for the tensor.
3. The method according to claim 2, wherein the tensors of the model are allocated to the blocks based on the profiling results. Includes: Arranging the tensors in a sequence identical to the execution sequence; Allocate the tensors in the same module into the same group block; Allocating the tensors to be recomputed in the same stage into the same group of blocks; allocating said tensor with a multi-execution state in memory; as well as The tensor having the hookable attribute is allocated as unhookable in the memory or in the middle of the chunk.
4. The method according to claim 2, further comprising: include: Based on the memory usage of the model profiling execution, locations of the chunks normally executed for the model are determined.
5. The method according to claim 1, further comprising: include: Based on the allocation of the tensor, a hook is placed on a portion of the tensor in the chunk.
6. The method according to claim 5, wherein the arrangement of the hooks include: placing a forward hook on a first tensor in the group; placing a forward reverse hook on the last tensor in the group block; as well as Place a forward reverse hook on the first tensor of the tensors being recomputed in the same stage.
7. The method according to claim 1, wherein the model is normally executed on the multiple devices in parallel Includes: Based on the profiling results from the model profiling execution and the allocation of the tensors, normal execution of the model is performed.
8. The method according to claim 1, further comprising: include: The chunks having the allocated tensors are distributed among the plurality of devices.
9. A machine learning model training system, the system Includes: Memory, used to store machine learning models; At least one processor configured to: Implement model profiling execution before normal model execution; allocating tensors of the model into chunks based on profiling results from an execution of the profiling of the model; as well as The normal execution of the model is performed in parallel on multiple devices to train the model.
10. The system of claim 9, wherein the at least one processor further executes the model to: determining hookable properties of the tensor; determining an execution state of the tensor; determining memory usage of the model profiling execution; determining an execution sequence of the tensor; determining a gradient checkpointing mode for the model; as well as A module of the model is determined for the tensor.
11. The system of claim 10, wherein the at least one processor is further configured to: Arranging the tensors in a sequence identical to the execution sequence; Allocate the tensors in the same module into the same group block; Allocating the tensors to be recomputed in the same stage into the same group of blocks; allocating said tensor with a multi-execution state in memory; as well as The tensor having the hookable attribute is allocated as unhookable in the memory or in the middle of the chunk.
12. The system of claim 10, wherein the at least one processor is further configured to: Based on the memory usage of the model profiling execution, locations of the chunks normally executed for the model are determined.
13. The system of claim 9, wherein the at least one processor is further configured to: Based on the allocation of the tensor, a hook is placed on a portion of the tensor in the chunk.
14. The system of claim 13, wherein the at least one processor is further configured to: placing a forward hook on a first tensor in the group; placing a forward reverse hook on the last tensor in the chunk; and Place a forward reverse hook on the first tensor of the tensors being recomputed in the same stage.
15. A non-transitory computer-readable medium having computer-executable instructions stored thereon, the instructions causing one or more processors to perform operations when executed, the operations include: Implement model profiling execution before normal model execution; Allocating tensors of the machine learning model into chunks based on profiling results from the model profiling execution; as well as The normal execution of the model is performed on multiple devices in parallel to train the model.
16. The computer-readable medium of claim 15, wherein the implementation of the model profiling execution comprises executing the model to: determining hookable properties of the tensor; determining an execution state of the tensor; determining memory usage of the model profiling execution; determining an execution sequence of the tensor; determining a gradient checkpointing mode for the model; as well as A module of the model is determined for the tensor.
17. The computer-readable medium of claim 16, wherein the tensors of the machine learning model are allocated to the blocks based on the profiling results. include: Arranging the tensors in a sequence identical to the execution sequence; Allocate the tensors in the same module into the same group block; Allocating the tensors to be recomputed in the same stage into the same group of blocks; allocating said tensor with a multi-execution state in memory; as well as The tensor having the hookable attribute is allocated as unhookable in the memory or in the middle of the chunk.
18. The computer readable medium of claim 16, wherein the operation further comprises: include: Based on the memory usage of the model profiling execution, locations of the chunks normally executed for the model are determined.
19. The computer readable medium of claim 15, wherein the operation further comprises: include: Based on the allocation of the tensor, a hook is placed on a portion of the tensor in the chunk.
20. The computer-readable medium of claim 19, wherein the arrangement of the hooks include: placing a forward hook on a first tensor in the group; Arrange the forward reverse hook on the last tensor in the group block; as well as Place a forward reverse hook on the first tensor of the tensors being recomputed in the same stage.
Citation Information
Patent Citations
Multithreading processor dynamic EMS memory management system and method
CN101055533A
Distributed model parallel equipment allocation optimization method based on equipment equalization principle
CN113052332A
Method, system and equipment for breaking through memory limitation in parallel training and storage medium
CN114880130A
Model training method and related device
CN115114927A
Biodegradable resin compositions including polyvinylalcohol and manufacturing methods thereof
KR102579310B1
