A GPU task queue hierarchical reconstruction method and system based on shape entropy driving

By adopting a shape entropy-driven hierarchical reconstruction method for GPU task queues, the problems of cross-batch task layout reuse and resource waste are solved, achieving efficient task adaptation and computational resource optimization, and constructing a feedback loop across consecutive inference steps.

CN123157465APending Publication Date: 2026-11-24ZHEJIANG CHUANGLIN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611664572.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-27
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing technologies fail to effectively utilize the queue structure inheritance mechanism across consecutive batches in continuous batch processing scenarios, resulting in the non-reuse of task layouts, waste of computing resources, and load balancing issues. Furthermore, the dynamic scheduling mechanism fails to quantify when to change the task queue structure, affecting computing efficiency and resource utilization.

Method used

A shape entropy-driven hierarchical reconstruction method for GPU task queues is adopted. Candidate virtual blocks are generated by generating shape categories, normalized shape entropy, and virtual merging. The queue reconstruction mode is determined based on the normalized shape entropy, the persistent task queue on the device side is reconstructed, and an inverse permutation mapping table is established to optimize the task stealing range and result recovery while maintaining request-level computation semantics.

Benefits of technology

This reduces waste in request-level tail tiles, lowers dynamic scheduling overhead, improves task adaptability, maintains consistency in computation results, forms a feedback loop across consecutive inference steps, and optimizes resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123157465A_ABST
    Figure CN123157465A_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for hierarchical reconstruction of GPU task queues based on shape entropy. The method includes the following steps: forming request shape vectors and shape categories for the current consecutive batches on the GPU device side; calculating normalized shape entropy; generating and merging virtual operator task blocks based on the normalized shape entropy; reconstructing the persistent task queue based on the normalized shape entropy and simultaneously establishing an inverse permutation mapping; determining the stealing range based on the shape entropy of the consecutive batches to retrieve and execute different types of tasks; restoring the virtual order results to the original order results of the original requests based on the inverse permutation mapping table; and updating the shape classification boundary of the next consecutive batch based on the actual execution results. This invention can reduce the overhead of task queue reconstruction between consecutive batches by driving hierarchical reconstruction of the queue with shape entropy, eliminate tail block fragments with fixed tile granularity, and dynamically adjust classification boundaries, thereby improving task scheduling efficiency and resource utilization in GPU continuous batch processing scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of large model inference technology, and in particular to a method and system for hierarchical reconstruction of GPU task queues based on shape entropy. Background Technology

[0002] With the rapid development of large-model inference and GPU heterogeneous computing technologies, continuous batching has become a key mechanism for improving the throughput of online inference services. Since requests can exit after any inference step, and new requests can be dynamically inserted into subsequent inference steps, the actual request composition often changes continuously even when adjacent inference steps execute the same model. Specifically, within the same inference step, there may be multiple dynamic factors such as different numbers of valid tokens, different context lengths, different numbers of KVCache physical pages, different attention header configurations, different routing results from the Adapter and hybrid experts, and continuous changes in the M dimensions of matrix operations such as GEMM, resulting in a highly diverse shape characteristic of the inference load.

[0003] Existing technologies mainly follow three paths. The first path focuses on optimizing request-level batching timing, such as US11442775B1, which discloses a selective batching method for variable input lengths. Its optimization target remains at the level of batching relationships between requests or model operations. The second path focuses on input shape-aware compilation optimization, such as US20250004736A1, which generates corresponding program binaries based on input length combinations to reduce padding computational overhead. The third path further advances to device-side task scheduling. MPK converts tensor programs into SM-level task graphs and adopts decentralized scheduling; GPUOS introduces persistent resident kernels and atomic task queues; and Event Tensor supports tile-level task partitioning and dynamic push / pop management under dynamic shapes.

[0004] However, the existing technologies still have the following shortcomings: First, dynamic shape is treated as an isolated problem for a single execution, lacking a queue structure inheritance mechanism across consecutive batches, and the task layout formed between adjacent inference steps is not effectively reused; Second, the task partitioning method with fixed tile granularity is prone to tail block fragmentation when each request generates tasks independently, resulting in wasted computing resources; Third, the fully dynamic scheduling mechanism itself needs to bear the runtime overhead of task push / pop, atomic operations, and branch judgment, lacking a continuous state variable that can quantify when it is worthwhile to change the task queue structure and control the degree of change; Fourth, request reordering, task queue reconstruction, and result recovery are usually designed separately, making it difficult to efficiently maintain the original request order, KV page access, and semantic correspondence of Adapter / Expert states after reorganizing the computation lines on the device side; Fifth, existing dynamic scheduling only solves the load balancing problem of the current queue, without using the execution results of this round to update the shape classification boundary of the next consecutive batch, and the fixed classification boundary is prone to problems such as decreased tail block utilization or a surge in the number of tasks after load changes. Summary of the Invention

[0005] To address the challenge of driving hierarchical reconstruction of task queues based on shape-varying continuous quantization in continuous batch processing scenarios while simultaneously maintaining request-level computational semantics, this invention provides the following technical solution: This invention proposes a shape entropy-driven hierarchical reconstruction method for GPU task queues, comprising the following steps: Generate the shape category of each request in the current consecutive batch inference step of the GPU device based on the preset classification boundary table; Based on the shape category of each request, the normalized shape entropy corresponding to each shape category is obtained; Requests that meet the preset hard compatibility conditions are virtually merged to generate candidate virtual blocks. Based on the normalized shape entropy, the candidate virtual blocks are divided according to shape categories to obtain the virtual operator task blocks corresponding to each shape category. The queue reconstruction mode is determined based on the normalized shape entropy. Based on the queue reconstruction mode, the persistent task queue on the device side is reconstructed to generate corresponding queue segment data. The task descriptor corresponding to the virtual operator task block is also updated based on the queue reconstruction mode, and the inverse permutation mapping table of the virtual operator task block is established synchronously. The task stealing range is determined based on the normalized shape entropy and queue segment data. Based on the task stealing range and task descriptor, the corresponding device function is called to execute the virtual operator task block. After the virtual operator task block is executed, the virtual sequence result is obtained. After rearranging the virtual order results according to the original request order based on the inverse permutation mapping table, the execution result of the current consecutive inference step of the GPU device is generated; Based on the execution results of the current consecutive inference step of the GPU device, generate a classification boundary table for the next consecutive batch inference step.

[0006] As one possible implementation, the shape category of each request in the current consecutive batch inference steps of the GPU device is generated based on a preset classification boundary table, including: Obtain multiple shape dimension parameters for the i-th request in the current continuous inference step. The multiple shape dimension parameters include the number of valid tokens, the context length, and the number of physical pages of the key-value cache. Based on the preset valid token count classification boundary table, the valid token count is ranged to determine the range number in which the valid token count is located. The context length is determined by the preset context length classification boundary table to obtain the interval number of the context length. The key-value cache physical page number is determined by the preset key-value cache page number classification boundary table to obtain the interval number of the key-value cache physical page number; The shape category of the i-th request is obtained by combining the interval number of the valid token count, the interval number of the context length, and the interval number of the key-value cache pages with the attention header configuration number, adapter or expert number, and execution phase number of the i-th request.

[0007] As one possible implementation, based on the shape category of each request, the normalized shape entropy corresponding to each shape category is obtained, including: Count the number of requests belonging to the shape category in the current consecutive inference step, divide the number of requests by the total number of requests in the current consecutive inference step, and obtain the current batch probability of the shape category; Obtain the recursive probability of the previous consecutive inference step, and perform an exponentially weighted recursive calculation between the current batch probability and the recursive probability of the previous consecutive inference step to obtain the recursive probability of the current consecutive inference step. The original shape entropy is calculated based on the recursive probability of the current consecutive inference step; the expression for the original shape entropy is: ; Among them, H t For the original shape entropy, C t Let be the total number of shape categories actually appearing in the current consecutive reasoning step, t be the round number of the current consecutive reasoning step, and c be the sequence number of the shape category. The class probability is the result of recursion through consecutive batches; Based on the original shape entropy and the preset maximum number of shape categories, the normalized shape entropy is obtained; where the expression for the normalized shape entropy is: ; Among them, E tC represents the normalized shape entropy, with a value range of [0,1]. cap H represents the maximum number of shape categories that can be independently maintained on the equipment side. t This represents the entropy of the original shape.

