IP Library › Granted Patent US 11,442,775
Granted Patent B1
US 11,442,775 · App. 17/542,193 · Granted Sep 13, 2022

Dynamic batching for inference system for transformer-based generation tasks

Inventors: Gyeongin Yu (Seoul, KR); Geon-Woo Kim (Seoul, KR); Joo Seong Jeong (Seoul, KR); Soojeong Kim (Seoul, KR); Byung-Gon Chun (Seoul, KR)
Assignee: FriendliAI Inc.
G06F9/4881G06F9/5016G06N5/04G06N20/00G06N3/0454G06N3/08
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 11,442,775
App. No.
17/542,193
Granted
Sep 13, 2022
Kind
B1
Abstract

An inference system applies a machine-learning transformer model to a batch of requests with variable input length or variable target length or variable internal state length by selectively batching a subset of operations in the transformer model but processing requests in the batch individually for a subset of operations in the transformer model. In one embodiment, the operation to be processed individually is an attention operation of an encoder or a decoder of the transformer model. By selective batching, the inference system can allow batching operations to be performed for a batch of requests with variable input or target length or internal state length to utilize the parallel computation capabilities of hardware accelerators while preventing unnecessary computations that occur for workarounds that restrain the data of a batch of requests to a same length.

Claims (38)

1. A method of dynamically executing batches of requests on one or more execution engines running a machine-learning transformer model, comprising:

receiving, by a serving system, one or more requests for execution, the serving system including a scheduler and one or more execution engines each coupled to access a machine-learning transformer model including at least a set of decoders;

scheduling, by the scheduler, a batch of requests including the one or more requests for execution on an execution engine;

generating, by the execution engine, a first set of output tokens by applying the transformer model to a first set of inputs for the batch of requests, wherein applying the transformer model comprises applying at least one batch operation to one or more input tensors associated with the batch of requests;

receiving, by a request processor, a new request from a client device, the new request including a sequence of input tokens;

scheduling, by the scheduler, a second batch of requests additionally including the new request for execution on the execution engine, the second batch of requests scheduled responsive to determining that the execution engine has memory available to execute the second batch of requests, wherein in a second set of inputs for the second batch of requests, a length of the sequence of input tokens for the new request is different from a length of an input for at least one request other than the new request; and

generating, by the execution engine, a second set of output tokens by applying the transformer model to the second set of inputs for the second batch.

2. The method of claim 1 , further comprising:

responsive to determining that a request in the first batch of requests has been completed, providing output tokens generated for the completed request to a client device as a response to the request, and

wherein the second batch of requests includes at least one of the remaining requests from the one or more requests and the new request.

3. The method of claim 2 , wherein the request is associated with a cache memory in the execution engine dedicated for storing an internal state for the request, and responsive to determining that the request has been completed, freeing the dedicated cache memory for the request in the execution engine.

4. The method of claim 1 , wherein the input for the at least one request is an output token from the first set of output tokens for the at least one request, and wherein a length of the sequence of input tokens for the new request is different from a length of the output token for the at least one request.

5. The method of claim 4 ,

wherein the execution engine includes a cache memory for maintaining a key cache tensor for storing keys and a value cache tensor for storing values for the at least one request, and

wherein after scheduling the second batch of requests, allocating, by the execution engine, a new cache memory dedicated to maintaining a key cache tensor and a value cache tensor for the new request.

6. The method of claim 5 , wherein after generating the second set of output tokens, a length of the key cache tensor for the at least one request is different from a length of a key cache tensor for the new request, and a length of the value cache tensor for the at least one request is different from a length of a value cache tensor for the new request.

7. The method of claim 1 , after receiving the new request from the client device, determining, by the scheduler, that there is insufficient memory available to execute the second batch of requests on a second execution engine different from the execution engine, and responsive to the determination for the second execution engine, determining whether the execution engine has the memory available to execute the second batch of requests.

8. The method of claim 1 , wherein the execution engine is configured as a graphics processing unit (GPU) or a tensor processing unit (TPU).

9. The method of claim 1 , wherein each token in the sequence of input tokens represents a text unit.

10. A non-transitory computer-readable storage medium storing computer program instructions executable to perform operations for dynamically executing batches of requests on one or more execution engines running a machine-learning transformer model, the operations comprising:

receiving, by a serving system, one or more requests for execution, the serving system including a scheduler and one or more execution engines each coupled to access a machine-learning transformer model including at least a set of decoders;

