# US 2017/0286864 A1 · Batching inputs to a machine learning model

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2017/0286864 A1
- Document ID: US20170286864A1
- Status: Published application
- Kind: A1
- Application number: 15/091,381
- Filed: 2016-04-05
- Published: 2017-10-05
- Earliest claimed: 2016-04-05
- Assignees: Google Inc.
- Applicants: Google Inc.
- Inventors: Noah Fiedel; Christopher Olston; Jeremiah Harmsen
- Web page: https://patentgrep.com/patent/US20170286864A1

## CPC

- G06N 20/00: Machine learning
- G06F 9/546: {Message passing systems or structures, e.g. queues}
- G06F 2209/548: Queue
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Methods, systems, and apparatus, including computer programs encoded on computer storage media, for batching inputs to machine learning models. One of the methods includes receiving a stream of requests, each request identifying a respective input for processing by a first machine learning model; adding the respective input from each request to a first queue of inputs for processing by the first machine learning model; determining, at a first time, that a count of inputs in the first queue as of the first time equals or exceeds a maximum batch size and, in response: generating a first batched input from the inputs in the queue as of the first time so that a count of inputs in the first batched input equals the maximum batch size, and providing the first batched input for processing by the first machine learning model.

## Claims

### Claim 1

A method comprising:
receiving a stream of requests, each request identifying a respective input for processing by a first machine learning model;
adding the respective input from each request to a first queue of inputs for processing by the first machine learning model;
determining, at a first time, that a count of inputs in the first queue as of the first time equals or exceeds a maximum batch size and, in response:
generating a first batched input from the inputs in the queue as of the first time so that a count of inputs in the first batched input equals the maximum batch size, and
providing the first batched input for processing by the first machine learning model; and
determining, at a second time, that (i) a count of inputs in the queue as of the second time is less than that the maximum batch size but (ii) an oldest input in the queue is older than a latency parameter, and in response:
generating a second batched input from the inputs in the queue as of the second time so that a count of inputs in the second batched input is less than the maximum batch size, and
providing the second batched input for processing by the first machine learning model.

### Claim 2 (depends on 1)

The method of claim 1, wherein generating the second batched input comprises:
determining that the count of inputs in the second batched input is more than a first acceptable batch size and less than a second acceptable batch size and, in response, adding placeholder inputs to the second batched input so that the count of inputs in the second batched input equals the second acceptable batch size.

### Claim 3 (depends on 2)

The method of claim 2, wherein each placeholder input is a copy of a respective input already in the second batched input.

### Claim 4 (depends on 2)

The method of claim 2, further comprising:
receiving a second machine learning output generated by the machine learning model for the second batched input;
determining, for each input in the second batched input, a respective portion of the second machine learning output that corresponds to the input;
for each placeholder input in the second batched input, discarding the respective corresponding portion of the second machine learning output; and
for each input in the second batched input that is not a placeholder input, providing the respective corresponding portion of the second machine learning output in a response to the request that identified the input.

### Claim 5 (depends on 1)

The method of claim 1,
wherein the processing of inputs by the first machine learning model is managed by a computational graph system that represents the operations of the first machine learning model during processing of a given batched input as computational graph,
wherein the computational graph comprises a plurality of nodes and directed edges,
wherein each node represents a respective operation, and
wherein each directed edge connects a respective first node to a respective second node that represents an operation that receives, as input, an output of an operation represented by the respective first node.

### Claim 6 (depends on 5)

The method of claim 5, wherein the computational graph system processes batched inputs by assigning the operations represented by the nodes in the computational graph among a plurality of devices.

### Claim 7 (depends on 5)

The method of claim 5, wherein providing the first batched input for processing by the first machine learning model comprises providing the first batched input to the computational graph system, and wherein providing the second batched input for processing by the first machine learning model comprises providing the second batched input to the computational graph system.

### Claim 8 (depends on 1)

The method of claim 1, further comprising:
maintaining a plurality of queues that includes the first queue, wherein each queue corresponds to a respective machine learning model from a plurality of machine learning models.

### Claim 9 (depends on 8)

The method of claim 8, further comprising:
determining that a thread has become available for processing a batched input by one of the plurality of machine learning models; and
selecting the first machine learning model from the plurality of machine learning models and, in response, providing the first batched input for processing on the thread that has become available.