[0008] As one possible implementation, requests that meet preset hard compatibility conditions are virtually merged to generate candidate virtual blocks. These candidate virtual blocks are then divided according to shape categories based on normalized shape entropy to obtain virtual operator task blocks corresponding to each shape category, including: Obtain the hard compatibility condition parameters of multiple requests belonging to the same operator type in the current inference step. The hard compatibility condition parameters include attention head group configuration number, adapter or expert number, execution stage number, data type and weight entry. When the hard compatibility condition parameters of multiple requests are the same, the multiple requests are virtually merged to generate candidate virtual blocks. Obtain the actual number of valid computation rows participating in the computation within the candidate virtual block. Based on the candidate M-dimensional granularity in the preset M-dimensional granularity set, calculate the tail block fragmentation rate when the candidate virtual block uses the candidate M-dimensional granularity. The expression for the tail block fragmentation rate when using the candidate M-dimensional granularity is: ; Among them, F g (m) represents the tail block fragmentation rate, ceil represents the rounding up function, g represents the candidate virtual block, and M g This represents the actual number of valid computation rows within the candidate virtual block g, where m is the candidate M-dimensional granularity; Calculate the base fragmentation rate for the current inference step when virtual merging is not performed; The upper limit of allowed additional fragmentation is calculated based on the normalized shape entropy and the base fragmentation rate; the upper limit of allowed additional fragmentation is used to limit the maximum allowable increase in tail block fragmentation rate after virtual merging; From the preset set of M-dimensional granularities, select candidate M-dimensional granularities that ensure the tail fragmentation rate does not exceed the upper limit of the allowable additional fragments, and take the maximum value among the candidate M-dimensional granularities that meet the conditions as the target M-dimensional granularity. Based on the target M-dimensional granularity, a corresponding task descriptor is generated for each candidate virtual block, and the candidate virtual blocks are divided into virtual operator task blocks.

[0009] As one possible implementation, a queue reconstruction mode is determined based on the normalized shape entropy. Based on the queue reconstruction mode, the persistent task queue on the device side is reconstructed to generate corresponding queue segment data. Furthermore, the task descriptor corresponding to the virtual operator task block is updated based on the queue reconstruction mode, including: When the normalized shape entropy is less than the preset first threshold, the queue reconstruction mode is determined to be the reuse mode. In the reuse mode, the original task descriptor physical slots are retained for queue segments whose shape category signatures have not changed. Only the request pointer, valid range, and task count in the task descriptor are updated to generate queue segment data. The task descriptor includes operator type, shape category number, virtual computation block shape, request and valid line range, key-value cache physical page table entry pointer, adapter or expert number, execution stage number, output write-back offset, inverse permutation mapping entry, and previous task completion count. When the normalized shape entropy is greater than or equal to the first threshold and less than the preset second threshold, the queue reconstruction mode is determined to be the local reconstruction mode; in the local reconstruction mode, the queue segments with changes in the number of shape categories and changes in the shape category boundaries are recompacted by the device-side prefix sum to obtain the queue segment data; the first threshold is less than the second threshold; When the normalized shape entropy is greater than or equal to the second threshold, the queue reconstruction mode is determined to be the full reconstruction mode. In the full reconstruction mode, the prefix of all queue segments is recalculated and a new task descriptor is generated to generate queue segment data.

[0010] As one possible implementation, the inverse permutation mapping table of the virtual operator task block is established synchronously, including: When dividing the candidate virtual block into virtual operator task blocks, for each logical calculation line number in the virtual operator task block, record the original request number to which the logical calculation line number belongs and the local offset of the logical calculation line number in the original request, and establish a positive mapping relationship from the logical calculation line number to the original request number and the local offset. For each logical computation line number in the virtual operator task block, establish a reverse mapping relationship from the original request number and local offset to the logical computation line number to obtain the inverse permutation mapping table.

[0011] As one possible implementation, the task stealing range is determined based on the normalized shape entropy and queue segment data. Based on the task stealing range and the task descriptor, the corresponding device function is called to execute the virtual operator task block. After the virtual operator task block is executed, a virtual sequence result is obtained, including: The number of queue segments in the current consecutive inference step is calculated based on the normalized shape entropy and the preset maximum number of queue segments in the queue segment data. Calculate the task stealing range of the current continuous inference step based on the normalized shape entropy and the number of queue segments in the current continuous inference step; The task stealing range is configured for each streaming multiprocessor. Each streaming multiprocessor first reads task descriptors from its own local queue segment. When there are no task descriptors to be executed in the local queue segment and other queue segments in its neighborhood, each streaming multiprocessor enters a global stealing state and steals and reads task descriptors from any queue segment that still has task descriptors to be executed. Each streaming multiprocessor extracts the operator type from the read task descriptor, calls the corresponding device function according to the operator type to perform calculation operations on the valid calculation lines in the virtual operator task block, and obtains the intermediate calculation results of each virtual operator task block; After each virtual operator task block is completed, each streaming multiprocessor releases subsequent tasks through atomic decrement operations, allowing the subsequent tasks to enter the execution state. The intermediate calculation results of each virtual operator task block are concatenated according to the order of the logical calculation lines in the virtual operator task block to obtain the virtual sequential result.

[0012] As one possible implementation, the virtual order results are rearranged according to the original request order based on the inverse permutation mapping table to generate the execution result of the current consecutive inference step of the GPU device, including: Obtain the virtual sequential result, in which each data element is arranged according to the order of the logical calculation row number in the virtual operator task block; For each data element corresponding to the logical calculation row number in the virtual sequence result, query the inverse permutation mapping table to obtain the original request number from which the data element originated and the local offset of the data element in the original request; Based on the original request number, local offset, and inverse permutation mapping table, restore all data elements in the virtual order result to the original order result at the original local position; Extract the output write-back offset from the task descriptor, and write the original sequential results to the original output location according to the output write-back offset to obtain the execution result of the current continuous inference step of the GPU device.

[0013] As one possible implementation, a classification boundary table for the next consecutive batch inference step is generated based on the execution result of the current consecutive inference step of the GPU device, including: After the current continuous inference step of the GPU device is completed, the ratio of the cumulative cycle of all waiting tasks in the streaming multiprocessor to the cumulative running cycle of all streaming multiprocessors is calculated to obtain the idle ratio of the streaming multiprocessor. The actual tail block fragmentation rate is obtained by calculating the ratio of the actual number of valid computing slots to the total number of valid computing slots and invalid tail slots within all computing blocks. The task theft rate is calculated by comparing the number of times a streaming multiprocessor retrieves tasks from a non-participating queue segment to the total number of tasks actually executed. The continuous average values ​​corresponding to the idle ratio of the streaming multiprocessor, the actual tail block fragmentation rate, and the task theft rate are obtained respectively. The continuous average values ​​of the idle ratio, the fragmentation rate, and the theft rate are obtained. The boundary adjustment direction is calculated, and the boundary adjustment direction is used to evaluate the rationality of the current classification boundary setting. Update the boundary scaling factor of the current continuous inference step based on the boundary adjustment direction amount, and obtain the boundary scaling factor of the next continuous inference step. Based on the boundary scaling factor of the next consecutive inference step, the initial valid token count classification boundary table, the initial context length classification boundary table, and the initial key-value cache page count classification boundary table are scaled as a whole, and the scaling results are rounded to obtain the valid token count classification boundary table, the context length classification boundary table, and the key-value cache page count classification boundary table for the next consecutive inference step.