scheduling, by the scheduler, a batch of requests including the one or more requests for execution on an execution engine;

generating, by the execution engine, a first set of output tokens by applying the transformer model to a first set of inputs for the batch of requests, wherein applying the transformer model comprises applying at least one batch operation to one or more input tensors associated with the batch of requests;

receiving, by a request processor, a new request from a client device, the new request including a sequence of input tokens;

scheduling, by the scheduler, a second batch of requests additionally including the new request for execution on the execution engine, the second batch of requests scheduled responsive to determining that the execution engine has memory available to execute the second batch of requests, wherein in a second set of inputs for the second batch of requests, a length of the sequence of input tokens for the new request is different from a length of an input for at least one request other than the new request; and

generating, by the execution engine, a second set of output tokens by applying the transformer model to the second set of inputs for the second batch.

11. The non-transitory computer-readable storage medium of claim 10 , the operations further comprising:

responsive to determining that a request in the first batch of requests has been completed, providing output tokens generated for the completed request to a client device as a response to the request, and

wherein the second batch of requests includes at least one of the remaining requests from the one or more requests and the new request.

12. The non-transitory computer-readable storage medium of claim 11 , wherein the request is associated with a cache memory in the execution engine dedicated for storing an internal state for the request, and responsive to determining that the request has been completed, freeing the dedicated cache memory for the request in the execution engine.

13. The non-transitory computer-readable storage medium of claim 10 , wherein the input for the at least one request is at least one output token from the first set of output tokens for the at least one request, and wherein a length of the sequence of input tokens for the new request is different from a length of the at least one output token for the at least one request.

14. The non-transitory computer-readable storage medium of claim 13 ,

wherein the execution engine includes a cache memory for maintaining a key cache tensor for storing keys and a value cache tensor for storing values for the at least one request, and

wherein after scheduling the second batch of requests, allocating, by the execution engine, a new cache memory dedicated to maintaining a key cache tensor and a value cache tensor for the new request.

15. The non-transitory computer-readable storage medium of claim 14 , wherein after generating the second set of output tokens, a length of the key cache tensor for the at least one request is different from a length of a key cache tensor for the new request, and a length of the value cache tensor for the at least one request is different from a length of a value cache tensor for the new request.

16. The non-transitory computer-readable storage medium of claim 10 , after receiving the new request from the client device, determining, by the scheduler, that there is insufficient memory available to execute the second batch of requests on a second execution engine different from the execution engine, and responsive to the determination for the second execution engine, determining whether the execution engine has the memory available to execute the second batch of requests.

17. The non-transitory computer-readable storage medium of claim 10 , wherein the execution engine is configured as a graphics processing unit (GPU) or a tensor processing unit (TPU).

18. The non-transitory computer-readable storage medium of claim 10 , wherein each token in the sequence of input tokens represents a text unit.

Assignments (4)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Oct 8, 2025
From: FRIENDLIAI INC.
To: FRIENDLIAI CORP.
Reel/Frame 072515/0423 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded May 17, 2022
From: SEOUL NATIONAL UNIVERSITY R&DB FOUNDATION
To: FRIENDLIAI INC.
Reel/Frame 059935/0001 →
CORRECTIVE ASSIGNMENT TO CORRECT THE SPELLING OF THE NAME OF ASSIGNEE PREVIOUSLY RECORDED ON REEL 058329 FRAME 0226. ASSIGNOR(S) HEREBY CONFIRMS THE CORRECT SPELLING OF THE NAME OF ASSIGNEE IS FRIENDLIAI INC. Recorded Dec 20, 2021
From: YU, GYEONGIN; KIM, GEON-WOO; JEONG, JOO SEONG; KIM, SOOJEONG; CHUN, BYUNG-GON
To: FRIENDLIAI INC.; SEOUL NATIONAL UNIVERSITY R&DB FOUNDATION
Reel/Frame 058599/0509 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 7, 2021
From: YU, GYEONGIN; KIM, GEON-WOO; JEONG, JOO SEONG; KIM, SOOJEONG; CHUN, BYUNG-GON
To: FRIENDLI AI INC.; SEOUL NATIONAL UNIVERSITY R&DB FOUNDATION
Reel/Frame 058329/0226 →
Cited By (4)
US 12,511,219 US 12,524,266 US 12,657,066 US 12,670,019