### Claim 10 (depends on 1)

The method of claim 1, further comprising:
determining the maximum batch size based on characteristics of hardware resources available for processing inputs to the machine learning model and an architecture of the machine learning model.

### Claim 11

A system comprising one or more computers and one or more storage devices storing instructions that, when executed by the one or more computers, cause the one or more computers to perform operations comprising:
receiving a stream of requests, each request identifying a respective input for processing by a first machine learning model;
adding the respective input from each request to a first queue of inputs for processing by the first machine learning model;
determining, at a first time, that a count of inputs in the first queue as of the first time equals or exceeds a maximum batch size and, in response:
generating a first batched input from the inputs in the queue as of the first time so that a count of inputs in the first batched input equals the maximum batch size, and
providing the first batched input for processing by the first machine learning model; and
determining, at a second time, that (i) a count of inputs in the queue as of the second time is less than that the maximum batch size but (ii) an oldest input in the queue is older than a latency parameter, and in response:
generating a second batched input from the inputs in the queue as of the second time so that a count of inputs in the second batched input is less than the maximum batch size, and
providing the second batched input for processing by the first machine learning model.

### Claim 12 (depends on 11)

The system of claim 11, wherein generating the second batched input comprises:
determining that the count of inputs in the second batched input is more than a first acceptable batch size and less than a second acceptable batch size and, in response, adding placeholder inputs to the second batched input so that the count of inputs in the second batched input equals the second acceptable batch size.

### Claim 13 (depends on 12)

The system of claim 12, wherein each placeholder input is a copy of a respective input already in the second batched input.

### Claim 14 (depends on 12)

The system of claim 12, the operations further comprising:
receiving a second machine learning output generated by the machine learning model for the second batched input;
determining, for each input in the second batched input, a respective portion of the second machine learning output that corresponds to the input;
for each placeholder input in the second batched input, discarding the respective corresponding portion of the second machine learning output; and
for each input in the second batched input that is not a placeholder input, providing the respective corresponding portion of the second machine learning output in a response to the request that identified the input.

### Claim 15 (depends on 11)

The system of claim 11,
wherein the processing of inputs by the first machine learning model is managed by a computational graph system that represents the operations of the first machine learning model during processing of a given batched input as computational graph,
wherein the computational graph comprises a plurality of nodes and directed edges,
wherein each node represents a respective operation, and
wherein each directed edge connects a respective first node to a respective second node that represents an operation that receives, as input, an output of an operation represented by the respective first node.

### Claim 16 (depends on 15)

The system of claim 15, wherein the computational graph system processes batched inputs by assigning the operations represented by the nodes in the computational graph among a plurality of devices.

### Claim 17 (depends on 15)

The system of claim 15, wherein providing the first batched input for processing by the first machine learning model comprises providing the first batched input to the computational graph system, and wherein providing the second batched input for processing by the first machine learning model comprises providing the second batched input to the computational graph system.

### Claim 18 (depends on 11)

The system of claim 11, the operations further comprising:
maintaining a plurality of queues that includes the first queue, wherein each queue corresponds to a respective machine learning model from a plurality of machine learning models.

### Claim 19 (depends on 18)

The system of claim 18, the operations further comprising:
determining that a thread has become available for processing a batched input by one of the plurality of machine learning models; and
selecting the first machine learning model from the plurality of machine learning models and, in response, providing the first batched input for processing on the thread that has become available.

### Claim 20

One or more non-transitory computer storage media storing instructions that when executed by one or more computers, cause the one or more computers to perform operations comprising:
receiving a stream of requests, each request identifying a respective input for processing by a first machine learning model;
adding the respective input from each request to a first queue of inputs for processing by the first machine learning model;
determining, at a first time, that a count of inputs in the first queue as of the first time equals or exceeds a maximum batch size and, in response:
generating a first batched input from the inputs in the queue as of the first time so that a count of inputs in the first batched input equals the maximum batch size, and
providing the first batched input for processing by the first machine learning model; and
determining, at a second time, that (i) a count of inputs in the queue as of the second time is less than that the maximum batch size but (ii) an oldest input in the queue is older than a latency parameter, and in response:
generating a second batched input from the inputs in the queue as of the second time so that a count of inputs in the second batched input is less than the maximum batch size, and
providing the second batched input for processing by the first machine learning model.