[0014] This invention also provides a shape entropy-driven GPU task queue hierarchical reconstruction system, comprising: The shape category generation module is used to generate the shape category of each request in the current consecutive batch inference steps of the GPU device based on a preset classification boundary table; The shape entropy calculation module is used to obtain the normalized shape entropy corresponding to each shape category based on the shape category of each request; The virtual operator task block generation module is used to virtually merge requests that meet the preset hard compatibility conditions to generate candidate virtual blocks. Based on the normalized shape entropy, the candidate virtual blocks are divided according to shape categories to obtain the virtual operator task blocks corresponding to each shape category. The device-side queue reconstruction and inverse permutation mapping module is used to determine the queue reconstruction mode based on the normalized shape entropy, reconstruct the device-side persistent task queue based on the queue reconstruction mode to generate corresponding queue segment data, update the task descriptor corresponding to the virtual operator task block based on the queue reconstruction mode, and synchronously establish the inverse permutation mapping table of the virtual operator task block. The persistent task execution module is used to determine the task stealing range based on the normalized shape entropy and queue segment data, call the corresponding device function to execute the virtual operator task block based on the task stealing range and task descriptor, and obtain the virtual sequence result after the virtual operator task block is executed. The inverse permutation recovery module is used to rearrange the virtual order results according to the original request order based on the inverse permutation mapping table, and then generate the execution result of the current consecutive inference step of the GPU device. The classification boundary table feedback update module is used to generate the classification boundary table for the next consecutive batch of inference steps based on the execution results of the current consecutive inference steps of the GPU device.

[0015] This invention, by adopting the above technical solutions, has significant technical effects: This invention can reduce request-level tail tile waste, reduce the dynamic scheduling overhead of rule-based continuous batches, improve the task adaptability of highly heterogeneous batches, without adding framework layer regrouping and data copying, maintain the consistency of key-value cache, adapter parameters, expert subnetwork and output results, and form a feedback closed loop across continuous inference steps. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart illustrating a shape entropy-driven hierarchical reconstruction method for GPU task queues in one embodiment.

[0018] Figure 2 This is a schematic diagram of the structure of a shape entropy-driven GPU task queue hierarchical reconstruction system in one embodiment. Detailed Implementation

[0019] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. The following embodiments are explanations of the present invention, but the present invention is not limited to the following embodiments.

[0020] The following are explanations of the terms and English fields used in this invention: GPU: Graphics Processing Unit.

[0021] SM: Streaming Multiprocessor, which is a computing unit that executes thread blocks within the GPU.

[0022] warp: a group of GPU threads that execute in lockstep mode.

[0023] tile: computational block, representing a local computational region delineated from the complete operator computational domain.

[0024] KV Cache: Key-Value Cache.

[0025] GQA stands for Grouped-Query Attention.

[0026] MQA stands for Multi-Query Attention.

[0027] Adapter: The adapter parameter is used to load specific task-specific incremental parameters onto the base model.

[0028] Expert: Expert subnetwork, mainly used for hybrid expert models.

[0029] prefill: The prefill stage represents the stage of processing input prompts and building a key-value cache.

[0030] decode: The decoding stage, which represents the stage of autoregressive generation of subsequent tokens.

[0031] MoE: Mixture of Experts.

[0032] Sequence metadata: Sequence metadata records the request length, stage, and sequence running status.

[0033] prefix-sum: Prefix sum is used to calculate the starting offset of multiple queue segments in a contiguous array of task descriptors.

[0034] worker: A worker thread block, representing a thread block that resides in the SM (Site Manager) for a long time and continuously receives tasks.

[0035] TaskDescriptor: A task descriptor that records information such as the operator type, tile shape, request range, key-value page entry, and write-back location required by the persistent kernel to execute a virtual operator task.

[0036] operator_type: Operator type.

[0037] request_span: The range of requests and valid lines covered by this task.

[0038] kv_page_ptr: The KV physical page table entry pointer.

[0039] adapter_expert_id: The number of the Adapter or Expert.

[0040] output_offset: Output write-back offset.

[0041] dependency_counter: The count of completed preceding tasks.

[0042] like Figure 1 The figure shows a method for hierarchical reconstruction of GPU task queues based on shape entropy driven by this application, including the following steps; S1, Generate the shape category of each request in the current consecutive batch inference step of the GPU device based on the preset classification boundary table; S2, based on the shape category of each request, obtain the normalized shape entropy corresponding to each shape category; S3, virtually merge requests that meet the preset hard compatibility conditions to generate candidate virtual blocks, divide the candidate virtual blocks according to shape categories based on normalized shape entropy, and obtain the virtual operator task blocks corresponding to each shape category; S4. Determine the queue reconstruction mode based on the normalized shape entropy, reconstruct the persistent task queue on the device side based on the queue reconstruction mode to generate corresponding queue segment data, update the task descriptor corresponding to the virtual operator task block based on the queue reconstruction mode, and synchronously establish the inverse permutation mapping table of the virtual operator task block. S5. Determine the task stealing range based on the normalized shape entropy and queue segment data. Call the corresponding device function to execute the virtual operator task block based on the task stealing range and task descriptor. After the virtual operator task block is executed, obtain the virtual sequence result. S6, after rearranging the virtual sequence results according to the original request order based on the inverse permutation mapping table, the execution result of the current continuous inference step of the GPU device is generated; S7, based on the execution results of the current consecutive inference step of the GPU device, generates the classification boundary table for the next consecutive batch inference step.

