A data processing method and related apparatus
By dividing the input data into multiple data segments and performing inference in multiple processing units, the inference time for each data segment is made similar, which solves the problem of uneven computational load caused by inconsistent input request lengths in artificial intelligence models, reduces synchronization waiting overhead, and improves the utilization efficiency of computing resources.
Patent Information
- Application Number
- CN202510691266.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-27
- Publication Date
- 2026-11-27
Smart Images

Figure CN123178044A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a data processing method and related apparatus. Background Technology
[0002] In business scenarios involving artificial intelligence (AI) models, the lengths of different input requests vary. When multiple input requests are integrated into data batches and processed in parallel across multiple processing units, the inconsistent lengths of these requests lead to uneven computational loads and synchronization waiting overhead between different processing units. Therefore, a data processing method is needed to reduce the synchronization waiting overhead caused by inconsistent input request lengths. Summary of the Invention
[0003] To address the aforementioned problems, this application provides a data processing method and related apparatus to reduce the synchronization waiting overhead caused by inconsistent input request lengths.
[0004] Therefore, the following technical solution is adopted in this application:
[0005] Firstly, this application provides a data processing method, comprising: acquiring N input data; dividing each input data into P data segments to obtain N first data segment groups; and performing inference in P processing units based on the N first data segment groups, so that different data segments in each first data segment group are processed by different processing units. The N first data segment groups correspond one-to-one with the N input data, and the inference time for each data segment in the P data segments of an input data is approximately equal. N and P are positive integers greater than 1.
[0006] In this application, multiple input data are segmented, allowing different data segments of the same input data to be inferred in different processing units. Since the inference time of different data segments of the same input data is similar, the inference time of different processing units is also basically similar, thereby alleviating the problem of uneven computational load between different processing units and reducing the synchronization waiting overhead between different processing units.
[0007] In one possible implementation, the above-mentioned process of dividing each input data into P data segments to obtain N first data segment groups further includes: evaluating the first inference duration of each input data; determining the second inference duration of each data segment in the P data segments based on the first inference duration and the number of processing units P; and dividing each input data into N first data segment groups based on the second inference duration.
[0008] In this implementation, the method for segmenting the input data is illustrated exemplarily. First, the first inference time for each input data segment can be evaluated. The first inference time can be understood as the time taken to infer the input data from one inference position to another. Based on the first inference time and the number of processing units P, the second inference time for each of the P data segments is determined. The input data is inferred in the P processing units. To balance the inference time of each processing unit, the second inference time is obtained, which is the average inference time of each processing unit. Then, based on the second inference time, each input data segment is segmented so that the inference time of each segment is close to the second inference time; thus, the inference time of each data segment will be similar. This results in N groups of first data segments. In this way, by using the second inference time as a reference, it is not necessary to first randomly segment the data and then make the inference time of each data segment similar, thereby improving the efficiency of input data segmentation.
[0009] In one possible implementation, the above-mentioned evaluation of the first inference time for each input data includes: obtaining the first inference time based on the sequence length and / or historical statistics of each input data; the historical statistics represent statistical information on the inference time of different input data.
[0010] In this implementation, an exemplary method for evaluating the first inference time for each input data point is described. The first inference time can be obtained based on at least one of the sequence length and historical statistical information for each input data point. This allows for rapid determination of the first inference time, improving the efficiency of its determination.
[0011] In one possible implementation, the above-mentioned reasoning based on N first data fragment groups in P processing units includes: combining the data fragments of the N first data fragment groups to obtain P second data fragment groups; the P second data fragment groups correspond to P processing units respectively, and the data fragments of each second data fragment group come from different first data fragment groups; and performing reasoning based on the P second data fragment groups in P processing units respectively.
[0012] In this implementation, during the inference process in the P processing units, the N first data segments can be redivided into P second data segments. This allows each of the P processing units to process the P second data segments separately, reducing the number of times processing units exchange input data to obtain the data segment they need to process, thus reducing data communication overhead.
[0013] In one possible implementation, before combining the data fragments of the N first data fragment groups to obtain P second data fragment groups, the method further includes: dividing the N first data fragment groups into P data batches and inputting them into P processing units respectively; aggregating the data in the P processing units to obtain N first data fragment groups.
[0014] In this implementation, to reduce data migration, the data structure and storage location of the input data are not modified before inputting the input data into the P processing units. Instead, the index of the splitting position of each data segment in the N data segment groups is determined. The indexing method can be, for example, the starting position of the data plus an offset. The input to the P processing units is still actually N input data. The N first data segment groups are divided into P data batches, which are then input into the P processing units respectively. This application does not limit the method of division; for example, one input data point can be input into one processing unit. Since the data to be processed by each processing unit is scattered across other processing units, the data from the P processing units needs to be aggregated to obtain N first data segment groups. This implementation makes the method of this application applicable to existing data parallel application scenarios.
[0015] In one possible implementation, the above-mentioned reasoning based on P second data segments in P processing units includes: processing the P second data segments to obtain P corresponding processing results; and homogenizing the P processing results to obtain P homogenized processing results.
[0016] In this implementation, the inference time for the input data processed by each processing unit is similar, but the length of the input data may be inconsistent. To avoid wasting computing resources and increasing inference time caused by whitespace padding in subsequent calculations, this application performs uniform processing on the P processing results of the P second data segments, so that the data processed by the subsequent calculations of the P processing units are of similar length, reducing the waste of computing resources caused by inconsistent data lengths and reducing the inference time in the subsequent inference stage.
[0017] In one possible implementation, the above-mentioned homogenization process for P processing results to obtain P homogenized processing results includes: exchanging data among the P processing results to make the sequence lengths of different processing results in the P processing results close; and obtaining P homogenized processing results based on the processing results of the P data exchange.
[0018] In this implementation, the present application provides an exemplary description of a method for homogenizing the processing results of different processing units, but this does not constitute a limitation of the present application.
[0019] In one possible implementation, the aforementioned processing unit represents a computing device that processes the data of a process in parallel.
[0020] In this implementation, the processing unit refers to any computing device that is a data-parallel process, and this application does not impose any restrictions on it.
[0021] Secondly, this application provides a data processing apparatus, mainly comprising: an acquisition module for acquiring N input data, where N is a positive integer greater than 1; and a processing module for dividing each input data into P data segments to obtain N first data segment groups. The N first data segment groups correspond one-to-one with the N input data, and the inference time for each data segment in the P data segments is approximately equal. P is a positive integer greater than 1. Furthermore, based on the N first data segment groups, inference is performed in P processing units, so that different data segments in each first data segment group are processed by different processing units. Here, N and P are positive integers greater than 1.
[0022] In one possible implementation, when each input data is divided into P data segments to obtain N first data segment groups, the processing module is specifically used to: evaluate the first inference time of each input data; determine the second inference time of each data segment in the P data segments based on the first inference time and the number of processing units P; and divide each input data into N first data segment groups based on the second inference time.
[0023] In one possible implementation, when evaluating the first inference duration for each input data, the processing module is specifically used to: obtain the first inference duration based on the sequence length and / or historical statistics of each input data; the historical statistics represent statistical information on the inference duration of different input data.
[0024] In one possible implementation, when inference is performed in P processing units based on N first data fragment groups, the processing module is specifically used to: combine the data fragments of the N first data fragment groups to obtain P second data fragment groups; the P second data fragment groups correspond to P processing units respectively, and the data fragments of each second data fragment group come from different first data fragment groups; and perform inference in P processing units based on the P second data fragment groups respectively.
[0025] In one possible implementation, before combining the data fragments of the N first data fragment groups to obtain the P second data fragment groups, the processing module is further configured to: divide the N first data fragment groups into P data batches and input them into P processing units respectively; and aggregate the data in the P processing units to obtain the N first data fragment groups.
[0026] In one possible implementation, when inference is performed in P processing units based on P groups of second data segments, the processing module is specifically used to: process the P groups of second data segments to obtain P corresponding processing results; and perform homogenization processing on the P processing results to obtain P homogenized processing results.
[0027] In one possible implementation, when homogenizing P processing results to obtain P homogenized processing results, the processing module is specifically used to: exchange data between the P processing results to make the sequence lengths of different processing results in the P processing results close; and obtain P homogenized processing results based on the P data exchange processing results.
[0028] In one possible implementation, the aforementioned processing unit represents a computing device that processes the data of a process in a data-parallel scenario.
[0029] Thirdly, this application provides a chip system including a processor and a power supply circuit, the power supply circuit being used to supply power to the processor, and the processor being used to execute the method described in any possible implementation of the first aspect and / or the method described in any possible implementation of the second aspect.
[0030] Fourthly, this application provides a computing device including a processor and a memory. The processor is configured to execute instructions stored in the memory, causing the computing device to perform the methods described in any possible implementation of the first aspect and / or the methods described in any possible implementation of the second aspect.
[0031] Fifthly, this application provides a computing device cluster, including at least one computing device, each computing device including a processor and a memory; the processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, such that the computing device cluster performs the method described in any possible implementation of the first aspect and / or the method described in any possible implementation of the second aspect.
[0032] In a sixth aspect, this application provides a computer-readable storage medium including computer program instructions that, when executed by a cluster of computing devices, cause the cluster of computing devices to perform the method described in any possible implementation of the first aspect and / or the method described in any possible implementation of the second aspect, wherein the cluster of computing devices includes at least one computing device.
[0033] In a seventh aspect, this application provides a computer program product containing instructions that, when executed by a cluster of computing devices, cause the cluster of computing devices to perform the method described in any possible implementation of the first aspect and / or the method described in any possible implementation of the second aspect, wherein the cluster of computing devices includes at least one computing device.
[0034] It is understood that the beneficial effects of the second to seventh aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0035] The accompanying drawings used in the embodiments or technical description are briefly introduced below.
[0036] Figure 1 This application provides a schematic diagram of the composition of a reasoning system according to an embodiment of the present application.
[0037] Figure 2 A schematic diagram illustrating an example of a data processing method provided in an embodiment of this application;
[0038] Figure 3 A schematic diagram illustrating the working process of the MoE model provided in the embodiments of this application;
[0039] Figure 4 A schematic diagram illustrating an example of the data processing method combined with the MoE model provided in the embodiments of this application;
[0040] Figure 5 A flowchart illustrating a data processing method provided in an embodiment of this application;
[0041] Figure 6 This is a schematic diagram of the composition of a data processing apparatus provided in an embodiment of this application;
[0042] Figure 7 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application;
[0043] Figure 8 This is a schematic diagram of the structure of a computing device cluster provided in an embodiment of this application;
[0044] Figure 9 This is a schematic diagram of another computing device cluster provided in an embodiment of this application. Detailed Implementation
[0045] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0046] In this article, the term "and / or" describes the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three cases: A exists alone, A and B exist simultaneously, and B exists alone. The symbol " / " in this article indicates that the related objects have an "or" relationship; for example, A / B means A or B.
[0047] The terms "first" and "second," etc., used in the specification and claims herein are used to distinguish different objects, not to describe a specific order of objects. For example, "first response message" and "second response message," etc., are used to distinguish different response messages, not to describe a specific order of response messages.
[0048] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design that is described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0049] In the description of the embodiments in this application, unless otherwise stated, "multiple" means two or more, for example, multiple processing units means two or more processing units, etc.; multiple elements means two or more elements, etc. "Several" means one or more.
[0050] To facilitate understanding of the solutions provided in the embodiments of this application, a brief introduction to some of the terms involved in this solution will be given first.
[0051] Mixture of Experts (MoE) is an architecture that improves computational efficiency and model performance by coordinating multiple sub-models, each corresponding to an expert network. Its core idea is to decompose complex tasks into smaller, more manageable sub-tasks, dynamically allocating these sub-tasks through a gating network, and then having different expert networks dynamically collaborate to process them. This adapts to the extreme computational efficiency demands of the era of large-scale models. This design increases model capacity while reducing computational costs, making it one of the key technologies for the era of large-scale models.
[0052] Expert Networks: Each expert is an independent small neural network (e.g., a fully connected layer) focused on processing a specific type of input. For example, in natural language tasks, some experts excel at analyzing verbs, while others excel at processing nouns. Expert networks are also called expert parts. In the MOE model, each expert network only participates in computation when it receives a corresponding route. In the early stages of model training, due to the randomization of the gating network parameters, the data received by each expert is relatively evenly distributed; however, as training progresses, local gradient updates cause some experts to gradually focus on processing specific types of input data. This "specialization" phenomenon gives the MoE model a diverse representational capability. For example, in image classification tasks, one expert might specialize in recognizing textures, while another expert might recognize edges or shapes.
[0053] Gating Networks: A gating network is a selector that decides which input data to send to which experts. It's similar to a router, selecting one or more best experts for each input. Essentially, a gating network is a classifier that generates a probability distribution based on the input token and selects the K most relevant experts (usually K=1 or 2) for the current task. For example, when the input is "running cheetah," the gating network might prioritize verb processing experts and animal entity recognition experts. Alternatively, a gating network might dynamically select which experts to activate based on the features of the input token. Gating networks typically use a simple feedforward network with softmax to calculate the weights for each expert. After training, the gating network gradually learns to route similar inputs to the better-performing experts.
[0054] Sparse activation: A method where only a few experts optimize computational efficiency for each input.
[0055] Data Parallelism (DP): DP is a method that divides a dataset into multiple subsets and processes these subsets in parallel on different processing units, such as Central Processing Units (CPUs), Graphics Processing Units (GPUs), and Neural Processing Units (NPUs). Each processing unit runs a complete copy of the model but processes only a subset of the dataset. Because each processing unit only needs to synchronize gradients at the end of training, the communication overhead is relatively low. Since the model copy is complete, complex model splitting is unnecessary, making it easy to implement. It fully utilizes the computational power of multiple processing units to accelerate the training process and is suitable for large-scale datasets.
[0056] Data Parallelism (DP) domain: refers to the scope of computational resource allocation and management involved in data parallelism strategies in distributed training. Its core goal is to achieve parallel computing across multiple devices and synchronize gradient update parameters by splitting data into batches.
[0057] Tensor Parallelism (TP) is a method that partitions different parts of a model (such as tensors) across multiple processing units for parallel computation. Each processing unit is responsible for computing a subset of the model and exchanges necessary intermediate results through communication. Because of the frequent exchange of intermediate results between processing units, the communication overhead is significant. Large models can be partitioned into multiple parts for parallel computation across multiple processing units, making it suitable for large models. To achieve efficient TP, high-speed interconnects and low-latency communication protocols are required, necessitating an efficient communication mechanism.
[0058] Sequence Parallelism (SP): SP refers to the process of splitting the data representation sequence along the sequence dimension and performing inference on the split data segments separately. For example, if an input tensor in a data batch is [seq_len, hidden_dim], SP means splitting the input tensor along the sequence length dimension (seq_len) and distributing it to multiple devices. It complements Tensor Parallelism (TP), where TP splits along the hidden_dim dimension and along the sequence length dimension (seq_len), while SP can handle operations on dimensions not covered by TP.
[0059] The AllGather operation involves aggregating local data blocks from all nodes and distributing them globally, ensuring that each node ultimately has a complete copy of the data. For example, AllGather reorders the inputs of all nodes within the communication domain according to their rank IDs (e.g., sorting rank IDs in ascending order), concatenates them, and then sends the result to the output buffers of all nodes.
[0060] ReduceScatter operation: ReduceScatter is a many-to-many set operation in distributed communication, consisting of two phases: the Reduce phase, where all nodes perform aggregation operations (such as summation or finding the maximum value) on data blocks at the same location; and the Scatter phase, where the reduction results are distributed as shards according to node numbers, with each node retaining only a portion of the results. Ultimately, node i obtains the i-th shard of the global data (e.g., in a 4-node cluster, node 0 obtains the reduction results of node block 0 from all nodes). For example, ReduceScatter performs a reduction operation (supporting sum, prod, max, min) on the input of all spatially multiplexed streams (rank) within the communication domain, and then evenly distributes the results to the output buffers of each rank according to their rank numbers. Each process receives 1 / ranksize of the data from other processes for the reduction operation. For example, there are four ranks: rank0, rank1, rank2, and rank3. The input data for each rank is divided into four parts. Each process takes 1 / 4 of the data from each rank and performs a sum operation (or other operation), and sends the result to the output buffer.
[0061] All-to-All (ATOAll) operation: ATOAll is a many-to-many set communication operation. ATOAll means that each node (or process) in a distributed system divides its local data into blocks, sends different data blocks to all other nodes, and synchronously receives the corresponding block data sent by all nodes.
[0062] The Prefill stage is a crucial preprocessing step in the lifecycle of large-scale model inference, primarily involving the initial encoding of the input sequence and the pre-allocation of computational resources. As a computationally intensive preprocessing step in large-scale model inference, its optimization directly impacts the overall inference efficiency.
[0063] Synchronization waiting overhead: This refers to the additional performance loss caused by synchronization mechanisms in multi-threaded / process systems. For example, in a Mixture of Experts (MoE) model, the Attention component of MoE needs to dynamically calculate the attention of each token in the input request before triggering the expert network activation operation of the gating network, and then using the activated expert network to process the input request. The Attention component takes different amounts of time to calculate input requests of different lengths. This means that processes that calculate the attention results earlier need to wait for processes that calculate the attention results later to obtain the attention of each token in each input request. This process results in synchronization waiting overhead for processes that calculate the attention results earlier, causing resource waste. This phenomenon of uneven data processing time for different processes is also known as the uneven computational load problem.
[0064] In business scenarios involving artificial intelligence (AI) models, the lengths of different input requests vary. Therefore, integrating multiple input requests into batches for parallel processing leads to uneven computational load across these requests due to their inconsistent lengths, resulting in synchronization waiting overhead between different inference processes.
[0065] In view of this, embodiments of this application propose a data processing method. The data processing method includes: acquiring N input data; dividing each input data into P data segments to obtain N first data segment groups; each of the N first data segment groups corresponds one-to-one with the N input data, and the inference time of each data segment in the P data segments is approximately equal; and performing inference in P processing units based on the N first data segment groups, so that different data segments in each first data segment group are processed by different processing units. Wherein, N and P are positive integers greater than 1.
[0066] In this embodiment, multiple input data are segmented, allowing different data segments of the same input data to be inferred in different processing units. Since the computation time for different data segments of the same input data is similar, the computation time of different processing units is also roughly similar, thereby alleviating the problem of uneven computational load between different processing units and reducing the synchronization waiting overhead between different processing units.
[0067] To better understand a data processing method according to an embodiment of this application, the application scenarios of the data processing method according to an embodiment of this application are described below. However, the description of the application scenarios does not constitute a limitation on the embodiments of this application.
[0068] Figure 1This is a schematic diagram illustrating the composition of a reasoning system provided in an embodiment of this application. Figure 1 As shown in the embodiments of this application, an inference system 100 includes a terminal 110 and a processing unit set 120. For example, the terminal 110 acquires N input data from a user and sends them to the processing unit set 120; the processing unit set 120 deploys an AI model; the processing unit set 120 includes P processing units; based on the data processing method of the embodiments of this application, the processing unit set 120 divides each input data into P data segments to obtain N first data segment groups; based on the N first data segment groups, inference is performed in the P processing units of the processing unit set 120, so that different data segments in each first data segment group are processed by different processing units in the processing unit set 120 to obtain an inference result.
[0069] Optionally, the processing unit set 120 can send inference results to the user; the user obtains the inference results through the terminal 110.
[0070] It should be noted that the processing unit set 120 may include one or more processing units. A processing unit represents a computing device for a process of data parallelism (DP). For example, a processing unit can refer to multiple servers, or one or more accelerator cards, processors, etc., within a single server. Accelerator cards include, for example, central processing units (CPUs), graphics processing units (GPUs), neural processing units (NPUs), etc. Figure 1 The example will include a server. Figure 1 The example also includes a terminal; the processing unit set 120 can provide the methods or apparatus provided in the embodiments of this application to one or more terminals.
[0071] Optionally, a related application may be installed on the terminal 110. The application or webpage can provide an interface that displays the inference results. The terminal 110 can receive input data entered by the user on the interface and send the input data to the processing unit set 120.
[0072] It should be understood that in some optional implementations, the terminal 110 may deploy the AI model and complete the work on its own without the cooperation of the processing unit set 120, and this application embodiment is not limited in this regard. In some optional implementations, the processing unit set 120 may also be based on input data received from other devices outside the terminal or locally stored, without the cooperation of the terminal 110, and this application embodiment is not limited in this regard.
[0073] The following description Figure 1 The product form of the terminal 110. In this application embodiment, the terminal 110 can be a mobile phone, tablet computer, wearable device, in-vehicle device, augmented reality (AR) / virtual reality (VR) device, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc., and this application embodiment does not impose any restrictions on it.
[0074] Furthermore, the processing unit set 120 can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers. It can also be configured as a cloud server or cloud server cluster that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The cloud server cluster is deployed in several cloud data centers. The software can be an application that implements object control methods, etc., but is not limited to the above forms.
[0075] In one possible scenario, the processing unit assembly 120 can function as a cloud platform (a software platform employing application virtualization technology, integrating multiple functions such as software search, download, use, management, and backup). In practical use, the processing unit assembly 120 can deploy a cloud management platform and a data center, with the terminal 110 interacting with the cloud through the cloud management platform. Additionally, the data center can deploy nodes, which can be virtual machine instances, container instances, physical servers, etc.
[0076] In another possible scenario, the method provided in this application embodiment can be implemented by software. The software has a terminal and a server; terminal 110 runs the software, and processing unit set 120 runs the software's server. During the process of terminal 110 running the software, it can call the server running on processing unit set 120 to implement the method provided in this application embodiment.
[0077] In other words, the method provided in this application embodiment can be applied to the terminal 110 and the processing unit set 120. In specific implementation, it can run as software on the terminal 110 or the processing unit set 120; for example, the software can be a service or an application. This application embodiment can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application embodiment can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can reside in local and remote computer storage media, including storage devices.
[0078] Furthermore, the systems that can implement the technical solutions of this application embodiment include cloud servers, web pages, application program interfaces (APIs), mobile application software, etc. The AI model of this application embodiment can be deployed on the server side, website, or mobile application software to meet the text generation needs of enterprise users and individual users, and can also be used by developers for secondary development through open API interfaces. Furthermore, the implementation of this application embodiment mainly involves deploying the relevant platforms and applications of the large language model of this application embodiment, such as cloud platforms, websites, and applications (APPs).
[0079] This application provides a data processing method that preprocesses the input data before performing parallel inference. This preprocessing includes: acquiring N input data points; dividing each input data point into P data segments to obtain N first data segment groups. The N first data segment groups correspond one-to-one with the N input data points, and the inference time for each data segment in the P data segments is approximately the same.
[0080] Figure 2 This is a schematic diagram illustrating an example of a data processing method provided in an embodiment of this application. For example... Figure 2As shown in one example, N input data points are input data 1, input data 2, and input data 3, and P processing units are processing unit 1, processing unit 2, processing unit 3, and processing unit 4. In other examples, the number of input data points N can be greater than or equal to the number of processing units P, which will not be elaborated here.
[0081] In this embodiment, the time consumed to infer N input data from a data batch to a certain inference position is also referred to as the inference time. The inference position refers to any position that requires a synchronization mechanism, such as the output position of a neural network operator or a neural network layer; in the MoE model, the inference position can refer to the position where the attention result is output.
[0082] In this example, the inference time for input data 1 is 10 μs, the inference time for input data 2 is 6 μs, and the inference time for input data 3 is 8 μs.
[0083] In related technologies, when a data batch includes input data 1, input data 2, and input data 3, different input data are input into different processing units for inference. For example, input data 1 is inferred in processing unit 1; input data 2 is inferred in processing unit 2; and input data 3 is inferred in processing unit 3. Due to the synchronization mechanism, after processing input data 2, processing unit 2 needs to wait 4μs before entering the next stage. This results in a 4μs synchronization waiting overhead for processing unit 2, wasting computational resources. Similarly, after processing input data 3, processing unit 3 needs to wait 2μs before entering the next stage. This also results in a 2μs synchronization waiting overhead for processing unit 3, wasting computational resources.
[0084] In this example, each input data is divided into 4 segments (the same number as the number of processing units). The segmentation is based on the fact that the inference time of each of the P data segments in each data set is approximately the same. For example, the four data segments in data segment group 1 after input data 1 are data segment 1, data segment 2, data segment 3, and data segment 4, with an inference time of approximately 2.5 μs for each segment. The four data segments in data segment group 2 after input data 2 are data segment 5, data segment 6, data segment 7, and data segment 8, with an inference time of approximately 1.5 μs for each segment. The four data segments in data segment group 3 after input data 3 are data segment 9, data segment 10, data segment 11, and data segment 12, with an inference time of approximately 2 μs for each segment.
[0085] In this example, reasoning is performed in four processing units based on the three groups of segmented data fragments, ensuring that different data fragments within each data fragment group are processed by different processing units. Specifically, the four data fragments of data fragment group 1 are processed by processing units 1, 2, 3, and 4, respectively; the four data fragments of data fragment group 2 are processed by processing units 1, 3, 2, and 4, respectively; and the four data fragments of data fragment group 3 are processed by processing units 3, 1, 4, and 2, respectively. In other words, the data fragments processed by different processing units come from different data fragment groups and input data. For example, processing unit 1 processes data fragment 1 from input data 1, data fragment 5 from input data 2, and data fragment 10 from input data 1. Processing unit 2 processes data fragment 2 from input data 1, data fragment 7 from input data 2, and data fragment 12 from input data 1. Processing unit 3 processes data fragment 9 from input data 3, data fragment 3 from input data 1, and data fragment 6 from input data 2. The data segments processed by processing unit 4 include data segment 4 from input data 1, data segment 8 from input data 2, and data segment 11 from input data 1.
[0086] In this embodiment, the data segment processed by a processing unit can be any data segment from the input data. The order in which multiple data segments processed by a processing unit are arranged can be arbitrary.
[0087] Understandably, unlike related technologies, in this embodiment, the N input data are segmented, allowing different data segments of the same input data to be inferred in different processing units. Since the computation time for different data segments of the same input data is similar, the computation time of different processing units is also approximately similar. For example, the inference time for processing units 1, 2, 3, and 4 after processing the input data is close to 4 μs. Thus, due to the synchronization mechanism, after processing the input data, the four processing units do not need to wait or need only wait a very short time before moving to the next stage. Therefore, there is no or almost no synchronization waiting overhead between different processing units, and computational resources are fully utilized.
[0088] Furthermore, in related technologies, the inference time to complete the current stage is 10 μs, which is the same as the time taken for the input data with the longest inference time. In this embodiment, the inference time to complete the current stage is 4 μs. It is evident that the method of this embodiment can significantly reduce inference time and improve inference efficiency. Alternatively, it can be understood that the method of this embodiment balances the computational load of different processing units, reducing the computational load and inference time of the processing unit with the highest load, thereby saving overall inference time and improving inference efficiency.
[0089] In related technologies, when a data batch includes input data 1, input data 2, and input data 3, different input data need to be input into different processing units for inference. In this case, firstly, when the number of input data N is less than the number of processing units P, there are (PN) processing units running idle, resulting in wasted computing resources. For example, in this example, the number of input data 3 may be less than the number of processing units 4; processing unit 4 may have empty data or not participate in the calculation, resulting in wasted computing resources for processing unit 4.
[0090] Understandably, unlike related technologies, in this embodiment, the number of data segments into which the input data is divided is the same as the number of processing units. This ensures that different data segments of the same input data are distributed across all processing units for inference. Furthermore, it guarantees that each processing unit can process one data segment from different input data, thus solving the problem of processing units running idle.
[0091] In related technologies, when a data batch includes input data 1, input data 2, and input data 3, different input data need to be fed into different processing units for inference. Thus, in the second scenario, when the number of input data N is greater than the number of processing units P, the current data batch can only process N input data. (NP) data points need to be placed into the next data batch for inference. This presents a problem of a limited number of input data points within the same data batch, resulting in a longer inference time to obtain all N input data points. For example, in this case, if the number of input data points is 6, then the number of input data points 6 is greater than the number of processing units 4. Therefore, 2 input data points will be inferred in the second data batch, and the inference time to obtain all 6 input data points is: the inference time of the first data batch + the inference time of the second data batch.
[0092] Understandably, unlike related technologies, in this embodiment, when the number of input data N is greater than the number of processing units P, the number of data segments processed by each processing unit can be increased to process N input data in the same data batch. For example, in this example, if the number of input data is 6, then the number of input data 6 is greater than the number of processing units 4. Thus, each of the 4 processing units processes 6 data segments, thereby processing 6 input data in the same data batch and solving the problem of the limited number of input data in the same data batch.
[0093] Optionally, the first inference time for each input data is evaluated. Based on the first inference time and the number of processing units P, the second inference time for each of the P data segments is determined. Based on the second inference time, each input data is segmented to obtain N groups of first data segments.
[0094] For example, in this example, the first inference time of each input data is evaluated by an evaluation method. For instance, the first inference time of input data 1 is evaluated as 10 μs; the first inference time of input data 2 is evaluated as 6 μs; and the first inference time of input data 3 is evaluated as 8 μs.
[0095] In this embodiment, a method for segmenting input data is described exemplarily. First, a first inference time for each input data segment can be evaluated. The first inference time can be understood as the time taken to infer the input data from one inference position to another. Based on the first inference time and the number of processing units P, a second inference time for each of the P data segments is determined. The input data is inferred in the P processing units. To balance the inference time of each processing unit, the average inference time of each processing unit is obtained, i.e., the second inference time. Then, based on the second inference time, each input data segment is segmented so that the inference time of each segmented data segment is close to the second inference time; thus, the inference time of each data segment will be similar. This results in N groups of first data segments. In this way, by using the second inference time as a reference, it is not necessary to first randomly segment the data and then make the inference time of each data segment similar, thereby improving the efficiency of input data segmentation.
[0096] It's important to note that the inference times of each of the P data segments from an input data set are "close," not necessarily "the same." This is because input data generally has a minimum segmentation unit, which cannot be further subdivided. For example, if the input data includes multiple tokens, the token is used as the minimum segmentation unit when segmenting the input data; that is, a token will not be split into two parts. This results in the inference times of each data segment being "close," not necessarily "the same." Of course, in rare cases, after segmenting using the token as the unit, the inference times of each data segment may be the same.
[0097] In this example, assume that input data 1 includes 30 tokens, the first inference time for input data 1 is 10 μs, and the second inference time is 2.5 μs. When input fragment 1 is segmented into the first 11 tokens, the estimated inference time for data fragment 1 is 2.498 μs; when input fragment 1 is segmented into the first 12 tokens, the estimated inference time for data fragment 1 is 2.512 μs.
[0098] Optionally, the input segment can be obtained based on the segment position closest to the estimated inference duration and the second inference duration. In this example, data segment 1 consists of the first 11 tokens.
[0099] Optionally, the input segment can also be obtained based on the segmentation position where the difference between the estimated inference time and the second inference time satisfies a threshold or a threshold interval. In this example, assuming the threshold interval is -0.005μs to 0.005μs, or the threshold is 0.005μs, then the data segment 1 that satisfies the threshold interval or is less than the threshold is the first 11 tokens. Multiple segmentation positions that satisfy the threshold or threshold interval may occur. In this case, the optimal segmentation position can be selected from multiple segmentation positions; the selection method will not be elaborated here. An optional approach is to stop the calculation when a segmentation position that satisfies the threshold or threshold interval is found, and directly determine the input segment based on the current segmentation position.
[0100] Optionally, the segmentation position of each data segment can be determined based on the similarity of inference times among the P second data segment groups. In this example, after segmenting the input data, the inference times of processing unit 1 (corresponding to the first second data segment group), processing unit 2 (corresponding to the second second data segment group), processing unit 3 (corresponding to the third second data segment group), and processing unit 4 (corresponding to the fourth second data segment group) are compared with 4μs, and the positions of each data segment in each second data segment group are adjusted accordingly. This also achieves the goal of ensuring that "the inference times of each data segment among the P data segments are similar."
[0101] Optionally, the input segment can be determined from at least one data segment whose estimated inference duration is close to the second inference duration, using any method. The estimated inference duration refers to the estimated inference duration corresponding to a data segment obtained at a split position. For example, for data segment 1: Data segment 1 can be determined as the data segment with the fewest tokens whose estimated inference duration is greater than the second inference duration, thus containing the first 12 tokens. Alternatively, data segment 1 can be determined as the data segment with the most tokens whose estimated inference duration is less than the second inference duration, thus containing the first 11 tokens. Or, data segment 1 can be determined as the data segment with the smallest absolute value of the difference between the estimated inference duration and the second inference duration, thus containing the first 11 tokens.
[0102] Optionally, the method for evaluating the first inference time for each input data may include: obtaining the first inference time based on the sequence length of each input data.
[0103] For example, the sequence length of each input data is obtained based on the relevant theoretical analysis method of computational load. For instance, the relevant theoretical analysis method of computational load can be an empirical formula that includes parameters such as computing power and computational load. This empirical formula can be as shown in formula (1). In formula (1), l represents the sequence length of the input data, t1 represents the first inference time of the input data, and f(·) represents the empirical formula for calculating the first inference time.
[0104] [t1]=f(l) (1)
[0105] Optionally, the second inference duration for each of the P data segments can be determined based on the sequence length of each input data segment and the number of processing units P.
[0106] For example, the sequence length of each input data is obtained based on the sequence length of each input data and the number of processing units P (the number of data segments), using relevant theoretical analysis methods of computational load. For instance, the relevant theoretical analysis methods of computational load can be empirical formulas that include parameters such as computing power and computational load. This empirical formula can be as shown in formula (2).
[0107]
[0108] In formula (2), l represents the sequence length of the input data; P represents the number of data segments, i.e., the number of data segments; t 2-i d represents the second inference time for the i-th data segment. 2-iLet d represent the position index of the i-th data segment; g(·) represents the empirical formula for calculating the second inference time. The i-th data segment is the data segment whose position index d is the position index of the (i-1)-th data segment. 2-i-1 The position index d of the i-th data segment 2-i The data between them. Taking multiple tokens as input data as an example, the i-th data segment is the position index of the (i-1)-th data segment. 2-i-1 The position index d of the i-th data segment 2-i One or more tokens between them.
[0109] In other implementations, the sequence length of each input data point can be input into a large model, utilizing the model's information analysis and processing capabilities to evaluate the first inference time for each input data point. This application does not impose any limitations on this approach.
[0110] Optionally, the method for evaluating the first inference time for each input data point may include: obtaining the first inference time based on historical statistical information; the historical statistical information represents statistical information on the inference time of different input data. Optionally, the historical statistical information may also be used to evaluate the second inference time for a data segment.
[0111] Furthermore, historical statistical information can be any information obtained by statistically analyzing the inference time of different input data. For example, historical statistical information can be a chart corresponding to "sequence length" and "inference time," and the inference time corresponding to the sequence length of the input data can be found by looking up the table or the chart.
[0112] In other implementations, a reference value for the second inference duration of a data segment can be obtained based on the sequence length of the data segment and historical statistical information. Then, a comprehensive evaluation (such as weighted processing) can be performed based on the aforementioned inference duration evaluation value and the reference value for the second inference duration to determine the number of tokens in the data segment. For example, based on the aforementioned inference duration evaluation value, the number of tokens in data segment 1 is determined to be 11; based on the reference value for the second inference duration, the number of tokens in data segment 1 is determined to be 13. After comprehensive evaluation, the number of tokens in data segment 1 can be determined to be 12.
[0113] Optionally, the method for evaluating the first inference time for each input data may include: obtaining the first inference time based on the sequence length and historical statistics of each input data; the historical statistics represent statistical information on the inference time of different input data.
[0114] In this application embodiment, a method for evaluating the first inference time for each input data is described by way of example. The first inference time can be obtained based on at least one of the sequence length and historical statistical information of each input data. The first inference time can be determined quickly, improving the efficiency of determining the first inference time.
[0115] In other implementations, N input data points can be directly input into a large model to evaluate the first inference time for each input data point. This application does not impose any limitations on this approach.
[0116] Optionally, the process of reasoning in the N first data segment groups within the P processing units includes: combining the data segments of the N first data segment groups to obtain P second data segment groups; and performing reasoning in the P processing units based on the P second data segment groups. Thus, the P second data segment groups correspond to the P processing units, and the data segments of each second data segment group originate from different first data segment groups.
[0117] For example, a processing unit processes a second data segment group. P second data segment groups may include, for example, data segment groups from input data 1 (data segment 1), input data 2 (data segment 5), input data 10 (data segment 10); input data 1 (data segment 2), input data 2 (data segment 7), input data 12 (data segment 12); input data 3 (data segment 9), input data 1 (data segment 3), input data 2 (data segment 6); input data 1 (data segment 4), input data 2 (data segment 8), input data 11 (data segment 11).
[0118] Furthermore, during the inference process within the P processing units, the N first data segments can be redivided into P second data segments. This allows each of the P processing units to process the P second data segments separately, reducing the number of times processing units exchange input data to obtain the data segments they need to process, thus reducing data communication overhead.
[0119] It should be noted that, in order to reduce the amount of data migration, the data segmentation and data fragment grouping operations involved in the embodiments of this application can be understood as recording the data index accordingly, and do not involve data migration issues at the data storage end. For example, dividing each input data into P data fragments to obtain N first data fragment groups; this can be understood as recording the index of the segmentation position of each data fragment in the input data; and using the index to obtain the data that needs to be processed in the inference process. Similarly, combining the data fragments of the N first data fragment groups to obtain P second data fragment groups; this can be understood as recording the index of the segmentation position of each data fragment in the P second data fragment groups by using the index of the segmentation position of each data fragment in the N first data fragment groups; and using the index to obtain the data that needs to be processed in the inference process.
[0120] Optionally, before combining the data segments of the N first data segment groups to obtain P second data segment groups, the method further includes: dividing the N input data into P data batches and inputting them into P processing units respectively; aggregating the data in the P processing units to obtain N first data segment groups.
[0121] Furthermore, to reduce data migration, the data structure and storage location of the input data are not modified before inputting the input data into the P processing units. The indices of the splitting positions of each data segment in the N data segment groups are determined. The input to the P processing units is actually still N input data. The N first data segment groups are divided into P data batches, which are then input into the P processing units respectively. This application does not limit the method of division; for example, one input data point can be input into one processing unit. Since the data to be processed by each processing unit is scattered across other processing units, it is necessary to aggregate the data from the P processing units to obtain N first data segment groups. The data aggregation method here includes, but is not limited to, using the AllGather operation to summarize and distribute the data blocks from all processing units to all processing units. This implementation method, which achieves the generalization of the method in this embodiment, can be applied to data-parallel dynamic programming (DP) application scenarios.
[0122] Optionally, the P second data segments are processed to obtain the corresponding P processing results; the P processing results are then homogenized to obtain the P homogenized processing results.
[0123] Furthermore, in this embodiment, the inference time of the input data processed by each processing unit is similar, but the length of the input data may be inconsistent. To avoid wasting computing resources and increasing inference time caused by phenomena such as whitespace padding in subsequent calculations, this embodiment performs uniform processing on the P processing results of the P second data segment groups, so that the data processed by the subsequent calculations of the P processing units are of similar length, reducing the waste of computing resources caused by inconsistent data lengths and reducing the inference time of the subsequent inference stage.
[0124] For example, in the inference scenario of a self-attention mechanism for time series data, the attention calculation process for later-appearing time series needs to refer to earlier-appearing time series. Thus, the inference time for earlier-appearing time series is shorter, while the inference time for later-appearing time series is longer. For instance, processing unit A processes a data segment containing more earlier-appearing time series, while processing unit B processes a data segment containing more later-appearing time series. In this case, if the inference times of processing unit A and processing unit B are similar, the sequence length of the input data processed by processing unit A will be longer, resulting in a longer processing result, while the sequence length of the input data processed by processing unit B will be shorter, resulting in a shorter processing result.
[0125] Optionally, the homogenization process may include: exchanging data among P processing results to make the sequence lengths of different processing results in the P processing results close; and obtaining P homogenized processing results based on the processing results of the P data exchanges.
[0126] Furthermore, the embodiments of this application provide an exemplary description of a method for homogenizing the processing results of different processing units, but this does not constitute a limitation on the embodiments of this application.
[0127] Alternatively, a processing unit refers to a computing device that processes data in parallel for a single process.
[0128] Furthermore, the method of this application embodiment can be applied to any data parallelism application scenario. A processing unit represents any computing device of a data parallelism (DP) process. For example, a processing unit can refer to multiple servers, or one or more accelerator cards, processors, etc., within a single server. Accelerator cards include, for example, central processing units (CPUs), graphics processing units (GPUs), neural processing units (NPUs), etc. This application embodiment does not impose any limitations on this.
[0129] This application's embodiments are applicable to data parallelism (DP) processing scenarios for any AI model. Any AI model can be a dense model, meaning a neural network model where all model parameters are activated during each input sample processing; or it can be a sparse model, meaning a neural network model where only a subset of model parameters are activated for inference. An example of a sparse model is a Mixture of Experts (MoE) model, which dynamically selects a minority of expert networks to process input data. The following description uses the MoE model as an example to illustrate the method of this application's embodiments.
[0130] Figure 3 This is a schematic diagram illustrating the working process of the MoE model provided in the embodiments of this application. Figure 3 As shown, the MoE model mainly consists of an Attention part (the network related to the attention calculation process) and an Expert part (the network related to the expert network processing process). Multiple input data are divided into one or more batches, each batch containing one or more input data points, such as input data a, input data b, input data c, and input data d in a batch. Each input data point passes through several neural network layers and is then input to the Attention part, which outputs the attention results for several tokens of each input data point. The attention results for these tokens are then input to a gating network. Based on the attention results for each token, the gating network sparsely activates some experts in the expert network (e.g., Expert1, Expert2, etc.) so that each token is processed by its corresponding Expert. After inference by the MoE model, the inference results for each input data point are, for example, inference result a, inference result b, inference result c, and inference result d.
[0131] It's important to note that in Mixture of Experts (MoE) models, the Attention component dynamically calculates the attention of each token in the input request before triggering the expert network activation operation of the gating network. The activated expert network then processes the input request. The Attention component takes different amounts of time to calculate the attention for input requests of varying lengths. This means that processes that calculate the attention earlier must wait for processes that calculate it later to obtain the attention for each token in each input request. This results in synchronization overhead for processes that calculate the attention earlier, leading to resource waste. This uneven processing time across different processes is also known as the uneven computational load problem.
[0132] For example, in the MoE model, the basic data unit processed by the Attention part is the data batch, while the basic data unit processed by the Expert part is the token. Therefore, when the lengths of multiple input requests in a data batch differ, the computational load of different processes for different input requests becomes unbalanced for the Attention part. This leads to synchronization waiting overhead for different processes of different input requests, resulting in a waste of computational resources.
[0133] It is understandable that in real-world business scenarios, large-scale model inference service systems exhibit input request lengths of varying lengths. A key challenge is how to rationally combine input requests into inference batches to reduce the synchronization waiting overhead caused by uneven computational load during parallel inference. Furthermore, when the number of input requests is less than the parallelism of the Attention part's dynamic programming (DP), data from different devices may be wasted, leading to wasted computational resources. In the MoE model, the Attention part processes batches as the basic data unit, while the Expert part processes tokens. Therefore, the impact of request length differences on computational load is primarily felt in the Attention part. However, the impact of request length differences on computational load is also felt in the Expert part; however, the uneven computational load in the Expert part is caused by many factors, with request length differences being one of them. This application's embodiments primarily address the problem of uneven computational load in the Attention part caused by differences in request length.
[0134] Figure 4 This is a schematic diagram illustrating an example of the data processing method combined with the MoE model provided in the embodiments of this application. Figure 4 As shown, in one example, the input data includes input data a, input data b, input data c, and input data d. The processing unit set includes processing unit a, processing unit b, processing unit c, and processing unit d.
[0135] In this example, based on the data processing method of this application embodiment, input data a is divided into 4 data segments, resulting in segment 0, segment 1, segment 2, and segment 3. Input data b is divided into 4 data segments, resulting in segment 4, segment 5, segment 6, and segment 7. Input data c is divided into 4 data segments, resulting in segment 8, segment 9, segment 10, and segment 11. Input data a is divided into 4 data segments, resulting in segment 12, segment 13, segment 14, and segment 15. This data partitioning process only records the index of the partitioning position.
[0136] In this example, the four divided input data are grouped into a single data batch input processing unit set; the four input data are... Figure 4The input in the context of data processing. For example, four input data points can be processed into four separate units.
[0137] In this example, taking a processing unit (e.g., processing unit a) as an example, the "qkv_down" module of processing unit a reduces the dimensionality of the query tensor, key tensor, and value tensor to match their dimensions with the input data and reduce computational overhead.
[0138] In this example, because the data fragments that one processing unit needs to process are scattered across other processing units, it is necessary to aggregate (gather) the data from the four processing units to obtain four input data sets. The data aggregation methods here include, but are not limited to, using the AllGather operation. Figure 4 The AG module in [the context of the project].
[0139] In this example, taking processing unit a as an example, the slice1 module in processing unit a is used to determine the data segment to be processed corresponding to the query tensor of processing unit a from all input data based on the index of each recorded data segment. For example, if the data segment processed by processing unit a is the first segment among all input data, then the data segments to be processed corresponding to the query tensor of processing unit a include segment 0, segment 4, segment 8, and segment 12. In neural networks, a slice typically refers to a block-based processing strategy for data or model structure, designed to optimize model performance for specific data distributions or task requirements.
[0140] Furthermore, similarly, the data segments processed corresponding to the query tensors of processing units b, c, and d can be obtained. For example, if processing unit b processes the second segment of each input data, then the data segments processed corresponding to the query tensor of processing unit b include segments 1, 5, 9, and 13. Similarly, if processing unit c processes the third segment of each input data, then the data segments processed corresponding to the query tensor of processing unit b include segments 2, 6, 10, and 14. And if processing unit d processes the fourth segment of each input data, then the data segments processed corresponding to the query tensor of processing unit d include segments 3, 7, 11, and 15.
[0141] In this example, taking processing unit a as an example, the slice2 module in processing unit a is used to determine the data segments to be processed corresponding to the key tensors and value tensors of processing unit a from all input data based on the indices of each recorded data segment. In the inference scenario of the self-attention mechanism, the attention calculation process of the later time series needs to refer to the earlier time series. Therefore, for example, if the data segment processed by processing unit a is the first segment among all input data, then the data segments to be processed corresponding to the key tensors and value tensors of processing unit a include segment 0, segment 4, segment 8, and segment 12.
[0142] Furthermore, similarly, the data segments processed corresponding to the key tensors and value tensors of processing units b, c, and d can be obtained. For example, if the data segment processed by processing unit b is the second segment among all input data, then the data segments processed corresponding to the key tensors and value tensors of processing unit b include segments 0, 4, 8, 12, 1, 5, 9, and 13. Similarly, if the data segment processed by processing unit c is the third segment among all input data, then the data segments processed corresponding to the key tensors and value tensors of processing unit b include segments 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, and 14. For example, if the data segment processed by processing unit d is the fourth segment among all input data, then the data segments processed by the key tensor and value tensor of processing unit d include segment 0, segment 4, segment 8, segment 12, segment 1, segment 5, segment 9, segment 13, segment 2, segment 6, segment 10, segment 14, segment 3, segment 7, segment 11, and segment 15.
[0143] In this example, taking processing unit a as an example, the q_up(TP4) module in processing unit a represents the process of increasing the dimensionality of the query tensor. Based on the weight matrix of each segment and the query tensor determined by the slice1 module, the query tensor corresponding to processing unit a is obtained. Similarly, the query tensors of processing units b, c, and d can be obtained, which will not be elaborated here. Here, TP4 indicates that the process of determining the query tensor by the q_up(TP4) module is performed in the four processing units using a tensor parallel TP method to perform matrix operations on the weight matrices of each segment and the query tensor.
[0144] In this example, taking processing unit a as an example, the k_up&v_up(TP4) module in processing unit a represents the dimensionality increase processing of the key tensor and value tensor respectively. Based on the weight matrices of each segment and the key tensor and value tensor determined by the slice1 module, the key tensor and value tensor corresponding to processing unit a are obtained. Similarly, the key tensors and value tensors of processing units b, c, and d can be obtained, which will not be elaborated here. Here, TP4 indicates that the process of determining the key tensor and value tensor by the k_up&v_up(TP4) module is to perform matrix operations on the weight matrices of each segment and the key tensor and value tensor in a tensor parallel TP manner in the four processing units.
[0145] In this example, taking processing unit a as an example, the FA module is used to perform fused attention (FA) processing on the obtained query tensor, key tensor, and value tensor to obtain the attention result of each token in each input data. The FA self-attention mechanism is an optimized self-attention calculation method, mainly used in high-efficiency computing scenarios.
[0146] In this example, the Quant module is used to quantize the attention results of each token in each input data. By reducing the numerical precision of weights and activation values, such as quantizing the data from a 32-bit floating-point data type to an 8-bit integer data type, the model storage and computational overhead can be reduced while maintaining inference accuracy.
[0147] In this example, this application embodiment provides a homogenization processing module for the processing results of different processing units: an A2A module. The A2A module is a module that enables data exchange between different processing units. The A2A module utilizes an All-to-All (ATOA) communication method to achieve data exchange between different processing units.
[0148] Furthermore, this application embodiment includes an A2A module. The A2A module utilizes an All-to-All (A2A) communication method to enable data exchange between different processing units. For example, the unit of data exchange is a token. To ensure that the number of tokens in different processing units is approximately equal, data exchange occurs between them. A data segment may include multiple tokens; using tokens as the unit of data exchange may result in some tokens within a data segment being migrated.
[0149] In this example, the results after the A2A module exchange are as follows: the data segments to which the attention result output by the Attention part of processing unit a belongs are segments 0, 4, and 8-1 (representing part of the tokens in segment 8); the data segments to which the attention result output by the Attention part of processing unit b belongs are segments 1, 5, 9, and 13-1 (representing part of the tokens in segment 13); the data segments to which the attention result output by the Attention part of processing unit c belongs are segments 2, 6, 10, 14, and 8-2 (representing the remaining tokens in segment 8); and the data segments to which the attention result output by the Attention part of processing unit d belongs are segments 3, 7, 11, 15, 12, and 13-2 (representing the remaining tokens in segment 13). Thus, the token sequence lengths corresponding to the attention results output by processing units a, b, c, and d are close.
[0150] In this example, the Out Projection (Out-Proj) module is the processing layer in the attention computation. In the attention mechanism, the out_proj module is the final step in the attention computation process, responsible for mapping the output of multi-head attention back to the target dimension.
[0151] In this example, the RS module is an example of the subsequent processing of the Attention part. The RS module refers to the module that performs the ReduceScatter operation. The RS module is used by all processing units to perform aggregation operations (such as summation, finding the maximum value, etc.) on data blocks at the same location, and then distribute the reduction results into shards according to the processing unit number, with each processing unit only retaining a portion of the results.
[0152] In this example, the number of tokens used for attention calculation in different processing units varies for each of the four input data points output by the Quant module. Therefore, the number of tokens processed in different processing units is different, resulting in different sequence lengths of attention results for different data segments obtained in different processing units.
[0153] Furthermore, if the A2A module is not configured, the out_proj module adds placeholder data to map the output attention results back to the target dimension. This is to maintain the consistency of the length of the attention sequences output by each processing unit and ensure that their dimension is the target dimension. Consequently, the output sequence of the RS module contains some placeholder data (such as the data marked in white). Placeholder data is invalid data, leading to a waste of computational resources and an increase in inference time.
[0154] Furthermore, this example includes an A2A module. The `out_proj` module, in order to map the output attention results back to the target dimension, does not require adding placeholder data. Consequently, the output sequence of the RS module does not contain placeholder data, avoiding wasted computational resources and increased inference time. The RS module can also re-segment its output data into multiple data fragment groups to ensure that the number of tokens in each data fragment is similar, facilitating subsequent data processing.
[0155] In this example, the problem of uneven computational load caused by the uneven sequence length in the processing batch of the inference system is alleviated, and the waste of computational resources caused by the number of input data in the processing batch being less than the DP parallelism in the parallel strategy is also alleviated.
[0156] In this example, in the Multi-Head Latent Attention (MLA) scenario, the Attention part of the MoE model suffers from severe computational load imbalance during the Prefill stage due to varying input request lengths. This application proposes a load-balanced variable-length hybrid sequence inference acceleration method based on the MLA scenario. Through collaborative optimization of the service-oriented side and the model-oriented side, the synchronization overhead caused by load imbalance is alleviated. The service-oriented side refers to the data processing stage before inference is performed using P processing units. The model-oriented side refers to the inference stage performed using the P processing units.
[0157] In this example, on the service-oriented side, the main task is sequence segmentation based on computational load awareness. Combining the sequence length of each input data point with theoretical analysis of the computational load of the Attention component, the inference time for each input data point is calculated; this theoretical analysis refers to analyses related to computing power and computational volume. By incorporating historical data statistics from the current inference system, the theoretically calculated inference time for each input data point can be adjusted. Furthermore, based on the size of the DP domain, a non-uniform segmentation of the input data is determined in the sequence dimension, ensuring that different processing units within the DP domain combine different slices (i.e., data fragments) of each input data point; thereby guaranteeing that the total time for the combination of slices from different processing units across the computational chains of the q_up module, k_up+v_up module, FA module, and out_proj module is approximately the same.
[0158] In this example, a parallel computing scheme of Fused Data and Sequence Parallel (FDSP) is proposed on the model side. The FDSP fusion parallel computing scheme refers to a technical solution combining data parallelism and sequence parallelism. To complement the non-uniform slicing scheme on the service-side, a DP and SP fusion parallel scheme is proposed on the model side. This scheme simultaneously implements both DP and SP parallel computing within the DP domain. The core of this parallel scheme lies in slicing the full token data after Allgather communication (A2A module) based on the index of the token sequence transmitted from the service-side. It comprehensively considers the uneven computational load of the FA model and matches the uneven computational load of the Linear layers (such as the "qkv_down" module, slice1 module, slice2 module, q_up(TP4) module, k_up&v_up(TP4) module, etc.) to achieve similar inference times for the Attention parts of different processing units.
[0159] In this example, an A2A module is also set up to achieve communication redundancy removal. By adding a pre-Alltoall communication (i.e., the A2A module), the additional communication and synchronization waiting overhead introduced by data completion is reduced in the communication process of the subsequent Attention part Reduce-Scatter (i.e., the RS module) and the Reduce-Scatter communication process of the rest of the MoE model.
[0160] This application proposes a variable-length hybrid sequence inference acceleration method based on MLA load balancing. The server-side data processing method is comparable to a request grouping scheduler based on computational load awareness. Specifically, input requests are sliced along the sequence dimension, ensuring that different slices of the same request have similar computational times in the MLA module (an example of the Attention part), thus alleviating the computational load imbalance problem of the MoE model. This request grouping scheduler is used to non-uniformly slice the inference system input requests according to the sequence length of each input data, combined with theoretical analysis of the computational load of the MLA part and historical data statistics of the inference system, and according to the DP parallelism of the MLA module, so that the computational times of different slices in the MLA module are approximately similar.
[0161] In this embodiment, the data processing method on the model side is based on an FDSP fused parallel inference structure. Specifically, it adapts to non-uniformly sliced data for inference on the MoE model side, simultaneously implementing both DP and SP request partitioning schemes within the DP domain to reduce synchronization latency caused by uneven computational load in real-world business scenarios. This parallel inference structure is used to perform non-uniform slicing of the input data in the Prefill stage according to the parameters passed from the request group scheduler; simultaneously implement both DP and SP request partitioning schemes within the DP domain; and effectively alleviate the communication load imbalance problem in the subsequent Expert section by adding additional Alltoall communication.
[0162] In this embodiment, the data processing includes: obtaining the sequence length of the input data and the DP parallelism of the Attention part; determining the slice index of the input data sequence based on the sequence length and DP parallelism of the input data, combined with theoretical analysis of MLA computational load and historical statistical information on the MLA computation time of different sequence lengths by the inference system; and passing the slice index value as an initialization parameter to the MoE model to start inference. In the FDSP fusion parallel inference structure, this embodiment modifies the network structure of the Attention part, adding input data segmentation logic in the Prefill stage; slicing the full data according to the slice index passed from the MoE model. Additional All-to-All communication is also added to reorder the MLA computation results.
[0163] Figure 5 This is a flowchart illustrating a data processing method provided in an embodiment of this application. Figure 5 As shown in the figure, this application provides a data processing method, which mainly includes the following steps:
[0164] Step S510: Obtain N input data.
[0165] In step S520, each input data is divided into P data segments, resulting in N first data segment groups. The N first data segment groups correspond one-to-one with the N input data, and the inference time of each data segment in the P data segments is approximately the same.
[0166] Step S530: Based on N first data segment groups, inference is performed in P processing units so that different data segments in each first data segment group are processed by different processing units. Here, N and P are positive integers greater than 1.
[0167] In this embodiment, multiple input data are segmented, allowing different data segments of the same input data to be inferred in different processing units. Since the computation time for different data segments of the same input data is similar, the computation time of different processing units is also roughly similar, thereby alleviating the problem of uneven computational load between different processing units and reducing the synchronization waiting overhead between different processing units.
[0168] In one possible implementation, the above-mentioned process of dividing each input data into P data segments to obtain N first data segment groups further includes: evaluating the first inference duration of each input data; determining the second inference duration of each data segment in the P data segments based on the first inference duration and the number of processing units P; and dividing each input data into N first data segment groups based on the second inference duration.
[0169] In this implementation, the method for segmenting the input data is illustrated exemplarily. First, the first inference time for each input data segment can be evaluated. The first inference time can be understood as the time taken to infer the input data from one inference position to another. Based on the first inference time and the number of processing units P, the second inference time for each of the P data segments is determined. The input data is inferred in the P processing units. To balance the inference time of each processing unit, the second inference time is obtained, which is the average inference time of each processing unit. Then, based on the second inference time, each input data segment is segmented so that the inference time of each segment is close to the second inference time; thus, the inference time of each data segment will be similar. This results in N groups of first data segments. In this way, by using the second inference time as a reference, it is not necessary to first randomly segment the data and then make the inference time of each data segment similar, thereby improving the efficiency of input data segmentation.
[0170] In one possible implementation, the above-mentioned evaluation of the first inference time for each input data includes: obtaining the first inference time based on the sequence length and / or historical statistics of each input data; the historical statistics represent statistical information on the inference time of different input data.
[0171] In this implementation, an exemplary method for evaluating the first inference time for each input data point is described. The first inference time can be obtained based on at least one of the sequence length and historical statistical information for each input data point. This allows for rapid determination of the first inference time, improving the efficiency of its determination.
[0172] In one possible implementation, the above-mentioned reasoning based on N first data fragment groups in P processing units includes: combining the data fragments of the N first data fragment groups to obtain P second data fragment groups; the P second data fragment groups correspond to P processing units respectively, and the data fragments of each second data fragment group come from different first data fragment groups; and performing reasoning based on the P second data fragment groups in P processing units respectively.
[0173] In this implementation, during the inference process in the P processing units, the N first data segments can be redivided into P second data segments. This allows each of the P processing units to process the P second data segments separately, reducing the number of times processing units exchange input data to obtain the data segment they need to process, thus reducing data communication overhead.
[0174] In one possible implementation, before combining the data fragments of the N first data fragment groups to obtain P second data fragment groups, the method further includes: dividing the N first data fragment groups into P data batches and inputting them into P processing units respectively; aggregating the data in the P processing units to obtain N first data fragment groups.
[0175] In this implementation, to reduce data migration, the data structure and storage location of the input data are not modified before inputting the input data into the P processing units. Instead, the index of the segmentation position of each data segment in the N data segment groups is determined. The input to the P processing units is actually still N input data. The N first data segment groups are divided into P data batches and input into the P processing units respectively; the method of division is not limited in this application, for example, one input data is input into one processing unit, etc. Since the data to be processed by the processing units is scattered in other processing units, it is necessary to aggregate the data in the P processing units to obtain N first data segment groups. This implementation makes the method of this application applicable to existing data parallel application scenarios.
[0176] In one possible implementation, the above-mentioned reasoning based on P second data segments in P processing units includes: processing the P second data segments to obtain P corresponding processing results; and homogenizing the P processing results to obtain P homogenized processing results.
[0177] In this implementation, the inference time for the input data processed by each processing unit is similar, but the length of the input data may be inconsistent. To avoid wasting computing resources and increasing inference time caused by whitespace padding in subsequent calculations, this embodiment of the application performs uniform processing on the P processing results of the P second data segment groups, so that the data processed by the subsequent calculations of the P processing units are of similar length, reducing the waste of computing resources caused by inconsistent data lengths and reducing the inference time of the subsequent inference stage.
[0178] In one possible implementation, the above-mentioned homogenization process for P processing results to obtain P homogenized processing results includes: exchanging data among the P processing results to make the sequence lengths of different processing results in the P processing results close; and obtaining P homogenized processing results based on the processing results of the P data exchange.
[0179] In this implementation, the embodiments of this application provide an exemplary description of the method for homogenizing the processing results of different processing units, but this does not constitute a limitation on the embodiments of this application.
[0180] In one possible implementation, the aforementioned processing unit represents a computing device that processes the data of a process in parallel.
[0181] In this implementation, the processing unit refers to any computing device that is a data-parallel process, and this application embodiment does not impose any restrictions on this.
[0182] Figure 6 This is a schematic diagram illustrating the composition of a data processing apparatus provided in an embodiment of this application. Figure 6 As shown, this application embodiment provides a data processing device 600, which mainly includes:
[0183] The acquisition module 610 is used to acquire N input data, where N is a positive integer greater than 1.
[0184] Processing module 620 is used to divide each input data into P data segments, resulting in N first data segment groups. Each of the N first data segment groups corresponds one-to-one with one of the N input data segments, and the inference time for each data segment in the P data segments is approximately equal. P is a positive integer greater than 1. Furthermore, based on the N first data segment groups, inference is performed in P processing units, so that different data segments within each first data segment group are processed by different processing units. Here, N and P are positive integers greater than 1.
[0185] In one possible implementation, when each input data is divided into P data segments to obtain N first data segment groups, the processing module 620 is specifically used to: evaluate the first inference time of each input data; determine the second inference time of each data segment in the P data segments based on the first inference time and the number of processing units P; and divide each input data into N first data segment groups based on the second inference time.
[0186] In one possible implementation, when evaluating the first inference duration for each input data, the processing module 620 is specifically configured to: obtain the first inference duration based on the sequence length and / or historical statistical information of each input data; the historical statistical information represents statistical information on the inference duration of different input data.
[0187] In one possible implementation, when inference is performed in P processing units based on N first data fragment groups, the processing module 620 is specifically used to: combine the data fragments of the N first data fragment groups to obtain P second data fragment groups; the P second data fragment groups correspond to P processing units respectively, and the data fragments of each second data fragment group come from different first data fragment groups; and perform inference in P processing units based on the P second data fragment groups respectively.
[0188] In one possible implementation, before combining the data fragments of the N first data fragment groups to obtain P second data fragment groups, the processing module 620 is further configured to: divide the N first data fragment groups into P data batches and input them into P processing units respectively; and aggregate the data in the P processing units to obtain N first data fragment groups.
[0189] In one possible implementation, when inference is performed in P processing units based on P groups of second data segments, the processing module 620 is specifically used to: process the P groups of second data segments to obtain P corresponding processing results; and perform homogenization processing on the P processing results to obtain P homogenized processing results.
[0190] In one possible implementation, when homogenizing P processing results to obtain P homogenized processing results, the processing module 620 is specifically used to: exchange data between the P processing results so that the sequence lengths of different processing results in the P processing results are close; and obtain P homogenized processing results based on the processing results of the P data exchange.
[0191] In one possible implementation, the aforementioned processing unit represents a computing device that processes the data of a process in a data-parallel scenario.
[0192] The following is about... Figure 6The software and hardware implementation of the data processing apparatus 600 shown (hereinafter referred to as: the apparatus of this application embodiment) needs further explanation.
[0193] As an example of a software functional unit, a module can include code running on a computing instance. A computing instance can include at least one of a physical host (computing device), a virtual machine, or a container. Furthermore, the aforementioned computing instance can be one or more. For example, a module can include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code can be distributed within the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code can be distributed within the same availability zone (AZ) or in different AZs, each AZ comprising one or more geographically proximate data centers. Typically, a region can include multiple AZs.
[0194] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.
[0195] As an example of a hardware functional unit, a module may include at least one computing device, such as a server. Alternatively, a module may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The aforementioned PLD may be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0196] The multiple computing devices included in the module can be distributed within the same region or in different regions. Similarly, the multiple computing devices included in the module can be distributed within the same Availability Zone (AZ) or in different AZs. Likewise, the multiple computing devices included in the module can be distributed within the same Virtual Private Cloud (VPC) or multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0197] It should be noted that, in other embodiments, the apparatus of this application embodiment additionally provides one or more modules for performing any of the steps included in the above implementation. The steps implemented by one or more modules in the apparatus of this application embodiment can be specified as needed, and more or fewer modules can be obtained than in the embodiments of this application to implement different steps in the above method, thereby realizing all the functions of the apparatus of this application embodiment.
[0198] This application also provides a computing device 700. For example... Figure 7 As shown, the computing device 700 includes a bus 702, a processor 704, a memory 706, and a communication interface 708. The processor 704, memory 706, and communication interface 708 communicate with each other via the bus 702. The computing device 700 can be a server, such as a central server, an edge server, or a local server in a local data center, or it can be an electronic device such as a desktop computer, laptop computer, or smartphone. It should be understood that this application does not limit the number of processors and memories in the computing device 700.
[0199] The 702 bus can be a Peripheral Component Interconnect (PCI) bus, a Peripheral Component Interconnect Express (PCIe) bus, an Extended Industry Standard Architecture (EISA) bus, a Unified Bus (Ubus or UB), a Compute Express Link (CXL), a Cache Coherent Interconnect for Accelerators (CCIX), etc. The Unified Bus is also known as the Lingqu Bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 7The bus 704 may be represented by a single line, but this does not mean that there is only one bus or one type of bus. The bus 704 may include a path for transmitting information between various components of the computing device 700 (e.g., memory 706, processor 704, communication interface 708).
[0200] The processor 704 may include any one or more computing devices such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP) or a digital signal processor (DSP), an ASIC, an FPGA, a CPLD, an NPU, a SoC, an offload card, or an accelerator card.
[0201] Memory 706 may include volatile memory, such as random access memory (RAM). Processor 704 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD). Furthermore, memory 706 may also be implemented using storage class memory (SCM), phase change memory (PCM), or other types of storage media.
[0202] It is worth noting that the same type of storage medium can be configured in the same computing device to realize the function of memory 706, or two or more types of storage media can be configured to realize the function of memory 706. This application does not limit this.
[0203] The memory 706 stores executable program code, and the processor 704 executes the executable program code to implement the functions of the apparatus in the embodiments of this application, thereby implementing the methods described in the above embodiments. That is, the memory 706 stores instructions for executing the methods described in the above embodiments.
[0204] Alternatively, the memory 706 may store executable code, which the processor 704 executes to implement the functions of the apparatus in the embodiments of this application, thereby implementing the methods described in the above embodiments. That is, the memory 706 stores instructions for executing the methods described in the above embodiments.
[0205] The communication interface 708 uses transceiver modules, such as, but not limited to, network interface cards and transceivers, to enable communication between the computing device 700 and other devices or communication networks.
[0206] As one possible implementation, the computing device 700 may also include a chip system, which includes a processor and a power supply circuit. The power supply circuit supplies power to the processor, and the processor executes the operation steps corresponding to the methods in the embodiments of this application. For simplicity, further details are omitted here. The processor can be implemented using a GPU, or it can be implemented using computing devices or AI chips such as a DPU, NPU, XPU, SoC, offload card, or accelerator card.
[0207] As one possible implementation, the computing device 700 may include various types of processors 704, meaning the computing device 700 is a heterogeneous device. For example, the computing device 700 may include a CPU and a GPU, and at least one of the processors 704 may execute the operation steps corresponding to the methods of the embodiments of this application. For the sake of brevity, further details are omitted here.
[0208] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be an electronic device such as a desktop computer, a laptop computer, or a smartphone.
[0209] like Figure 8 As shown, the computing device cluster includes at least one computing device 700. The memory 706 of one or more computing devices 700 in the computing device cluster may store the same instructions for performing the methods described in the above embodiments.
[0210] In some possible implementations, the memory 706 of one or more computing devices 700 in the computing device cluster may also store partial instructions for executing the methods described in the above embodiments. In other words, a combination of one or more computing devices 700 can jointly execute instructions for executing the methods described in the above embodiments.
[0211] It should be noted that the memories 706 in different computing devices 700 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the apparatus in this application embodiment. That is, the instructions stored in the memories 706 of different computing devices 700 can implement the functions of one or more modules of the apparatus in this application embodiment.
[0212] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 9 One possible implementation is shown. For example... Figure 9 As shown, two computing devices 700A and 700B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this possible implementation, the memory 706 in computing device 700A stores instructions for the functions of one or more modules of the apparatus of this application embodiment. Meanwhile, the memory 706 in computing device 700B stores instructions for the functions of another one or more modules of the apparatus of this application embodiment.
[0213] It should be understood that Figure 9 The functions of the computing device 700A shown can also be performed by multiple computing devices 700. Similarly, the functions of the computing device 700B can also be performed by multiple computing devices 700.
[0214] This application also provides another computing device cluster. The connection relationships between the computing devices in this computing device cluster can be similarly referred to... Figure 8 and Figure 9 The connection method of the computing device cluster is different in that the memory 706 of one or more computing devices 700 in the computing device cluster can store the same instructions for executing the methods in the above embodiments.
[0215] In some possible implementations, the memory 706 of one or more computing devices 700 in the computing device cluster may also store partial instructions for executing the aforementioned data processing method. In other words, a combination of one or more computing devices 700 can jointly execute the instructions for performing the aforementioned method.
[0216] Based on the methods in the above embodiments, this application provides a computer-readable storage medium including computer program instructions. When executed by a cluster of computing devices including at least one computing device, the computer program instructions cause the cluster of computing devices to perform the methods in the above embodiments. Exemplarily, the computer-readable storage medium can be any available medium capable of being stored in the cluster of computing devices or a data storage device such as a data center containing one or more available media. The available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives).
[0217] Based on the methods in the above embodiments, this application provides a computer program product containing instructions. The computer program product may be software or program products containing instructions, capable of running on a computing device or stored on any available medium. When the instructions are executed by a cluster of computing devices containing at least one computing device, at least one computing device in the cluster of computing devices performs the methods in the above embodiments.
[0218] It is understood that the processor in the embodiments of this application can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. A general-purpose processor can be a microprocessor or any conventional processor.
[0219] The method steps in the embodiments of this application can be implemented in hardware or by a processor executing software instructions. The software instructions can consist of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, portable hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor, enabling the processor to read information from and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can reside in an ASIC.
[0220] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0221] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application.
[0222] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of this application.
Claims
1. A data processing method, characterized in that, include: Obtain N input data; N is a positive integer greater than 1; Each input data is divided into P data segments to obtain N first data segment groups; the N first data segment groups correspond one-to-one with the N input data, and the inference time of each data segment in the P data segments is similar; P is a positive integer greater than 1; Based on the N first data fragment groups, inference is performed in P processing units so that different data fragments in each first data fragment group are processed by different processing units.
2. The method according to claim 1, characterized in that, The step of dividing each input data into P data segments to obtain N first data segment groups includes: Evaluate the first inference time for each of the input data; Based on the first inference duration and the number P of the processing units, determine the second inference duration for each of the P data segments; Based on the second inference duration, each input data is segmented to obtain the N first data segment groups.
3. The method according to claim 2, characterized in that, The evaluation of the first inference time for each of the input data includes: The first inference time is obtained based on the sequence length and / or historical statistics of each input data; the historical statistics represent the statistical information of the inference time of different input data.
4. The method according to any one of claims 1-3, characterized in that, The step of performing inference in P processing units based on the N first data fragment groups includes: The data segments of the N first data segment groups are combined to obtain P second data segment groups; the P second data segment groups correspond to the P processing units respectively, and the data segments of each second data segment group come from different first data segment groups. Inference is performed in each of the P second data fragment groups in the P processing units.
5. The method according to claim 4, characterized in that, Before combining the data segments of the N first data segment groups to obtain P second data segment groups, the method further includes: The N input data are divided into P data batches, which are then input into the P processing units respectively. The data from the P processing units are aggregated to obtain the N first data fragment groups.
6. The method according to claim 4 or 5, characterized in that, The step of performing inference in the P processing units based on the P groups of second data fragments includes: The P groups of second data segments are processed to obtain the corresponding P processing results; The P processing results are homogenized to obtain P homogenized processing results.
7. The method according to claim 6, characterized in that, The process of homogenizing the P processing results to obtain P homogenized processing results includes: Data exchange is performed on the P processing results to make the sequence lengths of different processing results among the P processing results approximately the same; Based on the processing results of P data exchanges, the P homogenization processing results are obtained.
8. The method according to any one of claims 1-7, characterized in that, The processing unit refers to a computing device that processes the data of a process in parallel.
9. A data processing apparatus, characterized in that, include: The acquisition module is used to acquire N input data; N is a positive integer greater than 9. The processing module is used to divide each input data into P data segments to obtain N first data segment groups; the N first data segment groups correspond one-to-one with the N input data, and the inference time of each data segment in the P data segments is similar; P is a positive integer greater than 9; Furthermore, based on the N first data fragment groups, inference is performed in P processing units so that different data fragments in each first data fragment group are processed by different processing units.
10. The apparatus according to claim 9, characterized in that, When dividing each input data into P data segments to obtain N first data segment groups, the processing module is specifically used for: Evaluate the first inference time for each of the input data; Based on the first inference duration and the number P of the processing units, determine the second inference duration for each of the P data segments; Based on the second inference duration, each input data is segmented to obtain the N first data segment groups.
11. The apparatus according to claim 10, characterized in that, When evaluating the first inference time for each of the input data, the processing module is specifically used for: The first inference time is obtained based on the sequence length and / or historical statistics of each input data; the historical statistics represent the statistical information of the inference time of different input data.
12. The apparatus according to any one of claims 9-11, characterized in that, When performing inference in P processing units based on the N first data fragment groups, the processing module is specifically used for: The data segments of the N first data segment groups are combined to obtain P second data segment groups; the P second data segment groups correspond to the P processing units respectively, and the data segments of each second data segment group come from different first data segment groups. Inference is performed in each of the P second data fragment groups in the P processing units.
13. The apparatus according to claim 12, characterized in that, Before combining the data segments of the N first data segment groups to obtain P second data segment groups, the processing module is further configured to: The N input data are divided into P data batches, which are then input into the P processing units respectively. The data from the P processing units are aggregated to obtain the N first data fragment groups.
14. The apparatus according to claim 12 or 13, characterized in that, When inference is performed in the P processing units based on the P groups of second data fragments, the processing module is specifically used for: The P groups of second data segments are processed to obtain the corresponding P processing results; The P processing results are homogenized to obtain P homogenized processing results.
15. The apparatus according to claim 14, characterized in that, When homogenizing the P processing results to obtain P homogenized processing results, the processing module is specifically used for: Data exchange is performed on the P processing results to make the sequence lengths of different processing results among the P processing results approximately the same; Based on the processing results of P data exchanges, the P homogenization processing results are obtained.
16. The apparatus according to any one of claims 9-15, characterized in that, The processing unit refers to a computing device that processes the data of a process in parallel.
17. A chip system, characterized in that, The chip system includes a processor and a power supply circuit, the power supply circuit being used to supply power to the processor, the processor being used to perform the method as described in any one of claims 1-8.
18. A computing device, characterized in that, The computing device includes a processor and memory; The processor is configured to execute instructions stored in the memory to cause the computing device to perform the method as described in any one of claims 1-8.
19. A computing device cluster, characterized in that, It includes at least one computing device, each computing device including a processor and memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform the method as described in any one of claims 1-8.
20. A computer-readable storage medium, characterized in that, The method includes computer program instructions that, when executed by a cluster of computing devices, cause the cluster of computing devices to perform the method as described in any one of claims 1-8, wherein the cluster of computing devices includes at least one computing device.
21. A computer program product containing instructions, characterized in that, When the instruction is executed by the computing device cluster, the computing device cluster causes the computing device cluster to perform the method as described in any one of claims 1-8, wherein the computing device cluster includes at least one computing device.
