A method, device, equipment and storage medium for reasoning of a large language model
By initializing the configuration of the inference engine of the large language model and optimizing and segmenting the model layers and operators, the problems of computing resource consumption and video memory management of the inference system in the existing technology are solved, and more efficient inference speed and resource utilization are achieved. Rate.
Patent Information
- Application Number
- CN202410633344.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-05-21
AI Technical Summary
Existing large language model inference systems have challenges in terms of computing resource consumption and user waiting delays. The inference speed is unsatisfactory, and memory management limits the inference batch size, which cannot meet the growing user needs.
By obtaining the original model input by the user, the inference engine is initialized and configured, and the preset integrated training tool is used to replace and segment the model layers and operators according to the optimization strategy, and is deployed on multiple accelerator cards. The optimized model is used To generate results, improve reasoning efficiency and resource utilization.
It significantly improves the inference speed and computing resource utilization of large language models, meets the growth of user needs, optimizes video memory management, and improves the performance of the inference system.
Smart Images

Figure CN118364918B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an inference method, device, equipment and storage medium for a large language model. Background Art
[0002] In recent years, thanks to the continuous development of computing resource hardware (industrial-grade graphics cards), parallel training systems, and algorithms (supervised fine-tuning and reinforcement learning, etc.), large language models have received unprecedented attention and flourished. Large language models have achieved outstanding performance in natural language understanding and generation tasks in various application scenarios. At the same time, the demand for efficient and highly available large language model inference systems has gradually increased, promoting the advancement of model optimization and deployment technologies.
[0003] In the prior art, when processing large language model reasoning tasks, the reasoning system faces many challenges, including but not limited to computing resource consumption, long user waiting time, reduced reasoning speed, etc. In response to these challenges, the reasoning system often uses various optimization techniques to improve reasoning efficiency and performance.
[0004] However, existing optimization methods have limitations in some cases and cannot meet the growing needs of users. Their inference speed is not satisfactory, and there are many restrictions on video memory management, which limits the inference batch size. Summary of the invention
[0005] The present invention provides a large language model reasoning method, device, equipment and storage medium, which can improve the reasoning efficiency of the large language model and improve the utilization rate of computing resources.
[0006] According to one aspect of the present invention, a large language model reasoning method is provided, which is applied to a reasoning engine, and the method comprises:
[0007] Obtaining the original model input by the user and initializing the configuration of the inference engine;
[0008] By using a preset integrated training tool, according to the current optimization strategy corresponding to the inference engine, the model layer and the operator in the original model are replaced, the original model is segmented, and the multiple segmentation results are respectively deployed on multiple different accelerator cards to obtain an optimized model;
[0009] Obtain a prompt word sequence input by a user, and output a generation result of the prompt word sequence through the optimized model reasoning.
[0010] Optionally, before the original model is segmented by a preset integrated training tool, the method further includes:
[0011] Pre-allocate a corresponding activation cache for each accelerator card;
[0012] Initialize the block KV cache manager corresponding to the inference engine, and allocate a corresponding block KV cache to each accelerator card;
[0013] Initialize the scheduler corresponding to the inference engine.
[0014] Optionally, obtaining a prompt word sequence input by a user, and outputting a generation result of the prompt word sequence through inference of the optimized model, includes:
[0015] The prompt word sequence input by the user is obtained, the sequence is scheduled by the scheduler corresponding to the inference engine, and then the generation result of the prompt word sequence is output through the optimized model inference.
[0016] Optionally, according to the current optimization strategy corresponding to the inference engine, the model layer and the operator in the original model are replaced, including:
[0017] Determining whether the user inputs a customized optimization strategy;
[0018] If yes, then according to the customized optimization strategy, the model layers and operators in the original model are replaced;
[0019] If not, the model layers and operators in the original model are replaced according to the preset optimization strategy corresponding to the inference engine.
[0020] Optionally, while outputting the generation result of the prompt word sequence through the optimized model inference, it also includes:
[0021] Determining whether the user has triggered a speculative sampling request;
[0022] If so, the draft model input by the user is obtained, speculative reasoning is performed using the draft model, and the draft model is synchronously verified for multiple tokens based on the output result of the optimized model.
[0023] Optionally, initializing and configuring the inference engine includes:
[0024] The data processing type, input restriction information, multi-card parallel strategy, access component function information and result generation method corresponding to the inference engine are configured.
[0025] According to another aspect of the present invention, there is provided a large language model reasoning device, which is applied to a reasoning engine, and the device comprises:
[0026] An initialization configuration module, used to obtain the original model input by the user and initialize the configuration of the inference engine;
[0027] A model optimization module, which is used to replace the model layers and operators in the original model through a preset integrated training tool according to the current optimization strategy corresponding to the inference engine, and to segment the original model, and to deploy the multiple segmentation results on multiple different accelerator cards to obtain an optimized model;
[0028] The result output module is used to obtain the prompt word sequence input by the user, and output the generation result of the prompt word sequence through the optimized model reasoning.
[0029] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0030] an accelerator card, at least one processor; and
[0031] a memory communicatively connected to the at least one processor; wherein,
[0032] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the reasoning method of the large language model described in any embodiment of the present invention.
[0033] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the reasoning method of the large language model described in any embodiment of the present invention when executed.
[0034] According to another aspect of the present invention, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the computer program implements the reasoning method of the large language model described in any embodiment of the present invention.
[0035] The technical solution provided by the embodiment of the present invention obtains the original model input by the user, initializes the configuration of the inference engine, replaces the model layer and the operator in the original model through a preset integrated training tool according to the current optimization strategy corresponding to the inference engine, and simultaneously segments the original model, and deploys multiple segmentation results on multiple different acceleration cards to obtain an optimized model, obtains the prompt word sequence input by the user, and outputs the generation result of the prompt word sequence through inference by the optimized model. The technical means can improve the inference efficiency of the large language model and improve the utilization rate of computing resources.
[0036] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0038] Figure 1 is a flow chart of a large language model reasoning method provided according to an embodiment of the present invention;
[0039] Figure 2 is a flow chart of another large language model reasoning method provided according to an embodiment of the present invention;
[0040] Figure 3 is a schematic diagram of the structure of an inference device for a large language model provided according to an embodiment of the present invention;
[0041] Figure 4 It is a schematic diagram of the structure of an electronic device for implementing the inference method of a large language model according to an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0043] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0044] Figure 1 This is a flowchart of a large language model reasoning method provided by an embodiment of the present invention. This embodiment is applicable to the case where the reasoning engine optimizes the reasoning performance of the large language model. The method can be executed by a large language model reasoning device. The large language model reasoning device can be implemented in the form of hardware and / or software. The large language model reasoning device can be configured in the reasoning engine of the electronic device. Figure 1 As shown, the method includes:
[0045] Step 110: Obtain the original model input by the user and initialize the configuration of the inference engine.
[0046] In this embodiment, specifically, the user can input a large language model to be inferred (that is, the original model) into the inference engine. After the inference engine receives the user's input request, it can initialize the inference engine, such as configuring the application parameters and functional components of the inference engine.
[0047] Step 120: Using a preset integrated training tool, according to the current optimization strategy corresponding to the inference engine, the model layers and operators in the original model are replaced, the original model is segmented, and the multiple segmentation results are deployed on multiple different acceleration cards to obtain an optimized model.
[0048] In this embodiment, after the inference engine is initialized and configured, the model layers and operators of the original model can be replaced with optimized versions through a preset integrated training tool (such as ColossalAI.ShardFormer) according to the current optimization strategy corresponding to the inference engine, and the original model can be segmented.
[0049] Among them, ColossalAI can be understood as an integrated system that provides users with a comprehensive set of training methods, such as mixed precision training and gradient accumulation methods. In addition, ColossalAI also provides a series of parallel technologies, including data parallelism, tensor parallelism, and pipeline parallelism. Specifically, tensor parallelism can be optimized through different multi-dimensional distributed matrix multiplication algorithms.
[0050] In this embodiment, optionally, for a multi-card configuration in the inference engine, the original model can be segmented and placed on a specified accelerator card in a tensor parallel manner. In this process, the optimization operator in the optimization strategy can be introduced in a variety of ways, for example, the CUDA operator can be introduced through the ColossalAI.Extension module.
[0051] Specifically, a tensor refers to the basic data structure for storing neural network parameters, which can be a high-dimensional array. Tensor parallelism (also known as model parallelism) is a method of parallel training and reasoning. By splitting the model's parameter tensors, the model is evenly distributed on each accelerator card, thereby reducing the memory overhead of each accelerator card and amortizing all computing operations. Operators refer to the large number of tensor calculations required in the process of reasoning and generating text for a large language model, such as addition, multiplication, matrix multiplication, matrix transposition, etc. are called operators. In a broad sense, operators also include various kernel functions or methods, which can be regarded as a type of encapsulation of computing methods.
[0052] In one implementation of this embodiment, before replacing the model layers and operators in the original model according to the current optimization strategy corresponding to the inference engine through a preset integrated training tool, it also includes: pre-allocating a corresponding activation cache to each accelerator card; initializing the block KV cache manager (KV CacheManager) corresponding to the inference engine, and allocating a corresponding block KV cache to each accelerator card; initializing the scheduler corresponding to the inference engine.
[0053] In the autoregressive decoder model, all tokens input to the model will generate tensors of attention keys and values, which are stored in the GPU memory to generate the next token. These cached key and value tensors are usually called KV caches.
[0054] In a specific embodiment, the optimization operator set in the inference engine can be adapted to the Blocked Key Value Cache, and the optimized model layer can be assembled using Python, providing users with highly flexible customized optimization options.
[0055] The benefit of this setting is that the KV cache of each sequence is divided into blocks by using a block-based KV cache. Each block contains the keys and values of a fixed number of tokens. In the attention calculation, the paged attention operator (kernels) can efficiently identify and extract these blocks. Since the blocks do not need to be continuous in memory, keys and values can be managed flexibly, similar to the virtual memory management of the operating system. In addition, continuous logical blocks can be mapped to non-continuous physical blocks through the block table. As new tokens are generated, physical blocks are allocated on demand. In this process, memory waste mainly occurs in the last block of the sequence, which can optimize the memory usage process and improve GPU utilization and throughput.
[0056] In one implementation of this embodiment, a KV CacheQuant can also be integrated in the inference engine to quantize when storing KV, convert the Key Value type to FP8 storage, and convert it back to the original type for calculation when reading, thereby saving hardware video memory and enabling larger batches of models to be executed. Assuming that FP16 is used when the model is initialized, the Key Value type is FP16 during the generation process. When quantization is used, the KV cache will be converted to FP8 format for storage, and the hardware video memory consumed by the KV cache is half of the original.
[0057] In this embodiment, optionally, after obtaining the optimized model, the inference engine may discard the original model and only retain the optimized model to avoid the original model occupying the device video memory.
[0058] Step 130: Obtain a prompt word sequence input by a user, and output a generation result of the prompt word sequence through inference of the optimized model.
[0059] In this embodiment, specifically, after the inference engine obtains the optimized model, it can enter a state of waiting to accept requests. The user can input a prompt word sequence to the inference engine, such as "What places are worth visiting for summer travel?" After receiving the prompt word sequence, the inference engine can feedback the inference result to the user through the optimized model, such as "Places worth visiting for summer travel include Chengde Mountain Resort, Qingdao, Suzhou, etc. Among them, the Mountain Resort, as one of the classical gardens, combines the majestic momentum of the north and the beautiful scenery of the south. Tourist attractions include..."
[0060] In this embodiment, by using the integrated training tool ColossalAI.ShardFormer to segment and optimize the original large language model, and deploying the model segmentation results on multiple different accelerator cards, an efficient, intelligent, and flexible large language model reasoning method can be provided, which can optimize the model for different types of reasoning tasks, different types of models, and different hardware devices, so as to achieve a significant improvement in reasoning speed and effective use of computing resources.
[0061] The technical solution provided by the embodiment of the present invention obtains the original model input by the user, initializes the configuration of the inference engine, replaces the model layer and the operator in the original model through a preset integrated training tool according to the current optimization strategy corresponding to the inference engine, and simultaneously segments the original model, and deploys multiple segmentation results on multiple different acceleration cards to obtain an optimized model, obtains the prompt word sequence input by the user, and outputs the generation result of the prompt word sequence through inference by the optimized model. The technical means can improve the inference efficiency of the large language model and improve the utilization rate of computing resources.
[0062] Figure 2 A flowchart of another large language model reasoning method provided by an embodiment of the present invention, such as Figure 2 As shown, the method includes:
[0063] Step 210: Obtain the original model input by the user and initialize the configuration of the inference engine.
[0064] In one implementation of this embodiment, the inference engine is initialized and configured, including: configuring the data processing type, input restriction information, multi-card parallel strategy, access component function information and result generation method corresponding to the inference engine.
[0065] Step 220 , determine whether the user inputs a customized optimization strategy, if so, execute step 230 , if not, execute step 240 .
[0066] Step 230: Using a preset integrated training tool, according to the customized optimization strategy, replace the model layers and operators in the original model, split the original model, and deploy multiple split results on multiple different acceleration cards to obtain an optimized model.
[0067] In this embodiment, the customized optimization strategy may include user-defined model layers and operators. The advantage of this setting is that by obtaining the customized optimization strategy input by the user, the scalability of the inference engine can be improved to meet the user's different inference requirements for large language models.
[0068] Step 240: Using a preset integrated training tool, according to a preset optimization strategy corresponding to the inference engine, the model layers and operators in the original model are replaced, the original model is segmented, and the multiple segmentation results are deployed on multiple different acceleration cards to obtain an optimized model.
[0069] Step 250: Obtain the prompt word sequence input by the user, schedule the sequence through the scheduler corresponding to the inference engine, and then output the generation result of the prompt word sequence through the optimized model inference.
[0070] In one implementation of the present embodiment, while outputting the generation result of the prompt word sequence through the optimized model reasoning, it also includes: determining whether the user has triggered a speculative sampling request; if so, obtaining the draft model input by the user, using the draft model for speculative reasoning, and performing synchronous verification of multiple tokens on the draft model based on the output result of the optimized model.
[0071] In this embodiment, the inference engine can also support speculative decoding requests. Users can selectively enable this component and provide a model with a small number of parameters as a draft model for speculative reasoning. The inference engine can use the optimized model as a verification model and use the verification model to synchronously verify multiple tokens of the draft model.
[0072] The technical solution provided by the embodiment of the present invention obtains the original model input by the user, initializes the configuration of the inference engine, determines whether the user inputs a custom optimization strategy, and if so, replaces the model layer and the operator in the original model according to the custom optimization strategy through a preset integrated training tool, and divides the original model at the same time, and deploys multiple segmentation results on multiple different acceleration cards to obtain an optimized model; if not, replaces the model layer and the operator in the original model according to the preset optimization strategy corresponding to the inference engine through a preset integrated training tool, and divides the original model at the same time, and deploys multiple segmentation results on multiple different acceleration cards to obtain an optimized model, obtains the prompt word sequence input by the user, schedules the sequence through a scheduler corresponding to the inference engine, and then outputs the generation result of the prompt word sequence through inference by the optimized model. The technical means can improve the reasoning efficiency of the large language model and improve the utilization rate of computing resources.
[0073] Figure 3 A schematic diagram of the structure of a large language model inference device provided by an embodiment of the present invention, wherein the device is applied to an inference engine of an electronic device, such as Figure 3As shown, the device includes: an initialization configuration module 310, a model optimization module 320 and a result output module 330.
[0074] An initialization configuration module 310 is used to obtain the original model input by the user and initialize the configuration of the inference engine;
[0075] The model optimization module 320 is used to replace the model layers and operators in the original model through a preset integrated training tool according to the current optimization strategy corresponding to the inference engine, and to segment the original model, and deploy multiple segmentation results on multiple different acceleration cards to obtain an optimized model;
[0076] The result output module 330 is used to obtain the prompt word sequence input by the user, and output the generation result of the prompt word sequence through the optimized model reasoning.
[0077] The technical solution provided by the embodiment of the present invention obtains the original model input by the user, initializes the configuration of the inference engine, replaces the model layer and the operator in the original model through a preset integrated training tool according to the current optimization strategy corresponding to the inference engine, and simultaneously segments the original model, and deploys multiple segmentation results on multiple different acceleration cards to obtain an optimized model, obtains the prompt word sequence input by the user, and outputs the generation result of the prompt word sequence through inference by the optimized model. The technical means can improve the inference efficiency of the large language model and improve the utilization rate of computing resources.
[0078] Based on the above embodiment, the initialization configuration module 310 includes:
[0079] A cache allocation unit, used to pre-allocate a corresponding activation cache to each accelerator card;
[0080] A manager initialization unit, used to initialize the block KV cache manager corresponding to the inference engine and allocate a corresponding block KV cache to each accelerator card;
[0081] A scheduler initialization unit, used to initialize the scheduler corresponding to the inference engine;
[0082] The engine configuration unit is used to configure the data processing type, input restriction information, multi-card parallel strategy, access component function information and result generation method corresponding to the inference engine.
[0083] The model optimization module 320 includes:
[0084] The strategy judgment unit is used to judge whether the user inputs a customized optimization strategy. If so, the model layers and operators in the original model are replaced according to the customized optimization strategy; if not, the model layers and operators in the original model are replaced according to the preset optimization strategy corresponding to the inference engine.
[0085] The result output module 330 includes:
[0086] A scheduling unit, used to obtain a prompt word sequence input by a user, schedule the sequence through a scheduler corresponding to the inference engine, and then output a generation result of the prompt word sequence through optimized model inference;
[0087] The speculative sampling unit is used to determine whether the user has triggered a speculative sampling request while outputting the generation result of the prompt word sequence through the optimized model reasoning. If so, obtain the draft model input by the user, use the draft model for speculative reasoning, and perform synchronous verification of multiple tokens on the draft model based on the output result of the optimized model.
[0088] The above device can execute the methods provided by all the above embodiments of the present invention, and has the corresponding functional modules and beneficial effects of executing the above methods. For technical details not fully described in the embodiments of the present invention, please refer to the methods provided by all the above embodiments of the present invention.
[0089] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0090] like Figure 4As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0091] Multiple components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks. In addition, the electronic device 10 may also include an accelerator card 20 for deploying the segmentation results of the original large language model.
[0092] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as the reasoning method of the large language model.
[0093] In some embodiments, the reasoning method of the large language model may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the reasoning method of the large language model described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the reasoning method of the large language model in any other appropriate manner (e.g., by means of firmware).
[0094] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0095] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0096] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0097] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0098] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0099] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0100] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0101] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for reasoning about a large language model, characterized in that: Applied in an inference engine, the method comprises: Obtaining the original model input by the user and initializing the configuration of the inference engine; By using a preset integrated training tool, according to the current optimization strategy corresponding to the inference engine, the model layer and the operator in the original model are replaced, the original model is segmented, and the multiple segmentation results are respectively deployed on multiple different accelerator cards to obtain an optimized model; Obtaining a prompt word sequence input by a user, and outputting a generation result of the prompt word sequence through inference of the optimized model; Among them, before replacing the model layer and operators in the original model according to the current optimization strategy corresponding to the inference engine through a preset integrated training tool, it also includes: pre-allocating a corresponding activation cache to each accelerator card; initializing the block KV cache manager corresponding to the inference engine, and allocating a corresponding block KV cache to each accelerator card; initializing the scheduler corresponding to the inference engine.
2. The method according to claim 1, characterized in that Obtaining a prompt word sequence input by a user, and outputting a generation result of the prompt word sequence through the optimized model inference, including: The prompt word sequence input by the user is obtained, the sequence is scheduled by the scheduler corresponding to the inference engine, and then the generation result of the prompt word sequence is output through the optimized model inference.
3. The method according to claim 1, characterized in that: According to the current optimization strategy corresponding to the inference engine, the model layers and operators in the original model are replaced, including: Determining whether the user inputs a customized optimization strategy; If yes, then according to the customized optimization strategy, the model layers and operators in the original model are replaced; If not, the model layers and operators in the original model are replaced according to the preset optimization strategy corresponding to the inference engine.
4. The method according to claim 1, characterized in that: While outputting the generation result of the prompt word sequence through the optimized model reasoning, the method also includes: Determining whether the user has triggered a speculative sampling request; If so, the draft model input by the user is obtained, speculative reasoning is performed using the draft model, and the draft model is synchronously verified for multiple tokens based on the output result of the optimized model.
5. The method according to claim 1, characterized in that Initializing and configuring the inference engine includes: The data processing type, input restriction information, multi-card parallel strategy, access component function information and result generation method corresponding to the inference engine are configured.
6. A large language model reasoning device, characterized in that: Applied in an inference engine, the device comprises: An initialization configuration module, used to obtain the original model input by the user and initialize the configuration of the inference engine; A model optimization module, which is used to replace the model layers and operators in the original model through a preset integrated training tool according to the current optimization strategy corresponding to the inference engine, and to segment the original model, and to deploy the multiple segmentation results on multiple different accelerator cards to obtain an optimized model; A result output module, used to obtain a prompt word sequence input by a user, and output a generation result of the prompt word sequence through the optimized model reasoning; Among them, before replacing the model layer and operators in the original model according to the current optimization strategy corresponding to the inference engine through a preset integrated training tool, it also includes: pre-allocating a corresponding activation cache to each accelerator card; initializing the block KV cache manager corresponding to the inference engine, and allocating a corresponding block KV cache to each accelerator card; initializing the scheduler corresponding to the inference engine.
7. An electronic device, characterized in that: The electronic device comprises: an accelerator card, at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the inference method of the large language model according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the reasoning method of a large language model according to any one of claims 1 to 5 when executed.
9. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the reasoning method of a large language model according to any one of claims 1 to 5.
Citation Information
Patent Citations
AIoT-oriented multi-task local collaborative reasoning method and system
CN116306943A
Method, device and equipment for realizing open domain questions and answers of large-scale language model
CN116662509A
Cited By
Systems and methods for key-value caching in speculative decoding
WO2026165346A1