[0043] In this embodiment, for multiple requests that can be virtually merged, based on Σceil(M) i / m)≥ceil(ΣM iBy using the method of ` / m`, it can be determined that the number of M-dimensional tiles after merging is no higher than the number of tiles generated independently per request, reducing request-level tail tile waste. At low shape entropy, the TaskDescriptor skeleton of the previous batch is directly reused, only modifying the changed request pointers and valid ranges, reducing the repeated generation of complete queues and lowering the dynamic scheduling overhead of rule-based continuous batches. As shape entropy increases, the number of queue segments is increased, the virtual merging range is tightened, and cross-shape task stealing is restricted, preventing different shapes from being forcibly placed into the same computational granularity, and improving the task adaptability of highly heterogeneous batches. Requests still maintain the logical batches given by the continuous batch processing framework; the device side only changes the mapping relationship of operator tiles, without adding framework layer regrouping and data copying. TaskDescriptor and inverse permutation table are generated synchronously; the virtual task order does not change the KV physical pages actually accessed by the request and the output logical address, maintaining consistency between KV, Adapter, Expert, and output results. The actual idle time, tail block fragmentation, and task stealing that occur on the GPU directly affect the shape classification boundary of the next batch, causing the task classification granularity to change with the online load. This forms a feedback loop across continuous inference steps. Shape vectors, consecutive batch shape entropy, virtual task blocks, queue segment topology, steal range, inverse permutation, and feedback boundary updates are continuously passed from the same batch of states, forming a single control chain.

[0044] As one possible implementation, S1 generates the shape category of each request in the current consecutive batch inference steps of the GPU device based on a preset classification boundary table, which may specifically include: S11, obtain multiple shape dimension parameters of the i-th request in the current continuous inference step. These parameters may include the number of valid tokens, context length, and the number of physical pages in the key-value cache. When the t-th continuous inference step contains N... t For each request, construct a shape vector for the i-th request. Shape vector It can be represented as: ;in, B represents the shape vector of the i-th request in the t-th consecutive inference step; i This indicates the number of valid tokens actually participating in the computation of the target operator for the current request, which can be derived from the valid token count generated by the scheduler in this round; L i This indicates the length of the current request context, which can be derived from request sequence metadata; P i This indicates a request for the current physical page number in the KVCache, which can be derived from the KV page table; H i This indicates the header group configuration number for Grouped Query Attention (GQA) or Multi-Query Attention (MQA), which can be derived from model structure metadata; R iThis indicates the adapter parameter number or expert subnetwork number, which can be derived from the adapter parameter binding table of this round or the routing results of the hybrid expert model (MoE); S i This indicates the execution phase number, with the prefill phase denoted as 0 and the decode phase as 1. It can be derived from the request's running status.

[0045] S12. Based on a preset valid token count classification boundary table, determine the range of valid token counts to obtain the range number of the valid token count; based on a preset context length classification boundary table, determine the range of context lengths to obtain the range number of the context length; based on a preset key-value cache page count classification boundary table, determine the range of key-value cache physical pages to obtain the range number of the key-value cache physical pages. Specifically, for Establish equipment side boundary tables respectively .in, The effective token count classification boundary, For context length classification boundaries, The initial valid token boundary is defined by the physical page number classification of the key-value (KV) domain. This boundary can be constructed using the M-dimensional basic micro-block size m0 of the persistence operator. It can be represented as: Where m0 can originate from the minimum M-dimensional computational micro-block fixed within the persistence operator. When each KV page contains... Each token represents a context boundary. and KV page number boundary They can be formed in the following ways: ; .

[0046] The above boundaries are all derived from the actual physical structure of the model and KV Cache, and offline model training is not required.

[0047] S13. Combine the interval number of the valid token count, the interval number of the context length, and the interval number of the key-value cache pages with the attention header configuration number, adapter or expert number, and execution phase number of the i-th request to obtain the shape category of the i-th request. Specifically, This indicates that the value is returned based on the boundary table D. Given the interval number, the shape category of the i-th request can be represented as: Among them, the header group, Adapter / Expert, and execution phase belong to computational semantic constraints and can use exact matching; the first three numerical dimensions can use updatable intervals.

[0048] In this embodiment, S1 does not modify the frame layer request batch, but only generates the computational shape category for operator tile reorganization on the device side. Its classification boundary can be modified by the actual GPU execution result in S7. Therefore, S1 also constitutes the input end of the closed loop.

[0049] As one possible implementation, in S2, based on the shape category of each request, the normalized shape entropy corresponding to each shape category is obtained, which may specifically include: S21, count the number of requests belonging to the shape category in the current consecutive inference step, divide the number of requests by the total number of requests in the current consecutive inference step, and obtain the current batch probability of the shape category. Optionally, count the number of requests n(c,t) of shape category c in the t-th inference step, and the current batch probability p(c,t) can be expressed as:

[0050] Where n(c,t) is the number of requests belonging to shape category c, N t p(c,t) represents the total number of requests for the current consecutive inference steps, and p(c,t) represents the proportion of category c in the current batch.

[0051] S22, obtain the recursive probability of the previous consecutive inference step, and perform an exponentially weighted recursive calculation between the current batch probability and the recursive probability of the previous consecutive inference step to obtain the recursive probability of the current consecutive inference step. To utilize the temporal continuity between consecutive batches, the class probability of the previous inference step is retained, and the recursive probability of the current consecutive inference step is calculated. :

[0052] in, The class probabilities are the results of recursive iterations through consecutive batches. Let ρ be the recursive category probability of the previous inference step, and ρ be the update coefficient of the current batch, with a value range of 0 < ρ ≤ 1. Here, ρ is derived from the continuous batch statistical window length W. When using an equivalent exponential window: ρ = 2 / (W + 1), where W is the number of continuous inference steps retained.

[0053] S23, calculate the original shape entropy based on the recursive probability of the current continuous inference step; where, the original shape entropy H t It can be represented as:

[0054] Among them, H t For the original shape entropy, C tt represents the total number of shape categories that actually appear in the current consecutive reasoning step, i.e., the number of shape categories that actually appear in the current step; t represents the round number of the current consecutive reasoning step, and c represents the sequence number of the shape category. This represents the class probability after continuous batch recursion.

[0055] S24, Based on the original shape entropy and the preset maximum number of shape categories, obtain the normalized shape entropy; where, the normalized shape entropy E t It can be represented as:

[0056] When there is actually only one category, E is specified. t =0. Where, H t E represents the shape entropy of the current consecutive batch, i.e., the original shape entropy. t The normalized continuous batch shape entropy, i.e., the normalized shape entropy, ranges from 0 to 1; C cap The maximum number of shape categories that can be independently maintained on the device side can be determined by the shape histogram capacity and the queue metadata capacity; low-frequency categories that exceed the capacity are classified as overflow categories.

[0057] As one possible implementation, in S3, requests that meet preset hard compatibility conditions are virtually merged to generate candidate virtual blocks. Based on normalized shape entropy, the candidate virtual blocks are divided according to shape categories to obtain virtual operator task blocks corresponding to each shape category, including: S31. Obtain the hard compatibility condition parameters of multiple requests belonging to the same operator type in the current inference step. The hard compatibility condition parameters include attention head group configuration number, adapter or expert number, execution stage number, data type, and weight entry. When the hard compatibility condition parameters of the multiple requests are all the same, the multiple requests are virtually merged to generate a candidate virtual block. Optionally, virtual merging is allowed for requests belonging to the same operator type and satisfying the following hard compatibility conditions: H i Same; R i Same; S i The data types are identical; the weight entries corresponding to the target operators are the same. The merging only changes the computation row mapping in the task descriptor; the key-value pages and result storage areas of the request itself remain independent.

[0058] S32. Obtain the actual number of valid computation rows participating in the computation in the candidate virtual block. Based on the candidate M-dimensional granularity in the preset M-dimensional granularity set, calculate the tail block fragmentation rate when the candidate virtual block uses the candidate M-dimensional granularity. Optionally, assume there are M candidate virtual blocks. g If there are valid M-dimensional computation rows, and the candidate tile contains m rows in M ​​dimensions, then the tail block fragmentation rate F g (m) can be represented as:

[0059] Among them, F g (m) represents the tail block fragmentation rate when virtual block g uses M-dimensional size m, M g Let m be the actual number of valid computation rows within the virtual block, m be the size of the candidate M-dimensional tile, and g be a virtual computation block to be generated. Further, the tail effect ratio W of the valid thread slots within the warp is statistically analyzed. g :W g =1-A g / (32·K g ), where W g For the proportion of the warp tail effect, A g K represents the number of thread slots corresponding to the actual effective elements executed. g 32 represents the number of warps actually issued by the virtual block, and 32 represents the number of threads contained in one warp in this embodiment.

[0060] S33. Calculate the current base fragmentation rate when virtual merging is not performed. :

[0061] in, M represents the current base fragmentation rate. i m is the number of actually valid computed rows within the i-th request virtual block. i Let M be the size of the tile for the i-th request.

[0062] S34. Calculate the allowable upper limit for additional fragmentation based on the normalized shape entropy and the base fragmentation rate; the allowable upper limit for additional fragmentation can be used to limit the maximum allowable increase in the tail block fragmentation rate after virtual merging. Optionally, the current merging upper limit is generated based on the shape entropy of consecutive batches. : ,in, This is the base fragmentation rate when the current batch generates tiles independently according to the original request. This is the maximum allowed additional fragmentation after virtual merging. High shape entropy means large request differences. Automatic reduction minimizes forced merging across dissimilar shapes; low shape entropy means requests are similar, allowing more requests to share a single virtual compute block.

[0063] S35. Select candidate M-dimensional granularities from the preset set of M-dimensional granularities that ensure the tail block fragmentation rate does not exceed the upper limit of the allowable additional fragmentation. Use the maximum value among the candidate M-dimensional granularities that meets the condition as the target M-dimensional granularity. Optionally, the persistence operator predefines a set M of legal M-dimensional granularities. Set M Set ={m0,2m0,4m0}, from satisfying The maximum value is selected from the candidate m.

[0064] S36. Based on the target M-dimensional granularity, generate corresponding task descriptors for each candidate virtual block, and divide the candidate virtual blocks into virtual operator task blocks. Optionally, using the maximum valid granularity can reduce the number of task descriptors while satisfying the tail block constraint; if there are no candidate values ​​that meet the conditions, split the current virtual block along the M-dimensional axis until each sub-block can be executed using m0. Here, m represents the computation range covered by the task descriptors within the same persistent operator, without selection among multiple independent GPU cores.

[0065] In this embodiment, shape entropy directly enters the task block formation process. The task partitioning and queue reconstruction modes share the same control source and are not simply a combination of the entropy judgment module and the ordinary tile module. For compatibility requests, based on the properties of the floor function: Therefore, when the hard compatibility condition is met and the same basic computational microblocks are used, the number of M-dimensional tiles generated by virtual merging will not be higher than the number of tiles generated independently per request.

[0066] As an example, merging virtual task blocks for consecutive decode requests can specifically include: With a fixed base of M-dimensional microblocks m0=16, and a set of legal task granularities M Set ={16,32,64}. The fixed input contains 64 requests, B i The sequence 1, 2, 4, and 8 repeats 16 times each; the first 56 requests have a context length of 1024 and a key-value page count of 32, while the last 8 requests have a context length of 1536 and a key-value page count of 48; all requests have a header group number of 4 and an adapter parameter number of 0, and are all in the decoding phase. Valid token classification boundary D. B ={4,16,64}.

[0067] The 48 requests with B values ​​of 1, 2, and 4 form one class, and the 16 requests with B value of 8 form another class, with probabilities of 0.75 and 0.25 respectively. The original shape entropy H and normalized shape entropy E are calculated for this fixed input: H=-(0.75·log20.75+0.25·log20.25)=0.811278 E = 0.811278 / log264 = 0.135213 E is less than 1 / 3, therefore it enters the reuse interval and remains in the low segment queue. The total number of valid M-dimensional computation rows for 64 requests is M. valid for: M valid =16×(1+2+4+8)=240 If a 32-row tile is used that is independent for each request, a total of M rows of effective M-dimensional computation rows need to be allocated. alloc-base and effective line utilization rate U base for: M alloc-base =64×32=2048 U base =240 / 2048=11.71875 After adopting this scheme, the first category with B values ​​of 1, 2, and 4 has a total of 112 rows, which are divided into 7 tiles based on 16-row basic micro-blocks; the second category with B value of 8 has a total of 128 rows, which are divided into 8 16-row tiles, for a total of 240 allocated rows, corresponding to a 100% utilization rate of effective rows in the M-dimensional dimension. This result is a verification result at the task descriptor level obtained by directly calculating the above formula for a fixed input, and does not include GPU throughput estimation.

[0068] As one possible implementation, in S4, the queue reconstruction mode is determined based on the normalized shape entropy, the device-side persistent task queue is reconstructed based on the queue reconstruction mode to generate corresponding queue segment data, and the task descriptor corresponding to the virtual operator task block is updated based on the queue reconstruction mode, including: After the persistent kernel (S411) boots, it maintains the following batch states and task descriptors in the device's global memory. The persistent kernel refers to the kernel that continuously resides on the GPU and continuously receives computational tasks after a single boot. The batch states include batch round number, continuous batch shape entropy, queue reconstruction mode, and queue version. The task descriptor contains operator type, shape category number, virtual computation block shape, request and valid line range, key-value cache physical page table entry pointer, adapter or expert number, execution stage number or decoding stage number, output write-back offset, inverse permutation mapping entry, and preceding task completion count. The queue reconstruction mode is determined based on the normalized shape entropy. When the normalized shape entropy is less than a preset first threshold, it indicates low entropy, and the queue reconstruction mode is determined as a reuse mode. When the normalized shape entropy is greater than or equal to the first threshold and less than a preset second threshold, it indicates medium entropy, and the queue reconstruction mode is determined as a partial reconstruction mode. When the first threshold is less than the second threshold, and the normalized shape entropy is greater than or equal to the second threshold, it indicates high entropy, and the queue reconstruction mode is determined as a full reconstruction mode. Specifically, the first threshold can be one-third, and the second threshold can be two-thirds, based on the normalized shape entropy E. t Refactoring Mode t It can be obtained in the following ways: ; ; ; In this context, Reuse represents the reuse mode, which only updates the request pointer, valid range, and task count in the previous round's task descriptor; Partial represents the partial reconstruction mode, which only regenerates queue segments where the number of categories or category boundaries have changed; and Full represents the full reconstruction mode, which reconstructs all virtual task blocks and queue segments. Shape entropy in this embodiment is not an independent statistical indicator, but rather directly determines whether and to what extent the physical description structure of the previous round's task queue is retained on the device side. In reuse mode, queue segments with unchanged category signatures retain the original task descriptor physical slots, modifying only request_span, kv_page_ptr, output_offset, and the valid task count. In partial reconstruction mode, the current round's task count n is calculated for each queue segment. (q,t) Compared to the number of tasks in the previous round, n (q,t-1) Quantity difference : ,right For queue segments whose shape boundary versions have changed, the device-side prefix-sum is recompacted. In full mode, the prefix sum of all segments is recalculated and a new TaskDescriptor array is generated.

[0069] In this embodiment, the changed objects include the TaskDescriptor slot organization, the number of queue segments, and the composition of each task segment; it also has a cross-continuous batch inheritance mechanism, so that the entire task queue is not regenerated when the shape is stable; and it avoids the atomic operation and scheduling overhead caused by using a fully dynamic task queue for all dynamic shapes.

[0070] As one possible implementation, the inverse permutation mapping table of the virtual operator task block is established synchronously, including: Write the inverse permutation map during each virtual merge, which may include: S421, when dividing the candidate virtual block into virtual operator task blocks, for each logical computation line number j in the virtual operator task block, record the original request number i to which the logical computation line number j belongs and the local offset o of the logical computation line number j in the original request, and establish a positive mapping relationship from the logical computation line number j to the original request number i and the local offset o. .

[0071] S422, for each logical computation line number in the virtual operator task block, establish a reverse mapping relationship from the original request number and local offset to the logical computation line number: Where j is the logical computation line number in the virtual task block, i is the original request number to which the computation line belonged, and o is the local offset of the computation line in the original request. This is a mapping table from the virtual computation order to the original request order. The queue reconstruction and inverse replacement table are generated during the same device-side scanning process to avoid scanning all requests again after reconstruction is complete.

[0072] This embodiment ensures consistent mapping of requests, KV pages, Adapters or Experts, and output addresses within the same resident kernel.

[0073] As one possible implementation, in S5, the task stealing range is determined based on the normalized shape entropy and queue segment data. Based on the task stealing range and the task descriptor, the corresponding device function is called to execute the virtual operator task block. After the virtual operator task block is executed, a virtual sequence result is obtained, including: S51, calculate the number of queue segments for the current consecutive inference step based on the normalized shape entropy and the preset maximum number of queue segments. Optionally, when the GPU has N... SM If there are SMs, then the maximum number of queue segments Q allowed on the device side is... max It can be represented as: , where Q mem N represents the maximum number of segments that the queue metadata area can support. SM This represents the total number of SMs in the GPU. Based on the normalized shape entropy E... t and the preset maximum number of queue segments Q max Calculate the number of queue segments in the current consecutive inference step, then the current number of queue segments Q. t It can be represented as: When the shape is uniform, tasks are concentrated in a small number of shared queues; when the shape is more heterogeneous, the queues are automatically divided into more task segments with similar shapes.

[0074] S52, calculate the task-stealing range for the current consecutive inference step based on the normalized shape entropy and the number of queue segments in the current consecutive inference step. Specifically, the persistent kernel launches a block of worker threads that matches or does not exceed the number of GPU SMs. Each SM preferentially reads the TaskDescriptor from its corresponding queue segment, thus determining the currently allowed task-stealing segment radius R. steal,t It can be represented as: , where R steal,t E represents the maximum number of queue segments that an SM can traverse, i.e., the radius of the currently allowed task-stealing segment. t The shape entropy for consecutive batches, i.e., the normalized shape entropy, is Q. t This represents the current number of queue segments.

[0075] S53, the task stealing range is configured for each streaming multiprocessor. Each streaming multiprocessor preferentially reads task descriptors from its corresponding local queue segment. When there are no task descriptors to be executed in the local queue segment and other queue segments in its neighborhood, each streaming multiprocessor enters a global stealing state, stealing and reading task descriptors from any queue segment that still has task descriptors to be executed. Optionally, if there are no tasks locally and within the allowed range, the SM enters a global fallback stealing state, taking tasks from any queue segment that still has tasks, preventing the SM from being idle for a long time due to local segment restrictions. Optionally, when E t At higher values, the execution differences between different shapes are significant. SM prioritizes stealing tasks within adjacent shape queue segments, reducing branch divergence caused by frequent operator state switching and different tile paths; when E t At lower speeds, the shapes of each task are similar, allowing for a larger theft range and improving SM load balancing capabilities.

[0076] In step S54, each streaming multiprocessor extracts the operator type from the read task descriptor, and calls the corresponding device function to perform computation operations on the valid computation lines in the virtual operator task block according to the operator type, thereby obtaining the intermediate computation results of each virtual operator task block. Optionally, each TaskDescriptor carries an operator_type, so the same persistent kernel can enter the corresponding device function execution logic according to the task type.

[0077] S55, after each virtual operator task block is executed, each streaming multiprocessor releases subsequent tasks through an atomic decrement operation, allowing the subsequent tasks to enter the execution state. Optionally, after a task is completed, subsequent tasks are released by atomically decrementing the dependency_counter, allowing the subsequent tasks to enter the executable state.

[0078] S56, the intermediate calculation results of each virtual operator task block are concatenated according to the order of the logical calculation lines in the virtual operator task block to obtain the virtual sequential result.

[0079] In the above steps, task stealing itself is a known scheduling technique. The difference in this embodiment is that the scope of task stealing is directly calculated by the shape entropy of the same continuous batch that forms the current virtual block and queue segment, so that queue segmentation and cross-segment scheduling are consistent.

[0080] As an example, queue segment expansion under highly heterogeneous continuous batches can specifically include: The fixed input is 64 requests. The number of valid tokens is B. i Context length L i KV Page Number P i Head group H i and Adapter number R iFrom the following set of valid tokens B respectively Set Context length set L Set KV page set P Set Head set H Set and Adapter ID set R Set Generates indexes according to the deterministic index formula: B Set ={1,2,4,8,16,24,32,48,64,96,128} L Set ={256,512,1024,048,4096,8192,12288} P Set ={8,16,32,64,128,256,384} H Set ={1,4,8},R Set ={0,1,2,3} B i =B Set [(3i+floor(i / 7)) mod 11] L i =L Set [(5i+floor(i / 5)) mod 7] P i =P Set [(4i+floor(i / 3)) mod 7] H i =H Set [(2i+floor(i / 4)) mod 3] R i =R Set [(i+floor(i / 6)) mod 4] During the execution phase, every three requests switch between the decode phase and the prefill phase. After encoding the fixed input using six-dimensional precise categories, the 64 requests form 64 different shape categories, each with a probability of 1 / 64. Therefore, the original shape entropy H and the normalized shape entropy E are: H = -64 × (1 / 64) × log2(1 / 64) = 6 E = 6 / log264 = 1 If the maximum number of queue segments allowed on the device side is Q max=6, then the current queue segment quantity Q is: Q=1+floor[(6-1)×1]=6, indicating that it has entered the full reconstruction mode and formed 6 shape queue segments. For the above fixed input, the effective M-dimensional total number of rows is 1828. If each request uses a fixed 32-row tile, a total of 2912 rows are allocated, and the effective row utilization rate U 32 For: U 32 =1828 / 2912=62.7747%.

[0081] Using the legal granularity set {16, 32, 64} of this scheme, the upper limit of additional fragmentation is merged when E=1. =0; for short tasks not divisible by 32 or 64, degenerate to a 16-line basic microblock. For 64 fixed B i After item-by-item calculation, the total number of allocated rows is 2176. Therefore, the effective row utilization rate U after reconstruction is... rebuild For: U rebuild = 1828 / 2176 = 84.0074%.

[0082] The above verification shows that in highly heterogeneous scenarios, shape entropy does not force different requests to be merged into the same task shape. Instead, it increases the number of queue segments and tightens cross-shape merging. At the same time, it reduces the empty slots at the tail of the fixed 32-row tile by using finer granularity of legal tasks. This result is also a deterministic calculation result with fixed input.

[0083] As one possible implementation, in S6, after rearranging the virtual sequence results according to the original request order based on the inverse permutation mapping table, the execution result of the current consecutive inference step of the GPU device is generated, including: S61: Obtain the virtual order result. The data elements in the virtual order result are arranged according to the logical computation row numbers in the virtual operator task block. For each data element corresponding to a logical computation row number in the virtual order result, query the inverse permutation mapping table to obtain the original request number from which the data element originates and the local offset of the data element in the original request. Based on the original request number, local offset, and inverse permutation mapping table, restore all data elements in the virtual order result to their original local positions. Optionally, the virtual order result is obtained after writing to the virtual computation block in S5. Based on the inverse permutation mapping generated synchronously by S4 Restore the result to: ,in, This refers to the result in the virtual task sequence, i.e., the virtual sequence result. This is to request the result of i at the original local position o, i.e., the original order result.

[0084] S62 extracts the output write-back offset from the task descriptor and writes the original sequential results to the original output position according to the output write-back offset, obtaining the execution result of the current consecutive inference step of the GPU device. Optionally, in an implementation with an independent output_offset, the original output position can be directly written according to the mapping when the task is completed, making the inverse permutation process degenerate into address transformation, without the need to copy the complete result tensor. KV access accesses the original request page table through kv_page_ptr in TaskDescriptor, so even if the computation lines of different requests are located in the same virtual tile, the attention visibility range between requests will not be changed. Adapter and Expert ensure that the same parameter entry is used within the same virtual block through the adapter_expert_id hard compatibility condition. The inverse permutation table is generated simultaneously with the S4 queue generation, making task reconstruction, computation, and recovery form the same mapping chain.

[0085] One possible implementation is to generate a classification boundary table for the next consecutive batch inference step based on the execution result of the current consecutive inference step of the GPU device, including: S71. After the current continuous inference step on the GPU device has finished executing, calculate the ratio of the cumulative cycle of all streaming multiprocessor waiting tasks to the cumulative running cycle of all streaming multiprocessors to obtain the streaming multiprocessor idle ratio. Specifically, after each batch round, calculate the SM idle ratio, actual tail block fragmentation rate, and task stealing rate on the GPU device side. The SM idle ratio can be expressed as: , among which, I t This represents the idle ratio of SM. The cumulative period for all workers waiting for tasks. The total running cycle for all workers.

[0086] S72. Calculate the ratio of the actual number of valid computing slots to the total number of valid computing slots and invalid tail slots within all computing blocks to obtain the actual tail block fragmentation rate. The actual tail block fragmentation rate can be expressed as: , of which F t A represents the actual tail fragmentation rate in this round. t Z represents the actual number of effective slots within all tiles. t This represents the number of slots for which there is no corresponding valid data due to insufficient tail tiles.

[0087] S73. The task theft rate is calculated by comparing the number of times a streaming multiprocessor retrieves tasks from non-participating queue segments to the total number of tasks actually executed. The task theft rate can be expressed as: , where K t For mission steal rate, This represents the number of times the SM (Skill Provider) retrieves tasks from non-affiliated queue segments. This represents the total number of tasks actually performed in this round.

[0088] S74. Obtain the continuous averages of the idle ratio, actual tail block fragmentation rate, and task stealing rate of the streaming multiprocessor, respectively, to obtain the continuous average of the idle ratio I. t Fragmentation rate continuous mean F t and the continuous mean of theft rate K t Calculate the boundary adjustment direction amount, which is used to evaluate the rationality of the current classification boundary setting; the boundary adjustment direction amount G. t It can be represented as: If the idle rate and theft rate increase, it indicates that the queue has been divided too finely. t To increase the size, the shape category range should be expanded; if the tail block fragmentation rate increases, G t To reduce this, the range of shape categories should be narrowed.

[0089] S75. Update the boundary scaling factor of the current continuous inference step according to the boundary adjustment direction amount to obtain the boundary scaling factor of the next continuous inference step. Optionally, the current classification boundary scaling factor is s. t Then the boundary scaling factor s of the next consecutive inference step t+1 The update formula is: , where clip is a truncation function that limits the result to specified upper and lower limits; s min s max η represents the minimum and maximum allowed boundary scaling factors; η is the update step size per round. η can be based on the maximum allowed boundary change rate per batch. The calculation yielded: Of these, 3 comes from I t、 K t、 F t Three normalized feedback components.

[0090] S76. Based on the boundary scaling factor s of the next consecutive inference step. t+1 Classification boundary table for the initial number of valid tokens Initial context length classification boundary table Initial key-value cache page number category boundary table Perform overall scaling and round the scaling result to obtain the effective token count classification boundary table for the next consecutive inference step. Context length classification boundary table for the next consecutive inference step Key-value cache page number classification boundary table for the next consecutive inference step Then the new classification boundary table can be represented as:

[0091]

[0092]

[0093] Among them, round Mset Indicates rounding to a valid M-dimensional tile multiple; round vpage This indicates rounding down to the nearest multiple of the KV page token capacity; round z This indicates rounding down to the integer page number. The output of S7 directly becomes the classification boundary for the next S1, thus forming a closed loop: request shape → continuous shape entropy → virtual task block → queue topology → SM execution → actual feedback → next round shape boundary. The shape classification change has a clear hardware result source.

[0094] like Figure 2 As shown, another embodiment of this application provides a shape entropy-driven GPU task queue hierarchical reconstruction system 20, including: Shape category generation module 21 is used to generate the shape category of each request in the current consecutive batch inference step of the GPU device based on a preset classification boundary table; The shape entropy calculation module 22 is used to obtain the normalized shape entropy corresponding to each shape category based on the shape category of each request; The virtual operator task block generation module 23 is used to virtually merge requests that meet the preset hard compatibility conditions to generate candidate virtual blocks, and divide the candidate virtual blocks according to shape categories based on normalized shape entropy to obtain the virtual operator task blocks corresponding to each shape category. The device-side queue reconstruction and inverse permutation mapping module 24 is used to determine the queue reconstruction mode based on the normalized shape entropy, reconstruct the device-side persistent task queue based on the queue reconstruction mode to generate corresponding queue segment data, update the task descriptor corresponding to the virtual operator task block based on the queue reconstruction mode, and synchronously establish the inverse permutation mapping table of the virtual operator task block. The persistent task execution module 25 is used to determine the task stealing range based on the normalized shape entropy and queue segment data, call the corresponding device function to execute the virtual operator task block based on the task stealing range and task descriptor, and obtain the virtual sequence result after the virtual operator task block is executed. The inverse permutation recovery module 26 is used to rearrange the virtual order results according to the original request order based on the inverse permutation mapping table, and then generate the execution result of the current continuous inference step of the GPU device. The classification boundary table feedback update module 27 is used to generate the classification boundary table for the next consecutive batch inference step based on the execution result of the current consecutive inference step of the GPU device.

[0095] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0096] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0097] This invention is described with reference to flowchart illustrations and / or block diagrams of the method, terminal device (system), and computer program product according to the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0098] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0099] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0100] It should be noted that: The phrase "an embodiment" or "an embodiment" used in this specification means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the invention. Therefore, the phrase "an embodiment" or "an embodiment" appearing in various places throughout the specification does not necessarily refer to the same embodiment.

[0101] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the invention.

[0102] Furthermore, it should be noted that the shapes and names of the parts and components described in the specific embodiments described in this specification may differ. All equivalent or simple variations made to the structure, features, and principles described in this patent concept are included within the protection scope of this patent. Those skilled in the art to which this invention pertains may make various modifications or additions to the described specific embodiments or use similar methods to replace them, as long as they do not depart from the structure of this invention or exceed the scope defined in these claims, they should all fall within the protection scope of this invention.

Claims

1. A method for hierarchical reconstruction of GPU task queues based on shape entropy, characterized in that, Includes the following steps: Generate the shape category of each request in the current consecutive batch inference step of the GPU device based on the preset classification boundary table; Based on the shape category of each request, the normalized shape entropy corresponding to each shape category is obtained; Requests that meet the preset hard compatibility conditions are virtually merged to generate candidate virtual blocks. The candidate virtual blocks are divided according to shape categories based on the normalized shape entropy to obtain virtual operator task blocks corresponding to each shape category. The queue reconstruction mode is determined based on the normalized shape entropy. Based on the queue reconstruction mode, the persistent task queue on the device side is reconstructed to generate corresponding queue segment data. The task descriptor corresponding to the virtual operator task block is also updated based on the queue reconstruction mode, and the inverse permutation mapping table of the virtual operator task block is established synchronously. The task stealing range is determined based on the normalized shape entropy and the queue segment data. The corresponding device function is called to execute the virtual operator task block based on the task stealing range and the task descriptor. After the virtual operator task block is executed, the virtual sequence result is obtained. After rearranging the virtual order results according to the original request order based on the inverse permutation mapping table, the execution result of the current consecutive inference step of the GPU device is generated; Based on the execution results of the current consecutive inference step of the GPU device, a classification boundary table for the next consecutive batch inference step is generated.

2. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 1, characterized in that, The process of generating the shape category of each request in the current consecutive batch inference steps of the GPU device based on a preset classification boundary table includes: Obtain multiple shape dimension parameters for the i-th request in the current continuous inference step, including the number of valid tokens, context length, and number of physical pages in the key-value cache; Based on a preset valid token count classification boundary table, the valid token count is ranged to determine the range number in which the valid token count is located. The context length is determined by a preset context length classification boundary table to obtain the interval number in which the context length is located. The key-value cache physical page number is ranged according to the preset key-value cache page number classification boundary table to obtain the range number of the key-value cache physical page number; The shape category of the i-th request is obtained by combining the interval number of the valid token count, the interval number of the context length, and the interval number of the key-value cache pages with the attention header configuration number, adapter or expert number, and execution phase number of the i-th request.

3. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 2, characterized in that, The process of obtaining the normalized shape entropy corresponding to each shape category based on each request includes: The number of requests belonging to the shape category in the current consecutive inference step is counted, and the number of requests is divided by the total number of requests in the current consecutive inference step to obtain the current batch probability of the shape category; Obtain the recursive probability of the previous consecutive inference step, and perform an exponentially weighted recursive calculation between the current batch probability and the recursive probability of the previous consecutive inference step to obtain the recursive probability of the current consecutive inference step. The original shape entropy is calculated based on the recursive probability of the current consecutive inference step; wherein, the expression for the original shape entropy is: ; Among them, H t Let C be the entropy of the original shape. t Let be the total number of shape categories actually appearing in the current consecutive inference step, t be the round number of the current consecutive inference step, and c be the sequence number of the shape category. The class probability is the result of recursion through consecutive batches; The normalized shape entropy is obtained based on the original shape entropy and the preset maximum number of shape categories; wherein, the expression for the normalized shape entropy is: ; Among them, E t The normalized shape entropy represents the value range [0,1], C cap H represents the maximum number of shape categories that can be independently maintained on the equipment side. t The entropy of the original shape.

4. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 3, characterized in that, The process of virtually merging requests that meet preset hard compatibility conditions to generate candidate virtual blocks, and dividing the candidate virtual blocks according to shape categories based on the normalized shape entropy to obtain virtual operator task blocks corresponding to each shape category includes: Obtain the hard compatibility condition parameters of multiple requests belonging to the same operator type in the current inference step. The hard compatibility condition parameters include attention head group configuration number, adapter or expert number, execution stage number, data type and weight entry. When the hard compatibility condition parameters of the multiple requests are all the same, the multiple requests are virtually merged to generate candidate virtual blocks. Obtain the actual number of valid computation rows participating in the computation in the candidate virtual block, and calculate the tail block fragmentation rate when the candidate virtual block uses the candidate M-dimensional granularity according to the candidate M-dimensional granularity in the preset M-dimensional granularity set; wherein, the expression for the tail block fragmentation rate when using the candidate M-dimensional granularity is: ; Among them, F g (m) represents the tail block fragmentation rate, ceil represents the rounding up function, g represents the candidate virtual block, and M g This represents the actual number of valid computation rows within the candidate virtual block g, where m is the candidate M-dimensional granularity; Calculate the base fragmentation rate for the current inference step when virtual merging is not performed; Based on the normalized shape entropy and the base fragmentation rate, the upper limit of allowed additional fragmentation is calculated; the upper limit of allowed additional fragmentation is used to limit the maximum allowable increase in tail block fragmentation rate after virtual merging; From the preset set of M-dimensional granularities, select candidate M-dimensional granularities that ensure the tail fragmentation rate does not exceed the upper limit of the allowable additional fragments, and take the maximum value among the candidate M-dimensional granularities that meet the conditions as the target M-dimensional granularity. Based on the target M-dimensional granularity, a corresponding task descriptor is generated for each candidate virtual block, and the candidate virtual blocks are divided into the virtual operator task blocks.

5. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 4, characterized in that, The process of determining the queue reconstruction mode based on the normalized shape entropy, reconstructing the device-side persistent task queue based on the queue reconstruction mode to generate corresponding queue segment data, and updating the task descriptor corresponding to the virtual operator task block based on the queue reconstruction mode includes: When the normalized shape entropy is less than a preset first threshold, the queue reconstruction mode is determined to be a reuse mode. In the reuse mode, the original task descriptor physical slots are retained for queue segments whose shape category signatures have not changed. Only the request pointer, valid range, and task count in the task descriptor are updated to generate the queue segment data. The task descriptor includes operator type, shape category number, virtual computation block shape, request and valid line range, key-value cache physical page table entry pointer, adapter or expert number, execution stage number, output write-back offset, inverse permutation mapping entry, and previous task completion count. When the normalized shape entropy is greater than or equal to the first threshold and less than the preset second threshold, the queue reconstruction mode is determined as a local reconstruction mode; in the local reconstruction mode, the queue segments with changes in the number of shape categories and changes in the shape category boundaries are subjected to device-side prefix sum and recompacted to obtain the queue segment data; the first threshold is less than the second threshold; When the normalized shape entropy is greater than or equal to the second threshold, the queue reconstruction mode is determined to be the full reconstruction mode; in the full reconstruction mode, the prefix of all queue segments is recalculated and a new task descriptor is generated to generate the queue segment data.

6. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 5, characterized in that, The synchronous establishment of the inverse permutation mapping table for the virtual operator task block includes: When dividing the candidate virtual block into the virtual operator task block, for each logical calculation line number in the virtual operator task block, record the original request number to which the logical calculation line number belongs and the local offset of the logical calculation line number in the original request, and establish a positive mapping relationship from the logical calculation line number to the original request number and the local offset. For each logical computation row number in the virtual operator task block, establish a reverse mapping relationship from the original request number and the local offset to the logical computation row number to obtain the inverse permutation mapping table.

7. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 6, characterized in that, The process involves determining the task stealing range based on the normalized shape entropy and the queue segment data, invoking the corresponding device function to execute the virtual operator task block based on the task stealing range and the task descriptor, and obtaining a virtual sequence result after the virtual operator task block has been executed. The number of queue segments in the current consecutive inference step is calculated based on the normalized shape entropy and the preset maximum number of queue segments in the queue segment data. The task stealing range of the current continuous inference step is calculated based on the normalized shape entropy and the number of queue segments of the current continuous inference step. The task stealing range is configured for each streaming multiprocessor. Each streaming multiprocessor first reads the task descriptor from its own local queue segment. When there are no task descriptors to be executed in the local queue segment and other queue segments in its neighborhood, each streaming multiprocessor enters a global stealing state and steals and reads the task descriptor from any queue segment that still has task descriptors to be executed. Each of the streaming multiprocessors extracts the operator type from the read task descriptor, and calls the corresponding device function according to the operator type to perform calculation operations on the valid calculation lines in the virtual operator task block to obtain the intermediate calculation results of each virtual operator task block; After each virtual operator task block is executed, each streaming multiprocessor releases subsequent tasks through an atomic decrement operation, allowing the subsequent tasks to enter the execution state. The intermediate calculation results of each virtual operator task block are concatenated according to the arrangement order of the logical calculation lines in the virtual operator task block to obtain the virtual sequential result.

8. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 7, characterized in that, The step of rearranging the virtual order results according to the original request order based on the inverse permutation mapping table to generate the execution result of the current consecutive inference step of the GPU device includes: Obtain the virtual sequence result, wherein each data element in the virtual sequence result is arranged in the order of the logical calculation row number in the virtual operator task block; For each data element corresponding to the logical calculation row number in the virtual sequence result, query the inverse permutation mapping table to obtain the original request number from which the data element originates and the local offset of the data element in the original request; Based on the original request number, the local offset, and the inverse permutation mapping table, all data elements in the virtual order result are restored to the original order result of the original local position; Extract the output write-back offset from the task descriptor, and write the original sequential result to the original output position according to the output write-back offset to obtain the execution result of the current continuous inference step of the GPU device.

9. The GPU task queue hierarchical reconstruction method based on shape entropy as described in claim 8, characterized in that, The step of generating a classification boundary table for the next consecutive batch inference step based on the execution result of the current consecutive inference step of the GPU device includes: After the current continuous inference step of the GPU device is completed, the ratio of the cumulative cycle of all streaming multiprocessor waiting tasks to the cumulative running cycle of all streaming multiprocessors is calculated to obtain the streaming multiprocessor idle ratio. The actual tail block fragmentation rate is obtained by calculating the ratio of the actual number of valid computing slots to the total number of valid computing slots and invalid tail slots within all computing blocks. The task theft rate is calculated by comparing the number of times a streaming multiprocessor retrieves tasks from a non-participating queue segment to the total number of tasks actually executed. The continuous average values ​​corresponding to the idle ratio of the streaming multiprocessor, the actual tail block fragmentation rate, and the task theft rate are obtained respectively to obtain the continuous average value of the idle ratio, the continuous average value of the fragmentation rate, and the continuous average value of the theft rate. The boundary adjustment direction amount is calculated, and the boundary adjustment direction amount is used to evaluate the rationality of the current classification boundary setting. The boundary scaling factor of the current continuous inference step is updated based on the boundary adjustment direction amount to obtain the boundary scaling factor of the next continuous inference step. Based on the boundary scaling factor of the next consecutive inference step, the initial valid token count classification boundary table, the initial context length classification boundary table, and the initial key-value cache page count classification boundary table are scaled as a whole, and the scaling results are rounded to obtain the valid token count classification boundary table, the context length classification boundary table, and the key-value cache page count classification boundary table for the next consecutive inference step.

10. A system for hierarchical reconstruction of GPU task queues based on shape entropy, characterized in that, The system includes: The shape category generation module is used to generate the shape category of each request in the current consecutive batch inference steps of the GPU device based on a preset classification boundary table; The shape entropy calculation module is used to obtain the normalized shape entropy corresponding to each shape category based on the shape category of each request; The virtual operator task block generation module is used to virtually merge requests that meet preset hard compatibility conditions to generate candidate virtual blocks, and divide the candidate virtual blocks according to shape categories based on the normalized shape entropy to obtain the virtual operator task blocks corresponding to each shape category. The device-side queue reconstruction and inverse permutation mapping module is used to determine the queue reconstruction mode based on the normalized shape entropy, reconstruct the device-side persistent task queue based on the queue reconstruction mode to generate corresponding queue segment data, update the task descriptor corresponding to the virtual operator task block based on the queue reconstruction mode, and synchronously establish the inverse permutation mapping table of the virtual operator task block. The persistent task execution module is used to determine the task stealing range based on the normalized shape entropy and the queue segment data, call the corresponding device function to execute the virtual operator task block based on the task stealing range and the task descriptor, and obtain the virtual sequence result after the virtual operator task block is executed. The inverse permutation recovery module is used to rearrange the virtual order results according to the original request order based on the inverse permutation mapping table, and then generate the execution result of the current continuous inference step of the GPU device. The classification boundary table feedback update module is used to generate the classification boundary table for the next consecutive batch inference step based on the execution result of the current consecutive inference step of the GPU device.

Citation Information

Patent Citations

  • Dynamic batching for inference system for transformer-based generation tasks

    US11442775B1

  • Generating program binaries for a transformer to process sequence concatenations having different input lengths

    US20250004736A1